本文整理汇总了PHP中yourls_do_action函数的典型用法代码示例。如果您正苦于以下问题:PHP yourls_do_action函数的具体用法?PHP yourls_do_action怎么用?PHP yourls_do_action使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yourls_do_action函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clayton_api_action_delete
function clayton_api_action_delete()
{
// We don't want unauthenticated users deleting links
// If YOURLS is in public mode, force authentication anyway
if (!yourls_is_private()) {
yourls_do_action('require_auth');
require_once YOURLS_INC . '/auth.php';
}
// Need 'shorturl' parameter
if (!isset($_REQUEST['shorturl'])) {
return array('statusCode' => 400, 'simple' => "Need a 'shorturl' parameter", 'message' => 'error: missing param');
}
$shorturl = $_REQUEST['shorturl'];
// Check if valid shorturl
if (!yourls_is_shorturl($shorturl)) {
return array('statusCode' => 404, 'simple ' => 'Error: short URL not found', 'message' => 'error: not found');
}
// Is $shorturl a URL (http://sho.rt/abc) or a keyword (abc) ?
if (yourls_get_protocol($shorturl)) {
$keyword = yourls_get_relative_url($shorturl);
} else {
$keyword = $shorturl;
}
// Delete shorturl
if (yourls_delete_link_by_keyword($keyword)) {
return array('statusCode' => 200, 'simple' => "Shorturl {$shorturl} deleted", 'message' => 'success: deleted');
} else {
return array('statusCode' => 500, 'simple' => 'Error: could not delete shorturl, not sure why :-/', 'message' => 'error: unknown error');
}
}
示例2: yourls_set_DB_driver
/**
* Pick the right DB class and return an instance
*
* @since 1.7
* @param string $extension Optional: user defined choice
* @return class $ydb DB class instance
*/
function yourls_set_DB_driver()
{
// Auto-pick the driver. Priority: user defined, then PDO, then mysqli, then mysql
if (defined('YOURLS_DB_DRIVER')) {
$driver = strtolower(YOURLS_DB_DRIVER);
// accept 'MySQL', 'mySQL', etc
} elseif (extension_loaded('pdo_mysql')) {
$driver = 'pdo';
} elseif (extension_loaded('mysqli')) {
$driver = 'mysqli';
} elseif (extension_loaded('mysql')) {
$driver = 'mysql';
} else {
$driver = '';
}
// Set the new driver
if (in_array($driver, array('mysql', 'mysqli', 'pdo'))) {
$class = yourls_require_db_files($driver);
}
global $ydb;
if (!class_exists($class, false)) {
$ydb = new stdClass();
yourls_die(yourls__('YOURLS requires the mysql, mysqli or pdo_mysql PHP extension. No extension found. Check your server config, or contact your host.'), yourls__('Fatal error'), 503);
}
yourls_do_action('set_DB_driver', $driver);
$ydb = new $class(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST);
$ydb->DB_driver = $driver;
yourls_debug_log("DB driver: {$driver}");
}
示例3: abdulrauf_adminreCaptcha_validatereCaptcha
function abdulrauf_adminreCaptcha_validatereCaptcha()
{
include 'captcha.php';
if ($resp != null && $resp->success) {
//reCaptcha validated
return true;
} else {
yourls_do_action('login_failed');
yourls_login_screen($error_msg = 'reCaptcha validation failed');
die;
return false;
}
}
示例4: allow_aliases
function allow_aliases()
{
yourls_do_action('pre_get_request');
// Ignore protocol & www. prefix
$root = str_replace(array('https://', 'http://', 'https://www.', 'http://www.'), '', YOURLS_SITE);
// Use the configured domain instead of $_SERVER['HTTP_HOST']
$root_host = parse_url(YOURLS_SITE);
// Case insensitive comparison of the YOURLS root to match both http://Sho.rt/blah and http://sho.rt/blah
$request = preg_replace("!{$root}/!i", '', $root_host['host'] . $_SERVER['REQUEST_URI'], 1);
// Unless request looks like a full URL (ie request is a simple keyword) strip query string
if (!preg_match("@^[a-zA-Z]+://.+@", $request)) {
$request = current(explode('?', $request));
}
return yourls_apply_filter('get_request', $request);
}
示例5: yourls_is_valid_user
/**
* Check for valid user. Returns true or an error message
*
*/
function yourls_is_valid_user()
{
static $valid = false;
if ($valid) {
return true;
}
$unfiltered_valid = false;
// Logout request
if (isset($_GET['action']) && $_GET['action'] == 'logout') {
yourls_do_action('logout');
yourls_store_cookie(null);
return yourls__('Logged out successfully');
}
// Check cookies or login request. Login form has precedence.
global $yourls_user_passwords;
yourls_do_action('pre_login');
// Determine auth method and check credentials
if (yourls_is_API() && isset($_REQUEST['timestamp']) && !empty($_REQUEST['timestamp']) && isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) {
yourls_do_action('pre_login_signature_timestamp');
$unfiltered_valid = yourls_check_signature_timestamp();
} elseif (yourls_is_API() && !isset($_REQUEST['timestamp']) && isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) {
yourls_do_action('pre_login_signature');
$unfiltered_valid = yourls_check_signature();
} elseif (isset($_REQUEST['username']) && isset($_REQUEST['password']) && !empty($_REQUEST['username']) && !empty($_REQUEST['password'])) {
yourls_do_action('pre_login_username_password');
$unfiltered_valid = yourls_check_username_password();
} elseif (!yourls_is_API() && isset($_COOKIE['yourls_username']) && isset($_COOKIE['yourls_password'])) {
yourls_do_action('pre_login_cookie');
$unfiltered_valid = yourls_check_auth_cookie();
}
$valid = yourls_apply_filter('is_valid_user', $unfiltered_valid);
// Login for the win!
if ($valid) {
yourls_do_action('login');
// (Re)store encrypted cookie if needed and tell it's ok
if (!yourls_is_API() && $unfiltered_valid) {
yourls_store_cookie(YOURLS_USER);
}
return true;
}
// Login failed
yourls_do_action('login_failed');
if (isset($_REQUEST['username']) || isset($_REQUEST['password'])) {
return yourls__('Invalid username or password');
} else {
return yourls__('Please log in');
}
}
示例6: insensitive_get_keyword_infos
function insensitive_get_keyword_infos($keyword, $use_cache = true)
{
global $ydb;
$keyword = yourls_sanitize_string($keyword);
yourls_do_action('pre_get_keyword', $keyword, $use_cache);
if (isset($ydb->infos[$keyword]) && $use_cache == true) {
return yourls_apply_filter('get_keyword_infos', $ydb->infos[$keyword], $keyword);
}
yourls_do_action('get_keyword_not_cached', $keyword);
$table = YOURLS_DB_TABLE_URL;
$infos = $ydb->get_row("SELECT * FROM `{$table}` WHERE LOWER(`keyword`) = LOWER('{$keyword}')");
if ($infos) {
$infos = (array) $infos;
$ydb->infos[$keyword] = $infos;
} else {
$ydb->infos[$keyword] = false;
}
return yourls_apply_filter('get_keyword_infos', $ydb->infos[$keyword], $keyword);
}
示例7: yourls_stats_countries_map
function yourls_stats_countries_map($countries)
{
yourls_do_action('stats_countries_map');
// Echo static map. Will be hidden if JS
$map = array('cht' => 't', 'chs' => '440x220', 'chtm' => 'world', 'chco' => 'FFFFFF,88C0EB,2A85B3,1F669C', 'chld' => join('', array_keys($countries)), 'chd' => 't:' . join(',', $countries), 'chf' => 'bg,s,EAF7FE');
$map_src = 'http://chart.apis.google.com/chart?' . http_build_query($map);
echo "<img id='yourls_stat_countries_static' class='hide-if-js' src='{$map_src}' width='440' height='220' border='0' />";
// Echo dynamic map. Will be hidden if no JS
echo <<<MAP
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geomap']});
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = new google.visualization.DataTable();
MAP;
echo '
data.addRows(' . count($countries) . ');
';
echo "\n\tdata.addColumn('string', 'Country');\n\tdata.addColumn('number', 'Hits');\n\t";
$i = 0;
foreach ($countries as $c => $v) {
echo "\n\t\t data.setValue({$i}, 0, '{$c}');\n\t\t data.setValue({$i}, 1, {$v});\n\t\t";
$i++;
}
echo <<<MAP
var options = {};
options['dataMode'] = 'regions';
options['width'] = '550px';
options['height'] = '340px';
options['colors'] = [0x88C0EB,0x2A85B3,0x1F669C];
var container = document.getElementById('yourls_stat_countries');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
};
</script>
<div id="yourls_stat_countries"></div>
MAP;
}
示例8: yourls_is_valid_user
<?php
// No direct call
if (!defined('YOURLS_ABSPATH')) {
die;
}
$auth = yourls_is_valid_user();
if ($auth !== true) {
// API mode,
if (yourls_is_API()) {
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml';
$callback = isset($_REQUEST['callback']) ? $_REQUEST['callback'] : '';
yourls_api_output($format, array('simple' => $auth, 'message' => $auth, 'errorCode' => 403, 'callback' => $callback));
// Regular mode
} else {
yourls_login_screen($auth);
}
die;
}
yourls_do_action('auth_successful');
示例9: yourls_sanitize_string
$keyword = $_GET['id'];
}
$keyword = yourls_sanitize_string($keyword);
// First possible exit:
if (!isset($keyword)) {
yourls_do_action('redirect_no_keyword');
yourls_redirect(YOURLS_SITE, 301);
}
// Get URL From Database
$url = yourls_get_keyword_longurl($keyword);
// URL found
if (!empty($url)) {
yourls_do_action('redirect_shorturl', $url, $keyword);
// Update click count in main table
$update_clicks = yourls_update_clicks($keyword);
// Update detailed log for stats
$log_redirect = yourls_log_redirect($keyword);
yourls_redirect($url, 301);
// URL not found. Either reserved, or page, or doesn't exist
} else {
// Do we have a page?
if (file_exists(YOURLS_PAGEDIR . "/{$keyword}.php")) {
yourls_page($keyword);
// Either reserved id, or no such id
} else {
yourls_do_action('redirect_keyword_not_found', $keyword);
yourls_redirect(YOURLS_SITE, 302);
// no 404 to tell browser this might change, and also to not pollute logs
}
}
exit;
示例10: throw
try {
throw ('ozhismygod');
} catch (z) {
a = function () {
if (!w.open(u,'Share','width=450,height=450,left=430','_blank')) l = u;
};
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
else a();
}
void(0);
TUMBLR;
yourls_bookmarklet_link(yourls_make_bookmarklet($js_code), yourls__('YOURLS & Tumblr'));
?>
<?php
yourls_do_action('social_bookmarklet_buttons_after');
?>
</p>
<h2><?php
yourls_e('Prefix-n-Shorten');
?>
</h2>
<p><?php
yourls_se("When viewing a page, you can also prefix its full URL: just head to your browser's address bar, add \"<span>%s</span>\" to the beginning of the current URL (right before its 'http://' part) and hit enter.", preg_replace('@https?://@', '', YOURLS_SITE) . '/');
?>
</p>
<p><?php
示例11: yourls_plugin_admin_page
/**
* Handle plugin administration page
*
*/
function yourls_plugin_admin_page($plugin_page)
{
global $ydb;
// Check the plugin page is actually registered
if (!isset($ydb->plugin_pages[$plugin_page])) {
yourls_die('This page does not exist. Maybe a plugin you thought was activated is inactive?', 'Invalid link');
}
// Draw the page itself
yourls_do_action('load-' . $plugin_page);
yourls_html_head('plugin_page_' . $plugin_page, $ydb->plugin_pages[$plugin_page]['title']);
yourls_html_logo();
yourls_html_menu();
call_user_func($ydb->plugin_pages[$plugin_page]['function']);
yourls_html_footer();
die;
}
示例12: isset
if (preg_match("@^([{$pattern}]+)/?\$@", $request, $matches)) {
$keyword = isset($matches[1]) ? $matches[1] : '';
$keyword = yourls_sanitize_keyword($keyword);
yourls_do_action('load_template_go', $keyword);
require_once YOURLS_ABSPATH . '/yourls-go.php';
exit;
}
// Stats:
if (preg_match("@^([{$pattern}]+)\\+(all)?/?\$@", $request, $matches)) {
$keyword = isset($matches[1]) ? $matches[1] : '';
$keyword = yourls_sanitize_keyword($keyword);
$aggregate = isset($matches[2]) ? (bool) $matches[2] && yourls_allow_duplicate_longurls() : false;
yourls_do_action('load_template_infos', $keyword);
require_once YOURLS_ABSPATH . '/yourls-infos.php';
exit;
}
// Prefix-n-Shorten sends to bookmarklet (doesn't work on Windows)
if (preg_match("@^[a-zA-Z]+://.+@", $request, $matches)) {
$url = yourls_sanitize_url($matches[0]);
if ($parse = yourls_get_protocol_slashes_and_rest($url, array('up', 'us', 'ur'))) {
yourls_do_action('load_template_redirect_admin', $url);
$parse = array_map('rawurlencode', $parse);
// Redirect to /admin/index.php?up=<url protocol>&us=<url slashes>&ur=<url rest>
yourls_redirect(yourls_add_query_arg($parse, yourls_admin_url('index.php')), 302);
exit;
}
}
// Past this point this is a request the loader could not understand
yourls_do_action('loader_failed', $request);
yourls_redirect(YOURLS_SITE, 302);
exit;
示例13: yourls_do_action
yourls_do_action('infos_no_keyword');
yourls_redirect(YOURLS_SITE, 302);
}
// Get basic infos for this shortened URL
$keyword = yourls_sanitize_string($keyword);
$longurl = yourls_get_keyword_longurl($keyword);
$clicks = yourls_get_keyword_clicks($keyword);
$timestamp = yourls_get_keyword_timestamp($keyword);
$title = yourls_get_keyword_title($keyword);
// Update title if it hasn't been stored yet
if ($title == '') {
$title = yourls_get_remote_title($longurl);
yourls_edit_link_title($keyword, $title);
}
if ($longurl === false) {
yourls_do_action('infos_keyword_not_found');
yourls_redirect(YOURLS_SITE, 302);
}
if (yourls_do_log_redirect()) {
// Duplicate keywords, if applicable
$keyword_list = yourls_get_duplicate_keywords($longurl);
// Fetch all information from the table log
$table = YOURLS_DB_TABLE_LOG;
if ($aggregate) {
$keywords = join("', '", $keyword_list);
// Fetch information for all keywords pointing to $longurl
$hits = $ydb->get_results("SELECT `shorturl`, `click_time`, `referrer`, `user_agent`, `country_code` FROM `{$table}` WHERE `shorturl` IN ( '{$keywords}' );");
} else {
// Fetch information for current keyword only
$hits = $ydb->get_results("SELECT `click_time`, `referrer`, `user_agent`, `country_code` FROM `{$table}` WHERE `shorturl` = '{$keyword}';");
}
示例14: yourls_check_IP_flood
function yourls_check_IP_flood($ip = '')
{
yourls_do_action('pre_check_ip_flood', $ip);
// at this point $ip can be '', check it if your plugin hooks in here
if (defined('YOURLS_FLOOD_DELAY_SECONDS') && YOURLS_FLOOD_DELAY_SECONDS === 0 || !defined('YOURLS_FLOOD_DELAY_SECONDS')) {
return true;
}
$ip = $ip ? yourls_sanitize_ip($ip) : yourls_get_IP();
// Don't throttle whitelist IPs
if (defined('YOURLS_FLOOD_IP_WHITELIST' && YOURLS_FLOOD_IP_WHITELIST)) {
$whitelist_ips = explode(',', YOURLS_FLOOD_IP_WHITELIST);
foreach ((array) $whitelist_ips as $whitelist_ip) {
$whitelist_ip = trim($whitelist_ip);
if ($whitelist_ip == $ip) {
return true;
}
}
}
// Don't throttle logged in users
if (yourls_is_private()) {
if (yourls_is_valid_user() === true) {
return true;
}
}
yourls_do_action('check_ip_flood', $ip);
global $ydb;
$table = YOURLS_DB_TABLE_URL;
$lasttime = $ydb->get_var("SELECT `timestamp` FROM {$table} WHERE `ip` = '{$ip}' ORDER BY `timestamp` DESC LIMIT 1");
if ($lasttime) {
$now = date('U');
$then = date('U', strtotime($lasttime));
if ($now - $then <= YOURLS_FLOOD_DELAY_SECONDS) {
// Flood!
yourls_do_action('ip_flood', $ip, $now - $then);
yourls_die('Too many URLs added too fast. Slow down please.', 'Forbidden', 403);
}
}
return true;
}
示例15: yourls_content_type_header
/**
* Send a filerable content type header
*
* @since 1.7
* @param string $type content type ('text/html', 'application/json', ...)
* @return bool whether header was sent
*/
function yourls_content_type_header($type)
{
yourls_do_action('content_type_header', $type);
if (!headers_sent()) {
$charset = yourls_apply_filter('content_type_header_charset', 'utf-8');
header("Content-Type: {$type}; charset={$charset}");
return true;
}
return false;
}