Ejemplo n.º 1
0
 function init()
 {
     $params = array();
     $params['begin'] = x($_REQUEST, 'date_begin') ? $_REQUEST['date_begin'] : NULL_DATE;
     $params['end'] = x($_REQUEST, 'date_end') ? $_REQUEST['date_end'] : '';
     $params['type'] = stristr(argv(0), 'json') ? 'json' : 'xml';
     $params['pages'] = x($_REQUEST, 'pages') ? intval($_REQUEST['pages']) : 0;
     $params['top'] = x($_REQUEST, 'top') ? intval($_REQUEST['top']) : 0;
     $params['start'] = x($params, 'start') ? intval($params['start']) : 0;
     $params['records'] = x($params, 'records') ? intval($params['records']) : 40;
     $params['direction'] = x($params, 'direction') ? dbesc($params['direction']) : 'desc';
     $params['cat'] = x($_REQUEST, 'cat') ? escape_tags($_REQUEST['cat']) : '';
     $channel = '';
     if (argc() > 1) {
         $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_address = '%s' limit 1", dbesc(argv(1)));
         if (!($r && count($r))) {
             killme();
         }
         $channel = $r[0];
         if (observer_prohibited(true)) {
             killme();
         }
         logger('mod_feed: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $channel['channel_address']);
         echo get_public_feed($channel, $params);
         killme();
     }
 }
Ejemplo n.º 2
0
 function init()
 {
     $result = array('success' => false);
     $mindate = $_REQUEST['mindate'] ? datetime_convert('UTC', 'UTC', $_REQUEST['mindate']) : '';
     if (!$mindate) {
         $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days');
     }
     if (observer_prohibited()) {
         $result['message'] = 'Public access denied';
         json_return_and_die($result);
     }
     $observer = \App::get_observer();
     $channel_address = argc() > 1 ? argv(1) : '';
     if ($channel_address) {
         $r = q("select channel_id, channel_name from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc(argv(1)));
     } else {
         $x = get_sys_channel();
         if ($x) {
             $r = array($x);
         }
         $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days');
     }
     if (!$r) {
         $result['message'] = 'Channel not found.';
         json_return_and_die($result);
     }
     logger('zotfeed request: ' . $r[0]['channel_name'], LOGGER_DEBUG);
     $result['messages'] = zot_feed($r[0]['channel_id'], $observer['xchan_hash'], array('mindate' => $mindate));
     $result['success'] = true;
     json_return_and_die($result);
 }
Ejemplo n.º 3
0
 function get()
 {
     if (observer_prohibited()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     if (!count(\App::$profile) || \App::$profile['hide_friends']) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!perm_is_allowed(\App::$profile['uid'], get_observer_hash(), 'view_contacts')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!$_REQUEST['aj']) {
         $_SESSION['return_url'] = \App::$query_string;
     }
     $is_owner = local_channel() && local_channel() == \App::$profile['uid'] ? true : false;
     $abook_flags = " and abook_pending = 0 and abook_self = 0 ";
     $sql_extra = '';
     if (!$is_owner) {
         $abook_flags = " and abook_hidden = 0 ";
         $sql_extra = " and xchan_hidden = 0 ";
     }
     $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d {$abook_flags} and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra} ", intval(\App::$profile['uid']));
     if ($r) {
         \App::set_pager_total($r[0]['total']);
     }
     $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d {$abook_flags} and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra} order by xchan_name LIMIT %d OFFSET %d ", intval(\App::$profile['uid']), intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     if (!$r && !$_REQUEST['aj']) {
         info(t('No connections.') . EOL);
         return $o;
     }
     $contacts = array();
     foreach ($r as $rr) {
         $url = chanlink_url($rr['xchan_url']);
         if ($url) {
             $contacts[] = array('id' => $rr['abook_id'], 'archived' => intval($rr['abook_archived']) ? true : false, 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['xchan_name'], $rr['xchan_url']), 'thumb' => $rr['xchan_photo_m'], 'name' => substr($rr['xchan_name'], 0, 20), 'username' => $rr['xchan_addr'], 'link' => $url, 'sparkle' => '', 'itemurl' => $rr['url'], 'network' => '');
         }
     }
     if ($_REQUEST['aj']) {
         if ($contacts) {
             $o = replace_macros(get_markup_template('viewcontactsajax.tpl'), array('$contacts' => $contacts));
         } else {
             $o = '<div id="content-complete"></div>';
         }
         echo $o;
         killme();
     } else {
         $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
         $tpl = get_markup_template("viewcontact_template.tpl");
         $o .= replace_macros($tpl, array('$title' => t('View Connections'), '$contacts' => $contacts));
     }
     if (!$contacts) {
         $o .= '<div id="content-complete"></div>';
     }
     return $o;
 }
