Esempio n. 1
0
function search_doc_files($s)
{
    $a = get_app();
    $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']));
    $regexop = db_getfunc('REGEXP');
    $r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and\n\t\tbody {$regexop} '%s' and item_type = %d {$pager_sql}", dbesc($s), intval(ITEM_TYPE_DOC));
    $r = fetch_post_tags($r, true);
    for ($x = 0; $x < count($r); $x++) {
        $r[$x]['text'] = $r[$x]['body'];
        $r[$x]['rank'] = 0;
        if ($r[$x]['term']) {
            foreach ($r[$x]['term'] as $t) {
                if (stristr($t['term'], $s)) {
                    $r[$x]['rank']++;
                }
            }
        }
        if (stristr($r[$x]['sid'], $s)) {
            $r[$x]['rank']++;
        }
        $r[$x]['rank'] += substr_count(strtolower($r[$x]['text']), strtolower($s));
        // bias the results to the observer's native language
        if ($r[$x]['lang'] === App::$language) {
            $r[$x]['rank'] = $r[$x]['rank'] + 10;
        }
    }
    usort($r, 'doc_rank_sort');
    return $r;
}
Esempio n. 2
0
/**
 * @brief Controller for /match.
 *
 * It takes keywords from your profile and queries the directory server for
 * matching keywords from other profiles.
 *
 * @FIXME this has never been properly ported from Friendica.
 *
 * @param App &$a
 * @return void|string
 */
function match_content(&$a)
{
    $o = '';
    if (!local_channel()) {
        return;
    }
    $_SESSION['return_url'] = z_root() . '/' . App::$cmd;
    $o .= '<h2>' . t('Profile Match') . '</h2>';
    $r = q("SELECT `keywords` FROM `profile` WHERE `is_default` = 1 AND `uid` = %d LIMIT 1", intval(local_channel()));
    if (!count($r)) {
        return;
    }
    if (!$r[0]['keywords']) {
        notice(t('No keywords to match. Please add keywords to your default profile.') . EOL);
        return;
    }
    $params = array();
    $tags = trim($r[0]['keywords']);
    if ($tags) {
        $params['s'] = $tags;
        if (App::$pager['page'] != 1) {
            $params['p'] = App::$pager['page'];
        }
        //		if(strlen(get_config('system','directory_submit_url')))
        //			$x = post_url('http://dir.friendica.com/msearch', $params);
        //		else
        //			$x = post_url(z_root() . '/msearch', $params);
        $j = json_decode($x);
        if ($j->total) {
            App::set_pager_total($j->total);
            App::set_pager_itemspage($j->items_page);
        }
        if (count($j->results)) {
            $tpl = get_markup_template('match.tpl');
            foreach ($j->results as $jj) {
                $connlnk = z_root() . '/follow/?url=' . $jj->url;
                $o .= replace_macros($tpl, array('$url' => zid($jj->url), '$name' => $jj->name, '$photo' => $jj->photo, '$inttxt' => ' ' . t('is interested in:'), '$conntxt' => t('Connect'), '$connlnk' => $connlnk, '$tags' => $jj->tags));
            }
        } else {
            info(t('No matches') . EOL);
        }
    }
    $o .= cleardiv();
    $o .= paginate($a);
    return $o;
}
Esempio n. 3
0
 function init()
 {
     \App::set_pager_itemspage(60);
     if (x($_GET, 'ignore')) {
         q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ", intval(local_channel()), dbesc($_GET['ignore']));
         goaway(z_root() . '/directory?suggest=1');
     }
     $observer = get_observer_hash();
     $global_changed = false;
     $safe_changed = false;
     $pubforums_changed = false;
     if (array_key_exists('global', $_REQUEST)) {
         $globaldir = intval($_REQUEST['global']);
         $global_changed = true;
     }
     if ($global_changed) {
         $_SESSION['globaldir'] = $globaldir;
         if ($observer) {
             set_xconfig($observer, 'directory', 'globaldir', $globaldir);
         }
     }
     if (array_key_exists('safe', $_REQUEST)) {
         $safemode = intval($_REQUEST['safe']);
         $safe_changed = true;
     }
     if ($safe_changed) {
         $_SESSION['safemode'] = $safemode;
         if ($observer) {
             set_xconfig($observer, 'directory', 'safemode', $safemode);
         }
     }
     if (array_key_exists('pubforums', $_REQUEST)) {
         $pubforums = intval($_REQUEST['pubforums']);
         $pubforums_changed = true;
     }
     if ($pubforums_changed) {
         $_SESSION['pubforums'] = $pubforums;
         if ($observer) {
             set_xconfig($observer, 'directory', 'pubforums', $pubforums);
         }
     }
 }
