• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP z_post_url函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: pumpio_registerclient

function pumpio_registerclient($a, $host)
{
    $url = 'https://' . $host . '/api/client/register';
    $params = array();
    $application_name = get_config('pumpio', 'application_name');
    if (!$application_name) {
        $application_name = $a->get_hostname();
    }
    $params['type'] = 'client_associate';
    $params['contacts'] = get_config('system', 'admin_email');
    $params['application_type'] = 'native';
    $params['application_name'] = $application_name;
    $params['logo_uri'] = z_root() . '/images/rhash-32.png';
    $params['redirect_uris'] = z_root() . '/pumpio/connect';
    $res = z_post_url($url, $params);
    if ($res['success']) {
        logger('pumpio: registerclient: ' . $res['body'], LOGGER_DATA);
        $values = json_decode($res['body'], true);
        $pumpio = array();
        $pumpio["client_id"] = $values['client_id'];
        $pumpio["client_secret"] = $values['client_secret'];
        //print_r($values);
        return $values;
    }
    return false;
}
开发者ID:royalterra,项目名称:hubzilla-addons,代码行数:26,代码来源:pumpio.php


示例2: share_init

function share_init(&$a)
{
    $post_id = argc() > 1 ? intval(argv(1)) : 0;
    if (!$post_id) {
        killme();
    }
    if (!(local_channel() || remote_channel())) {
        killme();
    }
    $r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d  LIMIT 1", intval($post_id));
    if (!$r) {
        killme();
    }
    if ($r[0]['item_private'] && $r[0]['xchan_network'] !== 'rss') {
        killme();
    }
    $sql_extra = item_permissions_sql($r[0]['uid']);
    $r = q("select * from item where id = %d {$sql_extra}", intval($post_id));
    if (!$r) {
        killme();
    }
    /** @FIXME we only share bbcode */
    if ($r[0]['mimetype'] !== 'text/bbcode') {
        killme();
    }
    /** @FIXME eventually we want to post remotely via rpost on your home site */
    // When that works remove this next bit:
    if (!local_channel()) {
        killme();
    }
    xchan_query($r);
    if (strpos($r[0]['body'], "[/share]") !== false) {
        $pos = strpos($r[0]['body'], "[share");
        $o = substr($r[0]['body'], $pos);
    } else {
        $o = "[share author='" . urlencode($r[0]['author']['xchan_name']) . "' profile='" . $r[0]['author']['xchan_url'] . "' avatar='" . $r[0]['author']['xchan_photo_s'] . "' link='" . $r[0]['plink'] . "' posted='" . $r[0]['created'] . "' message_id='" . $r[0]['mid'] . "']";
        if ($r[0]['title']) {
            $o .= '[b]' . $r[0]['title'] . '[/b]' . "\n";
        }
        $o .= $r[0]['body'];
        $o .= "[/share]";
    }
    if (local_channel()) {
        echo $o;
        killme();
    }
    $observer = $a->get_observer();
    $parsed = $observer['xchan_url'];
    if ($parsed) {
        $post_url = $parsed['scheme'] . ':' . $parsed['host'] . ($parsed['port'] ? ':' . $parsed['port'] : '') . '/rpost';
        /**
         * @FIXME we were probably called from JS so we don't know the return page.
         * In fact we won't be able to load the remote page.
         * we might need an iframe
         */
        $x = z_post_url($post_url, array('f' => '', 'body' => $o));
        killme();
    }
}
开发者ID:redmatrix,项目名称:red,代码行数:59,代码来源:share.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;
    }
    $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


示例4: 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


示例5: oexchange_content