Ejemplo n.º 4
0
 function get()
 {
     if (observer_prohibited()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $rating_enabled = get_config('system', 'rating_enabled');
     if (!$rating_enabled) {
         return;
     }
     $site_target = array_key_exists('target', \App::$data) && array_key_exists('site_url', \App::$data['target']) ? '<a href="' . \App::$data['target']['site_url'] . '" >' . \App::$data['target']['site_url'] . '</a>' : '';
     $o = replace_macros(get_markup_template('prep.tpl'), array('$header' => t('Ratings'), '$rating_lbl' => t('Rating: '), '$website' => t('Website: '), '$site' => $site_target, '$rating_text_lbl' => t('Description: '), '$raters' => \App::$data['results']));
     return $o;
 }
Ejemplo n.º 5
0
 function get()
 {
     if (observer_prohibited(true)) {
         return login();
     }
     $groups = array();
     $tab = 'profile';
     $o = '';
     if (!perm_is_allowed(\App::$profile['profile_uid'], get_observer_hash(), 'view_profile')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $is_owner = local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false;
     if (\App::$profile['hidewall'] && !$is_owner && !remote_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
     \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n";
     $o .= advanced_profile($a);
     call_hooks('profile_advanced', $o);
     return $o;
 }
Ejemplo n.º 6
0
 function get()
 {
     if (observer_prohibited()) {
         return;
     }
     $channel = null;
     if (argc() > 1) {
         $channel = channelx_by_nick(argv(1));
     }
     if (!$channel) {
         notice(t('Channel not found.') . EOL);
         return;
     }
     // since we don't currently have an event permission - use the stream permission
     if (!perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_stream')) {
         notice(t('Permissions denied.') . EOL);
         return;
     }
     $sql_extra = permissions_sql($channel['channel_id'], get_observer_hash(), 'event');
     $first_day = get_pconfig(local_channel(), 'system', 'cal_first_day');
     $first_day = $first_day ? $first_day : 0;
     $htpl = get_markup_template('event_head.tpl');
     \App::$page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => z_root(), '$module_url' => '/cal/' . $channel['channel_address'], '$modparams' => 2, '$lang' => \App::$language, '$first_day' => $first_day));
     $o = '';
     $tabs = profile_tabs($a, True, $channel['channel_address']);
     $mode = 'view';
     $y = 0;
     $m = 0;
     $ignored = x($_REQUEST, 'ignored') ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '';
     // logger('args: ' . print_r(\App::$argv,true));
     if (argc() > 3 && intval(argv(2)) && intval(argv(3))) {
         $mode = 'view';
         $y = intval(argv(2));
         $m = intval(argv(3));
     }
     if (argc() <= 3) {
         $mode = 'view';
         $event_id = argv(2);
     }
     if ($mode == 'view') {
         /* edit/create form */
         if ($event_id) {
             $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval($channel['channel_id']));
             if (count($r)) {
                 $orig_event = $r[0];
             }
         }
         // Passed parameters overrides anything found in the DB
         if (!x($orig_event)) {
             $orig_event = array();
         }
         $tz = date_default_timezone_get();
         if (x($orig_event)) {
             $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
         }
         $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
         $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
         $sday = datetime_convert('UTC', $tz, $sdt, 'd');
         $shour = datetime_convert('UTC', $tz, $sdt, 'H');
         $sminute = datetime_convert('UTC', $tz, $sdt, 'i');
         $stext = datetime_convert('UTC', $tz, $sdt);
         $stext = substr($stext, 0, 14) . "00:00";
         $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
         $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
         $fday = datetime_convert('UTC', $tz, $fdt, 'd');
         $fhour = datetime_convert('UTC', $tz, $fdt, 'H');
         $fminute = datetime_convert('UTC', $tz, $fdt, 'i');
         $ftext = datetime_convert('UTC', $tz, $fdt);
         $ftext = substr($ftext, 0, 14) . "00:00";
         $type = x($orig_event) ? $orig_event['etype'] : 'event';
         $f = get_config('system', 'event_input_format');
         if (!$f) {
             $f = 'ymd';
         }
         $catsenabled = feature_enabled($channel['channel_id'], 'categories');
         $show_bd = perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_contacts');
         if (!$show_bd) {
             $sql_extra .= " and event.etype != 'birthday' ";
         }
         $category = '';
         $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
         $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
         if (!$y) {
             $y = intval($thisyear);
         }
         if (!$m) {
             $m = intval($thismonth);
         }
         // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
         // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
         if ($y < 1901) {
             $y = 1900;
         }
         if ($y > 2099) {
             $y = 2100;
         }
         $nextyear = $y;
         $nextmonth = $m + 1;
         if ($nextmonth > 12) {
             $nextmonth = 1;
             $nextyear++;
         }
         $prevyear = $y;
         if ($m > 1) {
             $prevmonth = $m - 1;
         } else {
             $prevmonth = 12;
             $prevyear--;
         }
         $dim = get_dim($y, $m);
         $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
         $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
         if (argv(2) === 'json') {
             if (x($_GET, 'start')) {
                 $start = $_GET['start'];
             }
             if (x($_GET, 'end')) {
                 $finish = $_GET['end'];
             }
         }
         $start = datetime_convert('UTC', 'UTC', $start);
         $finish = datetime_convert('UTC', 'UTC', $finish);
         $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
         $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
         if (x($_GET, 'id')) {
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d {$sql_extra} limit 1", intval($channel['channel_id']), intval($_GET['id']));
         } else {
             // fixed an issue with "nofinish" events not showing up in the calendar.
             // There's still an issue if the finish date crosses the end of month.
             // Noting this for now - it will need to be fixed here and in Friendica.
             // Ultimately the finish date shouldn't be involved in the query.
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                              from event left join item on event_hash = resource_id \n\t\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored} \n\t\t\t\t\tAND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) \n\t\t\t\t\tOR  (  adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) {$sql_extra} ", intval($channel['channel_id']), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         }
         $links = array();
         if ($r) {
             xchan_query($r);
             $r = fetch_post_tags($r, true);
             $r = sort_by_date($r);
         }
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 if (!x($links, $j)) {
                     $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
                 }
             }
         }
         $events = array();
         $last_date = '';
         $fmt = t('l, F j');
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt);
                 $d = day_translate($d);
                 $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c');
                 if ($rr['nofinish']) {
                     $end = null;
                 } else {
                     $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c');
                 }
                 $is_first = $d !== $last_date;
                 $last_date = $d;
                 $edit = false;
                 $drop = false;
                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                 if (!$title) {
                     list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                     $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                 }
                 $html = format_event_html($rr);
                 $rr['desc'] = bbcode($rr['desc']);
                 $rr['location'] = bbcode($rr['location']);
                 $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
             }
         }
         if (argv(2) === 'json') {
             echo json_encode($events);
             killme();
         }
         // links: array('href', 'text', 'extra css classes', 'title')
         if (x($_GET, 'id')) {
             $tpl = get_markup_template("event_cal.tpl");
         } else {
             $tpl = get_markup_template("events_cal-js.tpl");
         }
         $nick = $channel['channel_address'];
         $o = replace_macros($tpl, array('$baseurl' => z_root(), '$new_event' => array(z_root() . '/cal', $event_id ? t('Edit Event') : t('Create Event'), '', ''), '$previus' => array(z_root() . "/cal/{$nick}/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array(z_root() . "/cal/{$nick}/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array(z_root() . "/cal/{$nick}/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, '$upload' => t('Import'), '$submit' => t('Submit'), '$prev' => t('Previous'), '$next' => t('Next'), '$today' => t('Today'), '$form' => $form, '$expandform' => x($_GET, 'expandform') ? true : false, '$tabs' => $tabs));
         if (x($_GET, 'id')) {
             echo $o;
             killme();
         }
         return $o;
     }
 }
Ejemplo n.º 7
0
 function get($update = 0, $load = false)
 {
     $checkjs = new \Zotlabs\Web\CheckJS(1);
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     if (observer_prohibited()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     require_once "include/bbcode.php";
     require_once 'include/security.php';
     require_once 'include/conversation.php';
     require_once 'include/acl_selectors.php';
     require_once 'include/items.php';
     \App::$page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
     if (argc() > 1 && argv(1) !== 'load') {
         $item_hash = argv(1);
     }
     if ($_REQUEST['mid']) {
         $item_hash = $_REQUEST['mid'];
     }
     if (!$item_hash) {
         \App::$error = 404;
         notice(t('Item not found.') . EOL);
         return;
     }
     $observer_is_owner = false;
     if (local_channel() && !$update) {
         $channel = \App::get_channel();
         $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
         $x = array('is_owner' => true, 'allow_location' => intval(get_pconfig($channel['channel_id'], 'system', 'use_browser_location')) ? '1' : '', 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], 'lockstate' => $group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'permissions' => $channel_acl, 'bang' => '', 'visitor' => true, 'profile_uid' => local_channel(), 'return_path' => 'channel/' . $channel['channel_address'], 'expanded' => true, 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true);
         $o = '<div id="jot-popup">';
         $o .= status_editor($a, $x);
         $o .= '</div>';
     }
     // This page can be viewed by anybody so the query could be complicated
     // First we'll see if there is a copy of the item which is owned by us - if we're logged in locally.
     // If that fails (or we aren't logged in locally),
     // query an item in which the observer (if logged in remotely) has cid or gid rights
     // and if that fails, look for a copy of the post that has no privacy restrictions.
     // If we find the post, but we don't find a copy that we're allowed to look at, this fact needs to be reported.
     // find a copy of the item somewhere
     $target_item = null;
     $r = q("select id, uid, mid, parent_mid, item_type, item_deleted from item where mid like '%s' limit 1", dbesc($item_hash . '%'));
     if ($r) {
         $target_item = $r[0];
     }
     $r = null;
     if ($target_item['item_type'] == ITEM_TYPE_WEBPAGE) {
         $x = q("select * from channel where channel_id = %d limit 1", intval($target_item['uid']));
         $y = q("select * from iconfig left join item on iconfig.iid = item.id \n\t\t\t\twhere item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item.id = %d limit 1", intval($target_item['uid']), intval($target_item['id']));
         if ($x && $y) {
             goaway(z_root() . '/page/' . $x[0]['channel_address'] . '/' . $y[0]['v']);
         } else {
             notice(t('Page not found.') . EOL);
             return '';
         }
     }
     $simple_update = $update ? " AND item_unseen = 1 " : '';
     if ($update && $_SESSION['loadtime']) {
         $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
     }
     if ($load) {
         $simple_update = '';
     }
     if (!$update && !$load) {
         $o .= '<div id="live-display"></div>' . "\r\n";
         $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] . "; </script>\r\n";
         \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'display', '$uid' => '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '99', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$fh' => '0', '$nouveau' => '0', '$wall' => '0', '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$search' => '', '$order' => '', '$file' => '', '$cats' => '', '$tags' => '', '$dend' => '', '$dbegin' => '', '$verb' => '', '$mid' => $item_hash));
     }
     $observer_hash = get_observer_hash();
     $item_normal = item_normal();
     $sql_extra = public_permissions_sql($observer_hash);
     if ($update && $load || $checkjs->disabled()) {
         $updateable = false;
         $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
         if ($load || $checkjs->disabled()) {
             $r = null;
             require_once 'include/channel.php';
             $sys = get_sys_channel();
             $sysid = $sys['channel_id'];
             if (local_channel()) {
                 $r = q("SELECT * from item\n\t\t\t\t\t\tWHERE uid = %d\n\t\t\t\t\t\tand mid = '%s'\n\t\t\t\t\t\t{$item_normal}\n\t\t\t\t\t\tlimit 1", intval(local_channel()), dbesc($target_item['parent_mid']));
                 if ($r) {
                     $updateable = true;
                 }
             }
             if ($r === null) {
                 // in case somebody turned off public access to sys channel content using permissions
                 // make that content unsearchable by ensuring the owner_xchan can't match
                 if (!perm_is_allowed($sysid, $observer_hash, 'view_stream')) {
                     $sysid = 0;
                 }
                 $r = q("SELECT * from item\n\t\t\t\t\t\tWHERE mid = '%s'\n\t\t\t\t\t\tAND (((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' \n\t\t\t\t\t\tAND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer_hash ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\t\tOR uid = %d )\n\t\t\t\t\t\t{$sql_extra} )\n\t\t\t\t\t\t{$item_normal}\n\t\t\t\t\t\tlimit 1", dbesc($target_item['parent_mid']), intval($sysid));
             }
         }
     } elseif ($update && !$load) {
         $r = null;
         require_once 'include/channel.php';
         $sys = get_sys_channel();
         $sysid = $sys['channel_id'];
         if (local_channel()) {
             $r = q("SELECT * from item\n\t\t\t\t\tWHERE uid = %d\n\t\t\t\t\tand mid = '%s'\n\t\t\t\t\t{$item_normal}\n\t\t\t\t\t{$simple_update}\n\t\t\t\t\tlimit 1", intval(local_channel()), dbesc($target_item['parent_mid']));
             if ($r) {
                 $updateable = true;
             }
         }
         if ($r === null) {
             // in case somebody turned off public access to sys channel content using permissions
             // make that content unsearchable by ensuring the owner_xchan can't match
             if (!perm_is_allowed($sysid, $observer_hash, 'view_stream')) {
                 $sysid = 0;
             }
             $r = q("SELECT * from item\n\t\t\t\t\tWHERE mid = '%s'\n\t\t\t\t\tAND (((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' \n\t\t\t\t\tAND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer_hash ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\tOR uid = %d )\n\t\t\t\t\t{$sql_extra} )\n\t\t\t\t\t{$item_normal}\n\t\t\t\t\t{$simple_update}\n\t\t\t\t\tlimit 1", dbesc($target_item['parent_mid']), intval($sysid));
         }
         $_SESSION['loadtime'] = datetime_convert();
     } else {
         $r = array();
     }
     if ($r) {
         $parents_str = ids_to_querystr($r, 'id');
         if ($parents_str) {
             $items = q("SELECT `item`.*, `item`.`id` AS `item_id` \n\t\t\t\t\tFROM `item`\n\t\t\t\t\tWHERE parent in ( %s ) {$item_normal} ", dbesc($parents_str));
             xchan_query($items);
             $items = fetch_post_tags($items, true);
             $items = conv_sort($items, 'created');
         }
     } else {
         $items = array();
     }
     if ($checkjs->disabled()) {
         $o .= conversation($a, $items, 'display', $update, 'traditional');
         if ($items[0]['title']) {
             \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title'];
         }
     } else {
         $o .= conversation($a, $items, 'display', $update, 'client');
     }
     if ($updateable) {
         $x = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d and parent = %d ", intval(local_channel()), intval($r[0]['parent']));
     }
     $o .= '<div id="content-complete"></div>';
     return $o;
     /*
     	elseif((! $update) && (!  {
     		
     		$r = q("SELECT `id`, item_flags FROM `item` WHERE `id` = '%s' OR `mid` = '%s' LIMIT 1",
     			dbesc($item_hash),
     			dbesc($item_hash)
     		);
     		if($r) {
     			if(intval($r[0]['item_deleted'])) {
     				notice( t('Item has been removed.') . EOL );
     			}
     			else {	
     				notice( t('Permission denied.') . EOL ); 
     			}
     		}
     		else {
     			notice( t('Item not found.') . EOL );
     		}
     
     	}
     */
 }
