PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/broken-link-checker/includes/admin/table-printer.php

https://bitbucket.org/lgorence/quickpress
PHP | 761 lines | 518 code | 106 blank | 137 comment | 69 complexity | 4ea160f57695f8e7c28066238b7ef732 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. if ( !class_exists('blcTablePrinter') ) {
  3. /**
  4. * Utility class for printing the link listing table.
  5. *
  6. * @package Broken Link Checker
  7. * @access public
  8. */
  9. class blcTablePrinter {
  10. var $current_filter; //The current search filter. Also contains the list of links to display.
  11. var $page; //The current page number
  12. var $per_page; //Max links per page
  13. /** @var wsBrokenLinkChecker */
  14. var $core; //A reference to the main plugin object
  15. var $neutral_current_url; //The "safe" version of the current URL, for use in the bulk action form.
  16. var $bulk_actions_html = '';
  17. var $pagination_html = '';
  18. var $searched_link_type = '';
  19. var $columns;
  20. var $layouts;
  21. function blcTablePrinter($core){
  22. $this->core = $core;
  23. //Initialize layout and column definitions
  24. $this->setup_columns();
  25. $this->setup_layouts();
  26. //Figure out what the "safe" URL to acccess the current page would be.
  27. //This is used by the bulk action form.
  28. $special_args = array('_wpnonce', '_wp_http_referer', 'action', 'selected_links');
  29. $this->neutral_current_url = remove_query_arg($special_args);
  30. }
  31. /**
  32. * Print the entire link table and associated navigation elements.
  33. *
  34. * @param array $current_filter
  35. * @param string $layout
  36. * @param array $visible_columns
  37. * @param bool $compact
  38. * @return void
  39. */
  40. function print_table($current_filter, $layout = 'flexible', $visible_columns = null, $compact = false){
  41. $this->current_filter = $current_filter;
  42. $this->page = $current_filter['page'];
  43. $this->per_page = $current_filter['per_page'];
  44. $current_layout = $this->layouts[$layout];
  45. if ( empty($visible_columns) ){
  46. $visible_columns = $current_layout;
  47. }
  48. //Only allow columns actually present in this layout
  49. $visible_columns = array_intersect($visible_columns, $current_layout);
  50. echo '<form id="blc-bulk-action-form" action="', $this->neutral_current_url, '" method="post">';
  51. wp_nonce_field('bulk-action');
  52. //Top navigation
  53. $this->prepare_nav_html();
  54. $this->navigation($compact);
  55. //Table header
  56. $table_classes = array('widefat');
  57. if ( $compact ) {
  58. $table_classes[] = 'compact';
  59. };
  60. if ( $this->core->conf->options['table_color_code_status'] ) {
  61. $table_classes[] = 'color-code-link-status';
  62. };
  63. $table_classes[] = 'base-filter-' . $current_filter['base_filter'];
  64. printf(
  65. '<table class="%s" id="blc-links"><thead><tr>',
  66. implode(' ', $table_classes)
  67. );
  68. //The select-all checkbox
  69. echo '<th scope="col" class="column-checkbox check-column" id="cb"><input type="checkbox" /></th>';
  70. //Column headers
  71. foreach($current_layout as $column_id){
  72. $column = $this->columns[$column_id];
  73. $column_classes = array('column-'.$column_id);
  74. if ( isset($column['class']) ){
  75. $column_classes[] = $column['class'];
  76. }
  77. if ( !in_array($column_id, $visible_columns) ) {
  78. $column_classes[] = 'hidden';
  79. }
  80. $heading = $column['heading'];
  81. if ( isset($column['sortable']) && $column['sortable'] ) {
  82. $orderby = $column['orderby'];
  83. $current_orderby = isset($_GET['orderby']) ? $_GET['orderby'] : '';
  84. $current_order = isset($_GET['order']) ? $_GET['order'] : 'asc';
  85. if ( $orderby == $current_orderby ) {
  86. $column_classes[] = 'sorted';
  87. $column_classes[] = $current_order;
  88. $order = ($current_order == 'asc') ? 'desc' : 'asc'; //Reverse the sort direction
  89. } else {
  90. $order = 'asc';
  91. $column_classes[] = 'desc';
  92. $column_classes[] = 'sortable';
  93. }
  94. $heading = sprintf(
  95. '<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
  96. add_query_arg(array(
  97. 'orderby' => $orderby,
  98. 'order' => $order,
  99. )),
  100. $heading
  101. );
  102. }
  103. printf(
  104. '<th scope="col" class="%s"%s>%s</th>',
  105. implode(' ', $column_classes),
  106. isset($column['id']) ? ' id="' . $column['id'] . '"' : '',
  107. $heading
  108. );
  109. }
  110. echo '</tr></thead>';
  111. //Table body
  112. echo '<tbody id="the-list">';
  113. $this->bulk_edit_form($visible_columns);
  114. $rownum = 0;
  115. foreach ($this->current_filter['links'] as $link) {
  116. $rownum++;
  117. $this->link_row($link, $current_layout, $visible_columns, $rownum);
  118. $this->link_details_row($link, $visible_columns, $rownum);
  119. }
  120. echo '</tbody></table>';
  121. //Bottom navigation
  122. $this->navigation($compact, '2');
  123. echo '</form>';
  124. }
  125. /**
  126. * Print the "Bulk Actions" dropdown and navigation links
  127. *
  128. * @param bool $table_compact Whether to use the full or compact view.
  129. * @param string $suffix Optional. Appended to ID and name attributes of the bulk action dropdown.
  130. * @return void
  131. */
  132. function navigation($table_compact = false, $suffix = ''){
  133. //Display the "Bulk Actions" dropdown
  134. echo '<div class="tablenav">',
  135. '<div class="alignleft actions">',
  136. '<select name="action', $suffix ,'" id="blc-bulk-action', $suffix ,'">',
  137. $this->bulk_actions_html,
  138. '</select>',
  139. ' <input type="submit" name="doaction', $suffix ,'" id="doaction',$suffix,'" value="',
  140. esc_attr(__('Apply', 'broken-link-checker')),
  141. '" class="button-secondary action">',
  142. '</div>';
  143. //Display pagination links
  144. if ( !empty($this->pagination_html) ){
  145. echo $this->pagination_html;
  146. }
  147. //Display the view switch (only in the top nav. area)
  148. if ( empty($suffix) ){
  149. ?>
  150. <div class="view-switch">
  151. <a href="<?php echo esc_url(add_query_arg('compact', '1', $_SERVER['REQUEST_URI'])) ?>"><img <?php if ( $table_compact ) echo 'class="current"'; ?> id="view-switch-list" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" width="20" height="20" title="<?php _e('Compact View', 'broken-link-checker') ?>" alt="<?php _e('Compact View', 'broken-link-checker') ?>" /></a>
  152. <a href="<?php echo esc_url(add_query_arg('compact', '0', $_SERVER['REQUEST_URI'])) ?>"><img <?php if ( !$table_compact ) echo 'class="current"'; ?> id="view-switch-excerpt" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" width="20" height="20" title="<?php _e('Detailed View', 'broken-link-checker') ?>" alt="<?php _e('Detailed View', 'broken-link-checker') ?>" /></a>
  153. </div>
  154. <?php
  155. }
  156. echo '</div>';
  157. }
  158. /**
  159. * Initialize the internal list of available table columns.
  160. *
  161. * @return void
  162. */
  163. function setup_columns(){
  164. $this->columns = array(
  165. 'status' => array(
  166. 'heading' => __('Status', 'broken-link-checker'),
  167. 'content' => array($this, 'column_status'),
  168. ),
  169. 'new-url' => array(
  170. 'heading' => __('URL', 'broken-link-checker'),
  171. 'content' => array($this, 'column_new_url'),
  172. 'sortable' => true,
  173. 'orderby' => 'url',
  174. ),
  175. 'used-in' => array(
  176. 'heading' => __('Source', 'broken-link-checker'),
  177. 'class' => 'column-title',
  178. 'content' => array($this, 'column_used_in'),
  179. ),
  180. 'new-link-text' => array(
  181. 'heading' => __('Link Text', 'broken-link-checker'),
  182. 'content' => array($this, 'column_new_link_text'),
  183. ),
  184. 'redirect-url' => array(
  185. 'heading' => __('Redirect URL', 'broken-link-checker'),
  186. 'content' => array($this, 'column_redirect_url'),
  187. ),
  188. );
  189. }
  190. /**
  191. * Initialize the list of available layouts
  192. *
  193. * @return void
  194. */
  195. function setup_layouts(){
  196. $this->layouts = array(
  197. 'classic' => array('used-in', 'new-link-text', 'new-url'),
  198. 'flexible' => array('new-url', 'status', 'new-link-text', 'redirect-url', 'used-in', ),
  199. );
  200. }
  201. /**
  202. * Get a list of columns available in a specific table layout.
  203. *
  204. * @param string $layout Layout ID.
  205. * @return array Associative array of column data indexed by column ID.
  206. */
  207. function get_layout_columns($layout){
  208. if ( isset($this->layouts[$layout]) ){
  209. $result = array();
  210. foreach($this->layouts[$layout] as $column_id){
  211. if ( isset($this->columns[$column_id]) )
  212. $result[$column_id] = $this->columns[$column_id];
  213. }
  214. return $result;
  215. } else {
  216. return null;
  217. }
  218. }
  219. /**
  220. * Pre-generate some HTML fragments used for both the top and bottom navigation/bulk action boxes.
  221. *
  222. * @return void
  223. */
  224. function prepare_nav_html(){
  225. //Generate an <option> element for each possible bulk action. The list doesn't change,
  226. //so we can do it once and reuse the generated HTML.
  227. $bulk_actions = array(
  228. '-1' => __('Bulk Actions', 'broken-link-checker'),
  229. "bulk-edit" => __('Edit URL', 'broken-link-checker'),
  230. "bulk-recheck" => __('Recheck', 'broken-link-checker'),
  231. "bulk-deredirect" => __('Fix redirects', 'broken-link-checker'),
  232. "bulk-not-broken" => __('Mark as not broken', 'broken-link-checker'),
  233. "bulk-unlink" => __('Unlink', 'broken-link-checker'),
  234. );
  235. if ( EMPTY_TRASH_DAYS ){
  236. $bulk_actions["bulk-trash-sources"] = __('Move sources to Trash', 'broken-link-checker');
  237. } else {
  238. $bulk_actions["bulk-delete-sources"] = __('Delete sources', 'broken-link-checker');
  239. }
  240. $bulk_actions_html = '';
  241. foreach($bulk_actions as $value => $name){
  242. $bulk_actions_html .= sprintf('<option value="%s">%s</option>', $value, $name);
  243. }
  244. $this->bulk_actions_html = $bulk_actions_html;
  245. //Pagination links can also be pre-generated.
  246. //WP has a built-in function for pagination :)
  247. $page_links = paginate_links( array(
  248. 'base' => add_query_arg( 'paged', '%#%' ),
  249. 'format' => '',
  250. 'prev_text' => __('&laquo;'),
  251. 'next_text' => __('&raquo;'),
  252. 'total' => $this->current_filter['max_pages'],
  253. 'current' => $this->page
  254. ));
  255. if ( $page_links ) {
  256. $this->pagination_html = '<div class="tablenav-pages">';
  257. $this->pagination_html .= sprintf(
  258. '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of <span class="current-link-count">%s</span>', 'broken-link-checker' ) . '</span>%s',
  259. number_format_i18n( ( $this->page - 1 ) * $this->per_page + 1 ),
  260. number_format_i18n( min( $this->page * $this->per_page, $this->current_filter['count'] ) ),
  261. number_format_i18n( $this->current_filter['count'] ),
  262. $page_links
  263. );
  264. $this->pagination_html .= '</div>';
  265. } else {
  266. $this->pagination_html = '';
  267. }
  268. }
  269. /**
  270. * Print the bulk edit form.
  271. *
  272. * @param array $visible_columns List of visible columns.
  273. * @return void
  274. */
  275. function bulk_edit_form($visible_columns){
  276. ?>
  277. <tr id="bulk-edit" class="inline-edit-rows"><td colspan="<?php echo count($visible_columns)+1; ?>">
  278. <div id="bulk-edit-wrap">
  279. <fieldset>
  280. <h4><?php _e('Bulk Edit URLs'); ?></h4>
  281. <label>
  282. <span class="title"><?php _e('Find', 'broken-link-checker'); ?></span>
  283. <input type="text" name="search" class="text">
  284. </label>
  285. <label>
  286. <span class="title"><?php _e('Replace with', 'broken-link-checker'); ?></span>
  287. <input type="text" name="replace" class="text">
  288. </label>
  289. <div id="bulk-edit-options">
  290. <span class="title">&nbsp;</span>
  291. <label>
  292. <input type="checkbox" name="case_sensitive">
  293. <?php _e('Case sensitive', 'broken-link-checker'); ?>
  294. </label>
  295. <label>
  296. <input type="checkbox" name="regex">
  297. <?php _e('Regular expression', 'broken-link-checker'); ?>
  298. </label>
  299. </div>
  300. </fieldset>
  301. <p class="submit inline-edit-save">
  302. <a href="#bulk-edit" class="button-secondary cancel alignleft" title="<?php echo esc_attr(__('Cancel', 'broken-link-checker')); ?>" accesskey="c"><?php _e('Cancel', 'broken-link-checker'); ?></a>
  303. <input type="submit" name="bulk_edit" class="button-primary alignright" value="<?php
  304. _e('Update', 'broken-link-checker');
  305. ?>" accesskey="s">
  306. </p>
  307. </div>
  308. </td></tr>
  309. <?php
  310. }
  311. /**
  312. * Print the link row.
  313. *
  314. * @param blcLink $link The link to display.
  315. * @param array $layout List of columns to output.
  316. * @param array $visible_columns List of visible columns.
  317. * @param integer $rownum Table row number.
  318. * @return void
  319. */
  320. function link_row($link, $layout, $visible_columns, $rownum = 0){
  321. //Figure out what CSS classes the link row should have
  322. $rowclass = ($rownum % 2)? 'alternate' : '';
  323. $excluded = $this->core->is_excluded( $link->url );
  324. if ( $excluded ) $rowclass .= ' blc-excluded-link';
  325. if ( $link->redirect_count > 0){
  326. $rowclass .= ' blc-redirect';
  327. }
  328. $days_broken = 0;
  329. if ( $link->broken ){
  330. //Add a highlight to broken links that appear to be permanently broken
  331. $days_broken = intval( (time() - $link->first_failure) / (3600*24) );
  332. if ( $days_broken >= $this->core->conf->options['failure_duration_threshold'] ){
  333. $rowclass .= ' blc-permanently-broken';
  334. if ( $this->core->conf->options['highlight_permanent_failures'] ){
  335. $rowclass .= ' blc-permanently-broken-hl';
  336. }
  337. }
  338. }
  339. $status = $link->analyse_status();
  340. $rowclass .= ' link-status-' . $status['code'];
  341. //Retrieve link instances to display in the table
  342. $instances = $link->get_instances();
  343. if ( !empty($instances) ){
  344. //Put instances that match the selected link type at the top. Makes search results look better.
  345. if ( !empty($this->current_filter['search_params']['s_link_type']) ){
  346. $s_link_type = $this->current_filter['search_params']['s_link_type'];
  347. } else {
  348. $s_link_type = '';
  349. }
  350. $instances = $this->sort_instances_for_display($instances, $s_link_type);
  351. }
  352. printf(
  353. '<tr id="blc-row-%s" class="blc-row %s" data-days-broken="%d">',
  354. $link->link_id,
  355. $rowclass,
  356. $days_broken
  357. );
  358. //The checkbox used to select links is automatically printed in all layouts
  359. //and can't be disabled. Without it, bulk actions wouldn't work.
  360. $this->column_checkbox($link);
  361. foreach($layout as $column_id){
  362. $column = $this->columns[$column_id];
  363. printf(
  364. '<td class="column-%s%s">',
  365. $column_id,
  366. in_array($column_id, $visible_columns) ? '' : ' hidden'
  367. );
  368. if ( isset($column['content']) ){
  369. if ( is_callable($column['content']) ){
  370. call_user_func($column['content'], $link, $instances);
  371. } else {
  372. echo $column['content'];
  373. }
  374. } else {
  375. echo '[', $column_id, ']';
  376. }
  377. echo '</td>';
  378. }
  379. echo '</tr>';
  380. }
  381. /**
  382. * Print the details row for a specific link.
  383. *
  384. * @uses blcTablePrinter::details_row_contents()
  385. *
  386. * @param object $link The link to display.
  387. * @param array $visible_columns List of visible columns.
  388. * @param integer $rownum Table row number.
  389. * @return void
  390. */
  391. function link_details_row($link, $visible_columns, $rownum = 0){
  392. printf(
  393. '<tr id="link-details-%d" class="blc-link-details"><td colspan="%d">',
  394. $link->link_id,
  395. count($visible_columns)+1
  396. );
  397. $this->details_row_contents($link);
  398. echo '</td></tr>';
  399. }
  400. /**
  401. * Print the contents of the details row for a specific link.
  402. *
  403. * @param blcLink $link
  404. * @return void
  405. */
  406. public static function details_row_contents($link){
  407. ?>
  408. <div class="blc-detail-container">
  409. <div class="blc-detail-block" style="float: left; width: 49%;">
  410. <ol style='list-style-type: none;'>
  411. <?php if ( !empty($link->post_date) ) { ?>
  412. <li><strong><?php _e('Post published on', 'broken-link-checker'); ?> :</strong>
  413. <span class='post_date'><?php
  414. echo date_i18n(get_option('date_format'),strtotime($link->post_date));
  415. ?></span></li>
  416. <?php } ?>
  417. <li><strong><?php _e('Link last checked', 'broken-link-checker'); ?> :</strong>
  418. <span class='check_date'><?php
  419. $last_check = $link->last_check;
  420. if ( $last_check < strtotime('-10 years') ){
  421. _e('Never', 'broken-link-checker');
  422. } else {
  423. echo date_i18n(get_option('date_format'), $last_check);
  424. }
  425. ?></span></li>
  426. <li><strong><?php _e('HTTP code', 'broken-link-checker'); ?> :</strong>
  427. <span class='http_code'><?php
  428. print $link->http_code;
  429. ?></span></li>
  430. <li><strong><?php _e('Response time', 'broken-link-checker'); ?> :</strong>
  431. <span class='request_duration'><?php
  432. printf( __('%2.3f seconds', 'broken-link-checker'), $link->request_duration);
  433. ?></span></li>
  434. <li><strong><?php _e('Final URL', 'broken-link-checker'); ?> :</strong>
  435. <span class='final_url'><?php
  436. print $link->final_url;
  437. ?></span></li>
  438. <li><strong><?php _e('Redirect count', 'broken-link-checker'); ?> :</strong>
  439. <span class='redirect_count'><?php
  440. print $link->redirect_count;
  441. ?></span></li>
  442. <li><strong><?php _e('Instance count', 'broken-link-checker'); ?> :</strong>
  443. <span class='instance_count'><?php
  444. print count($link->get_instances());
  445. ?></span></li>
  446. <?php if ( $link->broken && (intval( $link->check_count ) > 0) ){ ?>
  447. <li><br/>
  448. <?php
  449. printf(
  450. _n('This link has failed %d time.', 'This link has failed %d times.', $link->check_count, 'broken-link-checker'),
  451. $link->check_count
  452. );
  453. echo '<br>';
  454. $delta = time() - $link->first_failure;
  455. printf(
  456. __('This link has been broken for %s.', 'broken-link-checker'),
  457. blcUtility::fuzzy_delta($delta)
  458. );
  459. ?>
  460. </li>
  461. <?php } ?>
  462. </ol>
  463. </div>
  464. <div class="blc-detail-block" style="float: right; width: 50%;">
  465. <ol style='list-style-type: none;'>
  466. <li><strong><?php _e('Log', 'broken-link-checker'); ?> :</strong>
  467. <span class='blc_log'><?php
  468. print nl2br($link->log);
  469. ?></span></li>
  470. </ol>
  471. </div>
  472. <div style="clear:both;"> </div>
  473. </div>
  474. <?php
  475. }
  476. function column_checkbox($link){
  477. ?>
  478. <th scope="row" class="check-column"><input type="checkbox" name="selected_links[]" value="<?php echo $link->link_id; ?>" /></th>
  479. <?php
  480. }
  481. /**
  482. * @param blcLink $link
  483. * @param blcLinkInstance[] $instances
  484. */
  485. function column_status($link, $instances){
  486. printf(
  487. '<table class="mini-status" title="%s">',
  488. esc_attr(__('Show more info about this link', 'broken-link-checker'))
  489. );
  490. $status = $link->analyse_status();
  491. printf(
  492. '<tr class="link-status-row link-status-%s">
  493. <td>
  494. <span class="http-code">%s</span> <span class="status-text">%s</span>
  495. </td>
  496. </tr>',
  497. $status['code'],
  498. empty($link->http_code)?'':$link->http_code,
  499. $status['text']
  500. );
  501. //Last checked...
  502. if ( $link->last_check != 0 ){
  503. $last_check = _x('Checked', 'checked how long ago', 'broken-link-checker') . ' ';
  504. $last_check .= blcUtility::fuzzy_delta(time() - $link->last_check, 'ago');
  505. printf(
  506. '<tr class="link-last-checked"><td>%s</td></tr>',
  507. $last_check
  508. );
  509. }
  510. //Broken for...
  511. if ( $link->broken ){
  512. $delta = time() - $link->first_failure;
  513. $broken_for = blcUtility::fuzzy_delta($delta);
  514. printf(
  515. '<tr class="link-broken-for"><td>%s %s</td></tr>',
  516. __('Broken for', 'broken-link-checker'),
  517. $broken_for
  518. );
  519. }
  520. echo '</table>';
  521. }
  522. /**
  523. * @param blcLink $link
  524. */
  525. function column_new_url($link){
  526. ?>
  527. <a href="<?php print esc_attr($link->url); ?>" target='_blank' class='blc-link-url' title="<?php echo esc_attr($link->url); ?>">
  528. <?php print $link->url; ?></a>
  529. <input type='text' id='link-editor-<?php print $link->link_id; ?>'
  530. value="<?php print esc_attr($link->url); ?>"
  531. class='blc-link-editor' style='display:none' />
  532. <?php
  533. //Output inline action links for the link/URL
  534. $actions = array();
  535. $actions['edit'] = "<span class='edit'><a href='javascript:void(0)' class='blc-edit-button' title='" . esc_attr( __('Edit link URL' , 'broken-link-checker') ) . "'>". __('Edit URL' , 'broken-link-checker') ."</a>";
  536. $actions['delete'] = "<span class='delete'><a class='submitdelete blc-unlink-button' title='" . esc_attr( __('Remove this link from all posts', 'broken-link-checker') ). "' ".
  537. "href='javascript:void(0);'>" . __('Unlink', 'broken-link-checker') . "</a>";
  538. if ( $link->broken ){
  539. $actions['discard'] = sprintf(
  540. '<span><a href="#" title="%s" class="blc-discard-button">%s</a>',
  541. esc_attr(__('Remove this link from the list of broken links and mark it as valid', 'broken-link-checker')),
  542. __('Not broken', 'broken-link-checker')
  543. );
  544. }
  545. if ( !$link->dismissed && ($link->broken || ($link->redirect_count > 0)) ) {
  546. $actions['dismiss'] = sprintf(
  547. '<span><a href="#" title="%s" class="blc-dismiss-button">%s</a>',
  548. esc_attr(__('Hide this link and do not report it again unless its status changes' , 'broken-link-checker')),
  549. __('Dismiss', 'broken-link-checker')
  550. );
  551. } else if ( $link->dismissed ) {
  552. $actions['undismiss'] = sprintf(
  553. '<span><a href="#" title="%s" class="blc-undismiss-button">%s</a>',
  554. esc_attr(__('Undismiss this link', 'broken-link-checker')),
  555. __('Undismiss', 'broken-link-checker')
  556. );
  557. }
  558. echo '<div class="row-actions">';
  559. echo implode(' | </span>', $actions) .'</span>';
  560. echo "<span style='display:none' class='blc-cancel-button-container'> " .
  561. "| <a href='javascript:void(0)' class='blc-cancel-button' title='". esc_attr(__('Cancel URL editing' , 'broken-link-checker')) ."'>". __('Cancel' , 'broken-link-checker') ."</a></span>";
  562. echo '</div>';
  563. ?>
  564. <div class="blc-url-editor-buttons">
  565. <input type="button" class="button-secondary cancel alignleft blc-cancel-button" value="<?php echo esc_attr(__('Cancel', 'broken-link-checker')); ?>" />
  566. <input type="button" class="button-primary save alignright blc-update-url-button" value="<?php echo esc_attr(__('Update URL', 'broken-link-checker')); ?>" />
  567. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  568. </div>
  569. <?php
  570. }
  571. /**
  572. * @param blcLink $link
  573. * @param blcLinkInstance[] $instances
  574. */
  575. function column_used_in($link, $instances){
  576. echo '<span class="blc-link-id" style="display:none;">',
  577. $link->link_id,
  578. '</span>';
  579. if ( !empty($instances) ){
  580. /** @var $instance blcLinkInstance */
  581. $instance = reset($instances);
  582. echo $instance->ui_get_source();
  583. $actions = $instance->ui_get_action_links();
  584. echo '<div class="row-actions">';
  585. echo implode(' | </span>', $actions);
  586. echo '</div>';
  587. } else {
  588. _e("[An orphaned link! This is a bug.]", 'broken-link-checker');
  589. }
  590. }
  591. /**
  592. * @param blcLink $link
  593. * @param blcLinkInstance[] $instances
  594. */
  595. function column_new_link_text($link, $instances){
  596. if ( empty($instances) ){
  597. echo '<em>N/A</em>';
  598. } else {
  599. $instance = reset($instances); /** @var blcLinkInstance $instance */
  600. echo $instance->ui_get_link_text();
  601. }
  602. }
  603. function column_redirect_url($link, $instances) {
  604. if ( $link->redirect_count > 0 ) {
  605. printf(
  606. '<a href="%1$s" target="_blank" class="blc-redirect-url" title="%1$s">%2$s</a>',
  607. esc_attr($link->final_url),
  608. esc_html($link->final_url)
  609. );
  610. }
  611. }
  612. /**
  613. * Sort a list of link instances to be displayed in the "Broken Links" page.
  614. *
  615. * Groups instances by container type and, if $search_link_type is specified,
  616. * puts instances that have a matching container type or parser type at the
  617. * beginning.
  618. *
  619. * @param array $instances An array of blcLinkInstance objects.
  620. * @param string $searched_link_type Optional. The required container/parser type.
  621. * @return array Sorted array.
  622. */
  623. function sort_instances_for_display($instances, $searched_link_type = ''){
  624. $this->searched_link_type = $searched_link_type;
  625. usort($instances, array($this, 'compare_link_instances'));
  626. return $instances;
  627. }
  628. /**
  629. * Callback function for sorting link instances.
  630. *
  631. * @see blcTablePrinter::sort_instances_for_display()
  632. *
  633. * @param blcLinkInstance $a
  634. * @param blcLinkInstance $b
  635. * @return int
  636. */
  637. function compare_link_instances($a, $b){
  638. if ( !empty($this->searched_link_type) ){
  639. if ( ($a->container_type == $this->searched_link_type) || ($a->parser_type == $this->searched_link_type) ){
  640. if ( ($b->container_type == $this->searched_link_type) || ($b->parser_type == $this->searched_link_type) ){
  641. return 0;
  642. } else {
  643. return -1;
  644. }
  645. } else {
  646. if ( ($b->container_type == $this->searched_link_type) || ($b->parser_type == $this->searched_link_type) ){
  647. return 1;
  648. }
  649. }
  650. }
  651. return strcmp($a->container_type, $b->container_type);
  652. }
  653. }
  654. }//class_exists
  655. ?>