private static function init($view_folder, $cache_folder, $config_path)
 {
     define('CardsConst', 1);
     // SETTINGS
     $config = (require $config_path);
     $config_root = dirname($config_path);
     // get stats for this page
     // make it work from iframe
     $path = "/";
     if (isset($_GET['path'])) {
         $path = $_GET['path'];
     }
     if (isset($_SERVER['HTTP_REFERER'])) {
         $path = $_SERVER['HTTP_REFERER'];
     }
     if (substr($path, 0, 4) == "http") {
         // get relative path only
         $path = parse_url($path, PHP_URL_PATH);
     }
     //$_SERVER['REQUEST_URI'];
     // CLASSES
     $hero = new APIHero(function () use($config, $config_root) {
         $handler = new APIHandler($config_root . "/" . $config['ACCESS_FILE'], $config['SERVICE_EMAIL']);
         $service = $handler->getService();
         $view = $handler->getFirstprofileId($config['TRACKING_ID']);
         return [$service, $view];
     }, $cache_folder);
     $hero->setPath($path);
     $hero->setLimit(5);
     $hero->setPeriod($config['TRACKING_PERIOD_DAYS']);
     // make request
     $countries = $hero->getTopCountries();
     $cities = $hero->getTopCities();
     // RENDER HTML
     $render = new DataRender($view_folder, $cache_folder);
     $render->setColor($config['material_color']);
     $render->setCountries($countries);
     $render->setCities($cities);
     $render->setDays($config['TRACKING_PERIOD_DAYS']);
     return $render;
 }
Пример #2
0
 public function load(HttpLoader $loader, DataRender $render)
 {
     $pages_url = $this->webPagesURI;
     $result = $loader->load($pages_url);
     //print_r($result);
     if (false !== $result) {
         return $render->render($result);
     } else {
         echo 'failed curl request';
     }
 }