Ejemplo n.º 8
0
 function get($update = 0, $load = false)
 {
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     $checkjs = new \Zotlabs\Web\CheckJS(1);
     $category = $datequery = $datequery2 = '';
     $mid = x($_REQUEST, 'mid') ? $_REQUEST['mid'] : '';
     $datequery = x($_GET, 'dend') && is_a_date_arg($_GET['dend']) ? notags($_GET['dend']) : '';
     $datequery2 = x($_GET, 'dbegin') && is_a_date_arg($_GET['dbegin']) ? notags($_GET['dbegin']) : '';
     if (observer_prohibited(true)) {
         return login();
     }
     $category = x($_REQUEST, 'cat') ? $_REQUEST['cat'] : '';
     $hashtags = x($_REQUEST, 'tag') ? $_REQUEST['tag'] : '';
     $groups = array();
     $o = '';
     if ($update) {
         // Ensure we've got a profile owner if updating.
         \App::$profile['profile_uid'] = \App::$profile_uid = $update;
     } else {
         if (\App::$profile['profile_uid'] == local_channel()) {
             nav_set_selected('home');
         }
     }
     $is_owner = local_channel() && \App::$profile['profile_uid'] == local_channel() ? true : false;
     $channel = \App::get_channel();
     $observer = \App::get_observer();
     $ob_hash = $observer ? $observer['xchan_hash'] : '';
     $perms = get_all_perms(\App::$profile['profile_uid'], $ob_hash);
     if (!$perms['view_stream']) {
         // We may want to make the target of this redirect configurable
         if ($perms['view_profile']) {
             notice(t('Insufficient permissions.  Request redirected to profile page.') . EOL);
             goaway(z_root() . "/profile/" . \App::$profile['channel_address']);
         }
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!$update) {
         $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
         $o .= common_friends_visitor_widget(\App::$profile['profile_uid']);
         if ($channel && $is_owner) {
             $channel_acl = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
         } else {
             $channel_acl = array();
         }
         if ($perms['post_wall']) {
             $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $observer) && intval(get_pconfig(\App::$profile['profile_uid'], 'system', 'use_browser_location')) ? true : false, 'default_location' => $is_owner ? \App::$profile['channel_location'] : '', 'nickname' => \App::$profile['channel_address'], 'lockstate' => strlen(\App::$profile['channel_allow_cid']) || strlen(\App::$profile['channel_allow_gid']) || strlen(\App::$profile['channel_deny_cid']) || strlen(\App::$profile['channel_deny_gid']) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($channel_acl, true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : '', 'showacl' => $is_owner ? 'yes' : '', 'bang' => '', 'visitor' => $is_owner || $observer ? true : false, 'profile_uid' => \App::$profile['profile_uid'], 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true);
             $o .= status_editor($a, $x);
         }
     }
     /**
      * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
      */
     $item_normal = item_normal();
     $sql_extra = item_permissions_sql(\App::$profile['profile_uid']);
     if (get_pconfig(\App::$profile['profile_uid'], 'system', 'channel_list_mode') && !$mid) {
         $page_mode = 'list';
     } else {
         $page_mode = 'client';
     }
     $abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " ";
     $simple_update = $update ? " AND item_unseen = 1 " : '';
     \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n";
     if ($update && $_SESSION['loadtime']) {
         $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
     }
     if ($load) {
         $simple_update = '';
     }
     if ($update && !$load) {
         if ($mid) {
             $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d {$item_normal}\n\t\t\t\t\tAND item_wall = 1 AND item_unseen = 1 {$sql_extra} limit 1", dbesc($mid . '%'), intval(\App::$profile['profile_uid']));
         } else {
             $r = q("SELECT distinct parent AS `item_id`, created from item\n\t\t\t\t\tleft join abook on ( item.owner_xchan = abook.abook_xchan {$abook_uids} )\n\t\t\t\t\tWHERE uid = %d {$item_normal}\n\t\t\t\t\tAND item_wall = 1 {$simple_update}\n\t\t\t\t\tAND (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t{$sql_extra}\n\t\t\t\t\tORDER BY created DESC", intval(\App::$profile['profile_uid']));
             $_SESSION['loadtime'] = datetime_convert();
         }
     } else {
         if (x($category)) {
             $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY));
         }
         if (x($hashtags)) {
             $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG));
         }
         if ($datequery) {
             $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
         }
         if ($datequery2) {
             $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
         }
         $itemspage = get_pconfig(local_channel(), 'system', 'itemspage');
         \App::set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
         $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
         if ($load || $checkjs->disabled()) {
             if ($mid) {
                 $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d {$item_normal}\n\t\t\t\t\t\tAND item_wall = 1 {$sql_extra} limit 1", dbesc($mid), intval(\App::$profile['profile_uid']));
                 if (!$r) {
                     notice(t('Permission denied.') . EOL);
                 }
             } else {
                 $r = q("SELECT distinct id AS item_id, created FROM item \n\t\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\t\tWHERE uid = %d {$item_normal}\n\t\t\t\t\t\tAND item_wall = 1 and item_thread_top = 1\n\t\t\t\t\t\tAND (abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t\t{$sql_extra} {$sql_extra2}\n\t\t\t\t\t\tORDER BY created DESC {$pager_sql} ", intval(\App::$profile['profile_uid']));
             }
         } else {
             $r = array();
         }
     }
     if ($r) {
         $parents_str = ids_to_querystr($r, 'item_id');
         $items = q("SELECT `item`.*, `item`.`id` AS `item_id` \n\t\t\t\tFROM `item`\n\t\t\t\tWHERE `item`.`uid` = %d {$item_normal}\n\t\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t\t{$sql_extra} ", intval(\App::$profile['profile_uid']), dbesc($parents_str));
         xchan_query($items);
         $items = fetch_post_tags($items, true);
         $items = conv_sort($items, 'created');
         if ($load && $mid && !count($items)) {
             // This will happen if we don't have sufficient permissions
             // to view the parent item (or the item itself if it is toplevel)
             notice(t('Permission denied.') . EOL);
         }
     } else {
         $items = array();
     }
     if (!$update && !$load) {
         // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
         // because browser prefetching might change it on us. We have to deliver it with the page.
         $maxheight = get_pconfig(\App::$profile['profile_uid'], 'system', 'channel_divmore_height');
         if (!$maxheight) {
             $maxheight = 400;
         }
         $o .= '<div id="live-channel"></div>' . "\r\n";
         $o .= "<script> var profile_uid = " . \App::$profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] . "; divmore_height = " . intval($maxheight) . "; </script>\r\n";
         \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'channel', '$uid' => \App::$profile['profile_uid'] ? \App::$profile['profile_uid'] : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '0', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$nouveau' => '0', '$wall' => '1', '$fh' => '0', '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$search' => '', '$order' => '', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$file' => '', '$cats' => $category ? $category : '', '$tags' => $hashtags ? $hashtags : '', '$mid' => $mid, '$verb' => '', '$dend' => $datequery, '$dbegin' => $datequery2));
     }
     $update_unseen = '';
     if ($page_mode === 'list') {
         /**
          * in "list mode", only mark the parent item and any like activities as "seen". 
          * We won't distinguish between comment likes and post likes. The important thing
          * is that the number of unseen comments will be accurate. The SQL to separate the
          * comment likes could also get somewhat hairy. 
          */
         if ($parents_str) {
             $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )";
             $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) ";
         }
     } else {
         if ($parents_str) {
             $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )";
         }
     }
     if ($is_owner && $update_unseen) {
         $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d {$update_unseen}", intval(local_channel()));
     }
     if ($checkjs->disabled()) {
         $o .= conversation($a, $items, 'channel', $update, 'traditional');
     } else {
         $o .= conversation($a, $items, 'channel', $update, $page_mode);
     }
     if (!$update || $checkjs->disabled()) {
         $o .= alt_pager($a, count($items));
         if ($mid && $items[0]['title']) {
             \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title'];
         }
     }
     if ($mid) {
         $o .= '<div id="content-complete"></div>';
     }
     return $o;
 }
