Ejemplo n.º 1
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // shorten values
         $pagePath = $this->frm->getField('page_path')->getValue();
         if (count($this->linkList) > 1) {
             $pageList = $this->frm->getField('page_list')->getSelected();
         }
         // get the target
         if ($this->frm->getfield('page_path')->isFilled()) {
             $page = $pagePath;
         } elseif ($pageList == '0') {
             $page = null;
         } else {
             $page = SITE_MULTILANGUAGE ? substr($pageList, strpos($pageList, '/', 1)) : $pageList;
         }
         // validate fields
         if (isset($page) && !SpoonFilter::isURL(SITE_URL . $page)) {
             $this->frm->getField('page_path')->addError(BL::err('InvalidURL'));
         }
         if (!isset($page)) {
             $this->frm->getField('page_path')->addError(BL::err('FieldIsRequired'));
         }
         if (!$this->frm->getField('page_path')->isFilled() && !$this->frm->getfield('page_list')->isFilled()) {
             $this->frm->getField('page_path')->addError(BL::err('FieldIsRequired'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // get metrics
             $metrics = BackendAnalyticsHelper::getMetricsForPage($page, $this->startTimestamp, $this->endTimestamp);
             // build item
             $item['page_path'] = $page;
             $item['entrances'] = isset($metrics['entrances']) ? $metrics['entrances'] : 0;
             $item['bounces'] = isset($metrics['bounces']) ? $metrics['bounces'] : 0;
             $item['bounce_rate'] = ($metrics['entrances'] == 0 ? 0 : number_format((int) $metrics['bounces'] / $metrics['entrances'] * 100, 2)) . '%';
             $item['start_date'] = date('Y-m-d', $this->startTimestamp) . ' 00:00:00';
             $item['end_date'] = date('Y-m-d', $this->endTimestamp) . ' 00:00:00';
             $item['updated_on'] = date('Y-m-d H:i:s');
             // insert the item
             $item['id'] = (int) BackendAnalyticsModel::insertLandingPage($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_landing_page', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('landing_pages') . '&report=saved&var=' . urlencode($item['page_path']));
         }
     }
 }
Ejemplo n.º 2
0
    /**
     * Fetch landing pages
     *
     * @return	array
     * @param	int $startTimestamp			The start timestamp for the cache file.
     * @param	int $endTimestamp			The end timestamp for the cache file.
     * @param	int[optional] $limit		An optional limit of the number of landing pages to get.
     */
    public static function getLandingPages($startTimestamp, $endTimestamp, $limit = null)
    {
        // init vars
        $results = array();
        $db = BackendModel::getDB();
        // get data from database
        if ($limit === null) {
            $items = (array) $db->getRecords('SELECT *, UNIX_TIMESTAMP(updated_on) AS updated_on
																FROM analytics_landing_pages
																ORDER BY entrances DESC');
        } else {
            $items = (array) $db->getRecords('SELECT *, UNIX_TIMESTAMP(updated_on) AS updated_on
												FROM analytics_landing_pages
												ORDER BY entrances DESC
												LIMIT ?', array((int) $limit));
        }
        // loop items
        foreach ($items as $item) {
            // init var
            $result = array();
            $startDate = date('Y-m-d', $startTimestamp) . ' 00:00:00';
            $endDate = date('Y-m-d', $endTimestamp) . ' 00:00:00';
            // no longer up to date, not for the period we need - get new one
            if ($item['updated_on'] < time() - 43200 || $item['start_date'] != $startDate || $item['end_date'] != $endDate) {
                // get metrics
                $metrics = BackendAnalyticsHelper::getMetricsForPage($item['page_path'], $startTimestamp, $endTimestamp);
                // build item
                $result['page_path'] = $item['page_path'];
                $result['entrances'] = isset($metrics['entrances']) ? $metrics['entrances'] : 0;
                $result['bounces'] = isset($metrics['bounces']) ? $metrics['bounces'] : 0;
                $result['bounce_rate'] = ($metrics['entrances'] == 0 ? 0 : number_format((int) $metrics['bounces'] / $metrics['entrances'] * 100, 2)) . '%';
                $result['start_date'] = $startDate;
                $result['end_date'] = $endDate;
                $result['updated_on'] = date('Y-m-d H:i:s');
                // update record
                $db->update('analytics_landing_pages', $result, 'id = ?', $item['id']);
            } else {
                $result = $item;
            }
            // add encoded page path
            $result['page_encoded'] = urlencode($result['page_path']);
            // save record in results array
            $results[] = $result;
        }
        // return results
        return $results;
    }