function oexchange_content(&$a)
{
    if (!local_channel()) {
        if (remote_channel()) {
            $observer = $a->get_observer();
            if ($observer && $observer['xchan_url']) {
                $parsed = @parse_url($observer['xchan_url']);
                if (!$parsed) {
                    notice(t('Unable to find your hub.') . EOL);
                    return;
                }
                $url = $parsed['scheme'] . '://' . $parsed['host'] . ($parsed['port'] ? ':' . $parsed['port'] : '');
                $url .= '/oexchange';
                $result = z_post_url($url, $_REQUEST);
                json_return_and_die($result);
            }
        }
        return login(false);
    }
    if (argc() > 1 && argv(1) === 'done') {
        info(t('Post successful.') . EOL);
        return;
    }
    $url = x($_REQUEST, 'url') && strlen($_REQUEST['url']) ? urlencode(notags(trim($_REQUEST['url']))) : '';
    $title = x($_REQUEST, 'title') && strlen($_REQUEST['title']) ? '&title=' . urlencode(notags(trim($_REQUEST['title']))) : '';
    $description = x($_REQUEST, 'description') && strlen($_REQUEST['description']) ? '&description=' . urlencode(notags(trim($_REQUEST['description']))) : '';
    $tags = x($_REQUEST, 'tags') && strlen($_REQUEST['tags']) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '';
    $ret = z_fetch_url($a->get_baseurl() . '/urlinfo?f=&url=' . $url . $title . $description . $tags);
    if ($ret['success']) {
        $s = $ret['body'];
    }
    if (!strlen($s)) {
        return;
    }
    $post = array();
    $post['profile_uid'] = local_channel();
    $post['return'] = '/oexchange/done';
    $post['body'] = $s;
    $post['type'] = 'wall';
    $_REQUEST = $post;
    require_once 'mod/item.php';
    item_post($a);
}
开发者ID:TamirAl,项目名称:hubzilla,代码行数:43,代码来源:oexchange.php


示例6: sync_files


