当前位置: 首页>>代码示例>>PHP>>正文


PHP cli_startup函数代码示例

本文整理汇总了PHP中cli_startup函数的典型用法代码示例。如果您正苦于以下问题:PHP cli_startup函数的具体用法?PHP cli_startup怎么用?PHP cli_startup使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cli_startup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checksites_run

function checksites_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    logger('checksites: start');
    if ($argc > 1 && $argv[1]) {
        $site_id = $argv[1];
    }
    if ($site_id) {
        $sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
    }
    $days = intval(get_config('system', 'sitecheckdays'));
    if ($days < 1) {
        $days = 30;
    }
    $r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d {$sql_options} ", db_utcnow(), db_quoteinterval($days . ' DAY'), intval(SITE_TYPE_ZOT));
    if (!$r) {
        return;
    }
    foreach ($r as $rr) {
        if (!strcasecmp($rr['site_url'], z_root())) {
            continue;
        }
        $x = ping_site($rr['site_url']);
        if ($x['success']) {
            logger('checksites: ' . $rr['site_url']);
            q("update site set site_update = '%s' where site_url = '%s' ", dbesc(datetime_convert()), dbesc($rr['site_url']));
        } else {
            logger('marking dead site: ' . $x['message']);
            q("update site set site_dead = 1 where site_url = '%s' ", dbesc($rr['site_url']));
        }
    }
    return;
}
开发者ID:TamirAl,项目名称:hubzilla,代码行数:34,代码来源:checksites.php

示例2: onedirsync_run

function onedirsync_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    logger('onedirsync: start ' . intval($argv[1]));
    if ($argc > 1 && intval($argv[1])) {
        $update_id = intval($argv[1]);
    }
    if (!$update_id) {
        logger('onedirsync: no update');
        return;
    }
    $r = q("select * from updates where ud_id = %d limit 1", intval($update_id));
    if (!$r) {
        return;
    }
    if ($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED || !$r[0]['ud_addr']) {
        return;
    }
    // Have we probed this channel more recently than the other directory server
    // (where we received this update from) ?
    // If we have, we don't need to do anything except mark any older entries updated
    $x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d ) order by ud_date desc limit 1", dbesc($r[0]['ud_addr']), dbesc($r[0]['ud_date']), intval(UPDATE_FLAGS_UPDATED));
    if ($x) {
        $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not ( ud_flags & %d ) and ud_date < '%s' ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), intval(UPDATE_FLAGS_UPDATED), dbesc($x[0]['ud_date']));
        return;
    }
    update_directory_entry($r[0]);
    return;
}
开发者ID:Mauru,项目名称:red,代码行数:30,代码来源:onedirsync.php

示例3: queue_run

function queue_run($argv, $argc)
{
    cli_startup();
    global $a;
    require_once 'include/items.php';
    require_once 'include/bbcode.php';
    if (argc() > 1) {
        $queue_id = argv(1);
    } else {
        $queue_id = 0;
    }
    logger('queue: start');
    // delete all queue items more than 3 days old
    // but first mark these sites dead if we haven't heard from them in a month
    $r = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('3 DAY'));
    if ($r) {
        foreach ($r as $rr) {
            $site_url = '';
            $h = parse_url($rr['outq_posturl']);
            $desturl = $h['scheme'] . '://' . $h['host'] . ($h['port'] ? ':' . $h['port'] : '');
            q("update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s", dbesc($desturl), db_utcnow(), db_quoteinterval('1 MONTH'));
        }
    }
    $r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('3 DAY'));
    if ($queue_id) {
        $r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1", dbesc($queue_id));
    } else {
        // For the first 12 hours we'll try to deliver every 15 minutes
        // After that, we'll only attempt delivery once per hour.
        // This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
        // so that we don't start off a thousand deliveries for a couple of dead hubs.
        // The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
        // Other drivers will have to do something different here and may need their own query.
        // Note: this requires some tweaking as new posts to long dead hubs once a day will keep them in the
        // "every 15 minutes" category. We probably need to prioritise them when inserted into the queue
        // or just prior to this query based on recent and long-term delivery history. If we have good reason to believe
        // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
        // or twice a day.
        // FIXME: can we sort postgres on outq_priority and maintain the 'distinct' ?
        // The order by max(outq_priority) might be a dodgy query because of the group by.
        // The desired result is to return a sequence in the order most likely to be delivered in this run.
        // If a hub has already been sitting in the queue for a few days, they should be delivered last;
        // hence every failure should drop them further down the priority list.
        if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
            $prefix = 'DISTINCT ON (outq_posturl)';
            $suffix = 'ORDER BY outq_posturl';
        } else {
            $prefix = '';
            $suffix = 'GROUP BY outq_posturl ORDER BY max(outq_priority)';
        }
        $r = q("SELECT {$prefix} * FROM outq WHERE outq_delivered = 0 and (( outq_created > %s - INTERVAL %s and outq_updated < %s - INTERVAL %s ) OR ( outq_updated < %s - INTERVAL %s )) {$suffix}", db_utcnow(), db_quoteinterval('12 HOUR'), db_utcnow(), db_quoteinterval('15 MINUTE'), db_utcnow(), db_quoteinterval('1 HOUR'));
    }
    if (!$r) {
        return;
    }
    foreach ($r as $rr) {
        queue_deliver($rr);
    }
}
开发者ID:TamirAl,项目名称:hubzilla,代码行数:59,代码来源:queue.php