Ejemplo n.º 9
0
function get_online_status($nick)
{
    $ret = array('result' => false);
    if (observer_prohibited()) {
        return $ret;
    }
    $r = q("select channel_id, channel_hash from channel where channel_address = '%s' limit 1", dbesc(argv(1)));
    if ($r) {
        $hide = get_pconfig($r[0]['channel_id'], 'system', 'hide_online_status');
        if ($hide) {
            return $ret;
        }
        $x = q("select cp_status from chatpresence where cp_xchan = '%s' and cp_room = 0 limit 1", dbesc($r[0]['channel_hash']));
        if ($x) {
            $ret['result'] = $x[0]['cp_status'];
        }
    }
    return $ret;
}
Ejemplo n.º 10
0
function poco($a, $extended = false)
{
    $system_mode = false;
    if (observer_prohibited()) {
        logger('mod_poco: block_public');
        http_status_exit(401);
    }
    $observer = App::get_observer();
    if (argc() > 1) {
        $user = notags(trim(argv(1)));
    }
    if (!x($user)) {
        $c = q("select * from pconfig where cat = 'system' and k = 'suggestme' and v = '1'");
        if (!$c) {
            logger('mod_poco: system mode. No candidates.', LOGGER_DEBUG);
            http_status_exit(404);
        }
        $system_mode = true;
    }
    $format = $_REQUEST['format'] ? $_REQUEST['format'] : 'json';
    $justme = false;
    if (argc() > 2 && argv(2) === '@me') {
        $justme = true;
    }
    if (argc() > 3) {
        if (argv(3) === '@all') {
            $justme = false;
        } elseif (argv(3) === '@self') {
            $justme = true;
        }
    }
    if (argc() > 4 && intval(argv(4)) && $justme == false) {
        $cid = intval(argv(4));
    }
    if (!$system_mode) {
        $r = q("SELECT channel_id from channel where channel_address = '%s' limit 1", dbesc($user));
        if (!$r) {
            logger('mod_poco: user mode. Account not found. ' . $user);
            http_status_exit(404);
        }
        $channel_id = $r[0]['channel_id'];
        $ohash = $observer ? $observer['xchan_hash'] : '';
        if (!perm_is_allowed($channel_id, $ohash, 'view_contacts')) {
            logger('mod_poco: user mode. Permission denied for ' . $ohash . ' user: '******'system' and k = 'suggestme' and v = '1') ");
    } else {
        $r = q("SELECT count(*) as `total` from abook where abook_channel = %d \n\t\t\t{$sql_extra} ", intval($channel_id));
        $rooms = q("select * from menu_item where ( mitem_flags & " . intval(MENU_ITEM_CHATROOM) . " )>0 and allow_cid = '' and allow_gid = '' and deny_cid = '' and deny_gid = '' and mitem_channel_id = %d", intval($channel_id));
    }
    if ($r) {
        $totalResults = intval($r[0]['total']);
    } else {
        $totalResults = 0;
    }
    $startIndex = intval($_GET['startIndex']);
    if (!$startIndex) {
        $startIndex = 0;
    }
    $itemsPerPage = x($_GET, 'count') && intval($_GET['count']) ? intval($_GET['count']) : $totalResults;
    if ($system_mode) {
        $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_self = 1 \n\t\t\tand abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = '1') \n\t\t\tlimit %d offset %d ", intval($itemsPerPage), intval($startIndex));
    } else {
        $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d \n\t\t\t{$sql_extra} LIMIT %d OFFSET %d", intval($channel_id), intval($itemsPerPage), intval($startIndex));
    }
    $ret = array();
    if (x($_GET, 'sorted')) {
        $ret['sorted'] = 'false';
    }
    if (x($_GET, 'filtered')) {
        $ret['filtered'] = 'false';
    }
    if (x($_GET, 'updatedSince')) {
        $ret['updateSince'] = 'false';
    }
    $ret['startIndex'] = (string) $startIndex;
    $ret['itemsPerPage'] = (string) $itemsPerPage;
    $ret['totalResults'] = (string) $totalResults;
    if ($rooms) {
        $ret['chatrooms'] = array();
        foreach ($rooms as $room) {
            $ret['chatrooms'][] = array('url' => $room['mitem_link'], 'desc' => $room['mitem_desc']);
        }
    }
    $ret['entry'] = array();
    $fields_ret = array('id' => false, 'guid' => false, 'guid_sig' => false, 'hash' => false, 'displayName' => false, 'urls' => false, 'preferredUsername' => false, 'photos' => false, 'rating' => false);
    if (!x($_GET, 'fields') || $_GET['fields'] === '@all') {
        foreach ($fields_ret as $k => $v) {
            $fields_ret[$k] = true;
        }
    } else {
        $fields_req = explode(',', $_GET['fields']);
        foreach ($fields_req as $f) {
            $fields_ret[trim($f)] = true;
        }
    }
    if (is_array($r)) {
        if (count($r)) {
            foreach ($r as $rr) {
                $entry = array();
                if ($fields_ret['id']) {
                    $entry['id'] = $rr['abook_id'];
                }
                if ($fields_ret['guid']) {
                    $entry['guid'] = $rr['xchan_guid'];
                }
                if ($fields_ret['guid_sig']) {
                    $entry['guid_sig'] = $rr['xchan_guid_sig'];
                }
                if ($fields_ret['hash']) {
                    $entry['hash'] = $rr['xchan_hash'];
                }
                if ($fields_ret['displayName']) {
                    $entry['displayName'] = $rr['xchan_name'];
                }
                if ($fields_ret['urls']) {
                    $entry['urls'] = array(array('value' => $rr['xchan_url'], 'type' => 'profile'));
                    $network = $rr['xchan_network'];
                    if (strpos($network, 'friendica') !== false) {
                        $network = 'friendica';
                    }
                    if ($rr['xchan_addr']) {
                        $entry['urls'][] = array('value' => 'acct:' . $rr['xchan_addr'], 'type' => $network);
                    }
                }
                if ($fields_ret['preferredUsername']) {
                    $entry['preferredUsername'] = substr($rr['xchan_addr'], 0, strpos($rr['xchan_addr'], '@'));
                }
                if ($fields_ret['photos']) {
                    $entry['photos'] = array(array('value' => $rr['xchan_photo_l'], 'mimetype' => $rr['xchan_photo_mimetype'], 'type' => 'profile'));
                }
                $ret['entry'][] = $entry;
            }
        } else {
            $ret['entry'][] = array();
        }
    } else {
        http_status_exit(500);
    }
    if ($format === 'xml') {
        header('Content-type: text/xml');
        echo replace_macros(get_markup_template('poco_xml.tpl'), array_xmlify(array('$response' => $ret)));
        http_status_exit(500);
    }
    if ($format === 'json') {
        header('Content-type: application/json');
        echo json_encode($ret);
        killme();
    } else {
        http_status_exit(500);
    }
}
Ejemplo n.º 11
0
 function navbar_complete(&$a)
 {
     //	logger('navbar_complete');
     if (observer_prohibited()) {
         return;
     }
     $dirmode = intval(get_config('system', 'directory_mode'));
     $search = x($_REQUEST, 'search') ? htmlentities($_REQUEST['search'], ENT_COMPAT, 'UTF-8', false) : '';
     if (!$search || mb_strlen($search) < 2) {
         return array();
     }
     $star = false;
     $address = false;
     if (substr($search, 0, 1) === '@') {
         $search = substr($search, 1);
     }
     if (substr($search, 0, 1) === '*') {
         $star = true;
         $search = substr($search, 1);
     }
     if (strpos($search, '@') !== false) {
         $address = true;
     }
     if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
         $url = z_root() . '/dirsearch';
     }
     if (!$url) {
         require_once "include/dir_fns.php";
         $directory = find_upstream_directory($dirmode);
         $url = $directory['url'] . '/dirsearch';
     }
     $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 100;
     if ($url) {
         $query = $url . '?f=';
         $query .= '&name=' . urlencode($search) . "&limit={$count}" . ($address ? '&address=' . urlencode($search) : '');
         $x = z_fetch_url($query);
         if ($x['success']) {
             $t = 0;
             $j = json_decode($x['body'], true);
             if ($j && $j['results']) {
                 return $j['results'];
             }
         }
     }
     return array();
 }