Esempio n. 4
0
 function get($update = 0, $load = false)
 {
     if (!local_channel()) {
         $_SESSION['return_url'] = \App::$query_string;
         return login(false);
     }
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     $arr = array('query' => \App::$query_string);
     call_hooks('network_content_init', $arr);
     $channel = \App::get_channel();
     $item_normal = item_normal();
     $datequery = $datequery2 = '';
     $group = 0;
     $nouveau = false;
     $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']) : '';
     $nouveau = x($_GET, 'new') ? intval($_GET['new']) : 0;
     $gid = x($_GET, 'gid') ? intval($_GET['gid']) : 0;
     $category = x($_REQUEST, 'cat') ? $_REQUEST['cat'] : '';
     $hashtags = x($_REQUEST, 'tag') ? $_REQUEST['tag'] : '';
     $verb = x($_REQUEST, 'verb') ? $_REQUEST['verb'] : '';
     $search = $_GET['search'] ? $_GET['search'] : '';
     if ($search) {
         if (strpos($search, '@') === 0) {
             $r = q("select abook_id from abook left join xchan on abook_xchan = xchan_hash where xchan_name = '%s' and abook_channel = %d limit 1", dbesc(substr($search, 1)), intval(local_channel()));
             if ($r) {
                 $_GET['cid'] = $r[0]['abook_id'];
                 $search = $_GET['search'] = '';
             }
         } elseif (strpos($search, '#') === 0) {
             $hashtags = substr($search, 1);
             $search = $_GET['search'] = '';
         }
     }
     if ($datequery) {
         $_GET['order'] = 'post';
     }
     // filter by collection (e.g. group)
     if ($gid) {
         $r = q("SELECT * FROM groups WHERE id = %d AND uid = %d LIMIT 1", intval($gid), intval(local_channel()));
         if (!$r) {
             if ($update) {
                 killme();
             }
             notice(t('No such group') . EOL);
             goaway(z_root() . '/network');
             // NOTREACHED
         }
         $group = $gid;
         $group_hash = $r[0]['hash'];
         $def_acl = array('allow_gid' => '<' . $r[0]['hash'] . '>');
     }
     $o = '';
     // if no tabs are selected, defaults to comments
     $cid = x($_GET, 'cid') ? intval($_GET['cid']) : 0;
     $star = x($_GET, 'star') ? intval($_GET['star']) : 0;
     $order = x($_GET, 'order') ? notags($_GET['order']) : 'comment';
     $liked = x($_GET, 'liked') ? intval($_GET['liked']) : 0;
     $conv = x($_GET, 'conv') ? intval($_GET['conv']) : 0;
     $spam = x($_GET, 'spam') ? intval($_GET['spam']) : 0;
     $cmin = x($_GET, 'cmin') ? intval($_GET['cmin']) : 0;
     $cmax = x($_GET, 'cmax') ? intval($_GET['cmax']) : 99;
     $firehose = x($_GET, 'fh') ? intval($_GET['fh']) : 0;
     $file = x($_GET, 'file') ? $_GET['file'] : '';
     $deftag = '';
     if (x($_GET, 'search') || x($_GET, 'file')) {
         $nouveau = true;
     }
     if ($cid) {
         $r = q("SELECT abook_xchan FROM abook WHERE abook_id = %d AND abook_channel = %d LIMIT 1", intval($cid), intval(local_channel()));
         if (!$r) {
             if ($update) {
                 killme();
             }
             notice(t('No such channel') . EOL);
             goaway(z_root() . '/network');
             // NOTREACHED
         }
         if ($_GET['pf'] === '1') {
             $deftag = '@' . t('forum') . '+' . intval($cid) . '+';
         } else {
             $def_acl = array('allow_cid' => '<' . $r[0]['abook_xchan'] . '>');
         }
     }
     if (!$update) {
         $tabs = network_tabs();
         $o .= $tabs;
         // search terms header
         if ($search) {
             $o .= replace_macros(get_markup_template("section_title.tpl"), array('$title' => t('Search Results For:') . ' ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8')));
         }
         nav_set_selected('network');
         $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']);
         $private_editing = ($group || $cid) && !intval($_GET['pf']) ? true : false;
         $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' => $private_editing || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($private_editing ? $def_acl : $channel_acl, true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post'), 'bang' => $private_editing ? '!' : '', 'visitor' => true, 'profile_uid' => local_channel(), 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true);
         if ($deftag) {
             $x['pretext'] = $deftag;
         }
         $status_editor = status_editor($a, $x);
         $o .= $status_editor;
     }
     // We don't have to deal with ACL's on this page. You're looking at everything
     // that belongs to you, hence you can see all of it. We will filter by group if
     // desired.
     $sql_options = $star ? " and item_starred = 1 " : '';
     $sql_nets = '';
     $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE item_thread_top = 1 {$sql_options} ) ";
     if ($group) {
         $contact_str = '';
         $contacts = group_get_members($group);
         if ($contacts) {
             foreach ($contacts as $c) {
                 if ($contact_str) {
                     $contact_str .= ',';
                 }
                 $contact_str .= "'" . $c['xchan'] . "'";
             }
         } else {
             $contact_str = ' 0 ';
             info(t('Privacy group is empty'));
         }
         $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true {$sql_options} AND (( author_xchan IN ( {$contact_str} ) OR owner_xchan in ( {$contact_str} )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent {$item_normal} ) ";
         $x = group_rec_byhash(local_channel(), $group_hash);
         if ($x) {
             $title = replace_macros(get_markup_template("section_title.tpl"), array('$title' => t('Privacy group: ') . $x['name']));
         }
         $o = $tabs;
         $o .= $title;
         $o .= $status_editor;
     } elseif ($cid) {
         $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and abook_blocked = 0 limit 1", intval($cid), intval(local_channel()));
         if ($r) {
             $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true {$sql_options} AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) {$item_normal} ) ";
             $title = replace_macros(get_markup_template("section_title.tpl"), array('$title' => '<a href="' . zid($r[0]['xchan_url']) . '" ><img src="' . zid($r[0]['xchan_photo_s']) . '" alt="' . urlencode($r[0]['xchan_name']) . '" /></a> <a href="' . zid($r[0]['xchan_url']) . '" >' . $r[0]['xchan_name'] . '</a>'));
             $o = $tabs;
             $o .= $title;
             $o .= $status_editor;
         } else {
             notice(t('Invalid connection.') . EOL);
             goaway(z_root() . '/network');
         }
     }
     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 (!$update) {
         // The special div is needed for liveUpdate to kick in for this page.
         // We only launch liveUpdate if you aren't filtering in some incompatible
         // way and also you aren't writing a comment (discovered in javascript).
         if ($gid || $cid || $cmin || $cmax != 99 || $star || $liked || $conv || $spam || $nouveau || $list) {
             $firehose = 0;
         }
         $maxheight = get_pconfig(local_channel(), 'system', 'network_divmore_height');
         if (!$maxheight) {
             $maxheight = 400;
         }
         $o .= '<div id="live-network"></div>' . "\r\n";
         $o .= "<script> var profile_uid = " . local_channel() . "; 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' => 'network', '$uid' => local_channel() ? local_channel() : '0', '$gid' => $gid ? $gid : '0', '$cid' => $cid ? $cid : '0', '$cmin' => $cmin ? $cmin : '0', '$cmax' => $cmax ? $cmax : '0', '$star' => $star ? $star : '0', '$liked' => $liked ? $liked : '0', '$conv' => $conv ? $conv : '0', '$spam' => $spam ? $spam : '0', '$fh' => $firehose ? $firehose : '0', '$nouveau' => $nouveau ? $nouveau : '0', '$wall' => '0', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$search' => $search ? $search : '', '$order' => $order, '$file' => $file, '$cats' => $category, '$tags' => $hashtags, '$dend' => $datequery, '$mid' => '', '$verb' => $verb, '$dbegin' => $datequery2));
     }
     $sql_extra3 = '';
     if ($datequery) {
         $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
     }
     if ($datequery2) {
         $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
     }
     $sql_extra2 = $nouveau ? '' : " AND item.parent = item.id ";
     $sql_extra3 = $nouveau ? '' : $sql_extra3;
     if (x($_GET, 'search')) {
         $search = escape_tags($_GET['search']);
         if (strpos($search, '#') === 0) {
             $sql_extra .= term_query('item', substr($search, 1), TERM_HASHTAG, TERM_COMMUNITYTAG);
         } else {
             $sql_extra .= sprintf(" AND item.body like '%s' ", dbesc(protect_sprintf('%' . $search . '%')));
         }
     }
     if ($verb) {
         $sql_extra .= sprintf(" AND item.verb like '%s' ", dbesc(protect_sprintf('%' . $verb . '%')));
     }
     if (strlen($file)) {
         $sql_extra .= term_query('item', $file, TERM_FILE);
     }
     if ($conv) {
         $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", dbesc(protect_sprintf($channel['channel_hash'])));
     }
     if ($update && !$load) {
         // only setup pagination on initial page view
         $pager_sql = '';
     } else {
         $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 ($cmin != 0 || $cmax != 99) {
         // Not everybody who shows up in the network stream will be in your address book.
         // By default those that aren't are assumed to have closeness = 99; but this isn't
         // recorded anywhere. So if cmax is 99, we'll open the search up to anybody in
         // the stream with a NULL address book entry.
         $sql_nets .= " AND ";
         if ($cmax == 99) {
             $sql_nets .= " ( ";
         }
         $sql_nets .= "( abook.abook_closeness >= " . intval($cmin) . " ";
         $sql_nets .= " AND abook.abook_closeness <= " . intval($cmax) . " ) ";
         if ($cmax == 99) {
             $sql_nets .= " OR abook.abook_closeness IS NULL ) ";
         }
     }
     $abook_uids = " and abook.abook_channel = " . local_channel() . " ";
     if ($firehose && !get_config('system', 'disable_discover_tab')) {
         require_once 'include/identity.php';
         $sys = get_sys_channel();
         $uids = " and item.uid  = " . intval($sys['channel_id']) . " ";
         \App::$data['firehose'] = intval($sys['channel_id']);
     } else {
         $uids = " and item.uid = " . local_channel() . " ";
     }
     if (get_pconfig(local_channel(), 'system', 'network_list_mode')) {
         $page_mode = 'list';
     } else {
         $page_mode = 'client';
     }
     $simple_update = $update ? " and item_unseen = 1 " : '';
     // This fixes a very subtle bug so I'd better explain it. You wake up in the morning or return after a day
     // or three and look at your matrix page - after opening up your browser. The first page loads just as it
     // should. All of a sudden a few seconds later, page 2 will get inserted at the beginning of the page
     // (before the page 1 content). The update code is actually doing just what it's supposed
     // to, it's fetching posts that have the ITEM_UNSEEN bit set. But the reason that page 2 content is being
     // returned in an UPDATE is because you hadn't gotten that far yet - you're still on page 1 and everything
     // that we loaded for page 1 is now marked as seen. But the stuff on page 2 hasn't been. So... it's being
     // treated as "new fresh" content because it is unseen. We need to distinguish it somehow from content
     // which "arrived as you were reading page 1". We're going to do this
     // by storing in your session the current UTC time whenever you LOAD a network page, and only UPDATE items
     // which are both ITEM_UNSEEN and have "changed" since that time. Cross fingers...
     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 ($nouveau && $load) {
         // "New Item View" - show all items unthreaded in reverse created date order
         $items = q("SELECT item.*, item.id AS item_id, received FROM item\n\t\t\t\tleft join abook on ( item.owner_xchan = abook.abook_xchan {$abook_uids} )\n\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t{$simple_update}\n\t\t\t\t{$sql_extra} {$sql_nets}\n\t\t\t\tORDER BY item.received DESC {$pager_sql} ");
         require_once 'include/items.php';
         xchan_query($items);
         $items = fetch_post_tags($items, true);
     } elseif ($update) {
         // Normal conversation view
         if ($order === 'post') {
             $ordering = "created";
         } else {
             $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.owner_xchan = abook.abook_xchan {$abook_uids} )\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} ");
         } else {
             // this is an update
             $r = q("SELECT item.parent AS item_id 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 true {$uids} {$item_normal} {$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, $firehose ? local_channel() : 0);
             $items = fetch_post_tags($items, true);
             $items = conv_sort($items, $ordering);
         } else {
             $items = array();
         }
         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 ($update_unseen && !$firehose) {
         $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d {$update_unseen} ", intval(local_channel()));
     }
     $mode = $nouveau ? 'network-new' : 'network';
     $o .= conversation($a, $items, $mode, $update, $page_mode);
     if ($items && !$update) {
         $o .= alt_pager($a, count($items));
     }
     return $o;
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
function public_content(&$a, $update = 0, $load = false)
{
    if ($load) {
        $_SESSION['loadtime'] = datetime_convert();
    }
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        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-public"></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' => 'public', '$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/identity.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\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\tAND item.parent = item.id\n\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}\n\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\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\tAND item.parent = item.id {$simple_update}\n\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\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\tWHERE true {$uids} {$item_normal}\n\t\t\t\tAND item.parent IN ( %s )\n\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;
}
Esempio n. 7
0
function items_fetch($arr, $channel = null, $observer_hash = null, $client_mode = CLIENT_MODE_NORMAL, $module = 'network')
{
    $result = array('success' => false);
    $sql_extra = '';
    $sql_nets = '';
    $sql_options = '';
    $sql_extra2 = '';
    $sql_extra3 = '';
    $def_acl = '';
    $item_uids = ' true ';
    $item_normal = item_normal();
    if ($arr['uid']) {
        $uid = $arr['uid'];
    }
    if ($channel) {
        $uid = $channel['channel_id'];
        $uidhash = $channel['channel_hash'];
        $item_uids = " item.uid = " . intval($uid) . " ";
    }
    if ($arr['star']) {
        $sql_options .= " and item_starred = 1 ";
    }
    if ($arr['wall']) {
        $sql_options .= " and item_wall = 1 ";
    }
    if ($arr['item_id']) {
        $sql_options .= " and parent = " . intval($arr['item_id']) . " ";
    }
    if ($arr['mid']) {
        $sql_options .= " and parent_mid = '" . dbesc($arr['mid']) . "' ";
    }
    $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 {$sql_options} {$item_normal} ) ";
    if ($arr['since_id']) {
        $sql_extra .= " and item.id > " . $since_id . " ";
    }
    if ($arr['cat']) {
        $sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY));
    }
    if ($arr['gid'] && $uid) {
        $r = q("SELECT * FROM `groups` WHERE id = %d AND uid = %d LIMIT 1", intval($arr['group']), intval($uid));
        if (!$r) {
            $result['message'] = t('Privacy group not found.');
            return $result;
        }
        $contact_str = '';
        $contacts = group_get_members($r[0]['id']);
        if ($contacts) {
            foreach ($contacts as $c) {
                if ($contact_str) {
                    $contact_str .= ',';
                }
                $contact_str .= "'" . $c['xchan'] . "'";
            }
        } else {
            $contact_str = ' 0 ';
            $result['message'] = t('Privacy group is empty.');
            return $result;
        }
        $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true {$sql_options} AND (( author_xchan IN ( {$contact_str} ) OR owner_xchan in ( {$contact_str})) or allow_gid like '" . protect_sprintf('%<' . dbesc($r[0]['hash']) . '>%') . "' ) and id = parent {$item_normal} ) ";
        $x = group_rec_byhash($uid, $r[0]['hash']);
        $result['headline'] = sprintf(t('Privacy group: %s'), $x['gname']);
    } elseif ($arr['cid'] && $uid) {
        $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and abook_blocked = 0 limit 1", intval($arr['cid']), intval(local_channel()));
        if ($r) {
            $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true {$sql_options} AND uid = " . intval($arr['uid']) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) {$item_normal} ) ";
            $result['headline'] = sprintf(t('Connection: %s'), $r[0]['xchan_name']);
        } else {
            $result['message'] = t('Connection not found.');
            return $result;
        }
    }
    if ($arr['datequery']) {
        $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert('UTC', 'UTC', $arr['datequery']))));
    }
    if ($arr['datequery2']) {
        $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert('UTC', 'UTC', $arr['datequery2']))));
    }
    if (!array_key_exists('nouveau', $arr)) {
        $sql_extra2 = " AND item.parent = item.id ";
        //		$sql_extra3 = '';
    }
    if ($arr['search']) {
        if (strpos($arr['search'], '#') === 0) {
            $sql_extra .= term_query('item', substr($arr['search'], 1), TERM_HASHTAG, TERM_COMMUNITYTAG);
        } else {
            $sql_extra .= sprintf(" AND item.body like '%s' ", dbesc(protect_sprintf('%' . $arr['search'] . '%')));
        }
    }
    if (strlen($arr['file'])) {
        $sql_extra .= term_query('item', $arr['files'], TERM_FILE);
    }
    if ($arr['conv'] && $channel) {
        $sql_extra .= sprintf(" AND parent IN (SELECT distinct parent from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", dbesc(protect_sprintf($uidhash)));
    }
    if ($client_mode & CLIENT_MODE_UPDATE && !($client_mode & CLIENT_MODE_LOAD)) {
        // only setup pagination on initial page view
        $pager_sql = '';
    } else {
        $itemspage = $channel ? get_pconfig($uid, 'system', 'itemspage') : 20;
        App::set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
        $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
    }
    if (isset($arr['start']) && isset($arr['records'])) {
        $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($arr['records']), intval($arr['start']));
    }
    if (array_key_exists('cmin', $arr) || array_key_exists('cmax', $arr)) {
        if ($arr['cmin'] != 0 || $arr['cmax'] != 99) {
            // Not everybody who shows up in the network stream will be in your address book.
            // By default those that aren't are assumed to have closeness = 99; but this isn't
            // recorded anywhere. So if cmax is 99, we'll open the search up to anybody in
            // the stream with a NULL address book entry.
            $sql_nets .= " AND ";
            if ($arr['cmax'] == 99) {
                $sql_nets .= " ( ";
            }
            $sql_nets .= "( abook.abook_closeness >= " . intval($arr['cmin']) . " ";
            $sql_nets .= " AND abook.abook_closeness <= " . intval($arr['cmax']) . " ) ";
            /** @fixme dead code, $cmax is undefined */
            if ($cmax == 99) {
                $sql_nets .= " OR abook.abook_closeness IS NULL ) ";
            }
        }
    }
    $simple_update = $client_mode & CLIENT_MODE_UPDATE ? " and item.item_unseen = 1 " : '';
    if ($client_mode & CLIENT_MODE_LOAD) {
        $simple_update = '';
    }
    //$start = dba_timer();
    require_once 'include/security.php';
    $sql_extra .= item_permissions_sql($channel['channel_id'], $observer_hash);
    if ($arr['pages']) {
        $item_restrict = " AND item_type = " . ITEM_TYPE_WEBPAGE . " ";
    } else {
        $item_restrict = " AND item_type = 0 ";
    }
    if ($arr['item_type'] === '*') {
        $item_restrict = '';
    }
    if ($arr['nouveau'] && $client_mode & CLIENT_MODE_LOAD && $channel) {
        // "New Item View" - show all items unthreaded in reverse created date order
        $items = q("SELECT item.*, item.id AS item_id FROM item\n\t\t\t\tWHERE {$item_uids} {$item_restrict}\n\t\t\t\t{$simple_update}\n\t\t\t\t{$sql_extra} {$sql_nets}\n\t\t\t\tORDER BY item.received DESC {$pager_sql}");
        require_once 'include/items.php';
        xchan_query($items);
        $items = fetch_post_tags($items, true);
    } else {
        // Normal conversation view
        if ($arr['order'] === 'post') {
            $ordering = "created";
        } else {
            $ordering = "commented";
        }
        if ($client_mode & CLIENT_MODE_LOAD || $client_mode == CLIENT_MODE_NORMAL) {
            // Fetch a page full of parent items for this page
            $r = q("SELECT distinct item.id AS item_id, item.{$ordering} FROM item\n                left join abook on item.author_xchan = abook.abook_xchan\n                WHERE {$item_uids} {$item_restrict}\n                AND item.parent = item.id\n                and (abook.abook_blocked = 0 or abook.abook_flags is null)\n                {$sql_extra3} {$sql_extra} {$sql_nets}\n                ORDER BY item.{$ordering} DESC {$pager_sql} ");
        } else {
            // update
            $r = q("SELECT item.parent AS item_id FROM item\n                left join abook on item.author_xchan = abook.abook_xchan\n                WHERE {$item_uids} {$item_restrict} {$simple_update}\n                and (abook.abook_blocked = 0 or abook.abook_flags is null)\n                {$sql_extra3} {$sql_extra} {$sql_nets} ");
        }
        //$first = dba_timer();
        // Then fetch all the children of the parents that are on this page
        if ($r) {
            $parents_str = ids_to_querystr($r, 'item_id');
            if ($arr['top']) {
                $sql_extra = ' and id = parent ' . $sql_extra;
            }
            $items = q("SELECT item.*, item.id AS item_id FROM item\n\t\t\t\tWHERE {$item_uids} {$item_restrict}\n\t\t\t\tAND item.parent IN ( %s )\n\t\t\t\t{$sql_extra} ", dbesc($parents_str));
            //$second = dba_timer();
            xchan_query($items);
            //$third = dba_timer();
            $items = fetch_post_tags($items, true);
            //$fourth = dba_timer();
            require_once 'include/conversation.php';
            $items = conv_sort($items, $ordering);
            //logger('items: ' . print_r($items,true));
        } else {
            $items = array();
        }
        if ($parents_str && $arr['mark_seen']) {
            $update_unseen = ' AND parent IN ( ' . dbesc($parents_str) . ' )';
        }
        /** @FIXME finish mark unseen sql */
    }
    return $items;
}
Esempio n. 8
0
function dirsearch_init(&$a)
{
    App::set_pager_itemspage(60);
}
Esempio n. 9
0
/**
 * @param App $a
 * @return string
 */
