本文整理汇总了PHP中service_class_allows函数的典型用法代码示例。如果您正苦于以下问题:PHP service_class_allows函数的具体用法?PHP service_class_allows怎么用?PHP service_class_allows使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了service_class_allows函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: identity_check_service_class
/**
* @function identity_check_service_class($account_id)
* Called when creating a new channel. Checks the account's service class and number
* of current channels to determine whether creating a new channel is within the current
* service class constraints.
*
* @param int $account_id
* Account_id used for this request
*
* @returns array
* 'success' => boolean true if creating a new channel is allowed for this account
* 'message' => if success is false, optional error text
*/
function identity_check_service_class($account_id)
{
$ret = array('success' => false, $message => '');
$r = q("select count(channel_id) as total from channel where channel_account_id = %d and not ( channel_pageflags & %d ) ", intval($account_id), intval(PAGE_REMOVED));
if (!($r && count($r))) {
$ret['message'] = t('Unable to obtain identity information from database');
return $ret;
}
if (!service_class_allows($account_id, 'total_identities', $r[0]['total'])) {
$result['message'] .= upgrade_message();
return $result;
}
$ret['success'] = true;
return $ret;
}
示例2: new_contact
function new_contact($uid, $url, $channel, $interactive = false, $confirm = false)
{
$result = array('success' => false, 'message' => '');
$is_red = false;
$is_http = strpos($url, '://') !== false ? true : false;
if ($is_http && substr($url, -1, 1) === '/') {
$url = substr($url, 0, -1);
}
if (!allowed_url($url)) {
$result['message'] = t('Channel is blocked on this site.');
return $result;
}
if (!$url) {
$result['message'] = t('Channel location missing.');
return $result;
}
// check service class limits
$r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", intval($uid));
if ($r) {
$total_channels = $r[0]['total'];
}
if (!service_class_allows($uid, 'total_channels', $total_channels)) {
$result['message'] = upgrade_message();
return $result;
}
$arr = array('url' => $url, 'channel' => array());
call_hooks('follow', $arr);
if ($arr['channel']['success']) {
$ret = $arr['channel'];
} elseif (!$is_http) {
$ret = Zotlabs\Zot\Finger::run($url, $channel);
}
if ($ret && is_array($ret) && $ret['success']) {
$is_red = true;
$j = $ret;
}
$my_perms = get_channel_default_perms($uid);
$role = get_pconfig($uid, 'system', 'permissions_role');
if ($role) {
$x = \Zotlabs\Access\PermissionRoles::role_perms($role);
if ($x['perms_connect']) {
$my_perms = $x['perms_connect'];
}
}
if ($is_red && $j) {
logger('follow: ' . $url . ' ' . print_r($j, true), LOGGER_DEBUG);
if (!($j['success'] && $j['guid'])) {
$result['message'] = t('Response from remote channel was incomplete.');
logger('mod_follow: ' . $result['message']);
return $result;
}
// Premium channel, set confirm before callback to avoid recursion
if (array_key_exists('connect_url', $j) && $interactive && !$confirm) {
goaway(zid($j['connect_url']));
}
// do we have an xchan and hubloc?
// If not, create them.
$x = import_xchan($j);
if (array_key_exists('deleted', $j) && intval($j['deleted'])) {
$result['message'] = t('Channel was deleted and no longer exists.');
return $result;
}
if (!$x['success']) {
return $x;
}
$xchan_hash = $x['hash'];
if (array_key_exists('permissions', $j) && array_key_exists('data', $j['permissions'])) {
$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);
}
logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
} else {
$permissions = $j['permissions'];
}
if (is_array($permissions) && $permissions) {
foreach ($permissions as $k => $v) {
set_abconfig($channel['channel_uid'], $xchan_hash, 'their_perms', $k, intval($v));
}
}
} else {
$xchan_hash = '';
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url));
if (!$r) {
// attempt network auto-discovery
$d = discover_by_webbie($url);
if (!$d && $is_http) {
// try RSS discovery
if (get_config('system', 'feed_contacts')) {
$d = discover_by_url($url);
} else {
$result['message'] = t('Protocol disabled.');
return $result;
}
}
if ($d) {
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url));
}
}
// if discovery was a success we should have an xchan record in $r
//.........这里部分代码省略.........
示例3: item_check_service_class
function item_check_service_class($channel_id, $iswebpage)
{
$ret = array('success' => false, 'message' => '');
if ($iswebpage) {
// note: we aren't counting comanche templates and blocks, only webpages
$r = q("select count(id) as total from item where parent = id \n\t\t\tand ( item_restrict & %d ) > 0 and ( item_restrict & %d ) = 0 and uid = %d ", intval(ITEM_WEBPAGE), intval(ITEM_DELETED), intval($channel_id));
} else {
$r = q("select count(id) as total from item where parent = id and item_restrict = 0 and (item_flags & %d) > 0 and uid = %d ", intval(ITEM_WALL), intval($channel_id));
}
if (!$r) {
$ret['message'] = t('Unable to obtain post information from database.');
return $ret;
}
if (!$iswebpage) {
$max = service_class_fetch($channel_id, 'total_items');
if (!service_class_allows($channel_id, 'total_items', $r[0]['total'])) {
$result['message'] .= upgrade_message() . sprintf(t('You have reached your limit of %1$.0f top level posts.'), $max);
return $result;
}
} else {
$max = service_class_fetch($channel_id, 'total_pages');
if (!service_class_allows($channel_id, 'total_pages', $r[0]['total'])) {
$result['message'] .= upgrade_message() . sprintf(t('You have reached your limit of %1$.0f webpages.'), $max);
return $result;
}
}
$ret['success'] = true;
return $ret;
}
示例4: new_contact
function new_contact($uid, $url, $interactive = false)
{
$result = array('cid' => -1, 'success' => false, 'message' => '');
$a = get_app();
// remove ajax junk, e.g. Twitter
$url = str_replace('/#!/', '/', $url);
if (!allowed_url($url)) {
$result['message'] = t('Disallowed profile URL.');
return $result;
}
if (!$url) {
$result['message'] = t('Connect URL missing.');
return $result;
}
$arr = array('url' => $url, 'contact' => array());
call_hooks('follow', $arr);
if (x($arr['contact'], 'name')) {
$ret = $arr['contact'];
} else {
$ret = probe_url($url);
}
if ($ret['network'] === NETWORK_DFRN) {
if ($interactive) {
if (strlen($a->path)) {
$myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
} else {
$myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
}
goaway($ret['request'] . "&addr={$myaddr}");
// NOTREACHED
}
} else {
if (get_config('system', 'dfrn_only')) {
$result['message'] = t('This site is not configured to allow communications with other networks.') . EOL;
$result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL;
return $result;
}
}
// This extra param just confuses things, remove it
if ($ret['network'] === NETWORK_DIASPORA) {
$ret['url'] = str_replace('?absolute=true', '', $ret['url']);
}
// do we have enough information?
if (!(x($ret, 'name') && x($ret, 'poll') && (x($ret, 'url') || x($ret, 'addr')))) {
$result['message'] .= t('The profile address specified does not provide adequate information.') . EOL;
if (!x($ret, 'poll')) {
$result['message'] .= t('No compatible communication protocols or feeds were discovered.') . EOL;
}
if (!x($ret, 'name')) {
$result['message'] .= t('An author or name was not found.') . EOL;
}
if (!x($ret, 'url')) {
$result['message'] .= t('No browser URL could be matched to this address.') . EOL;
}
if (strpos($url, '@') !== false) {
$result['message'] .= t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL;
$result['message'] .= t('Use mailto: in front of address to force email check.') . EOL;
}
return $result;
}
if ($ret['network'] === NETWORK_OSTATUS && get_config('system', 'ostatus_disabled')) {
$result['message'] .= t('The profile address specified belongs to a network which has been disabled on this site.') . EOL;
$ret['notify'] = '';
}
if (!$ret['notify']) {
$result['message'] .= t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL;
}
$writeable = $ret['network'] === NETWORK_OSTATUS && $ret['notify'] ? 1 : 0;
$subhub = $ret['network'] === NETWORK_OSTATUS ? true : false;
$hidden = $ret['network'] === NETWORK_MAIL ? 1 : 0;
if ($ret['network'] === NETWORK_MAIL) {
$writeable = 1;
}
if ($ret['network'] === NETWORK_DIASPORA) {
$writeable = 1;
}
// check if we already have a contact
// the poll url is more reliable than the profile url, as we may have
// indirect links or webfinger links
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` IN ('%s', '%s') AND `network` = '%s' LIMIT 1", intval($uid), dbesc($ret['poll']), dbesc(normalise_link($ret['poll'])), dbesc($ret['network']));
if (!count($r)) {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` = '%s' LIMIT 1", intval($uid), dbesc(normalise_link($url)), dbesc($ret['network']));
}
if (count($r)) {
// update contact
if ($r[0]['rel'] == CONTACT_IS_FOLLOWER || $network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING) {
q("UPDATE `contact` SET `rel` = %d , `subhub` = %d, `readonly` = 0 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($subhub), intval($r[0]['id']), intval($uid));
}
} else {
// check service class limits
$r = q("select count(*) as total from contact where uid = %d and pending = 0 and self = 0", intval($uid));
if (count($r)) {
$total_contacts = $r[0]['total'];
}
if (!service_class_allows($uid, 'total_contacts', $total_contacts)) {
$result['message'] .= upgrade_message();
return $result;
}
$r = q("select count(network) as total from contact where uid = %d and network = '%s' and pending = 0 and self = 0", intval($uid), dbesc($network));
if (count($r)) {
//.........这里部分代码省略.........
示例5: settings_content
function settings_content(&$a)
{
$o = '';
nav_set_selected('settings');
if (!local_user()) {
#notice( t('Permission denied.') . EOL );
return;
}
if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
notice(t('Permission denied.') . EOL);
return;
}
if ($a->argc > 1 && $a->argv[1] === 'oauth') {
if ($a->argc > 2 && $a->argv[2] === 'add') {
$tpl = get_markup_template("settings_oauth_edit.tpl");
$o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$title' => t('Add application'), '$submit' => t('Save Settings'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), '', ''), '$key' => array('key', t('Consumer Key'), '', ''), '$secret' => array('secret', t('Consumer Secret'), '', ''), '$redirect' => array('redirect', t('Redirect'), '', ''), '$icon' => array('icon', t('Icon url'), '', '')));
return $o;
}
if ($a->argc > 3 && $a->argv[2] === 'edit') {
$r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user());
if (!count($r)) {
notice(t("You can't edit this application."));
return;
}
$app = $r[0];
$tpl = get_markup_template("settings_oauth_edit.tpl");
$o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$title' => t('Add application'), '$submit' => t('Update'), '$cancel' => t('Cancel'), '$name' => array('name', t('Name'), $app['name'], ''), '$key' => array('key', t('Consumer Key'), $app['client_id'], ''), '$secret' => array('secret', t('Consumer Secret'), $app['pw'], ''), '$redirect' => array('redirect', t('Redirect'), $app['redirect_uri'], ''), '$icon' => array('icon', t('Icon url'), $app['icon'], '')));
return $o;
}
if ($a->argc > 3 && $a->argv[2] === 'delete') {
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
$r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user());
goaway($a->get_baseurl(true) . "/settings/oauth/");
return;
}
$r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my\n\t\t\t\tFROM clients\n\t\t\t\tLEFT JOIN tokens ON clients.client_id=tokens.client_id\n\t\t\t\tWHERE clients.uid IN (%d,0)", local_user(), local_user());
$tpl = get_markup_template("settings_oauth.tpl");
$o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_oauth"), '$baseurl' => $a->get_baseurl(true), '$title' => t('Connected Apps'), '$add' => t('Add application'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$consumerkey' => t('Client key starts with'), '$noname' => t('No name'), '$remove' => t('Remove authorization'), '$apps' => $r));
return $o;
}
if ($a->argc > 1 && $a->argv[1] === 'addon') {
$settings_addons = "";
$r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' ");
if (!count($r)) {
$settings_addons = t('No Plugin settings configured');
}
call_hooks('plugin_settings', $settings_addons);
$tpl = get_markup_template("settings_addons.tpl");
$o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_addon"), '$title' => t('Plugin Settings'), '$settings_addons' => $settings_addons));
return $o;
}
if ($a->argc > 1 && $a->argv[1] === 'features') {
$arr = array();
$features = get_features();
foreach ($features as $fname => $fdata) {
$arr[$fname] = array();
$arr[$fname][0] = $fdata[0];
foreach (array_slice($fdata, 1) as $f) {
$arr[$fname][1][] = array('feature_' . $f[0], $f[1], intval(get_pconfig(local_user(), 'feature', $f[0])) ? "1" : '', $f[2], array(t('Off'), t('On')));
}
}
$tpl = get_markup_template("settings_features.tpl");
$o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_features"), '$title' => t('Additional Features'), '$features' => $arr, '$submit' => t('Save Settings')));
return $o;
}
if ($a->argc > 1 && $a->argv[1] === 'connectors') {
$settings_connectors = "";
call_hooks('connector_settings', $settings_connectors);
if (is_site_admin()) {
$diasp_enabled = sprintf(t('Built-in support for %s connectivity is %s'), t('Diaspora'), get_config('system', 'diaspora_enabled') ? t('enabled') : t('disabled'));
$ostat_enabled = sprintf(t('Built-in support for %s connectivity is %s'), t('StatusNet'), get_config('system', 'ostatus_disabled') ? t('disabled') : t('enabled'));
} else {
$diasp_enabled = "";
$ostat_enabled = "";
}
$mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1;
if (get_config('system', 'dfrn_only')) {
$mail_disabled = 1;
}
if (!$mail_disabled) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", local_user());
} else {
$r = null;
}
$mail_server = count($r) ? $r[0]['server'] : '';
$mail_port = count($r) && intval($r[0]['port']) ? intval($r[0]['port']) : '';
$mail_ssl = count($r) ? $r[0]['ssltype'] : '';
$mail_user = count($r) ? $r[0]['user'] : '';
$mail_replyto = count($r) ? $r[0]['reply_to'] : '';
$mail_pubmail = count($r) ? $r[0]['pubmail'] : 0;
$mail_action = count($r) ? $r[0]['action'] : 0;
$mail_movetofolder = count($r) ? $r[0]['movetofolder'] : '';
$mail_chk = count($r) ? $r[0]['last_check'] : '0000-00-00 00:00:00';
$tpl = get_markup_template("settings_connectors.tpl");
if (!service_class_allows(local_user(), 'email_connect')) {
$mail_disabled_message = upgrade_bool_message();
} else {
$mail_disabled_message = $mail_disabled ? t('Email access is disabled on this site.') : '';
}
$o .= replace_macros($tpl, array('$form_security_token' => get_form_security_token("settings_connectors"), '$title' => t('Social Networks'), '$diasp_enabled' => $diasp_enabled, '$ostat_enabled' => $ostat_enabled, '$h_imap' => t('Email/Mailbox Setup'), '$imap_desc' => t("If you wish to communicate with email contacts using this service (optional), please specify how to connect to your mailbox."), '$imap_lastcheck' => array('imap_lastcheck', t('Last successful email check:'), $mail_chk, ''), '$mail_disabled' => $mail_disabled_message, '$mail_server' => array('mail_server', t('IMAP server name:'), $mail_server, ''), '$mail_port' => array('mail_port', t('IMAP port:'), $mail_port, ''), '$mail_ssl' => array('mail_ssl', t('Security:'), strtoupper($mail_ssl), '', array('notls' => t('None'), 'TLS' => 'TLS', 'SSL' => 'SSL')), '$mail_user' => array('mail_user', t('Email login name:'), $mail_user, ''), '$mail_pass' => array('mail_pass', t('Email password:'), '', ''), '$mail_replyto' => array('mail_replyto', t('Reply-to address:'), $mail_replyto, 'Optional'), '$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''), '$mail_action' => array('mail_action', t('Action after import:'), $mail_action, '', array(0 => t('None'), 2 => t('Mark as seen'), 3 => t('Move to folder'))), '$mail_movetofolder' => array('mail_movetofolder', t('Move to folder:'), $mail_movetofolder, ''), '$submit' => t('Save Settings'), '$settings_connectors' => $settings_connectors));
//.........这里部分代码省略.........
示例6: new_contact
function new_contact($uid, $url, $channel, $interactive = false, $confirm = false)
{
$result = array('success' => false, 'message' => '');
$a = get_app();
$is_red = false;
$is_http = strpos($url, '://') !== false ? true : false;
if ($is_http && substr($url, -1, 1) === '/') {
$url = substr($url, 0, -1);
}
if (!allowed_url($url)) {
$result['message'] = t('Channel is blocked on this site.');
return $result;
}
if (!$url) {
$result['message'] = t('Channel location missing.');
return $result;
}
// check service class limits
$r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", intval($uid));
if ($r) {
$total_channels = $r[0]['total'];
}
if (!service_class_allows($uid, 'total_channels', $total_channels)) {
$result['message'] = upgrade_message();
return $result;
}
$arr = array('url' => $url, 'channel' => array());
call_hooks('follow', $arr);
if ($arr['channel']['success']) {
$ret = $arr['channel'];
} elseif (!$is_http) {
$ret = zot_finger($url, $channel);
}
if ($ret && $ret['success']) {
$is_red = true;
$j = json_decode($ret['body'], true);
}
$my_perms = get_channel_default_perms($uid);
$role = get_pconfig($uid, 'system', 'permissions_role');
if ($role) {
$x = get_role_perms($role);
if ($x['perms_follow']) {
$my_perms = $x['perms_follow'];
}
}
if ($is_red && $j) {
logger('follow: ' . $url . ' ' . print_r($j, true), LOGGER_DEBUG);
if (!($j['success'] && $j['guid'])) {
$result['message'] = t('Response from remote channel was incomplete.');
logger('mod_follow: ' . $result['message']);
return $result;
}
// Premium channel, set confirm before callback to avoid recursion
if (array_key_exists('connect_url', $j) && $interactive && !$confirm) {
goaway(zid($j['connect_url']));
}
// do we have an xchan and hubloc?
// If not, create them.
$x = import_xchan($j);
if (array_key_exists('deleted', $j) && intval($j['deleted'])) {
$result['message'] = t('Channel was deleted and no longer exists.');
return $result;
}
if (!$x['success']) {
return $x;
}
$xchan_hash = $x['hash'];
$their_perms = 0;
$global_perms = get_perms();
if (array_key_exists('permissions', $j) && array_key_exists('data', $j['permissions'])) {
$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);
}
logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
} else {
$permissions = $j['permissions'];
}
foreach ($permissions as $k => $v) {
if ($v) {
$their_perms = $their_perms | intval($global_perms[$k][1]);
}
}
} else {
$their_perms = 0;
$xchan_hash = '';
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url));
if (!$r) {
// attempt network auto-discovery
if (strpos($url, '@') && !$is_http) {
$r = discover_by_webbie($url);
} elseif ($is_http) {
$r = discover_by_url($url);
$r['allowed'] = intval(get_config('system', 'feed_contacts'));
}
if ($r) {
$r['channel_id'] = $uid;
call_hooks('follow_allow', $r);
if (!$r['allowed']) {
$result['message'] = t('Protocol disabled.');
//.........这里部分代码省略.........
示例7: item_check_service_class
function item_check_service_class($channel_id, $iswebpage)
{
$ret = array('success' => false, 'message' => '');
if ($iswebpage) {
$r = q("select count(i.id) as total from item i \n\t\t\tright join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id ) \n\t\t\tand i.parent=i.id and i.item_type = %d and i.item_deleted = 0 and i.uid= %d ", intval(ITEM_TYPE_WEBPAGE), intval($channel_id));
} else {
$r = q("select count(id) as total from item where parent = id and item_wall = 1 and uid = %d " . item_normal(), intval($channel_id));
}
if (!$r) {
$ret['message'] = t('Unable to obtain post information from database.');
return $ret;
}
if (!$iswebpage) {
$max = service_class_fetch($channel_id, 'total_items');
if (!service_class_allows($channel_id, 'total_items', $r[0]['total'])) {
$result['message'] .= upgrade_message() . sprintf(t('You have reached your limit of %1$.0f top level posts.'), $max);
return $result;
}
} else {
$max = service_class_fetch($channel_id, 'total_pages');
if (!service_class_allows($channel_id, 'total_pages', $r[0]['total'])) {
$result['message'] .= upgrade_message() . sprintf(t('You have reached your limit of %1$.0f webpages.'), $max);
return $result;
}
}
$ret['success'] = true;
return $ret;
}
示例8: fbpost_content
/**
* @param App $a
* @return string
*/
function fbpost_content(&$a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
return '';
}
if (!service_class_allows(local_user(), 'facebook_connect')) {
notice(t('Permission denied.') . EOL);
return upgrade_bool_message();
}
if ($a->argc > 1 && $a->argv[1] === 'remove') {
del_pconfig(local_user(), 'facebook', 'post');
info(t('Facebook Post disabled') . EOL);
}
require_once "mod/settings.php";
settings_init($a);
$o = '';
$accounts = array();
$fb_installed = false;
if (get_pconfig(local_user(), 'facebook', 'post')) {
$access_token = get_pconfig(local_user(), 'facebook', 'access_token');
if ($access_token) {
// fetching the list of accounts to check, if facebook is working
// The value is needed several lines below.
$url = 'https://graph.facebook.com/me/accounts';
$s = fetch_url($url . "?access_token=" . $access_token, false, $redirects, 10);
if ($s) {
$accounts = json_decode($s);
if (isset($accounts->data)) {
$fb_installed = true;
}
}
// I'm not totally sure, if this above will work in every situation,
// So this old code will be called as well.
if (!$fb_installed) {
$url = "https://graph.facebook.com/me/feed";
$s = fetch_url($url . "?access_token=" . $access_token . "&limit=1", false, $redirects, 10);
if ($s) {
$j = json_decode($s);
if (isset($j->data)) {
$fb_installed = true;
}
}
}
}
}
$appid = get_config('facebook', 'appid');
if (!$appid) {
notice(t('Facebook API key is missing.') . EOL);
return '';
}
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/fbpost/fbpost.css' . '" media="all" />' . "\r\n";
$result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`");
$fbsync = count($result) > 0;
if ($fbsync) {
$title = t('Facebook Import/Export/Mirror');
} else {
$title = t('Facebook Export/Mirror');
}
$o .= '<img class="connector" src="images/facebook.png" /><h3 class="connector">' . $title . '</h3>';
if (!$fb_installed) {
$o .= '<div id="fbpost-enable-wrapper">';
//read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access
//export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=publish_actions,publish_pages,user_posts,user_photos,user_status,user_videos,manage_pages,user_managed_groups">' . t('Install Facebook Post connector for this account.') . '</a>';
$o .= '</div>';
}
if ($fb_installed) {
$o .= '<div id="fbpost-disable-wrapper">';
$o .= '<a href="' . $a->get_baseurl() . '/fbpost/remove' . '">' . t('Remove Facebook Post connector') . '</a></div>';
$o .= '<div id="fbpost-enable-wrapper">';
//export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=publish_actions,publish_pages,user_posts,user_photos,user_status,user_videos,manage_pages,user_managed_groups">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>';
$o .= '</div>';
$o .= '<div id="fbpost-post-default-form">';
$o .= '<form action="fbpost" method="post" >';
$post_by_default = get_pconfig(local_user(), 'facebook', 'post_by_default');
$checked = $post_by_default ? ' checked="checked" ' : '';
$o .= '<input type="checkbox" name="post_by_default" value="1"' . $checked . '/>' . ' ' . t('Post to Facebook by default') . EOL;
$suppress_view_on_friendica = get_pconfig(local_user(), 'facebook', 'suppress_view_on_friendica');
$checked = $suppress_view_on_friendica ? ' checked="checked" ' : '';
$o .= '<input type="checkbox" name="suppress_view_on_friendica" value="1"' . $checked . '/>' . ' ' . t('Suppress "View on friendica"') . EOL;
$mirror_posts = get_pconfig(local_user(), 'facebook', 'mirror_posts');
$checked = $mirror_posts ? ' checked="checked" ' : '';
$o .= '<input type="checkbox" name="mirror_posts" value="1"' . $checked . '/>' . ' ' . t('Mirror wall posts from facebook to friendica.') . EOL;
// List all pages
$post_to_page = get_pconfig(local_user(), 'facebook', 'post_to_page');
$page_access_token = get_pconfig(local_user(), 'facebook', 'page_access_token');
$fb_token = get_pconfig($a->user['uid'], 'facebook', 'access_token');
//$url = 'https://graph.facebook.com/me/accounts';
//$x = fetch_url($url."?access_token=".$fb_token, false, $redirects, 10);
//$accounts = json_decode($x);
$o .= t("Post to page/group:") . "<select name='post_to_page'>";
if (intval($post_to_page) == 0) {
$o .= "<option value='0-0' selected>" . t('None') . "</option>";
} else {
//.........这里部分代码省略.........
示例9: item_check_service_class
function item_check_service_class($channel_id, $iswebpage)
{
$ret = array('success' => false, $message => '');
if ($iswebpage) {
$r = q("select count(i.id) as total from item i \n\t\t\tright join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id ) \n\t\t\tand i.parent=i.id and (i.item_restrict & %d) and not (i.item_restrict & %d) and i.uid= %d ", intval(ITEM_WEBPAGE), intval(ITEM_DELETED), intval($channel_id));
} else {
$r = q("select count(i.id) as total from item i \n\t\t\tright join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id ) \n\t\t\tand i.parent=i.id and (i.item_restrict=0) and i.uid= %d ", intval($channel_id));
}
if (!($r && count($r))) {
$ret['message'] = t('Unable to obtain identity information from database');
return $ret;
}
if (!$iswebpage) {
if (!service_class_allows($channel_id, 'total_items', $r[0]['total'])) {
$result['message'] .= upgrade_message() . sprintf(t("You have reached your limit of %1\$.0f top level posts."), $r[0]['total']);
return $result;
}
} else {
if (!service_class_allows($channel_id, 'total_pages', $r[0]['total'])) {
$result['message'] .= upgrade_message() . sprintf(t("You have reached your limit of %1\$.0f webpages."), $r[0]['total']);
return $result;
}
}
$ret['success'] = true;
return $ret;
}
示例10: facebook_content
/**
* @param App $a
* @return string
*/
function facebook_content(&$a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
return '';
}
if (!service_class_allows(local_user(), 'facebook_connect')) {
notice(t('Permission denied.') . EOL);
return upgrade_bool_message();
}
if ($a->argc > 1 && $a->argv[1] === 'remove') {
del_pconfig(local_user(), 'facebook', 'post');
info(t('Facebook disabled') . EOL);
}
if ($a->argc > 1 && $a->argv[1] === 'friends') {
fb_get_friends(local_user(), true);
info(t('Updating contacts') . EOL);
}
$fb_limited = get_config('facebook', 'restrict');
$o = '';
$fb_installed = false;
if (get_pconfig(local_user(), 'facebook', 'post')) {
$access_token = get_pconfig(local_user(), 'facebook', 'access_token');
if ($access_token) {
$s = fetch_url('https://graph.facebook.com/me/feed?access_token=' . $access_token);
if ($s) {
$j = json_decode($s);
if (isset($j->data)) {
$fb_installed = true;
}
}
}
}
$appid = get_config('facebook', 'appid');
if (!$appid) {
notice(t('Facebook API key is missing.') . EOL);
return '';
}
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/facebook/facebook.css' . '" media="all" />' . "\r\n";
$o .= '<h3>' . t('Facebook Connect') . '</h3>';
if (!$fb_installed) {
$o .= '<div id="facebook-enable-wrapper">';
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' . $a->get_baseurl() . '/facebook/' . $a->user['nickname'] . '&scope=publish_stream,read_stream,offline_access">' . t('Install Facebook connector for this account.') . '</a>';
$o .= '</div>';
}
if ($fb_installed) {
$o .= '<div id="facebook-disable-wrapper">';
$o .= '<a href="' . $a->get_baseurl() . '/facebook/remove' . '">' . t('Remove Facebook connector') . '</a></div>';
$o .= '<div id="facebook-enable-wrapper">';
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' . $a->get_baseurl() . '/facebook/' . $a->user['nickname'] . '&scope=publish_stream,read_stream,offline_access">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>';
$o .= '</div>';
$o .= '<div id="facebook-post-default-form">';
$o .= '<form action="facebook" method="post" >';
$post_by_default = get_pconfig(local_user(), 'facebook', 'post_by_default');
$checked = $post_by_default ? ' checked="checked" ' : '';
$o .= '<input type="checkbox" name="post_by_default" value="1"' . $checked . '/>' . ' ' . t('Post to Facebook by default') . EOL;
$no_linking = get_pconfig(local_user(), 'facebook', 'no_linking');
$checked = $no_linking ? '' : ' checked="checked" ';
if ($fb_limited) {
if ($no_linking) {
$o .= EOL . '<strong>' . t('Facebook friend linking has been disabled on this site. The following settings will have no effect.') . '</strong>' . EOL;
$checked .= " disabled ";
} else {
$o .= EOL . '<strong>' . t('Facebook friend linking has been disabled on this site. If you disable it, you will be unable to re-enable it.') . '</strong>' . EOL;
}
}
$o .= '<input type="checkbox" name="facebook_linking" value="1"' . $checked . '/>' . ' ' . t('Link all your Facebook friends and conversations on this website') . EOL;
$o .= '<p>' . t('Facebook conversations consist of your <em>profile wall</em> and your friend <em>stream</em>.');
$o .= ' ' . t('On this website, your Facebook friend stream is only visible to you.');
$o .= ' ' . t('The following settings determine the privacy of your Facebook profile wall on this website.') . '</p>';
$private_wall = get_pconfig(local_user(), 'facebook', 'private_wall');
$checked = $private_wall ? ' checked="checked" ' : '';
$o .= '<input type="checkbox" name="facebook_private_wall" value="1"' . $checked . '/>' . ' ' . t('On this website your Facebook profile wall conversations will only be visible to you') . EOL;
$no_wall = get_pconfig(local_user(), 'facebook', 'no_wall');
$checked = $no_wall ? ' checked="checked" ' : '';
$o .= '<input type="checkbox" name="facebook_no_wall" value="1"' . $checked . '/>' . ' ' . t('Do not import your Facebook profile wall conversations') . EOL;
$o .= '<p>' . t('If you choose to link conversations and leave both of these boxes unchecked, your Facebook profile wall will be merged with your profile wall on this website and your privacy settings on this website will be used to determine who may see the conversations.') . '</p>';
$blocked_apps = get_pconfig(local_user(), 'facebook', 'blocked_apps');
$o .= '<div><label id="blocked-apps-label" for="blocked-apps">' . t('Comma separated applications to ignore') . ' </label></div>';
$o .= '<div><textarea id="blocked-apps" name="blocked_apps" >' . htmlspecialchars($blocked_apps) . '</textarea></div>';
$o .= '<input type="submit" name="submit" value="' . t('Save Settings') . '" /></form></div>';
}
return $o;
}