/** * Print the contents of the details row for a specific link. * * @param blcLink $link * @return void */ public static function details_row_contents($link) { ?> <div class="blc-detail-container"> <div class="blc-detail-block" style="float: left; width: 49%;"> <ol style='list-style-type: none;'> <?php if (!empty($link->post_date)) { ?> <li><strong><?php _e('Post published on', 'broken-link-checker'); ?> :</strong> <span class='post_date'><?php echo date_i18n(get_option('date_format'), strtotime($link->post_date)); ?> </span></li> <?php } ?> <li><strong><?php _e('Link last checked', 'broken-link-checker'); ?> :</strong> <span class='check_date'><?php $last_check = $link->last_check; if ($last_check < strtotime('-10 years')) { _e('Never', 'broken-link-checker'); } else { echo date_i18n(get_option('date_format'), $last_check); } ?> </span></li> <li><strong><?php _e('HTTP code', 'broken-link-checker'); ?> :</strong> <span class='http_code'><?php print $link->http_code; ?> </span></li> <li><strong><?php _e('Response time', 'broken-link-checker'); ?> :</strong> <span class='request_duration'><?php printf(__('%2.3f seconds', 'broken-link-checker'), $link->request_duration); ?> </span></li> <li><strong><?php _e('Final URL', 'broken-link-checker'); ?> :</strong> <span class='final_url'><?php print $link->final_url; ?> </span></li> <li><strong><?php _e('Redirect count', 'broken-link-checker'); ?> :</strong> <span class='redirect_count'><?php print $link->redirect_count; ?> </span></li> <li><strong><?php _e('Instance count', 'broken-link-checker'); ?> :</strong> <span class='instance_count'><?php print count($link->get_instances()); ?> </span></li> <?php if ($link->broken && intval($link->check_count) > 0) { ?> <li><br/> <?php printf(_n('This link has failed %d time.', 'This link has failed %d times.', $link->check_count, 'broken-link-checker'), $link->check_count); echo '<br>'; $delta = time() - $link->first_failure; printf(__('This link has been broken for %s.', 'broken-link-checker'), blcUtility::fuzzy_delta($delta)); ?> </li> <?php } ?> </ol> </div> <div class="blc-detail-block" style="float: right; width: 50%;"> <ol style='list-style-type: none;'> <li><strong><?php _e('Log', 'broken-link-checker'); ?> :</strong> <span class='blc_log'><?php print nl2br($link->log); ?> </span></li> </ol> </div> <div style="clear:both;"> </div> </div> <?php }
static function sync_link_data() { $max_results = get_option('mainwp_child_blc_max_number_of_links', 50); $params = array(array('load_instances' => true)); if (!empty($max_results)) { $params['max_results'] = $max_results; } $links = blc_get_links($params); $get_fields = array('link_id', 'url', 'being_checked', 'last_check', 'last_check_attempt', 'check_count', 'http_code', 'request_duration', 'timeout', 'redirect_count', 'final_url', 'broken', 'first_failure', 'last_success', 'may_recheck', 'false_positive', 'dismissed', 'status_text', 'status_code', 'log'); $return = ''; $site_id = $_POST['site_id']; $blc_option = get_option('wsblc_options'); if (is_string($blc_option) && !empty($blc_option)) { $blc_option = json_decode($blc_option, true); } if (is_array($links)) { foreach ($links as $link) { $lnk = new stdClass(); foreach ($get_fields as $field) { $lnk->{$field} = $link->{$field}; } if (!empty($link->post_date)) { $lnk->post_date = $link->post_date; } $days_broken = 0; if ($link->broken) { //Add a highlight to broken links that appear to be permanently broken $days_broken = intval((time() - $link->first_failure) / (3600 * 24)); if ($days_broken >= $blc_option['failure_duration_threshold']) { $lnk->permanently_broken = 1; if ($blc_option['highlight_permanent_failures']) { $lnk->permanently_broken_highlight = 1; } } } $lnk->days_broken = $days_broken; $instances = false; $get_link = new blcLink(intval($link->link_id)); if ($get_link->valid()) { $instances = $get_link->get_instances(); } if (!empty($instances)) { $first_instance = reset($instances); $lnk->link_text = $first_instance->ui_get_link_text(); $lnk->count_instance = count($instances); $container = $first_instance->get_container(); /** @var blcContainer $container */ $lnk->container = $container; if (!empty($container)) { $lnk->container_type = $container->container_type; $lnk->container_id = $container->container_id; $lnk->source_data = MainWP_Child_Links_Checker::Instance()->ui_get_source($container, $first_instance->container_field); } $can_edit_text = false; $can_edit_url = false; $editable_link_texts = $non_editable_link_texts = array(); foreach ($instances as $instance) { if ($instance->is_link_text_editable()) { $can_edit_text = true; $editable_link_texts[$instance->link_text] = true; } else { $non_editable_link_texts[$instance->link_text] = true; } if ($instance->is_url_editable()) { $can_edit_url = true; } } $link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts; $data_link_text = ''; if (count($link_texts) === 1) { //All instances have the same text - use it. $link_text = key($link_texts); $data_link_text = esc_attr($link_text); } $lnk->data_link_text = $data_link_text; $lnk->can_edit_url = $can_edit_url; $lnk->can_edit_text = $can_edit_text; } else { $lnk->link_text = ''; $lnk->count_instance = 0; } $lnk->site_id = $site_id; $return[] = $lnk; } } else { return ''; } return $return; }