privatePage = false; $content['robots']= array('index','follow','noarchive'); } else { $this->privatePage = true; $content['robots']= array('noindex','nofollow','noarchive'); } $return = ''; return $return; } /** * convinience function for clean meta name tags * @param STRING $name: author, date, generator, revisit-after, language * @param MIXED $content: if array, it will be seperated by commas * @return string $htmlMarkup * 2009-07-07 ms */ public function metaName($name = null, $content = null) { if (empty($name) || empty($content)) { return ''; } if (!is_array($content)) { $content = (array)$content; } $return = ''; return $return; } /** * @param string $content * @param string $language (iso2: de, en-us, ...) * @param array $additionalOptions * @return string $htmlMarkup */ public function metaDescription($content, $language = null, $options = array()) { if (!empty($language)) { $options['lang'] = mb_strtolower($language); } elseif ($language !== false) { $options['lang'] = Configure::read('Config.locale'); // DEFAULT_LANGUAGE } return $this->Html->meta('description', $content, $options); } /** * @param string|array $keywords * @param string $language (iso2: de, en-us, ...) * @param bool $escape * @return string $htmlMarkup */ public function metaKeywords($keywords = null, $language = null, $escape = true) { if ($keywords === null) { $keywords = Configure::read('Config.keywords'); } if (is_array($keywords)) { $keywords = implode(', ', $keywords); } if ($escape) { $keywords = h($keywords); } if (!empty($language)) { $options['lang'] = mb_strtolower($language); } elseif ($language !== false) { $options['lang'] = Configure::read('Config.locale'); // DEFAULT_LANGUAGE } return $this->Html->meta('keywords', $keywords, $options); } /** * convinience function for "canonical" SEO links * * @return string $htmlMarkup * 2010-03-03 ms */ public function metaCanonical($url = null, $full = false) { $canonical = $this->Html->url($url, $full); //return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null)); return ''; } /** * convinience function for "alternate" SEO links * @param mixed $url * @param mixed $lang (lang(iso2) or array of langs) * lang: language (in ISO 6391-1 format) + optionally the region (in ISO 3166-1 Alpha 2 format) * - de * - de-ch * etc * @return string $htmlMarkup * 2011-12-12 ms */ public function metaAlternate($url, $lang, $full = false) { $canonical = $this->Html->url($url, $full); //return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null)); $lang = (array)$lang; $res = array(); foreach ($lang as $language => $countries) { if (is_numeric($language)) { $language = ''; } else { $language .= '-'; } $countries = (array)$countries; foreach ($countries as $country) { $l = $language . $country; $options = array('rel' => 'alternate', 'hreflang' => $l, 'type' => null, 'title' => null); $res[] = $this->Html->meta('alternate', $url, $options).PHP_EOL; } } return implode('', $res); } /** * convinience function for META Tags * @param STRING type * @param STRING content * @return string $htmlMarkup * 2008-12-08 ms */ public function metaRss($url = null, $title = null) { $tags = array( 'meta' => '', ); $content = array(); if (empty($url)) { return ''; } if (empty($title)) { $title = 'Diesen Feed abonnieren'; } return sprintf($tags['meta'], $title, $this->url($url)); } /** * convinience function for META Tags * @param STRING type * @param STRING content * @return string $htmlMarkup * 2008-12-08 ms */ public function metaEquiv($type = null, $value = null, $escape = true) { $tags = array( 'meta' => '', ); if (empty($value)) { return ''; } if ($escape) { $value = h($value); } if ($type == 'language') { return sprintf($tags['meta'], 'language', ' content="'.$value.'"'); } elseif ($type == 'pragma') { return sprintf($tags['meta'], 'pragma', ' content="'.$value.'"'); } elseif ($type == 'expires') { return sprintf($tags['meta'], 'expires', ' content="'.$value.'"'); } elseif ($type == 'cache-control') { return sprintf($tags['meta'], 'cache-control', ' content="'.$value.'"'); } elseif ($type == 'refresh') { return sprintf($tags['meta'], 'refresh', ' content="'.$value.'"'); } return ''; } /** * (example): array(x, Tools|y, Tools.Jquery|jquery/sub/z) * => x is in webroot/ * => y is in plugins/tools/webroot/ * => z is in plugins/tools/packages/jquery/files/jquery/sub/ * @return string $htmlMarkup * 2011-03-23 ms */ public function css($files = array(), $rel = null, $options = array()) { $files = (array)$files; $pieces = array(); foreach ($files as $file) { $pieces[] = 'file='.$file; } if ($v = Configure::read('Config.layout_v')) { $pieces[] = 'v='.$v; } $string = implode('&', $pieces); return $this->Html->css('/css.php?'.$string, $rel, $options); } /** * (example): array(x, Tools|y, Tools.Jquery|jquery/sub/z) * => x is in webroot/ * => y is in plugins/tools/webroot/ * => z is in plugins/tools/packages/jquery/files/jquery/sub/ * @return string $htmlMarkup * 2011-03-23 ms */ public function script($files = array(), $options = array()) { $files = (array)$files; foreach ($files as $file) { $pieces[] = 'file='.$file; } if ($v = Configure::read('Config.layout_v')) { $pieces[] = 'v='.$v; } $string = implode('&', $pieces); return $this->Html->script('/js.php?'.$string, $options); } /** * special css tag generator with the option to add '?...' to the link (for caching prevention) * IN USAGE * needs manual adjustment, but still better than the core one! * @example needs Asset.cssversion => xyz (going up with counter) * @return string $htmlMarkup * 2008-12-08 ms */ public function cssDyn($path, $rel = null, $htmlAttributes = array(), $return = true) { $v = (int)Configure::read('Asset.version'); return $this->Html->css($path.'.css?'.$v, $rel, $htmlAttributes, $return); } /** * NOT IN USAGE * but better than the core one! * @example needs Asset.timestamp => force * @return string $htmlMarkup * 2008-12-08 ms */ public function cssAuto($path, $rel = null, $htmlAttributes = array(), $return = true) { define('COMPRESS_CSS',true); $time = date('YmdHis', filemtime(APP . 'webroot' . DS . CSS_URL . $path . '.css')); $url = "{$this->request->webroot}" . (COMPRESS_CSS ? 'c' : '') . CSS_URL . $this->themeWeb . $path . ".css?" . $time; return $url; } /*** Content Stuff ***/ /** * still necessary? * @param array $fields * @return string $html */ public function displayErrors($fields = array()) { $res = ''; if (!empty($this->validationErrors)) { if ($fields === null) { # catch ALL foreach ($this->validationErrors as $alias => $error) { list($alias, $fieldname) = explode('.', $error); $this->validationErrors[$alias][$fieldname]; } } elseif (!empty($fields)) { foreach ($fields as $field) { list($alias, $fieldname) = explode('.', $field); if (!empty($this->validationErrors[$alias][$fieldname])) { $res .= $this->_renderError($this->validationErrors[$alias][$fieldname]); } } } /* if (!empty($catched)) { foreach ($catched as $c) { } } */ } return $res; } protected function _renderError($error, $escape = true) { if ($escape !== false) { $error = h($error); } return '
'; } /** * Alternates between two or more strings. * * echo CommonHelper::alternate('one', 'two'); // "one" * echo CommonHelper::alternate('one', 'two'); // "two" * echo CommonHelper::alternate('one', 'two'); // "one" * * Note that using multiple iterations of different strings may produce * unexpected results. * TODO: move to booststrap!!! * * @param string strings to alternate between * @return string */ public static function alternate() { static $i; if (func_num_args() === 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } /** * check if session works due to allowed cookies * * 2009-06-29 ms */ public function sessionCheck() { return !CommonComponent::cookiesDisabled(); /* if (!empty($_COOKIE) && !empty($_COOKIE[Configure::read('Session.cookie')])) { return true; } return false; */ } /** * display warning if cookies are disallowed (and session won't work) * 2009-06-29 ms */ public function sessionCheckAlert() { if (!$this->sessionCheck()) { return ''; } return ''; } /** * //TODO: move boostrap * auto-pluralizing a word using the Inflection class * @param string $s = the string to be pl. * @param int $c = the count * @return $string "member" or "members" OR "Mitglied"/"Mitglieder" if autoTranslate TRUE * 2009-07-23 ms */ public function asp($s, $c, $autoTranslate = false) { if ((int)$c !== 1) { $p = Inflector::pluralize($s); } else { $p = null; # no pluralization necessary } return $this->sp($s, $p, $c, $autoTranslate); } /** * //TODO: move boostrap * manual pluralizing a word using the Inflection class * * @param string $singular * @param string $plural * @param int $count * @return string $result * 2009-07-23 ms */ public function sp($s, $p, $c, $autoTranslate = false) { if ((int)$c !== 1) { $ret = $p; } else { $ret = $s; } if ($autoTranslate) { $ret = __($ret); } return $ret; } /** * Show FlashMessages * @param boolean unsorted true/false [default:FALSE = sorted by priority] * TODO: export div wrapping method (for static messaging on a page) * TODO: sorting * 2010-11-22 ms */ public function flash($unsorted = false, $backwardsComp = true) { // Get the messages from the session $messages = (array)$this->Session->read('messages'); $cMessages = (array)Configure::read('messages'); if (!empty($cMessages)) { $messages = (array)Set::merge($messages, $cMessages); } $html=''; if (!empty($messages)) { $html = '\n"; $output .= h($debug['debug']); $output .= "\n\n