Beispiel #1
0
function status_editor($a, $x, $notes_cid = 0, $popup = false)
{
    $o = '';
    $geotag = $x['allow_location'] ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '';
    /*	$plaintext = false;
    	if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
    		$plaintext = true;*/
    $plaintext = true;
    if (local_user() && feature_enabled(local_user(), 'richtext')) {
        $plaintext = false;
    }
    $tpl = get_markup_template('jot-header.tpl');
    $a->page['htmlhead'] .= replace_macros($tpl, array('$newpost' => 'true', '$baseurl' => $a->get_baseurl(true), '$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:'), '$fileas' => t('Save to Folder:'), '$whereareu' => t('Where are you right now?'), '$delitems' => t('Delete item(s)?')));
    $tpl = get_markup_template('jot-end.tpl');
    $a->page['end'] .= replace_macros($tpl, array('$newpost' => 'true', '$baseurl' => $a->get_baseurl(true), '$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:'), '$fileas' => t('Save to Folder:'), '$whereareu' => t('Where are you right now?')));
    $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;
            }
        }
    }
    if (!$a->user['hidewall']) {
        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>';
        }
        call_hooks('jot_networks', $jotnets);
    } else {
        $jotnets .= sprintf(t('Connectors disabled, since "%s" is enabled.'), t('Hide your profile details from unknown viewers?'));
    }
    call_hooks('jot_tool', $jotplugins);
    if ($notes_cid) {
        $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid . '" />';
    }
    // Private/public post links for the non-JS ACL form
    $private_post = 1;
    if ($_REQUEST['public']) {
        $private_post = 0;
    }
    $query_str = $a->query_string;
    if (strpos($query_str, 'public=1') !== false) {
        $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
    }
    // I think $a->query_string may never have ? in it, but I could be wrong
    // It looks like it's from the index.php?q=[etc] rewrite that the web
    // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
    if (strpos($query_str, '?') === false) {
        $public_post_link = '?public=1';
    } else {
        $public_post_link = '&public=1';
    }
    //	$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
    $tpl = get_markup_template("jot.tpl");
    $o .= replace_macros($tpl, array('$return_path' => $query_str, '$action' => $a->get_baseurl(true) . '/item', '$share' => x($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'), '$category' => "", '$placeholdercategory' => feature_enabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : '', '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$shortpermset' => t('permissions'), '$ptyp' => $notes_cid ? 'note' : 'wall', '$content' => '', '$post_id' => '', '$baseurl' => $a->get_baseurl(true), '$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'], '$bang' => $x['bang'], '$profile_uid' => $x['profile_uid'], '$preview' => feature_enabled($x['profile_uid'], 'preview') ? t('Preview') : '', '$jotplugins' => $jotplugins, '$sourceapp' => t($a->sourcename), '$cancel' => t('Cancel'), '$rand_num' => random_digits(12), '$acl' => $x['acl'], '$acl_data' => $x['acl_data'], '$group_perms' => t('Post to Groups'), '$contact_perms' => t('Post to Contacts'), '$private' => t('Private post'), '$is_private' => $private_post, '$public_link' => $public_post_link));
    if ($popup == true) {
        $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
    }
    return $o;
}
Beispiel #2
0
echo "<div id=\"comment_block\">\n";
?>
	<?php 
echo "<div id=\"showhideform\"><strong> " . __('Post a Comment') . "</strong>:";
?>
	<span class="comment_toggle"> 
	[&nbsp;
	<?php 
echo "<a href=\"javascript:toggle_comment()\"><span id=\"showlink\">" . __('Show Form') . "</span><span id=\"hidelink\" style=\"display:none;\">" . __('Hide Form') . "</span></a>";
?>
	&nbsp;]
	</span>
	</div>
	
	<div id="comment_form" style="display: none;">
<?php 
$this->form_start($ThisUrl, "post", NULL);
$this->input("text", "commentname", $username, __('Name:'), NULL, __('Enter your name.'));
$this->input("checkbox", "savecommentname", "1", __('Remember Name:'), "yes", __('Should the browser remember your name?'));
$magic_number = random_digits(4);
//temporary. should generate an image instead
echo "<div class=\"row\"><div class=\"control\">{$magic_number}</div></div>\n";
$this->input("hidden", "commentkolacek", md5($magic_number), NULL, NULL, NULL);
$this->input("text", "commentspamcheck", "", __('Retype PIN Above:'), NULL, __('Enter the number shown above.'));
$this->input("textarea", "commentdata", "", __('Comment') . " :", NULL, __('Allowed HTML tags: a,b,i,ul,li,blockquote,br.'));
$this->input("submit", "", __('Send'), NULL, NULL, NULL);
$this->form_end();
?>
	</div>
</div>
Beispiel #3
0
 /**
  * Get the comment box
  *
  * Returns:
  *      _ The comment box string (empty if no comment box)
  *      _ false on failure
  */
 private function get_comment_box($indent)
 {
     $a = $this->get_app();
     if (!$this->is_toplevel() && !(get_config('system', 'thread_allow') && $a->theme_thread_allow)) {
         return '';
     }
     $comment_box = '';
     $conv = $this->get_conversation();
     $template = get_markup_template($this->get_comment_box_template());
     $ww = '';
     if ($conv->get_mode() === 'network' && $this->is_wall_to_wall()) {
         $ww = 'ww';
     }
     if ($conv->is_writable() && $this->is_writable()) {
         $qc = $qcomment = null;
         /*
          * Hmmm, code depending on the presence of a particular plugin?
          * This should be better if done by a hook
          */
         if (in_array('qcomment', $a->plugins)) {
             $qc = local_user() ? get_pconfig(local_user(), 'qcomment', 'words') : null;
             $qcomment = $qc ? explode("\n", $qc) : null;
         }
         $comment_box = replace_macros($template, array('$return_path' => $a->query_string, '$threaded' => $this->is_threaded(), '$jsreload' => '', '$type' => $conv->get_mode() === 'profile' ? 'wall-comment' : 'net-comment', '$id' => $this->get_id(), '$parent' => $this->get_id(), '$qcomment' => $qcomment, '$profile_uid' => $conv->get_profile_owner(), '$mylink' => $a->contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $a->contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$edbold' => t('Bold'), '$editalic' => t('Italic'), '$eduline' => t('Underline'), '$edquote' => t('Quote'), '$edcode' => t('Code'), '$edimg' => t('Image'), '$edurl' => t('Link'), '$edvideo' => t('Video'), '$preview' => feature_enabled($conv->get_profile_owner(), 'preview') ? t('Preview') : '', '$indent' => $indent, '$sourceapp' => t($a->sourcename), '$ww' => $conv->get_mode() === 'network' ? $ww : '', '$rand_num' => random_digits(12)));
     }
     return $comment_box;
 }
Beispiel #4
0
function editpost_content(&$a)
{
    $o = '';
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $post_id = $a->argc > 1 ? intval($a->argv[1]) : 0;
    if (!$post_id) {
        notice(t('Item not found') . EOL);
        return;
    }
    $itm = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($post_id), intval(local_user()));
    if (!count($itm)) {
        notice(t('Item not found') . EOL);
        return;
    }
    /*	$plaintext = false;
    	if( local_user() && intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
    		$plaintext = true;*/
    $plaintext = true;
    if (local_user() && feature_enabled(local_user(), 'richtext')) {
        $plaintext = false;
    }
    $o .= '<h2>' . t('Edit post') . '</h2>';
    $tpl = get_markup_template('jot-header.tpl');
    $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$ispublic' => '&nbsp;', '$geotag' => $geotag, '$nickname' => $a->user['nickname']));
    $tpl = get_markup_template('jot-end.tpl');
    $a->page['end'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$ispublic' => '&nbsp;', '$geotag' => $geotag, '$nickname' => $a->user['nickname']));
    $tpl = get_markup_template("jot.tpl");
    if ($group || is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) {
        $lockstate = 'lock';
    } else {
        $lockstate = 'unlock';
    }
    $celeb = $a->user['page-flags'] == PAGE_SOAPBOX || $a->user['page-flags'] == PAGE_COMMUNITY ? true : false;
    $jotplugins = '';
    $jotnets = '';
    $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1;
    $mail_enabled = false;
    $pubmail_enabled = false;
    if (!$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;
            }
        }
    }
    // I don't think there's any need for the $jotnets when editing the post,
    // and including them makes it difficult for the JS-free theme, so let's
    // disable them
    /*	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>';
    	}*/
    call_hooks('jot_tool', $jotplugins);
    //call_hooks('jot_networks', $jotnets);
    //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
    $o .= replace_macros($tpl, array('$return_path' => $_SESSION['return_url'], '$action' => 'item', '$share' => t('Save'), '$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'), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$baseurl' => $a->get_baseurl(), '$defloc' => $a->user['default-location'], '$visitor' => 'none', '$pvisit' => 'none', '$emailcc' => t('CC: email addresses'), '$public' => t('Public post'), '$jotnets' => $jotnets, '$title' => htmlspecialchars($itm[0]['title']), '$placeholdertitle' => t('Set title'), '$category' => file_tag_file_to_list($itm[0]['file'], 'category'), '$placeholdercategory' => feature_enabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : '', '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', '$bang' => $group ? '!' : '', '$profile_uid' => $_SESSION['uid'], '$preview' => t('Preview'), '$jotplugins' => $jotplugins, '$sourceapp' => t($a->sourcename), '$cancel' => t('Cancel'), '$rand_num' => random_digits(12)));
    return $o;
}
Beispiel #5
0
function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/upload
    // photos/name/upload/xxxxx (xxxxx is album name)
    // photos/name/album/xxxxx
    // photos/name/album/xxxxx/edit
    // photos/name/image/xxxxx
    // photos/name/image/xxxxx/edit
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'user')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $phototypes = Photo::supportedTypes();
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    if ($a->argc > 3) {
        $datatype = $a->argv[2];
        $datum = $a->argv[3];
    } elseif ($a->argc > 2 && $a->argv[2] === 'upload') {
        $datatype = 'upload';
    } else {
        $datatype = 'summary';
    }
    if ($a->argc > 4) {
        $cmd = $a->argv[4];
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $contact = null;
    $remote_contact = false;
    $contact_id = 0;
    $owner_uid = $a->data['user']['uid'];
    $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY ? true : false;
    if (local_user() && local_user() == $owner_uid) {
        $can_post = true;
    } else {
        if ($community_page && remote_user()) {
            if (is_array($_SESSION['remote'])) {
                foreach ($_SESSION['remote'] as $v) {
                    if ($v['uid'] == $owner_uid) {
                        $contact_id = $v['cid'];
                        break;
                    }
                }
            }
            if ($contact_id) {
                $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid));
                if (count($r)) {
                    $can_post = true;
                    $contact = $r[0];
                    $remote_contact = true;
                    $visitor = $cid;
                }
            }
        }
    }
    // perhaps they're visiting - but not a community page, so they wouldn't have write access
    if (remote_user() && !$visitor) {
        $contact_id = 0;
        if (is_array($_SESSION['remote'])) {
            foreach ($_SESSION['remote'] as $v) {
                if ($v['uid'] == $owner_uid) {
                    $contact_id = $v['cid'];
                    break;
                }
            }
        }
        if ($contact_id) {
            $groups = init_groups_visitor($contact_id);
            $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid));
            if (count($r)) {
                $contact = $r[0];
                $remote_contact = true;
            }
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    if ($a->data['user']['hidewall'] && local_user() != $owner_uid && !$remote_contact) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
    $o = "";
    // tabs
    $_is_owner = local_user() && local_user() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['user']['nickname']);
    //
    // dispatch request
    //
    if ($datatype === 'upload') {
        if (!$can_post) {
            notice(t('Permission denied.'));
            return;
        }
        $selname = $datum ? hex2bin($datum) : '';
        $albumselect = '';
        $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
        if (count($a->data['albums'])) {
            foreach ($a->data['albums'] as $album) {
                if ($album['album'] === '' || $album['album'] === 'Contact Photos' || $album['album'] === t('Contact Photos')) {
                    continue;
                }
                $selected = $selname === $album['album'] ? ' selected="selected" ' : '';
                $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
            }
        }
        $celeb = $a->user['page-flags'] == PAGE_SOAPBOX || $a->user['page-flags'] == PAGE_COMMUNITY ? true : false;
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
        $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array('$submit' => t('Submit')));
        $usage_message = '';
        $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit');
        if ($limit !== false) {
            $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", intval($a->data['user']['uid']));
            $usage_message = sprintf(t("You have used %1\$.2f Mbytes of %2\$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000);
        }
        // Private/public post links for the non-JS ACL form
        $private_post = 1;
        if ($_REQUEST['public']) {
            $private_post = 0;
        }
        $query_str = $a->query_string;
        if (strpos($query_str, 'public=1') !== false) {
            $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
        }
        // I think $a->query_string may never have ? in it, but I could be wrong
        // It looks like it's from the index.php?q=[etc] rewrite that the web
        // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
        if (strpos($query_str, '?') === false) {
            $public_post_link = '?public=1';
        } else {
            $public_post_link = '&public=1';
        }
        $tpl = get_markup_template('photos_upload.tpl');
        if ($a->theme['template_engine'] === 'internal') {
            $albumselect_e = template_escape($albumselect);
            $aclselect_e = $visitor ? '' : template_escape(populate_acl($a->user, $celeb));
        } else {
            $albumselect_e = $albumselect;
            $aclselect_e = $visitor ? '' : populate_acl($a->user, $celeb);
        }
        $o .= replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['user']['nickname'], '$newalbum' => t('New album name: '), '$existalbumtext' => t('or existing album name: '), '$nosharetext' => t('Do not show a status post for this upload'), '$albumselect' => $albumselect_e, '$permissions' => t('Permissions'), '$aclselect' => $aclselect_e, '$alt_uploader' => $ret['addon_text'], '$default_upload_box' => $ret['default_upload'] ? $default_upload_box : '', '$default_upload_submit' => $ret['default_upload'] ? $default_upload_submit : '', '$uploadurl' => $ret['post_url'], '$acl_data' => construct_acl_data($a, $a->user), '$group_perms' => t('Show to Groups'), '$contact_perms' => t('Show to Contacts'), '$private' => t('Private Photo'), '$public' => t('Public Photo'), '$is_private' => $private_post, '$return_path' => $query_str, '$public_link' => $public_post_link));
        return $o;
    }
    if ($datatype === 'album') {
        $album = hex2bin($datum);
        $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 {$sql_extra} GROUP BY `resource-id`", intval($owner_uid), dbesc($album));
        if (count($r)) {
            $a->set_pager_total(count($r));
            $a->set_pager_itemspage(20);
        }
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 {$sql_extra} GROUP BY `resource-id` ORDER BY `created` {$order} LIMIT %d , %d", intval($owner_uid), dbesc($album), intval($a->pager['start']), intval($a->pager['itemspage']));
        $o .= '<h3 id="photo-album-title">' . $album . '</h3>';
        if ($cmd === 'edit') {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $edit_tpl = get_markup_template('album_edit.tpl');
                    if ($a->theme['template_engine'] === 'internal') {
                        $album_e = template_escape($album);
                    } else {
                        $album_e = $album;
                    }
                    $o .= replace_macros($edit_tpl, array('$nametext' => t('New album name: '), '$nickname' => $a->data['user']['nickname'], '$album' => $album_e, '$hexalbum' => bin2hex($album), '$submit' => t('Submit'), '$dropsubmit' => t('Delete Album')));
                }
            }
        } else {
            if ($album !== t('Profile Photos') && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
                if ($can_post) {
                    $o .= '<div id="album-edit-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">' . t('Edit Album') . '</a></div>';
                }
            }
        }
        if ($_GET['order'] === 'posted') {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>';
        } else {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>';
        }
        if ($can_post) {
            $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
        }
        $tpl = get_markup_template('photo_album.tpl');
        if (count($r)) {
            $twist = 'rotright';
        }
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->theme['template_engine'] === 'internal') {
                $imgalt_e = template_escape($rr['filename']);
                $desc_e = template_escape($rr['desc']);
            } else {
                $imgalt_e = $rr['filename'];
                $desc_e = $rr['desc'];
            }
            $o .= replace_macros($tpl, array('$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2, 4), '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : ''), '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' . $ext, '$imgalt' => $imgalt_e, '$desc' => $desc_e));
        }
        $o .= '<div id="photo-album-end"></div>';
        $o .= paginate($a);
        return $o;
    }
    if ($datatype === 'image') {
        //$o = '';
        // fetch image, item containing image, then comments
        $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' \n\t\t\t{$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum));
        if (!count($ph)) {
            $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'\n\t\t\t\tLIMIT 1", intval($owner_uid), dbesc($datum));
            if (count($ph)) {
                notice(t('Permission denied. Access to this item may be restricted.'));
            } else {
                notice(t('Photo not available') . EOL);
            }
            return;
        }
        $prevlink = '';
        $nextlink = '';
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0\n\t\t\t{$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid));
        if (count($prvnxt)) {
            for ($z = 0; $z < count($prvnxt); $z++) {
                if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
                    $prv = $z - 1;
                    $nxt = $z + 1;
                    if ($prv < 0) {
                        $prv = count($prvnxt) - 1;
                    }
                    if ($nxt >= count($prvnxt)) {
                        $nxt = 0;
                    }
                    break;
                }
            }
            $edit_suffix = $cmd === 'edit' && $can_post ? '/edit' : '';
            $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
            $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
        }
        if (count($ph) == 1) {
            $hires = $lores = $ph[0];
        }
        if (count($ph) > 1) {
            if ($ph[1]['scale'] == 2) {
                // original is 640 or less, we can display it directly
                $hires = $lores = $ph[0];
            } else {
                $hires = $ph[0];
                $lores = $ph[1];
            }
        }
        $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
        $tools = Null;
        $lock = Null;
        if ($can_post && $ph[0]['uid'] == $owner_uid) {
            $tools = array('edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . ($cmd === 'edit' ? '' : '/edit'), $cmd === 'edit' ? t('View photo') : t('Edit photo')), 'profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource-id'], t('Use as profile photo')));
            // lock
            $lock = $ph[0]['uid'] == local_user() && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) ? t('Private Message') : Null;
        }
        if ($cmd === 'edit') {
            $tpl = get_markup_template('photo_edit_head.tpl');
            $a->page['htmlhead'] .= replace_macros($tpl, array('$prevlink' => $prevlink, '$nextlink' => $nextlink));
        }
        if ($prevlink) {
            $prevlink = array($prevlink, '<div class="icon prev"></div>');
        }
        $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'), 'height' => $hires['height'], 'width' => $hires['width'], 'album' => $hires['album'], 'filename' => $hires['filename']);
        if ($nextlink) {
            $nextlink = array($nextlink, '<div class="icon next"></div>');
        }
        // Do we have an item for this photo?
        // FIXME! - replace following code to display the conversation with our normal
        // conversation functions so that it works correctly and tracks changes
        // in the evolving conversation code.
        // The difference is that we won't be displaying the conversation head item
        // as a "post" but displaying instead the photo it is linked to
        $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' {$sql_extra} LIMIT 1", dbesc($datum));
        if (count($linked_items)) {
            $link_item = $linked_items[0];
            $r = q("SELECT COUNT(*) AS `total`\n\t\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tAND `item`.`uid` = %d\n\t\t\t\t{$sql_extra} ", dbesc($link_item['uri']), dbesc($link_item['uri']), intval($link_item['uid']));
            if (count($r)) {
                $a->set_pager_total($r[0]['total']);
            }
            $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,\n\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,\n\t\t\t\t`contact`.`rel`, `contact`.`thumb`, `contact`.`self`,\n\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tAND `item`.`uid` = %d\n\t\t\t\t{$sql_extra}\n\t\t\t\tORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ", dbesc($link_item['uri']), dbesc($link_item['uri']), intval($link_item['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
            if (local_user() && local_user() == $link_item['uid']) {
                q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d", intval($link_item['parent']), intval(local_user()));
                update_thread($link_item['parent']);
            }
        }
        $tags = Null;
        if (count($linked_items) && strlen($link_item['tag'])) {
            $arr = explode(',', $link_item['tag']);
            // parse tags and add links
            $tag_str = '';
            foreach ($arr as $t) {
                if (strlen($tag_str)) {
                    $tag_str .= ', ';
                }
                $tag_str .= bbcode($t);
            }
            $tags = array(t('Tags: '), $tag_str);
            if ($cmd === 'edit') {
                $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
                $tags[] = t('[Remove any tag]');
            }
        }
        $edit = Null;
        if ($cmd === 'edit' && $can_post) {
            $edit_tpl = get_markup_template('photo_edit.tpl');
            // Private/public post links for the non-JS ACL form
            $private_post = 1;
            if ($_REQUEST['public']) {
                $private_post = 0;
            }
            $query_str = $a->query_string;
            if (strpos($query_str, 'public=1') !== false) {
                $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
            }
            // I think $a->query_string may never have ? in it, but I could be wrong
            // It looks like it's from the index.php?q=[etc] rewrite that the web
            // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
            if (strpos($query_str, '?') === false) {
                $public_post_link = '?public=1';
            } else {
                $public_post_link = '&public=1';
            }
            if ($a->theme['template_engine'] === 'internal') {
                $album_e = template_escape($ph[0]['album']);
                $caption_e = template_escape($ph[0]['desc']);
                $aclselect_e = template_escape(populate_acl($ph[0]));
            } else {
                $album_e = $ph[0]['album'];
                $caption_e = $ph[0]['desc'];
                $aclselect_e = populate_acl($ph[0]);
            }
            $edit = replace_macros($edit_tpl, array('$id' => $ph[0]['id'], '$rotatecw' => t('Rotate CW (right)'), '$rotateccw' => t('Rotate CCW (left)'), '$album' => $album_e, '$newalbum' => t('New album name'), '$nickname' => $a->data['user']['nickname'], '$resource_id' => $ph[0]['resource-id'], '$capt_label' => t('Caption'), '$caption' => $caption_e, '$tag_label' => t('Add a Tag'), '$tags' => $link_item['tag'], '$permissions' => t('Permissions'), '$aclselect' => $aclselect_e, '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), '$item_id' => count($linked_items) ? $link_item['id'] : 0, '$submit' => t('Submit'), '$delete' => t('Delete Photo'), '$acl_data' => construct_acl_data($a, $ph[0]), '$group_perms' => t('Show to Groups'), '$contact_perms' => t('Show to Contacts'), '$private' => t('Private photo'), '$public' => t('Public photo'), '$is_private' => $private_post, '$return_path' => $query_str, '$public_link' => $public_post_link));
        }
        if (count($linked_items)) {
            $cmnt_tpl = get_markup_template('comment_item.tpl');
            $tpl = get_markup_template('photo_item.tpl');
            $return_url = $a->cmd;
            $like_tpl = get_markup_template('like_noshare.tpl');
            $likebuttons = '';
            if ($can_post || can_write_wall($a, $owner_uid)) {
                $likebuttons = replace_macros($like_tpl, array('$id' => $link_item['id'], '$likethis' => t("I like this (toggle)"), '$nolike' => feature_enabled(local_user(), 'dislike') ? t("I don't like this (toggle)") : '', '$share' => t('Share'), '$wait' => t('Please wait'), '$return_path' => $a->query_string));
            }
            $comments = '';
            if (!count($r)) {
                if ($can_post || can_write_wall($a, $owner_uid)) {
                    if ($link_item['last-child']) {
                        $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => '', '$rand_num' => random_digits(12)));
                    }
                }
            }
            $alike = array();
            $dlike = array();
            $like = '';
            $dislike = '';
            // display comments
            if (count($r)) {
                foreach ($r as $item) {
                    like_puller($a, $item, $alike, 'like');
                    like_puller($a, $item, $dlike, 'dislike');
                }
                $like = isset($alike[$link_item['id']]) ? format_like($alike[$link_item['id']], $alike[$link_item['id'] . '-l'], 'like', $link_item['id']) : '';
                $dislike = isset($dlike[$link_item['id']]) ? format_like($dlike[$link_item['id']], $dlike[$link_item['id'] . '-l'], 'dislike', $link_item['id']) : '';
                if ($can_post || can_write_wall($a, $owner_uid)) {
                    if ($link_item['last-child']) {
                        $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => '', '$rand_num' => random_digits(12)));
                    }
                }
                foreach ($r as $item) {
                    $comment = '';
                    $template = $tpl;
                    $sparkle = '';
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                    if (local_user() && $item['contact-uid'] == local_user() && $item['network'] == 'dfrn' && !$item['self']) {
                        $profile_url = $redirect_url;
                        $sparkle = ' sparkle';
                    } else {
                        $profile_url = $item['url'];
                        $sparkle = '';
                    }
                    $diff_author = $item['url'] !== $item['author-link'] ? true : false;
                    $profile_name = strlen($item['author-name']) && $diff_author ? $item['author-name'] : $item['name'];
                    $profile_avatar = strlen($item['author-avatar']) && $diff_author ? $item['author-avatar'] : $item['thumb'];
                    $profile_link = $profile_url;
                    $dropping = $item['contact-id'] == $contact_id || $item['uid'] == local_user();
                    $drop = array('dropping' => $dropping, 'pagedrop' => false, 'select' => t('Select'), 'delete' => t('Delete'));
                    if ($a->theme['template_engine'] === 'internal') {
                        $name_e = template_escape($profile_name);
                        $title_e = template_escape($item['title']);
                        $body_e = template_escape(bbcode($item['body']));
                    } else {
                        $name_e = $profile_name;
                        $title_e = $item['title'];
                        $body_e = bbcode($item['body']);
                    }
                    $comments .= replace_macros($template, array('$id' => $item['item_id'], '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['item_id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                    if ($can_post || can_write_wall($a, $owner_uid)) {
                        if ($item['last-child']) {
                            $comments .= replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $item['item_id'], '$parent' => $item['parent'], '$profile_uid' => $owner_uid, '$mylink' => $contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => '', '$rand_num' => random_digits(12)));
                        }
                    }
                }
            }
            $paginate = paginate($a);
        }
        $photo_tpl = get_markup_template('photo_view.tpl');
        if ($a->theme['template_engine'] === 'internal') {
            $album_e = array($album_link, template_escape($ph[0]['album']));
            $tags_e = template_escape($tags);
            $like_e = template_escape($like);
            $dislike_e = template_escape($dislike);
        } else {
            $album_e = array($album_link, $ph[0]['album']);
            $tags_e = $tags;
            $like_e = $like;
            $dislike_e = $dislike;
        }
        $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lock, '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['desc'], '$tags' => $tags_e, '$edit' => $edit, '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dikslike_e, '$comments' => $comments, '$paginate' => $paginate));
        $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
        $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
        return $o;
    }
    // Default - show recent photos with upload link (if applicable)
    //$o = '';
    $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\t{$sql_extra} GROUP BY `resource-id`", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc(t('Contact Photos')));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(20);
    }
    $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`\n\t\tWHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'  \n\t\t{$sql_extra} GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['user']['uid']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval($a->pager['start']), intval($a->pager['itemspage']));
    $photos = array();
    if (count($r)) {
        $twist = 'rotright';
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->theme['template_engine'] === 'internal') {
                $alt_e = template_escape($rr['filename']);
                $name_e = template_escape($rr['album']);
            } else {
                $alt_e = $rr['filename'];
                $name_e = $rr['album'];
            }
            $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
        }
    }
    $tpl = get_markup_template('photos_recent.tpl');
    $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'), '$photos' => $photos));
    $o .= paginate($a);
    return $o;
}
Beispiel #6
0
function render_content(&$a, $items, $mode, $update, $preview = false)
{
    require_once 'include/bbcode.php';
    require_once 'mod/proxy.php';
    $ssl_state = local_user() ? true : false;
    $profile_owner = 0;
    $page_writeable = false;
    $previewing = $preview ? ' preview ' : '';
    if ($mode === 'network') {
        $profile_owner = local_user();
        $page_writeable = true;
    }
    if ($mode === 'profile') {
        $profile_owner = $a->profile['profile_uid'];
        $page_writeable = can_write_wall($a, $profile_owner);
    }
    if ($mode === 'notes') {
        $profile_owner = local_user();
        $page_writeable = true;
    }
    if ($mode === 'display') {
        $profile_owner = $a->profile['uid'];
        $page_writeable = can_write_wall($a, $profile_owner);
    }
    if ($mode === 'community') {
        $profile_owner = 0;
        $page_writeable = false;
    }
    if ($update) {
        $return_url = $_SESSION['return_url'];
    } else {
        $return_url = $_SESSION['return_url'] = $a->query_string;
    }
    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 = 'wall_item.tpl';
    $wallwall = 'wallwall_item.tpl';
    $hide_comments_tpl = get_markup_template('hide_comments.tpl');
    $alike = array();
    $dlike = array();
    // array with html for each thread (parent+comments)
    $threads = array();
    $threadsid = -1;
    if ($items && count($items)) {
        if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
            // "New Item View" on network page or search page results
            // - just loop through the items and format them minimally for display
            //$tpl = get_markup_template('search_item.tpl');
            $tpl = 'search_item.tpl';
            foreach ($items as $item) {
                $threadsid++;
                $comment = '';
                $owner_url = '';
                $owner_photo = '';
                $owner_name = '';
                $sparkle = '';
                if ($mode === 'search' || $mode === 'community') {
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $nickname = $item['nickname'];
                } else {
                    $nickname = $a->user['nickname'];
                }
                // prevent private email from leaking.
                if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
                    continue;
                }
                $profile_name = strlen($item['author-name']) ? $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 ($profile_link === 'mailbox') {
                    $profile_link = '';
                }
                if ($sp) {
                    $sparkle = ' sparkle';
                } else {
                    $profile_link = zrl($profile_link);
                }
                $normalised = normalise_link(strlen($item['author-link']) ? $item['author-link'] : $item['url']);
                if ($normalised != 'mailbox' && x($a->contacts[$normalised])) {
                    $profile_avatar = $a->contacts[$normalised]['thumb'];
                } else {
                    $profile_avatar = strlen($item['author-avatar']) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb'];
                }
                $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
                call_hooks('render_location', $locate);
                $location = strlen($locate['html']) ? $locate['html'] : render_location_dummy($locate);
                localize_item($item);
                if ($mode === 'network-new') {
                    $dropping = true;
                } else {
                    $dropping = false;
                }
                $drop = array('dropping' => $dropping, 'select' => t('Select'), 'delete' => t('Delete'));
                $star = false;
                $isstarred = "unstarred";
                $lock = false;
                $likebuttons = false;
                $shareable = false;
                $body = prepare_body($item, true);
                if ($a->theme['template_engine'] === 'internal') {
                    $name_e = template_escape($profile_name);
                    $title_e = template_escape($item['title']);
                    $body_e = template_escape($body);
                    $text_e = strip_tags(template_escape($body));
                    $location_e = template_escape($location);
                    $owner_name_e = template_escape($owner_name);
                } else {
                    $name_e = $profile_name;
                    $title_e = $item['title'];
                    $body_e = $body;
                    $text_e = strip_tags($body);
                    $location_e = $location;
                    $owner_name_e = $owner_name;
                }
                //$tmp_item = replace_macros($tpl,array(
                $tmp_item = array('template' => $tpl, '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), 'name' => $name_e, 'sparkle' => $sparkle, 'lock' => $lock, 'thumb' => proxy_url($profile_avatar), 'title' => $title_e, 'body' => $body_e, 'text' => $text_e, 'ago' => $item['app'] ? sprintf(t('%s from %s'), relative_date($item['created']), $item['app']) : relative_date($item['created']), 'location' => $location_e, 'indent' => '', 'owner_name' => $owner_name_e, 'owner_url' => $owner_url, 'owner_photo' => proxy_url($owner_photo), 'plink' => get_plink($item), 'edpost' => false, 'isstarred' => $isstarred, 'star' => $star, 'drop' => $drop, 'vote' => $likebuttons, 'like' => '', 'dislike' => '', 'comment' => '', 'conv' => $preview ? '' : array('href' => $a->get_baseurl($ssl_state) . '/display/' . $item['guid'], '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'] = $item['item_id'];
                $threads[$threadsid]['items'] = array($arr['output']);
            }
        } else {
            // Normal View
            // Figure out how many comments each parent has
            // (Comments all have gravity of 6)
            // Store the result in the $comments array
            $comments = array();
            foreach ($items as $item) {
                if (intval($item['gravity']) == 6 && $item['id'] != $item['parent']) {
                    if (!x($comments, $item['parent'])) {
                        $comments[$item['parent']] = 1;
                    } else {
                        $comments[$item['parent']] += 1;
                    }
                } elseif (!x($comments, $item['parent'])) {
                    $comments[$item['parent']] = 0;
                }
                // avoid notices later on
            }
            // map all the like/dislike activities for each parent item
            // Store these in the $alike and $dlike arrays
            foreach ($items as $item) {
                like_puller($a, $item, $alike, 'like');
                like_puller($a, $item, $dlike, 'dislike');
            }
            $comments_collapsed = false;
            $comments_seen = 0;
            $comment_lastcollapsed = false;
            $comment_firstcollapsed = false;
            $blowhard = 0;
            $blowhard_count = 0;
            foreach ($items as $item) {
                $comment = '';
                $template = $tpl;
                $commentww = '';
                $sparkle = '';
                $owner_url = $owner_photo = $owner_name = '';
                // We've already parsed out like/dislike for special treatment. We can ignore them now
                if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                    continue;
                }
                $toplevelpost = $item['id'] == $item['parent'] ? true : false;
                // Take care of author collapsing and comment collapsing
                // (author collapsing is currently disabled)
                // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
                // If there are more than two comments, squash all but the last 2.
                if ($toplevelpost) {
                    $item_writeable = $item['writable'] || $item['self'] ? true : false;
                    $comments_seen = 0;
                    $comments_collapsed = false;
                    $comment_lastcollapsed = false;
                    $comment_firstcollapsed = false;
                    $threadsid++;
                    $threads[$threadsid]['id'] = $item['item_id'];
                    $threads[$threadsid]['private'] = $item['private'];
                    $threads[$threadsid]['items'] = array();
                } else {
                    // prevent private email reply to public conversation from leaking.
                    if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
                        continue;
                    }
                    $comments_seen++;
                    $comment_lastcollapsed = false;
                    $comment_firstcollapsed = false;
                }
                $override_comment_box = $page_writeable && $item_writeable ? true : false;
                $show_comment_box = $page_writeable && $item_writeable && $comments_seen == $comments[$item['parent']] ? true : false;
                if ($comments[$item['parent']] > 2 && $comments_seen <= $comments[$item['parent']] - 2 && $item['gravity'] == 6) {
                    if (!$comments_collapsed) {
                        $threads[$threadsid]['num_comments'] = sprintf(tt('%d comment', '%d comments', $comments[$item['parent']]), $comments[$item['parent']]);
                        $threads[$threadsid]['hidden_comments_num'] = $comments[$item['parent']];
                        $threads[$threadsid]['hidden_comments_text'] = tt('comment', 'comments', $comments[$item['parent']]);
                        $threads[$threadsid]['hide_text'] = t('show more');
                        $comments_collapsed = true;
                        $comment_firstcollapsed = true;
                    }
                }
                if ($comments[$item['parent']] > 2 && $comments_seen == $comments[$item['parent']] - 1) {
                    $comment_lastcollapsed = true;
                }
                $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'];
                $lock = $item['private'] == 1 || $item['uid'] == local_user() && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false;
                // Top-level wall post not written by the wall owner (wall-to-wall)
                // First figure out who owns it.
                $osparkle = '';
                if ($toplevelpost && !$item['self'] && $mode !== 'profile') {
                    if ($item['wall']) {
                        // On the network page, I am the owner. On the display page it will be the profile owner.
                        // This will have been stored in $a->page_contact by our calling page.
                        // Put this person as the wall owner of the wall-to-wall notice.
                        $owner_url = zrl($a->page_contact['url']);
                        $owner_photo = $a->page_contact['thumb'];
                        $owner_name = $a->page_contact['name'];
                        $template = $wallwall;
                        $commentww = 'ww';
                    }
                    if (!$item['wall'] && $item['owner-link']) {
                        $owner_linkmatch = $item['owner-link'] && link_compare($item['owner-link'], $item['author-link']);
                        $alias_linkmatch = $item['alias'] && link_compare($item['alias'], $item['author-link']);
                        $owner_namematch = $item['owner-name'] && $item['owner-name'] == $item['author-name'];
                        if (!$owner_linkmatch && !$alias_linkmatch && !$owner_namematch) {
                            // The author url doesn't match the owner (typically the contact)
                            // and also doesn't match the contact alias.
                            // The name match is a hack to catch several weird cases where URLs are
                            // all over the park. It can be tricked, but this prevents you from
                            // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
                            // well that it's the same Bob Smith.
                            // But it could be somebody else with the same name. It just isn't highly likely.
                            $owner_url = $item['owner-link'];
                            $owner_photo = $item['owner-avatar'];
                            $owner_name = $item['owner-name'];
                            $template = $wallwall;
                            $commentww = 'ww';
                            // If it is our contact, use a friendly redirect link
                            if (link_compare($item['owner-link'], $item['url']) && $item['network'] === NETWORK_DFRN) {
                                $owner_url = $redirect_url;
                                $osparkle = ' sparkle';
                            } else {
                                $owner_url = zrl($owner_url);
                            }
                        }
                    }
                }
                $likebuttons = '';
                $shareable = $profile_owner == local_user() && $item['private'] != 1 ? true : false;
                if ($page_writeable) {
                    /*					if($toplevelpost) {  */
                    $likebuttons = array('like' => array(t("I like this (toggle)"), t("like")), 'dislike' => array(t("I don't like this (toggle)"), t("dislike")));
                    if ($shareable) {
                        $likebuttons['share'] = array(t('Share this'), t('share'));
                    }
                    /*					} */
                    $qc = $qcomment = null;
                    if (in_array('qcomment', $a->plugins)) {
                        $qc = local_user() ? get_pconfig(local_user(), 'qcomment', 'words') : null;
                        $qcomment = $qc ? explode("\n", $qc) : null;
                    }
                    if ($show_comment_box || $show_comment_box == false && $override_comment_box == false && $item['last-child']) {
                        $comment = replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $mode === 'display' ? $_SESSION['return_url'] : '', '$type' => $mode === 'profile' ? 'wall-comment' : 'net-comment', '$id' => $item['item_id'], '$parent' => $item['parent'], '$qcomment' => $qcomment, '$profile_uid' => $profile_owner, '$mylink' => $a->contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $a->contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$edbold' => t('Bold'), '$editalic' => t('Italic'), '$eduline' => t('Underline'), '$edquote' => t('Quote'), '$edcode' => t('Code'), '$edimg' => t('Image'), '$edurl' => t('Link'), '$edvideo' => t('Video'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), '$ww' => $mode === 'network' ? $commentww : '', '$rand_num' => random_digits(12)));
                    }
                }
                if (local_user() && link_compare($a->contact['url'], $item['author-link'])) {
                    $edpost = array($a->get_baseurl($ssl_state) . "/editpost/" . $item['id'], t("Edit"));
                } else {
                    $edpost = false;
                }
                $drop = '';
                $dropping = false;
                if (intval($item['contact-id']) && $item['contact-id'] == remote_user() || $item['uid'] == local_user()) {
                    $dropping = true;
                }
                $drop = array('dropping' => $dropping, 'select' => t('Select'), 'delete' => t('Delete'));
                $star = false;
                $filer = false;
                $isstarred = "unstarred";
                if ($profile_owner == local_user()) {
                    if ($toplevelpost) {
                        $isstarred = $item['starred'] ? "starred" : "unstarred";
                        $star = array('do' => t("add star"), 'undo' => t("remove star"), 'toggle' => t("toggle star status"), 'classdo' => $item['starred'] ? "hidden" : "", 'classundo' => $item['starred'] ? "" : "hidden", 'starred' => t('starred'), 'tagger' => t("add tag"), 'classtagger' => "");
                    }
                    $filer = t("save to folder");
                }
                $photo = $item['photo'];
                $thumb = $item['thumb'];
                // Post was remotely authored.
                $diff_author = link_compare($item['url'], $item['author-link']) ? false : true;
                $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 ($profile_link === 'mailbox') {
                    $profile_link = '';
                }
                if ($sp) {
                    $sparkle = ' sparkle';
                } else {
                    $profile_link = zrl($profile_link);
                }
                $normalised = normalise_link(strlen($item['author-link']) ? $item['author-link'] : $item['url']);
                if ($normalised != 'mailbox' && x($a->contacts, $normalised)) {
                    $profile_avatar = $a->contacts[$normalised]['thumb'];
                } else {
                    $profile_avatar = strlen($item['author-avatar']) && $diff_author ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb);
                }
                $like = x($alike, $item['uri']) ? format_like($alike[$item['uri']], $alike[$item['uri'] . '-l'], 'like', $item['uri']) : '';
                $dislike = x($dlike, $item['uri']) ? format_like($dlike[$item['uri']], $dlike[$item['uri'] . '-l'], 'dislike', $item['uri']) : '';
                $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
                call_hooks('render_location', $locate);
                $location = strlen($locate['html']) ? $locate['html'] : render_location_dummy($locate);
                $indent = $toplevelpost ? '' : ' comment';
                $shiny = "";
                if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
                    $shiny = 'shiny';
                }
                //
                localize_item($item);
                $tags = array();
                foreach (explode(',', $item['tag']) as $tag) {
                    $tag = trim($tag);
                    if ($tag != "") {
                        $tags[] = bbcode($tag);
                    }
                }
                // Build the HTML
                $body = prepare_body($item, true);
                //$tmp_item = replace_macros($template,
                if ($a->theme['template_engine'] === 'internal') {
                    $body_e = template_escape($body);
                    $text_e = strip_tags(template_escape($body));
                    $name_e = template_escape($profile_name);
                    $title_e = template_escape($item['title']);
                    $location_e = template_escape($location);
                    $owner_name_e = template_escape($owner_name);
                } else {
                    $body_e = $body;
                    $text_e = strip_tags($body);
                    $name_e = $profile_name;
                    $title_e = $item['title'];
                    $location_e = $location;
                    $owner_name_e = $owner_name;
                }
                $tmp_item = array('comment_firstcollapsed' => $comment_firstcollapsed, 'comment_lastcollapsed' => $comment_lastcollapsed, 'template' => $template, 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), 'tags' => $tags, 'body' => $body_e, 'text' => $text_e, 'id' => $item['item_id'], 'linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['author-link']) ? $item['author-link'] : $item['url']), 'olinktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['owner-link']) ? $item['owner-link'] : $item['url']), 'to' => t('to'), 'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $name_e, 'thumb' => proxy_url($profile_avatar), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title_e, 'ago' => $item['app'] ? sprintf(t('%s from %s'), relative_date($item['created']), $item['app']) : relative_date($item['created']), 'lock' => $lock, 'location' => $location_e, 'indent' => $indent, 'shiny' => $shiny, 'owner_url' => $owner_url, 'owner_photo' => proxy_url($owner_photo), 'owner_name' => $owner_name_e, 'plink' => get_plink($item), 'edpost' => $edpost, 'isstarred' => $isstarred, 'star' => $star, 'filer' => $filer, 'drop' => $drop, 'vote' => $likebuttons, 'like' => $like, 'dislike' => $dislike, 'comment' => $comment, 'previewing' => $previewing, 'wait' => t('Please wait'));
                $arr = array('item' => $item, 'output' => $tmp_item);
                call_hooks('display_item', $arr);
                $threads[$threadsid]['items'][] = $arr['output'];
            }
        }
    }
    return $threads;
}
Beispiel #7
0
function status_editor($a, $x, $notes_cid = 0, $popup = false)
{
    $o = '';
    $geotag = $x['allow_location'] ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '';
    /*	$plaintext = false;
    	if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
    		$plaintext = true;*/
    $plaintext = true;
    if (local_user() && feature_enabled(local_user(), 'richtext')) {
        $plaintext = false;
    }
    $tpl = get_markup_template('jot-header.tpl');
    $a->page['htmlhead'] .= replace_macros($tpl, array('$newpost' => 'true', '$baseurl' => $a->get_baseurl(true), '$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:'), '$fileas' => t('Save to Folder:'), '$whereareu' => t('Where are you right now?'), '$delitems' => t('Delete item(s)?')));
    $tpl = get_markup_template('jot-end.tpl');
    $a->page['end'] .= replace_macros($tpl, array('$newpost' => 'true', '$baseurl' => $a->get_baseurl(true), '$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:'), '$fileas' => t('Save to Folder:'), '$whereareu' => t('Where are you right now?')));
    $jotplugins = '';
    call_hooks('jot_tool', $jotplugins);
    // Private/public post links for the non-JS ACL form
    $private_post = 1;
    if ($_REQUEST['public']) {
        $private_post = 0;
    }
    $query_str = $a->query_string;
    if (strpos($query_str, 'public=1') !== false) {
        $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
    }
    // I think $a->query_string may never have ? in it, but I could be wrong
    // It looks like it's from the index.php?q=[etc] rewrite that the web
    // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
    if (strpos($query_str, '?') === false) {
        $public_post_link = '?public=1';
    } else {
        $public_post_link = '&public=1';
    }
    //	$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
    $tpl = get_markup_template("jot.tpl");
    $o .= replace_macros($tpl, array('$return_path' => $query_str, '$action' => $a->get_baseurl(true) . '/item', '$share' => x($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' => $x['title'], '$placeholdertitle' => t('Set title'), '$category' => $x['category'], '$placeholdercategory' => feature_enabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : '', '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$shortpermset' => t('permissions'), '$ptyp' => $notes_cid ? 'note' : 'wall', '$content' => $x['content'], '$post_id' => $x['post_id'], '$baseurl' => $a->get_baseurl(true), '$defloc' => $x['default_location'], '$visitor' => $x['visitor'], '$pvisit' => $notes_cid ? 'none' : $x['visitor'], '$public' => t('Public post'), '$jotnets' => $jotnets, '$lockstate' => $x['lockstate'], '$bang' => $x['bang'], '$profile_uid' => $x['profile_uid'], '$preview' => feature_enabled($x['profile_uid'], 'preview') ? t('Preview') : '', '$jotplugins' => $jotplugins, '$notes_cid' => $notes_cid, '$sourceapp' => t($a->sourcename), '$cancel' => t('Cancel'), '$rand_num' => random_digits(12), '$acl' => $x['acl'], '$acl_data' => $x['acl_data'], '$group_perms' => t('Post to Groups'), '$contact_perms' => t('Post to Contacts'), '$private' => t('Private post'), '$is_private' => $private_post, '$public_link' => $public_post_link));
    if ($popup == true) {
        $o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
    }
    return $o;
}
 function new_content_file_name()
 {
     $date = date("Y m d H");
     list($year, $month, $day, $hour) = explode(" ", $date);
     if (!file_exists(CONTENT_LOCAL_PATH . "{$year}")) {
         mkdir(CONTENT_LOCAL_PATH . "{$year}");
     }
     if (!file_exists(CONTENT_LOCAL_PATH . "{$year}/{$month}")) {
         mkdir(CONTENT_LOCAL_PATH . "{$year}/{$month}");
     }
     if (!file_exists(CONTENT_LOCAL_PATH . "{$year}/{$month}/{$day}")) {
         mkdir(CONTENT_LOCAL_PATH . "{$year}/{$month}/{$day}");
     }
     if (!file_exists(CONTENT_LOCAL_PATH . "{$year}/{$month}/{$day}/{$hour}")) {
         mkdir(CONTENT_LOCAL_PATH . "{$year}/{$month}/{$day}/{$hour}");
     }
     // Generate a random identifier for the data object
     // loop until we have a unique random identifier
     $file = random_digits(5);
     while (glob(CONTENT_LOCAL_PATH . "{$year}/{$month}/{$day}/{$hour}/{$file}" . "*")) {
         $file = random_digits(5);
     }
     return CONTENT_LOCAL_PATH . "{$year}/{$month}/{$day}/{$hour}/{$file}";
 }