/** * This happens after a find happens. * * @param object $Model Model about to be saved. * @return boolean true if save should proceed, false otherwise * @access public */ public function afterFind($Model, $data) { // skip finds with more than one result. $skip = $Model->findQueryType == 'neighbors' || $Model->findQueryType == 'count' || empty($data) || isset($data[0][0]['count']) || isset($data[0]) && count($data) > 1 || !isset($data[0][$Model->alias][$Model->primaryKey]); if ($skip) { return $data; } if (isset($this->__settings[$Model->alias]['session_tracking']) && $this->__settings[$Model->alias]['session_tracking']) { $this->__session[$Model->alias] = CakeSession::read('Viewable.' . $Model->alias); } $user_id = AuthComponent::user('id'); $view['ViewCount'] = array('user_id' => $user_id > 0 ? $user_id : 0, 'model' => Inflector::camelize($Model->plugin) . '.' . $Model->name, 'foreign_key' => $data[0][$Model->alias][$Model->primaryKey], 'referer' => str_replace(InfinitasRouter::url('/'), '/', $Model->__referer)); $location = EventCore::trigger($this, 'GeoLocation.getLocation'); $location = current($location['getLocation']); foreach ($location as $k => $v) { $view['ViewCount'][$k] = $v; } $view['ViewCount']['year'] = date('Y'); $view['ViewCount']['month'] = date('m'); $view['ViewCount']['day'] = date('j'); $view['ViewCount']['day_of_year'] = date('z'); $view['ViewCount']['week_of_year'] = date('W'); $view['ViewCount']['hour'] = date('G'); // no leading 0 $view['ViewCount']['city'] = $view['ViewCount']['city'] ? $view['ViewCount']['city'] : 'Unknown'; /** * http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_dayofweek * sunday is 1, php uses 0 */ $view['ViewCount']['day_of_week'] = date('w') + 1; $Model->ViewCount->unBindModel(array('belongsTo' => array('GlobalCategory'))); $Model->ViewCount->create(); $Model->ViewCount->save($view); return $data; }
/** * create the items in the list. * * @param array $array part of the tree * @param string $model the alias of the model being used * * @return part of the formated tree. */ private function __buildDropdownMenu($array = array(), $model = '') { if (empty($array['MenuItem']) || ($model = '')) { $this->errors[] = 'nothing passed to generate'; return false; } $currentCss = $suffix = ''; if ($this->_menuLevel == 0) { $suffix = '0'; } $isSeperator = $array['MenuItem']['name'] == '--' ? true : false; if ($isSeperator) { $array['MenuItem']['item'] = ''; } $linkName = __($array['MenuItem']['name']); if (!empty($array['children'])) { $linkName = '<span>' . $linkName . '</span>'; } $class = 'pureCssMenui' . $suffix; if ($isSeperator) { $class .= ' seperator'; } $this->_menuData .= '<li class="' . $class . '">'; if (!$isSeperator) { $menuLink = $this->url($array); if ($menuLink == $this->here || is_array($menuLink) && ($menuLink['controller'] == $this->request->params['controller'] || $menuLink['plugin'] == $this->request->params['plugin'])) { $currentCss = ' current'; $this->_currentCssDone = true; } if (!empty($currentCss) && $this->_currentCssDone === false && Router::url($menuLink) == $this->here) { $currentCss = ' current'; $this->_currentCssDone = true; } $this->_menuData .= $this->Html->link($linkName, InfinitasRouter::url($menuLink), array('class' => 'pureCssMenui' . $suffix . $currentCss, 'escape' => false)); if (!empty($array['children'])) { $this->_menuData .= '<ul class="pureCssMenum">'; foreach ($array['children'] as $k => $v) { $this->_menuLevel = 1; $this->__buildDropdownMenu($v, $model); } $this->_menuData .= '</ul>'; } $this->_menuData .= '</a>'; } else { $this->_menuData .= $linkName; } $this->_menuData .= '</li>'; }
/** * @brief save a maker for a later redirect * * @access public * * This will set a session var for the current page * * @return void */ public function saveRedirectMarker() { $var = $this->lastPageRedirectVar(); $lastPage = $this->Session->read($var); if (!$lastPage && InfinitasRouter::url($lastPage) != $this->referer()) { $this->Session->write($var, $this->referer()); } }