function admin_page_users(&$a)
{
    if ($a->argc > 2) {
        $uid = $a->argv[3];
        $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
        if (count($user) == 0) {
            notice('User not found' . EOL);
            goaway($a->get_baseurl(true) . '/admin/users');
            return '';
            // NOTREACHED
        }
        switch ($a->argv[2]) {
            case "delete":
                check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
                // delete user
                require_once "include/Contact.php";
                user_remove($uid);
                notice(sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
                break;
            case "block":
                check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
                q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s", intval(1 - $user[0]['blocked']), intval($uid));
                notice(sprintf($user[0]['blocked'] ? t("User '%s' unblocked") : t("User '%s' blocked"), $user[0]['username']) . EOL);
                break;
        }
        goaway($a->get_baseurl(true) . '/admin/users');
        return '';
        // NOTREACHED
    }
    /* get pending */
    $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`\n\t\t\t\t FROM `register`\n\t\t\t\t LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`\n\t\t\t\t LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
    /* get users */
    $total = q("SELECT count(*) as total FROM `user` where 1");
    if (count($total)) {
        $a->set_pager_total($total[0]['total']);
        $a->set_pager_itemspage(100);
    }
    $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`\n\t\t\t\tFROM\n\t\t\t\t\t(SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`\n\t\t\t\t\tFROM `item`\n\t\t\t\t\tWHERE `item`.`type` = 'wall'\n\t\t\t\t\tGROUP BY `item`.`uid`) AS `lastitem`\n\t\t\t\t\t\t RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,\n\t\t\t\t\t   `contact`\n\t\t\t\tWHERE\n\t\t\t\t\t   `user`.`uid` = `contact`.`uid`\n\t\t\t\t\t\tAND `user`.`verified` =1\n\t\t\t\t\tAND `contact`.`self` =1\n\t\t\t\tORDER BY `contact`.`name` LIMIT %d, %d\n\t\t\t\t", intval($a->pager['start']), intval($a->pager['itemspage']));
    function _setup_users($e)
    {
        $accounts = array(t('Normal Account'), t('Soapbox Account'), t('Community/Celebrity Account'), t('Automatic Friend Account'));
        $e['page-flags'] = $accounts[$e['page-flags']];
        $e['register_date'] = relative_date($e['register_date']);
        $e['login_date'] = relative_date($e['login_date']);
        $e['lastitem_date'] = relative_date($e['lastitem_date']);
        return $e;
    }
    $users = array_map("_setup_users", $users);
    $t = get_markup_template("admin_users.tpl");
    $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Users'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$h_pending' => t('User registrations waiting for confirm'), '$th_pending' => array(t('Request date'), t('Name'), t('Email')), '$no_pending' => t('No registrations.'), '$approve' => t('Approve'), '$deny' => t('Deny'), '$delete' => t('Delete'), '$block' => t('Block'), '$unblock' => t('Unblock'), '$h_users' => t('Users'), '$th_users' => array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), '$confirm_delete_multi' => t('Selected users will be deleted!\\n\\nEverything these users had posted on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The user {0} will be deleted!\\n\\nEverything this user has posted on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_users"), '$baseurl' => $a->get_baseurl(true), '$pending' => $pending, '$users' => $users));
    $o .= paginate($a);
    return $o;
}
Esempio n. 10
0
function search_doc_files($s)
{
    $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']));
    $regexop = db_getfunc('REGEXP');
    $r = q("select iconfig.v, item.* from item left join iconfig on item.id = iconfig.iid \n\t\twhere iconfig.cat = 'system' and iconfig.k = 'docfile' and\n\t\tbody {$regexop} '%s' and item_type = %d {$pager_sql}", dbesc($s), intval(ITEM_TYPE_DOC));
    $r = fetch_post_tags($r, true);
    for ($x = 0; $x < count($r); $x++) {
        $position = stripos($r[$x]['body'], $s);
        $dislen = 300;
        $start = $position - floor($dislen / 2);
        if ($start < 0) {
            $start = 0;
        }
        $r[$x]['text'] = substr($r[$x]['body'], $start, $dislen);
        $r[$x]['rank'] = 0;
        if ($r[$x]['term']) {
            foreach ($r[$x]['term'] as $t) {
                if (stristr($t['term'], $s)) {
                    $r[$x]['rank']++;
                }
            }
        }
        if (stristr($r[$x]['v'], $s)) {
            $r[$x]['rank']++;
        }
        $r[$x]['rank'] += substr_count(strtolower($r[$x]['text']), strtolower($s));
        // bias the results to the observer's native language
        if ($r[$x]['lang'] === \App::$language) {
            $r[$x]['rank'] = $r[$x]['rank'] + 10;
        }
    }
    usort($r, 'doc_rank_sort');
    return $r;
}
Esempio n. 11
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;
 }
Esempio n. 12
0
 function init()
 {
     \App::set_pager_itemspage(60);
 }
Esempio n. 13
0
File: admin.php Progetto: Mauru/red
/**
 * @param App $a
 * @return string
 */
function admin_page_channels(&$a)
{
    if (argc() > 2) {
        $uid = argv(3);
        $channel = q("SELECT * FROM channel WHERE channel_id = %d", intval($uid));
        if (!$channel) {
            notice(t('Channel not found') . EOL);
            goaway($a->get_baseurl(true) . '/admin/channels');
        }
        switch (argv(2)) {
            case "delete":
                check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                // delete channel
                require_once "include/Contact.php";
                channel_remove($uid, true);
                notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
                break;
            case "block":
                check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                q("UPDATE channel SET channel_pageflags = ( channel_pageflags ^ %d ) where channel_id = %d", intval(PAGE_CENSORED), intval($uid));
                notice(sprintf($channel[0]['channel_pageflags'] & PAGE_CENSORED ? t("Channel '%s' uncensored") : t("Channel '%s' censored"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                break;
        }
        goaway($a->get_baseurl(true) . '/admin/channels');
        return '';
        // NOTREACHED
    }
    /* get channels */
    $total = q("SELECT count(*) as total FROM channel where not (channel_pageflags & %d)", intval(PAGE_REMOVED));
    if ($total) {
        $a->set_pager_total($total[0]['total']);
        $a->set_pager_itemspage(100);
    }
    $order = " order by channel_name asc ";
    $channels = q("SELECT * from channel where not ( channel_pageflags & %d ) {$order} limit %d , %d ", intval(PAGE_REMOVED), intval($a->pager['start']), intval($a->pager['itemspage']));
    if ($channels) {
        for ($x = 0; $x < count($channels); $x++) {
            if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
                $channels[$x]['blocked'] = true;
            } else {
                $channels[$x]['blocked'] = false;
            }
        }
    }
    $t = get_markup_template("admin_channels.tpl");
    $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Channels'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$delete' => t('Delete'), '$block' => t('Censor'), '$unblock' => t('Uncensor'), '$h_channels' => t('Channel'), '$th_channels' => array(t('UID'), t('Name'), t('Address')), '$confirm_delete_multi' => t('Selected channels will be deleted!\\n\\nEverything that was posted in these channels on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The channel {0} will be deleted!\\n\\nEverything that was posted in this channel on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_channels"), '$baseurl' => $a->get_baseurl(true), '$channels' => $channels));
    $o .= paginate($a);
    return $o;
}
Esempio n. 14
0
 function get($update = 0, $load = false)
 {
     if (get_config('system', 'block_public') || get_config('system', 'block_public_search')) {
         if (!local_channel() && !remote_channel()) {
             notice(t('Public access denied.') . EOL);
             return;
         }
     }
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     nav_set_selected('search');
     require_once "include/bbcode.php";
     require_once 'include/security.php';
     require_once 'include/conversation.php';
     require_once 'include/items.php';
     $format = $_REQUEST['format'] ? $_REQUEST['format'] : '';
     if ($format !== '') {
         $update = $load = 1;
     }
     $observer = \App::get_observer();
     $observer_hash = $observer ? $observer['xchan_hash'] : '';
     $o = '<div id="live-search"></div>' . "\r\n";
     $o = '<div class="generic-content-wrapper-styled">' . "\r\n";
     $o .= '<h3>' . t('Search') . '</h3>';
     if (x(\App::$data, 'search')) {
         $search = trim(\App::$data['search']);
     } else {
         $search = x($_GET, 'search') ? trim(rawurldecode($_GET['search'])) : '';
     }
     $tag = false;
     if (x($_GET, 'tag')) {
         $tag = true;
         $search = x($_GET, 'tag') ? trim(rawurldecode($_GET['tag'])) : '';
     }
     if (!local_channel() || !feature_enabled(local_channel(), 'savedsearch')) {
         $o .= search($search, 'search-box', '/search', local_channel() ? true : false);
     }
     if (strpos($search, '#') === 0) {
         $tag = true;
         $search = substr($search, 1);
     }
     if (strpos($search, '@') === 0) {
         $search = substr($search, 1);
         goaway(z_root() . '/directory' . '?f=1&navsearch=1&search=' . $search);
     }
     if (strpos($search, '?') === 0) {
         $search = substr($search, 1);
         goaway(z_root() . '/help' . '?f=1&navsearch=1&search=' . $search);
     }
     // look for a naked webbie
     if (strpos($search, '@') !== false) {
         goaway(z_root() . '/directory' . '?f=1&navsearch=1&search=' . $search);
     }
     if (!$search) {
         return $o;
     }
     if ($tag) {
         $sql_extra = sprintf(" AND `item`.`id` IN (select `oid` from term where otype = %d and type in ( %d , %d) and term = '%s') ", intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(TERM_COMMUNITYTAG), dbesc(protect_sprintf($search)));
     } else {
         $regstr = db_getfunc('REGEXP');
         $sql_extra = sprintf(" AND `item`.`body` {$regstr} '%s' ", dbesc(protect_sprintf(preg_quote($search))));
     }
     // Here is the way permissions work in the search module...
     // Only public posts can be shown
     // OR your own posts if you are a logged in member
     // No items will be shown if the member has a blocked profile wall.
     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.
         $o .= '<div id="live-search"></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' => 'search', '$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', '$fh' => '0', '$nouveau' => '0', '$wall' => '0', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$search' => ($tag ? urlencode('#') : '') . $search, '$order' => '', '$file' => '', '$cats' => '', '$tags' => '', '$mid' => '', '$verb' => '', '$dend' => '', '$dbegin' => ''));
     }
     $item_normal = item_normal();
     $pub_sql = public_permissions_sql($observer_hash);
     require_once 'include/identity.php';
     $sys = get_sys_channel();
     if ($update && $load) {
         $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']));
         // in case somebody turned off public access to sys channel content with permissions
         if (!perm_is_allowed($sys['channel_id'], $observer_hash, 'view_stream')) {
             $sys['xchan_hash'] .= 'disabled';
         }
         if ($load) {
             $r = null;
             if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
                 $prefix = 'distinct on (created, mid)';
                 $suffix = 'ORDER BY created DESC, mid';
             } else {
                 $prefix = 'distinct';
                 $suffix = 'group by mid ORDER BY created DESC';
             }
             if (local_channel()) {
                 $r = q("SELECT {$prefix} mid, item.id as item_id, item.* from item\n\t\t\t\t\t\tWHERE ((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\t\tOR ( `item`.`uid` = %d )) OR item.owner_xchan = '%s' )\n\t\t\t\t\t\t{$item_normal}\n\t\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t\t{$suffix} {$pager_sql} ", intval(local_channel()), dbesc($sys['xchan_hash']));
             }
             if ($r === null) {
                 $r = q("SELECT {$prefix} mid, item.id as item_id, item.* from item\n\t\t\t\t\t\tWHERE (((( `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 ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\t\t\t{$pub_sql} ) OR owner_xchan = '%s')\n\t\t\t\t\t\t{$item_normal}\n\t\t\t\t\t\t{$sql_extra} \n\t\t\t\t\t\t{$suffix} {$pager_sql}", dbesc($sys['xchan_hash']));
             }
         } else {
             $r = array();
         }
     }
     if ($r) {
         xchan_query($r);
         $items = fetch_post_tags($r, true);
     } else {
         $items = array();
     }
     if ($format == 'json') {
         $result = array();
         require_once 'include/conversation.php';
         foreach ($items as $item) {
             $item['html'] = bbcode($item['body']);
             $x = encode_item($item);
             $x['html'] = prepare_text($item['body'], $item['mimetype']);
             $result[] = $x;
         }
         json_return_and_die(array('success' => true, 'messages' => $result));
     }
     if ($tag) {
         $o .= '<h2>' . sprintf(t('Items tagged with: %s'), htmlspecialchars($search, ENT_COMPAT, 'UTF-8')) . '</h2>';
     } else {
         $o .= '<h2>' . sprintf(t('Search results for: %s'), htmlspecialchars($search, ENT_COMPAT, 'UTF-8')) . '</h2>';
     }
     $o .= conversation($a, $items, 'search', $update, 'client');
     $o .= '</div>';
     return $o;
 }
Esempio n. 15
0
 /**
  * @brief Generate accounts admin page and handle single item operations.
  *
  * This function generates the accounts/account admin page and handles the actions
  * if an icon next to an entry was clicked. If several items were selected and
  * the form was submitted it is handled by the function admin_page_accounts_post().
  *
  * @return string
  */
 function get()
 {
     if (argc() > 2) {
         $uid = argv(3);
         $account = q("SELECT * FROM account WHERE account_id = %d", intval($uid));
         if (!$account) {
             notice(t('Account not found') . EOL);
             goaway(z_root() . '/admin/accounts');
         }
         check_form_security_token_redirectOnErr('/admin/accounts', 'admin_accounts', 't');
         switch (argv(2)) {
             case 'delete':
                 // delete user
                 account_remove($uid, true, false);
                 notice(sprintf(t("Account '%s' deleted"), $account[0]['account_email']) . EOL);
                 break;
             case 'block':
                 q("UPDATE account SET account_flags = ( account_flags | %d ) WHERE account_id = %d", intval(ACCOUNT_BLOCKED), intval($uid));
                 notice(sprintf(t("Account '%s' blocked"), $account[0]['account_email']) . EOL);
                 break;
             case 'unblock':
                 q("UPDATE account SET account_flags = ( account_flags & ~%d ) WHERE account_id = %d", intval(ACCOUNT_BLOCKED), intval($uid));
                 notice(sprintf(t("Account '%s' unblocked"), $account[0]['account_email']) . EOL);
                 break;
         }
         goaway(z_root() . '/admin/accounts');
     }
     /* get pending */
     $pending = q("SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d )>0 ", intval(ACCOUNT_PENDING));
     /* get accounts */
     $total = q("SELECT count(*) as total FROM account");
     if (count($total)) {
         \App::set_pager_total($total[0]['total']);
         \App::set_pager_itemspage(100);
     }
     $serviceclass = $_REQUEST['class'] ? " and account_service_class = '" . dbesc($_REQUEST['class']) . "' " : '';
     $key = $_REQUEST['key'] ? dbesc($_REQUEST['key']) : 'account_id';
     $dir = 'asc';
     if (array_key_exists('dir', $_REQUEST)) {
         $dir = intval($_REQUEST['dir']) ? 'asc' : 'desc';
     }
     $base = z_root() . '/admin/accounts?f=';
     $odir = $dir === 'asc' ? '0' : '1';
     $users = q("SELECT `account_id` , `account_email`, `account_lastlog`, `account_created`, `account_expires`, " . "`account_service_class`, ( account_flags & %d ) > 0 as `blocked`, " . "(SELECT %s FROM channel as ch " . "WHERE ch.channel_account_id = ac.account_id and ch.channel_removed = 0 ) as `channels` " . "FROM account as ac where true {$serviceclass} order by {$key} {$dir} limit %d offset %d ", intval(ACCOUNT_BLOCKED), db_concat('ch.channel_address', ' '), intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     //	function _setup_users($e){
     //		$accounts = Array(
     //			t('Normal Account'),
     //			t('Soapbox Account'),
     //			t('Community/Celebrity Account'),
     //			t('Automatic Friend Account')
     //		);
     //		$e['page_flags'] = $accounts[$e['page-flags']];
     //		$e['register_date'] = relative_date($e['register_date']);
     //		$e['login_date'] = relative_date($e['login_date']);
     //		$e['lastitem_date'] = relative_date($e['lastitem_date']);
     //		return $e;
     //	}
     //	$users = array_map("_setup_users", $users);
     $t = get_markup_template('admin_accounts.tpl');
     $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Accounts'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$h_pending' => t('Registrations waiting for confirm'), '$th_pending' => array(t('Request date'), t('Email')), '$no_pending' => t('No registrations.'), '$approve' => t('Approve'), '$deny' => t('Deny'), '$delete' => t('Delete'), '$block' => t('Block'), '$unblock' => t('Unblock'), '$odir' => $odir, '$base' => $base, '$h_users' => t('Accounts'), '$th_users' => array([t('ID'), 'account_id'], [t('Email'), 'account_email'], [t('All Channels'), 'channels'], [t('Register date'), 'account_created'], [t('Last login'), 'account_lastlog'], [t('Expires'), 'account_expires'], [t('Service Class'), 'account_service_class']), '$confirm_delete_multi' => t('Selected accounts will be deleted!\\n\\nEverything these accounts had posted on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The account {0} will be deleted!\\n\\nEverything this account has posted on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_accounts"), '$baseurl' => z_root(), '$pending' => $pending, '$users' => $users));
     $o .= paginate($a);
     return $o;
 }
Esempio n. 16
0
/**
 * @param App $a
 * @return string
 */
function admin_page_users(&$a)
{
    if ($a->argc > 2) {
        $uid = $a->argv[3];
        $user = q("SELECT username, blocked FROM `user` WHERE `uid`=%d", intval($uid));
        if (count($user) == 0) {
            notice('User not found' . EOL);
            goaway($a->get_baseurl(true) . '/admin/users');
            return '';
            // NOTREACHED
        }
        switch ($a->argv[2]) {
            case "delete":
                check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
                // delete user
                require_once "include/Contact.php";
                user_remove($uid);
                notice(sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
                break;
            case "block":
                check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
                q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s", intval(1 - $user[0]['blocked']), intval($uid));
                notice(sprintf($user[0]['blocked'] ? t("User '%s' unblocked") : t("User '%s' blocked"), $user[0]['username']) . EOL);
                break;
        }
        goaway($a->get_baseurl(true) . '/admin/users');
        return '';
        // NOTREACHED
    }
    /* get pending */
    $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`\n\t\t\t\t FROM `register`\n\t\t\t\t LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`\n\t\t\t\t LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
    /* get users */
    $total = q("SELECT count(*) as total FROM `user` where 1");
    if (count($total)) {
        $a->set_pager_total($total[0]['total']);
        $a->set_pager_itemspage(100);
    }
    $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`, `user`.`account_expired`\n\t\t\t\tFROM\n\t\t\t\t\t(SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`\n\t\t\t\t\tFROM `item`\n\t\t\t\t\tWHERE `item`.`type` = 'wall'\n\t\t\t\t\tGROUP BY `item`.`uid`) AS `lastitem`\n\t\t\t\t\t\t RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,\n\t\t\t\t\t   `contact`\n\t\t\t\tWHERE\n\t\t\t\t\t   `user`.`uid` = `contact`.`uid`\n\t\t\t\t\t\tAND `user`.`verified` =1\n\t\t\t\t\tAND `contact`.`self` =1\n\t\t\t\tORDER BY `contact`.`name` LIMIT %d, %d\n\t\t\t\t", intval($a->pager['start']), intval($a->pager['itemspage']));
    function _setup_users($e)
    {
        $a = get_app();
        $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
        $accounts = array(t('Normal Account'), t('Soapbox Account'), t('Community/Celebrity Account'), t('Automatic Friend Account'));
        $e['page-flags'] = $accounts[$e['page-flags']];
        $e['register_date'] = relative_date($e['register_date']);
        $e['login_date'] = relative_date($e['login_date']);
        $e['lastitem_date'] = relative_date($e['lastitem_date']);
        //$e['is_admin'] = ($e['email'] === $a->config['admin_email']);
        $e['is_admin'] = in_array($e['email'], $adminlist);
        $e['deleted'] = $e['account_removed'] ? relative_date($e['account_expires_on']) : False;
        return $e;
    }
    $users = array_map("_setup_users", $users);
    // Get rid of dashes in key names, Smarty3 can't handle them
    // and extracting deleted users
    $tmp_users = array();
    $deleted = array();
    while (count($users)) {
        $new_user = array();
        foreach (array_pop($users) as $k => $v) {
            $k = str_replace('-', '_', $k);
            $new_user[$k] = $v;
        }
        if ($new_user['deleted']) {
            array_push($deleted, $new_user);
        } else {
            array_push($tmp_users, $new_user);
        }
    }
    //Reversing the two array, and moving $tmp_users to $users
    array_reverse($deleted);
    while (count($tmp_users)) {
        array_push($users, array_pop($tmp_users));
    }
    $t = get_markup_template("admin_users.tpl");
    $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Users'), '$submit' => t('Add User'), '$select_all' => t('select all'), '$h_pending' => t('User registrations waiting for confirm'), '$h_deleted' => t('User waiting for permanent deletion'), '$th_pending' => array(t('Request date'), t('Name'), t('Email')), '$no_pending' => t('No registrations.'), '$approve' => t('Approve'), '$deny' => t('Deny'), '$delete' => t('Delete'), '$block' => t('Block'), '$unblock' => t('Unblock'), '$siteadmin' => t('Site admin'), '$accountexpired' => t('Account expired'), '$h_users' => t('Users'), '$h_newuser' => t('New User'), '$th_deleted' => array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Deleted since')), '$th_users' => array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), '$confirm_delete_multi' => t('Selected users will be deleted!\\n\\nEverything these users had posted on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The user {0} will be deleted!\\n\\nEverything this user has posted on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_users"), '$baseurl' => $a->get_baseurl(true), '$pending' => $pending, 'deleted' => $deleted, '$users' => $users, '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")), '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")), '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user."), '', '', 'email')));
    $o .= paginate($a);
    return $o;
}
Esempio n. 17
0
 /**
  * @brief
  *
  * @param App &$a
  * @return string
  */
 function admin_page_channels(&$a)
 {
     if (argc() > 2) {
         $uid = argv(3);
         $channel = q("SELECT * FROM channel WHERE channel_id = %d", intval($uid));
         if (!$channel) {
             notice(t('Channel not found') . EOL);
             goaway(z_root() . '/admin/channels');
         }
         switch (argv(2)) {
             case "delete":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 // delete channel
                 require_once "include/Contact.php";
                 channel_remove($uid, true);
                 notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
                 break;
             case "block":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 proc_run('php', 'include/directory.php', $uid, 'nopush');
                 notice(sprintf($pflags & PAGE_CENSORED ? t("Channel '%s' censored") : t("Channel '%s' uncensored"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             case "code":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 notice(sprintf($pflags & PAGE_ALLOWCODE ? t("Channel '%s' code allowed") : t("Channel '%s' code disallowed"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             default:
                 break;
         }
         goaway(z_root() . '/admin/channels');
     }
     /* get channels */
     $total = q("SELECT count(*) as total FROM channel where channel_removed = 0 and channel_system = 0");
     if ($total) {
         \App::set_pager_total($total[0]['total']);
         \App::set_pager_itemspage(100);
     }
     $order = " order by channel_name asc ";
     $channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 {$order} limit %d offset %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     if ($channels) {
         for ($x = 0; $x < count($channels); $x++) {
             if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
                 $channels[$x]['blocked'] = true;
             } else {
                 $channels[$x]['blocked'] = false;
             }
             if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) {
                 $channels[$x]['allowcode'] = true;
             } else {
                 $channels[$x]['allowcode'] = false;
             }
         }
     }
     $t = get_markup_template("admin_channels.tpl");
     $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Channels'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$delete' => t('Delete'), '$block' => t('Censor'), '$unblock' => t('Uncensor'), '$code' => t('Allow Code'), '$uncode' => t('Disallow Code'), '$h_channels' => t('Channel'), '$th_channels' => array(t('UID'), t('Name'), t('Address')), '$confirm_delete_multi' => t('Selected channels will be deleted!\\n\\nEverything that was posted in these channels on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The channel {0} will be deleted!\\n\\nEverything that was posted in this channel on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_channels"), '$baseurl' => z_root(), '$channels' => $channels));
     $o .= paginate($a);
     return $o;
 }
Esempio n. 18
0
 /**
  * @brief
  *
  * @return string
  */
 function get()
 {
     if (argc() > 2) {
         $uid = argv(3);
         $channel = q("SELECT * FROM channel WHERE channel_id = %d", intval($uid));
         if (!$channel) {
             notice(t('Channel not found') . EOL);
             goaway(z_root() . '/admin/channels');
         }
         switch (argv(2)) {
             case "delete":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 // delete channel
                 channel_remove($uid, true);
                 notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
                 break;
             case "block":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 \Zotlabs\Daemon\Master::Summon(array('Directory', $uid, 'nopush'));
                 notice(sprintf($pflags & PAGE_CENSORED ? t("Channel '%s' censored") : t("Channel '%s' uncensored"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             case "code":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 notice(sprintf($pflags & PAGE_ALLOWCODE ? t("Channel '%s' code allowed") : t("Channel '%s' code disallowed"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             default:
                 break;
         }
         goaway(z_root() . '/admin/channels');
     }
     $key = $_REQUEST['key'] ? dbesc($_REQUEST['key']) : 'channel_id';
     $dir = 'asc';
     if (array_key_exists('dir', $_REQUEST)) {
         $dir = intval($_REQUEST['dir']) ? 'asc' : 'desc';
     }
     $base = z_root() . '/admin/channels?f=';
     $odir = $dir === 'asc' ? '0' : '1';
     /* get channels */
     $total = q("SELECT count(*) as total FROM channel where channel_removed = 0 and channel_system = 0");
     if ($total) {
         \App::set_pager_total($total[0]['total']);
         \App::set_pager_itemspage(100);
     }
     $channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 order by {$key} {$dir} limit %d offset %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     if ($channels) {
         for ($x = 0; $x < count($channels); $x++) {
             if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
                 $channels[$x]['blocked'] = true;
             } else {
                 $channels[$x]['blocked'] = false;
             }
             if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) {
                 $channels[$x]['allowcode'] = true;
             } else {
                 $channels[$x]['allowcode'] = false;
             }
         }
     }
     $t = get_markup_template("admin_channels.tpl");
     $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Channels'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$delete' => t('Delete'), '$block' => t('Censor'), '$unblock' => t('Uncensor'), '$code' => t('Allow Code'), '$uncode' => t('Disallow Code'), '$h_channels' => t('Channel'), '$base' => $base, '$odir' => $odir, '$th_channels' => array([t('UID'), 'channel_id'], [t('Name'), 'channel_name'], [t('Address'), 'channel_address']), '$confirm_delete_multi' => t('Selected channels will be deleted!\\n\\nEverything that was posted in these channels on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The channel {0} will be deleted!\\n\\nEverything that was posted in this channel on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_channels"), '$baseurl' => z_root(), '$channels' => $channels));
     $o .= paginate($a);
     return $o;
 }