/** * Generate a slug for the given string using specified settings. * * @param string $string String. * @param array $settings Settings to use (looks for 'separator' and 'length') * * @return string Slug for given string. */ private function _getSlug($string, $settings) { return AppHelper::slug($string, $settings['separator']); }
/** * Generate a slug for the given string using specified settings. * * @param string $string String. * @param array $settings Settings to use (looks for 'separator' and 'length') * * @return string Slug for given string. */ private function _getSlug($string, $settings) { /* might pertain to cakephp 1.2.4 if (!class_exists('AppHelper')) { App::import('Core', 'AppHelper', false); } */ require_once APP . 'app_helper.php'; return AppHelper::slug($string, $settings['separator']); }
/** * Create navigation * Generate an unordered list of links. Adds "current" CSS class to current item. * * @param array $items * @param array $settings Options array * @return string List HTML */ function create($items = array(), $settings = array(), $toOutput = false) { $settings = am($this->_defaultOptions, $settings); // Begin list $ulAttr = ''; if (!empty($settings['id'])) { $ulAttr .= " id=\"{$settings['id']}\""; } if (!empty($settings['class'])) { $ulAttr .= " class=\"{$settings['class']}\""; } $html = str_replace('%attr%', $ulAttr, $settings['before']); // List nodes foreach ($items as $name => $url) { $isCurrent = false; if (is_int($name)) { $name = $url; $url = '/' . low($url); $url = $this->Html->url($url); } else { if (is_string($url)) { $url = $this->Html->url($url); if ($this->params['action'] === 'index') { } $isCurrent = $this->here === $url; } else { if (is_array($url)) { $keys = array('controller', 'action'); if (isset($url['controller']) && (!isset($url['action']) || $url['action'] === 'index')) { // We can decide by comparing controllers $isCurrent = $url['controller'] === $this->params['controller']; } else { if (isset($url['controller']) and isset($url['action'])) { $isCurrent = $url['controller'] === $this->params['controller'] && $url['action'] === $this->params['action']; } } // This is basically a hack to get a nice url in form of wf/controller-name/ instead of wf/controller-name/index if (!isset($url['action']) || $url['action'] === 'wf_index') { $url = '/' . Configure::read('Wildflower.prefix') . '/' . str_replace('', '', $url['controller']); } $url = $this->Html->url($url); } } } $liAttr = ''; $slug = AppHelper::slug(low($name)); $cssClasses = array(); if (!empty($settings['id'])) { $cssClasses[] = "{$settings['id']}-{$slug}"; } else { if (!empty($settings['class'])) { $firstClass = array_shift(explode(' ', $settings['class'])); $cssClasses[] = "{$firstClass}-{$slug}"; } } $itemTemplate = $settings['itemTemplate']; if ($isCurrent) { $cssClasses[] = $settings['activeCssClass']; $itemTemplate = $settings['activeItemTemplate']; } $cssClasses = implode(' ', $cssClasses); $liAttr = " class=\"{$cssClasses}\""; // Translation $name = __($name, true); $html .= str_replace(array('%attr%', '%url%', '%name%'), array($liAttr, $url, $name), $itemTemplate); $html .= "\n"; } $html .= $settings['after']; $html .= "\n"; if ($toOutput) { $this->_toOutput .= $toOutput; return null; } return $html; }
function admin_update() { //fb($this->data); $this->data[$this->modelClass]['user_id'] = $this->getLoggedInUserId(); // Publish? if (isset($this->data['__save']['publish'])) { $this->data[$this->modelClass]['draft'] = 0; } unset($this->data['__save']); if (isset($this->data[$this->modelClass]['slug'])) { $this->data[$this->modelClass]['slug'] = AppHelper::slug($this->data[$this->modelClass]['slug']); } $this->Post->create($this->data); if (!$this->Post->exists()) { return $this->cakeError('object_not_found'); } if (isset($this->data[$this->modelClass]['categories_can_be_empty']) && !isset($this->data['Category'])) { // Delete all post categories $this->Post->query("DELETE FROM categories_posts WHERE post_id = {$this->Post->id}"); } if (!$this->Post->save()) { return $this->cakeError('save_error'); } // @TODO Rendering the exact save errors would be better // $cacheName = str_replace('-', '_', $this->data[$this->modelClass]['slug']); // @TODO check cache for proper naming method // clearCache($cacheName, 'views', '.php'); if ($this->RequestHandler->isAjax()) { $this->Post->contain('User'); $this->data = $post = $this->Post->findById($this->Post->id); // @TODO clean up $this->set(compact('post')); return $this->render('admin_update'); } $this->redirect(array('action' => 'edit', $this->Post->id)); }
/** * Create a new event * * Returns the updated category list as JSON. */ function wf_update() { if (!empty($this->data)) { // Publish? if (isset($this->data['__save']['publish'])) { $this->data[$this->modelClass]['draft'] = 0; } unset($this->data['__save']); if (isset($this->data[$this->modelClass]['location'])) { $this->data[$this->modelClass]['location'] = serialize($this->data[$this->modelClass]['location']); } if (isset($this->data[$this->modelClass]['slug'])) { $this->data[$this->modelClass]['slug'] = AppHelper::slug($this->data[$this->modelClass]['slug']); } $this->{$this->modelClass}->create($this->data); if ($this->{$this->modelClass}->save()) { $message = __('Event has been saved.', true); $msgClass = 'message'; } else { $message = __('An error occured while saving your event.', true); $msgClass = 'error'; } $this->Session->setFlash($message, 'default', array('class' => $msgClass)); $this->redirect(array('action' => 'edit', $this->{$this->modelClass}->id)); } }