Advertisement
protools905

yourls my functions.html

Jul 27th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.98 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Display <h1> header and logo
  5. *
  6. */
  7. function yourls_html_logo() {
  8. yourls_do_action( 'pre_html_logo' );
  9. ?>
  10. <h1>
  11. <a href="<?php echo yourls_admin_url( 'index.php' ) ?>" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/>
  12. <img src="<?php yourls_site_url(); ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" border="0" style="border: 0px;" /></a>
  13. </h1>
  14. <?php
  15. yourls_do_action( 'html_logo' );
  16. }
  17.  
  18. /**
  19. * Display HTML head and <body> tag
  20. *
  21. * @param string $context Context of the page (stats, index, infos, ...)
  22. * @param string $title HTML title of the page
  23. */
  24. function yourls_html_head( $context = 'index', $title = '' ) {
  25.  
  26. yourls_do_action( 'pre_html_head', $context, $title );
  27.  
  28. // All components to false, except when specified true
  29. $share = $insert = $tablesorter = $tabs = $cal = $charts = false;
  30.  
  31. // Load components as needed
  32. switch ( $context ) {
  33. case 'infos':
  34. $share = $tabs = $charts = true;
  35. break;
  36.  
  37. case 'bookmark':
  38. $share = $insert = $tablesorter = true;
  39. break;
  40.  
  41. case 'index':
  42. $insert = $tablesorter = $cal = $share = true;
  43. break;
  44.  
  45. case 'plugins':
  46. case 'tools':
  47. $tablesorter = true;
  48. break;
  49.  
  50. case 'install':
  51. case 'login':
  52. case 'new':
  53. case 'upgrade':
  54. break;
  55. }
  56.  
  57. // Force no cache for all admin pages
  58. if( yourls_is_admin() && !headers_sent() ) {
  59. header( 'Expires: Thu, 23 Mar 1972 07:00:00 GMT' );
  60. header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
  61. header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
  62. header( 'Pragma: no-cache' );
  63. yourls_content_type_header( yourls_apply_filters( 'html_head_content-type', 'text/html' ) );
  64. yourls_do_action( 'admin_headers', $context, $title );
  65. }
  66.  
  67. // Store page context in global object
  68. global $ydb;
  69. $ydb->context = $context;
  70.  
  71. // Body class
  72. $bodyclass = yourls_apply_filter( 'bodyclass', '' );
  73. $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' );
  74.  
  75. // Page title
  76. $_title = 'YOURLS &mdash; Your Own URL Shortener | ' . yourls_link();
  77. $title = $title ? $title . " &laquo; " . $_title : $_title;
  78. $title = yourls_apply_filter( 'html_title', $title, $context );
  79.  
  80. ?>
  81. <!DOCTYPE html>
  82. <html <?php yourls_html_language_attributes(); ?>>
  83. <head>
  84. <title><?php echo $title ?></title>
  85. <link rel="shortcut icon" href="<?php yourls_favicon(); ?>" />
  86. <meta http-equiv="Content-Type" content="<?php echo yourls_apply_filters( 'html_head_meta_content-type', 'text/html; charset=utf-8' ); ?>" />
  87. <meta http-equiv="X-UA-Compatible" content="IE-9"/>
  88. <meta name="author" content="Ozh RICHARD & Lester CHAN for http://yourls.org/" />
  89. <meta name="generator" content="YOURLS <?php echo YOURLS_VERSION ?>" />
  90. <meta name="description" content="Insert URL &laquo; YOURLS &raquo; Your Own URL Shortener' | <?php yourls_site_url(); ?>" />
  91. <script src="<?php yourls_site_url(); ?>/js/jquery-1.9.1.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  92. <script src="<?php yourls_site_url(); ?>/js/common.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  93. <script src="<?php yourls_site_url(); ?>/js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  94. <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
  95. <?php if ( $tabs ) { ?>
  96. <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
  97. <script src="<?php yourls_site_url(); ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  98. <?php } ?>
  99. <?php if ( $tablesorter ) { ?>
  100. <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
  101. <script src="<?php yourls_site_url(); ?>/js/jquery.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  102. <?php } ?>
  103. <?php if ( $insert ) { ?>
  104. <script src="<?php yourls_site_url(); ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  105. <?php } ?>
  106. <?php if ( $share ) { ?>
  107. <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
  108. <script src="<?php yourls_site_url(); ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  109. <script src="<?php yourls_site_url(); ?>/js/jquery.zclip.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  110. <?php } ?>
  111. <?php if ( $cal ) { ?>
  112. <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" />
  113. <?php yourls_l10n_calendar_strings(); ?>
  114. <script src="<?php yourls_site_url(); ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script>
  115. <?php } ?>
  116. <?php if ( $charts ) { ?>
  117. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  118. <script type="text/javascript">
  119. google.load('visualization', '1.0', {'packages':['corechart', 'geochart']});
  120. </script>
  121. <?php } ?>
  122. <script type="text/javascript">
  123. //<![CDATA[
  124. var ajaxurl = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>';
  125. var zclipurl = '<?php yourls_site_url(); ?>/js/ZeroClipboard.swf';
  126. //]]>
  127. </script>
  128. <?php yourls_do_action( 'html_head', $context ); ?>
  129. <script type="text/javascript"
  130. src="http://api.solvemedia.com/papi/challenge.script?k=.VFjTYIriMq.fY7EHO1b23IABhiVaC4F">
  131. </script>
  132. </head>
  133. <body class="<?php echo $context; ?> <?php echo $bodyclass; ?>">
  134. <div id="wrap">
  135. <?php
  136. }
  137.  
  138. /**
  139. * Display HTML footer (including closing body & html tags)
  140. *
  141. */
  142. function yourls_html_footer() {
  143. global $ydb;
  144.  
  145. $num_queries = sprintf( yourls_n( '1 query', '%s queries', $ydb->num_queries ), $ydb->num_queries );
  146. ?>
  147. </div> <?php // wrap ?>
  148. <div id="footer"><p>
  149. <?php
  150. $footer = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION );
  151. $footer .= ' &ndash; '.$num_queries;
  152. echo yourls_apply_filters( 'html_footer_text', $footer );
  153. ?>
  154. </p></div>
  155. <?php if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) {
  156. echo '<div style="text-align:left"><pre>';
  157. echo join( "\n", $ydb->debug_log );
  158. echo '</div>';
  159. } ?>
  160. <?php yourls_do_action( 'html_footer', $ydb->context ); ?>
  161. </body>
  162. </html>
  163. <?php
  164. }
  165.  
  166. /**
  167. * Display "Add new URL" box
  168. *
  169. * @param string $url URL to prefill the input with
  170. * @param string $keyword Keyword to prefill the input with
  171. */
  172. function yourls_html_addnew( $url = '', $keyword = '' ) {
  173. $url = $url ? $url : 'http://';
  174. ?>
  175. <div id="new_url">
  176. <div>
  177. <form id="new_url_form" action="" method="get">
  178. <div><strong><?php yourls_e( 'Enter the URL' ); ?></strong>:<input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" />
  179. <?php yourls_e( 'Optional '); ?>: <strong><?php yourls_e('Custom short URL'); ?></strong>:<input type="text" id="add-keyword" name="keyword" value="<?php echo $keyword; ?>" class="text" size="8" />
  180. <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?>
  181. <input type="button" id="add-button" name="add-button" value="<?php yourls_e( 'Shorten The URL' ); ?>" class="button" onclick="add_link();" /></div>
  182. </form>
  183. <div id="feedback" style="display:none"></div>
  184. </div>
  185. <?php yourls_do_action( 'html_addnew' ); ?>
  186. </div>
  187. <?php
  188. }
  189.  
  190. /**
  191. * Display main table's footer
  192. *
  193. * The $param array is defined in /admin/index.php, check the yourls_html_tfooter() call
  194. *
  195. * @param array $params Array of all required parameters
  196. * @return string Result
  197. */
  198. function yourls_html_tfooter( $params = array() ) {
  199. extract( $params ); // extract $search_text, $page, $search_in ...
  200. ?>
  201. <tfoot>
  202. <tr>
  203. <th colspan="6">
  204. <div id="filter_form">
  205. <form action="" method="get">
  206. <div id="filter_options">
  207. <?php
  208.  
  209. // First search control: text to search
  210. $_input = '<input type="text" name="search" class="text" size="12" value="' . yourls_esc_attr( $search_text ) . '" />';
  211. $_options = array(
  212. 'keyword' => yourls__( 'Short URL' ),
  213. 'url' => yourls__( 'URL' ),
  214. 'title' => yourls__( 'Title' ),
  215. 'ip' => yourls__( 'IP' ),
  216. );
  217. $_select = yourls_html_select( 'search_in', $_options, $search_in );
  218. /* //translators: "Search for <input field with text to search> in <select dropdown with URL, title...>" */
  219. yourls_se( 'Search for %1$s in %2$s', $_input , $_select );
  220. echo "&ndash;\n";
  221.  
  222. // Second search control: order by
  223. $_options = array(
  224. 'keyword' => yourls__( 'Short URL' ),
  225. 'url' => yourls__( 'URL' ),
  226. 'timestamp' => yourls__( 'Date' ),
  227. 'ip' => yourls__( 'IP' ),
  228. 'clicks' => yourls__( 'Clicks' ),
  229. );
  230. $_select = yourls_html_select( 'sort_by', $_options, $sort_by );
  231. $sort_order = isset( $sort_order ) ? $sort_order : 'desc' ;
  232. $_options = array(
  233. 'asc' => yourls__( 'Ascending' ),
  234. 'desc' => yourls__( 'Descending' ),
  235. );
  236. $_select2 = yourls_html_select( 'sort_order', $_options, $sort_order );
  237. /* //translators: "Order by <criteria dropdown (date, clicks...)> in <order dropdown (Descending or Ascending)>" */
  238. yourls_se( 'Order by %1$s %2$s', $_select , $_select2 );
  239. echo "&ndash;\n";
  240.  
  241. // Third search control: Show XX rows
  242. /* //translators: "Show <text field> rows" */
  243. yourls_se( 'Show %s rows', '<input type="text" name="perpage" class="text" size="2" value="' . $perpage . '" />' );
  244. echo "<br/>\n";
  245.  
  246. // Fourth search control: Show links with more than XX clicks
  247. $_options = array(
  248. 'more' => yourls__( 'more' ),
  249. 'less' => yourls__( 'less' ),
  250. );
  251. $_select = yourls_html_select( 'click_filter', $_options, $click_filter );
  252. $_input = '<input type="text" name="click_limit" class="text" size="4" value="' . $click_limit . '" /> ';
  253. /* //translators: "Show links with <more/less> than <text field> clicks" */
  254. yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input );
  255. echo "<br/>\n";
  256.  
  257. // Fifth search control: Show links created before/after/between ...
  258. $_options = array(
  259. 'before' => yourls__('before'),
  260. 'after' => yourls__('after'),
  261. 'between' => yourls__('between'),
  262. );
  263. $_select = yourls_html_select( 'date_filter', $_options, $date_filter );
  264. $_input = '<input type="text" name="date_first" id="date_first" class="text" size="12" value="' . $date_first . '" />';
  265. $_and = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> &amp; </span>';
  266. $_input2 = '<input type="text" name="date_second" id="date_second" class="text" size="12" value="' . $date_second . '"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '/>';
  267. /* //translators: "Show links created <before/after/between> <date input> <"and" if applicable> <date input if applicable>" */
  268. yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 );
  269. ?>
  270.  
  271. <div id="filter_buttons">
  272. <input type="submit" id="submit-sort" value="<?php yourls_e('Search'); ?>" class="button primary" />
  273. &nbsp;
  274. <input type="button" id="submit-clear-filter" value="<?php yourls_e('Clear'); ?>" class="button" onclick="window.parent.location.href = 'index.php'" />
  275. </div>
  276.  
  277. </div>
  278. </form>
  279. </div>
  280.  
  281. <?php
  282. // Remove empty keys from the $params array so it doesn't clutter the pagination links
  283. $params = array_filter( $params, 'yourls_return_if_not_empty_string' ); // remove empty keys
  284.  
  285. if( isset( $search_text ) ) {
  286. $params['search'] = $search_text;
  287. unset( $params['search_text'] );
  288. }
  289. ?>
  290.  
  291. <div id="pagination">
  292. <span class="navigation">
  293. <?php if( $total_pages > 1 ) { ?>
  294. <span class="nav_total"><?php echo sprintf( yourls_n( '1 page', '%s pages', $total_pages ), $total_pages ); ?></span>
  295. <?php
  296. $base_page = yourls_admin_url( 'index.php' );
  297. // Pagination offsets: min( max ( zomg! ) );
  298. $p_start = max( min( $total_pages - 4, $page - 2 ), 1 );
  299. $p_end = min( max( 5, $page + 2 ), $total_pages );
  300. if( $p_start >= 2 ) {
  301. $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page );
  302. echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '&laquo; First' ) . '</a></span>';
  303. echo '<span class="nav_link nav_prev"></span>';
  304. }
  305. for( $i = $p_start ; $i <= $p_end; $i++ ) {
  306. if( $i == $page ) {
  307. echo "<span class='nav_link nav_current'>$i</span>";
  308. } else {
  309. $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page );
  310. echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>';
  311. }
  312. }
  313. if( ( $p_end ) < $total_pages ) {
  314. $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page );
  315. echo '<span class="nav_link nav_next"></span>';
  316. echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( 'Last &raquo;' ) . '</a></span>';
  317. }
  318. ?>
  319. <?php } ?>
  320. </span>
  321. </div>
  322. </th>
  323. </tr>
  324. <?php yourls_do_action( 'html_tfooter' ); ?>
  325. </tfoot>
  326. <?php
  327. }
  328.  
  329. /**
  330. * Return a select box
  331. *
  332. * @since 1.6
  333. *
  334. * @param string $name HTML 'name' (also use as the HTML 'id')
  335. * @param array $options array of 'value' => 'Text displayed'
  336. * @param string $selected optional 'value' from the $options array that will be highlighted
  337. * @param boolean $display false (default) to return, true to echo
  338. * @return string HTML content of the select element
  339. */
  340. function yourls_html_select( $name, $options, $selected = '', $display = false ) {
  341. $html = "<select name='$name' id='$name' size='1'>\n";
  342. foreach( $options as $value => $text ) {
  343. $html .= "<option value='$value' ";
  344. $html .= $selected == $value ? ' selected="selected"' : '';
  345. $html .= ">$text</option>\n";
  346. }
  347. $html .= "</select>\n";
  348. $html = yourls_apply_filters( 'html_select', $html, $name, $options, $selected, $display );
  349. if( $display )
  350. echo $html;
  351. return $html;
  352. }
  353.  
  354. /**
  355. * Display the Quick Share box
  356. *
  357. */
  358. function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) {
  359. if ( $shortlink_title == '' )
  360. $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>';
  361. if ( $share_title == '' )
  362. $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>';
  363.  
  364. // Allow plugins to short-circuit the whole function
  365. $pre = yourls_apply_filter( 'shunt_share_box', false );
  366. if ( false !== $pre )
  367. return $pre;
  368.  
  369. $text = ( $text ? '"'.$text.'" ' : '' );
  370. $title = ( $title ? "$title " : '' );
  371. $share = yourls_esc_textarea( $title.$text.$shorturl );
  372. $count = 140 - strlen( $share );
  373. $hidden = ( $hidden ? 'style="display:none;"' : '' );
  374.  
  375. // Allow plugins to filter all data
  376. $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' );
  377. $data = yourls_apply_filter( 'share_box_data', $data );
  378. extract( $data );
  379.  
  380. $_share = rawurlencode( $share );
  381. $_url = rawurlencode( $shorturl );
  382. ?>
  383.  
  384. <div id="shareboxes" <?php echo $hidden; ?>>
  385.  
  386. <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?>
  387.  
  388. <div id="copybox" class="share">
  389. <?php echo $shortlink_title; ?>
  390. <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p>
  391. <p><small><?php yourls_e( 'Long link' ); ?>: <a id="origlink" href="<?php echo yourls_esc_url( $longurl ); ?>"><?php echo yourls_esc_url( $longurl ); ?></a></small>
  392. <?php if( yourls_do_log_redirect() ) { ?>
  393. <br/><small><?php yourls_e( 'Stats' ); ?>: <a id="statlink" href="<?php echo yourls_esc_url( $shorturl ); ?>+"><?php echo yourls_esc_url( $shorturl ); ?>+</a></small>
  394. <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" />
  395. <?php } ?>
  396. </p>
  397. </div>
  398.  
  399. <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?>
  400.  
  401. <div id="sharebox" class="share">
  402. <?php echo $share_title; ?>
  403. <div id="tweet">
  404. <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span>
  405. <textarea id="tweet_body"><?php echo $share; ?></textarea>
  406. </div>
  407. <p id="share_links"><?php yourls_e( 'Share with' ); ?>
  408. <a id="share_tw" href="http://twitter.com/home?status=<?php echo $_share; ?>" title="<?php yourls_e( 'Tweet this!' ); ?>" onclick="share('tw');return false">Twitter</a>
  409. <a id="share_fb" href="http://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e( 'Share on Facebook' ); ?>" onclick="share('fb');return false;">Facebook</a>
  410. <a id="share_ff" href="http://friendfeed.com/share/bookmarklet/frame#title=<?php echo $_share; ?>" title="<?php yourls_e( 'Share on Friendfeed' ); ?>" onclick="share('ff');return false;">FriendFeed</a>
  411. <?php
  412. yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text );
  413. // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn.
  414. ?>
  415. </p>
  416. </div>
  417.  
  418. <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?>
  419.  
  420. </div>
  421.  
  422. <?php
  423. }
  424.  
  425. /**
  426. * Die die die
  427. *
  428. */
  429. function yourls_die( $message = '', $title = '', $header_code = 200 ) {
  430. yourls_status_header( $header_code );
  431.  
  432. if( !yourls_did_action( 'html_head' ) ) {
  433. yourls_html_head();
  434. yourls_html_logo();
  435. }
  436. echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" );
  437. echo yourls_apply_filter( 'die_message', "<p>$message</p>" );
  438. yourls_do_action( 'yourls_die' );
  439. if( !yourls_did_action( 'html_head' ) ) {
  440. yourls_html_footer();
  441. }
  442. die();
  443. }
  444.  
  445. /**
  446. * Return an "Edit" row for the main table
  447. *
  448. * @param string $keyword Keyword to edit
  449. * @return string HTML of the edit row
  450. */
  451. function yourls_table_edit_row( $keyword ) {
  452. $keyword = yourls_sanitize_string( $keyword );
  453. $id = yourls_string2htmlid( $keyword ); // used as HTML #id
  454. $url = yourls_get_keyword_longurl( $keyword );
  455.  
  456. $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );
  457. $safe_url = yourls_esc_attr( $url );
  458. $safe_title = yourls_esc_attr( $title );
  459. $www = yourls_link();
  460.  
  461. $nonce = yourls_create_nonce( 'edit-save_'.$id );
  462.  
  463. if( $url ) {
  464. $return = <<<RETURN
  465. <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');" />&nbsp;<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>
  466. RETURN;
  467. $return = sprintf( urldecode( $return ), yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) );
  468. } else {
  469. $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>';
  470. }
  471.  
  472. $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title );
  473.  
  474. return $return;
  475. }
  476.  
  477. /**
  478. * Return an "Add" row for the main table
  479. *
  480. * @return string HTML of the edit row
  481. */
  482. function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) {
  483. $keyword = yourls_sanitize_string( $keyword );
  484. $id = yourls_string2htmlid( $keyword ); // used as HTML #id
  485. $shorturl = yourls_link( $keyword );
  486.  
  487. $statlink = yourls_statlink( $keyword );
  488.  
  489. $delete_link = yourls_nonce_url( 'delete-link_'.$id,
  490. yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
  491. );
  492.  
  493. $edit_link = yourls_nonce_url( 'edit-link_'.$id,
  494. yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) )
  495. );
  496.  
  497. // Action link buttons: the array
  498. $actions = array(
  499. 'stats' => array(
  500. 'href' => $statlink,
  501. 'id' => "statlink-$id",
  502. 'title' => yourls_esc_attr__( 'Stats' ),
  503. 'anchor' => yourls__( 'Stats' ),
  504. ),
  505. 'share' => array(
  506. 'href' => '',
  507. 'id' => "share-button-$id",
  508. 'title' => yourls_esc_attr__( 'Share' ),
  509. 'anchor' => yourls__( 'Share' ),
  510. 'onclick' => "toggle_share('$id');return false;",
  511. ),
  512. 'edit' => array(
  513. 'href' => $edit_link,
  514. 'id' => "edit-button-$id",
  515. 'title' => yourls_esc_attr__( 'Edit' ),
  516. 'anchor' => yourls__( 'Edit' ),
  517. 'onclick' => "edit_link_display('$id');return false;",
  518. ),
  519. 'delete' => array(
  520. 'href' => $delete_link,
  521. 'id' => "delete-button-$id",
  522. 'title' => yourls_esc_attr__( 'Delete' ),
  523. 'anchor' => yourls__( 'Delete' ),
  524. 'onclick' => "remove_link('$id');return false;",
  525. )
  526. );
  527. $actions = yourls_apply_filter( 'table_add_row_action_array', $actions );
  528.  
  529. // Action link buttons: the HTML
  530. $action_links = '';
  531. foreach( $actions as $key => $action ) {
  532. $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ;
  533. $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>',
  534. $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor']
  535. );
  536. }
  537. $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp );
  538.  
  539. if( ! $title )
  540. $title = $url;
  541.  
  542. $protocol_warning = '';
  543. if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) )
  544. $protocol_warning = yourls_apply_filters( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">&#9733;</span>' );
  545.  
  546. // Row cells: the array
  547. $cells = array(
  548. 'keyword' => array(
  549. 'template' => '<a href="%shorturl%">%keyword_html%</a>',
  550. 'shorturl' => yourls_esc_url( $shorturl ),
  551. 'keyword_html' => yourls_esc_html( $keyword ),
  552. ),
  553. 'url' => array(
  554. 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>',
  555. 'long_url' => yourls_esc_url( $url ),
  556. 'title_attr' => yourls_esc_attr( $title ),
  557. 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ),
  558. 'long_url_html' => yourls_esc_html( yourls_trim_long_string( $url ) ),
  559. 'warning' => $protocol_warning,
  560. ),
  561. 'timestamp' => array(
  562. 'template' => '%date%',
  563. 'date' => date( 'M d, Y H:i', $timestamp +( YOURLS_HOURS_OFFSET * 3600 ) ),
  564. ),
  565. 'ip' => array(
  566. 'template' => '%ip%',
  567. 'ip' => $ip,
  568. ),
  569. 'clicks' => array(
  570. 'template' => '%clicks%',
  571. 'clicks' => yourls_number_format_i18n( $clicks, 0, '', '' ),
  572. ),
  573. 'actions' => array(
  574. 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>',
  575. 'actions' => $action_links,
  576. 'id' => $id,
  577. 'keyword' => $keyword,
  578. ),
  579. );
  580. $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp );
  581.  
  582. // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value.
  583. $row = "<tr id=\"id-$id\">";
  584. foreach( $cells as $cell_id => $elements ) {
  585. $callback = new yourls_table_add_row_callback( $elements );
  586. $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id );
  587. $row .= preg_replace_callback( '/%([^%]+)?%/', array( $callback, 'callback' ), $elements['template'] );
  588. // For the record, in PHP 5.3+ we don't need to introduce a class in order to pass additional parameters
  589. // to the callback function. Instead, we would have used the 'use' keyword :
  590. // $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] );
  591.  
  592. $row .= '</td>';
  593. }
  594. $row .= "</tr>";
  595. $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp );
  596.  
  597. return $row;
  598. }
  599.  
  600. /**
  601. * Callback class for yourls_table_add_row
  602. *
  603. * See comment about PHP 5.3+ in yourls_table_add_row()
  604. *
  605. * @since 1.7
  606. */
  607. class yourls_table_add_row_callback {
  608. private $elements;
  609.  
  610. function __construct($elements) {
  611. $this->elements = $elements;
  612. }
  613.  
  614. function callback( $matches ) {
  615. return $this->elements[ $matches[1] ];
  616. }
  617. }
  618.  
  619.  
  620. /**
  621. * Echo the main table head
  622. *
  623. */
  624. function yourls_table_head() {
  625. $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n";
  626. echo yourls_apply_filter( 'table_head_start', $start );
  627.  
  628. $cells = yourls_apply_filter( 'table_head_cells', array(
  629. 'shorturl' => yourls__( 'Short URL' ),
  630. 'longurl' => yourls__( 'Original URL' ),
  631. 'date' => yourls__( 'Date' ),
  632. 'ip' => yourls__( 'IP' ),
  633. 'clicks' => yourls__( 'Clicks' ),
  634. 'actions' => yourls__( 'Actions' )
  635. ) );
  636. foreach( $cells as $k => $v ) {
  637. echo "<th id='main_table_head_$k'>$v</th>\n";
  638. }
  639.  
  640. $end = "</tr></thead>\n";
  641. echo yourls_apply_filter( 'table_head_end', $end );
  642. }
  643.  
  644. /**
  645. * Echo the tbody start tag
  646. *
  647. */
  648. function yourls_table_tbody_start() {
  649. echo yourls_apply_filter( 'table_tbody_start', '<tbody>' );
  650. }
  651.  
  652. /**
  653. * Echo the tbody end tag
  654. *
  655. */
  656. function yourls_table_tbody_end() {
  657. echo yourls_apply_filter( 'table_tbody_end', '</tbody>' );
  658. }
  659.  
  660. /**
  661. * Echo the table start tag
  662. *
  663. */
  664. function yourls_table_end() {
  665. echo yourls_apply_filter( 'table_end', '</table>' );
  666. }
  667.  
  668. /**
  669. * Echo HTML tag for a link
  670. *
  671. */
  672. function yourls_html_link( $href, $title = '', $element = '' ) {
  673. if( !$title )
  674. $title = $href;
  675. if( $element )
  676. $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) );
  677. $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) );
  678. echo yourls_apply_filter( 'html_link', $link );
  679. }
  680.  
  681. /**
  682. * Display the login screen. Nothing past this point.
  683. *
  684. */
  685. function yourls_login_screen( $error_msg = '' ) {
  686. yourls_html_head( 'login' );
  687.  
  688. $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' );
  689.  
  690. yourls_html_logo();
  691. ?>
  692. <div id="login">
  693. <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?>
  694. <?php
  695. if( !empty( $error_msg ) ) {
  696. echo '<p class="error">'.$error_msg.'</p>';
  697. }
  698. ?>
  699. <p>
  700. <label for="username"><?php yourls_e( 'Username' ); ?></label><br />
  701. <input type="text" id="username" name="username" size="30" class="text" />
  702. </p>
  703. <p>
  704. <label for="password"><?php yourls_e( 'Password' ); ?></label><br />
  705. <input type="password" id="password" name="password" size="30" class="text" />
  706. </p>
  707. <p style="text-align: right;">
  708. <input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" />
  709. </p>
  710. </form>
  711. <script type="text/javascript">$('#username').focus();</script>
  712. </div>
  713. <?php
  714. yourls_html_footer();
  715. die();
  716. }
  717.  
  718. /**
  719. * Display the admin menu
  720. *
  721. */
  722. function yourls_html_menu() {
  723.  
  724. // Build menu links
  725. if( defined( 'YOURLS_USER' ) ) {
  726. $logout_link = yourls_apply_filter( 'logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' (<a href="?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' );
  727. } else {
  728. $logout_link = yourls_apply_filter( 'logout_link', '' );
  729. }
  730. $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' );
  731.  
  732. $admin_links = array();
  733. $admin_sublinks = array();
  734.  
  735. $admin_links['admin'] = array(
  736. 'url' => yourls_admin_url( 'index.php' ),
  737. 'title' => yourls__( 'Go to the admin interface' ),
  738. 'anchor' => yourls__( 'Admin interface' )
  739. );
  740.  
  741. if( yourls_is_admin() ) {
  742. $admin_links['tools'] = array(
  743. 'url' => yourls_admin_url( 'tools.php' ),
  744. 'anchor' => yourls__( 'Tools' )
  745. );
  746. $admin_links['plugins'] = array(
  747. 'url' => yourls_admin_url( 'plugins.php' ),
  748. 'anchor' => yourls__( 'Manage Plugins' )
  749. );
  750. $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages();
  751. }
  752.  
  753. $admin_links = yourls_apply_filter( 'admin_links', $admin_links );
  754. $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks );
  755.  
  756. // Now output menu
  757. echo '<ul id="admin_menu">'."\n";
  758. if ( yourls_is_private() && !empty( $logout_link ) )
  759. echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>';
  760.  
  761. foreach( (array)$admin_links as $link => $ar ) {
  762. if( isset( $ar['url'] ) ) {
  763. $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
  764. $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
  765. printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor );
  766. }
  767. // Output submenu if any. TODO: clean up, too many code duplicated here
  768. if( isset( $admin_sublinks[$link] ) ) {
  769. echo "<ul>\n";
  770. foreach( $admin_sublinks[$link] as $link => $ar ) {
  771. if( isset( $ar['url'] ) ) {
  772. $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link;
  773. $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : '';
  774. printf( '<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor );
  775. }
  776. }
  777. echo "</ul>\n";
  778. }
  779. }
  780.  
  781. if ( isset( $help_link ) )
  782. echo '<li id="admin_menu_help_link">' . $help_link .'</li>';
  783.  
  784. yourls_do_action( 'admin_menu' );
  785. echo "</ul>\n";
  786. yourls_do_action( 'admin_notices' );
  787. yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice'
  788. /*
  789. To display a notice:
  790. $message = "<div>OMG, dude, I mean!</div>" );
  791. yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );
  792. */
  793. }
  794.  
  795. /**
  796. * Wrapper function to display admin notices
  797. *
  798. */
  799. function yourls_add_notice( $message, $style = 'notice' ) {
  800. // Escape single quotes in $message to avoid breaking the anonymous function
  801. $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style );
  802. yourls_add_action( 'admin_notices', create_function( '', "echo '$message';" ) );
  803. }
  804.  
  805. /**
  806. * Return a formatted notice
  807. *
  808. */
  809. function yourls_notice_box( $message, $style = 'notice' ) {
  810. return <<<HTML
  811. <div class="$style">
  812. <p>$message</p>
  813. </div>
  814. HTML;
  815. }
  816.  
  817. /**
  818. * Display a page
  819. *
  820. */
  821. function yourls_page( $page ) {
  822. $include = YOURLS_ABSPATH . "/pages/$page.php";
  823. if( !file_exists( $include ) ) {
  824. yourls_die( "Page '$page' not found", 'Not found', 404 );
  825. }
  826. yourls_do_action( 'pre_page', $page );
  827. include_once( $include );
  828. yourls_do_action( 'post_page', $page );
  829. die();
  830. }
  831.  
  832. /**
  833. * Display the language attributes for the HTML tag.
  834. *
  835. * Builds up a set of html attributes containing the text direction and language
  836. * information for the page. Stolen from WP.
  837. *
  838. * @since 1.6
  839. */
  840. function yourls_html_language_attributes() {
  841. $attributes = array();
  842. $output = '';
  843.  
  844. $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' );
  845.  
  846. $doctype = yourls_apply_filters( 'html_language_attributes_doctype', 'html' );
  847. // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR
  848. if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) {
  849. if( $doctype == 'xhtml' ) {
  850. $attributes[] = "xml:lang=\"$lang\"";
  851. } else {
  852. $attributes[] = "lang=\"$lang\"";
  853. }
  854. }
  855.  
  856. $output = implode( ' ', $attributes );
  857. $output = yourls_apply_filters( 'html_language_attributes', $output );
  858. echo $output;
  859. }
  860.  
  861. /**
  862. * Output translated strings used by the Javascript calendar
  863. *
  864. * @since 1.6
  865. */
  866. function yourls_l10n_calendar_strings() {
  867. echo "\n<script>\n";
  868. echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n";
  869. echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n";
  870. echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n";
  871. echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n";
  872. echo "</script>\n";
  873.  
  874. // Dummy returns, to initialize l10n strings used in the calendar
  875. yourls__( 'Today' );
  876. yourls__( 'Close' );
  877. }
  878.  
  879.  
  880. /**
  881. * Display a notice if there is a newer version of YOURLS available
  882. *
  883. * @since 1.7
  884. */
  885. function yourls_new_core_version_notice() {
  886.  
  887. yourls_debug_log( 'Check for new version: ' . ( yourls_maybe_check_core_version() ? 'yes' : 'no' ) );
  888.  
  889. $checks = yourls_get_option( 'core_version_checks' );
  890.  
  891. if( isset( $checks->last_result->latest ) AND version_compare( $checks->last_result->latest, YOURLS_VERSION, '>' ) ) {
  892. $msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $checks->last_result->latest );
  893. yourls_add_notice( $msg );
  894. }
  895. }
  896.  
  897. /**
  898. * Send a filerable content type header
  899. *
  900. * @since 1.7
  901. * @param string $type content type ('text/html', 'application/json', ...)
  902. * @return bool whether header was sent
  903. */
  904. function yourls_content_type_header( $type ) {
  905. if( !headers_sent() ) {
  906. $charset = yourls_apply_filters( 'content_type_header_charset', 'utf-8' );
  907. header( "Content-Type: $type; charset=$charset" );
  908. return true;
  909. }
  910. return false;
  911. }
  912.  
  913. /**
  914. * Get search text from query string variables search_protocol, search_slashes and search
  915. *
  916. * Some servers don't like query strings containing "(ht|f)tp(s)://". A javascript bit
  917. * explodes the search text into protocol, slashes and the rest (see JS function
  918. * split_search_text_before_search()) and this function glues pieces back together
  919. * See issue https://github.com/YOURLS/YOURLS/issues/1576
  920. *
  921. * @since 1.7
  922. * @return string Search string
  923. */
  924. function yourls_get_search_text() {
  925. $search = '';
  926. if( isset( $_GET['search_protocol'] ) )
  927. $search .= $_GET['search_protocol'];
  928. if( isset( $_GET['search_slashes'] ) )
  929. $search .= $_GET['search_slashes'];
  930. if( isset( $_GET['search'] ) )
  931. $search .= $_GET['search'];
  932.  
  933. return htmlspecialchars( trim( $search ) );
  934. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement