<?php 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');
$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; $text = isset($_GET['s']) ? stripslashes($_GET['s']) : ''; // Sharing with social bookmarklets if (!empty($_GET['share'])) { yourls_do_action('pre_share_redirect'); switch ($_GET['share']) { case 'twitter': // share with Twitter
/** * Return API result. Dies after this * */ function yourls_api_output($mode, $return) { if (isset($return['simple'])) { $simple = $return['simple']; unset($return['simple']); } yourls_do_action('pre_api_output', $mode, $return); if (isset($return['statusCode'])) { $code = $return['statusCode']; } elseif (isset($return['errorCode'])) { $code = $return['errorCode']; } else { $code = 200; } yourls_status_header($code); switch ($mode) { case 'jsonp': yourls_content_type_header('application/javascript'); echo $return['callback'] . '(' . json_encode($return) . ')'; break; case 'json': yourls_content_type_header('application/json'); echo json_encode($return); break; case 'xml': yourls_content_type_header('application/xml'); echo yourls_xml_encode($return); break; case 'simple': default: yourls_content_type_header('text/plain'); if (isset($simple)) { echo $simple; } break; } yourls_do_action('api_output', $mode, $return); die; }
/** * Display HTML head and <body> tag * * @param string $context Context of the page (stats, index, infos, ...) * @param string $title HTML title of the page */ function yourls_html_head($context = 'index', $title = '') { yourls_do_action('pre_html_head', $context, $title); // All components to false, except when specified true $share = $insert = $tablesorter = $tabs = $cal = $charts = false; // Load components as needed switch ($context) { case 'infos': $share = $tabs = $charts = true; break; case 'bookmark': $share = $insert = $tablesorter = true; break; case 'index': $insert = $tablesorter = $cal = $share = true; break; case 'plugins': case 'tools': $tablesorter = true; break; case 'install': case 'login': case 'new': case 'upgrade': break; } // Force no cache for all admin pages if (yourls_is_admin() && !headers_sent()) { header('Expires: Thu, 23 Mar 1972 07:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate, max-age=0'); header('Pragma: no-cache'); yourls_content_type_header(yourls_apply_filter('html_head_content-type', 'text/html')); yourls_do_action('admin_headers', $context, $title); } // Store page context in global object global $ydb; $ydb->context = $context; // Body class $bodyclass = yourls_apply_filter('bodyclass', ''); $bodyclass .= yourls_is_mobile_device() ? 'mobile' : 'desktop'; // Page title $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link(); $title = $title ? $title . " « " . $_title : $_title; $title = yourls_apply_filter('html_title', $title, $context); ?> <!DOCTYPE html> <html <?php yourls_html_language_attributes(); ?> > <head> <title><?php echo $title; ?> </title> <link rel="shortcut icon" href="<?php yourls_favicon(); ?> " /> <meta http-equiv="Content-Type" content="<?php echo yourls_apply_filter('html_head_meta_content-type', 'text/html; charset=utf-8'); ?> " /> <meta name="generator" content="YOURLS <?php echo YOURLS_VERSION; ?> " /> <meta name="description" content="YOURLS » Your Own URL Shortener' | <?php yourls_site_url(); ?> " /> <meta name="referrer" content="always" /> <script src="<?php yourls_site_url(); ?> /js/jquery-1.9.1.min.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <script src="<?php yourls_site_url(); ?> /js/common.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <script src="<?php yourls_site_url(); ?> /js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <link rel="stylesheet" href="<?php yourls_site_url(); ?> /css/style.css?v=<?php echo YOURLS_VERSION; ?> " type="text/css" media="screen" /> <?php if ($tabs) { ?> <link rel="stylesheet" href="<?php yourls_site_url(); ?> /css/infos.css?v=<?php echo YOURLS_VERSION; ?> " type="text/css" media="screen" /> <script src="<?php yourls_site_url(); ?> /js/infos.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <?php } ?> <?php if ($tablesorter) { ?> <link rel="stylesheet" href="<?php yourls_site_url(); ?> /css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?> " type="text/css" media="screen" /> <script src="<?php yourls_site_url(); ?> /js/jquery.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <?php } ?> <?php if ($insert) { ?> <script src="<?php yourls_site_url(); ?> /js/insert.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <?php } ?> <?php if ($share) { ?> <link rel="stylesheet" href="<?php yourls_site_url(); ?> /css/share.css?v=<?php echo YOURLS_VERSION; ?> " type="text/css" media="screen" /> <script src="<?php yourls_site_url(); ?> /js/share.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <script src="<?php yourls_site_url(); ?> /js/clipboard.min.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <?php } ?> <?php if ($cal) { ?> <link rel="stylesheet" href="<?php yourls_site_url(); ?> /css/cal.css?v=<?php echo YOURLS_VERSION; ?> " type="text/css" media="screen" /> <?php yourls_l10n_calendar_strings(); ?> <script src="<?php yourls_site_url(); ?> /js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?> " type="text/javascript"></script> <?php } ?> <?php if ($charts) { ?> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1.0', {'packages':['corechart', 'geochart']}); </script> <?php } ?> <script type="text/javascript"> //<![CDATA[ var ajaxurl = '<?php echo yourls_admin_url('admin-ajax.php'); ?> '; //]]> </script> <?php yourls_do_action('html_head', $context); ?> </head> <body class="<?php echo $context; ?> <?php echo $bodyclass; ?> "> <div id="wrap"> <?php }
/** * Output and return API result * * This function will echo (or only return if asked) an array as JSON, JSONP or XML. If the array has a * 'simple' key, it can also output that key as unformatted text if expected output mode is 'simple' * * Most likely, script should not do anything after outputting this * * @since 1.6 * * @param string $mode Expected output mode ('json', 'jsonp', 'xml', 'simple') * @param array $output Array of things to output * @param bool $send_headers Optional, default true: Whether a headers (status, content type) should be sent or not * @param bool $echo Optional, default true: Whether the output should be outputted or just returned * @return string API output, as an XML / JSON / JSONP / raw text string */ function yourls_api_output($mode, $output, $send_headers = true, $echo = true) { if (isset($output['simple'])) { $simple = $output['simple']; unset($output['simple']); } yourls_do_action('pre_api_output', $mode, $output, $send_headers, $echo); if ($send_headers) { if (isset($output['statusCode'])) { $code = $output['statusCode']; } elseif (isset($output['errorCode'])) { $code = $output['errorCode']; } else { $code = 200; } yourls_status_header($code); } $result = ''; switch ($mode) { case 'jsonp': if ($send_headers) { yourls_content_type_header('application/javascript'); } $callback = isset($output['callback']) ? $output['callback'] : ''; $result = $callback . '(' . json_encode($output) . ')'; break; case 'json': if ($send_headers) { yourls_content_type_header('application/json'); } $result = json_encode($output); break; case 'xml': if ($send_headers) { yourls_content_type_header('application/xml'); } $result = yourls_xml_encode($output); break; case 'simple': default: if ($send_headers) { yourls_content_type_header('text/plain'); } $result = isset($simple) ? $simple : ''; break; } if ($echo) { echo $result; } yourls_do_action('api_output', $mode, $output, $send_headers, $echo); return $result; }