예제 #1
0
 function links_checker()
 {
     MainWP_Child_Links_Checker::Instance()->action();
 }
 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;
 }