本文整理汇总了PHP中Utils::slugify方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::slugify方法的具体用法?PHP Utils::slugify怎么用?PHP Utils::slugify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils
的用法示例。
在下文中一共展示了Utils::slugify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: module_setup
public function module_setup()
{
$this->slug = Utils::slugify($this->text);
$this->tag = new Tag(array('term_display' => $this->text, 'term' => $this->slug));
$this->tag_empty_term_display = new Tag(array('term_display' => '', 'term' => 'no-display'));
$this->tag_empty_term = new Tag(array('term_display' => 'Empty Term', 'term' => ''));
}
示例2: get
public function get(Theme $theme)
{
$primary = true;
$controls = array();
/** @var FormControlSubmit $control */
foreach ($this->controls as $index => $control) {
if ($control->is_enabled()) {
$control->add_class('dropbutton_action');
$control->add_class(Utils::slugify($control->input_name()));
if ($primary) {
$control->add_class('primary');
$primary = false;
}
$controls[$index] = $control;
}
}
if (count($controls) == 0) {
return '';
}
$this->vars['first'] = array_shift($controls);
$this->vars['actions'] = $controls;
$this->set_template_properties('div', array('id' => $this->get_visualizer()));
$this->add_template_class('ul', 'dropdown-menu');
if (count($controls) > 0) {
// Remember, these are in the dropmenu, doesn't include the first
$this->add_template_class('div', 'has-drop');
} else {
$this->add_template_class('div', 'no-drop');
}
return parent::get($theme);
}
示例3: setslug
/**
* Generate a new slug for the post.
*
* @return string The slug
*/
protected function setslug()
{
$value = '';
// determine the base value from:
// - the new slug
if (isset($this->newfields['term']) && $this->newfields['term'] != '') {
$value = $this->newfields['term'];
} elseif ($this->fields['term'] != '') {
$value = $this->fields['term'];
} elseif (isset($this->newfields['term_display']) && $this->newfields['term_display'] != '') {
$value = $this->newfields['term_display'];
} elseif ($this->fields['term_display'] != '') {
$value = $this->fields['term_display'];
}
// make sure our slug is unique
$slug = Plugins::filter('term_setslug', $value);
$slug = Utils::slugify($slug);
$postfix = '';
$postfixcount = 0;
do {
if (!($slugcount = DB::get_row('SELECT COUNT(term) AS ct FROM {terms} WHERE term = ? AND vocabulary_id = ?;', array($slug . $postfix, $this->fields['vocabulary_id'])))) {
Utils::debug(DB::get_errors());
exit;
}
if ($slugcount->ct != 0) {
$postfix = "-" . ++$postfixcount;
}
} while ($slugcount->ct != 0);
return $this->newfields['term'] = $slug . $postfix;
}
示例4: fetch_dashboard_modules
/**
* Fetches active modules for display on the dashboard
*/
public function fetch_dashboard_modules()
{
if ( count( Modules::get_all() ) == 0 ) {
$this->theme->modules = array();
return;
}
// get the active module list
$modules = Modules::get_active();
if ( User::identify()->can( 'manage_dash_modules' ) ) {
// append the 'Add Item' module
$modules['nosort'] = 'Add Item';
// register the 'Add Item' filter
Plugins::register( array( $this, 'filter_dash_module_add_item' ), 'filter', 'dash_module_add_item' );
}
foreach ( $modules as $id => $module_name ) {
$slug = Utils::slugify( (string) $module_name, '_' );
$module = array(
'name' => $module_name,
'title' => $module_name,
'content' => '',
'options' => ''
);
$module = Plugins::filter( 'dash_module_' .$slug, $module, $id, $this->theme );
$modules[$id] = $module;
}
$this->theme->modules = $modules;
}
示例5: test_create_post
public function test_create_post()
{
$tags = array('one', 'two', 'THREE');
$params = array(
'title' => 'A post title',
'content' => 'Some great content. Really.',
'user_id' => $this->user->id,
'status' => Post::status('published'),
'content_type' => Post::type('entry'),
'tags' => 'one, two, THREE',
'pubdate' => HabariDateTime::date_create( time() ),
);
$post = Post::create($params);
$this->assert_true( $post instanceof Post, 'Post should be created.' );
// Check the post's id is set.
$this->assert_true( (int)$post->id > 0, 'The Post id should be greater than zero' );
// Check the post's tags are usable.
$this->assert_equal(count($post->tags), count($tags), 'All tags should have been created.');
foreach ( $post->tags as $tag ) {
$this->assert_equal($tag->tag_slug, Utils::slugify($tag->tag_text), 'Tags key should be slugified tag.');
}
foreach( $post->tags as $tag ) {
Tags::vocabulary()->delete_term( $tag );
}
}
示例6: filter_user_permalink
/**
* Generate the permalink for this user. create a slug if none exists.
*/
public function filter_user_permalink($out, $user)
{
if (!$user->info->slug) {
$slug = Utils::slugify($user->displayname);
$user->info->slug = $slug;
$user->info->commit();
}
return URL::get('display_entries_by_author', array('author' => $user->info->slug));
}
示例7: get
public function get(Theme $theme)
{
$silos = Media::dir();
foreach ($silos as &$silo) {
$silo->path_slug = Utils::slugify($silo->path);
}
$this->vars['silos'] = $silos;
return parent::get($theme);
}
示例8: post_options
/**
* Handles POST requests from the options admin page
*/
public function post_options()
{
$option_items = array();
$timezones = DateTimeZone::listIdentifiers();
$timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones)));
$option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => ''));
$option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Info'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.')));
$option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(HabariDateTime::date_create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(HabariDateTime::date_create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(HabariDateTime::date_create()->time))));
$option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(HabariLocale::list_all(), HabariLocale::list_all())), 'helptext' => _t('International language code')), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server')));
$option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!')));
/*$option_items[_t('Presentation')] = array(
'encoding' => array(
'label' => _t('Encoding'),
'type' => 'select',
'selectarray' => array(
'UTF-8' => 'UTF-8'
),
'helptext' => '',
),
);*/
$option_items = Plugins::filter('admin_option_items', $option_items);
$form = new FormUI('Admin Options');
$tab_index = 3;
foreach ($option_items as $name => $option_fields) {
$fieldset = $form->append('wrapper', Utils::slugify(_u($name)), $name);
$fieldset->class = 'container settings';
$fieldset->append('static', $name, '<h2>' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>');
foreach ($option_fields as $option_name => $option) {
$field = $fieldset->append($option['type'], $option_name, $option_name, $option['label']);
$field->template = 'optionscontrol_' . $option['type'];
$field->class = 'item clear';
if ($option['type'] == 'select' && isset($option['selectarray'])) {
$field->options = $option['selectarray'];
}
$field->tabindex = $tab_index;
$tab_index++;
if (isset($option['helptext'])) {
$field->helptext = $option['helptext'];
} else {
$field->helptext = '';
}
}
}
/* @todo: filter for additional options from plugins
* We could either use existing config forms and simply extract
* the form controls, or we could create something different
*/
$submit = $form->append('submit', 'apply', _t('Apply'), 'admincontrol_submit');
$submit->tabindex = $tab_index;
$form->on_success(array($this, 'form_options_success'));
$this->theme->form = $form->get();
$this->theme->option_names = array_keys($option_items);
$this->theme->display('options');
}
示例9: get
public function get(Theme $theme)
{
$checkboxes = $this->options;
$control = $this;
if (!is_array($control->value)) {
$control->value = array();
}
array_walk($checkboxes, function (&$item, $key) use($control) {
$item = array('label' => Utils::htmlspecialchars($item), 'id' => Utils::slugify($control->get_id() . '-' . $key), 'checked' => in_array($key, $control->value) ? 'checked="checked"' : '');
});
$this->vars['checkboxes'] = $checkboxes;
$this->settings['ignore_name'] = true;
return parent::get($theme);
}
示例10: __construct
public function __construct()
{
parent::__construct();
// Let's register the options page form so we can use it with ajax
$self = $this;
FormUI::register('admin_options', function ($form, $name, $extra_data) use($self) {
$option_items = array();
$timezones = \DateTimeZone::listIdentifiers();
$timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones)));
$option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => ''));
$option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Email'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.')));
$option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(DateTime::create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(DateTime::create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(DateTime::create()->time))));
$option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(Locale::list_all(), Locale::list_all())), 'helptext' => Config::exists('locale') ? _t('International language code : This value is set in your config.php file, and cannot be changed here.') : _t('International language code'), 'disabled' => Config::exists('locale'), 'value' => Config::get('locale', Options::get('locale', 'en-us'))), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server')));
$option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!')));
$option_items = Plugins::filter('admin_option_items', $option_items);
$tab_index = 3;
foreach ($option_items as $name => $option_fields) {
/** @var FormControlFieldset $fieldset */
$fieldset = $form->append(FormControlWrapper::create(Utils::slugify(_u($name)))->set_properties(array('class' => 'container main settings')));
$fieldset->append(FormControlStatic::create($name)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>'));
$fieldset->set_wrap_each('<div>%s</div>');
foreach ($option_fields as $option_name => $option) {
/** @var FormControlLabel $label */
$label = $fieldset->append(FormControlLabel::create('label_for_' . $option_name, null)->set_label($option['label']));
/** @var FormControl $field */
$field = $label->append($option['type'], $option_name, $option_name);
$label->set_for($field);
if (isset($option['value'])) {
$field->set_value($option['value']);
}
if (isset($option['disabled']) && $option['disabled'] == true) {
$field->set_properties(array('disabled' => 'disabled'));
}
if ($option['type'] == 'select' && isset($option['selectarray'])) {
$field->set_options($option['selectarray']);
}
$field->tabindex = $tab_index;
$tab_index++;
if (isset($option['helptext'])) {
$field->set_helptext($option['helptext']);
}
}
}
$buttons = $form->append(new FormControlWrapper('buttons', null, array('class' => 'container')));
$buttons->append(FormControlSubmit::create('apply', null, array('tabindex' => $tab_index))->set_caption(_t('Apply')));
$form->on_success(array($self, 'form_options_success'));
$form = Plugins::filter('admin_options_form', $form);
});
}
示例11: comment_class
public function comment_class($comment, $post)
{
$classes = array('comment');
if ($comment->status == Comment::STATUS_UNAPPROVED) {
$classes[] = 'unapproved';
}
if ($u = User::get($comment->email)) {
$classes[] = 'byuser';
$classes[] = 'comment-author-' . Utils::slugify($u->displayname);
}
if ($comment->email == $post->author->email) {
$classes[] = 'bypostauthor';
}
echo implode(' ', $classes);
}
示例12: k2_comment_class
public function k2_comment_class($comment, $post)
{
$class = 'class="comment';
if ($comment->status == Comment::STATUS_UNAPPROVED) {
$class .= '-unapproved';
}
// check to see if the comment is by a registered user
if ($u = User::get($comment->email)) {
$class .= ' byuser comment-author-' . Utils::slugify($u->displayname);
}
if ($comment->email == $post->author->email) {
$class .= ' bypostauthor';
}
$class .= '"';
return $class;
}
示例13: setslug
/**
* Generate a new slug for the post.
*
* @return string The slug
*/
private function setslug()
{
// determine the base value from:
// - the new slug
if (isset($this->newfields['slug']) && $this->newfields['slug'] != '') {
$value = $this->newfields['slug'];
} elseif (isset($this->newfields['slug']) && $this->newfields['slug'] == '') {
if ($this->fields['status'] == Post::status('draft') || $this->fields['status'] != Post::status('draft') && $this->newfields['status'] != Post::status('draft')) {
if (isset($this->newfields['title']) && $this->newfields['title'] != '') {
$value = $this->newfields['title'];
} else {
$value = $this->fields['title'];
}
}
} elseif ($this->fields['slug'] != '') {
$value = $this->fields['slug'];
} elseif (isset($this->newfields['title']) && $this->newfields['title'] != '') {
$value = $this->newfields['title'];
} elseif ($this->fields['title'] != '') {
$value = $this->fields['title'];
} else {
$value = 'Post';
}
// make sure our slug is unique
$slug = Plugins::filter('post_setslug', $value);
$slug = Utils::slugify($slug);
$postfix = '';
$postfixcount = 0;
do {
if (!($slugcount = DB::get_row('SELECT COUNT(slug) AS ct FROM {posts} WHERE slug = ?;', array($slug . $postfix)))) {
Utils::debug(DB::get_errors());
exit;
}
if ($slugcount->ct != 0) {
$postfix = "-" . ++$postfixcount;
}
} while ($slugcount->ct != 0);
return $this->newfields['slug'] = $slug . $postfix;
}
示例14: get_collection
/**
* Output a post collection based on the provided parameters.
*
* @param array $params An array of parameters as passed to Posts::get() to retrieve posts.
*/
public function get_collection( $params = array() )
{
// Store handler vars since we'll be using them a lot.
$handler_vars = Controller::get_handler_vars();
// Retrieve the current matched rule and store its name and argument values.
$rr = URL::get_matched_rule();
$rr_name = $rr->name;
$rr_args = $rr->named_arg_values;
// Assign alternate links based on the matched rule.
$alternate_rules = array(
'atom_feed_tag' => 'display_entries_by_tag',
'atom_feed' => 'display_home',
'atom_entry' => 'display_entry',
'atom_feed_entry_comments' => 'display_entry',
'atom_feed_page_comments' => 'display_entry',
'atom_feed_comments' => 'display_home',
);
$alternate_rules = Plugins::filter( 'atom_get_collection_alternate_rules', $alternate_rules );
$alternate = URL::get( $alternate_rules[$rr_name], $handler_vars, false );
// Assign self link based on the matched rule.
$self = URL::get( $rr_name, $rr_args, false );
// Get posts to put in the feed
$page = ( isset( $rr_args['page'] ) ) ? $rr_args['page'] : 1;
if ( $page > 1 ) {
$params['page'] = $page;
}
if ( !isset( $params['content_type'] ) ) {
$params['content_type'] = Post::type( 'entry' );
}
$params['content_type'] = Plugins::filter( 'atom_get_collection_content_type', $params['content_type'] );
$params['status'] = $this->is_auth() ? 'any' : Post::status( 'published' );
$params['orderby'] = 'updated DESC';
$params['limit'] = Options::get( 'atom_entries' );
$params = array_merge( $params, $rr_args );
if ( array_key_exists( 'tag', $params ) ) {
$id = urlencode( $params['tag'] );
$tags = explode( ' ', $params['tag'] );
foreach ( $tags as $tag ) {
if ( $tag[0] == '-' ) {
$tag = substr( $tag, 1 );
$params['vocabulary'][Tags::vocabulary()->name . ':not:term'][] = Utils::slugify( $tag );
}
else {
$params['vocabulary'][Tags::vocabulary()->name . ':all:term'][] = Utils::slugify( $tag );
}
}
unset( $params['tag'] );
}
else {
$id = 'atom';
}
$posts = Posts::get( $params );
if ( count( $posts ) ) {
$updated = $posts[0]->updated;
}
else {
$updated = null;
header( 'HTTP/1.1 404 Not Found', true, 404 );
die( 'Posts could not be found' );
}
$xml = $this->create_atom_wrapper( $alternate, $self, $id, $updated );
$xml = $this->add_pagination_links( $xml, $posts->count_all() );
$xml = $this->add_posts( $xml, $posts );
Plugins::act( 'atom_get_collection', $xml, $params, $handler_vars );
$xml = $xml->asXML();
ob_clean();
header( 'Content-Type: application/atom+xml' );
print $this->tidy_xml( $xml );
}
示例15: get_collection
/**
* Output a post collection based on the provided parameters.
*
* @param array $params An array of parameters as passed to Posts::get() to retrieve posts.
*/
public function get_collection($params = array())
{
// Store handler vars since we'll be using them a lot.
$handler_vars = Controller::get_handler_vars();
// Retrieve the current matched rule and store its name and argument values.
$rr = URL::get_matched_rule();
$rr_name = $rr->name;
$rr_args = $rr->named_arg_values;
// Assign alternate links based on the matched rule.
$alternate_rules = array('atom_feed_tag' => 'display_entries_by_tag', 'atom_feed' => 'display_home', 'atom_entry' => 'display_entry', 'atom_feed_entry_comments' => 'display_entry', 'atom_feed_page_comments' => 'display_entry', 'atom_feed_comments' => 'display_home');
$alternate_rules = Plugins::filter('atom_get_collection_alternate_rules', $alternate_rules);
$alternate = URL::get($alternate_rules[$rr_name], $handler_vars, false);
// Assign self link based on the matched rule.
$self = URL::get($rr_name, $rr_args, false);
$id = isset($rr_args_values['tag']) ? $rr_args_values['tag'] : 'atom';
$xml = $this->create_atom_wrapper($alternate, $self, $id);
$xml = $this->add_pagination_links($xml, Posts::count_total(Post::status('published')));
// Get posts to put in the feed
$page = isset($rr_args['page']) ? $rr_args['page'] : 1;
if ($page > 1) {
$params['page'] = $page;
}
if (!isset($params['content_type'])) {
$params['content_type'] = Post::type('entry');
}
$params['content_type'] = Plugins::filter('atom_get_collection_content_type', $params['content_type']);
$params['status'] = Post::status('published');
$params['orderby'] = 'updated DESC';
$params['limit'] = Options::get('atom_entries');
$params = array_merge($params, $rr_args);
if (array_key_exists('tag', $params)) {
$params['tag_slug'] = Utils::slugify($params['tag']);
unset($params['tag']);
}
$posts = Posts::get($params);
$xml = $this->add_posts($xml, $posts);
Plugins::act('atom_get_collection', $xml, $params, $handler_vars);
$xml = $xml->asXML();
ob_clean();
header('Content-Type: application/atom+xml');
print $xml;
}