Exemplo n.º 1
0
function suggest_init(&$a)
{
    if (!local_user()) {
        return;
    }
    if (x($_GET, 'ignore') && intval($_GET['ignore'])) {
        // Check if we should do HTML-based delete confirmation
        if ($_REQUEST['confirm']) {
            // <form> can't take arguments in its "action" parameter
            // so add any arguments as hidden inputs
            $query = explode_querystring($a->query_string);
            $inputs = array();
            foreach ($query['args'] as $arg) {
                if (strpos($arg, 'confirm=') === false) {
                    $arg_parts = explode('=', $arg);
                    $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
                }
            }
            $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array('$method' => 'get', '$message' => t('Do you really want to delete this suggestion?'), '$extra_inputs' => $inputs, '$confirm' => t('Yes'), '$confirm_url' => $query['base'], '$confirm_name' => 'confirmed', '$cancel' => t('Cancel')));
            $a->error = 1;
            // Set $a->error so the other module functions don't execute
            return;
        }
        // Now check how the user responded to the confirmation query
        if (!$_REQUEST['canceled']) {
            q("INSERT INTO `gcign` ( `uid`, `gcid` ) VALUES ( %d, %d ) ", intval(local_user()), intval($_GET['ignore']));
        }
    }
}
Exemplo n.º 2
0
function drop_item($id, $interactive = true)
{
    $a = get_app();
    // locate item to be deleted
    $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($id));
    if (!count($r)) {
        if (!$interactive) {
            return 0;
        }
        notice(t('Item not found.') . EOL);
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
    }
    $item = $r[0];
    $owner = $item['uid'];
    $cid = 0;
    // check if logged in user is either the author or owner of this item
    if (is_array($_SESSION['remote'])) {
        foreach ($_SESSION['remote'] as $visitor) {
            if ($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) {
                $cid = $visitor['cid'];
                break;
            }
        }
    }
    if (local_user() == $item['uid'] || $cid || !$interactive) {
        // Check if we should do HTML-based delete confirmation
        if ($_REQUEST['confirm']) {
            // <form> can't take arguments in its "action" parameter
            // so add any arguments as hidden inputs
            $query = explode_querystring($a->query_string);
            $inputs = array();
            foreach ($query['args'] as $arg) {
                if (strpos($arg, 'confirm=') === false) {
                    $arg_parts = explode('=', $arg);
                    $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
                }
            }
            return replace_macros(get_markup_template('confirm.tpl'), array('$method' => 'get', '$message' => t('Do you really want to delete this item?'), '$extra_inputs' => $inputs, '$confirm' => t('Yes'), '$confirm_url' => $query['base'], '$confirm_name' => 'confirmed', '$cancel' => t('Cancel')));
        }
        // Now check how the user responded to the confirmation query
        if ($_REQUEST['canceled']) {
            goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
        }
        logger('delete item: ' . $item['id'], LOGGER_DEBUG);
        // delete the item
        $r = q("UPDATE `item` SET `deleted` = 1, `title` = '', `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), dbesc(datetime_convert()), intval($item['id']));
        create_tags_from_item($item['id']);
        create_files_from_item($item['id']);
        delete_thread($item['id'], $item['parent-uri']);
        // clean up categories and tags so they don't end up as orphans
        $matches = false;
        $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER);
        if ($cnt) {
            foreach ($matches as $mtch) {
                file_tag_unsave_file($item['uid'], $item['id'], $mtch[1], true);
            }
        }
        $matches = false;
        $cnt = preg_match_all('/\\[(.*?)\\]/', $item['file'], $matches, PREG_SET_ORDER);
        if ($cnt) {
            foreach ($matches as $mtch) {
                file_tag_unsave_file($item['uid'], $item['id'], $mtch[1], false);
            }
        }
        // If item is a link to a photo resource, nuke all the associated photos
        // (visitors will not have photo resources)
        // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
        // generate a resource-id and therefore aren't intimately linked to the item.
        if (strlen($item['resource-id'])) {
            q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ", dbesc($item['resource-id']), intval($item['uid']));
            // ignore the result
        }
        // If item is a link to an event, nuke the event record.
        if (intval($item['event-id'])) {
            q("DELETE FROM `event` WHERE `id` = %d AND `uid` = %d", intval($item['event-id']), intval($item['uid']));
            // ignore the result
        }
        // If item has attachments, drop them
        foreach (explode(",", $item['attach']) as $attach) {
            preg_match("|attach/(\\d+)|", $attach, $matches);
            q("DELETE FROM `attach` WHERE `id` = %d AND `uid` = %d", intval($matches[1]), local_user());
            // ignore the result
        }
        // clean up item_id and sign meta-data tables
        /*
        // Old code - caused very long queries and warning entries in the mysql logfiles:
        
        $r = q("DELETE FROM item_id where iid in (select id from item where parent = %d and uid = %d)",
        	intval($item['id']),
        	intval($item['uid'])
        );
        
        $r = q("DELETE FROM sign where iid in (select id from item where parent = %d and uid = %d)",
        	intval($item['id']),
        	intval($item['uid'])
        );
        */
        // The new code splits the queries since the mysql optimizer really has bad problems with subqueries
        // Creating list of parents
        $r = q("select id from item where parent = %d and uid = %d", intval($item['id']), intval($item['uid']));
        $parentid = "";
        foreach ($r as $row) {
            if ($parentid != "") {
                $parentid .= ", ";
            }
            $parentid .= $row["id"];
        }
        // Now delete them
        if ($parentid != "") {
            $r = q("DELETE FROM item_id where iid in (%s)", dbesc($parentid));
            $r = q("DELETE FROM sign where iid in (%s)", dbesc($parentid));
        }
        // If it's the parent of a comment thread, kill all the kids
        if ($item['uri'] == $item['parent-uri']) {
            $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = ''\n\t\t\t\tWHERE `parent-uri` = '%s' AND `uid` = %d ", dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($item['parent-uri']), intval($item['uid']));
            create_tags_from_itemuri($item['parent-uri'], $item['uid']);
            create_files_from_itemuri($item['parent-uri'], $item['uid']);
            delete_thread_uri($item['parent-uri'], $item['uid']);
            // ignore the result
        } else {
            // ensure that last-child is set in case the comment that had it just got wiped.
            q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", dbesc(datetime_convert()), dbesc($item['parent-uri']), intval($item['uid']));
            // who is the last child now?
            $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1", dbesc($item['parent-uri']), intval($item['uid']));
            if (count($r)) {
                q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d", intval($r[0]['id']));
            }
            // Add a relayable_retraction signature for Diaspora.
            store_diaspora_retract_sig($item, $a->user, $a->get_baseurl());
        }
        $drop_id = intval($item['id']);
        // send the notification upstream/downstream as the case may be
        proc_run('php', "include/notifier.php", "drop", "{$drop_id}");
        if (!$interactive) {
            return $owner;
        }
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
        //NOTREACHED
    } else {
        if (!$interactive) {
            return 0;
        }
        notice(t('Permission denied.') . EOL);
        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
        //NOTREACHED
    }
}
Exemplo n.º 3
0
    $query = array_combine($query_key, $query_val);
    return $query;
}
function implode_querystring($query)
{
    // Combine array into query string
    $query_string = array();
    if (is_array($query)) {
        foreach ($query as $key => $val) {
            $query_string[] = $key . "=" . $val;
        }
        $query_string = implode("&", $query_string);
    }
    return $query_string;
}
$main_query = explode_querystring($_SERVER['QUERY_STRING']);
// Languages list
$lang = array();
$lang['Thai']['name'] = 'ไทย';
$lang['Thai']['code'] = 'th_TH.UTF-8';
$lang['English']['name'] = 'English';
$lang['English']['code'] = 'en_US.UTF-8';
$lang_list = array();
$lang_link_template = "<a href='%s'>%s</a>";
foreach ($lang as $key => $eachlang) {
    $query = $main_query;
    $query['language'] = $key;
    $link = $_SERVER['PHP_SELF'] . "?" . implode_querystring($query);
    $lang_list[] = sprintf($lang_link_template, $link, $eachlang['name']);
}
echo "<div id='rh_language'>Language: " . implode(" | ", $lang_list) . "</div>";
Exemplo n.º 4
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(true) . '/contacts');
            return;
            // NOTREACHED
        }
        if ($cmd === 'update') {
            _contact_update($contact_id);
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            // NOTREACHED
        }
        if ($cmd === 'updateprofile') {
            _contact_update_profile($contact_id);
            goaway($a->get_baseurl(true) . '/crepair/' . $contact_id);
            // NOTREACHED
        }
        if ($cmd === 'block') {
            $r = _contact_block($contact_id, $orig_record[0]);
            if ($r) {
                $blocked = $orig_record[0]['blocked'] ? 0 : 1;
                info(($blocked ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL);
            }
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'ignore') {
            $r = _contact_ignore($contact_id, $orig_record[0]);
            if ($r) {
                $readonly = $orig_record[0]['readonly'] ? 0 : 1;
                info(($readonly ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL);
            }
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'archive') {
            $r = _contact_archive($contact_id, $orig_record[0]);
            if ($r) {
                $archived = $orig_record[0]['archive'] ? 0 : 1;
                info(($archived ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL);
            }
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'drop') {
            // Check if we should do HTML-based delete confirmation
            if ($_REQUEST['confirm']) {
                // <form> can't take arguments in its "action" parameter
                // so add any arguments as hidden inputs
                $query = explode_querystring($a->query_string);
                $inputs = array();
                foreach ($query['args'] as $arg) {
                    if (strpos($arg, 'confirm=') === false) {
                        $arg_parts = explode('=', $arg);
                        $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
                    }
                }
                $a->page['aside'] = '';
                return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array('$contact' => _contact_detail_for_template($orig_record[0]), '$method' => 'get', '$message' => t('Do you really want to delete this contact?'), '$extra_inputs' => $inputs, '$confirm' => t('Yes'), '$confirm_url' => $query['base'], '$confirm_name' => 'confirmed', '$cancel' => t('Cancel')));
            }
            // Now check how the user responded to the confirmation query
            if ($_REQUEST['canceled']) {
                if (x($_SESSION, 'return_url')) {
                    goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
                } else {
                    goaway($a->get_baseurl(true) . '/contacts');
                }
            }
            _contact_drop($contact_id, $orig_record[0]);
            info(t('Contact has been removed.') . EOL);
            if (x($_SESSION, 'return_url')) {
                goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
            } else {
                goaway($a->get_baseurl(true) . '/contacts');
            }
            return;
            // NOTREACHED
        }
    }
    $_SESSION['return_url'] = $a->query_string;
    if (x($a->data, 'contact') && is_array($a->data['contact'])) {
        $contact_id = $a->data['contact']['id'];
        $contact = $a->data['contact'];
        $editselect = 'none';
        if (feature_enabled(local_user(), 'richtext')) {
            $editselect = 'exact';
        }
        $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array('$baseurl' => $a->get_baseurl(true), '$editselect' => $editselect));
        $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array('$baseurl' => $a->get_baseurl(true), '$editselect' => $editselect));
        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;
        }
        if (!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
            $relation_text = "";
        }
        $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 = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
        $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(true) . '/contacts/' . $contact_id . '/block', 'sel' => '', 'title' => t('Toggle Blocked status')), array('label' => $contact['readonly'] ? t('Unignore') : t('Ignore'), 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore', 'sel' => '', 'title' => t('Toggle Ignored status')), array('label' => $contact['archive'] ? t('Unarchive') : t('Archive'), 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive', 'sel' => '', 'title' => t('Toggle Archive status')), array('label' => t('Repair'), 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id, 'sel' => '', 'title' => t('Advanced Contact Settings')));
        $tab_tpl = get_markup_template('common_tabs.tpl');
        $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
        $lost_contact = $contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('', '', 'now') ? t('Communications lost with this contact!') : '';
        if ($contact['network'] == NETWORK_FEED) {
            $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'), array('0' => t('Disabled'), '1' => t('Fetch information'), '2' => t('Fetch information and keywords')));
        }
        if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2))) {
            $poll_interval = contact_poll_interval($contact['priority'], !$poll_enabled);
        }
        if ($contact['network'] == NETWORK_DFRN) {
            $profile_select = contact_profile_assign($contact['profile-id'], $contact['network'] !== NETWORK_DFRN ? true : false);
        }
        $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(true) . '/common/loc/' . local_user() . '/' . $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' => $poll_interval, '$poll_enabled' => $poll_enabled, '$lastupdtext' => t('Last update:'), '$lost_contact' => $lost_contact, '$updpub' => t('Update public posts'), '$last_update' => $last_update, '$udnow' => t('Update now'), '$profile_select' => $profile_select, '$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') : '', '$archived' => $contact['archive'] ? t('Currently archived') : '', '$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')), '$notify' => array('notify', t('Notification for new posts'), $contact['notify_new_posts'] == 1, t('Send a notification of every new post of this contact')), '$fetch_further_information' => $fetch_further_information, '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'], '$ffi_keyword_blacklist' => array('ffi_keyword_blacklist', t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')), '$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;
    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;
    } elseif ($a->argc == 2 && $a->argv[1] === 'archived') {
        $sql_extra = " AND `archive` = 1 ";
        $archived = 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('Suggestions'), 'url' => $a->get_baseurl(true) . '/suggest', 'sel' => '', 'title' => t('Suggest potential friends')), array('label' => t('All Contacts'), 'url' => $a->get_baseurl(true) . '/contacts/all', 'sel' => $all ? 'active' : '', 'title' => t('Show all contacts')), array('label' => t('Unblocked'), 'url' => $a->get_baseurl(true) . '/contacts', 'sel' => !$all && !$blocked && !$hidden && !$search && !$nets && !$ignored && !$archived ? 'active' : '', 'title' => t('Only show unblocked contacts')), array('label' => t('Blocked'), 'url' => $a->get_baseurl(true) . '/contacts/blocked', 'sel' => $blocked ? 'active' : '', 'title' => t('Only show blocked contacts')), array('label' => t('Ignored'), 'url' => $a->get_baseurl(true) . '/contacts/ignored', 'sel' => $ignored ? 'active' : '', 'title' => t('Only show ignored contacts')), array('label' => t('Archived'), 'url' => $a->get_baseurl(true) . '/contacts/archived', 'sel' => $archived ? 'active' : '', 'title' => t('Only show archived contacts')), array('label' => t('Hidden'), 'url' => $a->get_baseurl(true) . '/contacts/hidden', 'sel' => $hidden ? 'active' : '', 'title' => t('Only show hidden contacts')));
    $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 ? " AND (name REGEXP '{$search_txt}' OR url REGEXP '{$search_txt}'  OR nick REGEXP '{$search_txt}') " : "";
    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 `self` = 0 AND `pending` = 0 {$sql_extra} {$sql_extra2} ", intval($_SESSION['uid']));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
        $total = $r[0]['total'];
    }
    $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 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']));
    $contacts = array();
    if (count($r)) {
        foreach ($r as $rr) {
            $contacts[] = _contact_detail_for_template($rr);
        }
    }
    $tpl = get_markup_template("contacts-template.tpl");
    $o .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$header' => t('Contacts') . ($nets ? ' - ' . network_to_name($nets) : ''), '$tabs' => $t, '$total' => $total, '$search' => $search_hdr, '$desc' => t('Search your contacts'), '$finding' => $searching ? t('Finding: ') . "'" . $search . "'" : "", '$submit' => t('Find'), '$cmd' => $a->cmd, '$contacts' => $contacts, '$contact_drop_confirm' => t('Do you really want to delete this contact?'), '$batch_actions' => array('contacts_batch_update' => t('Update'), 'contacts_batch_block' => t('Block') . "/" . t("Unblock"), "contacts_batch_ignore" => t('Ignore') . "/" . t("Unignore"), "contacts_batch_archive" => t('Archive') . "/" . t("Unarchive"), "contacts_batch_drop" => t('Delete')), '$paginate' => paginate($a)));
    return $o;
}
Exemplo n.º 5
0
function message_content(&$a)
{
    $o = '';
    nav_set_selected('messages');
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $myprofile = $a->get_baseurl(true) . '/profile/' . $a->user['nickname'];
    $tpl = get_markup_template('mail_head.tpl');
    $header = replace_macros($tpl, array('$messages' => t('Messages'), '$tab_content' => $tab_content));
    if ($a->argc == 3 && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
        if (!intval($a->argv[2])) {
            return;
        }
        // Check if we should do HTML-based delete confirmation
        if ($_REQUEST['confirm']) {
            // <form> can't take arguments in its "action" parameter
            // so add any arguments as hidden inputs
            $query = explode_querystring($a->query_string);
            $inputs = array();
            foreach ($query['args'] as $arg) {
                if (strpos($arg, 'confirm=') === false) {
                    $arg_parts = explode('=', $arg);
                    $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
                }
            }
            //$a->page['aside'] = '';
            return replace_macros(get_markup_template('confirm.tpl'), array('$method' => 'get', '$message' => t('Do you really want to delete this message?'), '$extra_inputs' => $inputs, '$confirm' => t('Yes'), '$confirm_url' => $query['base'], '$confirm_name' => 'confirmed', '$cancel' => t('Cancel')));
        }
        // Now check how the user responded to the confirmation query
        if ($_REQUEST['canceled']) {
            goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
        }
        $cmd = $a->argv[1];
        if ($cmd === 'drop') {
            $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), intval(local_user()));
            if ($r) {
                info(t('Message deleted.') . EOL);
            }
            //goaway($a->get_baseurl(true) . '/message' );
            goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
        } else {
            $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), intval(local_user()));
            if (count($r)) {
                $parent = $r[0]['parent-uri'];
                $convid = $r[0]['convid'];
                $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ", dbesc($parent), intval(local_user()));
                // remove diaspora conversation pointer
                // Actually if we do this, we can never receive another reply to that conversation,
                // as we will never again have the info we need to re-create it.
                // We'll just have to orphan it.
                //if($convid) {
                //	q("delete from conv where id = %d limit 1",
                //		intval($convid)
                //	);
                //}
                if ($r) {
                    info(t('Conversation removed.') . EOL);
                }
            }
            //goaway($a->get_baseurl(true) . '/message' );
            goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
        }
    }
    if ($a->argc > 1 && $a->argv[1] === 'new') {
        $o .= $header;
        /*		$plaintext = false;
        		if(intval(get_pconfig(local_user(),'system','plaintext')))
        			$plaintext = true;*/
        $plaintext = true;
        if (local_user() && feature_enabled(local_user(), 'richtext')) {
            $plaintext = false;
        }
        $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' => $a->user['nickname'], '$linkurl' => t('Please enter a link URL:')));
        $tpl = get_markup_template('msg-end.tpl');
        $a->page['end'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$nickname' => $a->user['nickname'], '$linkurl' => t('Please enter a link URL:')));
        $preselect = isset($a->argv[2]) ? array($a->argv[2]) : false;
        $prename = $preurl = $preid = '';
        if ($preselect) {
            $r = q("select name, url, id from contact where uid = %d and id = %d limit 1", intval(local_user()), intval($a->argv[2]));
            if (count($r)) {
                $prename = $r[0]['name'];
                $preurl = $r[0]['url'];
                $preid = $r[0]['id'];
            }
        }
        $prefill = $preselect ? $prename : '';
        // 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') ? escape_tags(htmlspecialchars($_REQUEST['body'])) : '', '$readonly' => '', '$yourmessage' => t('Your message:'), '$select' => $select, '$parent' => '', '$upload' => t('Upload photo'), '$insert' => t('Insert web link'), '$wait' => t('Please wait'), '$submit' => t('Submit')));
        return $o;
    }
    $_SESSION['return_url'] = $a->query_string;
    if ($a->argc == 1) {
        // list messages
        $o .= $header;
        $r = q("SELECT count(*) AS `total` FROM `mail`\n\t\t\tWHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `created` DESC", intval(local_user()), dbesc($myprofile));
        if (count($r)) {
            $a->set_pager_total($r[0]['total']);
        }
        $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,\n\t\t\t`mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb` , `contact`.`network`,\n\t\t\tcount( * ) as count\n\t\t\tFROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`\n\t\t\tWHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `mailcreated` DESC  LIMIT %d , %d ", intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage']));
        if (!count($r)) {
            info(t('No messages.') . EOL);
            return $o;
        }
        $tpl = get_markup_template('mail_list.tpl');
        foreach ($r as $rr) {
            if ($rr['unknown']) {
                $partecipants = sprintf(t("Unknown sender - %s"), $rr['from-name']);
            } elseif (link_compare($rr['from-url'], $myprofile)) {
                $partecipants = sprintf(t("You and %s"), $rr['name']);
            } else {
                $partecipants = sprintf(t("%s and You"), $rr['from-name']);
            }
            if ($a->theme['template_engine'] === 'internal') {
                $subject_e = template_escape($rr['mailseen'] ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>');
                $body_e = template_escape($rr['body']);
                $to_name_e = template_escape($rr['name']);
            } else {
                $subject_e = $rr['mailseen'] ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>';
                $body_e = $rr['body'];
                $to_name_e = $rr['name'];
            }
            $o .= replace_macros($tpl, array('$id' => $rr['id'], '$from_name' => $partecipants, '$from_url' => $rr['network'] === NETWORK_DFRN ? $a->get_baseurl(true) . '/redir/' . $rr['contact-id'] : $rr['url'], '$sparkle' => ' sparkle', '$from_photo' => $rr['thumb'] ? $rr['thumb'] : $rr['from-photo'], '$subject' => $subject_e, '$delete' => t('Delete conversation'), '$body' => $body_e, '$to_name' => $to_name_e, '$date' => datetime_convert('UTC', date_default_timezone_get(), $rr['mailcreated'], t('D, d M Y - g:i A')), '$ago' => relative_date($rr['mailcreated']), '$seen' => $rr['mailseen'], '$count' => sprintf(tt('%d message', '%d messages', $rr['count']), $rr['count'])));
        }
        $o .= paginate($a);
        return $o;
    }
    if ($a->argc > 1 && intval($a->argv[1])) {
        $o .= $header;
        $plaintext = true;
        if (local_user() && feature_enabled(local_user(), 'richtext')) {
            $plaintext = false;
        }
        $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`\n\t\t\tFROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`\n\t\t\tWHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1", intval(local_user()), intval($a->argv[1]));
        if (count($r)) {
            $contact_id = $r[0]['contact-id'];
            $convid = $r[0]['convid'];
            $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri']));
            if ($convid) {
                $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ", dbesc($r[0]['parent-uri']), intval($convid));
            }
            $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`\n\t\t\t\tFROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`\n\t\t\t\tWHERE `mail`.`uid` = %d {$sql_extra} ORDER BY `mail`.`created` ASC", intval(local_user()));
        }
        if (!count($messages)) {
            notice(t('Message not available.') . EOL);
            return $o;
        }
        $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($r[0]['parent-uri']), intval(local_user()));
        require_once "include/bbcode.php";
        $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' => $a->user['nickname'], '$linkurl' => t('Please enter a link URL:')));
        $tpl = get_markup_template('msg-end.tpl');
        $a->page['end'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$nickname' => $a->user['nickname'], '$linkurl' => t('Please enter a link URL:')));
        $mails = array();
        $seen = 0;
        $unknown = false;
        foreach ($messages as $message) {
            if ($message['unknown']) {
                $unknown = true;
            }
            if ($message['from-url'] == $myprofile) {
                $from_url = $myprofile;
                $sparkle = '';
            } else {
                $from_url = $a->get_baseurl(true) . '/redir/' . $message['contact-id'];
                $sparkle = ' sparkle';
            }
            $extracted = item_extract_images($message['body']);
            if ($extracted['images']) {
                $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
            }
            if ($a->theme['template_engine'] === 'internal') {
                $from_name_e = template_escape($message['from-name']);
                $subject_e = template_escape($message['title']);
                $body_e = template_escape(smilies(bbcode($message['body'])));
                $to_name_e = template_escape($message['name']);
            } else {
                $from_name_e = $message['from-name'];
                $subject_e = $message['title'];
                $body_e = smilies(bbcode($message['body']));
                $to_name_e = $message['name'];
            }
            $mails[] = array('id' => $message['id'], 'from_name' => $from_name_e, 'from_url' => $from_url, 'sparkle' => $sparkle, 'from_photo' => $message['from-photo'], 'subject' => $subject_e, 'body' => $body_e, 'delete' => t('Delete message'), 'to_name' => $to_name_e, 'date' => datetime_convert('UTC', date_default_timezone_get(), $message['created'], 'D, d M Y - g:i A'), 'ago' => relative_date($message['created']));
            $seen = $message['seen'];
        }
        $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
        $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
        $tpl = get_markup_template('mail_display.tpl');
        if ($a->theme['template_engine'] === 'internal') {
            $subjtxt_e = template_escape($message['title']);
        } else {
            $subjtxt_e = $message['title'];
        }
        $o = replace_macros($tpl, array('$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' => $subjtxt_e, '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', '$yourmessage' => t('Your message:'), '$text' => '', '$select' => $select, '$parent' => $parent, '$upload' => t('Upload photo'), '$insert' => t('Insert web link'), '$submit' => t('Submit'), '$wait' => t('Please wait')));
        return $o;
    }
}