From 93058af4fcfa0c1dbe8398271c60513dea16338c Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 11 Mar 2012 20:19:56 -0700 Subject: backend for "save to file" feature --- include/text.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 5ad0154d7..08b2b8487 100644 --- a/include/text.php +++ b/include/text.php @@ -1235,4 +1235,23 @@ function item_post_type($item) { return t('post'); } +// post categories and "save to file" use the same item.file table for storage. +// We will differentiate the different uses by wrapping categories in angle brackets +// and save to file categories in square brackets. +// To do this we need to escape these characters if they appear in our tag. +function file_tag_encode($s) { + return str_replace(array('<','>','[',']'),array('%3c','%3e','%5b','%5d'),$s); +} + +function file_tag_decode($s) { + return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s); +} + +function file_tag_file_query($table,$s,$type = 'file') { + if($type == 'file') + $str = preg_quote( '[' . file_tag_encode($s) . ']' ); + else + $str = preg_quote( '<' . file_tag_encode($s) . '>' ); + return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' "; +} \ No newline at end of file -- cgit v1.2.3 From 3bc990f7186af620e7e85bbf5c70bf5795c04a6d Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 11 Mar 2012 21:32:11 -0700 Subject: more save to file backend --- include/text.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 08b2b8487..011006b76 100644 --- a/include/text.php +++ b/include/text.php @@ -1254,4 +1254,58 @@ function file_tag_file_query($table,$s,$type = 'file') { else $str = preg_quote( '<' . file_tag_encode($s) . '>' ); return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' "; -} \ No newline at end of file +} + +function file_tag_save_file($uid,$item,$file) { + $result = false; + if(! intval($uid)) + return false; + $r = q("select file from item where id = %d and uid = %d limit 1", + intval($item), + intval($uid) + ); + if(count($r)) { + if(! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) + q("update item set file = '%s' where id = %d and uid = %d limit 1", + dbesc($r[0]['file'] . '[' . $file_tag_encode($file) . ']'), + intval($item), + intval($uid) + ); + $saved = get_pconfig($uid,'system','filetags'); + if((! strlen($saved)) || (! stristr($saved,'[' . file_tag_encode($file) . ']'))) + set_pconfig($uid,'system','filetags',$saved . '[' . file_tag_encode($file) . ']'); + } + return true; +} + +function file_tag_unsave_file($uid,$item,$file) { + $result = false; + if(! intval($uid)) + return false; + + $pattern = '[' . file_tag_encode($file) . ']' ; + + $r = q("select file from item where id = %d and uid = %d limit 1", + intval($item), + intval($uid) + ); + if(! count($r)) + return false; + + q("update item set file = '%s' where id = %d and uid = %d limit 1", + dbesc(str_replace($pattern,'',$r[0]['file'])), + intval($item), + intval($uid) + ); + + $r = q("select file from item where uid = %d " . file_tag_file_query('item',$file), + intval($uid) + ); + + if(! count($r)) { + $saved = get_pconfig($uid,'system','filetags'); + set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved)); + } + return true; +} + -- cgit v1.2.3 From 5a4167646553e589cf9647c0e0d0446e3f5fd672 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 13 Mar 2012 04:04:26 -0700 Subject: initial tag display for categories and save-to-file - suitable for testing but needs cleanup, links to delete term, and theming. --- include/text.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 011006b76..2663bdeba 100644 --- a/include/text.php +++ b/include/text.php @@ -913,6 +913,33 @@ function prepare_body($item,$attach = false) { } $s .= '
'; } + $matches = false; + $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); + if($cnt) { + logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG); + foreach($matches as $mtch) { + if(strlen($x)) + $x .= ','; + $x .= file_tag_decode($mtch[1]); + } + if(strlen($x)) + $s .= '
' . t('Categories:') . ' ' . $x . '
'; + + + } + $matches = false; + $x = ''; + $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); + if($cnt) { + logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG); + foreach($matches as $mtch) { + if(strlen($x)) + $x .= ','; + $x .= file_tag_decode($mtch[1]); + } + if(strlen($x) && (local_user() == $item['uid'])) + $s .= '
' . t('Filed under:') . ' ' . $x . '
'; + } $prep_arr = array('item' => $item, 'html' => $s); -- cgit v1.2.3 From be48fff1570aa1d04e049a6fd1665f4fc9634a62 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 13 Mar 2012 18:13:03 -0700 Subject: file as widget and basic filing implementation for duepuntozero,slackr much more work needed - this is just for test/evaluation currently --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 2663bdeba..c44b4d178 100644 --- a/include/text.php +++ b/include/text.php @@ -1294,7 +1294,7 @@ function file_tag_save_file($uid,$item,$file) { if(count($r)) { if(! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) q("update item set file = '%s' where id = %d and uid = %d limit 1", - dbesc($r[0]['file'] . '[' . $file_tag_encode($file) . ']'), + dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'), intval($item), intval($uid) ); -- cgit v1.2.3 From 4972d7ef6ee740f6eb09d8c7efa9a76ee40973c1 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 13 Mar 2012 20:46:37 -0700 Subject: more work on filer, comment level and file tag removal --- include/text.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index c44b4d178..199460d2c 100644 --- a/include/text.php +++ b/include/text.php @@ -874,6 +874,7 @@ function link_compare($a,$b) { if(! function_exists('prepare_body')) { function prepare_body($item,$attach = false) { + $a = get_app(); call_hooks('prepare_body_init', $item); $s = prepare_text($item['body']); @@ -916,7 +917,7 @@ function prepare_body($item,$attach = false) { $matches = false; $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); if($cnt) { - logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG); +// logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG); foreach($matches as $mtch) { if(strlen($x)) $x .= ','; @@ -931,11 +932,11 @@ function prepare_body($item,$attach = false) { $x = ''; $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); if($cnt) { - logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG); +// logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG); foreach($matches as $mtch) { if(strlen($x)) - $x .= ','; - $x .= file_tag_decode($mtch[1]); + $x .= '   '; + $x .= file_tag_decode($mtch[1]). ' ' . t('[remove]') . ''; } if(strlen($x) && (local_user() == $item['uid'])) $s .= '
' . t('Filed under:') . ' ' . $x . '
'; -- cgit v1.2.3