本文整理汇总了PHP中yourls_add_new_link函数的典型用法代码示例。如果您正苦于以下问题:PHP yourls_add_new_link函数的具体用法?PHP yourls_add_new_link怎么用?PHP yourls_add_new_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yourls_add_new_link函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: yourls_api_action_shorturl
/**
* API function wrapper: Shorten a URL
*
* @since 1.6
* @return array Result of API call
*/
function yourls_api_action_shorturl()
{
$url = isset($_REQUEST['url']) ? $_REQUEST['url'] : '';
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
$return = yourls_add_new_link($url, $keyword, $title);
$return['simple'] = isset($return['shorturl']) ? $return['shorturl'] : '';
// This one will be used in case output mode is 'simple'
unset($return['html']);
// in API mode, no need for our internal HTML output
return yourls_apply_filter('api_result_shorturl', $return);
}
示例2: bulk_api_bulkshortener
function bulk_api_bulkshortener($action)
{
if ($action[0] != 'bulkshortener') {
return;
}
if (!isset($_REQUEST['urls'])) {
$return = array('errorCode' => 400, 'message' => 'bulkshortener: missing URLS parameter', 'simple' => 'bulkshortener: missing URLS parameter');
echo $return['errorCode'] . ": " . $return['simple'];
die;
}
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
$urls = isset($_REQUEST['urls']) ? $_REQUEST['urls'] : array();
foreach ($urls as $url) {
$return = yourls_add_new_link($url, $keyword, $title);
echo $return['shorturl'] . "\n";
}
die;
}
示例3: define
<?php
define('YOURLS_API', true);
require_once dirname(__FILE__) . '/includes/load-yourls.php';
yourls_maybe_require_auth();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
yourls_do_action('api', $action);
switch ($action) {
// Shorten a URL
case 'shorturl':
$url = isset($_REQUEST['url']) ? $_REQUEST['url'] : '';
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$title = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
$return = yourls_add_new_link($url, $keyword, $title);
$return['simple'] = isset($return['shorturl']) ? $return['shorturl'] : '';
// This one will be used in case output mode is 'simple'
unset($return['html']);
// in API mode, no need for our internal HTML output
break;
// Global stats
// Global stats
case 'stats':
$filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '';
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : '';
$return = yourls_api_stats($filter, $limit);
break;
// Stats for a shorturl
// Stats for a shorturl
case 'url-stats':
$shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : '';
$return = yourls_api_url_stats($shorturl);
示例4: define
define('YOURLS_ADMIN', true);
define('YOURLS_AJAX', true);
require_once dirname(dirname(__FILE__)) . '/includes/load-yourls.php';
yourls_maybe_require_auth();
// This file will output a JSON string
yourls_content_type_header('application/json');
if (!isset($_REQUEST['action'])) {
die;
}
// Pick action
$action = $_REQUEST['action'];
switch ($action) {
case 'add':
yourls_verify_nonce('add_url', $_REQUEST['nonce'], false, 'omg error');
$return = yourls_add_new_link($_REQUEST['url'], $_REQUEST['keyword']);
echo json_encode($return);
break;
case 'edit_display':
yourls_verify_nonce('edit-link_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error');
$row = yourls_table_edit_row($_REQUEST['keyword']);
echo json_encode(array('html' => $row));
break;
case 'edit_save':
yourls_verify_nonce('edit-save_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error');
$return = yourls_edit_link($_REQUEST['url'], $_REQUEST['keyword'], $_REQUEST['newkeyword'], $_REQUEST['title']);
echo json_encode($return);
break;
case 'delete':
yourls_verify_nonce('delete-link_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error');
$query = yourls_delete_link_by_keyword($_REQUEST['keyword']);
示例5: yourls_do_action
yourls_do_action('bookmarklet');
// No sanitization needed here: everything happens in yourls_add_new_link()
if (isset($_GET['u'])) {
// Old school bookmarklet: ?u=<url>
$url = rawurldecode($_GET['u']);
} else {
// New style bookmarklet: ?up=<url protocol>&us=<url slashes>&ur=<url rest>
$url = rawurldecode($_GET['up'] . $_GET['us'] . $_GET['ur']);
}
$keyword = isset($_GET['k']) ? $_GET['k'] : '';
$title = isset($_GET['t']) ? $_GET['t'] : '';
$return = yourls_add_new_link($url, $keyword, $title);
// If fails because keyword already exist, retry with no keyword
if (isset($return['status']) && $return['status'] == 'fail' && isset($return['code']) && $return['code'] == 'error:keyword') {
$msg = $return['message'];
$return = yourls_add_new_link($url, '', $ydb);
$return['message'] .= ' (' . $msg . ')';
}
// Stop here if bookmarklet with a JSON callback function
if (isset($_GET['jsonp']) && $_GET['jsonp'] == 'yourls') {
$short = $return['shorturl'] ? $return['shorturl'] : '';
$message = $return['message'];
yourls_content_type_header('application/javascript');
echo yourls_apply_filter('bookmarklet_jsonp', "yourls_callback({'short_url':'{$short}','message':'{$message}'});");
die;
}
// Now use the URL that has been sanitized and returned by yourls_add_new_link()
$url = $return['url']['url'];
$where = sprintf(" AND `url` LIKE '%s' ", yourls_escape($url));
$page = $total_pages = $perpage = 1;
$offset = 0;
示例6: yourls_insert_sample_links
/**
* Populates the URL table with a few sample links
*
* @since 1.7
* @return bool
*/
function yourls_insert_sample_links()
{
$link1 = yourls_add_new_link('http://blog.yourls.org/', 'yourlsblog', 'YOURLS\' Blog');
$link2 = yourls_add_new_link('http://yourls.org/', 'yourls', 'YOURLS: Your Own URL Shortener');
$link3 = yourls_add_new_link('http://ozh.org/', 'ozh', 'ozh.org');
return (bool) ($link1['status'] == 'success' & $link2['status'] == 'success' & $link3['status'] == 'success');
}
示例7: jd_shorten_link
//.........这里部分代码省略.........
break;
case 2:
// updated to v3 3/31/2010
$bitlyapi = trim(get_option('bitlyapi'));
$bitlylogin = trim(strtolower(get_option('bitlylogin')));
$decoded = jd_remote_json("https://api-ssl.bitly.com/v3/shorten?longUrl=" . $encoded . "&login=" . $bitlylogin . "&apiKey=" . $bitlyapi . "&format=json");
if ($decoded) {
if ($decoded['status_code'] != 200) {
$shrink = $decoded;
$error = $decoded['status_txt'];
} else {
$shrink = $decoded['data']['url'];
}
} else {
$shrink = false;
}
if (!is_valid_url($shrink)) {
$shrink = false;
}
break;
case 5:
// local YOURLS installation
global $yourls_reserved_URL;
define('YOURLS_INSTALLING', true);
// Pretend we're installing YOURLS to bypass test for install or upgrade
define('YOURLS_FLOOD_DELAY_SECONDS', 0);
// Disable flood check
$opath = get_option('yourlspath');
$ypath = str_replace('user', 'includes', $opath);
if (file_exists(dirname($ypath) . '/load-yourls.php')) {
// YOURLS 1.4+
require_once dirname($ypath) . '/load-yourls.php';
global $ydb;
if (function_exists('yourls_add_new_link')) {
$yourls_result = yourls_add_new_link($url, $keyword_format, $thisposttitle);
} else {
$yourls_result = $url;
}
} else {
// YOURLS 1.3
if (file_exists(get_option('yourslpath'))) {
require_once get_option('yourlspath');
$yourls_db = new wpdb(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST);
$yourls_result = yourls_add_new_link($url, $keyword_format, $yourls_db);
}
}
if ($yourls_result) {
$shrink = $yourls_result['shorturl'];
} else {
$shrink = false;
}
break;
case 6:
// remote YOURLS installation
$yourlslogin = trim(get_option('yourlslogin'));
$yourlsapi = stripcslashes(get_option('yourlsapi'));
$api_url = sprintf(get_option('yourlsurl') . '?username=%s&password=%s&url=%s&format=json&action=shorturl&keyword=%s', $yourlslogin, $yourlsapi, $encoded, $keyword_format);
$json = jd_remote_json($api_url, false);
if ($json) {
$shrink = $json->shorturl;
} else {
$shrink = false;
}
break;
case 7:
$suprapi = trim(get_option('suprapi'));
示例8: wp_ozh_yourls_api_call
function wp_ozh_yourls_api_call($api, $url)
{
global $wp_ozh_yourls;
$shorturl = '';
switch ($api) {
case 'yourls-local':
global $yourls_reserved_URL;
require_once $wp_ozh_yourls['yourls_path'];
$yourls_db = new wpdb(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST);
$yourls_result = yourls_add_new_link($url, '', $yourls_db);
if ($yourls_result) {
$shorturl = $yourls_result['shorturl'];
}
break;
case 'yourls-remote':
$api_url = sprintf($wp_ozh_yourls['yourls_url'] . '?username=%s&password=%s&url=%s&format=json&action=shorturl', $wp_ozh_yourls['yourls_login'], $wp_ozh_yourls['yourls_password'], urlencode($url));
$json = wp_ozh_yourls_remote_json($api_url);
if ($json) {
$shorturl = $json->shorturl;
}
break;
case 'bitly':
$api_url = sprintf('http://api.bit.ly/shorten?version=2.0.1&longUrl=%s&login=%s&apiKey=%s', urlencode($url), $wp_ozh_yourls['bitly_login'], $wp_ozh_yourls['bitly_password']);
$json = wp_ozh_yourls_remote_json($api_url);
if ($json) {
$shorturl = $json->results->{$url}->shortUrl;
}
// bit.ly's API makes ugly JSON, seriously, tbh
break;
case 'rply':
$api_url = sprintf('http://rp.ly/api/trim_url.json?url=%s&username=%s&password=%s', urlencode($url), $wp_ozh_yourls['rply_login'], $wp_ozh_yourls['rply_password']);
$json = wp_ozh_yourls_remote_json($api_url);
if ($json) {
$shorturl = $json->url;
}
break;
case 'trim':
$api_url = sprintf('http://api.tr.im/api/trim_url.json?url=%s&username=%s&password=%s', urlencode($url), $wp_ozh_yourls['trim_login'], $wp_ozh_yourls['trim_password']);
$json = wp_ozh_yourls_remote_json($api_url);
if ($json) {
$shorturl = $json->url;
}
break;
case 'pingfm':
$api_url = 'http://api.ping.fm/v1/url.create';
$body = array('api_key' => 'd0e1aad9057142126728c3dcc03d7edb', 'user_app_key' => $wp_ozh_yourls['pingfm_user_app_key'], 'long_url' => $url);
$xml = wp_ozh_yourls_fetch_url($api_url, 'POST', $body);
if ($xml) {
preg_match_all('!<short_url>[^<]+</short_url>!', $xml, $matches);
$shorturl = $matches[0][0];
}
break;
case 'tinyurl':
$api_url = sprintf('http://tinyurl.com/api-create.php?url=%s', urlencode($url));
$shorturl = wp_ozh_yourls_remote_simple($api_url);
break;
case 'isgd':
$api_url = sprintf('http://is.gd/api.php?longurl=%s', urlencode($url));
$shorturl = wp_ozh_yourls_remote_simple($api_url);
break;
default:
die('Error, unknown service: ' . $api);
}
// at this point, if ($shorturl), it should contain expected short URL. Potential TODO: deal with edge cases?
return $shorturl;
}
示例9: jd_shorten_link
//.........这里部分代码省略.........
if ($decoded) {
if ($decoded['status_code'] != 200) {
$shrink = $decoded;
$error = $decoded['status_txt'];
} else {
$shrink = $decoded['data']['url'];
}
} else {
$shrink = false;
update_option('wp_bitly_error', "JSON result could not be decoded");
}
if (!is_valid_url($shrink)) {
$shrink = false;
update_option('wp_bitly_error', $error);
}
break;
case 3:
$shrink = urldecode($thispostlink);
break;
case 5:
// local YOURLS installation
$thispostlink = urldecode($thispostlink);
global $yourls_reserved_URL;
define('YOURLS_INSTALLING', true);
// Pretend we're installing YOURLS to bypass test for install or upgrade
define('YOURLS_FLOOD_DELAY_SECONDS', 0);
// Disable flood check
$opath = get_option('yourlspath');
$ypath = str_replace('user', 'includes', $opath);
if (file_exists(dirname($ypath) . '/load-yourls.php')) {
// YOURLS 1.4+
global $ydb;
require_once dirname($ypath) . '/load-yourls.php';
if (function_exists('yourls_add_new_link')) {
$yourls_result = yourls_add_new_link($thispostlink, $keyword_format);
} else {
$yourls_result = $thispostlink;
}
} else {
// YOURLS 1.3
require_once get_option('yourlspath');
$yourls_db = new wpdb(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST);
$yourls_result = yourls_add_new_link($thispostlink, $keyword_format, $yourls_db);
}
if ($yourls_result) {
$shrink = $yourls_result['shorturl'];
} else {
$shrink = false;
}
break;
case 6:
// remote YOURLS installation
$api_url = sprintf(get_option('yourlsurl') . '?username=%s&password=%s&url=%s&format=json&action=shorturl&keyword=%s', $yourlslogin, $yourlsapi, $thispostlink, $keyword_format);
$json = jd_remote_json($api_url, false);
if ($json) {
$shrink = $json->shorturl;
} else {
$shrink = false;
}
break;
case 7:
if ($suprapi != '') {
$decoded = jd_remote_json("http://su.pr/api/shorten?longUrl=" . $thispostlink . "&login=" . $suprlogin . "&apiKey=" . $suprapi);
} else {
$decoded = jd_remote_json("http://su.pr/api/shorten?longUrl=" . $thispostlink);
}
示例10: define
<?php
define('YOURLS_API', true);
require_once dirname(__FILE__) . '/includes/load-yourls.php';
yourls_maybe_require_auth();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
switch ($action) {
case 'shorturl':
$url = isset($_REQUEST['url']) ? $_REQUEST['url'] : '';
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$return = yourls_add_new_link($url, $keyword);
$return['simple'] = isset($return['shorturl']) ? $return['shorturl'] : '';
// This one will be used in case output mode is 'simple'
unset($return['html']);
// in API mode, no need for our internal HTML output
break;
case 'stats':
$filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '';
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : '';
$return = yourls_api_stats($filter, $limit);
break;
case 'url-stats':
$shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : '';
$return = yourls_api_url_stats($shorturl);
break;
case 'expand':
$shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : '';
$return = yourls_api_expand($shorturl);
break;
default:
$return = array('errorCode' => 400, 'message' => 'Unknown or missing "action" parameter', 'simple' => 'Unknown or missing "action" parameter');
示例11: my_upload_and_shorten_save_files
function my_upload_and_shorten_save_files()
{
// once again for translations:
$my_upload_and_shorten_domain = 'upload-and-shorten';
// did the user select any file?
if ($_FILES['file_upload']['error'] == UPLOAD_ERR_NO_FILE) {
return yourls_esc_html__('You need to select a file to upload.', $my_upload_and_shorten_domain);
}
// yes!
$my_url = SHARE_URL;
// has to be defined in user/config.php like this:
// define( 'SHARE_URL', 'http://my.domain.tld/directory/' );
$my_uploaddir = SHARE_DIR;
// has to be defined in user/config.php like this:
// define( 'SHARE_DIR', '/full/path/to/httpd/directory/' );
$my_extension = pathinfo($_FILES['file_upload']['name'], PATHINFO_EXTENSION);
$my_filename = pathinfo($_FILES['file_upload']['name'], PATHINFO_FILENAME);
if (isset($_POST['randomize_filename'])) {
// make up a random name for the uploaded file
// see http://www.mattytemple.com/projects/yourls-share-files/?replytocom=26686#respond
$my_safe_filename = substr(md5($my_filename . strtotime("now")), 0, 12);
// end randomize filename
} else {
// original code:
$my_filename_trim = trim($my_filename);
$my_RemoveChars = array("([ ])", "([^a-zA-Z0-9-])", "(-{2,})");
$my_ReplaceWith = array("-", "", "-");
$my_safe_filename = preg_replace($my_RemoveChars, $my_ReplaceWith, $my_filename_trim);
// end original code
}
// avoid duplicate filenames
$my_count = 2;
$my_path = $my_uploaddir . $my_safe_filename . '.' . $my_extension;
$my_final_file_name = $my_safe_filename . '.' . $my_extension;
while (file_exists($my_path)) {
$my_path = $my_uploaddir . $my_safe_filename . '-' . $my_count . '.' . $my_extension;
$my_final_file_name = $my_safe_filename . '-' . $my_count . '.' . $my_extension;
$my_count++;
}
// move the file from /tmp/ to destination and initiate link creation
if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $my_path)) {
$my_custom_keyword = NULL;
if (isset($_POST['custom_keyword']) && $_POST['custom_keyword'] != '') {
$my_custom_keyword = $_POST['custom_keyword'];
}
$my_short_url = yourls_add_new_link($my_url . $my_final_file_name, $my_custom_keyword, $my_final_file_name);
return yourls_esc_html__('Upload finished. This is your short-URL: ', $my_upload_and_shorten_domain) . '<a href="' . $my_short_url['shorturl'] . '" target="_blank">' . $my_short_url['shorturl'] . '</a></strong>';
} else {
return yourls_esc_html__('Upload failed! Something went wrong, sorry! :(', $my_upload_and_shorten_domain);
}
}
示例12: rawurldecode
// No sanitization needed here: everything happens in yourls_add_new_link()
if (isset($_GET['u'])) {
// Old school bookmarklet: ?u=<url>
$url = rawurldecode($_GET['u']);
} else {
// New style bookmarklet: ?up=<url protocol>&us=<url slashes>&ur=<url rest>
$url = rawurldecode($_GET['up'] . $_GET['us'] . $_GET['ur']);
}
$keyword = isset($_GET['k']) ? $_GET['k'] : '';
$title = isset($_GET['t']) ? $_GET['t'] : '';
$pass = isset($_GET['p']) ? $_GET['p'] : '';
$return = yourls_add_new_link($url, $keyword, $title, $pass);
// If fails because keyword already exist, retry with no keyword
if (isset($return['status']) && $return['status'] == 'fail' && isset($return['code']) && $return['code'] == 'error:keyword') {
$msg = $return['message'];
$return = yourls_add_new_link($url, '', $ydb, $pass);
$return['message'] .= ' (' . $msg . ')';
}
// Stop here if bookmarklet with a JSON callback function
if (isset($_GET['jsonp']) && $_GET['jsonp'] == 'yourls') {
$short = $return['shorturl'] ? $return['shorturl'] : '';
$message = $return['message'];
yourls_content_type_header('application/javascript');
echo yourls_apply_filter('bookmarklet_jsonp', "yourls_callback({'short_url':'{$short}','message':'{$message}'});");
die;
}
// Now use the URL that has been sanitized and returned by yourls_add_new_link()
$url = $return['url']['url'];
$where = sprintf(" AND `url` LIKE '%s' ", yourls_escape($url));
$page = $total_pages = $perpage = 1;
$offset = 0;