public static function title($title, $with = 'default', $when = 'save') { switch ($with) { case 'dash': $title = strip_tags($title); if (HuradFunctions::isUtf8($title)) { if (function_exists('mb_strtolower')) { $title = mb_strtolower($title, 'utf8'); } $title = HuradFunctions::utf8UriEncode($title, 200); } $title = strtolower($title); //Kill entity $title = preg_replace('/&.+?;/', ' ', $title); $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); //Replace whitespace with dash $title = preg_replace('/\\s+/', '-', $title); //Replace multi dash with one dash $title = preg_replace('/-+/', '-', $title); //Remove dash from start and end of string $title = trim($title, '-'); return HuradHook::apply_filters('sanitize_title_with_dash', $title); break; case 'default': default: if ($when == "save") { $safeTitle = filter_var($title, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); } else { $safeTitle = $title; } return HuradHook::apply_filters('sanitize_title', $safeTitle, $title, $when); break; } }
public function radio($fieldName, array $data, array $options, array $attributes = []) { $defaultAttributes = ['id' => 'Widget' . ucfirst($fieldName) . '-id', 'name' => $fieldName, 'label' => false]; if (count($data) > 0) { $attributes['value'] = $data[$fieldName]; } $attr = HuradFunctions::arraySliceAssoc($attributes, ['show-type', 'btn-class']); unset($attributes['show-type']); unset($attributes['btn-class']); $attributes = Hash::merge($defaultAttributes, $attributes); if ($attr['show-type'] == 'btn-group') { if (!isset($attr['btn-class'])) { $attr['btn-class'] = 'btn-default'; } $opt[] = '<div class="btn-group" data-toggle="buttons">'; foreach ($options as $value => $label) { if (isset($attributes['value']) && $value == $attributes['value']) { $active = ' active'; } else { $active = ''; } $opt[] = '<label class="btn ' . $attr['btn-class'] . $active . '">'; $opt[] = $this->Form->radio($fieldName, [$value => $label], $attributes); $opt[] = '</label>'; } $opt[] = '</div>'; } else { foreach ($options as $value => $label) { $opt[] = '<div class="radio">'; $opt[] = '<label>'; $opt[] = $this->Form->radio($fieldName, [$value => $label], $attributes); $opt[] = '</label>'; $opt[] = '</div>'; } } return implode('', $opt); }
/** * List all the authors of the blog, with several options available. * * @since 0.1.0 * * @param array $args The argument array. * * @return null|string The output, if echo is set to false. */ public function getListAuthors($args = array()) { $defaults = ['order_by' => 'username', 'order' => 'ASC', 'limit' => '', 'count' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => false, 'style' => 'list', 'html' => true]; $args = Hash::merge($defaults, $args); $return = ''; $queryArgs = HuradFunctions::arraySliceAssoc($args, ['order_by', 'order', 'limit']); $authors = ClassRegistry::init('User')->getUsers($queryArgs); foreach ($authors as $author) { $author = ClassRegistry::init('User')->getUser($author['User']['id']); if ($args['exclude_admin'] && 'administrator' == $author['User']['role']) { continue; } $posts = ClassRegistry::init('Post')->countUserPosts($author['User']['id']); if (!$posts && $args['hide_empty']) { continue; } if ($args['show_fullname'] && isset($author['UserMeta']['first_name']) && isset($author['UserMeta']['last_name'])) { $name = "{$author['UserMeta']['first_name']} {$author['UserMeta']['last_name']}"; } else { $name = $author['UserMeta']['display_name']; } if (!$args['html']) { $return .= $name . ', '; continue; } if ('list' == $args['style']) { $return .= '<li>'; } $link = $this->Html->link($name, $this->getAuthorPostsUrl($author['User']['id']), ['title' => __("Posts by %s", $author['UserMeta']['display_name'])]); if ($args['count']) { $link .= ' (' . $posts . ')'; } $return .= $link; $return .= 'list' == $args['style'] ? '</li>' : ', '; } $return = rtrim($return, ', '); return $return; }
/** * Display the language string for the number of comments the current post has. * * @uses applyFilters() Calls the 'comments_number' hook on the output and number of comments respectively. * * @param bool|string $zero Text for no comments * @param bool|string $one Text for one comment * @param bool|string $more Text for more than one comment * @param int $contentId Post or Page id * * @return mixed */ public function getCommentsNumber($zero = false, $one = false, $more = false, $contentId = null) { $number = $this->getCommentCount($contentId); if ($number > 1) { $output = str_replace('%', HuradFunctions::numberFormatI18n($number), false === $more ? __d('hurad', '% Comments') : $more); } elseif ($number == 0) { $output = false === $zero ? __d('hurad', 'No Comments') : $zero; } else { $output = false === $one ? __d('hurad', '1 Comment') : $one; } return $this->Hook->applyFilters('Helper.Comment.getCommentsNumber', $output, $number); }
public function listPages($args = '') { $defaults = array('direction' => 'asc', 'sort' => 'title', 'echo' => 1, 'link_before' => '', 'link_after' => ''); $mixedArgs = HuradFunctions::parseArgs($args, $defaults); $pages = $this->requestAction('/pages/pageIndex/sort:' . $mixedArgs['sort'] . '/direction:' . $mixedArgs['direction']); if (count($pages) > 0) { $output = $this->pageTreeRender($pages); } else { $output = __d('hurad', 'No pages were found'); } return $this->Hook->applyFilters('Helper.Page.listPages', $output, $pages, $mixedArgs); }