]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
make hr bbtag shareable, stray quote in duepuntozero wall_item
[friendica.git] / include / conversation.php
old mode 100644 (file)
new mode 100755 (executable)
index 78b3987..4eff0d0
@@ -116,6 +116,34 @@ function localize_item(&$item){
                $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
                
        }
+       if ($item['verb']=== ACTIVITY_FAVORITE){
+
+               if ($item['object-type']== "")
+                       return;
+
+               $Aname = $item['author-name'];
+               $Alink = $item['author-link'];
+               
+               $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
+               
+               $obj = parse_xml_string($xmlhead.$item['object']);
+               if(strlen($obj->id)) {
+                       $r = q("select * from item where uri = '%s' and uid = %d limit 1",
+                                       dbesc($obj->id),
+                                       intval($item['uid'])
+                       );
+                       if(count($r) && $r[0]['plink']) {
+                               $target = $r[0];
+                               $Bname = $target['author-name'];
+                               $Blink = $target['author-link'];
+                               $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
+                               $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
+                               $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
+                               $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
+
+                       }
+               }
+       }
 
 }
 
@@ -129,13 +157,15 @@ function localize_item(&$item){
  * that are based on unique features of the calling module.
  *
  */
-function conversation(&$a, $items, $mode, $update) {
+function conversation(&$a, $items, $mode, $update, $preview = false) {
 
        require_once('bbcode.php');
 
        $profile_owner = 0;
        $page_writeable      = false;
 
+       $previewing = (($preview) ? ' preview ' : '');
+
        if($mode === 'network') {
                $profile_owner = local_user();
                $page_writeable = true;
@@ -168,6 +198,10 @@ function conversation(&$a, $items, $mode, $update) {
 
        load_contact_links(local_user());
 
+       $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
+       call_hooks('conversation_start',$cb);
+
+       $items = $cb['items'];
 
        $cmnt_tpl    = get_markup_template('comment_item.tpl');
        $tpl         = get_markup_template('wall_item.tpl');
@@ -211,8 +245,8 @@ function conversation(&$a, $items, $mode, $update) {
                                
                        
                                $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
-                               if($author-link && (! $author-name))
-                                       $profile-name = $author-link;
+                               if($item['author-link'] && (! $item['author-name']))
+                                       $profile_name = $item['author-link'];
 
                                $sp = false;
                                $profile_link = best_link_url($item,$sp);
@@ -228,15 +262,10 @@ function conversation(&$a, $items, $mode, $update) {
                                else
                                        $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
 
-                               $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
-                               $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
-                               if($coord) {
-                                       if($location)
-                                               $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
-                                       else
-                                               $location = '<span class="smalltext">' . $coord . '</span>';
-                               }
+                               $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
+                               call_hooks('render_location',$locate);
 
+                               $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
 
                                localize_item($item);
                                if($mode === 'network-new')
@@ -261,7 +290,7 @@ function conversation(&$a, $items, $mode, $update) {
                                $body = prepare_body($item,true);
                                
                                $tmp_item = replace_macros($tpl,array(
-                                       '$id' => $item['item_id'],
+                                       '$id' => (($preview) ? 'P0' : $item['item_id']),
                                        '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
                                        '$profile_url' => $profile_link,
                                        '$item_photo_menu' => item_photo_menu($item),
@@ -287,14 +316,15 @@ function conversation(&$a, $items, $mode, $update) {
                                        '$like' => '',
                                        '$dislike' => '',
                                        '$comment' => '',
-                                       '$conv' => array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context')),
+                                       '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
+                                       '$previewing' => $previewing,
                                        '$wait' => t('Please wait'),
                                ));
 
                                $arr = array('item' => $item, 'output' => $tmp_item);
                                call_hooks('display_item', $arr);
 
-                               $threads[$threadsid]['id'] = $arr[$item['item_id']];
+                               $threads[$threadsid]['id'] = $item['item_id'];
                                $threads[$threadsid]['html'] .= $arr['output'];
 
                        }
@@ -459,7 +489,7 @@ function conversation(&$a, $items, $mode, $update) {
                                }
 
                                $likebuttons = '';
-                               $shareable = ((($profile_owner == local_user()) && ($mode != 'display') && (! $item['private'])) ? true : false);
+                               $shareable = ((($profile_owner == local_user()) &&  (! $item['private'])) ? true : false); //($mode != 'display') &&
 
                                if($page_writeable) {
                                        if($toplevelpost) {
@@ -483,6 +513,7 @@ function conversation(&$a, $items, $mode, $update) {
                                                        '$myphoto' => $a->contact['thumb'],
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
+                                                       '$preview' => t('Preview'),
                                                        '$ww' => (($mode === 'network') ? $commentww : '')
                                                ));
                                        }
@@ -533,6 +564,10 @@ function conversation(&$a, $items, $mode, $update) {
 
                                $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
 
+                               if($item['author-link'] && (! $item['author-name']))
+                                       $profile_name = $item['author-link'];
+
+
                                $sp = false;
                                $profile_link = best_link_url($item,$sp);
                                if($sp)
@@ -554,16 +589,10 @@ function conversation(&$a, $items, $mode, $update) {
                                $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
                                $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
 
-                               $location = (($item['location']) ? '<a target="map" title="' . $item['location'] 
-                                       . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
-                               $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] 
-                                       . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
-                               if($coord) {
-                                       if($location)
-                                               $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
-                                       else
-                                               $location = '<span class="smalltext">' . $coord . '</span>';
-                               }
+                               $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
+                               call_hooks('render_location',$locate);
+
+                               $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
 
                                $indent = (($toplevelpost) ? '' : ' comment');
 
@@ -580,7 +609,6 @@ function conversation(&$a, $items, $mode, $update) {
                                        if ($tag!="") $tags[] = bbcode($tag);
                                }
 
-
                                // Build the HTML
 
                                $body = prepare_body($item,true);
@@ -619,6 +647,7 @@ function conversation(&$a, $items, $mode, $update) {
                                        '$like' => $like,
                                        '$dislike' => $dislike,
                                        '$comment' => $comment,
+                                       '$previewing' => $previewing,
                                        '$wait' => t('Please wait'),
 
                                ));
@@ -720,10 +749,12 @@ function item_photo_menu($item){
        );
        
        
-       $args = array($item, &$menu);
+       $args = array('item' => $item, 'menu' => $menu);
        
        call_hooks('item_photo_menu', $args);
-       
+
+       $menu = $args['menu'];  
+
        $o = "";
        foreach($menu as $k=>$v){
                if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
@@ -789,94 +820,199 @@ function format_like($cnt,$arr,$type,$id) {
 }}
 
 
-function status_editor($a,$x, $notes_cid = 0) {
+function status_editor($a,$x, $notes_cid = 0, $popup=false) {
 
        $o = '';
                
        $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
 
-               $tpl = get_markup_template('jot-header.tpl');
+       $plaintext = false;
+       if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
+               $plaintext = true;
+
+       $tpl = get_markup_template('jot-header.tpl');
        
-               $a->page['htmlhead'] .= replace_macros($tpl, array(
-                       '$newpost' => 'true',
-                       '$baseurl' => $a->get_baseurl(),
-                       '$geotag' => $geotag,
-                       '$nickname' => $x['nickname'],
-                       '$ispublic' => t('Visible to <strong>everybody</strong>'),
-                       '$linkurl' => t('Please enter a link URL:'),
-                       '$vidurl' => t("Please enter a video link/URL:"),
-                       '$audurl' => t("Please enter an audio link/URL:"),
-                       '$term' => t('Tag term:'),
-                       '$whereareu' => t('Where are you right now?'),
-                       '$title' => t('Enter a title for this item') 
-               ));
-
-
-               $tpl = get_markup_template("jot.tpl");
+       $a->page['htmlhead'] .= replace_macros($tpl, array(
+               '$newpost' => 'true',
+               '$baseurl' => $a->get_baseurl(),
+               '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
+               '$geotag' => $geotag,
+               '$nickname' => $x['nickname'],
+               '$ispublic' => t('Visible to <strong>everybody</strong>'),
+               '$linkurl' => t('Please enter a link URL:'),
+               '$vidurl' => t("Please enter a video link/URL:"),
+               '$audurl' => t("Please enter an audio link/URL:"),
+               '$term' => t('Tag term:'),
+               '$whereareu' => t('Where are you right now?'),
+               '$title' => t('Enter a title for this item') 
+       ));
+
+
+       $tpl = get_markup_template("jot.tpl");
                
-               $jotplugins = '';
-               $jotnets = '';
+       $jotplugins = '';
+       $jotnets = '';
+
+       $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
+
+       $mail_enabled = false;
+       $pubmail_enabled = false;
+
+       if(($x['is_owner']) && (! $mail_disabled)) {
+               $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
+                       intval(local_user())
+               );
+               if(count($r)) {
+                       $mail_enabled = true;
+                       if(intval($r[0]['pubmail']))
+                               $pubmail_enabled = true;
+               }
+       }
 
-               $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
+       if($mail_enabled) {
+               $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
+               $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
+       }
 
-               $mail_enabled = false;
-               $pubmail_enabled = false;
+       call_hooks('jot_tool', $jotplugins);
+       call_hooks('jot_networks', $jotnets);
+
+       if($notes_cid)
+               $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
+
+       $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
+
+       $o .= replace_macros($tpl,array(
+               '$return_path' => $a->cmd,
+               '$action' =>  $a->get_baseurl().'/item',
+               '$share' => (($x['button']) ? $x['button'] : t('Share')),
+               '$upload' => t('Upload photo'),
+               '$shortupload' => t('upload photo'),
+               '$attach' => t('Attach file'),
+               '$shortattach' => t('attach file'),
+               '$weblink' => t('Insert web link'),
+               '$shortweblink' => t('web link'),
+               '$video' => t('Insert video link'),
+               '$shortvideo' => t('video link'),
+               '$audio' => t('Insert audio link'),
+               '$shortaudio' => t('audio link'),
+               '$setloc' => t('Set your location'),
+               '$shortsetloc' => t('set location'),
+               '$noloc' => t('Clear browser location'),
+               '$shortnoloc' => t('clear location'),
+               '$title' => "",
+               '$placeholdertitle' => t('Set title'),
+               '$wait' => t('Please wait'),
+               '$permset' => t('Permission settings'),
+               '$shortpermset' => t('permissions'),
+               '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
+               '$content' => '',
+               '$post_id' => '',
+               '$baseurl' => $a->get_baseurl(),
+               '$defloc' => $x['default_location'],
+               '$visitor' => $x['visitor'],
+               '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
+               '$emailcc' => t('CC: email addresses'),
+               '$public' => t('Public post'),
+               '$jotnets' => $jotnets,
+               '$emtitle' => t('Example: bob@example.com, mary@example.com'),
+               '$lockstate' => $x['lockstate'],
+               '$acl' => $x['acl'],
+               '$bang' => $x['bang'],
+               '$profile_uid' => $x['profile_uid'],
+               '$preview' => t('Preview'),
+       ));
 
-               if(($x['is_owner']) && (! $mail_disabled)) {
-                       $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
-                               intval(local_user())
-                       );
-                       if(count($r)) {
-                               $mail_enabled = true;
-                               if(intval($r[0]['pubmail']))
-                                       $pubmail_enabled = true;
-                       }
+
+       if ($popup==true){
+               $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
+               
+       }
+
+       return $o;
+}
+
+
+function conv_sort($arr,$order) {
+
+       if((!(is_array($arr) && count($arr))))
+               return array();
+
+       $parents = array();
+
+       foreach($arr as $x)
+               if($x['id'] == $x['parent'])
+                               $parents[] = $x;
+
+       if(stristr($order,'created'))
+               usort($parents,'sort_thr_created');
+       elseif(stristr($order,'commented'))
+               usort($parents,'sort_thr_commented');
+
+       if(count($parents))
+               foreach($parents as $x) 
+                       $x['children'] = array();
+
+       foreach($arr as $x) {
+               if($x['id'] != $x['parent']) {
+                       $p = find_thread_parent_index($parents,$x);
+                       if($p !== false)
+                               $parents[$p]['children'][] = $x;
                }
+       }
+       if(count($parents)) {
+               foreach($parents as $k => $v) {
+                       if(count($parents[$k]['children'])) {
+                               $y = $parents[$k]['children'];
+                               usort($y,'sort_thr_created_rev');
+                               $parents[$k]['children'] = $y;
+                       }
+               }       
+       }
 
-               if($mail_enabled) {
-              $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
-                       $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> '
-               . t("Post to Email") . '</div>';
+       $ret = array();
+       if(count($parents)) {
+               foreach($parents as $x) {
+                       $ret[] = $x;
+                       if(count($x['children']))
+                               foreach($x['children'] as $y)
+                                       $ret[] = $y;
                }
+       }
 
-               call_hooks('jot_tool', $jotplugins);
-               call_hooks('jot_networks', $jotnets);
-
-               if($notes_cid)
-                       $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
-
-               $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
-
-               $o .= replace_macros($tpl,array(
-                       '$return_path' => $a->cmd,
-                       '$action' => 'item',
-                       '$share' => (($x['button']) ? $x['button'] : t('Share')),
-                       '$upload' => t('Upload photo'),
-                       '$attach' => t('Attach file'),
-                       '$weblink' => t('Insert web link'),
-                       '$video' => t('Insert video link'),
-                       '$audio' => t('Insert audio link'),
-                       '$setloc' => t('Set your location'),
-                       '$noloc' => t('Clear browser location'),
-                       '$title' => t('Set title'),
-                       '$wait' => t('Please wait'),
-                       '$permset' => t('Permission settings'),
-                       '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
-                       '$content' => '',
-                       '$post_id' => '',
-                       '$baseurl' => $a->get_baseurl(),
-                       '$defloc' => $x['default_location'],
-                       '$visitor' => $x['visitor'],
-                       '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
-                       '$emailcc' => t('CC: email addresses'),
-                       '$public' => t('Public post'),
-                       '$jotnets' => $jotnets,
-                       '$emtitle' => t('Example: bob@example.com, mary@example.com'),
-                       '$lockstate' => $x['lockstate'],
-                       '$acl' => $x['acl'],
-                       '$bang' => $x['bang'],
-                       '$profile_uid' => $x['profile_uid'],
-               ));
+       return $ret;
+}
 
-       return $o;
+
+function sort_thr_created($a,$b) {
+       return strcmp($b['created'],$a['created']);
+}
+
+function sort_thr_created_rev($a,$b) {
+       return strcmp($a['created'],$b['created']);
 }
+
+function sort_thr_commented($a,$b) {
+       return strcmp($b['commented'],$a['commented']);
+}
+
+function find_thread_parent_index($arr,$x) {
+       foreach($arr as $k => $v)
+               if($v['id'] == $x['parent'])
+                       return $k;
+       return false;
+}
+
+function render_location_google($item) {
+       $location = '';
+       $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
+       $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
+       if($coord) {
+               if($location)
+                       $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
+               else
+                       $location = '<span class="smalltext">' . $coord . '</span>';
+       }
+       return $location;
+}
+