Exemplo n.º 1
0
 /** Logger hook: log number of results, if available */
 public function logResults($notification)
 {
     $action = $notification->getNotificationObject();
     $idaction = $action->getIdActionUrl();
     // load site config from tracker cache
     $info = $notification->getNotificationInfo();
     $idsite = $info['idSite'];
     $site = Piwik_Common::getCacheWebsiteAttributes($idsite);
     $site['idsite'] = $idsite;
     // search results passed via JS tracker
     $data = Piwik_Common::getRequestVar('data', '');
     $data = Piwik_Common::unsanitizeInputValue($data);
     $data = json_decode($data, true);
     $resultCount = false;
     if (isset($data['SiteSearch_Results'])) {
         $resultCount = intval($data['SiteSearch_Results']);
     }
     if (!empty($site['sitesearch_url']) && !empty($site['sitesearch_parameter'])) {
         // check whether action is a site search
         $url = preg_quote($site['sitesearch_url'], '/');
         $param = preg_quote($site['sitesearch_parameter'], '/');
         $regex = '/' . $url . '(.*)(&|\\?)' . $param . '=(.*?)(&|$)/i';
         $actionUrl = $action->getActionUrl();
         if (preg_match($regex, $actionUrl, $matches)) {
             require_once PIWIK_INCLUDE_PATH . '/plugins/SiteSearch/Archive.php';
             require_once PIWIK_INCLUDE_PATH . '/plugins/SiteSearch/Db.php';
             Piwik_SiteSearch_Archive::logAction(array('idaction' => $idaction, 'name' => $actionUrl), $site['idsite'], $site, $resultCount);
         }
     }
 }
Exemplo n.º 2
0
    /** Analyze site for serach URLs */
    private function analyzeSite($idSite)
    {
        // remove all searchterms from actions
        Piwik_Query('
			UPDATE ' . Piwik_Common::prefixTable('log_action') . ' AS action
			SET search_term = NULL
			WHERE search_term IS NOT NULL AND EXISTS (
				SELECT
					search.idsite
				FROM
					' . Piwik_Common::prefixTable('log_sitesearch') . ' AS search
				WHERE
					search.idsite = ' . intval($idSite) . ' AND
					search.id = action.search_term
			)
		');
        // rescan
        $site = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite);
        if (empty($site['sitesearch_url']) || empty($site['sitesearch_parameter'])) {
            return;
        }
        // this is only a rough filter, Piwik_SiteSearch_Archive::logAction
        // will do a more precise check
        $url = '%' . $site['sitesearch_url'] . '%' . $site['sitesearch_parameter'] . '=%';
        $sql = '
			SELECT
				action.idaction,
				action.name
			FROM
				' . Piwik_Common::prefixTable('log_action') . ' AS action
			LEFT JOIN
				' . Piwik_Common::prefixTable('log_link_visit_action') . ' AS link
				ON action.idaction = link.idaction_url
			LEFT JOIN
				' . Piwik_Common::prefixTable('log_visit') . ' AS visit
				ON link.idvisit = visit.idvisit
			WHERE
				action.type = 1 AND
				action.name LIKE :name AND
				visit.idsite = :idSite
			GROUP BY
				action.idaction
		';
        $bind = array(':name' => $url, ':idSite' => intval($idSite));
        $result = Piwik_SiteSearch_Db::fetchAll($sql, $bind);
        foreach ($result as $action) {
            Piwik_SiteSearch_Archive::logAction($action, $idSite, $site);
        }
        // remove unneccessary sitesearch entries
        $sql = '
			DELETE FROM ' . Piwik_Common::prefixTable('log_sitesearch') . '
			WHERE idsite = ' . intval($idSite) . ' AND NOT EXISTS (
				SELECT action.idaction
				FROM ' . Piwik_Common::prefixTable('log_action') . ' AS action
				WHERE action.search_term = id
			)
		';
        Piwik_Query($sql);
        $this->clearArchive($idSite);
    }