Exemplo n.º 1
0
Arquivo: Cse.php Projeto: sfie/pimcore
 /**
  *
  */
 public function load()
 {
     $client = Api::getSimpleClient();
     $config = $this->getConfig();
     $perPage = $this->getPerPage();
     $offset = $this->getOffset();
     $query = $this->getQuery();
     if ($client) {
         $search = new \Google_Service_Customsearch($client);
         // determine language
         $language = "";
         if (\Zend_Registry::isRegistered("Zend_Locale")) {
             $locale = \Zend_Registry::get("Zend_Locale");
             $language = $locale->getLanguage();
         }
         if (!array_key_exists("hl", $config) && !empty($language)) {
             $config["hl"] = $language;
         }
         if (!array_key_exists("lr", $config) && !empty($language)) {
             $config["lr"] = "lang_" . $language;
         }
         if ($query) {
             if ($offset) {
                 $config["start"] = $offset + 1;
             }
             if (empty($perPage)) {
                 $perPage = 10;
             }
             $config["num"] = $perPage;
             $cacheKey = "google_cse_" . md5($query . serialize($config));
             // this is just a protection so that no query get's sent twice in a request (loops, ...)
             if (\Zend_Registry::isRegistered($cacheKey)) {
                 $result = \Zend_Registry::get($cacheKey);
             } else {
                 if (!($result = Cache::load($cacheKey))) {
                     $result = $search->cse->listCse($query, $config);
                     Cache::save($result, $cacheKey, array("google_cse"), 3600, 999);
                     \Zend_Registry::set($cacheKey, $result);
                 }
             }
             $this->readGoogleResponse($result);
             return $this->getResults(false);
         }
         return array();
     } else {
         throw new \Exception("Google Simple API Key is not configured in System-Settings.");
     }
 }
Exemplo n.º 2
0
 /**
  * @param null $fields
  * @param null $drillDownFilters
  * @param bool $useDimensionHandling
  * @return mixed
  * @throws \Exception
  */
 protected function getDataHelper($fields = null, $drillDownFilters = null, $useDimensionHandling = true)
 {
     $configuration = clone $this->config;
     if (is_array($fields) && sizeof($fields)) {
         $configuration = $this->handleFields($configuration, $fields);
     }
     if ($this->fullConfig && $useDimensionHandling) {
         $configuration = $this->handleDimensions($configuration);
     }
     $client = \Pimcore\Google\Api::getServiceClient();
     if (!$client) {
         throw new \Exception("Google Analytics is not configured");
     }
     $service = new \Google_Service_Analytics($client);
     if (!$configuration->profileId) {
         throw new \Exception("no profileId given");
     }
     if (!$configuration->metric) {
         throw new \Exception("no metric given");
     }
     $options = array();
     if ($configuration->filters) {
         $options['filters'] = $configuration->filters;
     }
     if ($configuration->dimension) {
         $options['dimensions'] = $configuration->dimension;
     }
     if ($configuration->sort) {
         $options['sort'] = $configuration->sort;
     }
     if ($configuration->startIndex) {
         $options['start-index'] = $configuration->startIndex;
     }
     if ($configuration->maxResults) {
         $options['max-results'] = $configuration->maxResults;
     }
     if ($configuration->segment) {
         $options['segment'] = $configuration->segment;
     }
     $configuration->startDate = $this->calcDate($configuration->startDate, $configuration->relativeStartDate);
     $configuration->endDate = $this->calcDate($configuration->endDate, $configuration->relativeEndDate);
     if (!$configuration->startDate) {
         throw new \Exception("no start date given");
     }
     if (!$configuration->endDate) {
         throw new \Exception("no end date given");
     }
     return $service->data_ga->get('ga:' . $configuration->profileId, date('Y-m-d', $configuration->startDate), date('Y-m-d', $configuration->endDate), $configuration->metric, $options);
 }
Exemplo n.º 3
0
 public function getSystemAction()
 {
     $this->checkPermission("system_settings");
     $values = Config::getSystemConfig();
     if (($handle = fopen(PIMCORE_PATH . "/config/timezones.csv", "r")) !== FALSE) {
         while (($rowData = fgetcsv($handle, 10000, ",", '"')) !== false) {
             $timezones[] = $rowData[0];
         }
         fclose($handle);
     }
     $locales = Tool::getSupportedLocales();
     $languageOptions = array();
     foreach ($locales as $short => $translation) {
         if (!empty($short)) {
             $languageOptions[] = array("language" => $short, "display" => $translation . " ({$short})");
             $validLanguages[] = $short;
         }
     }
     $valueArray = $values->toArray();
     $valueArray['general']['validLanguage'] = explode(",", $valueArray['general']['validLanguages']);
     //for "wrong" legacy values
     if (is_array($valueArray['general']['validLanguage'])) {
         foreach ($valueArray['general']['validLanguage'] as $existingValue) {
             if (!in_array($existingValue, $validLanguages)) {
                 $languageOptions[] = array("language" => $existingValue, "display" => $existingValue);
             }
         }
     }
     //cache exclude patterns - add as array
     if (!empty($valueArray['cache']['excludePatterns'])) {
         $patterns = explode(",", $valueArray['cache']['excludePatterns']);
         if (is_array($patterns)) {
             foreach ($patterns as $pattern) {
                 $valueArray['cache']['excludePatternsArray'][] = array("value" => $pattern);
             }
         }
     }
     //remove password from values sent to frontend
     $valueArray['database']["params"]['password'] = "******";
     //admin users as array
     $adminUsers = array();
     $userList = new Model\User\Listing();
     $userList->setCondition("admin = 1 and email is not null and email != ''");
     $users = $userList->load();
     if (is_array($users)) {
         foreach ($users as $user) {
             $adminUsers[] = array("id" => $user->getId(), "username" => $user->getName());
         }
     }
     $adminUsers[] = array("id" => "", "username" => "-");
     $response = array("values" => $valueArray, "adminUsers" => $adminUsers, "config" => array("timezones" => $timezones, "languages" => $languageOptions, "client_ip" => Tool::getClientIp(), "google_private_key_exists" => file_exists(\Pimcore\Google\Api::getPrivateKeyPath()), "google_private_key_path" => \Pimcore\Google\Api::getPrivateKeyPath()));
     $this->_helper->json($response);
 }
Exemplo n.º 4
0
 public function getMetricsAction()
 {
     $this->_helper->json(["data" => Google\Api::getAnalyticsMetrics()]);
 }