Example #1
0
function help_content(&$a)
{
    nav_set_selected('help');
    global $lang;
    $text = '';
    if ($a->argc > 1) {
        $text = load_doc_file('doc/' . $a->argv[1] . '.md');
        $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($a->argv[1]));
    }
    $home = load_doc_file('doc/Home.md');
    if (!$text) {
        $text = $home;
        $a->page['title'] = t('Help');
    } else {
        $a->page['aside'] = Markdown($home);
    }
    if (!strlen($text)) {
        header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
        $tpl = get_markup_template("404.tpl");
        return replace_macros($tpl, array('$message' => t('Page not found.')));
    }
    $html = Markdown($text);
    $html = "<style>.md_warning { padding: 1em; border: #ff0000 solid 2px; background-color: #f9a3a3; color: #ffffff;</style>" . $html;
    return $html;
}
Example #2
0
 function get()
 {
     nav_set_selected('help');
     if ($_REQUEST['search']) {
         $o .= '<div id="help-content" class="generic-content-wrapper">';
         $o .= '<div class="section-title-wrapper">';
         $o .= '<h2>' . t('Documentation Search') . ' - ' . htmlspecialchars($_REQUEST['search']) . '</h2>';
         $o .= '</div>';
         $o .= '<div class="section-content-wrapper">';
         $r = search_doc_files($_REQUEST['search']);
         if ($r) {
             $o .= '<ul class="help-searchlist">';
             foreach ($r as $rr) {
                 $dirname = dirname($rr['v']);
                 $fname = basename($rr['v']);
                 $fname = substr($fname, 0, strrpos($fname, '.'));
                 $path = trim(substr($dirname, 4), '/');
                 $o .= '<li><a href="help/' . ($path ? $path . '/' : '') . $fname . '" >' . ucwords(str_replace('_', ' ', notags($fname))) . '</a><br />' . '<b><i>' . 'help/' . ($path ? $path . '/' : '') . $fname . '</i></b><br />' . '...' . str_replace('$Projectname', \Zotlabs\Lib\System::get_platform_name(), $rr['text']) . '...<br /><br /></li>';
             }
             $o .= '</ul>';
             $o .= '</div>';
             $o .= '</div>';
         }
         return $o;
     }
     $content = get_help_content();
     return replace_macros(get_markup_template("help.tpl"), array('$title' => t('$Projectname Documentation'), '$content' => $content));
 }
