<?php namespace WebBot\Core\WebBot; use WebBot\Core\Bot; // set unlimited execution time set_time_limit(0); // set the default timeout to 1 seconds Bot::$conf_default_timeout = 1; // set delay between consecutive fetches (in milli seconds) Bot::$conf_delay_between_fetches = 1000; // do not use HTTPS protocol Bot::$conf_force_https = false; // don't include document field raw values Bot::$conf_include_document_field_raw_values = false; // set the directory for storing information // $dir = your/custom/path; if (defined('LIB_PATH')) { $dir = LIB_PATH . '/WebBot/tmp/'; } else { $dir = '../tmp/'; } Bot::$logging = false; Bot::$conf_store_dir = $dir;
public static function fetchCampaign($url) { $data = []; try { $bot = new Bot(['cloud' => $url], ['logging' => false]); $bot->execute(); $documents = $bot->getDocuments(); // because only variables can be passed as reference $doc = array_shift($documents); $type = $doc->type; if (preg_match("/image/i", $type)) { $data["image"] = $data["url"] = $url; $data["description"] = $data["title"] = ""; return $data; } $data["title"] = $doc->query("/html/head/title")->item(0)->nodeValue; $data["url"] = $url; $data["description"] = ""; $data["image"] = ""; $metas = $doc->query("/html/head/meta"); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if ($meta->getAttribute('name') == 'description') { $data["description"] = $meta->getAttribute('content'); } if ($meta->getAttribute('property') == 'og:image') { $data["image"] = $meta->getAttribute('content'); } } } catch (\Exception $e) { $data["url"] = $url; $data["image"] = $data["description"] = $data["title"] = ""; } return $data; }