From 4b066e04f619c2c6f8d383daee9ceab49f39acdc Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 9 Jul 2012 22:08:25 -0700 Subject: making tags work --- include/contact_widgets.php | 36 +++++++---------- include/conversation.php | 37 +++++++++++------ include/nav.php | 2 +- include/text.php | 97 ++++++++++++++++++++++++++++++++------------- 4 files changed, 111 insertions(+), 61 deletions(-) (limited to 'include') diff --git a/include/contact_widgets.php b/include/contact_widgets.php index ce1cdbad5..ae88eefb4 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -77,21 +77,18 @@ function networks_widget($baseurl,$selected = '') { function fileas_widget($baseurl,$selected = '') { $a = get_app(); + if(! local_user()) return ''; - $saved = get_pconfig(local_user(),'system','filetags'); - if(! strlen($saved)) - return; - - $matches = false; $terms = array(); - $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER); - if($cnt) { - foreach($matches as $mtch) { - $unescaped = xmlify(file_tag_decode($mtch[1])); - $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : '')); - } + $r = q("select distinct(term) from term where uid = %d and type = %d order by term asc", + intval(local_user()), + intval(TERM_FILE) + ); + if(count($r)) { + foreach($r as $rr) + $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); } return replace_macros(get_markup_template('fileas_widget.tpl'),array( @@ -108,18 +105,15 @@ function fileas_widget($baseurl,$selected = '') { function categories_widget($baseurl,$selected = '') { $a = get_app(); - $saved = get_pconfig($a->profile['profile_uid'],'system','filetags'); - if(! strlen($saved)) - return; - $matches = false; $terms = array(); - $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER); - if($cnt) { - foreach($matches as $mtch) { - $unescaped = xmlify(file_tag_decode($mtch[1])); - $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : '')); - } + $r = q("select distinct(term) from term where uid = %d and type = %d order by term asc", + intval($a->profile['profile_uid']), + intval(TERM_CATEGORY) + ); + if(count($r)) { + foreach($r as $rr) + $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); } return replace_macros(get_markup_template('categories_widget.tpl'),array( diff --git a/include/conversation.php b/include/conversation.php index 240cd374f..f81a7e7d2 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -611,13 +611,12 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); if($page_writeable) { -/* if($toplevelpost) { */ - $likebuttons = array( - 'like' => array( t("I like this \x28toggle\x29"), t("like")), - 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), - ); - if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share')); -/* } */ + $likebuttons = array( + 'like' => array( t("I like this \x28toggle\x29"), t("like")), + 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), + ); + if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share')); + $qc = $qcomment = null; @@ -739,10 +738,11 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $tags=array(); - foreach(explode(',',$item['tag']) as $tag){ - $tag = trim($tag); - if ($tag!="") $tags[] = bbcode($tag); - } + $terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_UNKNOWN)); + if(count($terms)) + foreach($terms as $tag) + $tags[] = format_term_for_display($tag); + // Build the HTML @@ -1102,13 +1102,26 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { } -function conv_sort($arr,$order) { +function conv_sort($arr,$tags,$order) { if((!(is_array($arr) && count($arr)))) return array(); $parents = array(); + + for($x = 0; $x < count($arr); $x ++) { + if(count($tags)) { + foreach($tags as $t) { + if($t['oid'] == $arr[$x]['item_id']) { + if(! is_array($arr[$x]['term'])) + $arr[$x]['term'] = array(); + $arr[$x]['term'][] = $t; + } + } + } + } + foreach($arr as $x) if($x['id'] == $x['parent']) $parents[] = $x; diff --git a/include/nav.php b/include/nav.php index e26cc8889..3f65fe919 100644 --- a/include/nav.php +++ b/include/nav.php @@ -156,7 +156,7 @@ function nav(&$a) { $banner = get_config('system','banner'); if($banner === false) - $banner .= 'logoFriendica'; + $banner .= 'logored'; $tpl = get_markup_template('nav.tpl'); diff --git a/include/text.php b/include/text.php index 409d40d59..f3bc94265 100644 --- a/include/text.php +++ b/include/text.php @@ -881,20 +881,7 @@ function prepare_body($item,$attach = false) { $a = get_app(); call_hooks('prepare_body_init', $item); - $cache = get_config('system','itemcache'); - - if (($cache != '')) { - $cachefile = $cache."/".$item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']); - - if (file_exists($cachefile)) - $s = file_get_contents($cachefile); - else { - $s = prepare_text($item['body']); - file_put_contents($cachefile, $s); - } - } else - $s = prepare_text($item['body']); - + $s = prepare_text($item['body']); $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); @@ -938,30 +925,29 @@ 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) { + + $x = ''; + $terms = get_terms_oftype($item['term'],TERM_CATEGORY); + if($terms) { + foreach($terms as $t) { if(strlen($x)) $x .= ','; - $x .= xmlify(file_tag_decode($mtch[1])) - . ((local_user() == $item['uid']) ? ' ' . t('[remove]') . '' : ''); + $x .= $t['term'] + . ((local_user() == $item['uid']) ? ' ' . t('[remove]') . '' : ''); } 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) { + $terms = get_terms_oftype($item['term'],TERM_FILE); + if($terms) { + foreach($terms as $t) { if(strlen($x)) $x .= '   '; - $x .= xmlify(file_tag_decode($mtch[1])) . ' ' . t('[remove]') . ''; + $x .= $t['term'] . ' ' . t('[remove]') . ''; } if(strlen($x) && (local_user() == $item['uid'])) $s .= '
' . t('Filed under:') . ' ' . $x . '
'; @@ -1460,10 +1446,67 @@ function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') { return true; } +function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { + if(! $term) + return false; + $r = q("select * from term + where uid = %d and oid = %d and otype = %d and type = %d + and term = '%s' and url = '%s' ", + intval($uid), + intval($iid), + intval($otype), + intval($type), + dbesc($term), + dbesc($url) + ); + if(count($r)) + return false; + $r = q("insert into term (uid, oid, otype, type, term, url) + values( %d, %d, %d, %d, '%s', '%s') ", + intval($uid), + intval($iid), + intval($otype), + intval($type), + dbesc($term), + dbesc($url) + ); + return $r; +} + +function get_terms_oftype($arr,$type) { + $ret = array(); + if(! (is_array($arr) && count($arr))) + return $ret; + + if(! is_array($type)) + $type = array($type); + + foreach($type as $t) + foreach($arr as $x) + if($x['type'] == $t) + $ret[] = $x; + return $ret; +} + +function format_term_for_display($term) { + $s = ''; + if($term['type'] == TERM_HASHTAG) + $s .= '#'; + elseif($term['type'] == TERM_MENTION) + $s .= '@'; + + if($term['url']) $s .= '' . $term['term'] . ''; + else $s .= $term['term']; + return $s; +} + + + 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) -- cgit v1.2.3