aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-06-19 21:50:14 -0700
committerfriendica <info@friendica.com>2013-06-19 21:50:14 -0700
commit3b1e5e5204d7cade3afc320cc45b1eb4efa6743c (patch)
treecb5eba6c9cdffc771443a868e99c38cd81f2d401 /include/text.php
parent4f06905a186252327e7446b8767889dc37aff9fc (diff)
downloadvolse-hubzilla-3b1e5e5204d7cade3afc320cc45b1eb4efa6743c.tar.gz
volse-hubzilla-3b1e5e5204d7cade3afc320cc45b1eb4efa6743c.tar.bz2
volse-hubzilla-3b1e5e5204d7cade3afc320cc45b1eb4efa6743c.zip
source code re-org, move taxonomy to separate include
Diffstat (limited to 'include/text.php')
-rwxr-xr-xinclude/text.php282
1 files changed, 16 insertions, 266 deletions
diff --git a/include/text.php b/include/text.php
index c51ee0bd2..71268a793 100755
--- a/include/text.php
+++ b/include/text.php
@@ -1424,278 +1424,28 @@ function reltoabs($text, $base)
}
function item_post_type($item) {
- if(intval($item['event-id']))
- return t('event');
- if(strlen($item['resource_id']))
- return t('photo');
- if(strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST)
- return t('activity');
- if($item['id'] != $item['parent'])
- return t('comment');
- 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')
- $termtype = TERM_FILE;
- else
- $termtype = TERM_CATEGORY;
-
- return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
- intval($termtype),
- protect_sprintf(dbesc($s))
- );
-}
-
-function term_query($table,$s,$type = TERM_UNKNOWN) {
-
- return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
- intval($type),
- protect_sprintf(dbesc($s))
- );
-}
-
-// ex. given music,video return <music><video> or [music][video]
-function file_tag_list_to_file($list,$type = 'file') {
- $tag_list = '';
- if(strlen($list)) {
- $list_array = explode(",",$list);
- if($type == 'file') {
- $lbracket = '[';
- $rbracket = ']';
- }
- else {
- $lbracket = '<';
- $rbracket = '>';
- }
-
- foreach($list_array as $item) {
- if(strlen($item)) {
- $tag_list .= $lbracket . file_tag_encode(trim($item)) . $rbracket;
- }
- }
- }
- return $tag_list;
-}
-
-// ex. given <music><video>[friends], return music,video or friends
-function file_tag_file_to_list($file,$type = 'file') {
- $matches = false;
- $list = '';
- if($type == 'file') {
- $cnt = preg_match_all('/\[(.*?)\]/',$file,$matches,PREG_SET_ORDER);
- }
- else {
- $cnt = preg_match_all('/<(.*?)>/',$file,$matches,PREG_SET_ORDER);
- }
- if($cnt) {
- foreach($matches as $mtch) {
- if(strlen($list))
- $list .= ',';
- $list .= file_tag_decode($mtch[1]);
- }
- }
-
- return $list;
-}
-
-function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
- // $file_old - categories previously associated with an item
- // $file_new - new list of categories for an item
-
- if(! intval($uid))
- return false;
-
- if($file_old == $file_new)
- return true;
-
- $saved = get_pconfig($uid,'system','filetags');
- if(strlen($saved)) {
- if($type == 'file') {
- $lbracket = '[';
- $rbracket = ']';
- }
- else {
- $lbracket = '<';
- $rbracket = '>';
- }
-
- $filetags_updated = $saved;
-
- // check for new tags to be added as filetags in pconfig
- $new_tags = array();
- $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
-
- foreach($check_new_tags as $tag) {
- if(! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
- $new_tags[] = $tag;
- }
-
- $filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
-
- // check for deleted tags to be removed from filetags in pconfig
- $deleted_tags = array();
- $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
-
- foreach($check_deleted_tags as $tag) {
- if(! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
- $deleted_tags[] = $tag;
- }
-
- foreach($deleted_tags as $key => $tag) {
- $r = q("select file from item where uid = %d " . file_tag_file_query('item',$tag,$type),
- intval($uid)
- );
-
- if(count($r)) {
- unset($deleted_tags[$key]);
- }
- else {
- $filetags_updated = str_replace($lbracket . file_tag_encode($tag) . $rbracket,'',$filetags_updated);
- }
- }
-
- if($saved != $filetags_updated) {
- set_pconfig($uid,'system','filetags', $filetags_updated);
- }
- return true;
- }
- else
- if(strlen($file_new)) {
- set_pconfig($uid,'system','filetags', $file_new);
- }
- 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($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 .= '<a target="extlink" href="' . $term['url'] . '">' . htmlspecialchars($term['term']) . '</a>';
- else $s .= htmlspecialchars($term['term']);
- return $s;
-}
+ switch($item['resource_type']) {
+ case 'photo':
+ $post_type = t('photo');
+ break;
+ case 'event':
+ $post_type = t('event');
+ break;
+ default:
+ $post_type = t('status');
+ if($item['mid'] != $item['parent_mid'])
+ $post_type = t('comment');
+ break;
+ }
-function file_tag_save_file($uid,$item,$file) {
- $result = false;
- if(! intval($uid))
- return false;
+ if(strlen($item['verb']) && (! activity_compare($item['verb'],ACTIVITY_POST)))
+ $post_type = t('activity');
- $r = q("select file from item where id = %d and uid = %d limit 1",
- intval($item),
- intval($uid)
- );
- if($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) . ']');
- info( t('Item filed') );
- }
- return true;
+ return $post_type;
}
-function file_tag_unsave_file($uid,$item,$file,$cat = false) {
- $result = false;
- if(! intval($uid))
- return false;
-
- if($cat == true)
- $pattern = '<' . file_tag_encode($file) . '>' ;
- else
- $pattern = '[' . file_tag_encode($file) . ']' ;
-
-
- $r = q("select file from item where id = %d and uid = %d limit 1",
- intval($item),
- intval($uid)
- );
- if(! $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 and deleted = 0 " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')),
- intval($uid)
- );
-
- if(! $r) {
- $saved = get_pconfig($uid,'system','filetags');
- set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved));
-
- }
- return true;
-}
function normalise_openid($s) {
return trim(str_replace(array('http://','https://'),array('',''),$s),'/');