예제 #1
0
 public function getCrawlerInfo()
 {
     $data = $this->extractJsonFromPost();
     $id = (int) $data['id'];
     $crawlerModel = new CrawlerModel();
     $crawlerInfo = $crawlerModel->getCrawlerInfo($id);
     $response = array('success' => true, 'data' => $crawlerInfo);
     $this->jsonResponseOutput($response);
 }
예제 #2
0
파일: Home.php 프로젝트: krike/crawler-tool
 public function index()
 {
     $model = new CrawlerModel();
     $this->viewData['sources'] = $model->getAllSources();
     echo $this->twig->render('home/index.html.twig', $this->viewData);
 }
예제 #3
0
 public function index()
 {
     $crawlerModel = new CrawlerModel();
     $this->viewData['images'] = $crawlerModel->getAllFetchedImages();
     echo $this->twig->render('gallery/index.html.twig', $this->viewData);
 }
예제 #4
0
 public function getImage($returnJson = true)
 {
     $url = $_POST['url'];
     $crawlerId = $_POST['crawler'];
     $crawlerModel = new CrawlerModel();
     $crawlerInfo = $crawlerModel->getCrawlerInfo($crawlerId);
     if (empty($url)) {
         return false;
     }
     if (empty($crawlerId)) {
         return false;
     }
     $crawlerModel = new CrawlerModel();
     $source = $crawlerModel->getSourceById($crawlerInfo['source_type']);
     $dom = HtmlDomParser::file_get_html($url);
     $images = $dom->find($source['main_image']);
     $imgSrc = $images[0]->src;
     /**
      * find more sources
      */
     $moreSources = array();
     $moreFromBlock = $dom->find('.domainLinkWrapper');
     if (isset($moreFromBlock[0])) {
         $moreSources[] = $moreFromBlock[0]->href;
     }
     //paged Collection (suggested boards under pin
     $pagedCollection = $dom->find('.PagedCollection');
     if (isset($pagedCollection[0]) && !empty($pagedCollection[0])) {
         $boardLinkWrapper = $pagedCollection[0]->find('.boardLinkWrapper');
         foreach ($boardLinkWrapper as $blw) {
             $moreSources[] = $blw->href;
         }
     }
     $imgData = array('image' => $imgSrc, 'more-sources' => $moreSources);
     if ($returnJson) {
         echo json_encode($imgData);
         exit;
     } else {
         return $imgData;
     }
 }
예제 #5
0
 public function saveSources($sources, $crawlerId, $source_id)
 {
     $model = new CrawlerModel();
     foreach ($sources as $source) {
         $model->insertNewTempSource($source, $source_id);
     }
 }