//.........这里部分代码省略.........
                    // end duplicate detection
                    // @fixme - update attachment structures if they are modified rather than created
                    $att['content'] = $newfname;
                    // Note: we use $att['hash'] below after it has been escaped to
                    // fetch the file contents.
                    // If the hash ever contains any escapable chars this could cause
                    // problems. Currently it does not.
                    dbesc_array($att);
                    if ($attach_exists) {
                        logger('sync_files attach exists: ' . print_r($att, true), LOGGER_DEBUG);
                        $str = '';
                        foreach ($att as $k => $v) {
                            if ($str) {
                                $str .= ",";
                            }
                            $str .= " `" . $k . "` = '" . $v . "' ";
                        }
                        $r = dbq("update `attach` set " . $str . " where id = " . intval($attach_id));
                    } else {
                        logger('sync_files attach does not exists: ' . print_r($att, true), LOGGER_DEBUG);
                        $r = dbq("INSERT INTO attach (`" . implode("`, `", array_keys($att)) . "`) VALUES ('" . implode("', '", array_values($att)) . "')");
                    }
                    // is this a directory?
                    if ($att['filetype'] === 'multipart/mixed' && $att['is_dir']) {
                        os_mkdir($newfname, STORAGE_DEFAULT_PERMISSIONS, true);
                        $attachment_stored = true;
                        continue;
                    } else {
                        // it's a file
                        // for the sync version of this algorithm (as opposed to 'offline import')
                        // we will fetch the actual file from the source server so it can be
                        // streamed directly to disk and avoid consuming PHP memory if it's a huge
                        // audio/video file or something.
                        $time = datetime_convert();
                        $parr = array('hash' => $channel['channel_hash'], 'time' => $time, 'resource' => $att['hash'], 'revision' => 0, 'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])));
                        $store_path = $newfname;
                        $fp = fopen($newfname, 'w');
                        if (!$fp) {
                            logger('failed to open storage file.', LOGGER_NORMAL, LOG_ERR);
                            continue;
                        }
                        $redirects = 0;
                        $x = z_post_url($fetch_url, $parr, $redirects, array('filep' => $fp));
                        fclose($fp);
                        if ($x['success']) {
                            $attachment_stored = true;
                        }
                        continue;
                    }
                }
            }
            if (!$attachment_stored) {
                // @TODO should we queue this and retry or delete everything or what?
                logger('attachment store failed', LOGGER_NORMAL, LOG_ERR);
            }
            if ($f['photo']) {
                foreach ($f['photo'] as $p) {
                    unset($p['id']);
                    $p['aid'] = $channel['channel_account_id'];
                    $p['uid'] = $channel['channel_id'];
                    convert_oldfields($p, 'data', 'content');
                    convert_oldfields($p, 'scale', 'imgscale');
                    convert_oldfields($p, 'size', 'filesize');
                    convert_oldfields($p, 'type', 'mimetype');
                    // if this is a profile photo, undo the profile photo bit
                    // for any other photo which previously held it.
                    if ($p['photo_usage'] == PHOTO_PROFILE) {
                        $e = q("update photo set photo_usage = %d where photo_usage = %d\n\t\t\t\t\t\t\tand resource_id != '%s' and uid = %d ", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), dbesc($p['resource_id']), intval($channel['channel_id']));
                    }
                    // same for cover photos
                    if ($p['photo_usage'] == PHOTO_COVER) {
                        $e = q("update photo set photo_usage = %d where photo_usage = %d\n\t\t\t\t\t\t\tand resource_id != '%s' and uid = %d ", intval(PHOTO_NORMAL), intval(PHOTO_COVER), dbesc($p['resource_id']), intval($channel['channel_id']));
                    }
                    if ($p['imgscale'] === 0 && $p['os_storage']) {
                        $p['content'] = $store_path;
                    } else {
                        $p['content'] = base64_decode($p['content']);
                    }
                    $exists = q("select * from photo where resource_id = '%s' and imgscale = %d and uid = %d limit 1", dbesc($p['resource_id']), intval($p['imgscale']), intval($channel['channel_id']));
                    dbesc_array($p);
                    if ($exists) {
                        $str = '';
                        foreach ($p as $k => $v) {
                            if ($str) {
                                $str .= ",";
                            }
                            $str .= " `" . $k . "` = '" . $v . "' ";
                        }
                        $r = dbq("update `photo` set " . $str . " where id = " . intval($exists[0]['id']));
                    } else {
                        $r = dbq("INSERT INTO photo (`" . implode("`, `", array_keys($p)) . "`) VALUES ('" . implode("', '", array_values($p)) . "')");
                    }
                }
            }
            if ($f['item']) {
                sync_items($channel, $f['item'], ['channel_address' => $original_channel, 'url' => $oldbase]);
            }
        }
    }
}
开发者ID:einervonvielen,项目名称:hubzilla,代码行数:101,代码来源:import.php


示例7: pubsubhubbub_subscribe

