コード例 #1
0
ファイル: zot.php プロジェクト: 23n/hubzilla
/**
 * @brief
 *
 * This is the second part of public_recipes().
 * We'll find all the channels willing to accept public posts from us, then
 * match them against the sender privacy scope and see who in that list that
 * the sender is allowing.
 *
 * @see public_recipes()
 * @param array $msg
 * @return array
 */
function allowed_public_recips($msg)
{
    logger('allowed_public_recips: ' . print_r($msg, true), LOGGER_DATA);
    if (array_key_exists('public_scope', $msg['message'])) {
        $scope = $msg['message']['public_scope'];
    }
    // Mail won't have a public scope.
    // in fact, it's doubtful mail will ever get here since it almost universally
    // has a recipient, but in fact we don't require this, so it's technically
    // possible to send mail to anybody that's listening.
    $recips = public_recips($msg);
    if (!$recips) {
        return $recips;
    }
    if ($msg['message']['type'] === 'mail') {
        return $recips;
    }
    if ($scope === 'public' || $scope === 'network: red' || $scope === 'authenticated') {
        return $recips;
    }
    if (strpos($scope, 'site:') === 0) {
        if ($scope === 'site: ' . get_app()->get_hostname() && $msg['notify']['sender']['url'] === z_root()) {
            return $recips;
        } else {
            return array();
        }
    }
    $hash = make_xchan_hash($msg['notify']['sender']['guid'], $msg['notify']['sender']['guid_sig']);
    if ($scope === 'self') {
        foreach ($recips as $r) {
            if ($r['hash'] === $hash) {
                return array('hash' => $hash);
            }
        }
    }
    // note: we shouldn't ever see $scope === 'specific' in this function, but handle it anyway
    if ($scope === 'contacts' || $scope === 'any connections' || $scope === 'specific') {
        $condensed_recips = array();
        foreach ($recips as $rr) {
            $condensed_recips[] = $rr['hash'];
        }
        $results = array();
        $r = q("select channel_hash as hash from channel left join abook on abook_channel = channel_id where abook_xchan = '%s' and channel_removed = 0 ", dbesc($hash));
        if ($r) {
            foreach ($r as $rr) {
                if (in_array($rr['hash'], $condensed_recips)) {
                    $results[] = array('hash' => $rr['hash']);
                }
            }
        }
        return $results;
    }
    return array();
}
コード例 #2
0
ファイル: zot.php プロジェクト: Mauru/red
function allowed_public_recips($msg)
{
    logger('allowed_public_recips: ' . print_r($msg, true));
    $recips = public_recips($msg);
    if (!$recips) {
        return $recips;
    }
    if ($msg['message']['type'] === 'mail') {
        return $recips;
    }
    if (array_key_exists('public_scope', $msg['message'])) {
        $scope = $msg['message']['public_scope'];
    }
    $hash = make_xchan_hash($msg['notify']['sender']['guid'], $msg['notify']['sender']['guid_sig']);
    if ($scope === 'public' || $scope === 'network: red' || $scope === 'authenticated') {
        return $recips;
    }
    if (strpos($scope, 'site:') === 0) {
        if ($scope === 'site: ' . get_app()->get_hostname() && $msg['notify']['sender']['url'] === z_root()) {
            return $recips;
        } else {
            return array();
        }
    }
    if ($scope === 'self') {
        foreach ($recips as $r) {
            if ($r['hash'] === $hash) {
                return array('hash' => $hash);
            }
        }
    }
    if ($scope === 'contacts') {
        $condensed_recips = array();
        foreach ($recips as $rr) {
            $condensed_recips[] = $rr['hash'];
        }
        $results = array();
        $r = q("select channel_hash as hash from channel left join abook on abook_channel = channel_id where abook_xchan = '%s' and not ( channel_pageflags & %d ) ", dbesc($hash), intval(PAGE_REMOVED));
        if ($r) {
            foreach ($r as $rr) {
                if (in_array($rr['hash'], $condensed_recips)) {
                    $results[] = array('hash' => $rr['hash']);
                }
            }
        }
        return $results;
    }
    return array();
}