function mu_table_add_row($keyword, $url, $title = '', $ip, $clicks, $timestamp) { $keyword = yourls_sanitize_string($keyword); $display_keyword = htmlentities($keyword); $url = yourls_sanitize_url($url); $display_url = htmlentities(yourls_trim_long_string($url)); $title_url = htmlspecialchars($url); $title = yourls_sanitize_title($title); $display_title = yourls_trim_long_string($title); $title = htmlspecialchars($title); $id = yourls_string2htmlid($keyword); // used as HTML #id $date = date('M d, Y H:i', $timestamp + YOURLS_HOURS_OFFSET * 3600); $clicks = number_format($clicks, 0, '', ''); $shorturl = YOURLS_SITE . '/' . $keyword; $statlink = $shorturl . '+'; if (yourls_is_ssl()) { $statlink = str_replace('http://', 'https://', $statlink); } if ($title) { $display_link = "<a href=\"{$url}\" title=\"{$title}\">{$display_title}</a><br/><small><a href=\"{$url}\" title=\"{$title_url}\">{$display_url}</a></small>"; } else { $display_link = "<a href=\"{$url}\" title=\"{$title_url}\">{$display_url}</a>"; } $delete_link = yourls_nonce_url('delete-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'delete', 'keyword' => $keyword), muAdminUrl('admin-ajax.php'))); $edit_link = yourls_nonce_url('edit-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'edit', 'keyword' => $keyword), muAdminUrl('admin-ajax.php'))); $actions = <<<ACTION <a href="{$statlink}" id="statlink-{$id}" title="Stats" class="button button_stats">Stats</a><a href="" id="share-button-{$id}" name="share-button" title="Share" class="button button_share" onclick="toggle_share('{$id}');return false;">Share</a><a href="{$edit_link}" id="edit-button-{$id}" name="edit-button" title="Edit" class="button button_edit" onclick="edit('{$id}');return false;">Edit</a><a href="{$delete_link}" id="delete-button-{$id}" name="delete-button" title="Delete" class="button button_delete" onclick="remove('{$id}');return false;">Delete</a> ACTION; $actions = yourls_apply_filter('action_links', $actions, $keyword, $url, $ip, $clicks, $timestamp); $row = <<<ROW <tr id="id-{$id}"><td id="keyword-{$id}" class="keyword"><a href="{$shorturl}">{$display_keyword}</a></td><td id="url-{$id}" class="url">{$display_link}</td><td id="timestamp-{$id}" class="timestamp">{$date}</td><td id="ip-{$id}" class="ip">{$ip}</td><td id="clicks-{$id}" class="clicks">{$clicks}</td><td class="actions" id="actions-{$id}">{$actions}<input type="hidden" id="keyword_{$id}" value="{$keyword}"/></td></tr> ROW; $row = yourls_apply_filter('table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp); return $row; }
} else { yourls_html_link(yourls_link($keyword)); if (isset($keyword_list) && count($keyword_list) > 1) { echo ' <a href="' . yourls_link($keyword) . '+all" title="' . yourls_esc_attr__('Aggregate stats for duplicate short URLs') . '"><img src="' . yourls_match_current_protocol(YOURLS_SITE) . '/images/chart_bar_add.png" border="0" /></a>'; } } ?> </h3> <h3 id="longurl"><span class="label"><?php yourls_e('Long URL'); ?> :</span> <img class="fix_images" src="<?php echo yourls_get_favicon_url($longurl); ?> " /> <?php yourls_html_link($longurl, yourls_trim_long_string($longurl), 'longurl'); ?> </h3> <div id="tabs"> <div class="wrap_unfloat"> <ul id="headers" class="toggle_display stat_tab"> <?php if (yourls_do_log_redirect()) { ?> <li class="selected"><a href="#stat_tab_stats"><strong><?php yourls_e('Traffic statistics'); ?> </strong></a></li> <li><a href="#stat_tab_location"><strong><?php yourls_e('Traffic location');
/** * Edit a link * */ function yourls_edit_link($url, $keyword, $newkeyword = '', $title = '') { // Allow plugins to short-circuit the whole function $pre = yourls_apply_filter('shunt_edit_link', null, $keyword, $url, $keyword, $newkeyword, $title); if (null !== $pre) { return $pre; } global $ydb; $table = YOURLS_DB_TABLE_URL; $url = yourls_escape(yourls_sanitize_url($url)); $keyword = yourls_escape(yourls_sanitize_string($keyword)); $title = yourls_escape(yourls_sanitize_title($title)); $newkeyword = yourls_escape(yourls_sanitize_string($newkeyword)); $strip_url = stripslashes($url); $strip_title = stripslashes($title); $old_url = $ydb->get_var("SELECT `url` FROM `{$table}` WHERE `keyword` = '{$keyword}';"); // Check if new URL is not here already if ($old_url != $url && !yourls_allow_duplicate_longurls()) { $new_url_already_there = intval($ydb->get_var("SELECT COUNT(keyword) FROM `{$table}` WHERE `url` = '{$url}';")); } else { $new_url_already_there = false; } // Check if the new keyword is not here already if ($newkeyword != $keyword) { $keyword_is_ok = yourls_keyword_is_free($newkeyword); } else { $keyword_is_ok = true; } yourls_do_action('pre_edit_link', $url, $keyword, $newkeyword, $new_url_already_there, $keyword_is_ok); // All clear, update if ((!$new_url_already_there || yourls_allow_duplicate_longurls()) && $keyword_is_ok) { $update_url = $ydb->query("UPDATE `{$table}` SET `url` = '{$url}', `keyword` = '{$newkeyword}', `title` = '{$title}' WHERE `keyword` = '{$keyword}';"); if ($update_url) { $return['url'] = array('keyword' => $newkeyword, 'shorturl' => YOURLS_SITE . '/' . $newkeyword, 'url' => $strip_url, 'display_url' => yourls_trim_long_string($strip_url), 'title' => $strip_title, 'display_title' => yourls_trim_long_string($strip_title)); $return['status'] = 'success'; $return['message'] = yourls__('Link updated in database'); } else { $return['status'] = 'fail'; $return['message'] = yourls_s('Error updating %s (Short URL: %s)', yourls_trim_long_string($strip_url), $keyword); } // Nope } else { $return['status'] = 'fail'; $return['message'] = yourls__('URL or keyword already exists in database'); } return yourls_apply_filter('edit_link', $return, $url, $keyword, $newkeyword, $title, $new_url_already_there, $keyword_is_ok); }
/** * Return an "Add" row for the main table * * @return string HTML of the edit row */ function yourls_table_add_row($keyword, $url, $title = '', $ip, $clicks, $timestamp) { $keyword = yourls_sanitize_string($keyword); $id = yourls_string2htmlid($keyword); // used as HTML #id $shorturl = yourls_link($keyword); $statlink = yourls_statlink($keyword); $delete_link = yourls_nonce_url('delete-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'delete', 'keyword' => $keyword), yourls_admin_url('admin-ajax.php'))); $edit_link = yourls_nonce_url('edit-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'edit', 'keyword' => $keyword), yourls_admin_url('admin-ajax.php'))); // Action link buttons: the array $actions = array('stats' => array('href' => $statlink, 'id' => "statlink-{$id}", 'title' => yourls_esc_attr__('Stats'), 'anchor' => yourls__('Stats')), 'share' => array('href' => '', 'id' => "share-button-{$id}", 'title' => yourls_esc_attr__('Share'), 'anchor' => yourls__('Share'), 'onclick' => "toggle_share('{$id}');return false;"), 'edit' => array('href' => $edit_link, 'id' => "edit-button-{$id}", 'title' => yourls_esc_attr__('Edit'), 'anchor' => yourls__('Edit'), 'onclick' => "edit_link_display('{$id}');return false;"), 'delete' => array('href' => $delete_link, 'id' => "delete-button-{$id}", 'title' => yourls_esc_attr__('Delete'), 'anchor' => yourls__('Delete'), 'onclick' => "remove_link('{$id}');return false;")); $actions = yourls_apply_filter('table_add_row_action_array', $actions); // Action link buttons: the HTML $action_links = ''; foreach ($actions as $key => $action) { $onclick = isset($action['onclick']) ? 'onclick="' . $action['onclick'] . '"' : ''; $action_links .= sprintf('<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>', $action['href'], $action['id'], $action['title'], 'button button_' . $key, $onclick, $action['anchor']); } $action_links = yourls_apply_filter('action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp); if (!$title) { $title = $url; } $protocol_warning = ''; if (!in_array(yourls_get_protocol($url), array('http://', 'https://'))) { $protocol_warning = yourls_apply_filter('add_row_protocol_warning', '<span class="warning" title="' . yourls__('Not a common link') . '">★</span>'); } // Row cells: the array $cells = array('keyword' => array('template' => '<a href="%shorturl%">%keyword_html%</a>', 'shorturl' => yourls_esc_url($shorturl), 'keyword_html' => yourls_esc_html($keyword)), 'url' => array('template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>', 'long_url' => yourls_esc_url($url), 'title_attr' => yourls_esc_attr($title), 'title_html' => yourls_esc_html(yourls_trim_long_string($title)), 'long_url_html' => yourls_esc_html(yourls_trim_long_string($url)), 'warning' => $protocol_warning), 'timestamp' => array('template' => '%date%', 'date' => date('M d, Y H:i', $timestamp + YOURLS_HOURS_OFFSET * 3600)), 'ip' => array('template' => '%ip%', 'ip' => $ip), 'clicks' => array('template' => '%clicks%', 'clicks' => yourls_number_format_i18n($clicks, 0, '', '')), 'actions' => array('template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>', 'actions' => $action_links, 'id' => $id, 'keyword' => $keyword)); $cells = yourls_apply_filter('table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp); // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value. $row = "<tr id=\"id-{$id}\">"; foreach ($cells as $cell_id => $elements) { $callback = new yourls_table_add_row_callback($elements); $row .= sprintf('<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id); $row .= preg_replace_callback('/%([^%]+)?%/', array($callback, 'callback'), $elements['template']); // For the record, in PHP 5.3+ we don't need to introduce a class in order to pass additional parameters // to the callback function. Instead, we would have used the 'use' keyword : // $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] ); $row .= '</td>'; } $row .= "</tr>"; $row = yourls_apply_filter('table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp); return $row; }
function yourls_edit_link($url, $keyword, $newkeyword = '') { global $ydb; $table = YOURLS_DB_TABLE_URL; $url = yourls_escape(yourls_sanitize_url($url)); $keyword = yourls_sanitize_string($keyword); $newkeyword = yourls_sanitize_string($newkeyword); $strip_url = stripslashes($url); $old_url = $ydb->get_var("SELECT `url` FROM `{$table}` WHERE `keyword` = '{$keyword}';"); $old_id = $id = yourls_string2int($keyword); $new_id = $newkeyword == '' ? $old_id : yourls_string2int($newkeyword); // Check if new URL is not here already if ($old_url != $url) { $new_url_already_there = intval($ydb->get_var("SELECT COUNT(keyword) FROM `{$table}` WHERE `url` = '{$strip_url}';")); } else { $new_url_already_there = false; } // Check if the new keyword is not here already if ($newkeyword != $keyword) { $keyword_is_ok = yourls_keyword_is_free($newkeyword); } else { $keyword_is_ok = true; } // All clear, update if ((!$new_url_already_there || yourls_allow_duplicate_longurls()) && $keyword_is_ok) { $update_url = $ydb->query("UPDATE `{$table}` SET `url` = '{$url}', `keyword` = '{$newkeyword}' WHERE `keyword` = '{$keyword}';"); if ($update_url) { $return['url'] = array('keyword' => $newkeyword, 'shorturl' => YOURLS_SITE . '/' . $newkeyword, 'url' => $strip_url, 'display_url' => yourls_trim_long_string($strip_url), 'new_id' => $new_id); $return['status'] = 'success'; $return['message'] = 'Link updated in database'; } else { $return['status'] = 'fail'; $return['message'] = 'Error updating ' . $strip_url . ' (Short URL: ' . $keyword . ') to database'; } // Nope } else { $return['status'] = 'fail'; $return['message'] = 'URL or keyword already exists in database'; } return $return; }