function pubsubhubbub_subscribe($url, $channel, $xchan, $feed, $hubmode = 'subscribe')
{
    $push_url = z_root() . '/pubsub/' . $channel['channel_address'] . '/' . $xchan['abook_id'];
    $verify = get_abconfig($channel['channel_id'], $xchan['xchan_hash'], 'pubsubhubbub', 'verify_token');
    if (!$verify) {
        $verify = set_abconfig($channel['channel_id'], $xchan['xchan_hash'], 'pubsubhubbub', 'verify_token', random_string(16));
    }
    if ($feed) {
        set_xconfig($xchan['xchan_hash'], 'system', 'feed_url', $feed);
    } else {
        $feed = get_xconfig($xchan['xchan_hash'], 'system', 'feed_url');
    }
    $params = 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($feed) . '&hub.verify=async&hub.verify_token=' . $verify;
    logger('subscribe_to_hub: ' . $hubmode . ' ' . $xchan['xchan_name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify);
    $x = z_post_url($url, $params);
    logger('subscribe_to_hub: returns: ' . $x['return_code'], LOGGER_DEBUG);
    return;
}
开发者ID:phellmes,项目名称:hubzilla-addons,代码行数:18,代码来源:pubsubhubbub.php


示例8: run

 /**
  * @brief Look up information about channel.
  *
  * @param string $webbie
  *   does not have to be host qualified e.g. 'foo' is treated as 'foo\@thishub'
  * @param array $channel
  *   (optional), if supplied permissions will be enumerated specifically for $channel
  * @param boolean $autofallback
  *   fallback/failover to http if https connection cannot be established. Default is true.
  *
  * @return zotinfo array (with 'success' => true) or array('success' => false);
  */
 public static function run($webbie, $channel = null, $autofallback = true)
 {
     $ret = array('success' => false);
     self::$token = random_string();
     if (strpos($webbie, '@') === false) {
         $address = $webbie;
         $host = App::get_hostname();
     } else {
         $address = substr($webbie, 0, strpos($webbie, '@'));
         $host = substr($webbie, strpos($webbie, '@') + 1);
     }
     $xchan_addr = $address . '@' . $host;
     if (!$address || !$xchan_addr) {
         logger('zot_finger: no address :' . $webbie);
         return $ret;
     }
     logger('using xchan_addr: ' . $xchan_addr, LOGGER_DATA, LOG_DEBUG);
     // potential issue here; the xchan_addr points to the primary hub.
     // The webbie we were called with may not, so it might not be found
     // unless we query for hubloc_addr instead of xchan_addr
     $r = q("select xchan.*, hubloc.* from xchan\n\t\t\tleft join hubloc on xchan_hash = hubloc_hash\n\t\t\twhere xchan_addr = '%s' and hubloc_primary = 1 limit 1", dbesc($xchan_addr));
     if ($r) {
         $url = $r[0]['hubloc_url'];
         if ($r[0]['hubloc_network'] && $r[0]['hubloc_network'] !== 'zot') {
             logger('zot_finger: alternate network: ' . $webbie);
             logger('url: ' . $url . ', net: ' . var_export($r[0]['hubloc_network'], true), LOGGER_DATA, LOG_DEBUG);
             return $ret;
         }
     } else {
         $url = 'https://' . $host;
     }
     $rhs = '/.well-known/zot-info';
     $https = strpos($url, 'https://') === 0 ? true : false;
     logger('zot_finger: ' . $address . ' at ' . $url, LOGGER_DEBUG);
     if ($channel) {
         $postvars = array('address' => $address, 'target' => $channel['channel_guid'], 'target_sig' => $channel['channel_guid_sig'], 'key' => $channel['channel_pubkey'], 'token' => self::$token);
         $result = z_post_url($url . $rhs, $postvars);
         if (!$result['success'] && $autofallback) {
             if ($https) {
                 logger('zot_finger: https failed. falling back to http');
                 $result = z_post_url('http://' . $host . $rhs, $postvars);
             }
         }
     } else {
         $rhs .= '?f=&address=' . urlencode($address) . '&token=' . self::$token;
         $result = z_fetch_url($url . $rhs);
         if (!$result['success'] && $autofallback) {
             if ($https) {
                 logger('zot_finger: https failed. falling back to http');
                 $result = z_fetch_url('http://' . $host . $rhs);
             }
         }
     }
     if (!$result['success']) {
         logger('zot_finger: no results');
         return $ret;
     }
     $x = json_decode($result['body'], true);
     if ($x) {
         $signed_token = is_array($x) && array_key_exists('signed_token', $x) ? $x['signed_token'] : null;
         if ($signed_token) {
             $valid = rsa_verify('token.' . self::$token, base64url_decode($signed_token), $x['key']);
             if (!$valid) {
                 logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR);
                 return $ret;
             }
         } else {
             logger('No signed token from ' . $url . $rhs, LOGGER_NORMAL, LOG_WARNING);
             // after 2017-01-01 this will be a hard error unless you over-ride it.
             if (time() > 1483228800 && !get_config('system', 'allow_unsigned_zotfinger')) {
                 return $ret;
             }
         }
     }
     return $x;
 }
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:88,代码来源:Finger.php


示例9: zot_refresh

/**
 * @brief Refreshes after permission changed or friending, etc.
 *
 * zot_refresh is typically invoked when somebody has changed permissions of a channel and they are notified
 * to fetch new permissions via a finger/discovery operation. This may result in a new connection
 * (abook entry) being added to a local channel and it may result in auto-permissions being granted.
 *
 * Friending in zot is accomplished by sending a refresh packet to a specific channel which indicates a
 * permission change has been made by the sender which affects the target channel. The hub controlling
 * the target channel does targetted discovery (a zot-finger request requesting permissions for the local
 * channel). These are decoded here, and if necessary and abook structure (addressbook) is created to store
 * the permissions assigned to this channel.
 *
 * Initially these abook structures are created with a 'pending' flag, so that no reverse permissions are
 * implied until this is approved by the owner channel. A channel can also auto-populate permissions in
 * return and send back a refresh packet of its own. This is used by forum and group communication channels
 * so that friending and membership in the channel's "club" is automatic.
 *
 * @param array $them => xchan structure of sender
 * @param array $channel => local channel structure of target recipient, required for "friending" operations
 * @param array $force default false
 *
 * @returns boolean true if successful, else false
 */
function zot_refresh($them, $channel = null, $force = false)
{
    if (array_key_exists('xchan_network', $them) && $them['xchan_network'] !== 'zot') {
        logger('zot_refresh: not got zot. ' . $them['xchan_name']);
        return true;
    }
    logger('zot_refresh: them: ' . print_r($them, true), LOGGER_DATA);
    if ($channel) {
        logger('zot_refresh: channel: ' . print_r($channel, true), LOGGER_DATA);
    }
    $url = null;
    if ($them['hubloc_url']) {
        $url = $them['hubloc_url'];
    } else {
        $r = null;
        // if they re-installed the server we could end up with the wrong record - pointing to the old install.
        // We'll order by reverse id to try and pick off the newest one first and hopefully end up with the
        // correct hubloc. If this doesn't work we may have to re-write this section to try them all.
        if (array_key_exists('xchan_addr', $them) && $them['xchan_addr']) {
            $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_addr = '%s' order by hubloc_id desc", dbesc($them['xchan_addr']));
        }
        if (!$r) {
            $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_hash = '%s' order by hubloc_id desc", dbesc($them['xchan_hash']));
        }
        if ($r) {
            foreach ($r as $rr) {
                if (intval($rr['hubloc_primary'])) {
                    $url = $rr['hubloc_url'];
                    break;
                }
            }
            if (!$url) {
                $url = $r[0]['hubloc_url'];
            }
        }
    }
    if (!$url) {
        logger('zot_refresh: no url');
        return false;
    }
    $postvars = array();
    if ($channel) {
        $postvars['target'] = $channel['channel_guid'];
        $postvars['target_sig'] = $channel['channel_guid_sig'];
        $postvars['key'] = $channel['channel_pubkey'];
    }
    if (array_key_exists('xchan_addr', $them) && $them['xchan_addr']) {
        $postvars['address'] = $them['xchan_addr'];
    }
    if (array_key_exists('xchan_hash', $them) && $them['xchan_hash']) {
        $postvars['guid_hash'] = $them['xchan_hash'];
    }
    if (array_key_exists('xchan_guid', $them) && $them['xchan_guid'] && array_key_exists('xchan_guid_sig', $them) && $them['xchan_guid_sig']) {
        $postvars['guid'] = $them['xchan_guid'];
        $postvars['guid_sig'] = $them['xchan_guid_sig'];
    }
    $rhs = '/.well-known/zot-info';
    $result = z_post_url($url . $rhs, $postvars);
    logger('zot_refresh: zot-info: ' . print_r($result, true), LOGGER_DATA);
    if ($result['success']) {
        $j = json_decode($result['body'], true);
        if (!($j && $j['success'])) {
            logger('zot_refresh: result not decodable');
            return false;
        }
        $x = import_xchan($j, $force ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED);
        if (!$x['success']) {
            return false;
        }
        $their_perms = 0;
        if ($channel) {
            $global_perms = get_perms();
            if ($j['permissions']['data']) {
                $permissions = crypto_unencapsulate(array('data' => $j['permissions']['data'], 'key' => $j['permissions']['key'], 'iv' => $j['permissions']['iv']), $channel['channel_prvkey']);
                if ($permissions) {
                    $permissions = json_decode($permissions, true);
//.........这里部分代码省略.........
开发者ID:23n,项目名称:hubzilla,代码行数:101,代码来源:zot.php


示例10: z_post_url_json

/**
 * @brief Like z_post_url() but with an application/json HTTP header.
 *
 * Add a "Content-Type: application/json" HTTP-header to $opts and call z_post_url().
 *
 * @see z_post_url()
 *
 * @param string $url
 * @param array $params
 * @param number $redirects default 0
 * @param array $opts (optional) curl options
 * @return z_post_url()
 */
function z_post_url_json($url, $params, $redirects = 0, $opts = array())
{
    $opts = array_merge($opts, array('headers' => array('Content-Type: application/json')));
    return z_post_url($url, json_encode($params), $redirects, $opts);
}
开发者ID:bashrc,项目名称:hubzilla,代码行数:18,代码来源:network.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) {
            /**
             * Check to see if we have any recent communications with this hub (in the last month).
             * If not, reduce the outq_priority.
             */
            $h = parse_url($r[0]['outq_posturl']);
            if ($h) {
                $base = $h['scheme'] . '://' . $h['host'] . ($h['port'] ? ':' . $h['port'] : '');
                if ($base !== z_root()) {
                    $y = q("select site_update, site_dead from site where site_url = '%s' ", dbesc($base));
                    if ($y) {
                        if (intval($y[0]['site_dead'])) {
                            q("delete from outq where outq_posturl = '%s'", dbesc($r[0]['outq_posturl']));
                            logger('dead site ignored ' . $base);
                            continue;
                        }
                        if ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
                            q("update outq set outq_priority = %d where outq_hash = '%s'", intval($r[0]['outq_priority'] + 10), dbesc($r[0]['outq_hash']));
                            logger('immediate delivery deferred for site ' . $base);
                            continue;
                        }
                    }
                }
            }
            // "post" queue driver - used for diaspora and friendica-over-diaspora communications.
            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'", 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'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
                continue;
            }
            $notify = json_decode($r[0]['outq_notify'], true);
            // Check if this is a conversation request packet. It won't have outq_msg
            // but will be an encrypted packet - so will need to be handed off to
            // web delivery rather than processed inline.
            $sendtoweb = false;
            if (array_key_exists('iv', $notify) && !$r[0]['outq_msg']) {
                $sendtoweb = true;
            }
            if ($r[0]['outq_posturl'] === z_root() . '/post' && !$sendtoweb) {
                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)))));
                        zot_import($msg, z_root());
                    }
                    $r = q("delete from outq where outq_hash = '%s'", 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']) {
                    logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']);
                    zot_process_response($r[0]['outq_posturl'], $result, $r[0]);
                } else {
                    logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
            }
        }
    }
}
开发者ID:HaakonME,项目名称:redmatrix,代码行数:85,代码来源:deliver.php