示例4: Release

 public static function Release($argc, $argv)
 {
     cli_startup();
     logger('Master: release: ' . print_r($argv, true), LOGGER_ALL, LOG_DEBUG);
     require_once 'Zotlabs/Daemon/' . $argv[0] . '.php';
     $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
     $cls::run($argc, $argv);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:8,代码来源:Master.php

示例5: cronhooks_run

function cronhooks_run($argv, $argc)
{
    cli_startup();
    logger('cronhooks: start');
    $d = datetime_convert();
    call_hooks('cron', $d);
    return;
}
开发者ID:msooon,项目名称:hubzilla,代码行数:8,代码来源:cronhooks.php

示例6: directory_run

/**
 * @brief
 *
 * @param array $argv
 * @param array $argc
 */
function directory_run($argv, $argc)
{
    cli_startup();
    if ($argc < 2) {
        return;
    }
    $force = false;
    $pushall = true;
    if ($argc > 2) {
        if ($argv[2] === 'force') {
            $force = true;
        }
        if ($argv[2] === 'nopush') {
            $pushall = false;
        }
    }
    logger('directory update', LOGGER_DEBUG);
    $dirmode = get_config('system', 'directory_mode');
    if ($dirmode === false) {
        $dirmode = DIRECTORY_MODE_NORMAL;
    }
    $x = q("select * from channel where channel_id = %d limit 1", intval($argv[1]));
    if (!$x) {
        return;
    }
    $channel = $x[0];
    if ($dirmode != DIRECTORY_MODE_NORMAL) {
        // this is an in-memory update and we don't need to send a network packet.
        local_dir_update($argv[1], $force);
        q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
        // Now update all the connections
        if ($pushall) {
            proc_run('php', 'include/notifier.php', 'refresh_all', $channel['channel_id']);
        }
        return;
    }
    // otherwise send the changes upstream
    $directory = find_upstream_directory($dirmode);
    $url = $directory['url'] . '/post';
    // ensure the upstream directory is updated
    $packet = zot_build_packet($channel, $force ? 'force_refresh' : 'refresh');
    $z = zot_zot($url, $packet);
    // re-queue if unsuccessful
    if (!$z['success']) {
        /** @FIXME we aren't updating channel_dirdate if we have to queue
         * the directory packet. That means we'll try again on the next poll run.
         */
        $hash = random_string();
        q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) \n\t\t\tvalues ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($channel['channel_account_id']), intval($channel['channel_id']), dbesc('zot'), dbesc($url), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($packet), dbesc(''));
    } else {
        q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
    }
    // Now update all the connections
    if ($pushall) {
        proc_run('php', 'include/notifier.php', 'refresh_all', $channel['channel_id']);
    }
}
开发者ID:msooon,项目名称:hubzilla,代码行数:63,代码来源:directory.php

示例7: deliver_hooks_run

function deliver_hooks_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc < 2) {
        return;
    }
    $r = q("select * from item where id = '%d'", intval($argv[1]));
    if ($r) {
        call_hooks('notifier_normal', $r[0]);
    }
}
开发者ID:TamirAl,项目名称:hubzilla,代码行数:12,代码来源:deliver_hooks.php

示例8: queue_run

function queue_run($argv, $argc)
{
    cli_startup();
    global $a;
    require_once 'include/items.php';
    require_once 'include/bbcode.php';
    if (argc() > 1) {
        $queue_id = argv(1);
    } else {
        $queue_id = 0;
    }
    $deadguys = array();
    logger('queue: start');
    $r = q("DELETE FROM outq WHERE outq_created < UTC_TIMESTAMP() - INTERVAL 3 DAY");
    if ($queue_id) {
        $r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1", dbesc($queue_id));
    } else {
        // For the first 12 hours we'll try to deliver every 15 minutes
        // After that, we'll only attempt delivery once per hour.
        // This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
        // so that we don't start off a thousand deliveries for a couple of dead hubs.
        // The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
        // Other drivers will have to do something different here and may need their own query.
        $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and (( outq_created > UTC_TIMESTAMP() - INTERVAL 12 HOUR and outq_updated < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( outq_updated < UTC_TIMESTAMP() - INTERVAL 1 HOUR )) group by outq_posturl");
    }
    if (!$r) {
        return;
    }
    foreach ($r as $rr) {
        if (in_array($rr['outq_posturl'], $deadguys)) {
            continue;
        }
        if ($rr['outq_driver'] === 'post') {
            $result = z_post_url($rr['outq_posturl'], $rr['outq_msg']);
            if ($result['success'] && $result['return_code'] < 300) {
                logger('queue: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG);
                $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($rr['ouq_hash']));
            } else {
                logger('queue: queue post returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'], LOGGER_DEBUG);
                $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($rr['outq_hash']));
            }
            continue;
        }
        $result = zot_zot($rr['outq_posturl'], $rr['outq_notify']);
        if ($result['success']) {
            zot_process_response($rr['outq_posturl'], $result, $rr);
        } else {
            $deadguys[] = $rr['outq_posturl'];
            $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($rr['outq_hash']));
        }
    }
}
开发者ID:Mauru,项目名称:red,代码行数:52,代码来源:queue.php

示例9: deliver_run

function deliver_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc < 2) {
        return;
    }
    logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
    for ($x = 1; $x < $argc; $x++) {
        $dresult = null;
        $r = q("select * from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
        if ($r) {
            $notify = json_decode($r[0]['outq_notify'], true);
            // Messages without an outq_msg will need to go via the web, even if it's a
            // local delivery. This includes conversation requests and refresh packets.
            if ($r[0]['outq_posturl'] === z_root() . '/post' && $r[0]['outq_msg']) {
                logger('deliver: local delivery', LOGGER_DEBUG);
                // local delivery
                // we should probably batch these and save a few delivery processes
                if ($r[0]['outq_msg']) {
                    $m = json_decode($r[0]['outq_msg'], true);
                    if (array_key_exists('message_list', $m)) {
                        foreach ($m['message_list'] as $mm) {
                            $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify, 'message' => $mm)))));
                            zot_import($msg, z_root());
                        }
                    } else {
                        $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify, 'message' => $m)))));
                        $dresult = zot_import($msg, z_root());
                    }
                    remove_queue_item($r[0]['outq_hash']);
                    if ($dresult && is_array($dresult)) {
                        foreach ($dresult as $xx) {
                            if (is_array($xx) && array_key_exists('message_id', $xx)) {
                                if (delivery_report_is_storable($xx)) {
                                    q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", dbesc($xx['message_id']), dbesc($xx['location']), dbesc($xx['recipient']), dbesc($xx['status']), dbesc(datetime_convert($xx['date'])), dbesc($xx['sender']));
                                }
                            }
                        }
                    }
                    q("delete from dreport where dreport_queue = '%s'", dbesc($argv[$x]));
                }
            }
            // otherwise it's a remote delivery - call queue_deliver();
            queue_deliver($r[0], true);
        }
    }
}
开发者ID:TamirAl,项目名称:hubzilla,代码行数:48,代码来源:deliver.php

示例10: gprobe_run

function gprobe_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc != 2) {
        return;
    }
    $url = hex2bin($argv[1]);
    $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($url));
    if (!$r) {
        $x = zot_finger($url, null);
        if ($x['success']) {
            $j = json_decode($x['body'], true);
            $y = import_xchan($j);
        }
    }
    return;
}
开发者ID:redmatrix,项目名称:red,代码行数:18,代码来源:gprobe.php

示例11: deliver_run

function deliver_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc < 2) {
        return;
    }
    logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
    for ($x = 1; $x < $argc; $x++) {
        $r = q("select * from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
        if ($r) {
            if ($r[0]['outq_driver'] === 'post') {
                $result = z_post_url($r[0]['outq_posturl'], $r[0]['outq_msg']);
                if ($result['success'] && $result['return_code'] < 300) {
                    logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
                } else {
                    logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
                continue;
            }
            if ($r[0]['outq_posturl'] === z_root() . '/post') {
                logger('deliver: local delivery', LOGGER_DEBUG);
                // local delivery
                // we should probably batch these and save a few delivery processes
                // If there is no outq_msg, this is a refresh_all message which does not require local handling
                if ($r[0]['outq_msg']) {
                    $msg = array('body' => json_encode(array('pickup' => array(array('notify' => json_decode($r[0]['outq_notify'], true), 'message' => json_decode($r[0]['outq_msg'], true))))));
                    zot_import($msg, z_root());
                    $r = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
                }
            } else {
                logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                $result = zot_zot($r[0]['outq_posturl'], $r[0]['outq_notify']);
                if ($result['success']) {
                    zot_process_response($r[0]['outq_posturl'], $result, $r[0]);
                } else {
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
            }
        }
    }
}
开发者ID:Mauru,项目名称:red,代码行数:44,代码来源:deliver.php

示例12: onedirsync_run

function onedirsync_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    logger('onedirsync: start ' . intval($argv[1]));
    if ($argc > 1 && intval($argv[1])) {
        $update_id = intval($argv[1]);
    }
    if (!$update_id) {
        logger('onedirsync: no update');
        return;
    }
    $r = q("select * from updates where ud_id = %d limit 1", intval($update_id));
    if (!$r) {
        return;
    }
    if ($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED || !$r[0]['ud_addr']) {
        return;
    }
    // Have we probed this channel more recently than the other directory server
    // (where we received this update from) ?
    // If we have, we don't need to do anything except mark any older entries updated
    $x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1", dbesc($r[0]['ud_addr']), dbesc($r[0]['ud_date']), intval(UPDATE_FLAGS_UPDATED));
    if ($x) {
        $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), intval(UPDATE_FLAGS_UPDATED), dbesc($x[0]['ud_date']));
        return;
    }
    // ignore doing an update if this ud_addr refers to a known dead hubloc
    $h = q("select * from hubloc where hubloc_addr = '%s' limit 1", dbesc($r[0]['ud_addr']));
    if ($h && $h[0]['hubloc_status'] & HUBLOC_OFFLINE) {
        $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), intval(UPDATE_FLAGS_UPDATED));
        return;
    }
    // we might have to pull this out some day, but for now update_directory_entry()
    // runs zot_finger() and is kind of zot specific
    if ($h && $h[0]['hubloc_network'] !== 'zot') {
        return;
    }
    update_directory_entry($r[0]);
    return;
}
开发者ID:msooon,项目名称:hubzilla,代码行数:41,代码来源:onedirsync.php

示例13: expire_run

function expire_run($argv, $argc)
{
    cli_startup();
    $r = q("select id from item where (item_restrict & %d) and not (item_restrict & %d) and changed < UTC_TIMESTAMP() - INTERVAL 10 DAY", intval(ITEM_DELETED), intval(ITEM_PENDING_REMOVE));
    if ($r) {
        foreach ($r as $rr) {
            drop_item($rr['id'], false, DROPITEM_PHASE2);
        }
    }
    // physically remove anything that has been deleted for more than two months
    $r = q("delete from item where ( item_restrict & %d ) and changed < UTC_TIMESTAMP() - INTERVAL 36 DAY", intval(ITEM_PENDING_REMOVE));
    // make this optional as it could have a performance impact on large sites
    if (intval(get_config('system', 'optimize_items'))) {
        q("optimize table item");
    }
    logger('expire: start', LOGGER_DEBUG);
    $r = q("SELECT channel_id, channel_address, channel_expire_days from channel where channel_expire_days != 0");
    if ($r && count($r)) {
        foreach ($r as $rr) {
            logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $rr['channel_expire_days'], LOGGER_DEBUG);
            item_expire($rr['channel_id'], $rr['channel_expire_days']);
        }
    }
    $x = get_sys_channel();
    if ($x) {
        // this should probably just fetch the channel_expire_days from the sys channel,
        // but there's no convenient way to set it.
        $expire_days = get_config('externals', 'expire_days');
        if ($expire_days === false) {
            $expire_days = 30;
        }
        if ($expire_days) {
            item_expire($x['channel_id'], $expire_days);
        }
    }
    return;
}
开发者ID:Mauru,项目名称:red,代码行数:37,代码来源:expire.php

示例14: externals_run

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);
                }
            }
        }
    }
}
开发者ID:redmatrix,项目名称:red,代码行数:83,代码来源:externals.php

示例15: externals_run

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);
                }
            }
        }
    }
}
开发者ID:msooon,项目名称:hubzilla,代码行数:65,代码来源:externals.php


注:本文中的cli_startup函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。