Example #1
0
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public function get_links($url = '')
 {
     if (!$url || !$this->sel_listing) {
         return false;
     }
     $arr_url = DLN_Helper_Source::validate_url($url);
     $host = isset($arr_url['host']) ? $arr_url['host'] : '';
     $url = isset($arr_url['full']) ? $arr_url['full'] : '';
     $arr_links = array();
     if ($url) {
         // Get urls raw
         $arr_urls = array();
         $links = array();
         $opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n"));
         $context = stream_context_create($opts);
         $this->html = file_get_html($url, false, $context);
         if (is_array($this->sel_listing)) {
             foreach ($this->sel_listing as $i => $selector) {
                 $links = array_merge($links, $this->html->find($selector));
             }
         } else {
             $links = $this->html->find($this->sel_listing);
         }
         if (is_array($links)) {
             foreach ($links as $i => $link) {
                 if ($link->href) {
                     // Exclude bad url
                     if (!in_array($link->href, $this->arr_prevent)) {
                         if (substr($link->href, 0, 4) === 'http') {
                             $crawl_url = $link->href;
                         } else {
                             $crawl_url = $host . $link->href;
                         }
                         $arr_urls[] = $crawl_url;
                     }
                 }
             }
         }
         // Exclude duplicate urls
         if (!empty($arr_urls)) {
             foreach ($arr_urls as $i => $url) {
                 if (!in_array($url, $arr_links)) {
                     $arr_links[] = $url;
                 }
             }
         }
     }
     return $arr_links;
 }
 public static function get_links($url = '')
 {
     if (!$url || !self::$sel_listing) {
         return false;
     }
     $arr_url = DLN_Helper_Source::validate_url($url);
     $host = isset($arr_url['host']) ? $arr_url['host'] : '';
     $url = isset($arr_url['full']) ? $arr_url['full'] : '';
     $arr_links = array();
     if ($url) {
         // Get urls raw
         $arr_urls = array();
         $links = array();
         $html = file_get_html($url);
         if (is_array(self::$sel_listing)) {
             foreach (self::$sel_listing as $i => $selector) {
                 $links = array_merge($links, $html->find($selector));
             }
         } else {
             $links = $html->find(self::$sel_listing);
         }
         if (is_array($links)) {
             foreach ($links as $i => $link) {
                 if ($link->href) {
                     // Exclude bad url
                     if (!in_array($link->href, self::$arr_prevent)) {
                         if (substr($link->href, 0, 4) === 'http') {
                             $crawl_url = $link->href;
                         } else {
                             $crawl_url = $host . $link->href;
                         }
                         $crawl_url = str_replace('#box_comment', '', $crawl_url);
                         $arr_urls[] = $crawl_url;
                     }
                 }
             }
         }
         // Exclude duplicate urls
         if (!empty($arr_urls)) {
             foreach ($arr_urls as $i => $url) {
                 if (!in_array($url, $arr_links)) {
                     //var_dump(json_decode( file_get_contents( 'https://graph.facebook.com/v2.1/?ids=' . $url . '&access_token=225132297553705|8f00d29717ee8c6a49cd25da80c5aad8' ) ));
                     $arr_links[] = $url;
                 }
             }
         }
     }
     return $arr_links;
 }
Example #4
0
 public static function get_links($url = '')
 {
     if (!$url || !self::$sel_listing) {
         return false;
     }
     $arr_url = DLN_Helper_Source::validate_url($url);
     $host = isset($arr_url['host']) ? $arr_url['host'] : '';
     $url = isset($arr_url['full']) ? $arr_url['full'] : '';
     $arr_links = array();
     if ($url) {
         // Get urls raw
         $arr_urls = array();
         $links = array();
         $html = file_get_html($url);
         if (is_array(self::$sel_listing)) {
             foreach (self::$sel_listing as $i => $selector) {
                 $links = array_merge($links, $html->find($selector));
             }
         } else {
             $links = $html->find(self::$sel_listing);
         }
         if (is_array($links)) {
             foreach ($links as $i => $link) {
                 if ($link->href) {
                     // Exclude bad url
                     if (!in_array($link->href, self::$arr_prevent)) {
                         if (substr($link->href, 0, 4) === 'http') {
                             $crawl_url = $link->href;
                         } else {
                             $crawl_url = $host . $link->href;
                         }
                         $arr_urls[] = $crawl_url;
                     }
                 }
             }
         }
         // Exclude duplicate urls
         if (!empty($arr_urls)) {
             foreach ($arr_urls as $i => $url) {
                 if (!in_array($url, $arr_links)) {
                     $arr_links[] = $url;
                 }
             }
         }
     }
     return $arr_links;
 }
Example #5
0
 public static function save_source_cat_fields($term_id, $tt_id, $taxonomy)
 {
     $link = isset($_POST['dln_source_link']) ? $_POST['dln_source_link'] : '';
     $type = isset($_POST['dln_source_type']) ? $_POST['dln_source_type'] : '';
     $result = DLN_Helper_Source::add_source($term_id, $link, $type);
     if (is_wp_error($result)) {
         echo $result->get_error_message();
     }
 }
Example #6
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;
     }
 }