public static function get_list_cards()
 {
     self::$cards = array('000', '010', '020', '030', '100', '110', '120', '130', '200', '210', '220', '230', '300', '310', '320', '330', '400', '410', '420', '430', '500', '510', '520', '530', '600', '610', '620', '630', '700', '710', '720', '730');
     return self::$cards;
 }
Example #2
0
 public static function listener_form()
 {
     global $wpdb;
     if (isset($_GET['dln_crawl']) && $_GET['dln_crawl'] == '2') {
         DLN_Helper_HoroScope::insert_cards_db();
         die;
     }
     if (isset($_GET['dln_crawl']) && $_GET['dln_crawl'] == '3') {
         DLN_Helper_HoroScope::crawl_data_db();
         die;
     }
     if (isset($_GET['dln_crawl']) && $_GET['dln_crawl'] == '4') {
         DLN_Helper_HoroScope::crawl_horoscope_daily();
         die;
     }
     if (isset($_GET['dln_crawl']) && $_GET['dln_crawl'] == 'add_source') {
         DLN_Helper_Source::add_source_default();
     }
     if (isset($_GET['dln_crawl']) && $_GET['dln_crawl'] == '1') {
         include_once DLN_NEW_PLUGIN_DIR . '/libs/simple_html_dom.php';
         //$sources = DLN_Helper_Source::select_lastest( 3 );
         $sukien = new stdClass();
         $thethao = new stdClass();
         $xeco = new stdClass();
         $xeco1 = new stdClass();
         $xeco2 = new stdClass();
         $xeco3 = new stdClass();
         $sukien->type = 'haivl';
         $thethao->type = 'haivl';
         $xeco->type = 'haivl';
         $xeco1->type = 'haivl';
         $xeco2->type = 'haivl';
         $xeco3->type = 'haivl';
         $sukien->link = 'http://haivl.com/';
         $thethao->link = 'http://haivl.com/new/2';
         $xeco->link = 'http://haivl.com/new/3';
         $xeco1->link = 'http://haivl.com/new/4';
         $xeco2->link = 'http://haivl.com/new/5';
         $xeco3->link = 'http://haivl.com/new/6';
         $sources[] = $sukien;
         $sources[] = $thethao;
         $sources[] = $xeco;
         $sources[] = $xeco1;
         $sources[] = $xeco2;
         $sources[] = $xeco3;
         if ($sources) {
             $arr_links = array();
             $arr_images = array();
             // Get links from source
             foreach ($sources as $i => $source) {
                 if ($source->type) {
                     $source_class = DLN_Helper_Source::load_source_class($source->type);
                     $source_instance = $source_class::get_instance();
                     if ($source_instance && !empty($source->link)) {
                         $links = $source_instance->get_links($source->link);
                         if ($links) {
                             $arr_links = array_merge($arr_links, $links);
                         }
                     }
                 }
             }
             if ($arr_links) {
                 $arr_fb_links = self::get_fb_link_info($arr_links);
                 if (!empty($arr_fb_links)) {
                     $arr_md5 = array();
                     foreach ($arr_fb_links as $i => $link) {
                         if ($link) {
                             $arr_md5[] = $link->md5;
                         }
                     }
                     if (!empty($arr_md5)) {
                         // Get md5 exists in db
                         $where = implode("','", $arr_md5);
                         $sql = "SELECT md5, post_id FROM {$wpdb->dln_news_link} WHERE md5 IN ( '{$where}' )";
                         $arr_links = $wpdb->get_results($sql);
                         if (is_wp_error($arr_links)) {
                             var_dump($arr_links);
                             die;
                         }
                         if (!empty($arr_links) && !is_wp_error($arr_links)) {
                             foreach ($arr_links as $i => $data) {
                                 if (!empty($data->md5)) {
                                     foreach ($arr_fb_links as $i => $link) {
                                         if ($link->md5 == $data->md5) {
                                             $ex = $wpdb->update($wpdb->dln_news_link, array('url' => $link->url, 'update_time' => current_time('mysql'), 'likes' => $link->likes, 'share' => $link->share, 'bound_rate' => $link->bound_rate, 'comments' => $link->comment_count), array('md5' => $data->md5));
                                             if (is_wp_error($ex)) {
                                                 var_dump($ex);
                                                 die;
                                             }
                                             self::insert_fb_comments($data->post_id, $link->comments);
                                             unset($arr_fb_links[$i]);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     // Insert to db
                     if (count($arr_fb_links)) {
                         foreach ($arr_fb_links as $i => $link) {
                             if ($link) {
                                 // Insert post
                                 $post_id = wp_insert_post(array('post_type' => 'dln_source', 'post_title' => $link->title, 'post_content' => $link->desc, 'post_status' => 'publish', 'post_author' => 1));
                                 if (is_wp_error($post_id)) {
                                     var_dump($post_id);
                                     die;
                                 }
                                 if ($post_id) {
                                     if ($link->thumbs) {
                                         update_post_meta($post_id, '_dln_thumbs', $link->thumbs);
                                     }
                                     $ex = $wpdb->insert($wpdb->dln_news_link, array('post_id' => $post_id, 'md5' => $link->md5, 'url' => $link->url, 'title' => $link->title, 'image' => $link->thumbs, 'start_time' => current_time('mysql'), 'likes' => $link->likes, 'share' => $link->share, 'bound_rate' => $link->bound_rate, 'comments' => $link->comment_count));
                                     if (is_wp_error($ex)) {
                                         var_dump($ex);
                                         die;
                                     }
                                     self::insert_fb_comments($post_id, $link->comments);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         exit;
     }
 }