Example #3
0
function notes_init(&$a)
{
    if (!local_user()) {
        return;
    }
    $profile = 0;
    $which = $a->user['nickname'];
    nav_set_selected('home');
    //	profile_load($a,$which,$profile);
}
Example #4
0
function community_content(&$a, $update = 0)
{
    $o = '';
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (get_config('system', 'no_community_page')) {
        notice(t('Not available.') . EOL);
        return;
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    $o .= '<h3>' . t('Community') . '</h3>';
    if (!$update) {
        nav_set_selected('community');
    }
    if (x($a->data, 'search')) {
        $search = notags(trim($a->data['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    // Here is the way permissions work in this module...
    // Only public posts can be shown
    // OR your own posts if you are a logged in member
    if (!get_config('alt_pager', 'global') && !get_pconfig(local_user(), 'system', 'alt_pager')) {
        $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total`\n\t\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`\n\t\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\tAND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' \n\t\t\tAND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''\n\t\t\tAND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0 \n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0");
        if (count($r)) {
            $a->set_pager_total($r[0]['total']);
        }
        if (!$r[0]['total']) {
            info(t('No results.') . EOL);
            return $o;
        }
    }
    //$r = q("SELECT distinct(`item`.`uri`)
    $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, \n\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,\n\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, \n\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,\n\t\t`user`.`nickname`, `user`.`hidewall`\n\t\tFROM `item` FORCE INDEX (`received`) LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tLEFT JOIN `user` ON `user`.`uid` = `item`.`uid`\n\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\tAND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''\n\t\tAND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' \n\t\tAND `item`.`private` = 0 AND `item`.`wall` = 1 AND `item`.`id` = `item`.`parent`\n\t\tAND `user`.`hidewall` = 0\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`\n\t\tORDER BY `received` DESC LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']));
    //		group by `item`.`uri`
    if (!count($r)) {
        info(t('No results.') . EOL);
        return $o;
    }
    // we behave the same in message lists as the search module
    $o .= conversation($a, $r, 'community', $update);
    if (get_config('alt_pager', 'global') || get_pconfig(local_user(), 'system', 'alt_pager')) {
        $o .= alt_pager($a, count($r));
    } else {
        $o .= paginate($a);
    }
    return $o;
}
Example #5
0
File: help.php Project: Mauru/red
function help_content(&$a)
{
    nav_set_selected('help');
    global $lang;
    $doctype = 'markdown';
    require_once 'library/markdown.php';
    $text = '';
    if (argc() > 1) {
        $text = load_doc_file('doc/' . $a->argv[1] . '.md');
        $a->page['title'] = t('Help:') . ' ' . ucwords(str_replace('-', ' ', notags(argv(1))));
    }
    if (!$text) {
        $text = load_doc_file('doc/' . $a->argv[1] . '.bb');
        if ($text) {
            $doctype = 'bbcode';
        }
        $a->page['title'] = t('Help:') . ' ' . ucwords(str_replace('_', ' ', notags(argv(1))));
    }
    if (!$text) {
        $text = load_doc_file('doc/' . $a->argv[1] . '.html');
        if ($text) {
            $doctype = 'html';
        }
        $a->page['title'] = t('Help:') . ' ' . ucwords(str_replace('-', ' ', notags(argv(1))));
    }
    if (!$text) {
        $text = load_doc_file('doc/Site.md');
        $a->page['title'] = t('Help');
    }
    if (!$text) {
        $doctype = 'bbcode';
        $text = load_doc_file('doc/main.bb');
        $a->page['title'] = t('Help');
    }
    if (!strlen($text)) {
        header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
        $tpl = get_markup_template("404.tpl");
        return replace_macros($tpl, array('$message' => t('Page not found.')));
    }
    $text = preg_replace_callback("/#include (.*?)\\;/ism", 'preg_callback_help_include', $text);
    if ($doctype === 'html') {
        $content = $text;
    }
    if ($doctype === 'markdown') {
        $content = Markdown($text);
    }
    if ($doctype === 'bbcode') {
        require_once 'include/bbcode.php';
        $content = bbcode($text);
    }
    return replace_macros(get_markup_template("help.tpl"), array('$content' => $content));
}
Example #6
0
 function get()
 {
     nav_set_selected('settings');
     if (!local_channel() || $_SESSION['delegate']) {
         notice(t('Permission denied.') . EOL);
         return login();
     }
     $channel = \App::get_channel();
     if ($channel) {
         head_set_icon($channel['xchan_photo_s']);
     }
     $o = $this->sm->call('get');
     if ($o !== false) {
         return $o;
     }
     $o = '';
 }
Example #7
0
function viewcontacts_init(&$a)
{
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        return;
    }
    nav_set_selected('home');
    if ($a->argc > 1) {
        $nick = $a->argv[1];
        $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick));
        if (!count($r)) {
            return;
        }
        $a->data['user'] = $r[0];
        $a->profile_uid = $r[0]['uid'];
        $is_owner = local_user() && local_user() == $a->profile_uid;
        profile_load($a, $a->argv[1]);
    }
}
Example #8
0
function message_content(&$a)
{
    $o = '';
    nav_set_selected('messages');
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return login();
    }
    $channel = $a->get_channel();
    head_set_icon($channel['xchan_photo_s']);
    $cipher = get_pconfig(local_channel(), 'system', 'default_cipher');
    if (!$cipher) {
        $cipher = 'aes256';
    }
    $tpl = get_markup_template('mail_head.tpl');
    $header = replace_macros($tpl, array('$messages' => t('Messages'), '$tab_content' => $tab_content));
    if (argc() == 3 && argv(1) === 'dropconv') {
        if (!intval(argv(2))) {
            return;
        }
        $cmd = argv(1);
        $r = private_messages_drop(local_channel(), argv(2), true);
        if ($r) {
            info(t('Conversation removed.') . EOL);
        }
        goaway($a->get_baseurl(true) . '/message');
    }
    if (argc() == 1) {
        // list messages
        $o .= $header;
        // private_messages_list() can do other more complicated stuff, for now keep it simple
        $r = private_messages_list(local_channel(), '', $a->pager['start'], $a->pager['itemspage']);
        if (!$r) {
            info(t('No messages.') . EOL);
            return $o;
        }
        $tpl = get_markup_template('mail_list.tpl');
        foreach ($r as $rr) {
            $o .= replace_macros($tpl, array('$id' => $rr['id'], '$from_name' => $rr['from']['xchan_name'], '$from_url' => chanlink_hash($rr['from_xchan']), '$from_photo' => $rr['from']['xchan_photo_s'], '$to_name' => $rr['to']['xchan_name'], '$to_url' => chanlink_hash($rr['to_xchan']), '$to_photo' => $rr['to']['xchan_photo_s'], '$subject' => $rr['seen'] ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>', '$delete' => t('Delete conversation'), '$body' => smilies(bbcode($rr['body'])), '$date' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], t('D, d M Y - g:i A')), '$seen' => $rr['seen']));
        }
        $o .= alt_pager($a, count($r));
        return $o;
    }
}
Example #9
0
function community_content(&$a, $update = 0)
{
    $o = '';
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (get_config('system', 'no_community_page')) {
        notice(t('Not available.') . EOL);
        return;
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    $o .= '<h3>' . t('Community') . '</h3>';
    if (!$update) {
        nav_set_selected('community');
        $o .= '<div id="live-community"></div>' . "\r\n";
        $o .= "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
    }
    if (x($a->data, 'search')) {
        $search = notags(trim($a->data['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    // Here is the way permissions work in this module...
    // Only public wall posts can be shown
    // OR your own posts if you are a logged in member
    $r = q("SELECT COUNT(*) AS `total`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`\n\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\tAND `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' \n\t\tAND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0 \n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 ");
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    if (!$r[0]['total']) {
        info(t('No results.') . EOL);
        return $o;
    }
    $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, \n\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,\n\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, \n\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,\n\t\t`user`.`nickname`, `user`.`hidewall`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tLEFT JOIN `user` ON `user`.`uid` = `item`.`uid`\n\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\tAND `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' \n\t\tAND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0 \n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\tORDER BY `received` DESC LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']));
    // we behave the same in message lists as the search module
    $o .= conversation($a, $r, 'community', false);
    $o .= paginate($a);
    $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
    return $o;
}
Example #10
0
function help_content(&$a)
{
    nav_set_selected('help');
    global $lang;
    require_once 'library/markdown.php';
    $text = '';
    if ($a->argc > 1) {
        $text = load_doc_file('doc/' . $a->argv[1] . '.md');
        $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($a->argv[1]));
    }
    if (!$text) {
        $text = load_doc_file('doc/Home.md');
        $a->page['title'] = t('Help');
    }
    if (!strlen($text)) {
        header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
        $tpl = get_markup_template("404.tpl");
        return replace_macros($tpl, array('$message' => t('Page not found.')));
    }
    return Markdown($text);
}
Example #11
0
function search_content(&$a)
{
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    nav_set_selected('search');
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    $o = '<div id="live-search"></div>' . "\r\n";
    $o .= '<h3>' . t('Search This Site') . '</h3>';
    if (x($a->data, 'search')) {
        $search = notags(trim($a->data['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    $o .= search($search, 'search-box', '/search', local_user() ? true : false);
    if (!$search) {
        return $o;
    }
    // Here is the way permissions work in the search module...
    // Only public wall posts can be shown
    // OR your own posts if you are a logged in member
    $s_regx = sprintf("AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' )", dbesc(preg_quote($search)), dbesc('\\]' . preg_quote($search) . '\\['));
    $search_alg = $s_regx;
    $r = q("SELECT COUNT(*) AS `total`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`\n\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\tAND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0) \n\t\t\tOR `item`.`uid` = %d )\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t{$search_alg} ", intval(local_user()));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    if (!$r[0]['total']) {
        info(t('No results.') . EOL);
        return $o;
    }
    $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, \n\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,\n\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, \n\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,\n\t\t`user`.`nickname`\n\t\tFROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\tLEFT JOIN `user` ON `user`.`uid` = `item`.`uid`\n\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\tAND (( `wall` = 1 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND `user`.`hidewall` = 0 ) \n\t\t\tOR `item`.`uid` = %d )\n\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t{$search_alg}\n\t\tORDER BY `received` DESC LIMIT %d , %d ", intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']));
    $o .= '<h2>Search results for: ' . $search . '</h2>';
    $o .= conversation($a, $r, 'search', false);
    $o .= paginate($a);
    return $o;
}
function notifications_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('notifications');
    $o = '';
    $notif_tpl = get_markup_template('notifications.tpl');
    $not_tpl = get_markup_template('notify.tpl');
    require_once 'include/bbcode.php';
    $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc", intval(local_channel()));
    if (count($r) > 0) {
        $notifications_available = 1;
        foreach ($r as $it) {
            $notif_content .= replace_macros($not_tpl, array('$item_link' => z_root() . '/notify/view/' . $it['id'], '$item_image' => $it['photo'], '$item_text' => strip_tags(bbcode($it['msg'])), '$item_when' => relative_date($it['date'])));
        }
    } else {
        $notif_content .= t('No more system notifications.');
    }
    $o .= replace_macros($notif_tpl, array('$notif_header' => t('System Notifications'), '$notif_link_mark_seen' => t('Mark all system notifications seen'), '$notif_content' => $notif_content, '$notifications_available' => $notifications_available));
    return $o;
}
Example #13
0
 function settings_content(&$a)
 {
     $o = '';
     nav_set_selected('settings');
     if (!local_user()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $tabs = array(array('label' => t('Account settings'), 'url' => $a->get_baseurl() . '/settings', 'sel' => $a->argc == 1 ? 'active' : ''), array('label' => t('Connector settings'), 'url' => $a->get_baseurl() . '/settings/connectors', 'sel' => $a->argc > 1 && $a->argv[1] === 'connectors' ? 'active' : ''), array('label' => t('Plugin settings'), 'url' => $a->get_baseurl() . '/settings/addon', 'sel' => $a->argc > 1 && $a->argv[1] === 'addon' ? 'active' : ''), array('label' => t('Connections'), 'url' => $a->get_baseurl() . '/settings/oauth', 'sel' => $a->argc > 1 && $a->argv[1] === 'oauth' ? 'active' : ''), array('label' => t('Export personal data'), 'url' => $a->get_baseurl() . '/uexport', 'sel' => ''));
     $tabtpl = get_markup_template("common_tabs.tpl");
     $tabs = replace_macros($tabtpl, array('$tabs' => $tabs));
     if ($a->argc > 1 && $a->argv[1] === 'oauth') {
         if ($a->argc > 2 && $a->argv[2] === 'add') {
             $tpl = get_markup_template("settings_oauth_edit.tpl");
             $o .= replace_macros($tpl, array('$tabs' => $tabs, '$title' => t('Add application'), '$submit' => t('Submit'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), '', ''), '$key' => array('key', t('Consumer Key'), '', ''), '$secret' => array('secret', t('Consumer Secret'), '', ''), '$redirect' => array('redirect', t('Redirect'), '', ''), '$icon' => array('icon', t('Icon url'), '', '')));
             return $o;
         }
         if ($a->argc > 3 && $a->argv[2] === 'edit') {
             $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user());
             if (!count($r)) {
                 notice(t("You can't edit this application."));
                 return;
             }
             $app = $r[0];
             $tpl = get_markup_template("settings_oauth_edit.tpl");
             $o .= replace_macros($tpl, array('$tabs' => $tabs, '$title' => t('Add application'), '$submit' => t('Update'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), $app['name'], ''), '$key' => array('key', t('Consumer Key'), $app['client_id'], ''), '$secret' => array('secret', t('Consumer Secret'), $app['pw'], ''), '$redirect' => array('redirect', t('Redirect'), $app['redirect_uri'], ''), '$icon' => array('icon', t('Icon url'), $app['icon'], '')));
             return $o;
         }
         if ($a->argc > 3 && $a->argv[2] === 'delete') {
             $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user());
             goaway($a->get_baseurl() . "/settings/oauth/");
             return;
         }
         $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my \n\t\t\t\tFROM clients\n\t\t\t\tLEFT JOIN tokens ON clients.client_id=tokens.client_id\n\t\t\t\tWHERE clients.uid IN (%d,0)", local_user(), local_user());
         $tpl = get_markup_template("settings_oauth.tpl");
         $o .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$title' => t('Connected Apps'), '$add' => t('Add application'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$consumerkey' => t('Client key starts with'), '$noname' => t('No name'), '$remove' => t('Remove authorization'), '$tabs' => $tabs, '$apps' => $r));
         return $o;
     }
     if ($a->argc > 1 && $a->argv[1] === 'addon') {
         $settings_addons = "";
         $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
         if (!count($r)) {
             $settings_addons = t('No Plugin settings configured');
         }
         call_hooks('plugin_settings', $settings_addons);
         $tpl = get_markup_template("settings_addons.tpl");
         $o .= replace_macros($tpl, array('$title' => t('Plugin Settings'), '$tabs' => $tabs, '$settings_addons' => $settings_addons));
         return $o;
     }
     if ($a->argc > 1 && $a->argv[1] === 'connectors') {
         $settings_connectors = "";
         call_hooks('connector_settings', $settings_connectors);
         $diasp_enabled = sprintf(t('Built-in support for %s connectivity is %s'), t('Diaspora'), get_config('system', 'diaspora_enabled') ? t('enabled') : t('disabled'));
         $ostat_enabled = sprintf(t('Built-in support for %s connectivity is %s'), t('StatusNet'), get_config('system', 'ostatus_disabled') ? t('disabled') : t('enabled'));
         $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1;
         if (get_config('system', 'dfrn_only')) {
             $mail_disabled = 1;
         }
         if (!$mail_disabled) {
             $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", local_user());
         } else {
             $r = null;
         }
         $mail_server = count($r) ? $r[0]['server'] : '';
         $mail_port = count($r) && intval($r[0]['port']) ? intval($r[0]['port']) : '';
         $mail_ssl = count($r) ? $r[0]['ssltype'] : '';
         $mail_user = count($r) ? $r[0]['user'] : '';
         $mail_replyto = count($r) ? $r[0]['reply_to'] : '';
         $mail_pubmail = count($r) ? $r[0]['pubmail'] : 0;
         $mail_chk = count($r) ? $r[0]['last_check'] : '0000-00-00 00:00:00';
         $tpl = get_markup_template("settings_connectors.tpl");
         $o .= replace_macros($tpl, array('$title' => t('Connector Settings'), '$tabs' => $tabs, '$diasp_enabled' => $diasp_enabled, '$ostat_enabled' => $ostat_enabled, '$h_imap' => t('Email/Mailbox Setup'), '$imap_desc' => t("If you wish to communicate with email contacts using this service (optional), please specify how to connect to your mailbox."), '$imap_lastcheck' => array('imap_lastcheck', t('Last successful email check:'), $mail_chk, ''), '$mail_disabled' => $mail_disabled ? t('Email access is disabled on this site.') : '', '$mail_server' => array('mail_server', t('IMAP server name:'), $mail_server, ''), '$mail_port' => array('mail_port', t('IMAP port:'), $mail_port, ''), '$mail_ssl' => array('mail_ssl', t('Security:'), strtoupper($mail_ssl), '', array('' => t('None'), 'TSL' => 'TSL', 'SSL' => 'SSL')), '$mail_user' => array('mail_user', t('Email login name:'), $mail_user, ''), '$mail_pass' => array('mail_pass', t('Email password:'******'', ''), '$mail_replyto' => array('mail_replyto', t('Reply-to address:'), '', 'Optional'), '$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''), '$submit' => t('Submit'), '$settings_connectors' => $settings_connectors));
         return $o;
     }
     require_once 'include/acl_selectors.php';
     $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval(local_user()));
     if (count($p)) {
         $profile = $p[0];
     }
     $username = $a->user['username'];
     $email = $a->user['email'];
     $nickname = $a->user['nickname'];
     $timezone = $a->user['timezone'];
     $notify = $a->user['notify-flags'];
     $defloc = $a->user['default-location'];
     $openid = $a->user['openid'];
     $maxreq = $a->user['maxreq'];
     $expire = intval($a->user['expire']) ? $a->user['expire'] : '';
     $blockwall = $a->user['blockwall'];
     $blocktags = $a->user['blocktags'];
     $expire_items = get_pconfig(local_user(), 'expire', 'items');
     $expire_items = $expire_items === false ? 1 : $expire_items;
     // default if not set: 1
     $expire_notes = get_pconfig(local_user(), 'expire', 'notes');
     $expire_notes = $expire_notes === false ? 1 : $expire_notes;
     // default if not set: 1
     $expire_starred = get_pconfig(local_user(), 'expire', 'starred');
     $expire_starred = $expire_starred === false ? 1 : $expire_starred;
     // default if not set: 1
     $expire_photos = get_pconfig(local_user(), 'expire', 'photos');
     $expire_photos = $expire_photos === false ? 0 : $expire_photos;
     // default if not set: 0
     $suggestme = get_pconfig(local_user(), 'system', 'suggestme');
     $suggestme = $suggestme === false ? 0 : $suggestme;
     // default if not set: 0
     if (!strlen($a->user['timezone'])) {
         $timezone = date_default_timezone_get();
     }
     $pageset_tpl = get_markup_template('pagetypes.tpl');
     $pagetype = replace_macros($pageset_tpl, array('$page_normal' => array('page-flags', t('Normal Account'), PAGE_NORMAL, t('This account is a normal personal profile'), $a->user['page-flags'] == PAGE_NORMAL), '$page_soapbox' => array('page-flags', t('Soapbox Account'), PAGE_SOAPBOX, t('Automatically approve all connection/friend requests as read-only fans'), $a->user['page-flags'] == PAGE_SOAPBOX), '$page_community' => array('page-flags', t('Community/Celebrity Account'), PAGE_COMMUNITY, t('Automatically approve all connection/friend requests as read-write fans'), $a->user['page-flags'] == PAGE_COMMUNITY), '$page_freelove' => array('page-flags', t('Automatic Friend Account'), PAGE_FREELOVE, t('Automatically approve all connection/friend requests as friends'), $a->user['page-flags'] == PAGE_FREELOVE)));
     $noid = get_config('system', 'no_openid');
     if ($noid) {
         $openid_field = false;
     } else {
         $openid_field = array('openid_url', t('OpenID:'), $openid, t("(Optional) Allow this OpenID to login to this account."));
     }
     $opt_tpl = get_markup_template("field_yesno.tpl");
     if (get_config('system', 'publish_all')) {
         $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
     } else {
         $profile_in_dir = replace_macros($opt_tpl, array('$field' => array('profile_in_directory', t('Publish your default profile in your local site directory?'), $profile['publish'], '', array(t('No'), t('Yes')))));
     }
     if (strlen(get_config('system', 'directory_submit_url'))) {
         $profile_in_net_dir = replace_macros($opt_tpl, array('$field' => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'), t('Yes')))));
     } else {
         $profile_in_net_dir = '';
     }
     $hide_friends = replace_macros($opt_tpl, array('$field' => array('hide-friends', t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], '', array(t('No'), t('Yes')))));
     $hide_wall = replace_macros($opt_tpl, array('$field' => array('hidewall', t('Hide your profile details from unknown viewers?'), $a->user['hidewall'], '', array(t('No'), t('Yes')))));
     $blockwall = replace_macros($opt_tpl, array('$field' => array('blockwall', t('Allow friends to post to your profile page?'), !$a->user['blockwall'], '', array(t('No'), t('Yes')))));
     $blocktags = replace_macros($opt_tpl, array('$field' => array('blocktags', t('Allow friends to tag your posts?'), !$a->user['blocktags'], '', array(t('No'), t('Yes')))));
     $suggestme = replace_macros($opt_tpl, array('$field' => array('suggestme', t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', array(t('No'), t('Yes')))));
     $invisible = !$profile['publish'] && !$profile['net-publish'] ? true : false;
     if ($invisible) {
         info(t('Profile is <strong>not published</strong>.') . EOL);
     }
     $default_theme = get_config('system', 'theme');
     if (!$default_theme) {
         $default_theme = 'default';
     }
     $themes = array();
     $files = glob('view/theme/*');
     if ($files) {
         foreach ($files as $file) {
             $f = basename($file);
             $theme_name = file_exists($file . '/experimental') ? sprintf("%s - (Experimental)", $f) : $f;
             $themes[$f] = $theme_name;
         }
     }
     $theme_selected = !x($_SESSION, 'theme') ? $default_theme : $_SESSION['theme'];
     $subdir = strlen($a->get_path()) ? '<br />' . t('or') . ' ' . $a->get_baseurl() . '/profile/' . $nickname : '';
     $tpl_addr = get_markup_template("settings_nick_set.tpl");
     $prof_addr = replace_macros($tpl_addr, array('$desc' => t('Your Identity Address is'), '$nickname' => $nickname, '$subdir' => $subdir, '$basepath' => $a->get_hostname()));
     $stpl = get_markup_template('settings.tpl');
     $celeb = $a->user['page-flags'] == PAGE_SOAPBOX || $a->user['page-flags'] == PAGE_COMMUNITY ? true : false;
     $expire_arr = array('days' => array('expire', t("Automatically expire posts after days:"), $expire, t('If empty, posts will not expire. Expired posts will be deleted')), 'advanced' => t('Advanced expiration settings'), 'label' => t('Advanced Expiration'), 'items' => array('expire_items', t("Expire posts:"), $expire_items, '', array(t('No'), t('Yes'))), 'notes' => array('expire_notes', t("Expire personal notes:"), $expire_notes, '', array(t('No'), t('Yes'))), 'starred' => array('expire_starred', t("Expire starred posts:"), $expire_starred, '', array(t('No'), t('Yes'))), 'photos' => array('expire_photos', t("Expire photos:"), $expire_photos, '', array(t('No'), t('Yes'))));
     $o .= replace_macros($stpl, array('$tabs' => $tabs, '$ptitle' => t('Account Settings'), '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(), '$uid' => local_user(), '$nickname_block' => $prof_addr, '$h_pass' => t('Password Settings'), '$password1' => array('npassword', t('New Password:'******'', ''), '$password2' => array('confirm', t('Confirm:'), '', t('Leave password fields blank unless changing')), '$oid_enable' => !get_config('system', 'no_openid'), '$openid' => $openid_field, '$h_basic' => t('Basic Settings'), '$username' => array('username', t('Full Name:'), $username, ''), '$email' => array('email', t('Email Address:'), $email, ''), '$timezone' => array('timezone_select', t('Your Timezone:'), select_timezone($timezone), ''), '$defloc' => array('defloc', t('Default Post Location:'), $defloc, ''), '$allowloc' => array('allow_location', t('Use Browser Location:'), $a->user['allow_location'] == 1, ''), '$theme' => array('theme', t('Display Theme:'), $theme_selected, '', $themes), '$h_prv' => t('Security and Privacy Settings'), '$maxreq' => array('maxreq', t('Maximum Friend Requests/Day:'), $maxreq, t("(to prevent spam abuse)")), '$permissions' => t('Default Post Permissions'), '$permdesc' => t("(click to open/close)"), '$visibility' => $profile['net-publish'], '$aclselect' => populate_acl($a->user, $celeb), '$suggestme' => $suggestme, '$blockwall' => $blockwall, '$blocktags' => $blocktags, '$expire' => $expire_arr, '$profile_in_dir' => $profile_in_dir, '$profile_in_net_dir' => $profile_in_net_dir, '$hide_friends' => $hide_friends, '$hide_wall' => $hide_wall, '$h_not' => t('Notification Settings'), '$lbl_not' => t('Send a notification email when:'), '$notify1' => array('notify1', t('You receive an introduction'), $notify & NOTIFY_INTRO, NOTIFY_INTRO, ''), '$notify2' => array('notify2', t('Your introductions are confirmed'), $notify & NOTIFY_CONFIRM, NOTIFY_CONFIRM, ''), '$notify3' => array('notify3', t('Someone writes on your profile wall'), $notify & NOTIFY_WALL, NOTIFY_WALL, ''), '$notify4' => array('notify4', t('Someone writes a followup comment'), $notify & NOTIFY_COMMENT, NOTIFY_COMMENT, ''), '$notify5' => array('notify5', t('You receive a private message'), $notify & NOTIFY_MAIL, NOTIFY_MAIL, ''), '$h_advn' => t('Advanced Page Settings'), '$pagetype' => $pagetype));
     call_hooks('settings_form', $o);
     $o .= '</form>' . "\r\n";
     return $o;
 }
Example #14
0
function search_content(&$a)
{
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (get_config('system', 'local_search') and !local_user()) {
        notice(t('Public access denied.') . EOL);
        return;
        //http_status_exit(403);
        //killme();
    }
    nav_set_selected('search');
    $o = '<h3>' . t('Search') . '</h3>';
    if (x($a->data, 'search')) {
        $search = notags(trim($a->data['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    $tag = false;
    if (x($_GET, 'tag')) {
        $tag = true;
        $search = x($_GET, 'tag') ? notags(trim(rawurldecode($_GET['tag']))) : '';
    }
    $o .= search($search, 'search-box', '/search', local_user() ? true : false, false);
    if (strpos($search, '#') === 0) {
        $tag = true;
        $search = substr($search, 1);
    }
    if (strpos($search, '@') === 0) {
        return dirfind_content($a);
    }
    if (strpos($search, '!') === 0) {
        return dirfind_content($a);
    }
    if (x($_GET, 'search-option')) {
        switch ($_GET['search-option']) {
            case 'fulltext':
                break;
            case 'tags':
                $tag = true;
                break;
            case 'contacts':
                return dirfind_content($a, "@");
                break;
            case 'forums':
                return dirfind_content($a, "!");
                break;
        }
    }
    if (!$search) {
        return $o;
    }
    if (get_config('system', 'only_tag_search')) {
        $tag = true;
    }
    // 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 ($tag) {
        logger("Start tag search for '" . $search . "'", LOGGER_DEBUG);
        $r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,\n\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,\n\t\t\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,\n\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM `term`\n\t\t\t\tINNER JOIN `item` ON `item`.`id`=`term`.`oid`\n\t\t\t\tINNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`\n\t\t\tWHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`\n\t\t\t\tAND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s'\n\t\t\tORDER BY term.created DESC LIMIT %d , %d ", intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)), intval($a->pager['start']), intval($a->pager['itemspage']));
    } else {
        logger("Start fulltext search for '" . $search . "'", LOGGER_DEBUG);
        if (get_config('system', 'use_fulltext_engine')) {
            $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
        } else {
            $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
        }
        $r = q("SELECT STRAIGHT_JOIN `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,\n\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,\n\t\t\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,\n\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item`\n\t\t\t\tINNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`\n\t\t\tWHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`\n\t\t\t\tAND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND (`item`.`private` OR NOT `item`.`network` IN ('%s', '%s', '%s'))))\n\t\t\t\t{$sql_extra}\n\t\t\tGROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d ", intval(local_user()), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), intval($a->pager['start']), intval($a->pager['itemspage']));
    }
    if (!count($r)) {
        info(t('No results.') . EOL);
        return $o;
    }
    if ($tag) {
        $title = sprintf(t('Items tagged with: %s'), $search);
    } else {
        $title = sprintf(t('Search results for: %s'), $search);
    }
    $o .= replace_macros(get_markup_template("section_title.tpl"), array('$title' => $title));
    logger("Start Conversation for '" . $search . "'", LOGGER_DEBUG);
    $o .= conversation($a, $r, 'search', false);
    $o .= alt_pager($a, count($r));
    logger("Done '" . $search . "'", LOGGER_DEBUG);
    return $o;
}
Example #15
0
function events_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('all_events');
    if (argc() > 2 && argv(1) === 'ignore' && intval(argv(2))) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    if (argc() > 2 && argv(1) === 'unignore' && intval(argv(2))) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : 'textareas'));
    $o = "";
    // tabs
    $channel = $a->get_channel();
    $tabs = profile_tabs($a, True, $channel['channel_address']);
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? " and ignored = " . intval($_REQUEST['ignored']) . " " : '';
    if (argc() > 1) {
        if (argc() > 2 && argv(1) == 'event') {
            $mode = 'edit';
            $event_id = argv(2);
        }
        if (argc() > 2 && argv(1) === 'add') {
            $mode = 'add';
            $item_id = intval(argv(2));
        }
        if (argc() > 2 && argv(1) === 'drop') {
            $mode = 'drop';
            $event_id = argv(2);
        }
        if (argv(1) === 'new') {
            $mode = 'new';
            $event_id = '';
        }
        if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
            $mode = 'view';
            $y = intval(argv(1));
            $m = intval(argv(2));
        }
    }
    if ($mode === 'add') {
        event_addtocal($item_id, local_channel());
        killme();
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        $export = false;
        if (argc() === 4 && argv(3) === 'export') {
            $export = true;
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if (argv(1) === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']));
        } else {
            // fixed an issue with "nofinish" events not showing up in the calendar.
            // There's still an issue if the finish date crosses the end of month.
            // Noting this for now - it will need to be fixed here and in Friendica.
            // Ultimately the finish date shouldn't be involved in the query.
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                              from event left join item on event_hash = resource_id \n\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored}\n\t\t\t\tAND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if ($r) {
            xchan_query($r);
            $r = fetch_post_tags($r, true);
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if ($r) {
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                // FIXME
                $edit = $rr['item_flags'] & ITEM_WALL ? array($a->get_baseurl() . '/events/event/' . $rr['event_hash'], t('Edit event'), '', '') : null;
                $drop = array($a->get_baseurl() . '/events/drop/' . $rr['event_hash'], t('Delete event'), '', '');
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
            }
        }
        if ($export) {
            header('Content-type: text/calendar');
            header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"');
            echo ical_wrapper($r);
            killme();
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            $tpl = get_markup_template("events-js.tpl");
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array($a->get_baseurl() . "/events/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'drop' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if ($r) {
            $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event_id), intval(local_channel()));
            if ($r) {
                $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()));
                info(t('Event removed') . EOL);
            } else {
                notice(t('Failed to remove event') . EOL);
            }
            goaway(z_root() . '/events');
        }
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    $channel = $a->get_channel();
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['description'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $event_xchan = x($orig_event) ? $orig_event['event_xchan'] : $channel['channel_hash'];
        $mid = x($orig_event) ? $orig_event['mid'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = ($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' || !$orig_event['allow_cid']) && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($orig_event['event_xchan']) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $stext = datetime_convert('UTC', $tz, $sdt);
        $stext = substr($stext, 0, 14) . "00:00";
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $ftext = datetime_convert('UTC', $tz, $fdt);
        $ftext = substr($ftext, 0, 14) . "00:00";
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $catsenabled = feature_enabled(local_channel(), 'categories');
        $category = '';
        if ($catsenabled && x($orig_event)) {
            $itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1", dbesc($orig_event['event_hash']), intval(local_channel()));
            $itm = fetch_post_tags($itm);
            if ($itm) {
                $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
                foreach ($cats as $cat) {
                    if (strlen($category)) {
                        $category .= ', ';
                    }
                    $category .= $cat['term'];
                }
            }
        }
        require_once 'include/acl_selectors.php';
        $perm_defaults = 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']);
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$category' => $category, '$s_text' => t('Event Starts:'), '$stext' => $stext, '$ftext' => $ftext, '$required' => ' <span class="required" title="' . t('Required') . '">*</span>', '$ModalCANCEL' => t('Cancel'), '$ModalOK' => t('OK'), '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$adjust' => array('adjust', t('Adjust for viewer timezone'), $a_checked, t('Important for events that happen in a particular place. Not practical for global holidays.')), '$a_text' => t('Adjust for viewer timezone'), '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:'), '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$permissions' => t('Permissions'), '$acl' => $orig_event['event_xchan'] ? '' : populate_acl(x($orig_event) ? $orig_event : $perm_defaults, false), '$submit' => t('Submit')));
        return $o;
    }
}
Example #16
0
function notifications_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('notifications');
    $json = $a->argc > 1 && $a->argv[$a->argc - 1] === 'json' ? true : false;
    $o = '';
    $tabs = array(array('label' => t('System'), 'url' => $a->get_baseurl(true) . '/notifications/system', 'sel' => $a->argv[1] == 'system' ? 'active' : ''), array('label' => t('Network'), 'url' => $a->get_baseurl(true) . '/notifications/network', 'sel' => $a->argv[1] == 'network' ? 'active' : ''), array('label' => t('Personal'), 'url' => $a->get_baseurl(true) . '/notifications/personal', 'sel' => $a->argv[1] == 'personal' ? 'active' : ''), array('label' => t('Home'), 'url' => $a->get_baseurl(true) . '/notifications/home', 'sel' => $a->argv[1] == 'home' ? 'active' : ''), array('label' => t('Introductions'), 'url' => $a->get_baseurl(true) . '/notifications/intros', 'sel' => $a->argv[1] == 'intros' ? 'active' : ''));
    $o = "";
    if ($a->argc > 1 && $a->argv[1] == 'intros' || $a->argc == 1) {
        nav_set_selected('introductions');
        if ($a->argc > 2 && $a->argv[2] == 'all') {
            $sql_extra = '';
        } else {
            $sql_extra = " AND `ignore` = 0 ";
        }
        $notif_tpl = get_markup_template('notifications.tpl');
        $notif_content .= '<a href="' . (strlen($sql_extra) ? 'notifications/intros/all' : 'notifications/intros') . '" id="notifications-show-hide-link" >' . (strlen($sql_extra) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
        $r = q("SELECT COUNT(*)\tAS `total` FROM `intro`\n\t\t\tWHERE `intro`.`uid` = %d {$sql_extra} AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']));
        if ($r && count($r)) {
            $a->set_pager_total($r[0]['total']);
            $a->set_pager_itemspage(20);
        }
        $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest`\n\t\t\tFROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d {$sql_extra} AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']));
        if ($r !== false && count($r)) {
            $sugg = get_markup_template('suggestions.tpl');
            $tpl = get_markup_template("intros.tpl");
            foreach ($r as $rr) {
                if ($rr['fid']) {
                    $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . ($a->path ? '/' . $a->path : ''));
                    $notif_content .= replace_macros($sugg, array('$str_notifytype' => t('Notification type: '), '$notify_type' => t('Friend Suggestion'), '$intro_id' => $rr['intro_id'], '$madeby' => sprintf(t('suggested by %s'), $rr['name']), '$contact_id' => $rr['contact-id'], '$photo' => x($rr, 'fphoto') ? $rr['fphoto'] : "images/person-175.jpg", '$fullname' => $rr['fname'], '$url' => zrl($rr['furl']), '$hidden' => array('hidden', t('Hide this contact from others'), $rr['hidden'] == 1, ''), '$activity' => array('activity', t('Post a new friend activity'), intval(get_pconfig(local_user(), 'system', 'post_newfriend')) ? '1' : 0, t('if applicable')), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $rr['note'], '$request' => $rr['frequest'] . '?addr=' . $return_addr, '$ignore' => t('Ignore'), '$discard' => t('Discard')));
                    continue;
                }
                $friend_selected = $rr['network'] !== NETWORK_OSTATUS ? ' checked="checked" ' : ' disabled ';
                $fan_selected = $rr['network'] === NETWORK_OSTATUS ? ' checked="checked" disabled ' : '';
                $dfrn_tpl = get_markup_template('netfriend.tpl');
                $knowyou = '';
                $dfrn_text = '';
                if ($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
                    if ($rr['network'] === NETWORK_DFRN) {
                        $knowyou = t('Claims to be known to you: ') . ($rr['knowyou'] ? t('yes') : t('no'));
                        $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: ');
                    } else {
                        $knowyou = '';
                        $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: ');
                    }
                    $dfrn_text = replace_macros($dfrn_tpl, array('$intro_id' => $rr['intro_id'], '$friend_selected' => $friend_selected, '$fan_selected' => $fan_selected, '$approve_as' => $helptext, '$as_friend' => t('Friend'), '$as_fan' => $rr['network'] == NETWORK_DIASPORA ? t('Sharer') : t('Fan/Admirer')));
                }
                $notif_content .= replace_macros($tpl, array('$str_notifytype' => t('Notification type: '), '$notify_type' => $rr['network'] !== NETWORK_OSTATUS ? t('Friend/Connect Request') : t('New Follower'), '$dfrn_text' => $dfrn_text, '$dfrn_id' => $rr['issued-id'], '$uid' => $_SESSION['uid'], '$intro_id' => $rr['intro_id'], '$contact_id' => $rr['contact-id'], '$photo' => x($rr, 'photo') ? $rr['photo'] : "images/person-175.jpg", '$fullname' => $rr['name'], '$hidden' => array('hidden', t('Hide this contact from others'), $rr['hidden'] == 1, ''), '$activity' => array('activity', t('Post a new friend activity'), intval(get_pconfig(local_user(), 'system', 'post_newfriend')) ? '1' : 0, t('if applicable')), '$url' => zrl($rr['url']), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $rr['note'], '$ignore' => t('Ignore'), '$discard' => t('Discard')));
            }
        } else {
            info(t('No introductions.') . EOL);
        }
        $o .= replace_macros($notif_tpl, array('$notif_header' => t('Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
        $o .= paginate($a);
        return $o;
    } else {
        if ($a->argc > 1 && $a->argv[1] == 'network') {
            $notif_tpl = get_markup_template('notifications.tpl');
            $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC", intval(local_user()));
            $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
            $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
            $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
            $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
            $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
            $notif_content = '';
            if ($r) {
                foreach ($r as $it) {
                    switch ($it['verb']) {
                        case ACTIVITY_LIKE:
                            $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                            break;
                        case ACTIVITY_DISLIKE:
                            $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                            break;
                        case ACTIVITY_FRIEND:
                            $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                            $obj = parse_xml_string($xmlhead . $it['object']);
                            $it['fname'] = $obj->title;
                            $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                            break;
                        default:
                            $item_text = $it['id'] == $it['parent'] ? sprintf(t("%s created a new post"), $it['author-name']) : sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
                            $tpl = $it['id'] == $it['parent'] ? $tpl_item_posts : $tpl_item_comments;
                            $notif_content .= replace_macros($tpl, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => $item_text, '$item_when' => relative_date($it['created'])));
                    }
                }
            } else {
                $notif_content = t('No more network notifications.');
            }
            $o .= replace_macros($notif_tpl, array('$notif_header' => t('Network Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
        } else {
            if ($a->argc > 1 && $a->argv[1] == 'system') {
                $notif_tpl = get_markup_template('notifications.tpl');
                $not_tpl = get_markup_template('notify.tpl');
                require_once 'include/bbcode.php';
                $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc", intval(local_user()));
                if (count($r) > 0) {
                    foreach ($r as $it) {
                        $notif_content .= replace_macros($not_tpl, array('$item_link' => $a->get_baseurl(true) . '/notify/view/' . $it['id'], '$item_image' => $it['photo'], '$item_text' => strip_tags(bbcode($it['msg'])), '$item_when' => relative_date($it['date'])));
                    }
                } else {
                    $notif_content .= t('No more system notifications.');
                }
                $o .= replace_macros($notif_tpl, array('$notif_header' => t('System Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
            } else {
                if ($a->argc > 1 && $a->argv[1] == 'personal') {
                    $notif_tpl = get_markup_template('notifications.tpl');
                    $myurl = $a->get_baseurl(true) . '/profile/' . $a->user['nickname'];
                    $myurl = substr($myurl, strpos($myurl, '://') + 3);
                    $myurl = str_replace(array('www.', '.'), array('', '\\.'), $myurl);
                    $diasp_url = str_replace('/profile/', '/u/', $myurl);
                    $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", dbesc($myurl . '$'), dbesc($myurl . '\\]'), dbesc($diasp_url . '\\]'));
                    $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1\n\t\t\t\t{$sql_extra}\n\t\t\t\tAND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC", intval(local_user()));
                    $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
                    $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
                    $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
                    $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
                    $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
                    $notif_content = '';
                    if (count($r) > 0) {
                        foreach ($r as $it) {
                            switch ($it['verb']) {
                                case ACTIVITY_LIKE:
                                    $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                    break;
                                case ACTIVITY_DISLIKE:
                                    $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                    break;
                                case ACTIVITY_FRIEND:
                                    $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                                    $obj = parse_xml_string($xmlhead . $it['object']);
                                    $it['fname'] = $obj->title;
                                    $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                                    break;
                                default:
                                    $item_text = $it['id'] == $it['parent'] ? sprintf(t("%s created a new post"), $it['author-name']) : sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
                                    $tpl = $it['id'] == $it['parent'] ? $tpl_item_posts : $tpl_item_comments;
                                    $notif_content .= replace_macros($tpl, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => $item_text, '$item_when' => relative_date($it['created'])));
                            }
                        }
                    } else {
                        $notif_content = t('No more personal notifications.');
                    }
                    $o .= replace_macros($notif_tpl, array('$notif_header' => t('Personal Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
                } else {
                    if ($a->argc > 1 && $a->argv[1] == 'home') {
                        $notif_tpl = get_markup_template('notifications.tpl');
                        $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC", intval(local_user()));
                        $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
                        $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
                        $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
                        $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
                        $notif_content = '';
                        if (count($r) > 0) {
                            foreach ($r as $it) {
                                switch ($it['verb']) {
                                    case ACTIVITY_LIKE:
                                        $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                        break;
                                    case ACTIVITY_DISLIKE:
                                        $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                        break;
                                    case ACTIVITY_FRIEND:
                                        $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                                        $obj = parse_xml_string($xmlhead . $it['object']);
                                        $it['fname'] = $obj->title;
                                        $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                                        break;
                                    default:
                                        $notif_content .= replace_macros($tpl_item_comments, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                }
                            }
                        } else {
                            $notif_content = t('No more home notifications.');
                        }
                        $o .= replace_macros($notif_tpl, array('$notif_header' => t('Home Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
                    }
                }
            }
        }
    }
    $o .= paginate($a);
    return $o;
}
Example #17
0
function help_content(&$a)
{
    nav_set_selected('help');
    if ($_REQUEST['search']) {
        $o .= '<div id="help-content" class="generic-content-wrapper">';
        $o .= '<div class="section-title-wrapper">';
        $o .= '<h2>' . t('Documentation Search') . ' - ' . htmlspecialchars($_REQUEST['search']) . '</h2>';
        $o .= '</div>';
        $o .= '<div class="section-content-wrapper">';
        $r = search_doc_files($_REQUEST['search']);
        if ($r) {
            $o .= '<ul class="help-searchlist">';
            foreach ($r as $rr) {
                $dirname = dirname($rr['sid']);
                $fname = basename($rr['sid']);
                $fname = substr($fname, 0, strrpos($fname, '.'));
                $path = trim(substr($dirname, 4), '/');
                $o .= '<li><a href="help/' . ($path ? $path . '/' : '') . $fname . '" >' . ucwords(str_replace('_', ' ', notags($fname))) . '</a><br />' . str_replace('$Projectname', Zotlabs\Project\System::get_platform_name(), substr($rr['text'], 0, 200)) . '...<br /><br /></li>';
            }
            $o .= '</ul>';
            $o .= '</div>';
            $o .= '</div>';
        }
        return $o;
    }
    global $lang;
    $doctype = 'markdown';
    $text = '';
    if (argc() > 1) {
        $path = '';
        for ($x = 1; $x < argc(); $x++) {
            if (strlen($path)) {
                $path .= '/';
            }
            $path .= argv($x);
        }
        $title = basename($path);
        $text = load_doc_file('doc/' . $path . '.md');
        App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('-', ' ', notags($title)));
        if (!$text) {
            $text = load_doc_file('doc/' . $path . '.bb');
            if ($text) {
                $doctype = 'bbcode';
            }
            App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('_', ' ', notags($title)));
        }
        if (!$text) {
            $text = load_doc_file('doc/' . $path . '.html');
            if ($text) {
                $doctype = 'html';
            }
            App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('-', ' ', notags($title)));
        }
    }
    if (!$text) {
        $text = load_doc_file('doc/Site.md');
        App::$page['title'] = t('Help');
    }
    if (!$text) {
        $doctype = 'bbcode';
        $text = load_doc_file('doc/main.bb');
        App::$page['title'] = t('Help');
    }
    if (!strlen($text)) {
        header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
        $tpl = get_markup_template("404.tpl");
        return replace_macros($tpl, array('$message' => t('Page not found.')));
    }
    if ($doctype === 'html') {
        $content = $text;
    }
    if ($doctype === 'markdown') {
        require_once 'library/markdown.php';
        # escape #include tags
        $text = preg_replace('/#include/ism', '%%include', $text);
        $content = Markdown($text);
        $content = preg_replace('/%%include/ism', '#include', $content);
    }
    if ($doctype === 'bbcode') {
        require_once 'include/bbcode.php';
        $content = bbcode($text);
        // bbcode retargets external content to new windows. This content is internal.
        $content = str_replace(' target="_blank"', '', $content);
    }
    $content = preg_replace_callback("/#include (.*?)\\;/ism", 'preg_callback_help_include', $content);
    return replace_macros(get_markup_template("help.tpl"), array('$title' => t('$Projectname Documentation'), '$content' => translate_projectname($content)));
}
Example #18
0
function connections_content(&$a)
{
    $sort_type = 0;
    $o = '';
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return login();
    }
    $blocked = false;
    $hidden = false;
    $ignored = false;
    $archived = false;
    $unblocked = false;
    $pending = false;
    $unconnected = false;
    $all = false;
    if (!$_REQUEST['aj']) {
        $_SESSION['return_url'] = $a->query_string;
    }
    $search_flags = 0;
    $head = '';
    if (argc() == 2) {
        switch (argv(1)) {
            case 'blocked':
                $search_flags = ABOOK_FLAG_BLOCKED;
                $head = t('Blocked');
                $blocked = true;
                break;
            case 'ignored':
                $search_flags = ABOOK_FLAG_IGNORED;
                $head = t('Ignored');
                $ignored = true;
                break;
            case 'hidden':
                $search_flags = ABOOK_FLAG_HIDDEN;
                $head = t('Hidden');
                $hidden = true;
                break;
            case 'archived':
                $search_flags = ABOOK_FLAG_ARCHIVED;
                $head = t('Archived');
                $archived = true;
                break;
            case 'pending':
                $search_flags = ABOOK_FLAG_PENDING;
                $head = t('New');
                $pending = true;
                nav_set_selected('intros');
                break;
            case 'ifpending':
                $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", intval(local_channel()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF | ABOOK_FLAG_IGNORED), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
                if ($r && $r[0]['total']) {
                    $search_flags = ABOOK_FLAG_PENDING;
                    $head = t('New');
                    $pending = true;
                    nav_set_selected('intros');
                    $a->argv[1] = 'pending';
                } else {
                    $head = t('All');
                    $search_flags = 0;
                    $all = true;
                    $a->argc = 1;
                    unset($a->argv[1]);
                }
                nav_set_selected('intros');
                break;
                //			case 'unconnected':
                //				$search_flags = ABOOK_FLAG_UNCONNECTED;
                //				$head = t('Unconnected');
                //				$unconnected = true;
                //				break;
            //			case 'unconnected':
            //				$search_flags = ABOOK_FLAG_UNCONNECTED;
            //				$head = t('Unconnected');
            //				$unconnected = true;
            //				break;
            case 'all':
                $head = t('All');
            default:
                $search_flags = 0;
                $all = true;
                break;
        }
        $sql_extra = $search_flags ? " and ( abook_flags & " . $search_flags . " )>0 " : "";
        if (argv(1) === 'pending') {
            $sql_extra .= " and not ( abook_flags & " . ABOOK_FLAG_IGNORED . " )>0 ";
        }
    } else {
        $sql_extra = " and not ( abook_flags & " . ABOOK_FLAG_BLOCKED . " )>0 ";
        $unblocked = true;
    }
    $search = x($_REQUEST, 'search') ? notags(trim($_REQUEST['search'])) : '';
    $tabs = array(array('label' => t('Suggestions'), 'url' => z_root() . '/suggest', 'sel' => '', 'title' => t('Suggest new connections')), array('label' => t('New Connections'), 'url' => z_root() . '/connections/pending', 'sel' => $pending ? 'active' : '', 'title' => t('Show pending (new) connections')), array('label' => t('All Connections'), 'url' => z_root() . '/connections/all', 'sel' => $all ? 'active' : '', 'title' => t('Show all connections')), array('label' => t('Unblocked'), 'url' => z_root() . '/connections', 'sel' => $unblocked && !$search && !$nets ? 'active' : '', 'title' => t('Only show unblocked connections')), array('label' => t('Blocked'), 'url' => z_root() . '/connections/blocked', 'sel' => $blocked ? 'active' : '', 'title' => t('Only show blocked connections')), array('label' => t('Ignored'), 'url' => z_root() . '/connections/ignored', 'sel' => $ignored ? 'active' : '', 'title' => t('Only show ignored connections')), array('label' => t('Archived'), 'url' => z_root() . '/connections/archived', 'sel' => $archived ? 'active' : '', 'title' => t('Only show archived connections')), array('label' => t('Hidden'), 'url' => z_root() . '/connections/hidden', 'sel' => $hidden ? 'active' : '', 'title' => t('Only show hidden connections')));
    $tab_tpl = get_markup_template('common_tabs.tpl');
    $t = replace_macros($tab_tpl, array('$tabs' => $tabs));
    $searching = false;
    if ($search) {
        $search_hdr = $search;
        $search_txt = dbesc(protect_sprintf(preg_quote($search)));
        $searching = true;
    }
    $sql_extra .= $searching ? protect_sprintf(" AND xchan_name like '%{$search_txt}%' ") : "";
    if ($_REQUEST['gid']) {
        $sql_extra .= " and xchan_hash in ( select xchan from group_member where gid = " . intval($_REQUEST['gid']) . " and uid = " . intval(local_channel()) . " ) ";
    }
    $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash \n\t\twhere abook_channel = %d and not (abook_flags & %d)>0 and not (xchan_flags & %d )>0 {$sql_extra} {$sql_extra2} ", intval(local_channel()), intval(ABOOK_FLAG_SELF), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
    if ($r) {
        $a->set_pager_total($r[0]['total']);
        $total = $r[0]['total'];
    }
    $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash\n\t\tWHERE abook_channel = %d and not (abook_flags & %d)>0 and not ( xchan_flags & %d)>0 {$sql_extra} {$sql_extra2} ORDER BY xchan_name LIMIT %d OFFSET %d ", intval(local_channel()), intval(ABOOK_FLAG_SELF), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN), intval($a->pager['itemspage']), intval($a->pager['start']));
    $contacts = array();
    if (count($r)) {
        foreach ($r as $rr) {
            if ($rr['xchan_url']) {
                $contacts[] = array('img_hover' => sprintf(t('%1$s [%2$s]'), $rr['xchan_name'], $rr['xchan_url']), 'edit_hover' => t('Edit connection'), 'id' => $rr['abook_id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, 'thumb' => $rr['xchan_photo_m'], 'name' => $rr['xchan_name'], 'username' => $rr['xchan_name'], 'classes' => $rr['abook_flags'] & ABOOK_FLAG_ARCHIVED ? 'archived' : '', 'link' => z_root() . '/connedit/' . $rr['abook_id'], 'edit' => t('Edit'), 'url' => chanlink_url($rr['xchan_url']), 'network' => network_to_name($rr['network']));
            }
        }
    }
    if ($_REQUEST['aj']) {
        if ($contacts) {
            $o = replace_macros(get_markup_template('contactsajax.tpl'), array('$contacts' => $contacts, '$edit' => t('Edit')));
        } 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>";
        $o .= replace_macros(get_markup_template('connections.tpl'), array('$header' => t('Connections') . ($head ? ' - ' . $head : ''), '$tabs' => $t, '$total' => $total, '$search' => $search_hdr, '$desc' => t('Search your connections'), '$finding' => $searching ? t('Finding: ') . "'" . $search . "'" : "", '$submit' => t('Find'), '$edit' => t('Edit'), '$cmd' => $a->cmd, '$contacts' => $contacts, '$paginate' => paginate($a)));
    }
    if (!$contacts) {
        $o .= '<div id="content-complete"></div>';
    }
    return $o;
}
Example #19
0
 function get()
 {
     if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $observer = get_observer_hash();
     $globaldir = get_directory_setting($observer, 'globaldir');
     // override your personal global search pref if we're doing a navbar search of the directory
     if (intval($_REQUEST['navsearch'])) {
         $globaldir = 1;
     }
     $safe_mode = get_directory_setting($observer, 'safemode');
     $pubforums = get_directory_setting($observer, 'pubforums');
     $o = '';
     nav_set_selected('directory');
     if (x($_POST, 'search')) {
         $search = notags(trim($_POST['search']));
     } else {
         $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
     }
     if (strpos($search, '=') && local_channel() && get_pconfig(local_channel(), 'feature', 'expert')) {
         $advanced = $search;
     }
     $keywords = $_GET['keywords'] ? $_GET['keywords'] : '';
     // Suggest channels if no search terms or keywords are given
     $suggest = local_channel() && x($_REQUEST, 'suggest') ? $_REQUEST['suggest'] : '';
     if ($suggest) {
         $r = suggestion_query(local_channel(), get_observer_hash());
         // Remember in which order the suggestions were
         $addresses = array();
         $common = array();
         $index = 0;
         foreach ($r as $rr) {
             $common[$rr['xchan_addr']] = $rr['total'];
             $addresses[$rr['xchan_addr']] = $index++;
         }
         // Build query to get info about suggested people
         $advanced = '';
         foreach (array_keys($addresses) as $address) {
             $advanced .= "address=\"{$address}\" ";
         }
         // Remove last space in the advanced query
         $advanced = rtrim($advanced);
     }
     $tpl = get_markup_template('directory_header.tpl');
     $dirmode = intval(get_config('system', 'directory_mode'));
     if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
         $url = z_root() . '/dirsearch';
     }
     if (!$url) {
         $directory = find_upstream_directory($dirmode);
         if (!$directory || !array_key_exists('url', $directory) || !$directory['url']) {
             logger('CRITICAL: No directory server URL');
         }
         $url = $directory['url'] . '/dirsearch';
     }
     $token = get_config('system', 'realm_token');
     logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
     $contacts = array();
     if (local_channel()) {
         $x = q("select abook_xchan from abook where abook_channel = %d", intval(local_channel()));
         if ($x) {
             foreach ($x as $xx) {
                 $contacts[] = $xx['abook_xchan'];
             }
         }
     }
     if ($url) {
         $numtags = get_config('system', 'directorytags');
         $kw = intval($numtags) > 0 ? intval($numtags) : 50;
         if (get_config('system', 'disable_directory_keywords')) {
             $kw = 0;
         }
         $query = $url . '?f=&kw=' . $kw . ($safe_mode != 1 ? '&safe=' . $safe_mode : '');
         if ($token) {
             $query .= '&t=' . $token;
         }
         if (!$globaldir) {
             $query .= '&hub=' . \App::get_hostname();
         }
         if ($search) {
             $query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
         }
         if (strpos($search, '@')) {
             $query .= '&address=' . urlencode($search);
         }
         if ($keywords) {
             $query .= '&keywords=' . urlencode($keywords);
         }
         if ($advanced) {
             $query .= '&query=' . urlencode($advanced);
         }
         if (!is_null($pubforums)) {
             $query .= '&pubforums=' . intval($pubforums);
         }
         $directory_sort_order = get_config('system', 'directory_sort_order');
         if (!$directory_sort_order) {
             $directory_sort_order = 'date';
         }
         $sort_order = x($_REQUEST, 'order') ? $_REQUEST['order'] : $directory_sort_order;
         if ($sort_order) {
             $query .= '&order=' . urlencode($sort_order);
         }
         if (\App::$pager['page'] != 1) {
             $query .= '&p=' . \App::$pager['page'];
         }
         logger('mod_directory: query: ' . $query);
         $x = z_fetch_url($query);
         logger('directory: return from upstream: ' . print_r($x, true), LOGGER_DATA);
         if ($x['success']) {
             $t = 0;
             $j = json_decode($x['body'], true);
             if ($j) {
                 if ($j['results']) {
                     $entries = array();
                     $photo = 'thumb';
                     foreach ($j['results'] as $rr) {
                         $profile_link = chanlink_url($rr['url']);
                         $pdesc = $rr['description'] ? $rr['description'] . '<br />' : '';
                         $connect_link = local_channel() ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '';
                         // Checking status is disabled ATM until someone checks the performance impact more carefully
                         //$online = remote_online_status($rr['address']);
                         $online = '';
                         if (in_array($rr['hash'], $contacts)) {
                             $connect_link = '';
                         }
                         $location = '';
                         if (strlen($rr['locale'])) {
                             $location .= $rr['locale'];
                         }
                         if (strlen($rr['region'])) {
                             if (strlen($rr['locale'])) {
                                 $location .= ', ';
                             }
                             $location .= $rr['region'];
                         }
                         if (strlen($rr['country'])) {
                             if (strlen($location)) {
                                 $location .= ', ';
                             }
                             $location .= $rr['country'];
                         }
                         $age = '';
                         if (strlen($rr['birthday'])) {
                             if (($years = age($rr['birthday'], 'UTC', '')) != 0) {
                                 $age = $years;
                             }
                         }
                         $page_type = '';
                         if ($rr['total_ratings']) {
                             $total_ratings = sprintf(tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']);
                         } else {
                             $total_ratings = '';
                         }
                         $profile = $rr;
                         if (x($profile, 'locale') == 1 || x($profile, 'region') == 1 || x($profile, 'postcode') == 1 || x($profile, 'country') == 1) {
                             $gender = x($profile, 'gender') == 1 ? t('Gender: ') . $profile['gender'] : False;
                         }
                         $marital = x($profile, 'marital') == 1 ? t('Status: ') . $profile['marital'] : False;
                         $homepage = x($profile, 'homepage') == 1 ? t('Homepage: ') : False;
                         $homepageurl = x($profile, 'homepage') == 1 ? $profile['homepage'] : '';
                         $hometown = x($profile, 'hometown') == 1 ? $profile['hometown'] : False;
                         $about = x($profile, 'about') == 1 ? bbcode($profile['about']) : False;
                         $keywords = x($profile, 'keywords') ? $profile['keywords'] : '';
                         $out = '';
                         if ($keywords) {
                             $keywords = str_replace(',', ' ', $keywords);
                             $keywords = str_replace('  ', ' ', $keywords);
                             $karr = explode(' ', $keywords);
                             if ($karr) {
                                 if (local_channel()) {
                                     $r = q("select keywords from profile where uid = %d and is_default = 1 limit 1", intval(local_channel()));
                                     if ($r) {
                                         $keywords = str_replace(',', ' ', $r[0]['keywords']);
                                         $keywords = str_replace('  ', ' ', $keywords);
                                         $marr = explode(' ', $keywords);
                                     }
                                 }
                                 foreach ($karr as $k) {
                                     if (strlen($out)) {
                                         $out .= ', ';
                                     }
                                     if ($marr && in_arrayi($k, $marr)) {
                                         $out .= '<strong>' . $k . '</strong>';
                                     } else {
                                         $out .= $k;
                                     }
                                 }
                             }
                         }
                         $entry = array('id' => ++$t, 'profile_link' => $profile_link, 'public_forum' => $rr['public_forum'], 'photo' => $rr['photo'], 'hash' => $rr['hash'], 'alttext' => $rr['name'] . (local_channel() || remote_channel() ? ' ' . $rr['address'] : ''), 'name' => $rr['name'], 'age' => $age, 'age_label' => t('Age:'), 'profile' => $profile, 'address' => $rr['address'], 'nickname' => substr($rr['address'], 0, strpos($rr['address'], '@')), 'location' => $location, 'location_label' => t('Location:'), 'gender' => $gender, 'total_ratings' => $total_ratings, 'viewrate' => true, 'canrate' => local_channel() ? true : false, 'pdesc' => $pdesc, 'pdesc_label' => t('Description:'), 'marital' => $marital, 'homepage' => $homepage, 'homepageurl' => linkify($homepageurl), 'hometown' => $hometown, 'hometown_label' => t('Hometown:'), 'about' => $about, 'about_label' => t('About:'), 'conn_label' => t('Connect'), 'forum_label' => t('Public Forum:'), 'connect' => $connect_link, 'online' => $online, 'kw' => $out ? t('Keywords: ') : '', 'keywords' => $out, 'ignlink' => $suggest ? z_root() . '/directory?ignore=' . $rr['hash'] : '', 'ignore_label' => t('Don\'t suggest'), 'common_friends' => $common[$rr['address']] ? intval($common[$rr['address']]) : '', 'common_label' => t('Common connections:'), 'common_count' => intval($common[$rr['address']]), 'safe' => $safe_mode);
                         $arr = array('contact' => $rr, 'entry' => $entry);
                         call_hooks('directory_item', $arr);
                         unset($profile);
                         unset($location);
                         if (!$arr['entry']) {
                             continue;
                         }
                         if ($sort_order == '' && $suggest) {
                             $entries[$addresses[$rr['address']]] = $arr['entry'];
                             // Use the same indexes as originally to get the best suggestion first
                         } else {
                             $entries[] = $arr['entry'];
                         }
                     }
                     ksort($entries);
                     // Sort array by key so that foreach-constructs work as expected
                     if ($j['keywords']) {
                         \App::$data['directory_keywords'] = $j['keywords'];
                     }
                     logger('mod_directory: entries: ' . print_r($entries, true), LOGGER_DATA);
                     if ($_REQUEST['aj']) {
                         if ($entries) {
                             $o = replace_macros(get_markup_template('directajax.tpl'), array('$entries' => $entries));
                         } else {
                             $o = '<div id="content-complete"></div>';
                         }
                         echo $o;
                         killme();
                     } else {
                         $maxheight = 94;
                         $dirtitle = $globaldir ? t('Global Directory') : t('Local Directory');
                         $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; divmore_height = " . intval($maxheight) . ";  </script>";
                         $o .= replace_macros($tpl, array('$search' => $search, '$desc' => t('Find'), '$finddsc' => t('Finding:'), '$safetxt' => htmlspecialchars($search, ENT_QUOTES, 'UTF-8'), '$entries' => $entries, '$dirlbl' => $suggest ? t('Channel Suggestions') : $dirtitle, '$submit' => t('Find'), '$next' => alt_pager($a, $j['records'], t('next page'), t('previous page')), '$sort' => t('Sort options'), '$normal' => t('Alphabetic'), '$reverse' => t('Reverse Alphabetic'), '$date' => t('Newest to Oldest'), '$reversedate' => t('Oldest to Newest'), '$suggest' => $suggest ? '&suggest=1' : ''));
                     }
                 } else {
                     if ($_REQUEST['aj']) {
                         $o = '<div id="content-complete"></div>';
                         echo $o;
                         killme();
                     }
                     if (\App::$pager['page'] == 1 && $j['records'] == 0 && strpos($search, '@')) {
                         goaway(z_root() . '/chanview/?f=&address=' . $search);
                     }
                     info(t("No entries (some entries may be hidden).") . EOL);
                 }
             }
         }
     }
     return $o;
 }
Example #20
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;
 }
Example #21
0
function settings_content(&$a)
{
    $o = '';
    nav_set_selected('settings');
    if (!local_channel() || $_SESSION['delegate']) {
        notice(t('Permission denied.') . EOL);
        return login();
    }
    $channel = $a->get_channel();
    if ($channel) {
        head_set_icon($channel['xchan_photo_s']);
    }
    $yes_no = array(t('No'), t('Yes'));
    if (argc() > 1 && argv(1) === 'oauth') {
        if (argc() > 2 && argv(2) === 'add') {
            $tpl = get_markup_template("settings_oauth_edit.tpl");
            $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$title' => t('Add application'), '$submit' => t('Submit'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), '', t('Name of application')), '$key' => array('key', t('Consumer Key'), random_string(16), t('Automatically generated - change if desired. Max length 20')), '$secret' => array('secret', t('Consumer Secret'), random_string(16), t('Automatically generated - change if desired. Max length 20')), '$redirect' => array('redirect', t('Redirect'), '', t('Redirect URI - leave blank unless your application specifically requires this')), '$icon' => array('icon', t('Icon url'), '', t('Optional'))));
            return $o;
        }
        if (argc() > 3 && argv(2) === 'edit') {
            $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d", dbesc(argv(3)), local_channel());
            if (!count($r)) {
                notice(t("You can't edit this application."));
                return;
            }
            $app = $r[0];
            $tpl = get_markup_template("settings_oauth_edit.tpl");
            $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$title' => t('Add application'), '$submit' => t('Update'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), $app['name'], ''), '$key' => array('key', t('Consumer Key'), $app['client_id'], ''), '$secret' => array('secret', t('Consumer Secret'), $app['pw'], ''), '$redirect' => array('redirect', t('Redirect'), $app['redirect_uri'], ''), '$icon' => array('icon', t('Icon url'), $app['icon'], '')));
            return $o;
        }
        if (argc() > 3 && argv(2) === 'delete') {
            check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
            $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d", dbesc(argv(3)), local_channel());
            goaway($a->get_baseurl(true) . "/settings/oauth/");
            return;
        }
        $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my \n\t\t\t\tFROM clients\n\t\t\t\tLEFT JOIN tokens ON clients.client_id=tokens.client_id\n\t\t\t\tWHERE clients.uid IN (%d,0)", local_channel(), local_channel());
        $tpl = get_markup_template("settings_oauth.tpl");
        $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$baseurl' => $a->get_baseurl(true), '$title' => t('Connected Apps'), '$add' => t('Add application'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$consumerkey' => t('Client key starts with'), '$noname' => t('No name'), '$remove' => t('Remove authorization'), '$apps' => $r));
        return $o;
    }
    if (argc() > 1 && argv(1) === 'featured') {
        $settings_addons = "";
        $o = '';
        $r = q("SELECT * FROM `hook` WHERE `hook` = 'feature_settings' ");
        if (!$r) {
            $settings_addons = t('No feature settings configured');
        }
        call_hooks('feature_settings', $settings_addons);
        $tpl = get_markup_template("settings_addons.tpl");
        $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_featured"), '$title' => t('Feature/Addon Settings'), '$settings_addons' => $settings_addons));
        return $o;
    }
    /*
     * ACCOUNT SETTINGS
     */
    if (argc() > 1 && argv(1) === 'account') {
        $account_settings = "";
        call_hooks('account_settings', $account_settings);
        $email = $a->account['account_email'];
        $tpl = get_markup_template("settings_account.tpl");
        $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_account"), '$title' => t('Account Settings'), '$password1' => array('npassword', t('Enter New Password:'******'', ''), '$password2' => array('confirm', t('Confirm New Password:'******'', t('Leave password fields blank unless changing')), '$submit' => t('Submit'), '$email' => array('email', t('Email Address:'), $email, ''), '$removeme' => t('Remove Account'), '$removeaccount' => t('Remove this account including all its channels'), '$account_settings' => $account_settings));
        return $o;
    }
    if (argc() > 1 && argv(1) === 'features') {
        $arr = array();
        $features = get_features();
        foreach ($features as $fname => $fdata) {
            $arr[$fname] = array();
            $arr[$fname][0] = $fdata[0];
            foreach (array_slice($fdata, 1) as $f) {
                $arr[$fname][1][] = array('feature_' . $f[0], $f[1], intval(feature_enabled(local_channel(), $f[0])) ? "1" : '', $f[2], array(t('Off'), t('On')));
            }
        }
        $tpl = get_markup_template("settings_features.tpl");
        $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_features"), '$title' => t('Additional Features'), '$features' => $arr, '$submit' => t('Submit')));
        return $o;
    }
    if (argc() > 1 && argv(1) === 'connectors') {
        $settings_connectors = "";
        call_hooks('connector_settings', $settings_connectors);
        $r = null;
        $tpl = get_markup_template("settings_connectors.tpl");
        $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_connectors"), '$title' => t('Connector Settings'), '$submit' => t('Submit'), '$settings_connectors' => $settings_connectors));
        call_hooks('display_settings', $o);
        return $o;
    }
    /*
     * DISPLAY SETTINGS
     */
    if (argc() > 1 && argv(1) === 'display') {
        $default_theme = get_config('system', 'theme');
        if (!$default_theme) {
            $default_theme = 'default';
        }
        $default_mobile_theme = get_config('system', 'mobile_theme');
        if (!$mobile_default_theme) {
            $mobile_default_theme = 'none';
        }
        $allowed_themes_str = get_config('system', 'allowed_themes');
        $allowed_themes_raw = explode(',', $allowed_themes_str);
        $allowed_themes = array();
        if (count($allowed_themes_raw)) {
            foreach ($allowed_themes_raw as $x) {
                if (strlen(trim($x)) && is_dir("view/theme/{$x}")) {
                    $allowed_themes[] = trim($x);
                }
            }
        }
        $themes = array();
        $files = glob('view/theme/*');
        if ($allowed_themes) {
            foreach ($allowed_themes as $th) {
                $f = $th;
                $is_experimental = file_exists('view/theme/' . $th . '/experimental');
                $unsupported = file_exists('view/theme/' . $th . '/unsupported');
                $is_mobile = file_exists('view/theme/' . $th . '/mobile');
                $is_library = file_exists('view/theme/' . $th . '/library');
                $mobile_themes["---"] = t("No special theme for mobile devices");
                if (!$is_experimental or $is_experimental && (get_config('experimentals', 'exp_themes') == 1 or get_config('experimentals', 'exp_themes') === false)) {
                    $theme_name = $is_experimental ? sprintf(t('%s - (Experimental)'), $f) : $f;
                    if (!$is_library) {
                        if ($is_mobile) {
                            $mobile_themes[$f] = $themes[$f] = $theme_name . ' (' . t('mobile') . ')';
                        } else {
                            $mobile_themes[$f] = $themes[$f] = $theme_name;
                        }
                    }
                }
            }
        }
        $theme_selected = !x($_SESSION, 'theme') ? $default_theme : $_SESSION['theme'];
        $mobile_theme_selected = !x($_SESSION, 'mobile_theme') ? $default_mobile_theme : $_SESSION['mobile_theme'];
        $user_scalable = get_pconfig(local_channel(), 'system', 'user_scalable');
        $user_scalable = $user_scalable === false ? '1' : $user_scalable;
        // default if not set: 1
        $browser_update = intval(get_pconfig(local_channel(), 'system', 'update_interval'));
        $browser_update = $browser_update == 0 ? 80 : $browser_update / 1000;
        // default if not set: 40 seconds
        $itemspage = intval(get_pconfig(local_channel(), 'system', 'itemspage'));
        $itemspage = $itemspage > 0 && $itemspage < 101 ? $itemspage : 20;
        // default if not set: 20 items
        $nosmile = get_pconfig(local_channel(), 'system', 'no_smilies');
        $nosmile = $nosmile === false ? '0' : $nosmile;
        // default if not set: 0
        $title_tosource = get_pconfig(local_channel(), 'system', 'title_tosource');
        $title_tosource = $title_tosource === false ? '0' : $title_tosource;
        // default if not set: 0
        $theme_config = "";
        if (($themeconfigfile = get_theme_config_file($theme_selected)) != null) {
            require_once $themeconfigfile;
            $theme_config = theme_content($a);
        }
        $tpl = get_markup_template("settings_display.tpl");
        $o = replace_macros($tpl, array('$ptitle' => t('Display Settings'), '$d_tset' => t('Theme Settings'), '$d_ctset' => t('Custom Theme Settings'), '$d_cset' => t('Content Settings'), '$form_security_token' => get_form_security_token("settings_display"), '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(true), '$uid' => local_channel(), '$theme' => $themes ? array('theme', t('Display Theme:'), $theme_selected, '', $themes, 'preview') : false, '$mobile_theme' => $mobile_themes ? array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, '') : false, '$user_scalable' => array('user_scalable', t("Enable user zoom on mobile devices"), $user_scalable, '', $yes_no), '$ajaxint' => array('browser_update', t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds, no maximum')), '$itemspage' => array('itemspage', t("Maximum number of conversations to load at any time:"), $itemspage, t('Maximum of 100 items')), '$nosmile' => array('nosmile', t("Show emoticons (smilies) as images"), 1 - intval($nosmile), '', $yes_no), '$title_tosource' => array('title_tosource', t("Link post titles to source"), $title_tosource, '', $yes_no), '$layout_editor' => t('System Page Layout Editor - (advanced)'), '$theme_config' => $theme_config, '$expert' => feature_enabled(local_channel(), 'expert'), '$channel_list_mode' => array('channel_list_mode', t('Use blog/list mode on channel page'), get_pconfig(local_channel(), 'system', 'channel_list_mode'), t('(comments displayed separately)'), $yes_no), '$network_list_mode' => array('network_list_mode', t('Use blog/list mode on grid page'), get_pconfig(local_channel(), 'system', 'network_list_mode'), t('(comments displayed separately)'), $yes_no), '$channel_divmore_height' => array('channel_divmore_height', t('Channel page max height of content (in pixels)'), get_pconfig(local_channel(), 'system', 'channel_divmore_height') ? get_pconfig(local_channel(), 'system', 'channel_divmore_height') : 400, t('click to expand content exceeding this height')), '$network_divmore_height' => array('network_divmore_height', t('Grid page max height of content (in pixels)'), get_pconfig(local_channel(), 'system', 'network_divmore_height') ? get_pconfig(local_channel(), 'system', 'network_divmore_height') : 400, t('click to expand content exceeding this height'))));
        return $o;
    }
    if (argv(1) === 'channel') {
        require_once 'include/acl_selectors.php';
        require_once 'include/permissions.php';
        $p = q("SELECT * FROM `profile` WHERE `is_default` = 1 AND `uid` = %d LIMIT 1", intval(local_channel()));
        if (count($p)) {
            $profile = $p[0];
        }
        load_pconfig(local_channel(), 'expire');
        $channel = $a->get_channel();
        $global_perms = get_perms();
        $permiss = array();
        $perm_opts = array(array(t('Nobody except yourself'), 0), array(t('Only those you specifically allow'), PERMS_SPECIFIC), array(t('Approved connections'), PERMS_CONTACTS), array(t('Any connections'), PERMS_PENDING), array(t('Anybody on this website'), PERMS_SITE), array(t('Anybody in this network'), PERMS_NETWORK), array(t('Anybody authenticated'), PERMS_AUTHED), array(t('Anybody on the internet'), PERMS_PUBLIC));
        foreach ($global_perms as $k => $perm) {
            $options = array();
            foreach ($perm_opts as $opt) {
                if (!$perm[2] && $opt[1] == PERMS_PUBLIC) {
                    continue;
                }
                $options[$opt[1]] = $opt[0];
            }
            $permiss[] = array($k, $perm[3], $channel[$perm[0]], $perm[4], $options);
        }
        //		logger('permiss: ' . print_r($permiss,true));
        $username = $channel['channel_name'];
        $nickname = $channel['channel_address'];
        $timezone = $channel['channel_timezone'];
        $notify = $channel['channel_notifyflags'];
        $defloc = $channel['channel_location'];
        $maxreq = $channel['channel_max_friend_req'];
        $expire = $channel['channel_expire_days'];
        $adult_flag = intval($channel['channel_pageflags'] & PAGE_ADULT);
        $sys_expire = get_config('system', 'default_expire_days');
        //		$unkmail    = $a->user['unkmail'];
        //		$cntunkmail = $a->user['cntunkmail'];
        $hide_presence = intval(get_pconfig(local_channel(), 'system', 'hide_online_status'));
        $expire_items = get_pconfig(local_channel(), 'expire', 'items');
        $expire_items = $expire_items === false ? '1' : $expire_items;
        // default if not set: 1
        $expire_notes = get_pconfig(local_channel(), 'expire', 'notes');
        $expire_notes = $expire_notes === false ? '1' : $expire_notes;
        // default if not set: 1
        $expire_starred = get_pconfig(local_channel(), 'expire', 'starred');
        $expire_starred = $expire_starred === false ? '1' : $expire_starred;
        // default if not set: 1
        $expire_photos = get_pconfig(local_channel(), 'expire', 'photos');
        $expire_photos = $expire_photos === false ? '0' : $expire_photos;
        // default if not set: 0
        $expire_network_only = get_pconfig(local_channel(), 'expire', 'network_only');
        $expire_network_only = $expire_network_only === false ? '0' : $expire_network_only;
        // default if not set: 0
        $suggestme = get_pconfig(local_channel(), 'system', 'suggestme');
        $suggestme = $suggestme === false ? '0' : $suggestme;
        // default if not set: 0
        $post_newfriend = get_pconfig(local_channel(), 'system', 'post_newfriend');
        $post_newfriend = $post_newfriend === false ? '0' : $post_newfriend;
        // default if not set: 0
        $post_joingroup = get_pconfig(local_channel(), 'system', 'post_joingroup');
        $post_joingroup = $post_joingroup === false ? '0' : $post_joingroup;
        // default if not set: 0
        $post_profilechange = get_pconfig(local_channel(), 'system', 'post_profilechange');
        $post_profilechange = $post_profilechange === false ? '0' : $post_profilechange;
        // default if not set: 0
        $blocktags = get_pconfig(local_channel(), 'system', 'blocktags');
        $blocktags = $blocktags === false ? '0' : $blocktags;
        $timezone = date_default_timezone_get();
        $opt_tpl = get_markup_template("field_checkbox.tpl");
        if (get_config('system', 'publish_all')) {
            $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
        } else {
            $profile_in_dir = replace_macros($opt_tpl, array('$field' => array('profile_in_directory', t('Publish your default profile in the network directory'), $profile['publish'], '', $yes_no)));
        }
        $suggestme = replace_macros($opt_tpl, array('$field' => array('suggestme', t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', $yes_no)));
        $subdir = strlen($a->get_path()) ? '<br />' . t('or') . ' ' . $a->get_baseurl(true) . '/channel/' . $nickname : '';
        $tpl_addr = get_markup_template("settings_nick_set.tpl");
        $prof_addr = replace_macros($tpl_addr, array('$desc' => t('Your channel address is'), '$nickname' => $nickname, '$subdir' => $subdir, '$basepath' => $a->get_hostname()));
        $stpl = get_markup_template('settings.tpl');
        $acl = new AccessList($channel);
        $perm_defaults = $acl->get();
        require_once 'include/group.php';
        $group_select = mini_group_select(local_channel(), $channel['channel_default_group']);
        require_once 'include/menu.php';
        $m1 = menu_list(local_channel());
        $menu = false;
        if ($m1) {
            $menu = array();
            $current = get_pconfig(local_channel(), 'system', 'channel_menu');
            $menu[] = array('name' => '', 'selected' => !$current ? true : false);
            foreach ($m1 as $m) {
                $menu[] = array('name' => htmlspecialchars($m['menu_name'], ENT_COMPAT, 'UTF-8'), 'selected' => $m['menu_name'] === $current ? ' selected="selected" ' : false);
            }
        }
        $evdays = get_pconfig(local_channel(), 'system', 'evdays');
        if (!$evdays) {
            $evdays = 3;
        }
        $permissions_role = get_pconfig(local_channel(), 'system', 'permissions_role');
        if (!$permissions_role) {
            $permissions_role = 'custom';
        }
        $permissions_set = $permissions_role != 'custom' ? true : false;
        $vnotify = get_pconfig(local_channel(), 'system', 'vnotify');
        $always_show_in_notices = get_pconfig(local_channel(), 'system', 'always_show_in_notices');
        if ($vnotify === false) {
            $vnotify = -1;
        }
        $o .= replace_macros($stpl, array('$ptitle' => t('Channel Settings'), '$submit' => t('Submit'), '$baseurl' => $a->get_baseurl(true), '$uid' => local_channel(), '$form_security_token' => get_form_security_token("settings"), '$nickname_block' => $prof_addr, '$h_basic' => t('Basic Settings'), '$username' => array('username', t('Full Name:'), $username, ''), '$email' => array('email', t('Email Address:'), $email, ''), '$timezone' => array('timezone_select', t('Your Timezone:'), $timezone, '', get_timezones()), '$defloc' => array('defloc', t('Default Post Location:'), $defloc, t('Geographical location to display on your posts')), '$allowloc' => array('allow_location', t('Use Browser Location:'), get_pconfig(local_channel(), 'system', 'use_browser_location') ? 1 : '', '', $yes_no), '$adult' => array('adult', t('Adult Content'), $adult_flag, t('This channel frequently or regularly publishes adult content. (Please tag any adult material and/or nudity with #NSFW)'), $yes_no), '$h_prv' => t('Security and Privacy Settings'), '$permissions_set' => $permissions_set, '$perms_set_msg' => t('Your permissions are already configured. Click to view/adjust'), '$hide_presence' => array('hide_presence', t('Hide my online presence'), $hide_presence, t('Prevents displaying in your profile that you are online'), $yes_no), '$lbl_pmacro' => t('Simple Privacy Settings:'), '$pmacro3' => t('Very Public - <em>extremely permissive (should be used with caution)</em>'), '$pmacro2' => t('Typical - <em>default public, privacy when desired (similar to social network permissions but with improved privacy)</em>'), '$pmacro1' => t('Private - <em>default private, never open or public</em>'), '$pmacro0' => t('Blocked - <em>default blocked to/from everybody</em>'), '$permiss_arr' => $permiss, '$blocktags' => array('blocktags', t('Allow others to tag your posts'), 1 - $blocktags, t('Often used by the community to retro-actively flag inappropriate content'), $yes_no), '$lbl_p2macro' => t('Advanced Privacy Settings'), '$expire' => array('expire', t('Expire other channel content after this many days'), $expire, sprintf(t('0 or blank to use the website limit. The website expires after %d days.'), intval($sys_expire))), '$maxreq' => array('maxreq', t('Maximum Friend Requests/Day:'), intval($channel['channel_max_friend_req']), t('May reduce spam activity')), '$permissions' => t('Default Post Permissions'), '$permdesc' => t("(click to open/close)"), '$aclselect' => populate_acl($perm_defaults, false), '$suggestme' => $suggestme, '$group_select' => $group_select, '$role' => array('permissions_role', t('Channel permissions category:'), $permissions_role, '', get_roles()), '$profile_in_dir' => $profile_in_dir, '$hide_friends' => $hide_friends, '$hide_wall' => $hide_wall, '$unkmail' => $unkmail, '$cntunkmail' => array('cntunkmail', t('Maximum private messages per day from unknown people:'), intval($channel['channel_max_anon_mail']), t("Useful to reduce spamming")), '$h_not' => t('Notification Settings'), '$activity_options' => t('By default post a status message when:'), '$post_newfriend' => array('post_newfriend', t('accepting a friend request'), $post_newfriend, '', $yes_no), '$post_joingroup' => array('post_joingroup', t('joining a forum/community'), $post_joingroup, '', $yes_no), '$post_profilechange' => array('post_profilechange', t('making an <em>interesting</em> profile change'), $post_profilechange, '', $yes_no), '$lbl_not' => t('Send a notification email when:'), '$notify1' => array('notify1', t('You receive a connection request'), $notify & NOTIFY_INTRO, NOTIFY_INTRO, '', $yes_no), '$notify2' => array('notify2', t('Your connections are confirmed'), $notify & NOTIFY_CONFIRM, NOTIFY_CONFIRM, '', $yes_no), '$notify3' => array('notify3', t('Someone writes on your profile wall'), $notify & NOTIFY_WALL, NOTIFY_WALL, '', $yes_no), '$notify4' => array('notify4', t('Someone writes a followup comment'), $notify & NOTIFY_COMMENT, NOTIFY_COMMENT, '', $yes_no), '$notify5' => array('notify5', t('You receive a private message'), $notify & NOTIFY_MAIL, NOTIFY_MAIL, '', $yes_no), '$notify6' => array('notify6', t('You receive a friend suggestion'), $notify & NOTIFY_SUGGEST, NOTIFY_SUGGEST, '', $yes_no), '$notify7' => array('notify7', t('You are tagged in a post'), $notify & NOTIFY_TAGSELF, NOTIFY_TAGSELF, '', $yes_no), '$notify8' => array('notify8', t('You are poked/prodded/etc. in a post'), $notify & NOTIFY_POKE, NOTIFY_POKE, '', $yes_no), '$lbl_vnot' => t('Show visual notifications including:'), '$vnotify1' => array('vnotify1', t('Unseen grid activity'), $vnotify & VNOTIFY_NETWORK, VNOTIFY_NETWORK, '', $yes_no), '$vnotify2' => array('vnotify2', t('Unseen channel activity'), $vnotify & VNOTIFY_CHANNEL, VNOTIFY_CHANNEL, '', $yes_no), '$vnotify3' => array('vnotify3', t('Unseen private messages'), $vnotify & VNOTIFY_MAIL, VNOTIFY_MAIL, t('Recommended'), $yes_no), '$vnotify4' => array('vnotify4', t('Upcoming events'), $vnotify & VNOTIFY_EVENT, VNOTIFY_EVENT, '', $yes_no), '$vnotify5' => array('vnotify5', t('Events today'), $vnotify & VNOTIFY_EVENTTODAY, VNOTIFY_EVENTTODAY, '', $yes_no), '$vnotify6' => array('vnotify6', t('Upcoming birthdays'), $vnotify & VNOTIFY_BIRTHDAY, VNOTIFY_BIRTHDAY, t('Not available in all themes'), $yes_no), '$vnotify7' => array('vnotify7', t('System (personal) notifications'), $vnotify & VNOTIFY_SYSTEM, VNOTIFY_SYSTEM, '', $yes_no), '$vnotify8' => array('vnotify8', t('System info messages'), $vnotify & VNOTIFY_INFO, VNOTIFY_INFO, t('Recommended'), $yes_no), '$vnotify9' => array('vnotify9', t('System critical alerts'), $vnotify & VNOTIFY_ALERT, VNOTIFY_ALERT, t('Recommended'), $yes_no), '$vnotify10' => array('vnotify10', t('New connections'), $vnotify & VNOTIFY_INTRO, VNOTIFY_INTRO, t('Recommended'), $yes_no), '$vnotify11' => array('vnotify11', t('System Registrations'), $vnotify & VNOTIFY_REGISTER, VNOTIFY_REGISTER, '', $yes_no), '$always_show_in_notices' => array('always_show_in_notices', t('Also show new wall posts, private messages and connections under Notices'), $always_show_in_notices, 1, '', $yes_no), '$evdays' => array('evdays', t('Notify me of events this many days in advance'), $evdays, t('Must be greater than 0')), '$h_advn' => t('Advanced Account/Page Type Settings'), '$h_descadvn' => t('Change the behaviour of this account for special situations'), '$pagetype' => $pagetype, '$expert' => feature_enabled(local_channel(), 'expert'), '$hint' => t('Please enable expert mode (in <a href="settings/features">Settings > Additional features</a>) to adjust!'), '$lbl_misc' => t('Miscellaneous Settings'), '$photo_path' => array('photo_path', t('Default photo upload folder'), get_pconfig(local_channel(), 'system', 'photo_path'), t('%Y - current year, %m -  current month')), '$attach_path' => array('attach_path', t('Default file upload folder'), get_pconfig(local_channel(), 'system', 'attach_path'), t('%Y - current year, %m -  current month')), '$menus' => $menu, '$menu_desc' => t('Personal menu to display in your channel pages'), '$removeme' => t('Remove Channel'), '$removechannel' => t('Remove this channel.'), '$firefoxshare' => t('Firefox Share $Projectname provider'), '$cal_first_day' => array('first_day', t('Start calendar week on monday'), get_pconfig(local_channel(), 'system', 'cal_first_day') ? 1 : '', '', $yes_no)));
        call_hooks('settings_form', $o);
        $o .= '</form>' . "\r\n";
        return $o;
    }
}
Example #22
0
function network_content(&$a, $update = 0)
{
    require_once 'include/conversation.php';
    if (!local_user()) {
        $_SESSION['return_url'] = $a->query_string;
        return login(false);
    }
    // TODO:is this really necessary? $a is already available to hooks
    $arr = array('query' => $a->query_string);
    call_hooks('network_content_init', $arr);
    $datequery = $datequery2 = '';
    $group = 0;
    $nouveau = false;
    if ($a->argc > 1) {
        for ($x = 1; $x < $a->argc; $x++) {
            if (is_a_date_arg($a->argv[$x])) {
                if ($datequery) {
                    $datequery2 = escape_tags($a->argv[$x]);
                } else {
                    $datequery = escape_tags($a->argv[$x]);
                    $_GET['order'] = 'post';
                }
            } elseif ($a->argv[$x] === 'new') {
                $nouveau = true;
            } elseif (intval($a->argv[$x])) {
                $group = intval($a->argv[$x]);
                $def_acl = array('allow_gid' => '<' . $group . '>');
            }
        }
    }
    $o = '';
    // item filter tabs
    // TODO: fix this logic, reduce duplication
    //$a->page['content'] .= '<div class="tabs-wrapper">';
    list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
    // if no tabs are selected, defaults to comments
    if ($no_active == 'active') {
        $all_active = 'active';
    }
    $cmd = $datequery ? '' : $a->cmd;
    $len_naked_cmd = strlen(str_replace('/new', '', $cmd));
    // tabs
    $tabs = array(array('label' => t('Commented Order'), 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . (x($_GET, 'cid') ? '&cid=' . $_GET['cid'] : ''), 'sel' => $all_active, 'title' => t('Sort by Comment Date')), array('label' => t('Posted Order'), 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . (x($_GET, 'cid') ? '&cid=' . $_GET['cid'] : ''), 'sel' => $postord_active, 'title' => t('Sort by Post Date')));
    if (feature_enabled(local_user(), 'personal_tab')) {
        $tabs[] = array('label' => t('Personal'), 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . (x($_GET, 'cid') ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1', 'sel' => $conv_active, 'title' => t('Posts that mention or involve you'));
    }
    if (feature_enabled(local_user(), 'new_tab')) {
        $tabs[] = array('label' => t('New'), 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . (x($_GET, 'cid') ? '/?f=&cid=' . $_GET['cid'] : ''), 'sel' => $new_active, 'title' => t('Activity Stream - by date'));
    }
    if (feature_enabled(local_user(), 'link_tab')) {
        $tabs[] = array('label' => t('Shared Links'), 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . (x($_GET, 'cid') ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1', 'sel' => $bookmarked_active, 'title' => t('Interesting Links'));
    }
    if (feature_enabled(local_user(), 'star_posts')) {
        $tabs[] = array('label' => t('Starred'), 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . (x($_GET, 'cid') ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1', 'sel' => $starred_active, 'title' => t('Favourite Posts'));
    }
    // save selected tab, but only if not in search or file mode
    if (!x($_GET, 'search') && !x($_GET, 'file')) {
        set_pconfig(local_user(), 'network.view', 'tab.selected', array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active));
    }
    $arr = array('tabs' => $tabs);
    call_hooks('network_tabs', $arr);
    $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs' => $arr['tabs']));
    // --- end item filter tabs
    $contact_id = $a->cid;
    require_once 'include/acl_selectors.php';
    $cid = x($_GET, 'cid') ? intval($_GET['cid']) : 0;
    $star = x($_GET, 'star') ? intval($_GET['star']) : 0;
    $bmark = x($_GET, 'bmark') ? intval($_GET['bmark']) : 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;
    $nets = x($_GET, 'nets') ? $_GET['nets'] : '';
    $cmin = x($_GET, 'cmin') ? intval($_GET['cmin']) : 0;
    $cmax = x($_GET, 'cmax') ? intval($_GET['cmax']) : 99;
    $file = x($_GET, 'file') ? $_GET['file'] : '';
    if (x($_GET, 'search') || x($_GET, 'file')) {
        $nouveau = true;
    }
    if ($cid) {
        $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
    }
    if ($nets) {
        $r = q("select id from contact where uid = %d and network = '%s' and self = 0", intval(local_user()), dbesc($nets));
        $str = '';
        if (count($r)) {
            foreach ($r as $rr) {
                $str .= '<' . $rr['id'] . '>';
            }
        }
        if (strlen($str)) {
            $def_acl = array('allow_cid' => $str);
        }
    }
    set_pconfig(local_user(), 'network.view', 'net.selected', $nets ? $nets : 'all');
    if (!$update) {
        if ($group) {
            if (($t = group_public_members($group)) && !get_pconfig(local_user(), 'system', 'nowarn_insecure')) {
                notice(sprintf(tt('Warning: This group contains %s member from an insecure network.', 'Warning: This group contains %s members from an insecure network.', $t), $t) . EOL);
                notice(t('Private messages to this group are at risk of public disclosure.') . EOL);
            }
        }
        nav_set_selected('network');
        $content = "";
        if ($cid) {
            $contact = q("SELECT `nick` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `forum`", intval($cid), intval(local_user()));
            if ($contact) {
                $content = "@" . $contact[0]["nick"] . "+" . $cid;
            }
        }
        $x = array('is_owner' => true, 'allow_location' => $a->user['allow_location'], 'default_location' => $a->user['default-location'], 'nickname' => $a->user['nickname'], 'lockstate' => $group || $cid || $nets || is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock', 'default_perms' => get_acl_permissions($a->user), 'acl' => populate_acl($group || $cid || $nets ? $def_acl : $a->user, true), 'bang' => $group || $cid || $nets ? '!' : '', 'visitor' => 'block', 'profile_uid' => local_user(), 'acl_data' => construct_acl_data($a, $a->user), 'content' => $content);
        $o .= status_editor($a, $x);
    }
    // We don't have to deal with ACLs 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_post_table = "";
    $sql_options = $star ? " and starred = 1 " : '';
    $sql_options .= $bmark ? " and bookmark = 1 " : '';
    $sql_extra = $sql_options;
    $sql_extra2 = "";
    $sql_extra3 = "";
    $sql_table = "`thread`";
    $sql_parent = "`iid`";
    if ($nouveau or strlen($file) or $update) {
        $sql_table = "`item`";
        $sql_parent = "`parent`";
    }
    $sql_nets = $nets ? sprintf(" and {$sql_table}.`network` = '%s' ", dbesc($nets)) : '';
    if ($group) {
        $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($group), intval($_SESSION['uid']));
        if (!count($r)) {
            if ($update) {
                killme();
            }
            notice(t('No such group') . EOL);
            goaway($a->get_baseurl(true) . '/network/0');
            // NOTREACHED
        }
        $contacts = expand_groups(array($group));
        $contact_str_self = "";
        if (is_array($contacts) && count($contacts)) {
            $contact_str = implode(',', $contacts);
            $self = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($_SESSION['uid']));
            if (count($self)) {
                $contact_str_self = "," . $self[0]["id"];
            }
        } else {
            $contact_str = ' 0 ';
            info(t('Group is empty'));
        }
        //$sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` WHERE (`contact-id` IN ($contact_str) OR `allow_gid` like '".protect_sprintf('%<'.intval($group).'>%')."') and deleted = 0 ORDER BY `created` DESC) AS `temp1` ON $sql_table.$sql_parent = `temp1`.`parent` ";
        $sql_extra3 .= " AND `contact-id` IN ({$contact_str}{$contact_str_self}) ";
        $sql_extra3 .= " AND EXISTS (SELECT id FROM `item` WHERE (`contact-id` IN ({$contact_str}) \n\t\t\t\tOR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "') and deleted = 0 \n\t\t\t\tAND parent = {$sql_table}.{$sql_parent}) ";
        $o = replace_macros(get_markup_template("section_title.tpl"), array('$title' => sprintf(t('Group: %s'), $r[0]['name']))) . $o;
    } elseif ($cid) {
        $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d\n\t\t\t\tAND `blocked` = 0 AND `pending` = 0 LIMIT 1", intval($cid));
        if (count($r)) {
            $sql_post_table = " INNER JOIN (SELECT DISTINCT(`parent`) FROM `item` \n\t\t\t\t\t    WHERE 1 {$sql_options} AND `contact-id` = " . intval($cid) . " and deleted = 0 \n\t\t\t\t\t    ORDER BY `item`.`received` DESC) AS `temp1` \n\t\t\t\t\t    ON {$sql_table}.{$sql_parent} = `temp1`.`parent` ";
            $sql_extra = "";
            $o = replace_macros(get_markup_template("section_title.tpl"), array('$title' => sprintf(t('Contact: %s'), $r[0]['name']))) . $o;
            if ($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && !get_pconfig(local_user(), 'system', 'nowarn_insecure')) {
                notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
            }
        } else {
            notice(t('Invalid contact.') . EOL);
            goaway($a->get_baseurl(true) . '/network');
            // NOTREACHED
        }
    }
    if (!$group && !$cid && !$update && !get_config('theme', 'hide_eventlist')) {
        $o .= get_birthdays();
        $o .= get_events();
    }
    if ($datequery) {
        $sql_extra3 .= protect_sprintf(sprintf(" AND {$sql_table}.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
    }
    if ($datequery2) {
        $sql_extra3 .= protect_sprintf(sprintf(" AND {$sql_table}.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
    }
    //$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
    $sql_extra2 = $nouveau ? '' : $sql_extra2;
    $sql_extra3 = $nouveau ? '' : $sql_extra3;
    $sql_order = "";
    $order_mode = "received";
    $tag = false;
    if (x($_GET, 'search')) {
        $search = escape_tags($_GET['search']);
        if (strpos($search, '#') === 0) {
            $tag = true;
            $search = substr($search, 1);
        }
        if (get_config('system', 'only_tag_search')) {
            $tag = true;
        }
        if ($tag) {
            $sql_extra = "";
            $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user()));
            $sql_order = "`item`.`id`";
            $order_mode = "id";
        } else {
            if (get_config('system', 'use_fulltext_engine')) {
                $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
            } else {
                $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
            }
            $sql_order = "`item`.`received`";
            $order_mode = "received";
        }
    }
    if (strlen($file)) {
        $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
        $sql_order = "`item`.`id`";
        $order_mode = "id";
    }
    if ($conv) {
        $sql_extra3 .= " AND `mention`";
    }
    if ($update) {
        // only setup pagination on initial page view
        $pager_sql = '';
    } else {
        if (get_config('system', 'old_pager')) {
            $r = q("SELECT COUNT(*) AS `total`\n\t\t\t        FROM {$sql_table} {$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = {$sql_table}.`contact-id`\n\t\t\t        AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t        WHERE {$sql_table}.`uid` = %d AND {$sql_table}.`visible` = 1 AND {$sql_table}.`deleted` = 0\n\t\t\t        {$sql_extra2} {$sql_extra3}\n\t\t\t        {$sql_extra} {$sql_nets} ", intval($_SESSION['uid']));
            if (count($r)) {
                $a->set_pager_total($r[0]['total']);
            }
        }
        //  check if we serve a mobile device and get the user settings
        //  accordingly
        if ($a->is_mobile) {
            $itemspage_network = get_pconfig(local_user(), 'system', 'itemspage_mobile_network');
            $itemspage_network = intval($itemspage_network) ? $itemspage_network : 20;
        } else {
            $itemspage_network = get_pconfig(local_user(), 'system', 'itemspage_network');
            $itemspage_network = intval($itemspage_network) ? $itemspage_network : 40;
        }
        //  now that we have the user settings, see if the theme forces
        //  a maximum item number which is lower then the user choice
        if ($a->force_max_items > 0 && $a->force_max_items < $itemspage_network) {
            $itemspage_network = $a->force_max_items;
        }
        $a->set_pager_itemspage($itemspage_network);
        $pager_sql = sprintf(" LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']));
    }
    if ($nouveau) {
        $simple_update = $update ? " and `item`.`unseen` = 1 " : '';
        if ($sql_order == "") {
            $sql_order = "`item`.`received`";
        }
        // "New Item View" - show all items unthreaded in reverse created date order
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,\n\t\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,\n\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM {$sql_table} {$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1\n\t\t\tAND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\t{$simple_update}\n\t\t\t{$sql_extra} {$sql_nets}\n\t\t\tORDER BY {$sql_order} DESC {$pager_sql} ", intval($_SESSION['uid']));
        $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 {$sql_extra} {$sql_nets}";
    } else {
        // Normal conversation view
        if ($order === 'post') {
            $ordering = "`created`";
            if ($sql_order == "") {
                $order_mode = "created";
            }
        } else {
            $ordering = "`commented`";
            if ($sql_order == "") {
                $order_mode = "commented";
            }
        }
        if ($sql_order == "") {
            $sql_order = "{$sql_table}.{$ordering}";
        }
        if ($_GET["offset"] != "") {
            $sql_extra3 .= sprintf(" AND {$sql_order} <= '%s'", dbesc($_GET["offset"]));
        }
        // Fetch a page full of parent items for this page
        if ($update) {
            if (!get_config("system", "like_no_comment")) {
                $sql_extra4 = "(`item`.`deleted` = 0 OR `item`.`verb` = '" . ACTIVITY_LIKE . "' OR `item`.`verb` = '" . ACTIVITY_DISLIKE . "')";
            } else {
                $sql_extra4 = "`item`.`deleted` = 0 AND `item`.`verb` = '" . ACTIVITY_POST . "'";
            }
            $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`\n\t\t\t\tFROM {$sql_table} {$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND {$sql_extra4}\n\t\t\t\tAND `item`.`moderated` = 0 AND `item`.`unseen` = 1\n\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets} ORDER BY `item_id` DESC LIMIT 100", intval(local_user()));
        } else {
            $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`\n\t\t\t\tFROM {$sql_table} {$sql_post_table} STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`\n\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\tWHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0\n\t\t\t\tAND `thread`.`moderated` = 0\n\t\t\t\t{$sql_extra2} {$sql_extra3} {$sql_extra} {$sql_nets}\n\t\t\t\tORDER BY {$sql_order} DESC {$pager_sql} ", intval(local_user()));
        }
        // Then fetch all the children of the parents that are on this page
        $parents_arr = array();
        $parents_str = '';
        $date_offset = "";
        if (count($r)) {
            foreach ($r as $rr) {
                if (!in_array($rr['item_id'], $parents_arr)) {
                    $parents_arr[] = $rr['item_id'];
                }
            }
            $parents_str = implode(", ", $parents_arr);
            // splitted into separate queries to avoid the problem with very long threads
            // so always the last X comments are loaded
            // This problem can occur expecially with imported facebook posts
            $max_comments = get_config("system", "max_comments");
            if ($max_comments == 0) {
                $max_comments = 100;
            }
            $items = array();
            foreach ($parents_arr as $parents) {
                //					$sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
                $thread_items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,\n\t\t\t\t\t`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,\n\t\t\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\t\t\tFROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\t\t\t\tAND `item`.`moderated` = 0\n\t\t\t\t\tAND `item`.`parent` = %d\n\t\t\t\t\tORDER BY `item`.`commented` DESC LIMIT %d", intval(local_user()), intval($parents), intval($max_comments + 1));
                $items = array_merge($items, $thread_items);
            }
            $items = conv_sort($items, $ordering);
        } else {
            $items = array();
        }
        if ($_GET["offset"] == "") {
            $date_offset = $items[0][$order_mode];
        } else {
            $date_offset = $_GET["offset"];
        }
        $a->page_offset = $date_offset;
        if ($parents_str) {
            $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
        }
    }
    // We aren't going to try and figure out at the item, group, and page
    // level which items you've seen and which you haven't. If you're looking
    // at the top level network page just mark everything seen.
    // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact -
    // and other feeds that bring in stuff from the past. One can't find it all.
    // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure.
    // The correct solution is to implement a network notifications box just like the system notifications popup
    // with the ability in the popup to "mark all seen".
    // Several people are complaining because there are unseen messages they can't find and as time goes
    // on they just get buried deeper. It has happened to me a couple of times also.
    if (!$group && !$cid && !$star) {
        $r = q("UPDATE `item` SET `unseen` = 0\n\t\t\tWHERE `unseen` = 1 AND `uid` = %d", intval(local_user()));
    } else {
        if ($update_unseen) {
            $r = q("UPDATE `item` SET `unseen` = 0 {$update_unseen}");
        }
    }
    // Set this so that the conversation function can find out contact info for our wall-wall items
    $a->page_contact = $a->contact;
    $mode = $nouveau ? 'network-new' : 'network';
    $o .= conversation($a, $items, $mode, $update);
    if (!$update) {
        if (get_pconfig(local_user(), 'system', 'infinite_scroll')) {
            $o .= scroll_loader();
        } elseif (!get_config('system', 'old_pager')) {
            $o .= alt_pager($a, count($items));
        } else {
            $o .= paginate($a);
        }
    }
    return $o;
}
Example #23
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;
 }
Example #24
0
 function settings_content(&$a)
 {
     $o = '';
     nav_set_selected('settings');
     if (!local_user()) {
         #notice( t('Permission denied.') . EOL );
         return;
     }
     if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if ($a->argc > 1 && $a->argv[1] === 'oauth') {
         if ($a->argc > 2 && $a->argv[2] === 'add') {
             $tpl = get_markup_template("settings_oauth_edit.tpl");
             $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$title' => t('Add application'), '$submit' => t('Save Settings'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), '', ''), '$key' => array('key', t('Consumer Key'), '', ''), '$secret' => array('secret', t('Consumer Secret'), '', ''), '$redirect' => array('redirect', t('Redirect'), '', ''), '$icon' => array('icon', t('Icon url'), '', '')));
             return $o;
         }
         if ($a->argc > 3 && $a->argv[2] === 'edit') {
             $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user());
             if (!count($r)) {
                 notice(t("You can't edit this application."));
                 return;
             }
             $app = $r[0];
             $tpl = get_markup_template("settings_oauth_edit.tpl");
             $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$title' => t('Add application'), '$submit' => t('Update'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), $app['name'], ''), '$key' => array('key', t('Consumer Key'), $app['client_id'], ''), '$secret' => array('secret', t('Consumer Secret'), $app['pw'], ''), '$redirect' => array('redirect', t('Redirect'), $app['redirect_uri'], ''), '$icon' => array('icon', t('Icon url'), $app['icon'], '')));
             return $o;
         }
         if ($a->argc > 3 && $a->argv[2] === 'delete') {
             check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
             $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user());
             goaway($a->get_baseurl(true) . "/settings/oauth/");
             return;
         }
         $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my\n\t\t\t\tFROM clients\n\t\t\t\tLEFT JOIN tokens ON clients.client_id=tokens.client_id\n\t\t\t\tWHERE clients.uid IN (%d,0)", local_user(), local_user());
         $tpl = get_markup_template("settings_oauth.tpl");
         $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$baseurl' => $a->get_baseurl(true), '$title' => t('Connected Apps'), '$add' => t('Add application'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$consumerkey' => t('Client key starts with'), '$noname' => t('No name'), '$remove' => t('Remove authorization'), '$apps' => $r));
         return $o;
     }
     if ($a->argc > 1 && $a->argv[1] === 'addon') {
         $settings_addons = "";
         $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
         if (!count($r)) {
             $settings_addons = t('No Plugin settings configured');
         }
         call_hooks('plugin_settings', $settings_addons);
         $tpl = get_markup_template("settings_addons.tpl");
         $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_addon"), '$title' => t('Plugin Settings'), '$settings_addons' => $settings_addons));
         return $o;
     }
     if ($a->argc > 1 && $a->argv[1] === 'features') {
         $arr = array();
         $features = get_features();
         foreach ($features as $fname => $fdata) {
             $arr[$fname] = array();
             $arr[$fname][0] = $fdata[0];
             foreach (array_slice($fdata, 1) as $f) {
                 $arr[$fname][1][] = array('feature_' . $f[0], $f[1], intval(get_pconfig(local_user(), 'feature', $f[0])) ? "1" : '', $f[2], array(t('Off'), t('On')));
             }
         }
         $tpl = get_markup_template("settings_features.tpl");
         $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_features"), '$title' => t('Additional Features'), '$features' => $arr, '$submit' => t('Save Settings')));
         return $o;
     }
     if ($a->argc > 1 && $a->argv[1] === 'connectors') {
         $settings_connectors = "";
         call_hooks('connector_settings', $settings_connectors);
         if (is_site_admin()) {
             $diasp_enabled = sprintf(t('Built-in support for %s connectivity is %s'), t('Diaspora'), get_config('system', 'diaspora_enabled') ? t('enabled') : t('disabled'));
             $ostat_enabled = sprintf(t('Built-in support for %s connectivity is %s'), t('StatusNet'), get_config('system', 'ostatus_disabled') ? t('disabled') : t('enabled'));
         } else {
             $diasp_enabled = "";
             $ostat_enabled = "";
         }
         $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1;
         if (get_config('system', 'dfrn_only')) {
             $mail_disabled = 1;
         }
         if (!$mail_disabled) {
             $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", local_user());
         } else {
             $r = null;
         }
         $mail_server = count($r) ? $r[0]['server'] : '';
         $mail_port = count($r) && intval($r[0]['port']) ? intval($r[0]['port']) : '';
         $mail_ssl = count($r) ? $r[0]['ssltype'] : '';
         $mail_user = count($r) ? $r[0]['user'] : '';
         $mail_replyto = count($r) ? $r[0]['reply_to'] : '';
         $mail_pubmail = count($r) ? $r[0]['pubmail'] : 0;
         $mail_action = count($r) ? $r[0]['action'] : 0;
         $mail_movetofolder = count($r) ? $r[0]['movetofolder'] : '';
         $mail_chk = count($r) ? $r[0]['last_check'] : '0000-00-00 00:00:00';
         $tpl = get_markup_template("settings_connectors.tpl");
         if (!service_class_allows(local_user(), 'email_connect')) {
             $mail_disabled_message = upgrade_bool_message();
         } else {
             $mail_disabled_message = $mail_disabled ? t('Email access is disabled on this site.') : '';
         }
         $o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_connectors"), '$title' => t('Social Networks'), '$diasp_enabled' => $diasp_enabled, '$ostat_enabled' => $ostat_enabled, '$h_imap' => t('Email/Mailbox Setup'), '$imap_desc' => t("If you wish to communicate with email contacts using this service (optional), please specify how to connect to your mailbox."), '$imap_lastcheck' => array('imap_lastcheck', t('Last successful email check:'), $mail_chk, ''), '$mail_disabled' => $mail_disabled_message, '$mail_server' => array('mail_server', t('IMAP server name:'), $mail_server, ''), '$mail_port' => array('mail_port', t('IMAP port:'), $mail_port, ''), '$mail_ssl' => array('mail_ssl', t('Security:'), strtoupper($mail_ssl), '', array('notls' => t('None'), 'TLS' => 'TLS', 'SSL' => 'SSL')), '$mail_user' => array('mail_user', t('Email login name:'), $mail_user, ''), '$mail_pass' => array('mail_pass', t('Email password:'******'', ''), '$mail_replyto' => array('mail_replyto', t('Reply-to address:'), $mail_replyto, 'Optional'), '$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''), '$mail_action' => array('mail_action', t('Action after import:'), $mail_action, '', array(0 => t('None'), 2 => t('Mark as seen'), 3 => t('Move to folder'))), '$mail_movetofolder' => array('mail_movetofolder', t('Move to folder:'), $mail_movetofolder, ''), '$submit' => t('Save Settings'), '$settings_connectors' => $settings_connectors));
         call_hooks('display_settings', $o);
         return $o;
     }
     /*
      * DISPLAY SETTINGS
      */
     if ($a->argc > 1 && $a->argv[1] === 'display') {
         $default_theme = get_config('system', 'theme');
         if (!$default_theme) {
             $default_theme = 'default';
         }
         $default_mobile_theme = get_config('system', 'mobile-theme');
         if (!$mobile_default_theme) {
             $mobile_default_theme = 'none';
         }
         $allowed_themes_str = get_config('system', 'allowed_themes');
         $allowed_themes_raw = explode(',', $allowed_themes_str);
         $allowed_themes = array();
         if (count($allowed_themes_raw)) {
             foreach ($allowed_themes_raw as $x) {
                 if (strlen(trim($x)) && is_dir("view/theme/{$x}")) {
                     $allowed_themes[] = trim($x);
                 }
             }
         }
         $themes = array();
         $mobile_themes = array("---" => t('No special theme for mobile devices'));
         $files = glob('view/theme/*');
         /* */
         if ($allowed_themes) {
             foreach ($allowed_themes as $th) {
                 $f = $th;
                 $is_experimental = file_exists('view/theme/' . $th . '/experimental');
                 $unsupported = file_exists('view/theme/' . $th . '/unsupported');
                 $is_mobile = file_exists('view/theme/' . $th . '/mobile');
                 if (!$is_experimental or $is_experimental && (get_config('experimentals', 'exp_themes') == 1 or get_config('experimentals', 'exp_themes') === false)) {
                     $theme_name = $is_experimental ? sprintf("%s - (Experimental)", $f) : $f;
                     if ($is_mobile) {
                         $mobile_themes[$f] = $theme_name;
                     } else {
                         $themes[$f] = $theme_name;
                     }
                 }
             }
         }
         $theme_selected = !x($_SESSION, 'theme') ? $default_theme : $_SESSION['theme'];
         $mobile_theme_selected = !x($_SESSION, 'mobile-theme') ? $default_mobile_theme : $_SESSION['mobile-theme'];
         $browser_update = intval(get_pconfig(local_user(), 'system', 'update_interval'));
         $browser_update = $browser_update == 0 ? 40 : $browser_update / 1000;
         // default if not set: 40 seconds
         $itemspage_network = intval(get_pconfig(local_user(), 'system', 'itemspage_network'));
         $itemspage_network = $itemspage_network > 0 && $itemspage_network < 101 ? $itemspage_network : 40;
         // default if not set: 40 items
         $itemspage_mobile_network = intval(get_pconfig(local_user(), 'system', 'itemspage_mobile_network'));
         $itemspage_mobile_network = $itemspage_mobile_network > 0 && $itemspage_mobile_network < 101 ? $itemspage_mobile_network : 20;
         // default if not set: 20 items
         $nosmile = get_pconfig(local_user(), 'system', 'no_smilies');
         $nosmile = $nosmile === false ? '0' : $nosmile;
         // default if not set: 0
         $noinfo = get_pconfig(local_user(), 'system', 'ignore_info');
         $noinfo = $noinfo === false ? '0' : $noinfo;
         // default if not set: 0
         $infinite_scroll = get_pconfig(local_user(), 'system', 'infinite_scroll');
         $infinite_scroll = $infinite_scroll === false ? '0' : $infinite_scroll;
         // default if not set: 0
         $no_auto_update = get_pconfig(local_user(), 'system', 'no_auto_update');
         $no_auto_update = $no_auto_update === false ? '0' : $no_auto_update;
         // default if not set: 0
         $theme_config = "";
         if (($themeconfigfile = get_theme_config_file($theme_selected)) != null) {
             require_once $themeconfigfile;
             $theme_config = theme_content($a);
         }
         $tpl = get_markup_template("settings_display.tpl");
         $o = replace_macros($tpl, array('$ptitle' => t('Display Settings'), '$form_security_token' => get_form_security_token("settings_display"), '$submit' => t('Save Settings'), '$baseurl' => $a->get_baseurl(true), '$uid' => local_user(), '$theme' => array('theme', t('Display Theme:'), $theme_selected, '', $themes, true), '$mobile_theme' => array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, false), '$ajaxint' => array('browser_update', t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds, no maximum')), '$itemspage_network' => array('itemspage_network', t("Number of items to display per page:"), $itemspage_network, t('Maximum of 100 items')), '$itemspage_mobile_network' => array('itemspage_mobile_network', t("Number of items to display per page when viewed from mobile device:"), $itemspage_mobile_network, t('Maximum of 100 items')), '$nosmile' => array('nosmile', t("Don't show emoticons"), $nosmile, ''), '$noinfo' => array('noinfo', t("Don't show notices"), $noinfo, ''), '$infinite_scroll' => array('infinite_scroll', t("Infinite scroll"), $infinite_scroll, ''), '$no_auto_update' => array('no_auto_update', t("Automatic updates only at the top of the network page"), $no_auto_update, 'When disabled, the network page is updated all the time, which could be confusing while reading.'), '$theme_config' => $theme_config));
         $tpl = get_markup_template("settings_display_end.tpl");
         $a->page['end'] .= replace_macros($tpl, array('$theme' => array('theme', t('Display Theme:'), $theme_selected, '', $themes)));
         return $o;
     }
     /*
      * ACCOUNT SETTINGS
      */
     require_once 'include/acl_selectors.php';
     $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval(local_user()));
     if (count($p)) {
         $profile = $p[0];
     }
     $username = $a->user['username'];
     $email = $a->user['email'];
     $nickname = $a->user['nickname'];
     $timezone = $a->user['timezone'];
     $notify = $a->user['notify-flags'];
     $defloc = $a->user['default-location'];
     $openid = $a->user['openid'];
     $maxreq = $a->user['maxreq'];
     $expire = intval($a->user['expire']) ? $a->user['expire'] : '';
     $blockwall = $a->user['blockwall'];
     $blocktags = $a->user['blocktags'];
     $unkmail = $a->user['unkmail'];
     $cntunkmail = $a->user['cntunkmail'];
     $expire_items = get_pconfig(local_user(), 'expire', 'items');
     $expire_items = $expire_items === false ? '1' : $expire_items;
     // default if not set: 1
     $expire_notes = get_pconfig(local_user(), 'expire', 'notes');
     $expire_notes = $expire_notes === false ? '1' : $expire_notes;
     // default if not set: 1
     $expire_starred = get_pconfig(local_user(), 'expire', 'starred');
     $expire_starred = $expire_starred === false ? '1' : $expire_starred;
     // default if not set: 1
     $expire_photos = get_pconfig(local_user(), 'expire', 'photos');
     $expire_photos = $expire_photos === false ? '0' : $expire_photos;
     // default if not set: 0
     $expire_network_only = get_pconfig(local_user(), 'expire', 'network_only');
     $expire_network_only = $expire_network_only === false ? '0' : $expire_network_only;
     // default if not set: 0
     $suggestme = get_pconfig(local_user(), 'system', 'suggestme');
     $suggestme = $suggestme === false ? '0' : $suggestme;
     // default if not set: 0
     $post_newfriend = get_pconfig(local_user(), 'system', 'post_newfriend');
     $post_newfriend = $post_newfriend === false ? '0' : $post_newfriend;
     // default if not set: 0
     $post_joingroup = get_pconfig(local_user(), 'system', 'post_joingroup');
     $post_joingroup = $post_joingroup === false ? '0' : $post_joingroup;
     // default if not set: 0
     $post_profilechange = get_pconfig(local_user(), 'system', 'post_profilechange');
     $post_profilechange = $post_profilechange === false ? '0' : $post_profilechange;
     // default if not set: 0
     // nowarn_insecure
     if (!strlen($a->user['timezone'])) {
         $timezone = date_default_timezone_get();
     }
     $pageset_tpl = get_markup_template('pagetypes.tpl');
     $pagetype = replace_macros($pageset_tpl, array('$user' => t("User Types"), '$community' => t("Community Types"), '$page_normal' => array('page-flags', t('Normal Account Page'), PAGE_NORMAL, t('This account is a normal personal profile'), $a->user['page-flags'] == PAGE_NORMAL), '$page_soapbox' => array('page-flags', t('Soapbox Page'), PAGE_SOAPBOX, t('Automatically approve all connection/friend requests as read-only fans'), $a->user['page-flags'] == PAGE_SOAPBOX), '$page_community' => array('page-flags', t('Community Forum/Celebrity Account'), PAGE_COMMUNITY, t('Automatically approve all connection/friend requests as read-write fans'), $a->user['page-flags'] == PAGE_COMMUNITY), '$page_freelove' => array('page-flags', t('Automatic Friend Page'), PAGE_FREELOVE, t('Automatically approve all connection/friend requests as friends'), $a->user['page-flags'] == PAGE_FREELOVE), '$page_prvgroup' => array('page-flags', t('Private Forum [Experimental]'), PAGE_PRVGROUP, t('Private forum - approved members only'), $a->user['page-flags'] == PAGE_PRVGROUP)));
     $noid = get_config('system', 'no_openid');
     if ($noid) {
         $openid_field = false;
     } else {
         $openid_field = array('openid_url', t('OpenID:'), $openid, t("(Optional) Allow this OpenID to login to this account."));
     }
     $opt_tpl = get_markup_template("field_yesno.tpl");
     if (get_config('system', 'publish_all')) {
         $profile_in_dir = '<input type="hidden" name="profile_in_directory" value="1" />';
     } else {
         $profile_in_dir = replace_macros($opt_tpl, array('$field' => array('profile_in_directory', t('Publish your default profile in your local site directory?'), $profile['publish'], '', array(t('No'), t('Yes')))));
     }
     if (strlen(get_config('system', 'directory_submit_url'))) {
         $profile_in_net_dir = replace_macros($opt_tpl, array('$field' => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'), t('Yes')))));
     } else {
         $profile_in_net_dir = '';
     }
     $hide_friends = replace_macros($opt_tpl, array('$field' => array('hide-friends', t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], '', array(t('No'), t('Yes')))));
     $hide_wall = replace_macros($opt_tpl, array('$field' => array('hidewall', t('Hide your profile details from unknown viewers?'), $a->user['hidewall'], t("If enabled, posting public messages to Diaspora and other networks isn't possible."), array(t('No'), t('Yes')))));
     $blockwall = replace_macros($opt_tpl, array('$field' => array('blockwall', t('Allow friends to post to your profile page?'), intval($a->user['blockwall']) ? '0' : '1', '', array(t('No'), t('Yes')))));
     $blocktags = replace_macros($opt_tpl, array('$field' => array('blocktags', t('Allow friends to tag your posts?'), intval($a->user['blocktags']) ? '0' : '1', '', array(t('No'), t('Yes')))));
     $suggestme = replace_macros($opt_tpl, array('$field' => array('suggestme', t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', array(t('No'), t('Yes')))));
     $unkmail = replace_macros($opt_tpl, array('$field' => array('unkmail', t('Permit unknown people to send you private mail?'), $unkmail, '', array(t('No'), t('Yes')))));
     $invisible = !$profile['publish'] && !$profile['net-publish'] ? true : false;
     if ($invisible) {
         info(t('Profile is <strong>not published</strong>.') . EOL);
     }
     $subdir = strlen($a->get_path()) ? '<br />' . t('or') . ' ' . $a->get_baseurl(true) . '/profile/' . $nickname : '';
     $tpl_addr = get_markup_template("settings_nick_set.tpl");
     $prof_addr = replace_macros($tpl_addr, array('$desc' => t('Your Identity Address is'), '$nickname' => $nickname, '$subdir' => $subdir, '$basepath' => $a->get_hostname()));
     $stpl = get_markup_template('settings.tpl');
     $celeb = $a->user['page-flags'] == PAGE_SOAPBOX || $a->user['page-flags'] == PAGE_COMMUNITY ? true : false;
     $expire_arr = array('days' => array('expire', t("Automatically expire posts after this many days:"), $expire, t('If empty, posts will not expire. Expired posts will be deleted')), 'advanced' => t('Advanced expiration settings'), 'label' => t('Advanced Expiration'), 'items' => array('expire_items', t("Expire posts:"), $expire_items, '', array(t('No'), t('Yes'))), 'notes' => array('expire_notes', t("Expire personal notes:"), $expire_notes, '', array(t('No'), t('Yes'))), 'starred' => array('expire_starred', t("Expire starred posts:"), $expire_starred, '', array(t('No'), t('Yes'))), 'photos' => array('expire_photos', t("Expire photos:"), $expire_photos, '', array(t('No'), t('Yes'))), 'network_only' => array('expire_network_only', t("Only expire posts by others:"), $expire_network_only, '', array(t('No'), t('Yes'))));
     require_once 'include/group.php';
     $group_select = mini_group_select(local_user(), $a->user['def_gid']);
     // Private/public post links for the non-JS ACL form
     $private_post = 1;
     if ($_REQUEST['public']) {
         $private_post = 0;
     }
     $query_str = $a->query_string;
     if (strpos($query_str, 'public=1') !== false) {
         $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
     }
     // I think $a->query_string may never have ? in it, but I could be wrong
     // It looks like it's from the index.php?q=[etc] rewrite that the web
     // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
     if (strpos($query_str, '?') === false) {
         $public_post_link = '?public=1';
     } else {
         $public_post_link = '&public=1';
     }
     $o .= replace_macros($stpl, array('$ptitle' => t('Account Settings'), '$submit' => t('Save Settings'), '$baseurl' => $a->get_baseurl(true), '$uid' => local_user(), '$form_security_token' => get_form_security_token("settings"), '$nickname_block' => $prof_addr, '$h_pass' => t('Password Settings'), '$password1' => array('password', t('New Password:'******'', ''), '$password2' => array('confirm', t('Confirm:'), '', t('Leave password fields blank unless changing')), '$password3' => array('opassword', t('Current Password:'******'', t('Your current password to confirm the changes')), '$password4' => array('mpassword', t('Password:'******'', t('Your current password to confirm the changes')), '$oid_enable' => !get_config('system', 'no_openid'), '$openid' => $openid_field, '$h_basic' => t('Basic Settings'), '$username' => array('username', t('Full Name:'), $username, ''), '$email' => array('email', t('Email Address:'), $email, '', '', '', 'email'), '$timezone' => array('timezone_select', t('Your Timezone:'), select_timezone($timezone), ''), '$defloc' => array('defloc', t('Default Post Location:'), $defloc, ''), '$allowloc' => array('allow_location', t('Use Browser Location:'), $a->user['allow_location'] == 1, ''), '$h_prv' => t('Security and Privacy Settings'), '$maxreq' => array('maxreq', t('Maximum Friend Requests/Day:'), $maxreq, t("(to prevent spam abuse)")), '$permissions' => t('Default Post Permissions'), '$permdesc' => t("(click to open/close)"), '$visibility' => $profile['net-publish'], '$aclselect' => populate_acl($a->user, $celeb), '$suggestme' => $suggestme, '$blockwall' => $blockwall, '$blocktags' => $blocktags, '$acl_data' => construct_acl_data($a, $a->user), '$group_perms' => t('Show to Groups'), '$contact_perms' => t('Show to Contacts'), '$private' => t('Default Private Post'), '$public' => t('Default Public Post'), '$is_private' => $private_post, '$return_path' => $query_str, '$public_link' => $public_post_link, '$settings_perms' => t('Default Permissions for New Posts'), '$group_select' => $group_select, '$expire' => $expire_arr, '$profile_in_dir' => $profile_in_dir, '$profile_in_net_dir' => $profile_in_net_dir, '$hide_friends' => $hide_friends, '$hide_wall' => $hide_wall, '$unkmail' => $unkmail, '$cntunkmail' => array('cntunkmail', t('Maximum private messages per day from unknown people:'), $cntunkmail, t("(to prevent spam abuse)")), '$h_not' => t('Notification Settings'), '$activity_options' => t('By default post a status message when:'), '$post_newfriend' => array('post_newfriend', t('accepting a friend request'), $post_newfriend, ''), '$post_joingroup' => array('post_joingroup', t('joining a forum/community'), $post_joingroup, ''), '$post_profilechange' => array('post_profilechange', t('making an <em>interesting</em> profile change'), $post_profilechange, ''), '$lbl_not' => t('Send a notification email when:'), '$notify1' => array('notify1', t('You receive an introduction'), $notify & NOTIFY_INTRO, NOTIFY_INTRO, ''), '$notify2' => array('notify2', t('Your introductions are confirmed'), $notify & NOTIFY_CONFIRM, NOTIFY_CONFIRM, ''), '$notify3' => array('notify3', t('Someone writes on your profile wall'), $notify & NOTIFY_WALL, NOTIFY_WALL, ''), '$notify4' => array('notify4', t('Someone writes a followup comment'), $notify & NOTIFY_COMMENT, NOTIFY_COMMENT, ''), '$notify5' => array('notify5', t('You receive a private message'), $notify & NOTIFY_MAIL, NOTIFY_MAIL, ''), '$notify6' => array('notify6', t('You receive a friend suggestion'), $notify & NOTIFY_SUGGEST, NOTIFY_SUGGEST, ''), '$notify7' => array('notify7', t('You are tagged in a post'), $notify & NOTIFY_TAGSELF, NOTIFY_TAGSELF, ''), '$notify8' => array('notify8', t('You are poked/prodded/etc. in a post'), $notify & NOTIFY_POKE, NOTIFY_POKE, ''), '$email_textonly' => array('email_textonly', t('Text-only notification emails'), get_pconfig(local_user(), 'system', 'email_textonly'), t('Send text only notification emails, without the html part')), '$h_advn' => t('Advanced Account/Page Type Settings'), '$h_descadvn' => t('Change the behaviour of this account for special situations'), '$pagetype' => $pagetype, '$relocate' => t('Relocate'), '$relocate_text' => t("If you have moved this profile from another server, and some of your contacts don't receive your updates, try pushing this button."), '$relocate_button' => t("Resend relocate message to contacts")));
     call_hooks('settings_form', $o);
     $o .= '</form>' . "\r\n";
     return $o;
 }
Example #25
0
}
/*
 * check_config() is responsible for running update scripts. These automatically 
 * update the DB schema whenever we push a new one out. It also checks to see if
 * any plugins have been added or removed and reacts accordingly. 
 */
if ($install) {
    $a->module = 'install';
} elseif ($maintenance) {
    $a->module = 'maintenance';
} else {
    check_url($a);
    check_db();
    check_plugins($a);
}
nav_set_selected('nothing');
$arr = array('app_menu' => $a->apps);
call_hooks('app_menu', $arr);
$a->apps = $arr['app_menu'];
/**
 *
 * We have already parsed the server path into $a->argc and $a->argv
 *
 * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php
 * and use it for handling our URL request.
 * The module file contains a few functions that we call in various circumstances
 * and in the following order:
 * 
 * "module"_init
 * "module"_post (only called if there are $_POST variables)
 * "module"_afterpost
Example #26
0
function search_content(&$a, $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 = $a->get_observer();
    $observer_hash = $observer ? $observer['xchan_hash'] : '';
    $o = '<div id="live-search"></div>' . "\r\n";
    $o .= '<h3>' . t('Search') . '</h3>';
    if (x($a->data, 'search')) {
        $search = trim($a->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&search=' . $search);
    }
    // look for a naked webbie
    if (strpos($search, '@') !== false) {
        goaway(z_root() . '/directory' . '?f=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 = %d and term = '%s') ", intval(TERM_OBJ_POST), intval(TERM_HASHTAG), 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 = " . $a->pager['page'] . "; </script>\r\n";
        $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'search', '$uid' => $a->profile['profile_uid'] ? $a->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' => $a->pager['page'] != 1 ? $a->pager['page'] : 1, '$search' => ($tag ? urlencode('#') : '') . $search, '$order' => '', '$file' => '', '$cats' => '', '$tags' => '', '$mid' => '', '$verb' => '', '$dend' => '', '$dbegin' => ''));
    }
    $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');
        $a->set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
        $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->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\tWHERE item_restrict = 0\n\t\t\t\t\tAND ((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\tOR ( `item`.`uid` = %d )) OR item.owner_xchan = '%s' )\n\t\t\t\t\t{$sql_extra}\n\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\tWHERE item_restrict = 0\n\t\t\t\t\tAND (((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = ''\n\t\t\t\t\tAND `item`.`deny_gid`  = '' AND item_private = 0 )\n\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\t\t{$pub_sql} ) OR owner_xchan = '%s')\n\t\t\t\t\t{$sql_extra} \n\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>Items tagged with: ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8') . '</h2>';
    } else {
        $o .= '<h2>Search results for: ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8') . '</h2>';
    }
    $o .= conversation($a, $items, 'search', $update, 'client');
    return $o;
}
Example #27
0
function profile_content(&$a, $update = 0)
{
    $category = $datequery = $datequery2 = '';
    if ($a->argc > 2) {
        for ($x = 2; $x < $a->argc; $x++) {
            if (is_a_date_arg($a->argv[$x])) {
                if ($datequery) {
                    $datequery2 = escape_tags($a->argv[$x]);
                } else {
                    $datequery = escape_tags($a->argv[$x]);
                }
            } else {
                $category = $a->argv[$x];
            }
        }
    }
    if (!x($category)) {
        $category = x($_GET, 'category') ? $_GET['category'] : '';
    }
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        return login();
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    require_once 'include/acl_selectors.php';
    require_once 'include/items.php';
    $groups = array();
    $tab = 'posts';
    $o = '';
    if ($update) {
        // Ensure we've got a profile owner if updating.
        $a->profile['profile_uid'] = $update;
    } else {
        if ($a->profile['profile_uid'] == local_user()) {
            nav_set_selected('home');
        }
    }
    $contact = null;
    $remote_contact = false;
    $contact_id = 0;
    if (is_array($_SESSION['remote'])) {
        foreach ($_SESSION['remote'] as $v) {
            if ($v['uid'] == $a->profile['profile_uid']) {
                $contact_id = $v['cid'];
                break;
            }
        }
    }
    if ($contact_id) {
        $groups = init_groups_visitor($contact_id);
        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($a->profile['profile_uid']));
        if (count($r)) {
            $contact = $r[0];
            $remote_contact = true;
        }
    }
    if (!$remote_contact) {
        if (local_user()) {
            $contact_id = $_SESSION['cid'];
            $contact = $a->contact;
        }
    }
    $is_owner = local_user() && local_user() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !$remote_contact) {
        notice(t('Access to this profile has been restricted.') . EOL);
        return;
    }
    if (!$update) {
        if (x($_GET, 'tab')) {
            $tab = notags(trim($_GET['tab']));
        }
        $o .= profile_tabs($a, $is_owner, $a->profile['nickname']);
        if ($tab === 'profile') {
            $o .= advanced_profile($a);
            call_hooks('profile_advanced', $o);
            return $o;
        }
        $o .= common_friends_visitor_widget($a->profile['profile_uid']);
        if (x($_SESSION, 'new_member') && $_SESSION['new_member'] && $is_owner) {
            $o .= '<a href="newmember" id="newmember-tips" style="font-size: 1.2em;"><b>' . t('Tips for New Members') . '</b></a>' . EOL;
        }
        $commpage = $a->profile['page-flags'] == PAGE_COMMUNITY ? true : false;
        $commvisitor = $commpage && $remote_contact == true ? true : false;
        $a->page['aside'] .= posted_date_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
        $a->page['aside'] .= categories_widget($a->get_baseurl(true) . '/profile/' . $a->profile['nickname'], x($category) ? xmlify($category) : '');
        if (can_write_wall($a, $a->profile['profile_uid'])) {
            $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'] ? true : false, 'default_location' => $is_owner ? $a->user['default-location'] : '', 'nickname' => $a->profile['nickname'], 'lockstate' => is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($a->user, true) : '', 'bang' => '', 'visitor' => $is_owner || $commvisitor ? 'block' : 'none', 'profile_uid' => $a->profile['profile_uid'], 'acl_data' => $is_owner ? construct_acl_data($a, $a->user) : '');
            $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
     */
    $sql_extra = item_permissions_sql($a->profile['profile_uid'], $remote_contact, $groups);
    if ($update) {
        $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t`contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND\n\t\t\t(`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE . "' OR item.verb = '" . ACTIVITY_DISLIKE . "')\n\t\t\tand `item`.`moderated` = 0 and `item`.`unseen` = 1\n\t\t\tAND `item`.`wall` = 1\n\t\t\t{$sql_extra}\n\t\t\tORDER BY `item`.`created` DESC", intval($a->profile['profile_uid']));
    } else {
        $sql_post_table = "";
        if (x($category)) {
            $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
            //$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
        }
        if ($datequery) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
        }
        if ($datequery2) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
        }
        if (get_config('system', 'old_pager')) {
            $r = q("SELECT COUNT(*) AS `total`\n\t\t\t    FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`\n\t\t\t    {$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`\n\t\t\t    AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t    WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0\n\t\t\t    and `thread`.`moderated` = 0\n\t\t\t    AND `thread`.`wall` = 1\n\t\t\t    {$sql_extra} {$sql_extra2} ", intval($a->profile['profile_uid']));
            if (count($r)) {
                $a->set_pager_total($r[0]['total']);
            }
        }
        //  check if we serve a mobile device and get the user settings
        //  accordingly
        if ($a->is_mobile) {
            $itemspage_network = get_pconfig(local_user(), 'system', 'itemspage_mobile_network');
            $itemspage_network = intval($itemspage_network) ? $itemspage_network : 20;
        } else {
            $itemspage_network = get_pconfig(local_user(), 'system', 'itemspage_network');
            $itemspage_network = intval($itemspage_network) ? $itemspage_network : 40;
        }
        //  now that we have the user settings, see if the theme forces
        //  a maximum item number which is lower then the user choice
        if ($a->force_max_items > 0 && $a->force_max_items < $itemspage_network) {
            $itemspage_network = $a->force_max_items;
        }
        $a->set_pager_itemspage($itemspage_network);
        $pager_sql = sprintf(" LIMIT %d, %d ", intval($a->pager['start']), intval($a->pager['itemspage']));
        $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`,\n\t\t\t`thread`.`uid` AS `contact-uid`\n\t\t\tFROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid`\n\t\t\t{$sql_post_table} INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tWHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0\n\t\t\tand `thread`.`moderated` = 0\n\t\t\tAND `thread`.`wall` = 1\n\t\t\t{$sql_extra} {$sql_extra2}\n\t\t\tORDER BY `thread`.`created` DESC {$pager_sql} ", intval($a->profile['profile_uid']));
    }
    $parents_arr = array();
    $parents_str = '';
    if (count($r)) {
        foreach ($r as $rr) {
            $parents_arr[] = $rr['item_id'];
        }
        $parents_str = implode(', ', $parents_arr);
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,\n\t\t\t`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`network`, `contact`.`rel`,\n\t\t\t`contact`.`thumb`, `contact`.`self`, `contact`.`writable`,\n\t\t\t`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`\n\t\t\tFROM `item`, `contact`\n\t\t\tWHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0\n\t\t\tand `item`.`moderated` = 0\n\t\t\tAND `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t{$sql_extra} ", intval($a->profile['profile_uid']), dbesc($parents_str));
        $items = conv_sort($items, 'created');
    } else {
        $items = array();
    }
    if ($is_owner && !$update && !get_config('theme', 'hide_eventlist')) {
        $o .= get_birthdays();
        $o .= get_events();
    }
    if ($is_owner) {
        $r = q("UPDATE `item` SET `unseen` = 0\n\t\t\tWHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d", intval(local_user()));
    }
    $o .= conversation($a, $items, 'profile', $update);
    if (!$update) {
        if (!get_config('system', 'old_pager')) {
            $o .= alt_pager($a, count($items));
        } else {
            $o .= paginate($a);
        }
    }
    return $o;
}
Example #28
0
function contacts_content(&$a)
{
    $sort_type = 0;
    $o = '';
    nav_set_selected('contacts');
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc == 3) {
        $contact_id = intval($a->argv[1]);
        if (!$contact_id) {
            return;
        }
        $cmd = $a->argv[2];
        $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1", intval($contact_id), intval(local_user()));
        if (!count($orig_record)) {
            notice(t('Could not access contact record.') . EOL);
            goaway($a->get_baseurl() . '/contacts');
            return;
            // NOTREACHED
        }
        if ($cmd === 'update') {
            // pull feed and consume it, which should subscribe to the hub.
            proc_run('php', "include/poller.php", "{$contact_id}");
            goaway($a->get_baseurl() . '/contacts/' . $contact_id);
            // NOTREACHED
        }
        if ($cmd === 'block') {
            $blocked = $orig_record[0]['blocked'] ? 0 : 1;
            $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($blocked), intval($contact_id), intval(local_user()));
            if ($r) {
                //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
                info(($blocked ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL);
            }
            goaway($a->get_baseurl() . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'ignore') {
            $readonly = $orig_record[0]['readonly'] ? 0 : 1;
            $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($readonly), intval($contact_id), intval(local_user()));
            if ($r) {
                info(($readonly ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL);
            }
            goaway($a->get_baseurl() . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'drop') {
            // create an unfollow slap
            if ($orig_record[0]['network'] === NETWORK_OSTATUS) {
                $tpl = get_markup_template('follow_slap.tpl');
                $slap = replace_macros($tpl, array('$name' => $a->user['username'], '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'], '$photo' => $a->contact['photo'], '$thumb' => $a->contact['thumb'], '$published' => datetime_convert('UTC', 'UTC', 'now', ATOM_TIME), '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(), '$title' => '', '$type' => 'text', '$content' => t('stopped following'), '$nick' => $a->user['nickname'], '$verb' => 'http://ostatus.org/schema/1.0/unfollow', '$ostat_follow' => ''));
                if (x($orig_record[0], 'notify') && strlen($orig_record[0]['notify'])) {
                    require_once 'include/salmon.php';
                    slapper($a->user, $orig_record[0]['notify'], $slap);
                }
            } elseif ($orig_record[0]['network'] === NETWORK_DIASPORA) {
                require_once 'include/diaspora.php';
                diaspora_unshare($a->user, $orig_record[0]);
            } elseif ($orig_record[0]['network'] === NETWORK_DFRN) {
                require_once 'include/items.php';
                dfrn_deliver($a->user, $orig_record[0], 'placeholder', 1);
            }
            contact_remove($orig_record[0]['id']);
            info(t('Contact has been removed.') . EOL);
            if (x($_SESSION, 'return_url')) {
                goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
            } else {
                goaway($a->get_baseurl() . '/contacts');
            }
            return;
            // NOTREACHED
        }
    }
    if (x($a->data, 'contact') && is_array($a->data['contact'])) {
        $contact_id = $a->data['contact']['id'];
        $contact = $a->data['contact'];
        $tpl = get_markup_template('contact_head.tpl');
        $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
        require_once 'include/contact_selectors.php';
        $tpl = get_markup_template("contact_edit.tpl");
        switch ($contact['rel']) {
            case CONTACT_IS_FRIEND:
                $dir_icon = 'images/lrarrow.gif';
                $relation_text = t('You are mutual friends with %s');
                break;
            case CONTACT_IS_FOLLOWER:
                $dir_icon = 'images/larrow.gif';
                $relation_text = t('You are sharing with %s');
                break;
            case CONTACT_IS_SHARING:
                $dir_icon = 'images/rarrow.gif';
                $relation_text = t('%s is sharing with you');
                break;
            default:
                break;
        }
        $relation_text = sprintf($relation_text, $contact['name']);
        if ($contact['network'] === NETWORK_DFRN && $contact['rel']) {
            $url = "redir/{$contact['id']}";
            $sparkle = ' class="sparkle" ';
        } else {
            $url = $contact['url'];
            $sparkle = '';
        }
        $insecure = t('Private communications are not available for this contact.');
        $last_update = $contact['last-update'] == '0000-00-00 00:00:00' ? t('Never') : datetime_convert('UTC', date_default_timezone_get(), $contact['last-update'], 'D, j M Y, g:i A');
        if ($contact['last-update'] !== '0000-00-00 00:00:00') {
            $last_update .= ' ' . ($contact['last-update'] == $contact['success_update'] ? t("(Update was successful)") : t("(Update was not successful)"));
        }
        $lblsuggest = $contact['network'] === NETWORK_DFRN ? t('Suggest friends') : '';
        $poll_enabled = $contact['network'] !== NETWORK_DIASPORA ? true : false;
        $nettype = sprintf(t('Network type: %s'), network_to_name($contact['network']));
        $common = count_common_friends(local_user(), $contact['id']);
        $common_text = $common ? sprintf(tt('%d contact in common', '%d contacts in common', $common), $common) : '';
        $polling = $contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED ? 'polling' : '';
        $x = count_all_friends(local_user(), $contact['id']);
        $all_friends = $x ? t('View all contacts') : '';
        // tabs
        $tabs = array(array('label' => $contact['blocked'] ? t('Unblock') : t('Block'), 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block', 'sel' => ''), array('label' => $contact['readonly'] ? t('Unignore') : t('Ignore'), 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore', 'sel' => ''), array('label' => t('Repair'), 'url' => $a->get_baseurl() . '/crepair/' . $contact_id, 'sel' => ''));
        $tab_tpl = get_markup_template('common_tabs.tpl');
        $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
        $o .= replace_macros($tpl, array('$header' => t('Contact Editor'), '$tab_str' => $tab_str, '$submit' => t('Submit'), '$lbl_vis1' => t('Profile Visibility'), '$lbl_vis2' => sprintf(t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']), '$lbl_info1' => t('Contact Information / Notes'), '$infedit' => t('Edit contact notes'), '$common_text' => $common_text, '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'], '$all_friends' => $all_friends, '$relation_text' => $relation_text, '$visit' => sprintf(t('Visit %s\'s profile [%s]'), $contact['name'], $contact['url']), '$blockunblock' => t('Block/Unblock contact'), '$ignorecont' => t('Ignore contact'), '$lblcrepair' => t("Repair URL settings"), '$lblrecent' => t('View conversations'), '$lblsuggest' => $lblsuggest, '$delete' => t('Delete contact'), '$nettype' => $nettype, '$poll_interval' => contact_poll_interval($contact['priority'], !$poll_enabled), '$poll_enabled' => $poll_enabled, '$lastupdtext' => t('Last update:'), '$updpub' => t('Update public posts'), '$last_update' => $last_update, '$udnow' => t('Update now'), '$profile_select' => contact_profile_assign($contact['profile-id'], $contact['network'] !== NETWORK_DFRN ? true : false), '$contact_id' => $contact['id'], '$block_text' => $contact['blocked'] ? t('Unblock') : t('Block'), '$ignore_text' => $contact['readonly'] ? t('Unignore') : t('Ignore'), '$insecure' => $contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA ? $insecure : '', '$info' => $contact['info'], '$blocked' => $contact['blocked'] ? t('Currently blocked') : '', '$ignored' => $contact['readonly'] ? t('Currently ignored') : '', '$hidden' => array('hidden', t('Hide this contact from others'), $contact['hidden'] == 1, t('Replies/likes to your public posts <strong>may</strong> still be visible')), '$photo' => $contact['photo'], '$name' => $contact['name'], '$dir_icon' => $dir_icon, '$alt_text' => $alt_text, '$sparkle' => $sparkle, '$url' => $url));
        $arr = array('contact' => $contact, 'output' => $o);
        call_hooks('contact_edit', $arr);
        return $arr['output'];
    }
    $blocked = false;
    $hidden = false;
    $ignored = false;
    $all = false;
    $_SESSION['return_url'] = $a->query_string;
    if ($a->argc == 2 && $a->argv[1] === 'all') {
        $sql_extra = '';
        $all = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'blocked') {
        $sql_extra = " AND `blocked` = 1 ";
        $blocked = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'hidden') {
        $sql_extra = " AND `hidden` = 1 ";
        $hidden = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'ignored') {
        $sql_extra = " AND `readonly` = 1 ";
        $ignored = true;
    } else {
        $sql_extra = " AND `blocked` = 0 ";
    }
    $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
    $nets = x($_GET, 'nets') ? notags(trim($_GET['nets'])) : '';
    $tabs = array(array('label' => t('All Contacts'), 'url' => $a->get_baseurl() . '/contacts/all', 'sel' => $all ? 'active' : ''), array('label' => t('Unblocked Contacts'), 'url' => $a->get_baseurl() . '/contacts', 'sel' => !$all && !$blocked && !$hidden && !$search && !$nets && !$ignored ? 'active' : ''), array('label' => t('Blocked Contacts'), 'url' => $a->get_baseurl() . '/contacts/blocked', 'sel' => $blocked ? 'active' : ''), array('label' => t('Ignored Contacts'), 'url' => $a->get_baseurl() . '/contacts/ignored', 'sel' => $ignored ? 'active' : ''), array('label' => t('Hidden Contacts'), 'url' => $a->get_baseurl() . '/contacts/hidden', 'sel' => $hidden ? 'active' : ''));
    $tab_tpl = get_markup_template('common_tabs.tpl');
    $t = replace_macros($tab_tpl, array('$tabs' => $tabs));
    if ($search) {
        $search_hdr = $search;
        $search = dbesc($search . '*');
    }
    $sql_extra .= strlen($search) ? " AND MATCH `name` AGAINST ('{$search}' IN BOOLEAN MODE) " : "";
    if ($nets) {
        $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
    }
    $sql_extra2 = $sort_type > 0 && $sort_type <= CONTACT_IS_FRIEND ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '';
    $r = q("SELECT COUNT(*) AS `total` FROM `contact` \n\t\tWHERE `uid` = %d AND `pending` = 0 {$sql_extra} {$sql_extra2} ", intval($_SESSION['uid']));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    $tpl = get_markup_template("contacts-top.tpl");
    $o .= replace_macros($tpl, array('$header' => t('Contacts') . ($nets ? ' - ' . network_to_name($nets) : ''), '$tabs' => $t, '$total' => $r[0]['total'], '$search' => $search_hdr, '$desc' => t('Search your contacts'), '$finding' => strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "", '$submit' => t('Find'), '$cmd' => $a->cmd));
    $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 {$sql_extra} {$sql_extra2} ORDER BY `name` ASC LIMIT %d , %d ", intval($_SESSION['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
    if (count($r)) {
        $tpl = get_markup_template("contact_template.tpl");
        foreach ($r as $rr) {
            if ($rr['self']) {
                continue;
            }
            switch ($rr['rel']) {
                case CONTACT_IS_FRIEND:
                    $dir_icon = 'images/lrarrow.gif';
                    $alt_text = t('Mutual Friendship');
                    break;
                case CONTACT_IS_FOLLOWER:
                    $dir_icon = 'images/larrow.gif';
                    $alt_text = t('is a fan of yours');
                    break;
                case CONTACT_IS_SHARING:
                    $dir_icon = 'images/rarrow.gif';
                    $alt_text = t('you are a fan of');
                    break;
                default:
                    break;
            }
            if ($rr['network'] === 'dfrn' && $rr['rel']) {
                $url = "redir/{$rr['id']}";
                $sparkle = ' class="sparkle" ';
            } else {
                $url = $rr['url'];
                $sparkle = '';
            }
            $o .= replace_macros($tpl, array('$img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), '$edit_hover' => t('Edit contact'), '$contact_photo_menu' => contact_photo_menu($rr), '$id' => $rr['id'], '$alt_text' => $alt_text, '$dir_icon' => $dir_icon, '$thumb' => $rr['thumb'], '$name' => $rr['name'], '$username' => $rr['name'], '$sparkle' => $sparkle, '$url' => $url));
        }
        $o .= '<div id="contact-edit-end"></div>';
    }
    $o .= paginate($a);
    return $o;
}
Example #29
0
function community_content(&$a, $update = 0)
{
    $o = '';
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (get_config('system', 'community_page_style') == CP_NO_COMMUNITY_PAGE) {
        notice(t('Not available.') . EOL);
        return;
    }
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    $o .= '<h3>' . t('Community') . '</h3>';
    if (!$update) {
        nav_set_selected('community');
    }
    if (x($a->data, 'search')) {
        $search = notags(trim($a->data['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    // Here is the way permissions work in this module...
    // Only public posts can be shown
    // OR your own posts if you are a logged in member
    if (get_config('system', 'old_pager')) {
        $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total`\n\t\t\tFROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\tAND `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\tINNER JOIN `user` ON `user`.`uid` = `item`.`uid` AND `user`.`hidewall` = 0\n\t\t\tWHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0\n\t\t\tAND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''\n\t\t\tAND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''\n\t\t\tAND `item`.`private` = 0 AND `item`.`wall` = 1");
        if (count($r)) {
            $a->set_pager_total($r[0]['total']);
        }
        if (!$r[0]['total']) {
            info(t('No results.') . EOL);
            return $o;
        }
    }
    $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
    if (!count($r)) {
        info(t('No results.') . EOL);
        return $o;
    }
    $maxpostperauthor = get_config('system', 'max_author_posts_community_page');
    if ($maxpostperauthor != 0) {
        $count = 1;
        $previousauthor = "";
        $numposts = 0;
        $s = array();
        do {
            foreach ($r as $row => $item) {
                if ($previousauthor == $item["author-link"]) {
                    ++$numposts;
                } else {
                    $numposts = 0;
                }
                $previousauthor = $item["author-link"];
                if ($numposts < $maxpostperauthor and sizeof($s) < $a->pager['itemspage']) {
                    $s[] = $item;
                }
            }
            if (sizeof($s) < $a->pager['itemspage']) {
                $r = community_getitems($a->pager['start'] + $count * $a->pager['itemspage'], $a->pager['itemspage']);
            }
        } while (sizeof($s) < $a->pager['itemspage'] and ++$count < 50 and sizeof($r) > 0);
    } else {
        $s = $r;
    }
    // we behave the same in message lists as the search module
    $o .= conversation($a, $s, 'community', $update);
    if (!get_config('system', 'old_pager')) {
        $o .= alt_pager($a, count($r));
    } else {
        $o .= paginate($a);
    }
    return $o;
}
Example #30
0
File: mail.php Project: Mauru/red
function mail_content(&$a)
{
    $o = '';
    nav_set_selected('messages');
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return login();
    }
    $channel = $a->get_channel();
    head_set_icon($channel['xchan_photo_s']);
    $cipher = get_pconfig(local_user(), 'system', 'default_cipher');
    if (!$cipher) {
        $cipher = 'aes256';
    }
    $tpl = get_markup_template('mail_head.tpl');
    $header = replace_macros($tpl, array('$messages' => t('Messages'), '$tab_content' => $tab_content));
    if (argc() == 3 && argv(1) === 'drop') {
        if (!intval(argv(2))) {
            return;
        }
        $cmd = argv(1);
        $r = private_messages_drop(local_user(), argv(2));
        if ($r) {
            info(t('Message deleted.') . EOL);
        }
        goaway($a->get_baseurl(true) . '/message');
    }
    if (argc() == 3 && argv(1) === 'recall') {
        if (!intval(argv(2))) {
            return;
        }
        $cmd = argv(1);
        $r = q("update mail set mail_flags = mail_flags | %d where id = %d and channel_id = %d limit 1", intval(MAIL_RECALLED), intval(argv(2)), intval(local_user()));
        proc_run('php', 'include/notifier.php', 'mail', intval(argv(2)));
        if ($r) {
            info(t('Message recalled.') . EOL);
        }
        goaway($a->get_baseurl(true) . '/message');
    }
    if (argc() > 1 && argv(1) === 'new') {
        $o .= $header;
        $plaintext = true;
        $tpl = get_markup_template('msg-header.tpl');
        $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$nickname' => $channel['channel_address'], '$linkurl' => t('Please enter a link URL:'), '$expireswhen' => t('Expires YYYY-MM-DD HH:MM')));
        $preselect = isset($a->argv[2]) ? array($a->argv[2]) : false;
        $prename = $preurl = $preid = '';
        if (x($_REQUEST, 'hash')) {
            $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash\n\t\t\t\twhere abook_channel = %d and abook_xchan = '%s' limit 1", intval(local_user()), dbesc($_REQUEST['hash']));
            if ($r) {
                $prename = $r[0]['xchan_name'];
                $preurl = $r[0]['xchan_url'];
                $preid = $r[0]['abook_id'];
                $preselect = array($preid);
            }
        }
        if ($preselect) {
            $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash\n\t\t\t\twhere abook_channel = %d and abook_id = %d limit 1", intval(local_user()), intval(argv(2)));
            if ($r) {
                $prename = $r[0]['xchan_name'];
                $preurl = $r[0]['xchan_url'];
                $preid = $r[0]['abook_id'];
            }
        }
        $prefill = $preselect ? $prename : '';
        if (!$prefill) {
            if (array_key_exists('to', $_REQUEST)) {
                $prefill = $_REQUEST['to'];
            }
        }
        // the ugly select box
        $select = contact_select('messageto', 'message-to-select', $preselect, 4, true, false, false, 10);
        $tpl = get_markup_template('prv_message.tpl');
        $o .= replace_macros($tpl, array('$header' => t('Send Private Message'), '$to' => t('To:'), '$showinputs' => 'true', '$prefill' => $prefill, '$autocomp' => $autocomp, '$preid' => $preid, '$subject' => t('Subject:'), '$subjtxt' => x($_REQUEST, 'subject') ? strip_tags($_REQUEST['subject']) : '', '$text' => x($_REQUEST, 'body') ? htmlspecialchars($_REQUEST['body'], ENT_COMPAT, 'UTF-8') : '', '$readonly' => '', '$yourmessage' => t('Your message:'), '$select' => $select, '$parent' => '', '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$insert' => t('Insert web link'), '$wait' => t('Please wait'), '$submit' => t('Send'), '$defexpire' => '', '$feature_expire' => feature_enabled(local_user(), 'content_expire') ? true : false, '$expires' => t('Set expiration date'), '$feature_encrypt' => feature_enabled(local_user(), 'content_encrypt') ? true : false, '$encrypt' => t('Encrypt text'), '$cipher' => $cipher));
        return $o;
    }
    if (argc() > 1 && intval(argv(1))) {
        $o .= $header;
        $plaintext = true;
        //		if( local_user() && feature_enabled(local_user(),'richtext') )
        //			$plaintext = false;
        $messages = private_messages_fetch_conversation(local_user(), argv(1), true);
        if (!$messages) {
            info(t('Message not found.') . EOL);
            return $o;
        }
        if ($messages[0]['to_xchan'] === $channel['channel_hash']) {
            $a->poi = $messages[0]['from'];
        } else {
            $a->poi = $messages[0]['to'];
        }
        //		require_once('include/Contact.php');
        //		$a->set_widget('mail_conversant',vcard_from_xchan($a->poi,$get_observer_hash,'mail'));
        $tpl = get_markup_template('msg-header.tpl');
        $a->page['htmlhead'] .= replace_macros($tpl, array('$nickname' => $channel['channel_addr'], '$baseurl' => $a->get_baseurl(true), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$linkurl' => t('Please enter a link URL:'), '$expireswhen' => t('Expires YYYY-MM-DD HH:MM')));
        $mails = array();
        $seen = 0;
        $unknown = false;
        foreach ($messages as $message) {
            $s = theme_attachments($message);
            $mails[] = array('id' => $message['id'], 'from_name' => $message['from']['xchan_name'], 'from_url' => chanlink_hash($message['from_xchan']), 'from_photo' => $message['from']['xchan_photo_m'], 'to_name' => $message['to']['xchan_name'], 'to_url' => chanlink_hash($message['to_xchan']), 'to_photo' => $message['to']['xchan_photo_m'], 'subject' => $message['title'], 'body' => smilies(bbcode($message['body']) . $s), 'delete' => t('Delete message'), 'recall' => t('Recall message'), 'can_recall' => $channel['channel_hash'] == $message['from_xchan'] ? true : false, 'is_recalled' => $message['mail_flags'] & MAIL_RECALLED ? t('Message has been recalled.') : '', 'date' => datetime_convert('UTC', date_default_timezone_get(), $message['created'], 'D, d M Y - g:i A'));
            $seen = $message['seen'];
        }
        $recp = $message['from_xchan'] === $channel['channel_hash'] ? 'to' : 'from';
        // FIXME - move this HTML to template
        $select = $message[$recp]['xchan_name'] . '<input type="hidden" name="messageto" value="' . $message[$recp]['xchan_hash'] . '" />';
        $parent = '<input type="hidden" name="replyto" value="' . $message['parent_mid'] . '" />';
        $tpl = get_markup_template('mail_display.tpl');
        $o = replace_macros($tpl, array('$prvmsg_header' => t('Private Conversation'), '$thread_id' => $a->argv[1], '$thread_subject' => $message['title'], '$thread_seen' => $seen, '$delete' => t('Delete conversation'), '$canreply' => $unknown ? false : '1', '$unknown_text' => t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."), '$mails' => $mails, '$header' => t('Send Reply'), '$to' => t('To:'), '$showinputs' => '', '$subject' => t('Subject:'), '$subjtxt' => $message['title'], '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', '$yourmessage' => t('Your message:'), '$text' => '', '$select' => $select, '$parent' => $parent, '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$insert' => t('Insert web link'), '$submit' => t('Submit'), '$wait' => t('Please wait'), '$defexpire' => '', '$feature_expire' => feature_enabled(local_user(), 'content_expire') ? true : false, '$expires' => t('Set expiration date'), '$feature_encrypt' => feature_enabled(local_user(), 'content_encrypt') ? true : false, '$encrypt' => t('Encrypt text'), '$cipher' => $cipher));
        return $o;
    }
}