Пример #1
0
 /**
  * Explodes action name into an array of elements.
  *
  * NOTE: before calling this function make sure Piwik_Actions_ArchivingHelper::reloadConfig(); is called
  *
  * for downloads:
  *  we explode link http://piwik.org/some/path/piwik.zip into an array( 'piwik.org', '/some/path/piwik.zip' );
  *
  * for outlinks:
  *  we explode link http://dev.piwik.org/some/path into an array( 'dev.piwik.org', '/some/path' );
  *
  * for action urls:
  *  we explode link http://piwik.org/some/path into an array( 'some', 'path' );
  *
  * for action names:
  *   we explode name 'Piwik / Category 1 / Category 2' into an array('Piwik', 'Category 1', 'Category 2');
  *
  * @param string action name
  * @param int action type
  * @param int url prefix (only used for TYPE_ACTION_URL)
  * @return array of exploded elements from $name
  */
 public static function getActionExplodedNames($name, $type, $urlPrefix = null)
 {
     // Site Search does not split Search keywords
     if ($type == Piwik_Tracker_Action::TYPE_SITE_SEARCH) {
         return array($name);
     }
     $matches = array();
     $isUrl = false;
     $name = str_replace("\n", "", $name);
     $urlRegexAfterDomain = '([^/]+)[/]?([^#]*)[#]?(.*)';
     if ($urlPrefix === null) {
         // match url with protocol (used for outlinks / downloads)
         $urlRegex = '@^http[s]?://' . $urlRegexAfterDomain . '$@i';
     } else {
         // the name is a url that does not contain protocol and www anymore
         // we know that normalization has been done on db level because $urlPrefix is set
         $urlRegex = '@^' . $urlRegexAfterDomain . '$@i';
     }
     preg_match($urlRegex, $name, $matches);
     if (count($matches)) {
         $isUrl = true;
         $urlHost = $matches[1];
         $urlPath = $matches[2];
         $urlFragment = $matches[3];
     }
     if ($type == Piwik_Tracker_Action::TYPE_DOWNLOAD || $type == Piwik_Tracker_Action::TYPE_OUTLINK) {
         if ($isUrl) {
             return array(trim($urlHost), '/' . trim($urlPath));
         }
     }
     if ($isUrl) {
         $name = $urlPath;
         if ($name === '' || substr($name, -1) == '/') {
             $name .= self::$defaultActionName;
         }
     }
     if ($type == Piwik_Tracker_Action::TYPE_ACTION_NAME) {
         $categoryDelimiter = self::$actionTitleCategoryDelimiter;
     } else {
         $categoryDelimiter = self::$actionUrlCategoryDelimiter;
     }
     if ($isUrl) {
         $urlFragment = Piwik_Tracker_Action::processUrlFragment($urlFragment);
         if (!empty($urlFragment)) {
             $name .= '#' . $urlFragment;
         }
     }
     if (empty($categoryDelimiter)) {
         return array(trim($name));
     }
     $split = explode($categoryDelimiter, $name, self::getSubCategoryLevelLimit());
     // trim every category and remove empty categories
     $split = array_map('trim', $split);
     $split = array_filter($split, 'strlen');
     // forces array key to start at 0
     $split = array_values($split);
     if (empty($split)) {
         $defaultName = self::getUnknownActionName($type);
         return array(trim($defaultName));
     }
     $lastPageName = end($split);
     // we are careful to prefix the page URL / name with some value
     // so that if a page has the same name as a category
     // we don't merge both entries
     if ($type != Piwik_Tracker_Action::TYPE_ACTION_NAME) {
         $lastPageName = '/' . $lastPageName;
     } else {
         $lastPageName = ' ' . $lastPageName;
     }
     $split[count($split) - 1] = $lastPageName;
     return array_values($split);
 }