Ejemplo n.º 12
0
 function get()
 {
     // URLs:
     // photos/name
     // photos/name/album/xxxxx (xxxxx is album name)
     // photos/name/image/xxxxx
     if (observer_prohibited()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $unsafe = array_key_exists('unsafe', $_REQUEST) && $_REQUEST['unsafe'] ? 1 : 0;
     require_once 'include/bbcode.php';
     require_once 'include/security.php';
     require_once 'include/conversation.php';
     if (!x(\App::$data, 'channel')) {
         notice(t('No photos selected') . EOL);
         return;
     }
     $ph = photo_factory('');
     $phototypes = $ph->supportedTypes();
     $_SESSION['photo_return'] = \App::$cmd;
     //
     // Parse arguments
     //
     $can_comment = perm_is_allowed(\App::$profile['profile_uid'], get_observer_hash(), 'post_comments');
     if (argc() > 3) {
         $datatype = argv(2);
         $datum = argv(3);
     } else {
         if (argc() > 2) {
             $datatype = argv(2);
             $datum = '';
         } else {
             $datatype = 'summary';
         }
     }
     if (argc() > 4) {
         $cmd = argv(4);
     } else {
         $cmd = 'view';
     }
     //
     // Setup permissions structures
     //
     $can_post = false;
     $visitor = 0;
     $owner_uid = \App::$data['channel']['channel_id'];
     $owner_aid = \App::$data['channel']['channel_account_id'];
     $observer = \App::get_observer();
     $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'write_storage');
     $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_storage');
     if (!$can_view) {
         notice(t('Access to this item is restricted.') . EOL);
         return;
     }
     $sql_extra = permissions_sql($owner_uid);
     $o = "";
     $o .= "<script> var profile_uid = " . \App::$profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] . "; </script>\r\n";
     // tabs
     $_is_owner = local_channel() && local_channel() == $owner_uid;
     $o .= profile_tabs($a, $_is_owner, \App::$data['channel']['channel_address']);
     /**
      * Display upload form
      */
     if ($can_post) {
         $uploader = '';
         $ret = array('post_url' => z_root() . '/photos/' . \App::$data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true);
         call_hooks('photo_upload_form', $ret);
         /* Show space usage */
         $r = q("select sum(filesize) as total from photo where aid = %d and imgscale = 0 ", intval(\App::$data['channel']['channel_account_id']));
         $limit = engr_units_to_bytes(service_class_fetch(\App::$data['channel']['channel_id'], 'photo_upload_limit'));
         if ($limit !== false) {
             $usage_message = sprintf(t("%1\$.2f MB of %2\$.2f MB photo storage used."), $r[0]['total'] / 1024000, $limit / 1024000);
         } else {
             $usage_message = sprintf(t('%1$.2f MB photo storage used.'), $r[0]['total'] / 1024000);
         }
         if ($_is_owner) {
             $channel = \App::get_channel();
             $acl = new \Zotlabs\Access\AccessList($channel);
             $channel_acl = $acl->get();
             $lockstate = $acl->is_private() ? 'lock' : 'unlock';
         }
         $aclselect = $_is_owner ? populate_acl($channel_acl, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : '';
         // this is wrong but is to work around an issue with js_upload wherein it chokes if these variables
         // don't exist. They really should be set to a parseable representation of the channel's default permissions
         // which can be processed by getSelected()
         if (!$aclselect) {
             $aclselect = '<input id="group_allow" type="hidden" name="allow_gid[]" value="" /><input id="contact_allow" type="hidden" name="allow_cid[]" value="" /><input id="group_deny" type="hidden" name="deny_gid[]" value="" /><input id="contact_deny" type="hidden" name="deny_cid[]" value="" />';
         }
         $selname = $datum ? hex2bin($datum) : '';
         $albums = array_key_exists('albums', \App::$data) ? \App::$data['albums'] : photos_albums_list(\App::$data['channel'], \App::$data['observer']);
         if (!$selname) {
             $def_album = get_pconfig(\App::$data['channel']['channel_id'], 'system', 'photo_path');
             if ($def_album) {
                 $selname = filepath_macro($def_album);
                 $albums['album'][] = array('text' => $selname);
             }
         }
         $tpl = get_markup_template('photos_upload.tpl');
         $upload_form = replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => \App::$data['channel']['channel_address'], '$newalbum_label' => t('Enter an album name'), '$newalbum_placeholder' => t('or select an existing album (doubleclick)'), '$visible' => array('visible', t('Create a status post for this upload'), 0, '', array(t('No'), t('Yes')), 'onclick="showHideBodyTextarea();"'), '$caption' => array('description', t('Caption (optional):')), '$body' => array('body', t('Description (optional):'), '', 'Description will only appear in the status post'), '$albums' => $albums['albums'], '$selname' => $selname, '$permissions' => t('Permissions'), '$aclselect' => $aclselect, '$allow_cid' => acl2json($channel_acl['allow_cid']), '$allow_gid' => acl2json($channel_acl['allow_gid']), '$deny_cid' => acl2json($channel_acl['deny_cid']), '$deny_gid' => acl2json($channel_acl['deny_gid']), '$lockstate' => $lockstate, '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? true : false, '$uploadurl' => $ret['post_url'], '$submit' => t('Submit')));
     }
     //
     // dispatch request
     //
     /*
      * Display a single photo album
      */
     if ($datatype === 'album') {
         if (strlen($datum)) {
             if (strlen($datum) & 1 || !ctype_xdigit($datum)) {
                 notice(t('Album name could not be decoded') . EOL);
                 logger('mod_photos: illegal album encoding: ' . $datum);
                 $datum = '';
             }
         }
         $album = $datum ? hex2bin($datum) : '';
         \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$cmd) . '" title="oembed" />' . "\r\n";
         $r = q("SELECT `resource_id`, max(`imgscale`) AS `imgscale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\t\tAND `imgscale` <= 4 and photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe));
         if (count($r)) {
             \App::set_pager_total(count($r));
             \App::set_pager_itemspage(60);
         } else {
             goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address']);
         }
         if ($_GET['order'] === 'posted') {
             $order = 'ASC';
         } else {
             $order = 'DESC';
         }
         $r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN\n\t\t\t\t\t(SELECT resource_id, max(imgscale) imgscale FROM photo WHERE uid = %d AND album = '%s' AND imgscale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY resource_id) ph \n\t\t\t\t\tON (p.resource_id = ph.resource_id AND p.imgscale = ph.imgscale)\n\t\t\t\tORDER BY created {$order} LIMIT %d OFFSET %d", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
         //edit album name
         $album_edit = null;
         if ($album !== t('Profile Photos') && $album !== 'Profile Photos' && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
             if ($can_post) {
                 $album_e = $album;
                 $albums = array_key_exists('albums', \App::$data) ? \App::$data['albums'] : photos_albums_list(\App::$data['channel'], \App::$data['observer']);
                 // @fixme - syncronise actions with DAV
                 //				$edit_tpl = get_markup_template('album_edit.tpl');
                 //				$album_edit = replace_macros($edit_tpl,array(
                 //					'$nametext' => t('Enter a new album name'),
                 //					'$name_placeholder' => t('or select an existing one (doubleclick)'),
                 //					'$nickname' => \App::$data['channel']['channel_address'],
                 //					'$album' => $album_e,
                 //					'$albums' => $albums['albums'],
                 //					'$hexalbum' => bin2hex($album),
                 //					'$submit' => t('Submit'),
                 //					'$dropsubmit' => t('Delete Album')
                 //				));
             }
         }
         if ($_GET['order'] === 'posted') {
             $order = array(t('Show Newest First'), z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($album));
         } else {
             $order = array(t('Show Oldest First'), z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($album) . '?f=&order=posted');
         }
         $photos = array();
         if (count($r)) {
             $twist = 'rotright';
             foreach ($r as $rr) {
                 if ($twist == 'rotright') {
                     $twist = 'rotleft';
                 } else {
                     $twist = 'rotright';
                 }
                 $ext = $phototypes[$rr['mimetype']];
                 $imgalt_e = $rr['filename'];
                 $desc_e = $rr['description'];
                 $imagelink = z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/image/' . $rr['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
                 $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $imagelink, 'title' => t('View Photo'), 'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['imgscale'] . '.' . $ext, 'alt' => $imgalt_e, 'desc' => $desc_e, 'ext' => $ext, 'hash' => $rr['resource_id'], 'unknown' => t('Unknown'));
             }
         }
         if ($_REQUEST['aj']) {
             if ($photos) {
                 $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos, '$album_id' => bin2hex($album)));
             } else {
                 $o = '<div id="content-complete"></div>';
             }
             echo $o;
             killme();
         } else {
             $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
             $tpl = get_markup_template('photo_album.tpl');
             $o .= replace_macros($tpl, array('$photos' => $photos, '$album' => $album, '$album_id' => bin2hex($album), '$album_edit' => array(t('Edit Album'), $album_edit), '$can_post' => $can_post, '$upload' => array(t('Upload'), z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/upload/' . bin2hex($album)), '$order' => $order, '$upload_form' => $upload_form, '$usage' => $usage_message));
         }
         if (!$photos && $_REQUEST['aj']) {
             $o .= '<div id="content-complete"></div>';
             echo $o;
             killme();
         }
         //		$o .= paginate($a);
         return $o;
     }
     /** 
      * Display one photo
      */
     if ($datatype === 'image') {
         \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$cmd) . '" title="oembed" />' . "\r\n";
         // fetch image, item containing image, then comments
         $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,mimetype,height,width,filesize,imgscale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' \n\t\t\t\t{$sql_extra} ORDER BY `imgscale` ASC ", intval($owner_uid), dbesc($datum));
         if (!$ph) {
             /* Check again - this time without specifying permissions */
             $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' LIMIT 1", intval($owner_uid), dbesc($datum));
             if ($ph) {
                 notice(t('Permission denied. Access to this item may be restricted.') . EOL);
             } 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 `imgscale` = 0 \n\t\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;
                 }
             }
             $prevlink = z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
             $nextlink = z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
         }
         if (count($ph) == 1) {
             $hires = $lores = $ph[0];
         }
         if (count($ph) > 1) {
             if ($ph[1]['imgscale'] == 2) {
                 // original is 640 or less, we can display it directly
                 $hires = $lores = $ph[0];
             } else {
                 $hires = $ph[0];
                 $lores = $ph[1];
             }
         }
         $album_link = z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']);
         $tools = Null;
         $lock = Null;
         if ($can_post && $ph[0]['uid'] == $owner_uid) {
             $tools = array('profile' => array(z_root() . '/profile_photo/use/' . $ph[0]['resource_id'], t('Use as profile photo')), 'cover' => array(z_root() . '/cover_photo/use/' . $ph[0]['resource_id'], t('Use as cover photo')));
         }
         // lockstate
         $lockstate = strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']) ? array('lock', t('Private Photo')) : array('unlock', Null);
         \App::$page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n";
         if ($prevlink) {
             \App::$page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
         }
         if ($nextlink) {
             \App::$page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
         }
         \App::$page['htmlhead'] .= '});</script>';
         if ($prevlink) {
             $prevlink = array($prevlink, t('Previous'));
         }
         $photo = array('href' => z_root() . '/photo/' . $hires['resource_id'] . '-' . $hires['imgscale'] . '.' . $phototypes[$hires['mimetype']], 'title' => t('View Full Size'), 'src' => z_root() . '/photo/' . $lores['resource_id'] . '-' . $lores['imgscale'] . '.' . $phototypes[$lores['mimetype']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'));
         if ($nextlink) {
             $nextlink = array($nextlink, t('Next'));
         }
         // Do we have an item for this photo?
         $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' \n\t\t\t\t{$sql_extra} LIMIT 1", dbesc($datum));
         $map = null;
         if ($linked_items) {
             xchan_query($linked_items);
             $linked_items = fetch_post_tags($linked_items, true);
             $link_item = $linked_items[0];
             $item_normal = item_normal();
             $r = q("select * from item where parent_mid = '%s' \n\t\t\t\t\t{$item_normal} and uid = %d {$sql_extra} ", dbesc($link_item['mid']), intval($link_item['uid']));
             if ($r) {
                 xchan_query($r);
                 $r = fetch_post_tags($r, true);
                 $r = conv_sort($r, 'commented');
             }
             $tags = array();
             if ($link_item['term']) {
                 $cnt = 0;
                 foreach ($link_item['term'] as $t) {
                     $tags[$cnt] = array(0 => format_term_for_display($t));
                     if ($can_post && $ph[0]['uid'] == $owner_uid) {
                         $tags[$cnt][1] = 'tagrm/drop/' . $link_item['id'] . '/' . bin2hex($t['term']);
                         //?f=&item=' . $link_item['id'];
                         $tags[$cnt][2] = t('Remove');
                     }
                     $cnt++;
                 }
             }
             if (local_channel() && local_channel() == $link_item['uid']) {
                 q("UPDATE `item` SET item_unseen = 0 WHERE parent = %d and uid = %d and item_unseen = 1", intval($link_item['parent']), intval(local_channel()));
             }
             if ($link_item['coord']) {
                 $map = generate_map($link_item['coord']);
             }
         }
         //		logger('mod_photo: link_item' . print_r($link_item,true));
         // FIXME - remove this when we move to conversation module
         $r = $r[0]['children'];
         $edit = null;
         if ($can_post) {
             $m = q("select folder from attach where hash = '%s' and uid = %d limit 1", dbesc($ph[0]['resource_id']), intval($ph[0]['uid']));
             if ($m) {
                 $album_hash = $m[0]['folder'];
             }
             $album_e = $ph[0]['album'];
             $caption_e = $ph[0]['description'];
             $aclselect_e = $_is_owner ? populate_acl($ph[0], true, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : '';
             $albums = array_key_exists('albums', \App::$data) ? \App::$data['albums'] : photos_albums_list(\App::$data['channel'], \App::$data['observer']);
             $_SESSION['album_return'] = bin2hex($ph[0]['album']);
             $folder_list = attach_folder_select_list($ph[0]['uid']);
             $edit = array('edit' => t('Edit photo'), 'id' => $link_item['id'], 'rotatecw' => t('Rotate CW (right)'), 'rotateccw' => t('Rotate CCW (left)'), 'albums' => $albums['albums'], 'album' => $album_e, 'album_select' => ['move_to_album', t('Move photo to album'), $album_hash, '', $folder_list], 'newalbum_label' => t('Enter a new album name'), 'newalbum_placeholder' => t('or select an existing one (doubleclick)'), 'nickname' => \App::$data['channel']['channel_address'], 'resource_id' => $ph[0]['resource_id'], 'capt_label' => t('Caption'), 'caption' => $caption_e, 'tag_label' => t('Add a Tag'), 'permissions' => t('Permissions'), 'aclselect' => $aclselect_e, 'allow_cid' => acl2json($ph[0]['allow_cid']), 'allow_gid' => acl2json($ph[0]['allow_gid']), 'deny_cid' => acl2json($ph[0]['deny_cid']), 'deny_gid' => acl2json($ph[0]['deny_gid']), 'lockstate' => $lockstate[0], 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com'), 'item_id' => count($linked_items) ? $link_item['id'] : 0, 'adult_enabled' => feature_enabled($owner_uid, 'adult_photo_flagging'), 'adult' => array('adult', t('Flag as adult in album view'), intval($ph[0]['is_nsfw']), ''), 'submit' => t('Submit'), 'delete' => t('Delete Photo'));
         }
         if (count($linked_items)) {
             $cmnt_tpl = get_markup_template('comment_item.tpl');
             $tpl = get_markup_template('photo_item.tpl');
             $return_url = \App::$cmd;
             $like_tpl = get_markup_template('like_noshare.tpl');
             $likebuttons = '';
             if ($can_post || $can_comment) {
                 $likebuttons = array('id' => $link_item['id'], 'likethis' => t("I like this (toggle)"), 'nolike' => t("I don't like this (toggle)"), 'share' => t('Share'), 'wait' => t('Please wait'));
             }
             $comments = '';
             if (!count($r)) {
                 if ($can_post || $can_comment) {
                     $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => '', '$feature_encrypt' => false));
                 }
             }
             $alike = array();
             $dlike = array();
             $like = '';
             $dislike = '';
             $conv_responses = array('like' => array('title' => t('Likes', 'title')), 'dislike' => array('title' => t('Dislikes', 'title')), 'agree' => array('title' => t('Agree', 'title')), 'disagree' => array('title' => t('Disagree', 'title')), 'abstain' => array('title' => t('Abstain', 'title')), 'attendyes' => array('title' => t('Attending', 'title')), 'attendno' => array('title' => t('Not attending', 'title')), 'attendmaybe' => array('title' => t('Might attend', 'title')));
             if ($r) {
                 foreach ($r as $item) {
                     builtin_activity_puller($item, $conv_responses);
                 }
                 $like_count = x($alike, $link_item['mid']) ? $alike[$link_item['mid']] : '';
                 $like_list = x($alike, $link_item['mid']) ? $alike[$link_item['mid'] . '-l'] : '';
                 if (count($like_list) > MAX_LIKERS) {
                     $like_list_part = array_slice($like_list, 0, MAX_LIKERS);
                     array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
                 } else {
                     $like_list_part = '';
                 }
                 $like_button_label = tt('Like', 'Likes', $like_count, 'noun');
                 //if (feature_enabled($conv->get_profile_owner(),'dislike')) {
                 $dislike_count = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid']] : '';
                 $dislike_list = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid'] . '-l'] : '';
                 $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun');
                 if (count($dislike_list) > MAX_LIKERS) {
                     $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
                     array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
                 } else {
                     $dislike_list_part = '';
                 }
                 //}
                 $like = isset($alike[$link_item['mid']]) ? format_like($alike[$link_item['mid']], $alike[$link_item['mid'] . '-l'], 'like', $link_item['mid']) : '';
                 $dislike = isset($dlike[$link_item['mid']]) ? format_like($dlike[$link_item['mid']], $dlike[$link_item['mid'] . '-l'], 'dislike', $link_item['mid']) : '';
                 // display comments
                 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 = z_root() . '/redir/' . $item['cid'];
                     $profile_url = zid($item['author']['xchan_url']);
                     $sparkle = '';
                     $profile_name = $item['author']['xchan_name'];
                     $profile_avatar = $item['author']['xchan_photo_m'];
                     $profile_link = $profile_url;
                     $drop = '';
                     if ($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) {
                         $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
                     }
                     $name_e = $profile_name;
                     $title_e = $item['title'];
                     unobscure($item);
                     $body_e = prepare_text($item['body'], $item['mimetype']);
                     $comments .= replace_macros($template, array('$id' => $item['id'], '$mode' => 'photos', '$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['id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                 }
                 if ($can_post || $can_comment) {
                     $commentbox = 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' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => ''));
                 }
             }
             $paginate = paginate($a);
         }
         $album_e = array($album_link, $ph[0]['album']);
         $like_e = $like;
         $dislike_e = $dislike;
         $response_verbs = array('like');
         if (feature_enabled($owner_uid, 'dislike')) {
             $response_verbs[] = 'dislike';
         }
         $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
         $photo_tpl = get_markup_template('photo_view.tpl');
         $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools_label' => t('Photo Tools'), '$tools' => $tools, '$lock' => $lockstate[1], '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['description'], '$filename' => $ph[0]['filename'], '$unknown' => t('Unknown'), '$tag_hdr' => t('In This Photo:'), '$tags' => $tags, 'responses' => $responses, '$edit' => $edit, '$map' => $map, '$map_text' => t('Map'), '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dislike_e, '$like_count' => $like_count, '$like_list' => $like_list, '$like_list_part' => $like_list_part, '$like_button_label' => $like_button_label, '$like_modal_title' => t('Likes', 'noun'), '$dislike_modal_title' => t('Dislikes', 'noun'), '$dislike_count' => $dislike_count, '$dislike_list' => $dislike_list, '$dislike_list_part' => $dislike_list_part, '$dislike_button_label' => $dislike_button_label, '$modal_dismiss' => t('Close'), '$comments' => $comments, '$commentbox' => $commentbox, '$paginate' => $paginate));
         \App::$data['photo_html'] = $o;
         return $o;
     }
     // Default - show recent photos with upload link (if applicable)
     //$o = '';
     \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$cmd) . '" title="oembed" />' . "\r\n";
     $r = q("SELECT `resource_id`, max(`imgscale`) AS `imgscale` FROM `photo` WHERE `uid` = %d \n\t\t\tand photo_usage in ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval(\App::$data['channel']['channel_id']), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe));
     if ($r) {
         \App::set_pager_total(count($r));
         \App::set_pager_itemspage(60);
     }
     $r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.album, p.imgscale, p.created FROM photo p \n\t\t\tINNER JOIN ( SELECT resource_id, max(imgscale) imgscale FROM photo \n\t\t\t\tWHERE uid = %d AND photo_usage IN ( %d, %d ) \n\t\t\t\tAND is_nsfw = %d {$sql_extra} group by resource_id ) ph \n\t\t\tON (p.resource_id = ph.resource_id and p.imgscale = ph.imgscale) \n\t\t\tORDER by p.created DESC LIMIT %d OFFSET %d", intval(\App::$data['channel']['channel_id']), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     $photos = array();
     if ($r) {
         $twist = 'rotright';
         foreach ($r as $rr) {
             if ($twist == 'rotright') {
                 $twist = 'rotleft';
             } else {
                 $twist = 'rotright';
             }
             $ext = $phototypes[$rr['mimetype']];
             if (\App::get_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' => z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . ($rr['imgscale'] == 6 ? 4 : $rr['imgscale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
         }
     }
     if ($_REQUEST['aj']) {
         if ($photos) {
             $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos, '$album_id' => bin2hex(t('Recent Photos'))));
         } else {
             $o = '<div id="content-complete"></div>';
         }
         echo $o;
         killme();
     } else {
         $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
         $tpl = get_markup_template('photos_recent.tpl');
         $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$album_id' => bin2hex(t('Recent Photos')), '$can_post' => $can_post, '$upload' => array(t('Upload'), z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/upload'), '$photos' => $photos, '$upload_form' => $upload_form, '$usage' => $usage_message));
     }
     if (!$photos && $_REQUEST['aj']) {
         $o .= '<div id="content-complete"></div>';
         echo $o;
         killme();
     }
     //	paginate($a);
     return $o;
 }
