本文整理汇总了PHP中x函数的典型用法代码示例。如果您正苦于以下问题:PHP x函数的具体用法?PHP x怎么用?PHP x使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了x函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: api_login
/**
* API Login via basic-auth or OAuth
*/
function api_login(&$a)
{
$record = null;
require_once 'include/oauth.php';
// login with oauth
try {
$oauth = new ZotOAuth1();
$req = OAuth1Request::from_request();
list($consumer, $token) = $oauth->verify_request($req);
if (!is_null($token)) {
$oauth->loginUser($token->uid);
App::set_oauth_key($consumer->key);
call_hooks('logged_in', App::$user);
return;
}
killme();
} catch (Exception $e) {
logger($e->getMessage());
}
// workarounds for HTTP-auth in CGI mode
if (x($_SERVER, 'REDIRECT_REMOTE_USER')) {
$userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6));
if (strlen($userpass)) {
list($name, $password) = explode(':', $userpass);
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
}
}
if (x($_SERVER, 'HTTP_AUTHORIZATION')) {
$userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6));
if (strlen($userpass)) {
list($name, $password) = explode(':', $userpass);
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
}
}
require_once 'include/auth.php';
require_once 'include/security.php';
// process normal login request
if (isset($_SERVER['PHP_AUTH_USER'])) {
$channel_login = 0;
$record = account_verify_password($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
if ($record && $record['channel']) {
$channel_login = $record['channel']['channel_id'];
}
}
if ($record['account']) {
authenticate_success($record['account']);
if ($channel_login) {
change_channel($channel_login);
}
$_SESSION['allow_api'] = true;
return true;
} else {
$_SERVER['PHP_AUTH_PW'] = '*****';
logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
log_failed_login('API login failure');
retry_basic_auth();
}
}
示例2: send
/**
* Send a multipart/alternative message with Text and HTML versions
*
* @param fromName name of the sender
* @param fromEmail email fo the sender
* @param replyTo replyTo address to direct responses
* @param toEmail destination email address
* @param messageSubject subject of the message
* @param htmlVersion html version of the message
* @param textVersion text only version of the message
* @param additionalMailHeader additions to the smtp mail header
* @param optional uid user id of the destination user
*/
public static function send($params)
{
call_hooks('emailer_send_prepare', $params);
$email_textonly = False;
if (x($params, "uid")) {
$email_textonly = get_pconfig($params['uid'], "system", "email_textonly");
}
$fromName = email_header_encode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
$messageSubject = email_header_encode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
// generate a mime boundary
$mimeBoundary = rand(0, 9) . "-" . rand(10000000000, 99999999999) . "-" . rand(10000000000, 99999999999) . "=:" . rand(10000, 99999);
// generate a multipart/alternative message header
$messageHeader = $params['additionalMailHeader'] . "From: {$fromName} <{$params['fromEmail']}>\n" . "Reply-To: {$fromName} <{$params['replyTo']}>\n" . "MIME-Version: 1.0\n" . "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
// assemble the final multipart message body with the text and html types included
$textBody = chunk_split(base64_encode($params['textVersion']));
$htmlBody = chunk_split(base64_encode($params['htmlVersion']));
$multipartMessageBody = "--" . $mimeBoundary . "\n" . "Content-Type: text/plain; charset=UTF-8\n" . "Content-Transfer-Encoding: base64\n\n" . $textBody . "\n";
if (!$email_textonly && !is_null($params['htmlVersion'])) {
$multipartMessageBody .= "--" . $mimeBoundary . "\n" . "Content-Type: text/html; charset=UTF-8\n" . "Content-Transfer-Encoding: base64\n\n" . $htmlBody . "\n";
}
$multipartMessageBody .= "--" . $mimeBoundary . "--\n";
// message ending
// send the message
$hookdata = array('to' => $params['toEmail'], 'subject' => $messageSubject, 'body' => $multipartMessageBody, 'headers' => $messageHeader);
//echo "<pre>"; var_dump($hookdata); killme();
call_hooks("emailer_send", $hookdata);
$res = mail($hookdata['to'], $hookdata['subject'], $hookdata['body'], $hookdata['headers']);
logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
logger("return value " . ($res ? "true" : "false"), LOGGER_DEBUG);
return $res;
}
示例3: search_ac_init
function search_ac_init(&$a)
{
if (!local_channel()) {
killme();
}
$start = x($_REQUEST, 'start') ? $_REQUEST['start'] : 0;
$count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 100;
$search = x($_REQUEST, 'search') ? $_REQUEST['search'] : "";
if (x($_REQUEST, 'query') && strlen($_REQUEST['query'])) {
$search = $_REQUEST['query'];
}
// Priority to people searches
if ($search) {
$people_sql_extra = protect_sprintf(" AND `xchan_name` LIKE '%" . dbesc($search) . "%' ");
$tag_sql_extra = protect_sprintf(" AND term LIKE '%" . dbesc($search) . "%' ");
}
$r = q("SELECT `abook_id`, `xchan_name`, `xchan_photo_s`, `xchan_url`, `xchan_addr` FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d \n\t\t{$people_sql_extra}\n\t\tORDER BY `xchan_name` ASC ", intval(local_channel()));
$results = array();
if ($r) {
foreach ($r as $g) {
$results[] = array("photo" => $g['xchan_photo_s'], "name" => '@' . $g['xchan_name'], "id" => $g['abook_id'], "link" => $g['xchan_url'], "label" => '', "nick" => '');
}
}
$r = q("select distinct term, tid, url from term where type in ( %d, %d ) {$tag_sql_extra} group by term order by term asc", intval(TERM_HASHTAG), intval(TERM_COMMUNITYTAG));
if (count($r)) {
foreach ($r as $g) {
$results[] = array("photo" => $a->get_baseurl() . '/images/hashtag.png', "name" => '#' . $g['term'], "id" => $g['tid'], "link" => $g['url'], "label" => '', "nick" => '');
}
}
header("content-type: application/json");
$o = array('start' => $start, 'count' => $count, 'items' => $results);
echo json_encode($o);
logger('search_ac: ' . print_r($x, true));
killme();
}
示例4: tagrm_post
function tagrm_post(&$a)
{
if (!local_user()) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
if (x($_POST, 'submit') && $_POST['submit'] === t('Cancel')) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
$tag = x($_POST, 'tag') ? hex2bin(notags(trim($_POST['tag']))) : '';
$item = x($_POST, 'item') ? intval($_POST['item']) : 0;
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval(local_user()));
if (!count($r)) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
$arr = explode(',', $r[0]['tag']);
for ($x = 0; $x < count($arr); $x++) {
if ($arr[$x] === $tag) {
unset($arr[$x]);
break;
}
}
$tag_str = implode(',', $arr);
q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", dbesc($tag_str), intval($item), intval(local_user()));
info(t('Tag removed') . EOL);
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
示例5: get_timezones
/**
* @brief Return timezones grouped (primarily) by continent.
*
* @return array
*/
function get_timezones()
{
$timezone_identifiers = DateTimeZone::listIdentifiers();
usort($timezone_identifiers, 'timezone_cmp');
$continent = '';
$continents = array();
foreach ($timezone_identifiers as $value) {
$ex = explode("/", $value);
if (count($ex) > 1) {
$continent = t($ex[0]);
if (count($ex) > 2) {
$city = substr($value, strpos($value, '/') + 1);
} else {
$city = $ex[1];
}
} else {
$city = $ex[0];
$continent = t('Miscellaneous');
}
$city = str_replace('_', ' ', t($city));
if (!x($continents, $ex[0])) {
$continents[$ex[0]] = array();
}
$continents[$continent][$value] = $city;
}
return $continents;
}
示例6: post
function post()
{
if (!local_channel()) {
return;
}
if ($_SESSION['delegate']) {
return;
}
if (!x($_POST, 'qxz_password') || !strlen(trim($_POST['qxz_password']))) {
return;
}
if (!x($_POST, 'verify') || !strlen(trim($_POST['verify']))) {
return;
}
if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
return;
}
$account = \App::get_account();
$account_id = get_account_id();
if (!account_verify_password($account['account_email'], $_POST['qxz_password'])) {
return;
}
if ($account['account_password_changed'] != NULL_DATE) {
$d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours');
if ($account['account_password_changed'] > d1) {
notice(t('Account removals are not allowed within 48 hours of changing the account password.') . EOL);
return;
}
}
$global_remove = intval($_POST['global']);
account_remove($account_id, 1 - $global_remove);
}
示例7: get
function get()
{
$o .= '<h3>Probe Diagnostic</h3>';
$o .= '<form action="probe" method="get">';
$o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . $_GET['addr'] . '" />';
$o .= '<input type="submit" name="submit" value="Submit" /></form>';
$o .= '<br /><br />';
if (x($_GET, 'addr')) {
$channel = \App::get_channel();
$addr = trim($_GET['addr']);
$do_import = intval($_GET['import']) && is_site_admin() ? true : false;
$j = \Zotlabs\Zot\Finger::run($addr, $channel, false);
// $res = zot_finger($addr,$channel,false);
$o .= '<pre>';
if (!$j['success']) {
$o .= sprintf(t('Fetching URL returns error: %1$s'), $res['error'] . "\r\n\r\n");
$o .= "<strong>https connection failed. Trying again with auto failover to http.</strong>\r\n\r\n";
$j = \Zotlabs\Zot\Finger::run($addr, $channel, true);
if (!$j['success']) {
$o .= sprintf(t('Fetching URL returns error: %1$s'), $res['error'] . "\r\n\r\n");
}
}
if ($do_import && $j) {
$x = import_xchan($j);
}
if ($j && $j['permissions'] && $j['permissions']['iv']) {
$j['permissions'] = json_decode(crypto_unencapsulate($j['permissions'], $channel['channel_prvkey']), true);
}
$o .= str_replace("\n", '<br />', print_r($j, true));
$o .= '</pre>';
}
return $o;
}
示例8: siteinfo_init
function siteinfo_init(&$a)
{
if ($a->argv[1] == "json") {
$register_policy = array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN');
$sql_extra = '';
if (x($a->config, 'admin_nickname')) {
$sql_extra = sprintf(" AND nickname = '%s' ", dbesc($a->config['admin_nickname']));
}
if (isset($a->config['admin_email']) && $a->config['admin_email'] != '') {
$r = q("SELECT username, nickname FROM user WHERE email='%s' {$sql_extra}", dbesc($a->config['admin_email']));
$admin = array('name' => $r[0]['username'], 'profile' => $a->get_baseurl() . '/channel/' . $r[0]['nickname']);
} else {
$admin = false;
}
$visible_plugins = array();
if (is_array($a->plugins) && count($a->plugins)) {
$r = q("select * from addon where hidden = 0");
if (count($r)) {
foreach ($r as $rr) {
$visible_plugins[] = $rr['name'];
}
}
}
if (@is_dir('.git') && function_exists('shell_exec')) {
$commit = @shell_exec('git log -1 --format="%h"');
}
if (!isset($commit) || strlen($commit) > 16) {
$commit = '';
}
$data = array('version' => RED_VERSION, 'commit' => $commit, 'url' => z_root(), 'plugins' => $visible_plugins, 'register_policy' => $register_policy[$a->config['system']['register_policy']], 'admin' => $admin, 'site_name' => $a->config['sitename'], 'platform' => RED_PLATFORM, 'info' => x($a->config, 'info') ? $a->config['info'] : '');
echo json_encode($data);
killme();
}
}
示例9: libertree_post_local
function libertree_post_local(&$a, &$b)
{
// This can probably be changed to allow editing by pointing to a different API endpoint
if ($b['edit']) {
return;
}
if (!local_channel() || local_channel() != $b['uid']) {
return;
}
if ($b['item_private'] || $b['mid'] != $b['parent_mid']) {
return;
}
$ltree_post = intval(get_pconfig(local_channel(), 'libertree', 'post'));
$ltree_enable = $ltree_post && x($_REQUEST, 'libertree_enable') ? intval($_REQUEST['libertree_enable']) : 0;
if ($_REQUEST['api_source'] && intval(get_pconfig(local_channel(), 'libertree', 'post_by_default'))) {
$ltree_enable = 1;
}
if (!$ltree_enable) {
return;
}
if (strlen($b['postopts'])) {
$b['postopts'] .= ',';
}
$b['postopts'] .= 'libertree';
}
示例10: regmod_content
function regmod_content(&$a)
{
global $lang;
$_SESSION['return_url'] = $a->cmd;
if (!local_user()) {
info(t('Please login.') . EOL);
$o .= '<br /><br />' . login($a->config['register_policy'] == REGISTER_CLOSED ? 0 : 1);
return $o;
}
if (!is_site_admin() || x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
notice(t('Permission denied.') . EOL);
return '';
}
if ($a->argc != 3) {
killme();
}
$cmd = $a->argv[1];
$hash = $a->argv[2];
if ($cmd === 'deny') {
user_deny($hash);
goaway($a->get_baseurl() . "/admin/users/");
killme();
}
if ($cmd === 'allow') {
user_allow($hash);
goaway($a->get_baseurl() . "/admin/users/");
killme();
}
}
示例11: post
function post()
{
check_form_security_token_redirectOnErr('/admin/security', 'admin_security');
$allowed_email = x($_POST, 'allowed_email') ? notags(trim($_POST['allowed_email'])) : '';
$not_allowed_email = x($_POST, 'not_allowed_email') ? notags(trim($_POST['not_allowed_email'])) : '';
set_config('system', 'allowed_email', $allowed_email);
set_config('system', 'not_allowed_email', $not_allowed_email);
$block_public = x($_POST, 'block_public') ? True : False;
set_config('system', 'block_public', $block_public);
$ws = $this->trim_array_elems(explode("\n", $_POST['whitelisted_sites']));
set_config('system', 'whitelisted_sites', $ws);
$bs = $this->trim_array_elems(explode("\n", $_POST['blacklisted_sites']));
set_config('system', 'blacklisted_sites', $bs);
$wc = $this->trim_array_elems(explode("\n", $_POST['whitelisted_channels']));
set_config('system', 'whitelisted_channels', $wc);
$bc = $this->trim_array_elems(explode("\n", $_POST['blacklisted_channels']));
set_config('system', 'blacklisted_channels', $bc);
$embed_sslonly = x($_POST, 'embed_sslonly') ? True : False;
set_config('system', 'embed_sslonly', $embed_sslonly);
$we = $this->trim_array_elems(explode("\n", $_POST['embed_allow']));
set_config('system', 'embed_allow', $we);
$be = $this->trim_array_elems(explode("\n", $_POST['embed_deny']));
set_config('system', 'embed_deny', $be);
$ts = x($_POST, 'transport_security') ? True : False;
set_config('system', 'transport_security_header', $ts);
$cs = x($_POST, 'content_security') ? True : False;
set_config('system', 'content_security_policy', $cs);
goaway(z_root() . '/admin/security');
}
示例12: irc_content
function irc_content(&$a)
{
$baseurl = z_root() . '/addon/irc';
$o = '';
/* set the list of popular channels */
$sitechats = get_config('irc', 'sitechats');
if ($sitechats) {
$chats = explode(',', $sitechats);
} else {
$chats = array('hubzilla', 'friendica', 'chat', 'chatback', 'hottub', 'ircbar', 'dateroom', 'debian');
}
App::$page['aside'] .= '<div class="widget"><h3>' . t('Popular Channels') . '</h3><ul>';
foreach ($chats as $chat) {
App::$page['aside'] .= '<li><a href="' . z_root() . '/irc?channels=' . $chat . '" >' . '#' . $chat . '</a></li>';
}
App::$page['aside'] .= '</ul></div>';
/* setting the channel(s) to auto connect */
$autochans = get_config('irc', 'autochans');
if ($autochans) {
$channels = $autochans;
} else {
$channels = x($_GET, 'channels') ? $_GET['channels'] : 'hubzilla';
}
/* add the chatroom frame and some html */
$o .= <<<EOT
<h2>IRC chat</h2>
<p><a href="http://tldp.org/HOWTO/IRC/beginners.html" target="_blank">A beginner's guide to using IRC. [en]</a></p>
<iframe src="//webchat.freenode.net?channels={$channels}" width="100%" height="600"></iframe>
EOT;
return $o;
}
示例13: removeaccount_post
function removeaccount_post(&$a)
{
if (!local_user()) {
return;
}
if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
return;
}
if (!x($_POST, 'qxz_password') || !strlen(trim($_POST['qxz_password']))) {
return;
}
if (!x($_POST, 'verify') || !strlen(trim($_POST['verify']))) {
return;
}
if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
return;
}
$account = $a->get_account();
$account_id = get_account_id();
if (!account_verify_password($account['account_email'], $_POST['qxz_password'])) {
return;
}
if ($account['account_password_changed'] != NULL_DATE) {
$d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours');
if ($account['account_password_changed'] > d1) {
notice(t('Account removals are not allowed within 48 hours of changing the account password.') . EOL);
return;
}
}
require_once 'include/Contact.php';
$global_remove = intval($_POST['global']);
account_remove($account_id, true);
}
示例14: lostpass_content
function lostpass_content(&$a)
{
if (x($_GET, 'verify')) {
$verify = $_GET['verify'];
$r = q("SELECT * FROM account WHERE account_reset = '%s' LIMIT 1", dbesc($verify));
if (!$r) {
notice(t("Request could not be verified. (You may have previously submitted it.) Password reset failed.") . EOL);
goaway(z_root());
return;
}
$aid = $r[0]['account_id'];
$email = $r[0]['account_email'];
$new_password = autoname(6) . mt_rand(100, 9999);
$salt = random_string(32);
$password_encoded = hash('whirlpool', $salt . $new_password);
$r = q("UPDATE account SET account_salt = '%s', account_password = '%s', account_reset = '', account_flags = (account_flags & ~%d) where account_id = %d", dbesc($salt), dbesc($password_encoded), intval(ACCOUNT_UNVERIFIED), intval($aid));
if ($r) {
$tpl = get_markup_template('pwdreset.tpl');
$o .= replace_macros($tpl, array('$lbl1' => t('Password Reset'), '$lbl2' => t('Your password has been reset as requested.'), '$lbl3' => t('Your new password is'), '$lbl4' => t('Save or copy your new password - and then'), '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.', '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'), '$newpass' => $new_password, '$baseurl' => $a->get_baseurl()));
info("Your password has been reset." . EOL);
$email_tpl = get_intltext_template("passchanged_eml.tpl");
$message = replace_macros($email_tpl, array('$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$username' => sprintf(t('Site Member (%s)'), $email), '$email' => $email, '$new_password' => $new_password, '$uid' => $newuid));
$subject = email_header_encode(sprintf(t('Your password has changed at %s'), get_config('system', 'sitename')), 'UTF-8');
$res = mail($email, $subject, $message, 'From: ' . 'Administrator@' . $_SERVER['SERVER_NAME'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit');
return $o;
}
} else {
$tpl = get_markup_template('lostpass.tpl');
$o .= replace_macros($tpl, array('$title' => t('Forgot your Password?'), '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'), '$name' => t('Email Address'), '$submit' => t('Reset')));
return $o;
}
}
示例15: webfinger_content
function webfinger_content(&$a)
{
$o .= '<h3>Webfinger Diagnostic</h3>';
$o .= '<form action="webfinger" method="get">';
$o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . $_GET['addr'] . '" />';
$o .= '<input type="submit" name="submit" value="Submit" /></form>';
$o .= '<br /><br />';
if (x($_GET, 'addr')) {
$addr = trim($_GET['addr']);
if (strpos($addr, '@') !== false) {
$res = webfinger_rfc7033($addr, true);
if (!$res) {
$res = old_webfinger($addr);
}
} else {
if (function_exists('lrdd')) {
$res = lrdd($addr);
}
}
$o .= '<pre>';
$o .= str_replace("\n", '<br />', print_r($res, true));
$o .= '</pre>';
}
return $o;
}