示例12: zot_refresh

/**
 * @brief Refreshes after permission changed or friending, etc.
 *
 * zot_refresh is typically invoked when somebody has changed permissions of a channel and they are notified
 * to fetch new permissions via a finger/discovery operation. This may result in a new connection
 * (abook entry) being added to a local channel and it may result in auto-permissions being granted.
 *
 * Friending in zot is accomplished by sending a refresh packet to a specific channel which indicates a
 * permission change has been made by the sender which affects the target channel. The hub controlling
 * the target channel does targetted discovery (a zot-finger request requesting permissions for the local
 * channel). These are decoded here, and if necessary and abook structure (addressbook) is created to store
 * the permissions assigned to this channel.
 *
 * Initially these abook structures are created with a 'pending' flag, so that no reverse permissions are
 * implied until this is approved by the owner channel. A channel can also auto-populate permissions in
 * return and send back a refresh packet of its own. This is used by forum and group communication channels
 * so that friending and membership in the channel's "club" is automatic.
 *
 * @param array $them => xchan structure of sender
 * @param array $channel => local channel structure of target recipient, required for "friending" operations
 * @param array $force default false
 *
 * @returns boolean true if successful, else false
 */
function zot_refresh($them, $channel = null, $force = false)
{
    if (array_key_exists('xchan_network', $them) && $them['xchan_network'] !== 'zot') {
        logger('zot_refresh: not got zot. ' . $them['xchan_name']);
        return true;
    }
    logger('zot_refresh: them: ' . print_r($them, true), LOGGER_DATA, LOG_DEBUG);
    if ($channel) {
        logger('zot_refresh: channel: ' . print_r($channel, true), LOGGER_DATA, LOG_DEBUG);
    }
    $url = null;
    if ($them['hubloc_url']) {
        $url = $them['hubloc_url'];
    } else {
        $r = null;
        // if they re-installed the server we could end up with the wrong record - pointing to the old install.
        // We'll order by reverse id to try and pick off the newest one first and hopefully end up with the
        // correct hubloc. If this doesn't work we may have to re-write this section to try them all.
        if (array_key_exists('xchan_addr', $them) && $them['xchan_addr']) {
            $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_addr = '%s' order by hubloc_id desc", dbesc($them['xchan_addr']));
        }
        if (!$r) {
            $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_hash = '%s' order by hubloc_id desc", dbesc($them['xchan_hash']));
        }
        if ($r) {
            foreach ($r as $rr) {
                if (intval($rr['hubloc_primary'])) {
                    $url = $rr['hubloc_url'];
                    break;
                }
            }
            if (!$url) {
                $url = $r[0]['hubloc_url'];
            }
        }
    }
    if (!$url) {
        logger('zot_refresh: no url');
        return false;
    }
    $token = random_string();
    $postvars = array();
    $postvars['token'] = $token;
    if ($channel) {
        $postvars['target'] = $channel['channel_guid'];
        $postvars['target_sig'] = $channel['channel_guid_sig'];
        $postvars['key'] = $channel['channel_pubkey'];
    }
    if (array_key_exists('xchan_addr', $them) && $them['xchan_addr']) {
        $postvars['address'] = $them['xchan_addr'];
    }
    if (array_key_exists('xchan_hash', $them) && $them['xchan_hash']) {
        $postvars['guid_hash'] = $them['xchan_hash'];
    }
    if (array_key_exists('xchan_guid', $them) && $them['xchan_guid'] && array_key_exists('xchan_guid_sig', $them) && $them['xchan_guid_sig']) {
        $postvars['guid'] = $them['xchan_guid'];
        $postvars['guid_sig'] = $them['xchan_guid_sig'];
    }
    $rhs = '/.well-known/zot-info';
    $result = z_post_url($url . $rhs, $postvars);
    logger('zot_refresh: zot-info: ' . print_r($result, true), LOGGER_DATA, LOG_DEBUG);
    if ($result['success']) {
        $j = json_decode($result['body'], true);
        if (!($j && $j['success'])) {
            logger('zot_refresh: result not decodable');
            return false;
        }
        $signed_token = is_array($j) && array_key_exists('signed_token', $j) ? $j['signed_token'] : null;
        if ($signed_token) {
            $valid = rsa_verify('token.' . $token, base64url_decode($signed_token), $j['key']);
            if (!$valid) {
                logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR);
                return false;
            }
        } else {
            logger('No signed token from ' . $url . $rhs, LOGGER_NORMAL, LOG_WARNING);
//.........这里部分代码省略.........
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:101,代码来源:zot.php


示例13: 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) {
            /**
             * Check to see if we have any recent communications with this hub (in the last month).
             * If not, reduce the outq_priority.
             */
            $h = parse_url($r[0]['outq_posturl']);
            if ($h) {
                $base = $h['scheme'] . '://' . $h['host'] . ($h['port'] ? ':' . $h['port'] : '');
                if ($base !== z_root()) {
                    $y = q("select site_update, site_dead from site where site_url = '%s' ", dbesc($base));
                    if ($y) {
                        if (intval($y[0]['site_dead'])) {
                            q("delete from outq where outq_posturl = '%s'", dbesc($r[0]['outq_posturl']));
                            logger('dead site ignored ' . $base);
                            continue;
                        }
                        if ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
                            q("update outq set outq_priority = %d where outq_hash = '%s'", intval($r[0]['outq_priority'] + 10), dbesc($r[0]['outq_hash']));
                            logger('immediate delivery deferred for site ' . $base);
                            continue;
                        }
                    } else {
                        // zot sites should all have a site record, unless they've been dead for as long as
                        // your site has existed. Since we don't know for sure what these sites are,
                        // call them unknown
                        q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ", dbesc($base), dbesc(datetime_convert()), intval($r[0]['outq_driver'] === 'post' ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN));
                    }
                }
            }
            // "post" queue driver - used for diaspora and friendica-over-diaspora communications.
            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);
                    q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", dbesc(datetime_convert()), dbesc($site_url));
                    q("update dreport set status = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", dbesc('accepted for delivery'), dbesc(datetime_convert()), dbesc($argv[$x]));
                    $y = q("delete from outq where outq_hash = '%s'", 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'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
                continue;
            }
            $notify = json_decode($r[0]['outq_notify'], true);
            // Check if this is a conversation request packet. It won't have outq_msg
            // but will be an encrypted packet - so will need to be handed off to
            // web delivery rather than processed inline.
            $sendtoweb = false;
            if (array_key_exists('iv', $notify) && !$r[0]['outq_msg']) {
                $sendtoweb = true;
            }
            if ($r[0]['outq_posturl'] === z_root() . '/post' && !$sendtoweb) {
                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());
                    }
                    $r = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]));
                    if ($dresult && is_array($dresult)) {
                        foreach ($dresult as $xx) {
                            if (is_array($xx) && array_key_exists('message_id', $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' 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']) {
                    logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']);
                    zot_process_response($r[0]['outq_posturl'], $result, $r[0]);
                } else {
                    logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:kenrestivo,项目名称:hubzilla,代码行数:101,代码来源:deliver.php


示例14: z_post_url

/**
 * @function z_post_url
 * @param string $url
 *    URL to post
 * @param mixed $params
 *   The full data to post in a HTTP "POST" operation. This parameter can 
 *   either be passed as a urlencoded string like 'para1=val1&para2=val2&...' 
 *   or as an array with the field name as key and field data as value. If value 
 *   is an array, the Content-Type header will be set to multipart/form-data. 
 * @param int $redirects = 0
 *    internal use, recursion counter
 * @param array $opts (optional parameters)
 *    'accept_content' => supply Accept: header with 'accept_content' as the value
 *    'timeout' => int seconds, default system config value or 60 seconds
 *    'http_auth' => username:password
 *    'novalidate' => do not validate SSL certs, default is to validate using our CA list
 *    
 * @returns array
 *    'return_code' => HTTP return code or 0 if timeout or failure
 *    'success' => boolean true (if HTTP 2xx result) or false
 *    'header' => HTTP headers
 *    'body' => fetched content
 */
function z_post_url($url, $params, $ 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP z_root函数代码示例发布时间:2022-05-23
下一篇:
PHP z_path函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap