Ejemplo n.º 1
0
 public function actionCategory()
 {
     $cate_id = urlGETParams('cate_id', VARIABLE_NUMBER);
     $query = "SELECT * FROM tbl_category WHERE id = " . $cate_id;
     $category = $this->db->createCommand($query)->queryRow();
     $category_url = $category['cnet_url'];
     echo "<pre>" . print_r($category, true) . "</pre>";
     echo $category_url . '<br />';
     $response = fectchContent($category_url);
     $html = str_get_html($response);
     $data = array();
     for ($i = 1; $i <= 100; $i++) {
         $item = $html->find('div[section="prod' . $i . '"]', 0);
         if (!empty($item)) {
             $a = $item->find('a', 0);
             $link_url = $this->_domain . trim($a->href);
             $dek = $item->find('.dek', 0);
             if (!empty($dek)) {
                 $data[$link_url] = trim($dek->innertext());
             }
         }
     }
     if (empty($data)) {
         echo 'Khong co du lieu vui long kiem tra lai';
     }
     $params = array();
     foreach ($data as $link_url => $dek) {
         $params[] = array('cate_id' => $cate_id, 'url' => $link_url, 'md5url' => md5($link_url), 'source_id' => $this->_source_id, 'short_text' => $dek, 'parent_id' => $category['parent_id']);
     }
     $params = array_reverse($params);
     yii_insert_multiple('link', $params, 'db_crawler');
     echo "<pre>" . print_r($params, true) . "</pre>";
 }
Ejemplo n.º 2
0
 public function actionChannel()
 {
     $id = $_GET['id'];
     $channel_id = $this->_channel[$id];
     $channel_name = $this->_channel_name[$id];
     $pageToken = $_GET['pageToken'];
     $url = 'https://www.googleapis.com/youtube/v3/activities?part=contentDetails&channelId=' . $channel_id . '&maxResults=50&pageToken=' . $pageToken . '&key=' . $this->_key;
     $data = $this->fectchGoogleData($url);
     if (!empty($data['error'])) {
         echo "<pre>" . print_r($data, true) . "</pre>";
         die;
     }
     $nextPageToken = $data['nextPageToken'];
     $result = $data['items'];
     $list_video = array();
     foreach ($result as $item) {
         if (empty($item['contentDetails']['upload']['videoId'])) {
             continue;
         }
         $list_video[] = array('video_id' => $item['contentDetails']['upload']['videoId'], 'channel_name' => $channel_name);
     }
     $ok = yii_insert_multiple('youtube', $list_video, 'db_crawler');
     var_dump($ok);
     echo '<hr />';
     echo count($list_video) . ' - videos<br />';
     echo '&pageToken=' . $nextPageToken;
 }
Ejemplo n.º 3
0
 public function actionCategory()
 {
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     if ($page < 1) {
         $page = 1;
     }
     $cate_id = urlGETParams('cate_id', VARIABLE_NUMBER);
     $query = "SELECT * FROM tbl_category WHERE id = " . $cate_id;
     $category = $this->db->createCommand($query)->queryRow();
     $category_url = $category['techcrunch_url'];
     if ($page > 1) {
         $category_url .= 'page/' . $page . '/';
         //http://techcrunch.com/mobile/page/5/
     }
     echo "<pre>" . print_r($_GET, true) . "</pre>";
     echo $category_url . '<br />';
     $response = fectchContent($category_url);
     $html = str_get_html($response);
     $contents = $html->find('.block-content');
     $data = array();
     foreach ($contents as $item) {
         $a = $item->find('.post-title a', 0);
         $excerpt = $item->find('.excerpt', 0);
         $excerpt->find('a', 0)->outertext = '';
         $link_url = trim($a->href);
         $data[$link_url] = trim($excerpt->innertext());
     }
     if (empty($data)) {
         echo 'Khong co du lieu vui long kiem tra lai';
     }
     $params = array();
     $remove_link = array();
     foreach ($data as $link_url => $dek) {
         $break = false;
         foreach ($remove_link as $prefix) {
             if (strpos($link_url, $prefix) !== false) {
                 $break = true;
                 unset($data[$link_url]);
                 break;
             }
         }
         if ($break) {
             continue;
         }
         $params[] = array('cate_id' => $cate_id, 'url' => $link_url, 'md5url' => md5($link_url), 'source_id' => $this->_source_id, 'short_text' => $dek, 'parent_id' => $category['parent_id']);
         echo $link_url . '<br />';
     }
     $params = array_reverse($params);
     yii_insert_multiple('link', $params, 'db_crawler');
     //        echo "<pre>" . print_r($params, true) . "</pre>";
 }
Ejemplo n.º 4
0
 public function actionCategory()
 {
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     if ($page < 1) {
         $page = 1;
     }
     $cate_id = urlGETParams('cate_id', VARIABLE_NUMBER);
     $query = "SELECT * FROM tbl_category WHERE id = " . $cate_id;
     $category = $this->db->createCommand($query)->queryRow();
     $category_url = $category['wpcentral_url'];
     if ($page > 1) {
         $category_url .= '?pg=' . $page;
     }
     echo $category_url . '<br />';
     $response = fectchContent($category_url);
     $html = str_get_html($response);
     $content = $html->find('.articles-simple-list', $page == 1 ? 1 : 0);
     $data = array();
     $assets = $content->find('.rf-entry');
     foreach ($assets as $item) {
         $a = $item->find('.rf-image', 0);
         $link_url = $this->_domain . trim($a->href);
         $dek = $item->find('.rf-body', 0);
         if (!empty($dek)) {
             $data[$link_url] = trim($dek->innertext());
         }
     }
     if (empty($data)) {
         echo 'Khong co du lieu vui long kiem tra lai';
     }
     $params = array();
     $remove_link = array();
     foreach ($data as $link_url => $dek) {
         //            $break = false;
         //            foreach ($remove_link as $prefix) {
         //                if (strpos($link_url, $prefix) !== false) {
         //                    $break = true;
         //                    unset($data[$link_url]);
         //                    break;
         //                }
         //            }
         //            if ($break) {
         //                continue;
         //            }
         $params[] = array('cate_id' => $cate_id, 'url' => $link_url, 'md5url' => md5($link_url), 'source_id' => $this->_source_id, 'short_text' => $dek, 'parent_id' => $category['parent_id']);
     }
     $params = array_reverse($params);
     yii_insert_multiple('link', $params, 'db_crawler');
     echo "<pre>" . print_r($params, true) . "</pre>";
 }
Ejemplo n.º 5
0
 public function actionEdit()
 {
     $uid = urlGETParams('id', VARIABLE_NUMBER);
     $record = $this->getRow($uid);
     if (empty($record)) {
         createMessage('Hệ thống không tìm thấy nội dung bạn yêu cầu', 'danger');
         $this->redirect($this->createUrl('index'));
     }
     $data = array();
     $data['user'] = $record;
     $form = new UserForm();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $form->attributes = $_POST['UserForm'];
         if ($form->validate()) {
             $values = array();
             foreach ($form->attributes as $key => $vl) {
                 if ($key == 're_password') {
                     continue;
                 }
                 if ($key == 'password') {
                     if (empty($vl)) {
                         continue;
                     }
                     $vl = md5(trim($vl));
                 }
                 $values[$key] = trim($vl);
             }
             yii_update_row($this->_table, $values, 'id = ' . $uid);
             //user rule
             //xoa rule hien tai
             $query = "DELETE FROM {{user_rule}} WHERE uid = " . $uid;
             $this->db->createCommand($query)->execute();
             $user_rule = formPostParams('rule', VARIABLE_ARRAY);
             if (!empty($user_rule)) {
                 $params = array();
                 foreach ($user_rule as $rule_id) {
                     $params[] = array('uid' => $uid, 'rule_id' => $rule_id);
                 }
                 yii_insert_multiple('user_rule', $params);
             }
             createMessage('Sửa thông tin người dùng thành công');
             $this->redirect($this->createUrl('index'));
         }
     } else {
         $form->attributes = $record;
         $form->password = '';
     }
     $data['rule'] = $this->getListRule();
     //lay danh sach quyen
     $query = "SELECT rule_id FROM {{user_rule}} WHERE uid = " . $uid;
     $data['listRole'] = $this->db->createCommand($query)->queryColumn();
     $data['form'] = $form;
     $this->render('add', array('data' => $data));
 }
Ejemplo n.º 6
0
 public function actionTagYoutube()
 {
     $query = "UPDATE tbl_tags_youtube SET is_feature = 0";
     $this->db->createCommand($query)->execute();
     $query = "SELECT tags FROM tbl_youtube";
     $result = $this->db->createCommand($query)->queryColumn();
     $data = array();
     foreach ($result as $item) {
         $arr = explode(',', trim($item, ','));
         $data = array_merge($data, $arr);
     }
     $data = array_filter($data);
     $data = array_count_values($data);
     uasort($data, 'sortTag');
     $params = array();
     foreach ($data as $tag_id => $total_video) {
         $params[] = array('tag_id' => $tag_id, 'total_video' => $total_video);
     }
     yii_insert_multiple('tag_video', $params);
     $query = "UPDATE tbl_tags_youtube AS t1, tbl_tag_video AS t2 " . "SET t1.total_video = t2.total_video WHERE t1.id = t2.tag_id";
     $this->db->createCommand($query)->execute();
     createMessage('Update total video tag thanh cong');
     $this->redirect($this->createUrl('index'));
 }
Ejemplo n.º 7
0
 public function actionCategory()
 {
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     if ($page < 1) {
         $page = 1;
     }
     //        $cate_id = 1;
     //        $category_url = 'http://www.cnet.com/apple/';
     //        $cate_id = 2;
     //        $category_url = 'http://www.cnet.com/tags/google/';
     //        $cate_id = 3;
     //        $category_url = 'http://www.cnet.com/tags/microsoft/';
     $cate_id = urlGETParams('cate_id', VARIABLE_NUMBER);
     $query = "SELECT * FROM tbl_category WHERE id = " . $cate_id;
     $category = $this->db->createCommand($query)->queryRow();
     $category_url = $category['cnet_url'];
     if ($page > 1) {
         $category_url .= $page;
     }
     echo "<pre>" . print_r($_GET, true) . "</pre>";
     echo $category_url . '<br />';
     $response = fectchContent($category_url);
     $html = str_get_html($response);
     $content = $html->find('.col-8', 0);
     $remove_elements = array('.latestGalleries', '.curated-hero');
     foreach ($content->find(implode(', ', $remove_elements)) as $item) {
         $item->outertext = '';
     }
     $data = array();
     $assets = $content->find('.asset');
     foreach ($assets as $item) {
         $a = $item->find('.assetThumb a', 0);
         $link_url = $this->_domain . trim($a->href);
         $dek = $item->find('p.dek', 0);
         if (!empty($dek)) {
             $data[$link_url] = trim($dek->innertext());
         }
     }
     if (empty($data)) {
         echo 'Khong co du lieu vui long kiem tra lai';
     }
     $params = array();
     $remove_link = array('products', 'videos', 'pictures');
     foreach ($data as $link_url => $dek) {
         $break = false;
         foreach ($remove_link as $prefix) {
             if (strpos($link_url, $prefix) !== false) {
                 $break = true;
                 unset($data[$link_url]);
                 break;
             }
         }
         if ($break) {
             continue;
         }
         $params[] = array('cate_id' => $cate_id, 'url' => $link_url, 'md5url' => md5($link_url), 'source_id' => $this->_source_id, 'short_text' => $dek, 'parent_id' => $category['parent_id']);
     }
     $params = array_reverse($params);
     yii_insert_multiple('link', $params, 'db_crawler');
     echo "<pre>" . print_r($params, true) . "</pre>";
 }
Ejemplo n.º 8
0
 public function actionCategory()
 {
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     if ($page < 0) {
         $page = 0;
     }
     $cate_id = urlGETParams('cate_id', VARIABLE_NUMBER);
     $query = "SELECT * FROM tbl_category WHERE id = " . $cate_id;
     $category = $this->db->createCommand($query)->queryRow();
     $category_url = $category['android_center_url'];
     $category_url .= $page;
     //        echo $category_url . '<br />';
     if ($cate_id == 21) {
         $response = $this->fectchDataFromUrl($category_url);
         if (empty($response)) {
             die('Error Khong lay duoc noi dung');
         }
         $html = str_get_html($response);
         $items = $html->find('.grid_item');
         $data = array();
         foreach ($items as $item) {
             $a = $item->find('.grid_title a', 0);
             $link_url = $this->_domain . trim($a->href);
             if (strpos($link_url, 'forums.androidcentral.com') !== false) {
                 continue;
             }
             $dek = $item->find('.grid_summary', 0);
             if (!empty($dek)) {
                 $str_desc = $dek->innertext();
                 $str_desc = strip_tags($str_desc);
                 $data[$link_url] = trim($str_desc);
             }
         }
     } else {
         $response = fectchContent($category_url);
         $html = str_get_html($response);
         $content = $html->find('.content', 0);
         $items = $content->find('.node-article');
         foreach ($items as $item) {
             $a = $item->find('h2 a', 0);
             $link_url = $this->_domain . trim($a->href);
             if (strpos($link_url, 'forums.androidcentral.com') !== false) {
                 continue;
             }
             $dek = $item->find('.body', 0);
             if (!empty($dek)) {
                 $str_desc = $dek->innertext();
                 $str_desc = strip_tags($str_desc);
                 $data[$link_url] = trim($str_desc);
             }
         }
     }
     if (empty($data)) {
         echo 'Khong co du lieu vui long kiem tra lai';
         die;
     }
     $params = array();
     foreach ($data as $link_url => $dek) {
         $params[] = array('cate_id' => $cate_id, 'url' => $link_url, 'md5url' => md5($link_url), 'source_id' => $this->_source_id, 'short_text' => $dek, 'parent_id' => $category['parent_id']);
     }
     $params = array_reverse($params);
     yii_insert_multiple('link', $params, 'db_crawler');
     echo "<pre>" . print_r($params, true) . "</pre>";
 }
Ejemplo n.º 9
0
 public function actionPermission()
 {
     $data = array();
     $rule_id = urlGETParams('id', VARIABLE_NUMBER);
     $record = $this->getRow($rule_id);
     if (empty($record)) {
         createMessage('Nội dung bạn yêu cầu không tồn tại');
         $this->redirect($this->createUrl('index'));
     }
     $data['rule'] = $record;
     $system = isset($_GET['system']) ? trim($_GET['system']) : 'backend';
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (!empty($_POST)) {
             $query_delete = "DELETE FROM {{permission}} WHERE rule_id = :rule_id AND system = :system";
             $values = array(':rule_id' => $rule_id, ':system' => $system);
             $this->db->createCommand($query_delete)->bindValues($values)->execute();
             $params = array();
             foreach ($_POST as $controller => $actions) {
                 $params[] = array('system' => $system, 'rule_id' => $rule_id, 'controller' => $controller, 'actions' => serialize($actions));
             }
             if (!empty($params)) {
                 yii_insert_multiple('permission', $params);
             }
         }
         createMessage('Cập nhật thành công');
         $this->redirect($_SERVER['HTTP_REFERER']);
     }
     $query = "SELECT * FROM {{permission}} WHERE system = :system AND rule_id = :rule_id";
     $values = array(':system' => 'backend', ':rule_id' => $rule_id);
     $listController = $this->db->createCommand($query)->bindValues($values)->queryAll();
     $data['listController'] = array();
     if (!empty($listController)) {
         foreach ($listController as $item) {
             $data['listController'][$item['controller']] = unserialize($item['actions']);
         }
     }
     $myPath = ROOT_PATH . '/protected/controllers/' . $system;
     $controller_ignore = $this->controllerIgnore();
     $dir = new DirectoryIterator($myPath);
     $listClass = array();
     foreach ($dir as $fileinfo) {
         $pattern = '/.*\\.(php)/i';
         if (!$fileinfo->isDot() && $fileinfo->isFile()) {
             if (preg_match($pattern, $fileinfo->getFilename())) {
                 $filename = $fileinfo->getFilename();
                 //var_dump(file_exists($path . '/' . $filename));
                 //echo $myPath . '/' . $filename . '<br />';
                 include_once $myPath . '/' . $filename;
                 $filename = substr($filename, 0, strlen($filename) - 4);
                 $filename_tmp = str_replace('Controller', '', $filename);
                 if (in_array(strtolower($filename_tmp), $controller_ignore[$system])) {
                     continue;
                 }
                 $listClass[] = $filename;
             }
         }
     }
     $listAction = array();
     foreach ($listClass as $class) {
         $controller = strtolower(str_replace('Controller', '', $class));
         $listAction[$controller]['name'] = $class;
         $refClass = new ReflectionClass($class);
         $doc = $refClass->getDocComment();
         preg_match_all('#@desc(.*?)\\n#s', $doc, $desc);
         $listAction[$controller]['description'] = trim($desc[1][0]);
         $listAction[$controller]['controller'] = $controller;
         $actions = array();
         $class_methods = get_class_methods(new $class());
         foreach ($class_methods as $method) {
             $reflect = new ReflectionMethod($class, $method);
             if (strpos($method, 'action') === 0 && $reflect->isPublic() && $method != 'actions') {
                 $actions[] = strtolower(substr($method, 6, strlen($method)));
             }
         }
         $listAction[$controller]['actions'] = $actions;
     }
     $data['listItem'] = $listAction;
     $this->render('permission', array('data' => $data));
 }