function search_doc_files($s) { $a = get_app(); $itemspage = get_pconfig(local_channel(), 'system', 'itemspage'); App::set_pager_itemspage(intval($itemspage) ? $itemspage : 20); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); $regexop = db_getfunc('REGEXP'); $r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and\n\t\tbody {$regexop} '%s' and item_type = %d {$pager_sql}", dbesc($s), intval(ITEM_TYPE_DOC)); $r = fetch_post_tags($r, true); for ($x = 0; $x < count($r); $x++) { $r[$x]['text'] = $r[$x]['body']; $r[$x]['rank'] = 0; if ($r[$x]['term']) { foreach ($r[$x]['term'] as $t) { if (stristr($t['term'], $s)) { $r[$x]['rank']++; } } } if (stristr($r[$x]['sid'], $s)) { $r[$x]['rank']++; } $r[$x]['rank'] += substr_count(strtolower($r[$x]['text']), strtolower($s)); // bias the results to the observer's native language if ($r[$x]['lang'] === App::$language) { $r[$x]['rank'] = $r[$x]['rank'] + 10; } } usort($r, 'doc_rank_sort'); return $r; }
/** * @brief Channels admin page. * * @param App &$a */ function post() { $channels = x($_POST, 'channel') ? $_POST['channel'] : array(); check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels'); $xor = db_getfunc('^'); if (x($_POST, 'page_channels_block')) { foreach ($channels as $uid) { q("UPDATE channel SET channel_pageflags = ( channel_pageflags {$xor} %d ) where channel_id = %d", intval(PAGE_CENSORED), intval($uid)); \Zotlabs\Daemon\Master::Summon(array('Directory', $uid, 'nopush')); } notice(sprintf(tt("%s channel censored/uncensored", "%s channels censored/uncensored", count($channels)), count($channels))); } if (x($_POST, 'page_channels_code')) { foreach ($channels as $uid) { q("UPDATE channel SET channel_pageflags = ( channel_pageflags {$xor} %d ) where channel_id = %d", intval(PAGE_ALLOWCODE), intval($uid)); } notice(sprintf(tt("%s channel code allowed/disallowed", "%s channels code allowed/disallowed", count($channels)), count($channels))); } if (x($_POST, 'page_channels_delete')) { foreach ($channels as $uid) { channel_remove($uid, true); } notice(sprintf(tt("%s channel deleted", "%s channels deleted", count($channels)), count($channels))); } goaway(z_root() . '/admin/channels'); }
function custom_home_home(&$a, &$o) { $x = get_config('system', 'custom_home'); if ($x) { if ($x == "random") { $rand = db_getfunc('rand'); $r = q("select channel_address from channel where channel_r_stream = 1 and channel_address != 'sys' order by {$rand} limit 1"); $x = z_root() . '/channel/' . $r[0]['channel_address']; } else { $x = z_root() . '/' . $x; } goaway(zid($x)); } //If nothing is set return $o; }
function custom_home_home(&$a, &$o) { $x = get_config('system', 'custom_home'); if ($x) { if ($x == "random") { $rand = db_getfunc('rand'); $r = q("select channel_address from channel left join pconfig on channel_id = pconfig.uid where pconfig.cat = 'perm_limits' and pconfig.k = 'view_stream' and pconfig.v = 1 and channel_address != 'sys' order by {$rand} limit 1"); $x = z_root() . '/channel/' . $r[0]['channel_address']; } else { $x = z_root() . '/' . $x; } goaway(zid($x)); } //If nothing is set return $o; }
function init() { $start = $_REQUEST['start'] ? intval($_REQUEST['start']) : 0; $limit = intval($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 30; $order = $_REQUEST['order'] ? $_REQUEST['order'] : 'random'; $open = $_REQUEST['open'] ? intval($_REQUEST['open']) : false; $sql_order = " order by site_url "; $rand = db_getfunc('rand'); if ($order == 'random') { $sql_order = " order by {$rand} "; } $sql_limit = " LIMIT {$limit} OFFSET {$start} "; $sql_extra = ""; if ($open) { $sql_extra = " and site_register = " . intval(REGISTER_OPEN) . " "; } $realm = get_directory_realm(); if ($realm == DIRECTORY_REALM) { $sql_extra .= " and ( site_realm = '" . dbesc($realm) . "' or site_realm = '') "; } else { $sql_extra .= " and site_realm = '" . dbesc($realm) . "' "; } $result = array('success' => false); $r = q("select count(site_url) as total from site where site_type = %d {$sql_extra} ", intval(SITE_TYPE_ZOT)); if ($r) { $result['total'] = intval($r[0]['total']); } $result['start'] = $start; $result['limit'] = $limit; $r = q("select * from site where site_type = %d {$sql_extra} {$sql_order} {$sql_limit}", intval(SITE_TYPE_ZOT)); $result['results'] = 0; $result['entries'] = array(); if ($r) { $result['success'] = true; $result['results'] = count($r); foreach ($r as $rr) { $result['entries'][] = array('url' => $rr['site_url']); } } echo json_encode($result); killme(); }
function connect_post(&$a) { if (!array_key_exists('channel', App::$data)) { return; } $edit = local_channel() && local_channel() == App::$data['channel']['channel_id'] ? true : false; if ($edit) { $has_premium = App::$data['channel']['channel_pageflags'] & PAGE_PREMIUM ? 1 : 0; $premium = $_POST['premium'] ? intval($_POST['premium']) : 0; $text = escape_tags($_POST['text']); if ($has_premium != $premium) { $r = q("update channel set channel_pageflags = ( channel_pageflags %s %d ) where channel_id = %d", db_getfunc('^'), intval(PAGE_PREMIUM), intval(local_channel())); proc_run('php', 'include/notifier.php', 'refresh_all', App::$data['channel']['channel_id']); } set_pconfig(App::$data['channel']['channel_id'], 'system', 'selltext', $text); // reload the page completely to get fresh data goaway(z_root() . '/' . App::$query_string); } $url = ''; $observer = App::get_observer(); if ($observer && $_POST['submit'] === t('Continue')) { if ($observer['xchan_follow']) { $url = sprintf($observer['xchan_follow'], urlencode(App::$data['channel']['channel_address'] . '@' . App::get_hostname())); } if (!$url) { $r = q("select * from hubloc where hubloc_hash = '%s' order by hubloc_id desc limit 1", dbesc($observer['xchan_hash'])); if ($r) { $url = $r[0]['hubloc_url'] . '/follow?f=&url=' . urlencode(App::$data['channel']['channel_address'] . '@' . App::get_hostname()); } } } if ($url) { goaway($url . '&confirm=1'); } else { notice('Unable to connect to your home hub location.'); } }
function poller_run($argv, $argc) { cli_startup(); $a = get_app(); $maxsysload = intval(get_config('system', 'maxloadavg')); if ($maxsysload < 1) { $maxsysload = 50; } if (function_exists('sys_getloadavg')) { $load = sys_getloadavg(); if (intval($load[0]) > $maxsysload) { logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.'); return; } } $interval = intval(get_config('system', 'poll_interval')); if (!$interval) { $interval = get_config('system', 'delivery_interval') === false ? 3 : intval(get_config('system', 'delivery_interval')); } // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; if (file_exists($lockfile) && filemtime($lockfile) > time() - 3600 && !get_config('system', 'override_poll_lockfile')) { logger("poller: Already running"); return; } // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. file_put_contents($lockfile, $x); logger('poller: start'); // run queue delivery process in the background proc_run('php', "include/queue.php"); // maintenance for mod sharedwithme - check for updated items and remove them require_once 'include/sharedwithme.php'; apply_updates(); // expire any expired mail q("delete from mail where expires != '%s' and expires < %s ", dbesc(NULL_DATE), db_utcnow()); // expire any expired items $r = q("select id from item where expires != '%s' and expires < %s \n\t\tand item_deleted = 0 ", dbesc(NULL_DATE), db_utcnow()); if ($r) { require_once 'include/items.php'; foreach ($r as $rr) { drop_item($rr['id'], false); } } // Ensure that every channel pings a directory server once a month. This way we can discover // channels and sites that quietly vanished and prevent the directory from accumulating stale // or dead entries. $r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('30 DAY')); if ($r) { foreach ($r as $rr) { proc_run('php', 'include/directory.php', $rr['channel_id'], 'force'); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } } // publish any applicable items that were set to be published in the future // (time travel posts). Restrict to items that have come of age in the last // couple of days to limit the query to something reasonable. $r = q("select id from item where item_delayed = 1 and created <= %s and created > '%s' ", db_utcnow(), dbesc(datetime_convert('UTC', 'UTC', 'now - 2 days'))); if ($r) { foreach ($r as $rr) { $x = q("update item set item_delayed = 0 where id = %d", intval($rr['id'])); if ($x) { proc_run('php', 'include/notifier.php', 'wall-new', $rr['id']); } } } $abandon_days = intval(get_config('system', 'account_abandon_days')); if ($abandon_days < 1) { $abandon_days = 0; } // once daily run birthday_updates and then expire in background // FIXME: add birthday updates, both locally and for xprof for use // by directory servers $d1 = intval(get_config('system', 'last_expire_day')); $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd')); // Allow somebody to staggger daily activities if they have more than one site on their server, // or if it happens at an inconvenient (busy) hour. $h1 = intval(get_config('system', 'cron_hour')); $h2 = intval(datetime_convert('UTC', 'UTC', 'now', 'G')); $dirmode = get_config('system', 'directory_mode'); /** * Cron Daily * * Actions in the following block are executed once per day, not on every poller run * */ if ($d2 != $d1 && $h1 == $h2) { require_once 'include/dir_fns.php'; check_upstream_directory(); call_hooks('cron_daily', datetime_convert()); $d3 = intval(datetime_convert('UTC', 'UTC', 'now', 'N')); if ($d3 == 7) { /** * Cron Weekly * * Actions in the following block are executed once per day only on Sunday (once per week). * */ call_hooks('cron_weekly', datetime_convert()); z_check_cert(); require_once 'include/hubloc.php'; prune_hub_reinstalls(); require_once 'include/Contact.php'; mark_orphan_hubsxchans(); // get rid of really old poco records q("delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ", db_utcnow(), db_quoteinterval('14 DAY')); $dirmode = intval(get_config('system', 'directory_mode')); if ($dirmode === DIRECTORY_MODE_SECONDARY || $dirmode === DIRECTORY_MODE_PRIMARY) { logger('regdir: ' . print_r(z_fetch_url(get_directory_primary() . '/regdir?f=&url=' . urlencode(z_root()) . '&realm=' . urlencode(get_directory_realm())), true)); } // Check for dead sites proc_run('php', 'include/checksites.php'); // update searchable doc indexes proc_run('php', 'include/importdoc.php'); /** * End Cron Weekly */ } update_birthdays(); //update statistics in config require_once 'include/statistics_fns.php'; update_channels_total_stat(); update_channels_active_halfyear_stat(); update_channels_active_monthly_stat(); update_local_posts_stat(); // expire any read notifications over a month old q("delete from notify where seen = 1 and date < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('30 DAY')); // expire old delivery reports $keep_reports = intval(get_config('system', 'expire_delivery_reports')); if ($keep_reports === 0) { $keep_reports = 30; } q("delete from dreport where dreport_time < %s - INTERVAL %s", db_utcnow(), db_quoteinterval($keep_reports . ' DAY')); // expire any expired accounts downgrade_accounts(); // If this is a directory server, request a sync with an upstream // directory at least once a day, up to once every poll interval. // Pull remote changes and push local changes. // potential issue: how do we keep from creating an endless update loop? if ($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { require_once 'include/dir_fns.php'; sync_directories($dirmode); } set_config('system', 'last_expire_day', $d2); proc_run('php', 'include/expire.php'); proc_run('php', 'include/cli_suggest.php'); require_once 'include/hubloc.php'; remove_obsolete_hublocs(); /** * End Cron Daily */ } // update any photos which didn't get imported properly // This should be rare $r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = '' \n\t\tand xchan_photo_date < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('1 DAY')); if ($r) { require_once 'include/photo/photo_driver.php'; foreach ($r as $rr) { $photos = import_xchan_photo($rr['xchan_photo_l'], $rr['xchan_hash']); $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'\n\t\t\t\twhere xchan_hash = '%s'", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc($photos[3]), dbesc($rr['xchan_hash'])); } } // pull in some public posts if (!get_config('system', 'disable_discover_tab')) { proc_run('php', 'include/externals.php'); } $manual_id = 0; $generation = 0; $force = false; $restart = false; if ($argc > 1 && $argv[1] == 'force') { $force = true; } if ($argc > 1 && $argv[1] == 'restart') { $restart = true; $generation = intval($argv[2]); if (!$generation) { killme(); } } if ($argc > 1 && intval($argv[1])) { $manual_id = intval($argv[1]); $force = true; } $sql_extra = $manual_id ? " AND abook_id = " . intval($manual_id) . " " : ""; reload_plugins(); $d = datetime_convert(); // TODO check to see if there are any cronhooks before wasting a process if (!$restart) { proc_run('php', 'include/cronhooks.php'); } // Only poll from those with suitable relationships $abandon_sql = $abandon_days ? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days) . ' DAY')) : ''; $randfunc = db_getfunc('RAND'); $contacts = q("SELECT * FROM abook LEFT JOIN xchan on abook_xchan = xchan_hash \n\t\tLEFT JOIN account on abook_account = account_id\n\t\twhere abook_self = 0\n\t\t{$sql_extra} \n\t\tAND (( account_flags = %d ) OR ( account_flags = %d )) {$abandon_sql} ORDER BY {$randfunc}", intval(ACCOUNT_OK), intval(ACCOUNT_UNVERIFIED)); if ($contacts) { foreach ($contacts as $contact) { $update = false; $t = $contact['abook_updated']; $c = $contact['abook_connected']; if (intval($contact['abook_feed'])) { $min = service_class_fetch($contact['abook_channel'], 'minimum_feedcheck_minutes'); if (!$min) { $min = intval(get_config('system', 'minimum_feedcheck_minutes')); } if (!$min) { $min = 60; } $x = datetime_convert('UTC', 'UTC', "now - {$min} minutes"); if ($c < $x) { proc_run('php', 'include/onepoll.php', $contact['abook_id']); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } continue; } if ($contact['xchan_network'] !== 'zot') { continue; } if ($c == $t) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { $update = true; } } else { // if we've never connected with them, start the mark for death countdown from now if ($c == NULL_DATE) { $r = q("update abook set abook_connected = '%s' where abook_id = %d", dbesc(datetime_convert()), intval($contact['abook_id'])); $c = datetime_convert(); $update = true; } // He's dead, Jim if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 30 day")) > 0) { $r = q("update abook set abook_archived = 1 where abook_id = %d", intval($contact['abook_id'])); $update = false; continue; } if (intval($contact['abook_archived'])) { $update = false; continue; } // might be dead, so maybe don't poll quite so often // recently deceased, so keep up the regular schedule for 3 days if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 3 day")) > 0 && strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 1 day")) > 0) { $update = true; } // After that back off and put them on a morphine drip if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 2 day")) > 0) { $update = true; } } if (intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked'])) { continue; } if (!$update && !$force) { continue; } proc_run('php', 'include/onepoll.php', $contact['abook_id']); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } } if ($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { $r = q("SELECT u.ud_addr, u.ud_id, u.ud_last FROM updates AS u INNER JOIN (SELECT ud_addr, max(ud_id) AS ud_id FROM updates WHERE ( ud_flags & %d ) = 0 AND ud_addr != '' AND ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) GROUP BY ud_addr) AS s ON s.ud_id = u.ud_id ", intval(UPDATE_FLAGS_UPDATED), dbesc(NULL_DATE), db_utcnow(), db_quoteinterval('7 DAY')); if ($r) { foreach ($r as $rr) { // If they didn't respond when we attempted before, back off to once a day // After 7 days we won't bother anymore if ($rr['ud_last'] != NULL_DATE) { if ($rr['ud_last'] > datetime_convert('UTC', 'UTC', 'now - 1 day')) { continue; } } proc_run('php', 'include/onedirsync.php', $rr['ud_id']); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } } } set_config('system', 'lastpoll', datetime_convert()); //All done - clear the lockfile @unlink($lockfile); return; }
function contact_block() { $o = ''; $a = get_app(); if (!$a->profile['uid']) { return; } if (!perm_is_allowed($a->profile['uid'], get_observer_hash(), 'view_contacts')) { return; } $shown = get_pconfig($a->profile['uid'], 'system', 'display_friend_count'); if ($shown === false) { $shown = 25; } if ($shown == 0) { return; } $is_owner = local_channel() && local_channel() == $a->profile['uid'] ? true : false; $sql_extra = ''; $abook_flags = " and abook_pending = 0 and abook_self = 0 "; if (!$is_owner) { $abook_flags .= " and abook_hidden = 0 "; $sql_extra = " and xchan_hidden = 0 "; } if (!is_array($a->profile) || $a->profile['hide_friends']) { return $o; } $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d\n\t\t{$abook_flags} and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra}", intval($a->profile['uid'])); if (count($r)) { $total = intval($r[0]['total']); } if (!$total) { $contacts = t('No connections'); $micropro = null; } else { $randfunc = db_getfunc('RAND'); $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d {$abook_flags} and abook_archived = 0 and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra} ORDER BY {$randfunc} LIMIT %d", intval($a->profile['uid']), intval($shown)); if (count($r)) { $contacts = sprintf(tt('%d Connection', '%d Connections', $total), $total); $micropro = array(); foreach ($r as $rr) { $rr['archived'] = intval($rr['abook_archived']) ? true : false; $micropro[] = micropro($rr, true, 'mpfriend'); } } } $tpl = get_markup_template('contact_block.tpl'); $o = replace_macros($tpl, array('$contacts' => $contacts, '$nickname' => $a->profile['channel_address'], '$viewconnections' => t('View Connections'), '$micropro' => $micropro)); $arr = array('contacts' => $r, 'output' => $o); call_hooks('contact_block_end', $arr); return $o; }
function random_profile() { $randfunc = db_getfunc('rand'); $checkrandom = get_config('randprofile', 'check'); // False by default $retryrandom = intval(get_config('randprofile', 'retry')); if ($retryrandom == 0) { $retryrandom = 5; } for ($i = 0; $i < $retryrandom; $i++) { $r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_connected > %s - interval %s order by {$randfunc} limit 1", db_utcnow(), db_quoteinterval('30 day')); if (!$r) { return ''; } // Couldn't get a random channel if ($checkrandom) { $x = z_fetch_url($r[0]['xchan_url']); if ($x['success']) { return $r[0]['xchan_url']; } else { logger('Random channel turned out to be bad.'); } } else { return $r[0]['xchan_url']; } } return ''; }
function list_public_sites() { $rand = db_getfunc('rand'); $realm = get_directory_realm(); if ($realm == DIRECTORY_REALM) { $r = q("select * from site where site_access != 0 and site_register !=0 and ( site_realm = '%s' or site_realm = '') and site_type = %d order by {$rand}", dbesc($realm), intval(SITE_TYPE_ZOT)); } else { $r = q("select * from site where site_access != 0 and site_register !=0 and site_realm = '%s' and site_type = %d order by {$rand}", dbesc($realm), intval(SITE_TYPE_ZOT)); } $ret = array('success' => false); if ($r) { $ret['success'] = true; $ret['sites'] = array(); $insecure = array(); foreach ($r as $rr) { if ($rr['site_access'] == ACCESS_FREE) { $access = 'free'; } elseif ($rr['site_access'] == ACCESS_PAID) { $access = 'paid'; } elseif ($rr['site_access'] == ACCESS_TIERED) { $access = 'tiered'; } else { $access = 'private'; } if ($rr['site_register'] == REGISTER_OPEN) { $register = 'open'; } elseif ($rr['site_register'] == REGISTER_APPROVE) { $register = 'approve'; } else { $register = 'closed'; } if (strpos($rr['site_url'], 'https://') !== false) { $ret['sites'][] = array('url' => $rr['site_url'], 'access' => $access, 'register' => $register, 'sellpage' => $rr['site_sellpage'], 'location' => $rr['site_location'], 'project' => $rr['site_project']); } else { $insecure[] = array('url' => $rr['site_url'], 'access' => $access, 'register' => $register, 'sellpage' => $rr['site_sellpage'], 'location' => $rr['site_location'], 'project' => $rr['site_project']); } } if ($insecure) { $ret['sites'] = array_merge($ret['sites'], $insecure); } } return $ret; }
function jappixmini_cron(&$a, $d) { require_once 'include/Contact.php'; // For autosubscribe/autoapprove, we need to maintain a list of jabber addresses of our contacts. set_config("jappixmini", "last_cron_execution", $d); // go through list of users with jabber enabled $users = q("SELECT uid FROM pconfig WHERE cat = 'jappixmini' AND ( k = 'autosubscribe' OR k = 'autoapprove') AND v = '1' group by uid "); logger("jappixmini: Update list of contacts' jabber accounts for " . count($users) . " users."); if (!count($users)) { return; } foreach ($users as $row) { $uid = $row["uid"]; // for each user, go through list of contacts $rand = db_getfunc('rand'); $contacts = q("SELECT * FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel`=%d AND not (abook_flags & %d) > 0 order by {$rand}", intval($uid), intval(ABOOK_FLAG_SELF)); $channel = channelx_by_n($uid); if (!$channel || !$contacts) { continue; } foreach ($contacts as $contact_row) { $xchan_hash = $contact_row["abook_xchan"]; $pubkey = $contact_row["xchan_pubkey"]; // check if jabber address already present $present = get_pconfig($uid, "jappixmini", "id:" . $xchan_hash); $now = intval(time()); if ($present) { // $present has format "timestamp:jabber_address" $p = strpos($present, ":"); $timestamp = intval(substr($present, 0, $p)); // do not re-retrieve jabber address if last retrieval // is not older than a week if ($now - $timestamp < 3600 * 24 * 7) { continue; } } logger('jappixmini: checking ' . $contact_row['xchan_name'] . ' for channel ' . $channel['channel_name']); // construct base retrieval address $pos = strpos($contact_row['xchan_connurl'], "/poco/"); if ($pos === false) { continue; } $url = substr($contact_row['xchan_connurl'], 0, $pos) . "/jappixmini?f="; // construct own address $username = get_pconfig($uid, 'jappixmini', 'username'); if (!$username) { continue; } $server = get_pconfig($uid, 'jappixmini', 'server'); if (!$server) { continue; } $address = $username . "@" . $server; // sign address $signed_address = ""; openssl_private_encrypt($address, $signed_address, $channel['channel_prvkey']); // construct request url $signed_address_hex = base64url_encode($signed_address); $postvars = array('address' => $signed_address, 'requestor' => $channel['xchan_hash'], 'requestee' => $contact_row['xchan_hash']); try { // send request $answer_json = z_post_url($url, $postvars); logger('jappixmini: url response: ' . print_r($answer_json, true)); if (!$answer_json['success']) { logger('jappixmini: failed z_post_url ' . $url); throw new Exception(); } if ($answer_json['return_code'] == 404) { logger('jappixmini: failed z_post_url (404)' . $url); throw new Exception(); } // parse answer $answer = json_decode($answer_json['body'], true); if ($answer['status'] != "ok") { throw new Exception(); } $address = base64url_decode($answer['address']); if (!$address) { throw new Exception(); } // decrypt address $decrypted_address = ""; openssl_public_decrypt($address, $decrypted_address, $pubkey); if (!$decrypted_address) { throw new Exception(); } } catch (Exception $e) { $decrypted_address = ""; } // save address set_pconfig($uid, "jappixmini", "id:" . $xchan_hash, "{$now}:{$decrypted_address}"); } } }
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; }
function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0) { $perms = is_null($perms) ? PERMS_SITE | PERMS_NETWORK | PERMS_PUBLIC : $perms; $ret = array(); $limit_sql = $limit ? " LIMIT " . intval($limit) . " " : ''; $random_sql = $rand ? " ORDER BY " . db_getfunc('RAND') . " " : ''; if (local_channel()) { $ret[] = local_channel(); } $r = q("select channel_id from channel where channel_r_stream > 0 and ( channel_r_stream & %d )>0 and ( channel_pageflags & %d ) = 0 {$random_sql} {$limit_sql} ", intval($perms), intval(PAGE_ADULT | PAGE_CENSORED | PAGE_SYSTEM | PAGE_REMOVED)); if ($r) { foreach ($r as $rr) { if (!in_array($rr['channel_id'], $ret)) { $ret[] = $rr['channel_id']; } } } $str = ''; if ($ret) { foreach ($ret as $rr) { if ($str) { $str .= ','; } $str .= intval($rr); } } else { $str = "''"; } logger('stream_perms_api_uids: ' . $str, LOGGER_DEBUG); return $str; }
function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0) { $perms = is_null($perms) ? PERMS_SITE | PERMS_NETWORK | PERMS_PUBLIC : $perms; $ret = array(); $limit_sql = $limit ? " LIMIT " . intval($limit) . " " : ''; $random_sql = $rand ? " ORDER BY " . db_getfunc('RAND') . " " : ''; if (local_channel()) { $ret[] = local_channel(); } $x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' and ( v & %d ) > 0 ", intval($perms)); if ($x) { $ids = ids_to_querystr($x, 'uid'); $r = q("select channel_id from channel where channel_id in ( {$ids} ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 {$random_sql} {$limit_sql} ", intval(PAGE_ADULT | PAGE_CENSORED)); if ($r) { foreach ($r as $rr) { if (!in_array($rr['channel_id'], $ret)) { $ret[] = $rr['channel_id']; } } } } $str = ''; if ($ret) { foreach ($ret as $rr) { if ($str) { $str .= ','; } $str .= intval($rr); } } else { $str = "''"; } logger('stream_perms_api_uids: ' . $str, LOGGER_DEBUG); return $str; }
function common_friends($uid, $xchan, $start = 0, $limit = 100000000, $shuffle = false) { $rand = db_getfunc('rand'); if ($shuffle) { $sql_extra = " order by {$rand} "; } else { $sql_extra = " order by xchan_name asc "; } $r = q("SELECT * from xchan left join xlink on xlink_link = xchan_hash where xlink_xchan = '%s' and xlink_static = 0 and xlink_link in\n\t\t(select abook_xchan from abook where abook_xchan != '%s' and abook_channel = %d and abook_self = 0 ) {$sql_extra} limit %d offset %d", dbesc($xchan), dbesc($xchan), intval($uid), intval($limit), intval($start)); return $r; }
function externals_run($argv, $argc) { cli_startup(); $a = get_app(); $total = 0; $attempts = 0; logger('externals: startup', LOGGER_DEBUG); // pull in some public posts while ($total == 0 && $attempts < 3) { $arr = array('url' => ''); call_hooks('externals_url_select', $arr); if ($arr['url']) { $url = $arr['url']; } else { $randfunc = db_getfunc('RAND'); $r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d order by {$randfunc} limit 1", dbesc(z_root()), intval(DIRECTORY_MODE_STANDALONE)); if ($r) { $url = $r[0]['site_url']; } } // Note: blacklisted sites must be stored in the config as an array. // No simple way to turn this into a personal config because we have no identity here. // For that we probably need a variant of superblock. $blacklisted = false; $bl1 = get_config('system', 'blacklisted_sites'); if (is_array($bl1) && $bl1) { foreach ($bl1 as $bl) { if ($bl && strpos($url, $bl) !== false) { $blacklisted = true; break; } } } $attempts++; // make sure we can eventually break out if somebody blacklists all known sites if ($blacklisted) { if ($attempts > 20) { break; } $attempts--; continue; } if ($url) { if ($r[0]['site_pull'] !== NULL_DATE) { $mindate = urlencode(datetime_convert('', '', $r[0]['site_pull'] . ' - 1 day')); } else { $days = get_config('externals', 'since_days'); if ($days === false) { $days = 15; } $mindate = urlencode(datetime_convert('', '', 'now - ' . intval($days) . ' days')); } $feedurl = $url . '/zotfeed?f=&mindate=' . $mindate; logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG); $x = z_fetch_url($feedurl); if ($x && $x['success']) { q("update site set site_pull = '%s' where site_url = '%s'", dbesc(datetime_convert()), dbesc($url)); $j = json_decode($x['body'], true); if ($j['success'] && $j['messages']) { $sys = get_sys_channel(); foreach ($j['messages'] as $message) { // on these posts, clear any route info. $message['route'] = ''; $results = process_delivery(array('hash' => 'undefined'), get_item_elements($message), array(array('hash' => $sys['xchan_hash'])), false, true); $total++; // $z = q("select id from item where mid = '%s' and uid = %d limit 1", // dbesc($message['message_id']), // intval($sys['channel_id']) // ); $z = null; if ($z) { $flag_bits = ITEM_WALL | ITEM_ORIGIN | ITEM_UPLINK; // preserve the source $r = q("update item set source_xchan = owner_xchan where id = %d", intval($z[0]['id'])); $r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s' \n\t\t\t\t\t\t\t\twhere id = %d", intval($flag_bits), dbesc($sys['xchan_hash']), intval($z[0]['id'])); } } logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG); } } } } }
/** * @brief Checks for accounts that have past their expiration date. * * If the account has a service class which is not the site default, * the service class is reset to the site default and expiration reset to never. * If the account has no service class it is expired and subsequently disabled. * called from include/poller.php as a scheduled task. * * Reclaiming resources which are no longer within the service class limits is * not the job of this function, but this can be implemented by plugin if desired. * Default behaviour is to stop allowing additional resources to be consumed. */ function downgrade_accounts() { $r = q("select * from account where not ( account_flags & %d )>0 \n\t\tand account_expires != '%s' \n\t\tand account_expires < %s ", intval(ACCOUNT_EXPIRED), dbesc(NULL_DATE), db_getfunc('UTC_TIMESTAMP')); if (!$r) { return; } $basic = get_config('system', 'default_service_class'); foreach ($r as $rr) { if ($basic && $rr['account_service_class'] && $rr['account_service_class'] != $basic) { $x = q("UPDATE account set account_service_class = '%s', account_expires = '%s'\n\t\t\t\twhere account_id = %d", dbesc($basic), dbesc(NULL_DATE), intval($rr['account_id'])); $ret = array('account' => $rr); call_hooks('account_downgrade', $ret); logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' downgraded.'); } else { $x = q("UPDATE account SET account_flags = (account_flags | %d) where account_id = %d", intval(ACCOUNT_EXPIRED), intval($rr['account_id'])); $ret = array('account' => $rr); call_hooks('account_downgrade', $ret); logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' expired.'); } } }
function statusnet_cron($a, $b) { $last = get_config('statusnet', 'last_poll'); $poll_interval = intval(get_config('statusnet', 'poll_interval')); if (!$poll_interval) { $poll_interval = STATUSNET_DEFAULT_POLL_INTERVAL; } if ($last) { $next = $last + $poll_interval * 60; if ($next > time()) { logger('statusnet: poll intervall not reached'); return; } } logger('statusnet: cron_start', LOGGER_DEBUG); $rand = db_getfunc('rand'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY {$rand} "); if (count($r)) { foreach ($r as $rr) { logger('statusnet: fetching for user ' . $rr['uid']); statusnet_fetchtimeline($a, $rr['uid']); } } logger('statusnet: cron_end', LOGGER_DEBUG); set_config('statusnet', 'last_poll', time()); }
public static function run($argc, $argv) { $maxsysload = intval(get_config('system', 'maxloadavg')); if ($maxsysload < 1) { $maxsysload = 50; } if (function_exists('sys_getloadavg')) { $load = sys_getloadavg(); if (intval($load[0]) > $maxsysload) { logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.'); return; } } $interval = intval(get_config('system', 'poll_interval')); if (!$interval) { $interval = get_config('system', 'delivery_interval') === false ? 3 : intval(get_config('system', 'delivery_interval')); } // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; if (file_exists($lockfile) && filemtime($lockfile) > time() - 3600 && !get_config('system', 'override_poll_lockfile')) { logger("poller: Already running"); return; } // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. file_put_contents($lockfile, $x); logger('poller: start'); $manual_id = 0; $generation = 0; $force = false; $restart = false; if ($argc > 1 && $argv[1] == 'force') { $force = true; } if ($argc > 1 && $argv[1] == 'restart') { $restart = true; $generation = intval($argv[2]); if (!$generation) { killme(); } } if ($argc > 1 && intval($argv[1])) { $manual_id = intval($argv[1]); $force = true; } $sql_extra = $manual_id ? " AND abook_id = " . intval($manual_id) . " " : ""; reload_plugins(); $d = datetime_convert(); // Only poll from those with suitable relationships $abandon_sql = $abandon_days ? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days) . ' DAY')) : ''; $randfunc = db_getfunc('RAND'); $contacts = q("SELECT * FROM abook LEFT JOIN xchan on abook_xchan = xchan_hash \n\t\t\tLEFT JOIN account on abook_account = account_id\n\t\t\twhere abook_self = 0\n\t\t\t{$sql_extra} \n\t\t\tAND (( account_flags = %d ) OR ( account_flags = %d )) {$abandon_sql} ORDER BY {$randfunc}", intval(ACCOUNT_OK), intval(ACCOUNT_UNVERIFIED)); if ($contacts) { foreach ($contacts as $contact) { $update = false; $t = $contact['abook_updated']; $c = $contact['abook_connected']; if (intval($contact['abook_feed'])) { $min = service_class_fetch($contact['abook_channel'], 'minimum_feedcheck_minutes'); if (!$min) { $min = intval(get_config('system', 'minimum_feedcheck_minutes')); } if (!$min) { $min = 60; } $x = datetime_convert('UTC', 'UTC', "now - {$min} minutes"); if ($c < $x) { Master::Summon(array('Onepoll', $contact['abook_id'])); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } continue; } if ($contact['xchan_network'] !== 'zot') { continue; } if ($c == $t) { if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { $update = true; } } else { // if we've never connected with them, start the mark for death countdown from now if ($c == NULL_DATE) { $r = q("update abook set abook_connected = '%s' where abook_id = %d", dbesc(datetime_convert()), intval($contact['abook_id'])); $c = datetime_convert(); $update = true; } // He's dead, Jim if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 30 day")) > 0) { $r = q("update abook set abook_archived = 1 where abook_id = %d", intval($contact['abook_id'])); $update = false; continue; } if (intval($contact['abook_archived'])) { $update = false; continue; } // might be dead, so maybe don't poll quite so often // recently deceased, so keep up the regular schedule for 3 days if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 3 day")) > 0 && strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 1 day")) > 0) { $update = true; } // After that back off and put them on a morphine drip if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 2 day")) > 0) { $update = true; } } if (intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked'])) { continue; } if (!$update && !$force) { continue; } Master::Summon(array('Onepoll', $contact['abook_id'])); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } } if ($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { $r = q("SELECT u.ud_addr, u.ud_id, u.ud_last FROM updates AS u INNER JOIN (SELECT ud_addr, max(ud_id) AS ud_id FROM updates WHERE ( ud_flags & %d ) = 0 AND ud_addr != '' AND ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) GROUP BY ud_addr) AS s ON s.ud_id = u.ud_id ", intval(UPDATE_FLAGS_UPDATED), dbesc(NULL_DATE), db_utcnow(), db_quoteinterval('7 DAY')); if ($r) { foreach ($r as $rr) { // If they didn't respond when we attempted before, back off to once a day // After 7 days we won't bother anymore if ($rr['ud_last'] != NULL_DATE) { if ($rr['ud_last'] > datetime_convert('UTC', 'UTC', 'now - 1 day')) { continue; } } Master::Summon(array('Onedirsync', $rr['ud_id'])); if ($interval) { @time_sleep_until(microtime(true) + (double) $interval); } } } } set_config('system', 'lastpoll', datetime_convert()); //All done - clear the lockfile @unlink($lockfile); return; }
function externals_run($argv, $argc) { cli_startup(); $a = get_app(); $total = 0; $attempts = 0; logger('externals: startup', LOGGER_DEBUG); // pull in some public posts while ($total == 0 && $attempts < 3) { $arr = array('url' => ''); call_hooks('externals_url_select', $arr); if ($arr['url']) { $url = $arr['url']; } else { $randfunc = db_getfunc('RAND'); // fixme this query does not deal with directory realms. $r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d and site_dead = 0 order by {$randfunc} limit 1", dbesc(z_root()), intval(DIRECTORY_MODE_STANDALONE), intval(SITE_TYPE_ZOT)); if ($r) { $url = $r[0]['site_url']; } } $blacklisted = false; if (!check_siteallowed($url)) { logger('blacklisted site: ' . $url); $blacklisted = true; } $attempts++; // make sure we can eventually break out if somebody blacklists all known sites if ($blacklisted) { if ($attempts > 20) { break; } $attempts--; continue; } if ($url) { if ($r[0]['site_pull'] !== NULL_DATE) { $mindate = urlencode(datetime_convert('', '', $r[0]['site_pull'] . ' - 1 day')); } else { $days = get_config('externals', 'since_days'); if ($days === false) { $days = 15; } $mindate = urlencode(datetime_convert('', '', 'now - ' . intval($days) . ' days')); } $feedurl = $url . '/zotfeed?f=&mindate=' . $mindate; logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG); $x = z_fetch_url($feedurl); if ($x && $x['success']) { q("update site set site_pull = '%s' where site_url = '%s'", dbesc(datetime_convert()), dbesc($url)); $j = json_decode($x['body'], true); if ($j['success'] && $j['messages']) { $sys = get_sys_channel(); foreach ($j['messages'] as $message) { // on these posts, clear any route info. $message['route'] = ''; $results = process_delivery(array('hash' => 'undefined'), get_item_elements($message), array(array('hash' => $sys['xchan_hash'])), false, true); $total++; } logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG); } } } } }
function widget_random_block($arr) { $channel_id = 0; if (array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) { $channel_id = intval($arr['channel_id']); } if (!$channel_id) { $channel_id = get_app()->profile_uid; } if (!$channel_id) { return ''; } if (array_key_exists('contains', $arr)) { $contains = $arr['contains']; } $o = ''; require_once 'include/security.php'; $sql_options = item_permissions_sql($channel_id); $randfunc = db_getfunc('RAND'); $r = q("select item.* from item left join item_id on item.id = item_id.iid\n\t\twhere item.uid = %d and sid like '%s' and service = 'BUILDBLOCK' and \n\t\titem_type = %d {$sql_options} order by {$randfunc} limit 1", intval($channel_id), dbesc('%' . $contains . '%'), intval(ITEM_TYPE_BLOCK)); if ($r) { $o = '<div class="widget bblock">'; if ($r[0]['title']) { $o .= '<h3>' . $r[0]['title'] . '</h3>'; } $o .= prepare_text($r[0]['body'], $r[0]['mimetype']); $o .= '</div>'; } return $o; }
function search_doc_files($s) { $itemspage = get_pconfig(local_channel(), 'system', 'itemspage'); \App::set_pager_itemspage(intval($itemspage) ? $itemspage : 20); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); $regexop = db_getfunc('REGEXP'); $r = q("select iconfig.v, item.* from item left join iconfig on item.id = iconfig.iid \n\t\twhere iconfig.cat = 'system' and iconfig.k = 'docfile' and\n\t\tbody {$regexop} '%s' and item_type = %d {$pager_sql}", dbesc($s), intval(ITEM_TYPE_DOC)); $r = fetch_post_tags($r, true); for ($x = 0; $x < count($r); $x++) { $position = stripos($r[$x]['body'], $s); $dislen = 300; $start = $position - floor($dislen / 2); if ($start < 0) { $start = 0; } $r[$x]['text'] = substr($r[$x]['body'], $start, $dislen); $r[$x]['rank'] = 0; if ($r[$x]['term']) { foreach ($r[$x]['term'] as $t) { if (stristr($t['term'], $s)) { $r[$x]['rank']++; } } } if (stristr($r[$x]['v'], $s)) { $r[$x]['rank']++; } $r[$x]['rank'] += substr_count(strtolower($r[$x]['text']), strtolower($s)); // bias the results to the observer's native language if ($r[$x]['lang'] === \App::$language) { $r[$x]['rank'] = $r[$x]['rank'] + 10; } } usort($r, 'doc_rank_sort'); return $r; }
function contact_block() { $o = ''; $a = get_app(); if (!$a->profile['uid']) { return; } if (!perm_is_allowed($a->profile['uid'], get_observer_hash(), 'view_contacts')) { return; } $shown = get_pconfig($a->profile['uid'], 'system', 'display_friend_count'); if ($shown === false) { $shown = 25; } if ($shown == 0) { return; } $is_owner = local_channel() && local_channel() == $a->profile['uid'] ? true : false; $abook_flags = ABOOK_FLAG_PENDING | ABOOK_FLAG_SELF; $xchan_flags = XCHAN_FLAGS_ORPHAN | XCHAN_FLAGS_DELETED; if (!$is_owner) { $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN; $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN; } if (!is_array($a->profile) || $a->profile['hide_friends']) { return $o; } $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and ( abook_flags & %d ) = 0 and ( xchan_flags & %d ) = 0", intval($a->profile['uid']), intval($abook_flags), intval($xchan_flags)); if (count($r)) { $total = intval($r[0]['total']); } if (!$total) { $contacts = t('No connections'); $micropro = null; } else { $randfunc = db_getfunc('RAND'); $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND ( abook_flags & %d ) = 0 and ( xchan_flags & %d ) = 0 ORDER BY {$randfunc} LIMIT %d", intval($a->profile['uid']), intval($abook_flags | ABOOK_FLAG_ARCHIVED), intval($xchan_flags), intval($shown)); if (count($r)) { $contacts = sprintf(tt('%d Connection', '%d Connections', $total), $total); $micropro = array(); foreach ($r as $rr) { $rr['archived'] = $rr['abook_flags'] & ABOOK_FLAG_ARCHIVED ? true : false; $micropro[] = micropro($rr, true, 'mpfriend'); } } } $tpl = get_markup_template('contact_block.tpl'); $o = replace_macros($tpl, array('$contacts' => $contacts, '$nickname' => $a->profile['channel_address'], '$viewconnections' => t('View Connections'), '$micropro' => $micropro)); $arr = array('contacts' => $r, 'output' => $o); call_hooks('contact_block_end', $arr); return $o; }
/** * @brief Channels admin page. * * @param App &$a */ function admin_page_channels_post(&$a) { $channels = x($_POST, 'channel') ? $_POST['channel'] : array(); check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels'); $xor = db_getfunc('^'); if (x($_POST, 'page_channels_block')) { foreach ($channels as $uid) { q("UPDATE channel SET channel_pageflags = ( channel_pageflags {$xor} %d ) where channel_id = %d", intval(PAGE_CENSORED), intval($uid)); proc_run('php', 'include/directory.php', $uid, 'nopush'); } notice(sprintf(tt("%s channel censored/uncensored", "%s channels censored/uncensored", count($channels)), count($channels))); } if (x($_POST, 'page_channels_code')) { foreach ($channels as $uid) { q("UPDATE channel SET channel_pageflags = ( channel_pageflags {$xor} %d ) where channel_id = %d", intval(PAGE_ALLOWCODE), intval($uid)); } notice(sprintf(tt("%s channel code allowed/disallowed", "%s channels code allowed/disallowed", count($channels)), count($channels))); } if (x($_POST, 'page_channels_delete')) { require_once "include/Contact.php"; foreach ($channels as $uid) { channel_remove($uid, true); } notice(sprintf(tt("%s channel deleted", "%s channels deleted", count($channels)), count($channels))); } goaway(z_root() . '/admin/channels'); }