function ozh_preview_show($keyword) { require_once YOURLS_INC . '/functions-html.php'; yourls_html_head('preview', 'Short URL preview'); yourls_html_logo(); $title = yourls_get_keyword_title($keyword); $url = yourls_get_keyword_longurl($keyword); $base = YOURLS_SITE; $char = OZH_PREVIEW_CHAR; echo <<<HTML <h2>Link Preview</h2> <p>You requested the short URL <strong><a href="{$base}/{$keyword}">{$base}/{$keyword}</a></strong></p> <p>This short URL points to:</p> <ul> <li>Long URL: <strong><a href="{$base}/{$keyword}">{$url}</a></strong></li> <li>Page title: <strong>{$title}</strong></li> </ul> <p>If you still want to visit this link, please <strong><a href="{$base}/{$keyword}">click here</a></strong>.</p> <p>Thank you for using our shortening service.</p> HTML; yourls_html_footer(); }
if (!isset($keyword) && isset($_GET['id'])) { $keyword = $_GET['id']; } if (!isset($aggregate) && isset($_GET['all']) && $_GET['all'] == 1 && yourls_allow_duplicate_longurls()) { $aggregate = true; } if (!isset($keyword)) { 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); } yourls_do_action('pre_yourls_infos', $keyword); if (yourls_do_log_redirect()) { $table = YOURLS_DB_TABLE_LOG; $referrers = array(); $direct = $notdirect = 0; $countries = array();
function power_ga_mp_trackCurrent($unused) { global $keyword; power_ga_mp($keyword, yourls_get_keyword_title($keyword), $_SERVER['HTTP_REFERER']); return $unused; }
/** * Return an "Edit" row for the main table * * @param string $keyword Keyword to edit * @return string HTML of the edit row */ function yourls_table_edit_row($keyword) { $keyword = yourls_sanitize_string($keyword); $id = yourls_string2htmlid($keyword); // used as HTML #id $url = yourls_get_keyword_longurl($keyword); $title = htmlspecialchars(yourls_get_keyword_title($keyword)); $safe_url = yourls_esc_attr(rawurldecode($url)); $safe_title = yourls_esc_attr($title); // Make strings sprintf() safe: '%' -> '%%' $safe_url = str_replace('%', '%%', $safe_url); $safe_title = str_replace('%', '%%', $safe_title); $www = yourls_link(); $nonce = yourls_create_nonce('edit-save_' . $id); if ($url) { $return = <<<RETURN <tr id="edit-{$id}" class="edit-row"><td colspan="5" class="edit-row"><strong>%s</strong>:<input type="text" id="edit-url-{$id}" name="edit-url-{$id}" value="{$safe_url}" class="text" size="70" /><br/><strong>%s</strong>: {$www}<input type="text" id="edit-keyword-{$id}" name="edit-keyword-{$id}" value="{$keyword}" class="text" size="10" /><br/><strong>%s</strong>: <input type="text" id="edit-title-{$id}" name="edit-title-{$id}" value="{$safe_title}" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-{$id}" name="edit-submit-{$id}" value="%s" title="%s" class="button" onclick="edit_link_save('{$id}');" /> <input type="button" id="edit-close-{$id}" name="edit-close-{$id}" value="%s" title="%s" class="button" onclick="edit_link_hide('{$id}');" /><input type="hidden" id="old_keyword_{$id}" value="{$keyword}"/><input type="hidden" id="nonce_{$id}" value="{$nonce}"/></td></tr> RETURN; $return = sprintf($return, yourls__('Long URL'), yourls__('Short URL'), yourls__('Title'), yourls__('Save'), yourls__('Save new values'), yourls__('Cancel'), yourls__('Cancel editing')); } else { $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__('Error, URL not found') . '</td></tr>'; } $return = yourls_apply_filter('table_edit_row', $return, $keyword, $url, $title); return $return; }
/** * Expand short url to long url * */ function yourls_api_expand($shorturl) { $keyword = str_replace(YOURLS_SITE . '/', '', $shorturl); // accept either 'http://ozh.in/abc' or 'abc' $keyword = yourls_sanitize_string($keyword); $longurl = yourls_get_keyword_longurl($keyword); if ($longurl) { $return = array('keyword' => $keyword, 'shorturl' => YOURLS_SITE . "/{$keyword}", 'longurl' => $longurl, 'title' => yourls_get_keyword_title($keyword), 'simple' => $longurl, 'message' => 'success', 'statusCode' => 200); } else { $return = array('keyword' => $keyword, 'simple' => 'not found', 'message' => 'Error: short URL not found', 'errorCode' => 404); } return yourls_apply_filter('api_expand', $return, $shorturl); }
function ozh_toolbar_do($args) { global $ozh_toolbar; // Does this redirection need a toolbar? if (!$ozh_toolbar['do']) { return; } // Do we have a cookie stating the user doesn't want a toolbar? if (isset($_COOKIE['yourls_no_toolbar']) && $_COOKIE['yourls_no_toolbar'] == 1) { return; } // Get URL and page title $url = $args[0]; $pagetitle = yourls_get_keyword_title($ozh_toolbar['keyword']); // Update title if it hasn't been stored yet if ($pagetitle == '') { $pagetitle = yourls_get_remote_title($url); yourls_edit_link_title($ozh_toolbar['keyword'], $pagetitle); } $_pagetitle = htmlentities(yourls_get_remote_title($url)); $www = YOURLS_SITE; $ver = YOURLS_VERSION; $md5 = md5($url); $sql = yourls_get_num_queries(); // When was the link created (in days) $diff = abs(time() - strtotime(yourls_get_keyword_timestamp($ozh_toolbar['keyword']))); $days = floor($diff / (60 * 60 * 24)); if ($days == 0) { $created = 'today'; } else { $created = $days . ' ' . yourls_plural('day', $days) . ' ago'; } // How many hits on the page $hits = 1 + yourls_get_keyword_clicks($ozh_toolbar['keyword']); $hits = $hits . ' ' . yourls_plural('view', $hits); // Plugin URL (no URL is hardcoded) $pluginurl = YOURLS_PLUGINURL . '/' . yourls_plugin_basename(dirname(__FILE__)); // All set. Draw the toolbar itself. echo <<<PAGE <html> <head> \t<title>{$pagetitle} — YOURLS</title> \t<link rel="icon" type="image/gif" href="{$www}/images/favicon.gif" /> \t<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \t<meta http-equiv="X-UA-Compatible" content="chrome=1" /> \t<meta name="generator" content="YOURLS v{$ver}" /> \t<meta name="ROBOTS" content="NOINDEX, FOLLOW" /> \t<link rel="stylesheet" href="{$pluginurl}/css/toolbar.css" type="text/css" media="all" /> </head> <body> <div id="yourls-bar"> \t<div id="yourls-about"> \t\tShort link powered by <a href="http://yourls.org/">YOURLS</a> and created {$created}. {$hits}. \t\t<!-- {$sql} queries --> \t</div> \t \t<div id="yourls-delicious"> \t<img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" /> \t<a id="yourls-delicious-link" title="Bookmark on delicious" href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark on Delicious</a> \t</div> \t<script type="text/javascript" id="topsy_global_settings"> \tvar topsy_theme = "light-blue"; \tvar topsy_nick = " "; \tvar topsy_style = "small"; \tvar topsy_order = "count,retweet,badge"; \t</script> \t<div id="yourls-topsy" class="topsy_widget_data"> \t\t<!--{ \t\t "url": "{$www}/{$ozh_toolbar['keyword']}", \t\t "title": "{$_pagetitle}", \t\t}--> \t</div> \t \t<div id="yourls-selfclose"> \t\t<a id="yourls-once" href="{$url}" title="Close this toolbar">close</a> \t\t<a id="yourls-always" href="{$url}" title="Never show me this toolbar again">close</a> \t\t \t</div> </div> <iframe id="yourls-frame" frameborder="0" noresize="noresize" src="{$url}" name="yourlsFrame"></iframe> <script type="text/javascript" src="{$pluginurl}/js/toolbar.js"></script> <script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script> <script type="text/javascript" src="http://feeds.delicious.com/v2/json/urlinfo/{$md5}?callback=yourls_get_books"></script> </body> </html> PAGE; // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL) die; }
function yourls_table_edit_row($keyword) { global $ydb; $table = YOURLS_DB_TABLE_URL; $keyword = yourls_sanitize_string($keyword); $id = yourls_string2int($keyword); // used as HTML #id $url = yourls_get_keyword_longurl($keyword); $title = htmlspecialchars(yourls_get_keyword_title($keyword)); $safe_url = stripslashes($url); $safe_title = stripslashes($title); $www = YOURLS_SITE; $save_link = yourls_nonce_url('save-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'edit_save', 'keyword' => $keyword), yourls_admin_url('admin-ajax.php'))); $nonce = yourls_create_nonce('edit-save_' . $id); if ($url) { $return = <<<RETURN <tr id="edit-{$id}" class="edit-row"><td colspan="5"><strong>Original URL</strong>:<input type="text" id="edit-url-{$id}" name="edit-url-{$id}" value="{$safe_url}" class="text" size="70" /> <strong>Short URL</strong>: {$www}/<input type="text" id="edit-keyword-{$id}" name="edit-keyword-{$id}" value="{$keyword}" class="text" size="10" /><br/><strong>Title</strong>: <input type="text" id="edit-title-{$id}" name="edit-title-{$id}" value="{$title}" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-{$id}" name="edit-submit-{$id}" value="Save" title="Save new values" class="button" onclick="edit_save('{$id}');" /> <input type="button" id="edit-close-{$id}" name="edit-close-{$id}" value="X" title="Cancel editing" class="button" onclick="hide_edit('{$id}');" /><input type="hidden" id="old_keyword_{$id}" value="{$keyword}"/><input type="hidden" id="nonce_{$id}" value="{$nonce}"/></td></tr> RETURN; } else { $return = '<tr><td colspan="6">Error, URL not found</td></tr>'; } $return = yourls_apply_filter('table_edit_row', $return, $keyword, $url, $title); return $return; }
/** * Sends the keyword and destination URL to Piwik * * @param bool $return The value to return. Defaults to false with doesn't enable the filter * @param string $keyword The requested keyword * @return bool */ function itfs_piwik_log_request($return, $keyword) { // Get current configuration from database $piwik_config = yourls_get_option('piwik_config'); // Let's check if the user wants to log bots if ($piwik_config[remove_bots]) { if (itfs_piwik_is_bot()) { return $return; } } try { // Need to use a file_exists check as require only produces a fatal compilation error if (!file_exists(dirname(__FILE__) . '/libs/Piwik/PiwikTracker.php')) { throw new Exception("Error can't load PiwikTracker.php"); } else { // Piwik Tracking API init require_once dirname(__FILE__) . '/libs/Piwik/PiwikTracker.php'; PiwikTracker::$URL = $piwik_config[piwik_url]; } } catch (Exception $e) { error_log("ITFS_PIWIK: " . $e->getMessage(), 0); return $return; } // Use this to get the destination $destination = yourls_get_keyword_longurl($keyword); // Only log a request if we have a destination and the proper Piwik settings if ($destination == false) { error_log("ITFS_PIWIK: Missing parameters prevented me from logging the request with Piwik", 0); error_log("ITFS_PIWIK: Parameters we have: " . $keyword . ', ' . $destination, 0); return $return; } //Useful for hosts using one Piwik installation with multiple YOURLS installation $domain_landed = $_SERVER['HTTP_HOST']; $page_url = "http://" . $domain_landed . "/" . $keyword; try { $pt = new PiwikTracker($piwik_config[site_id]); // This will be the entry page in Piwik $pt->setUrl($page_url); // This will fail silently if the token is not valid or if the user doesn't have admin rights if (!empty($piwik_config[token])) { $pt->setTokenAuth($piwik_config[token]); } // This shows up in the visitor logs and identify the source of the data $pt->setCustomVariable(1, 'App', 'Piwik plugin for YOURLS', 'visit'); // Some useful variables $pt->setCustomVariable(2, 'Domain landed', $domain_landed, 'page'); $pt->setCustomVariable(3, 'Keyword', $keyword, 'page'); // User defined custom variable if (!empty($piwik_config[customvar_name]) && !empty($piwik_config[customvar_value])) { $pt->setCustomVariable(4, $piwik_config[customvar_name], $piwik_config[customvar_value], $piwik_config[customvar_scope]); } // Track the visit in Piwik $title = yourls_get_keyword_title($keyword); @$pt->doTrackPageView($title); // The destination URL will show up as an outlink @$pt->doTrackAction($destination, 'link'); } catch (Exception $e) { error_log("ITFS_PIWIK: Error when trying to log the request with Piwik. " . $e->getMessage(), 0); return $return; } if ($piwik_config[disable_stats]) { //error_log("ITFS_PIWIK: NOT logging locally", 0); return; } else { //error_log("ITFS_PIWIK: Logging locally", 0); return $return; } }
/** * Return an "Edit" row for the main table * * @param string $keyword Keyword to edit * @return string HTML of the edit row */ function yourls_table_edit_row($keyword) { global $ydb; $table = YOURLS_DB_TABLE_URL; $keyword = yourls_sanitize_string($keyword); $id = yourls_string2htmlid($keyword); // used as HTML #id $url = yourls_get_keyword_longurl($keyword); $title = htmlspecialchars(yourls_get_keyword_title($keyword)); $safe_url = yourls_esc_attr($url); $safe_title = yourls_esc_attr($title); $www = yourls_link(); $save_link = yourls_nonce_url('save-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'edit_save', 'keyword' => $keyword), yourls_admin_url('admin-ajax.php'))); $nonce = yourls_create_nonce('edit-save_' . $id); if ($url) { $return = <<<RETURN <tr id="edit-{$id}" class="edit-row"><td colspan="5" class="edit-row"><strong>%s</strong>:<input type="text" id="edit-url-{$id}" name="edit-url-{$id}" value="{$safe_url}" class="text" size="70" /><br/><strong>%s</strong>: {$www}<input type="text" id="edit-keyword-{$id}" name="edit-keyword-{$id}" value="{$keyword}" class="text" size="10" /><br/><strong>%s</strong>: <input type="text" id="edit-title-{$id}" name="edit-title-{$id}" value="{$safe_title}" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-{$id}" name="edit-submit-{$id}" value="%s" title="%s" class="button" onclick="edit_link_save('{$id}');" /> <input type="button" id="edit-close-{$id}" name="edit-close-{$id}" value="%s" title="%s" class="button" onclick="edit_link_hide('{$id}');" /><input type="hidden" id="old_keyword_{$id}" value="{$keyword}"/><input type="hidden" id="nonce_{$id}" value="{$nonce}"/></td></tr> RETURN; $return = sprintf(urldecode($return), yourls__('Long URL'), yourls__('Short URL'), yourls__('Title'), yourls__('Save'), yourls__('Save new values'), yourls__('Cancel'), yourls__('Cancel editing')); } else { $return = '<tr class="edit-row notfound">><td colspan="6" class="edit-row notfound">' . yourls__('Error, URL not found') . '</td></tr>'; } $return = yourls_apply_filter('table_edit_row', $return, $keyword, $url, $title); return $return; }