Ejemplo n.º 13
0
function widget_shortprofile($arr)
{
    if (!App::$profile['profile_uid']) {
        return;
    }
    $block = observer_prohibited();
    return profile_sidebar(App::$profile, $block, true, true);
}
Ejemplo n.º 14
0
 function get()
 {
     if (observer_prohibited(true)) {
         return login();
     }
     if (!feature_enabled(\App::$profile_uid, 'wiki')) {
         notice(t('Not found') . EOL);
         return;
     }
     $tab = 'wiki';
     require_once 'include/wiki.php';
     require_once 'include/acl_selectors.php';
     require_once 'include/conversation.php';
     // TODO: Combine the interface configuration into a unified object
     // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
     $wiki_owner = false;
     $showNewWikiButton = false;
     $showCommitMsg = false;
     $hidePageHistory = false;
     $pageHistory = array();
     $local_observer = null;
     $resource_id = '';
     // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1
     $nick = argv(1);
     $channel = get_channel_by_nick($nick);
     // The channel who owns the wikis being viewed
     if (!$channel) {
         notice('Invalid channel' . EOL);
         goaway('/' . argv(0));
     }
     // Determine if the observer is the channel owner so the ACL dialog can be populated
     if (local_channel() === intval($channel['channel_id'])) {
         $local_observer = \App::get_channel();
         $wiki_owner = true;
         // Obtain the default permission settings of the channel
         $channel_acl = array('allow_cid' => $local_observer['channel_allow_cid'], 'allow_gid' => $local_observer['channel_allow_gid'], 'deny_cid' => $local_observer['channel_deny_cid'], 'deny_gid' => $local_observer['channel_deny_gid']);
         // Initialize the ACL to the channel default permissions
         $x = array('lockstate' => $local_observer['channel_allow_cid'] || $local_observer['channel_allow_gid'] || $local_observer['channel_deny_cid'] || $local_observer['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '');
     } else {
         // Not the channel owner
         $channel_acl = $x = array();
     }
     switch (argc()) {
         case 2:
             // Configure page template
             $wikiheaderName = t('Wiki');
             $wikiheaderPage = t('Sandbox');
             require_once 'library/markdown.php';
             $content = t('"# Wiki Sandbox\\n\\nContent you **edit** and **preview** here *will not be saved*."');
             $renderedContent = Markdown(json_decode($content));
             $hide_editor = false;
             $showPageControls = false;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = false;
             $hidePageHistory = true;
             $showCommitMsg = false;
             break;
         case 3:
             // /wiki/channel/wiki -> No page was specified, so redirect to Home.md
             $wikiUrlName = urlencode(argv(2));
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/Home');
         case 4:
             // GET /wiki/channel/wiki/page
             // Fetch the wiki info and determine observer permissions
             $wikiUrlName = urlencode(argv(2));
             $pageUrlName = urlencode(argv(3));
             $w = wiki_exists_by_name($channel['channel_id'], $wikiUrlName);
             if (!$w['resource_id']) {
                 notice('Wiki not found' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1));
             }
             $resource_id = $w['resource_id'];
             if (!$wiki_owner) {
                 // Check for observer permissions
                 $observer_hash = get_observer_hash();
                 $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
                 if (!$perms['read']) {
                     notice('Permission denied.' . EOL);
                     goaway('/' . argv(0) . '/' . argv(1));
                 }
                 if ($perms['write']) {
                     $wiki_editor = true;
                 } else {
                     $wiki_editor = false;
                 }
             } else {
                 $wiki_editor = true;
             }
             $wikiheaderName = urldecode($wikiUrlName);
             $wikiheaderPage = urldecode($pageUrlName);
             $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             if (!$p['success']) {
                 notice('Error retrieving page content' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             }
             $content = $p['content'] !== '' ? htmlspecialchars_decode($p['content'], ENT_COMPAT) : '"# New page\\n"';
             // Render the Markdown-formatted page content in HTML
             require_once 'library/markdown.php';
             $html = wiki_generate_toc(purify_html(Markdown(json_decode($content))));
             $renderedContent = wiki_convert_links($html, argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             $hide_editor = false;
             $showPageControls = $wiki_editor;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = $wiki_editor;
             $hidePageHistory = false;
             $showCommitMsg = true;
             $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             break;
         default:
             // Strip the extraneous URL components
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/' . $pageUrlName);
     }
     $wikiModalID = random_string(3);
     $wikiModal = replace_macros(get_markup_template('generic_modal.tpl'), array('$id' => $wikiModalID, '$title' => t('Revision Comparison'), '$ok' => t('Revert'), '$cancel' => t('Cancel')));
     $is_owner = local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false;
     $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
     $o .= replace_macros(get_markup_template('wiki.tpl'), array('$wikiheaderName' => $wikiheaderName, '$wikiheaderPage' => $wikiheaderPage, '$hideEditor' => $hide_editor, '$showPageControls' => $showPageControls, '$showNewWikiButton' => $showNewWikiButton, '$showNewPageButton' => $showNewPageButton, '$hidePageHistory' => $hidePageHistory, '$showCommitMsg' => $showCommitMsg, '$channel' => $channel['channel_address'], '$resource_id' => $resource_id, '$page' => $pageUrlName, '$lockstate' => $x['lockstate'], '$acl' => $x['acl'], '$bang' => $x['bang'], '$content' => $content, '$renderedContent' => $renderedContent, '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''), '$pageRename' => array('pageRename', t('Enter the new name:'), '', ''), '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'), '$pageHistory' => $pageHistory['history'], '$wikiModal' => $wikiModal, '$wikiModalID' => $wikiModalID, '$commit' => 'HEAD', '$embedPhotos' => t('Embed image from photo albums'), '$embedPhotosModalTitle' => t('Embed an image from your albums'), '$embedPhotosModalCancel' => t('Cancel'), '$embedPhotosModalOK' => t('OK'), '$modalchooseimages' => t('Choose images to embed'), '$modalchoosealbum' => t('Choose an album'), '$modaldiffalbum' => t('Choose a different album...'), '$modalerrorlist' => t('Error getting album list'), '$modalerrorlink' => t('Error getting photo link'), '$modalerroralbum' => t('Error getting album')));
     head_add_js('library/ace/ace.js');
     // Ace Code Editor
     return $o;
 }
Ejemplo n.º 15
0
 function get()
 {
     if (observer_prohibited()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $observer = get_observer_hash();
     $globaldir = get_directory_setting($observer, 'globaldir');
     // override your personal global search pref if we're doing a navbar search of the directory
     if (intval($_REQUEST['navsearch'])) {
         $globaldir = 1;
     }
     $safe_mode = get_directory_setting($observer, 'safemode');
     $pubforums = get_directory_setting($observer, 'pubforums');
     $o = '';
     nav_set_selected('directory');
     if (x($_POST, 'search')) {
         $search = notags(trim($_POST['search']));
     } else {
         $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
     }
     if (strpos($search, '=') && local_channel() && feature_enabled(local_channel(), 'advanced_dirsearch')) {
         $advanced = $search;
     }
     $keywords = $_GET['keywords'] ? $_GET['keywords'] : '';
     // Suggest channels if no search terms or keywords are given
     $suggest = local_channel() && x($_REQUEST, 'suggest') ? $_REQUEST['suggest'] : '';
     if ($suggest) {
         $r = suggestion_query(local_channel(), get_observer_hash());
         // Remember in which order the suggestions were
         $addresses = array();
         $common = array();
         $index = 0;
         foreach ($r as $rr) {
             $common[$rr['xchan_addr']] = $rr['total'];
             $addresses[$rr['xchan_addr']] = $index++;
         }
         // Build query to get info about suggested people
         $advanced = '';
         foreach (array_keys($addresses) as $address) {
             $advanced .= "address=\"{$address}\" ";
         }
         // Remove last space in the advanced query
         $advanced = rtrim($advanced);
     }
     $tpl = get_markup_template('directory_header.tpl');
     $dirmode = intval(get_config('system', 'directory_mode'));
     if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
         $url = z_root() . '/dirsearch';
     }
     if (!$url) {
         $directory = find_upstream_directory($dirmode);
         if (!$directory || !array_key_exists('url', $directory) || !$directory['url']) {
             logger('CRITICAL: No directory server URL');
         }
         $url = $directory['url'] . '/dirsearch';
     }
     $token = get_config('system', 'realm_token');
     logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
     $contacts = array();
     if (local_channel()) {
         $x = q("select abook_xchan from abook where abook_channel = %d", intval(local_channel()));
         if ($x) {
             foreach ($x as $xx) {
                 $contacts[] = $xx['abook_xchan'];
             }
         }
     }
     if ($url) {
         $numtags = get_config('system', 'directorytags');
         $kw = intval($numtags) > 0 ? intval($numtags) : 50;
         if (get_config('system', 'disable_directory_keywords')) {
             $kw = 0;
         }
         $query = $url . '?f=&kw=' . $kw . ($safe_mode != 1 ? '&safe=' . $safe_mode : '');
         if ($token) {
             $query .= '&t=' . $token;
         }
         if (!$globaldir) {
             $query .= '&hub=' . \App::get_hostname();
         }
         if ($search) {
             $query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
         }
         if (strpos($search, '@')) {
             $query .= '&address=' . urlencode($search);
         }
         if ($keywords) {
             $query .= '&keywords=' . urlencode($keywords);
         }
         if ($advanced) {
             $query .= '&query=' . urlencode($advanced);
         }
         if (!is_null($pubforums)) {
             $query .= '&pubforums=' . intval($pubforums);
         }
         $directory_sort_order = get_config('system', 'directory_sort_order');
         if (!$directory_sort_order) {
             $directory_sort_order = 'date';
         }
         $sort_order = x($_REQUEST, 'order') ? $_REQUEST['order'] : $directory_sort_order;
         if ($sort_order) {
             $query .= '&order=' . urlencode($sort_order);
         }
         if (\App::$pager['page'] != 1) {
             $query .= '&p=' . \App::$pager['page'];
         }
         logger('mod_directory: query: ' . $query);
         $x = z_fetch_url($query);
         logger('directory: return from upstream: ' . print_r($x, true), LOGGER_DATA);
         if ($x['success']) {
             $t = 0;
             $j = json_decode($x['body'], true);
             if ($j) {
                 if ($j['results']) {
                     $entries = array();
                     $photo = 'thumb';
                     foreach ($j['results'] as $rr) {
                         $profile_link = chanlink_url($rr['url']);
                         $pdesc = $rr['description'] ? $rr['description'] . '<br />' : '';
                         $connect_link = local_channel() ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '';
                         // Checking status is disabled ATM until someone checks the performance impact more carefully
                         //$online = remote_online_status($rr['address']);
                         $online = '';
                         if (in_array($rr['hash'], $contacts)) {
                             $connect_link = '';
                         }
                         $location = '';
                         if (strlen($rr['locale'])) {
                             $location .= $rr['locale'];
                         }
                         if (strlen($rr['region'])) {
                             if (strlen($rr['locale'])) {
                                 $location .= ', ';
                             }
                             $location .= $rr['region'];
                         }
                         if (strlen($rr['country'])) {
                             if (strlen($location)) {
                                 $location .= ', ';
                             }
                             $location .= $rr['country'];
                         }
                         $age = '';
                         if (strlen($rr['birthday'])) {
                             if (($years = age($rr['birthday'], 'UTC', '')) != 0) {
                                 $age = $years;
                             }
                         }
                         $page_type = '';
                         $rating_enabled = get_config('system', 'rating_enabled');
                         if ($rr['total_ratings'] && $rating_enabled) {
                             $total_ratings = sprintf(tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']);
                         } else {
                             $total_ratings = '';
                         }
                         $profile = $rr;
                         if (x($profile, 'locale') == 1 || x($profile, 'region') == 1 || x($profile, 'postcode') == 1 || x($profile, 'country') == 1) {
                             $gender = x($profile, 'gender') == 1 ? t('Gender: ') . $profile['gender'] : False;
                         }
                         $marital = x($profile, 'marital') == 1 ? t('Status: ') . $profile['marital'] : False;
                         $homepage = x($profile, 'homepage') == 1 ? t('Homepage: ') : False;
                         $homepageurl = x($profile, 'homepage') == 1 ? $profile['homepage'] : '';
                         $hometown = x($profile, 'hometown') == 1 ? $profile['hometown'] : False;
                         $about = x($profile, 'about') == 1 ? bbcode($profile['about']) : False;
                         $keywords = x($profile, 'keywords') ? $profile['keywords'] : '';
                         $out = '';
                         if ($keywords) {
                             $keywords = str_replace(',', ' ', $keywords);
                             $keywords = str_replace('  ', ' ', $keywords);
                             $karr = explode(' ', $keywords);
                             if ($karr) {
                                 if (local_channel()) {
                                     $r = q("select keywords from profile where uid = %d and is_default = 1 limit 1", intval(local_channel()));
                                     if ($r) {
                                         $keywords = str_replace(',', ' ', $r[0]['keywords']);
                                         $keywords = str_replace('  ', ' ', $keywords);
                                         $marr = explode(' ', $keywords);
                                     }
                                 }
                                 foreach ($karr as $k) {
                                     if (strlen($out)) {
                                         $out .= ', ';
                                     }
                                     if ($marr && in_arrayi($k, $marr)) {
                                         $out .= '<strong>' . $k . '</strong>';
                                     } else {
                                         $out .= $k;
                                     }
                                 }
                             }
                         }
                         $entry = array('id' => ++$t, 'profile_link' => $profile_link, 'public_forum' => $rr['public_forum'], 'photo' => $rr['photo'], 'hash' => $rr['hash'], 'alttext' => $rr['name'] . (local_channel() || remote_channel() ? ' ' . $rr['address'] : ''), 'name' => $rr['name'], 'age' => $age, 'age_label' => t('Age:'), 'profile' => $profile, 'address' => $rr['address'], 'nickname' => substr($rr['address'], 0, strpos($rr['address'], '@')), 'location' => $location, 'location_label' => t('Location:'), 'gender' => $gender, 'total_ratings' => $total_ratings, 'viewrate' => true, 'canrate' => $rating_enabled && local_channel() ? true : false, 'pdesc' => $pdesc, 'pdesc_label' => t('Description:'), 'marital' => $marital, 'homepage' => $homepage, 'homepageurl' => linkify($homepageurl), 'hometown' => $hometown, 'hometown_label' => t('Hometown:'), 'about' => $about, 'about_label' => t('About:'), 'conn_label' => t('Connect'), 'forum_label' => t('Public Forum:'), 'connect' => $connect_link, 'online' => $online, 'kw' => $out ? t('Keywords: ') : '', 'keywords' => $out, 'ignlink' => $suggest ? z_root() . '/directory?ignore=' . $rr['hash'] : '', 'ignore_label' => t('Don\'t suggest'), 'common_friends' => $common[$rr['address']] ? intval($common[$rr['address']]) : '', 'common_label' => t('Common connections:'), 'common_count' => intval($common[$rr['address']]), 'safe' => $safe_mode);
                         $arr = array('contact' => $rr, 'entry' => $entry);
                         call_hooks('directory_item', $arr);
                         unset($profile);
                         unset($location);
                         if (!$arr['entry']) {
                             continue;
                         }
                         if ($sort_order == '' && $suggest) {
                             $entries[$addresses[$rr['address']]] = $arr['entry'];
                             // Use the same indexes as originally to get the best suggestion first
                         } else {
                             $entries[] = $arr['entry'];
                         }
                     }
                     ksort($entries);
                     // Sort array by key so that foreach-constructs work as expected
                     if ($j['keywords']) {
                         \App::$data['directory_keywords'] = $j['keywords'];
                     }
                     logger('mod_directory: entries: ' . print_r($entries, true), LOGGER_DATA);
                     if ($_REQUEST['aj']) {
                         if ($entries) {
                             $o = replace_macros(get_markup_template('directajax.tpl'), array('$entries' => $entries));
                         } else {
                             $o = '<div id="content-complete"></div>';
                         }
                         echo $o;
                         killme();
                     } else {
                         $maxheight = 94;
                         $dirtitle = $globaldir ? t('Global Directory') : t('Local Directory');
                         $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; divmore_height = " . intval($maxheight) . ";  </script>";
                         $o .= replace_macros($tpl, array('$search' => $search, '$desc' => t('Find'), '$finddsc' => t('Finding:'), '$safetxt' => htmlspecialchars($search, ENT_QUOTES, 'UTF-8'), '$entries' => $entries, '$dirlbl' => $suggest ? t('Channel Suggestions') : $dirtitle, '$submit' => t('Find'), '$next' => alt_pager($a, $j['records'], t('next page'), t('previous page')), '$sort' => t('Sort options'), '$normal' => t('Alphabetic'), '$reverse' => t('Reverse Alphabetic'), '$date' => t('Newest to Oldest'), '$reversedate' => t('Oldest to Newest'), '$suggest' => $suggest ? '&suggest=1' : ''));
                     }
                 } else {
                     if ($_REQUEST['aj']) {
                         $o = '<div id="content-complete"></div>';
                         echo $o;
                         killme();
                     }
                     if (\App::$pager['page'] == 1 && $j['records'] == 0 && strpos($search, '@')) {
                         goaway(z_root() . '/chanview/?f=&address=' . $search);
                     }
                     info(t("No entries (some entries may be hidden).") . EOL);
                 }
             }
         }
     }
     return $o;
 }
Ejemplo n.º 16
0
 function get($update = 0, $load = false)
 {
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     if (observer_prohibited(true)) {
         return login();
     }
     if (get_config('system', 'disable_discover_tab')) {
         return;
     }
     $item_normal = item_normal();
     if (!$update) {
         $maxheight = get_config('system', 'home_divmore_height');
         if (!$maxheight) {
             $maxheight = 400;
         }
         $o .= '<div id="live-pubstream"></div>' . "\r\n";
         $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; var profile_page = " . \App::$pager['page'] . "; divmore_height = " . intval($maxheight) . "; </script>\r\n";
         \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'pubstream', '$uid' => local_channel() ? local_channel() : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '99', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$fh' => '1', '$nouveau' => '0', '$wall' => '0', '$list' => '0', '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$search' => '', '$order' => 'comment', '$file' => '', '$cats' => '', '$tags' => '', '$dend' => '', '$mid' => '', '$verb' => '', '$dbegin' => ''));
     }
     if ($update && !$load) {
         // only setup pagination on initial page view
         $pager_sql = '';
     } else {
         \App::set_pager_itemspage(20);
         $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     }
     require_once 'include/channel.php';
     require_once 'include/security.php';
     if (get_config('system', 'site_firehose')) {
         $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0  and item_wall = 1 ";
     } else {
         $sys = get_sys_channel();
         $uids = " and item.uid  = " . intval($sys['channel_id']) . " ";
         $sql_extra = item_permissions_sql($sys['channel_id']);
         \App::$data['firehose'] = intval($sys['channel_id']);
     }
     if (get_config('system', 'public_list_mode')) {
         $page_mode = 'list';
     } else {
         $page_mode = 'client';
     }
     $simple_update = $update ? " and item.item_unseen = 1 " : '';
     if ($update && $_SESSION['loadtime']) {
         $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
     }
     if ($load) {
         $simple_update = '';
     }
     //logger('update: ' . $update . ' load: ' . $load);
     if ($update) {
         $ordering = "commented";
         if ($load) {
             // Fetch a page full of parent items for this page
             $r = q("SELECT distinct item.id AS item_id, {$ordering} FROM item\n\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\t\tAND item.parent = item.id\n\t\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}\n\t\t\t\t\tORDER BY {$ordering} DESC {$pager_sql} ");
         } elseif ($update) {
             $r = q("SELECT distinct item.id AS item_id, {$ordering} FROM item\n\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\t\tAND item.parent = item.id {$simple_update}\n\t\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}");
             $_SESSION['loadtime'] = datetime_convert();
         }
         // Then fetch all the children of the parents that are on this page
         $parents_str = '';
         $update_unseen = '';
         if ($r) {
             $parents_str = ids_to_querystr($r, 'item_id');
             $items = q("SELECT item.*, item.id AS item_id FROM item\n\t\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\t\tAND item.parent IN ( %s )\n\t\t\t\t\t{$sql_extra} ", dbesc($parents_str));
             xchan_query($items, true, -1);
             $items = fetch_post_tags($items, true);
             $items = conv_sort($items, $ordering);
         } else {
             $items = array();
         }
     }
     // fake it
     $mode = 'network';
     $o .= conversation($a, $items, $mode, $update, $page_mode);
     if ($items && !$update) {
         $o .= alt_pager($a, count($items));
     }
     return $o;
 }