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' => '')); }
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); }
/** * 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; }
/** * 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; }
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 ); } }
/** * 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)); }
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); }
/** * 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'); }
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); }
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); }); }
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); }
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; }
/** * 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; }
/** * 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 ); }
/** * 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; }
/** * Return directory contents for the silo path * * @param string $path The path to retrieve the contents of * @return array An array of MediaAssets describing the contents of the directory */ public function silo_dir( $path ) { $flickr = new Flickr(); $results = array(); $size = Options::get( 'flickrsilo__flickr_size' ); $section = strtok( $path, '/' ); switch ( $section ) { case 'attrib-sa': $xml = $flickr->photosSearch( array( 'user_id' => '', 'license' => '4,5', 'text'=>$_SESSION['flickrsearch'] ) ); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$photo['owner']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'search': $xml = $flickr->photosSearch( array( 'text'=>$_SESSION['flickrsearch'] ) ); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'photos': $xml = $flickr->photosSearch(); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'videos': $xml = $flickr->videoSearch(); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $props['filetype'] = 'flickrvideo'; $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'tags': $selected_tag = strtok('/'); if ( $selected_tag ) { $xml = $flickr->photosSearch( array( 'tags'=>$selected_tag ) ); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } } else { $xml = $flickr->tagsGetListUser( $_SESSION['nsid'] ); foreach( $xml->who->tags->tag as $tag ) { $results[] = new MediaAsset( self::SILO_NAME . '/tags/' . (string)$tag, true, array( 'title' => (string)$tag ) ); } } break; case 'sets': $selected_set = strtok('/'); if ( $selected_set ) { $xml = $flickr->photosetsGetPhotos( $selected_set ); foreach( $xml->photoset->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } } else { $xml = $flickr->photosetsGetList( $_SESSION['nsid'] ); foreach( $xml->photosets->photoset as $set ) { $results[] = new MediaAsset( self::SILO_NAME . '/sets/' . (string)$set['id'], true, array( 'title' => (string)$set->title ) ); } } break; case '$search': $path = strtok( '/' ); $dosearch = Utils::slugify( $path ); $_SESSION['flickrsearch'] = $path; $section = $path; case '': if ( isset( $_SESSION['flickrsearch'] ) ) { $results[] = new MediaAsset( self::SILO_NAME . '/search', true, array( 'title' => _t( 'Search' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/attrib-sa', true, array( 'title' => _t( 'Search CC' ) ) ); } $results[] = new MediaAsset( self::SILO_NAME . '/photos', true, array('title' => _t( 'Photos' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/videos', true, array('title' => _t( 'Videos' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/tags', true, array('title' => _t( 'Tags' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/sets', true, array('title' => _t( 'Sets' ) ) ); break; } return $results; }
/** * Generate a new slug for the tag. * * @return string The slug */ private function setslug() { // determine the base value from: // - the new slug if (isset($this->newfields['tag_slug']) && $this->newfields['tag_slug'] != '') { $value = $this->newfields['tag_slug']; } elseif ($this->fields['tag_slug'] != '') { $value = $this->fields['tag_slug']; } elseif (isset($this->newfields['tag_text']) && $this->newfields['tag_text'] != '') { $value = $this->newfields['tag_text']; } elseif ($this->fields['tag_text'] != '') { $value = $this->fields['tag_text']; } // make sure our slug is unique $slug = Plugins::filter('tag_setslug', $value); $slug = Utils::slugify($slug); return $this->newfields['tag_slug'] = $slug; }
/** * Parse tag parameters from a URL string * * @param String $tags The URL parameter string * * @return Array. Associative array of included and excluded tags */ public static function parse_url_tags($tags, $objectify = false) { $tags = explode(' ', $tags); $exclude_tag = array(); $include_tag = array(); foreach ($tags as $tag) { if (MultiByte::substr($tag, 0, 1) == '-') { $tag = MultiByte::substr($tag, 1); $exclude_tag[] = $objectify ? Tags::get_one(Utils::slugify($tag)) : Utils::slugify($tag); } else { $include_tag[] = $objectify ? Tags::get_one(Utils::slugify($tag)) : Utils::slugify($tag); } } return compact('include_tag', 'exclude_tag'); }
/** * Produce a unique id (not name) for this control for use with labels and such, only if one is not provided in the control properties * @param bool $force_set Default to true, forcing the id to be set to the name of the control if it's not set already * @return string|null The id of this control, or null if it's not set and not forced */ public function get_id($force_set = true) { if (!isset($this->properties['id']) && $force_set) { $id_stack = array($this->name); $c = $this->container; while (!empty($c)) { array_unshift($id_stack, $c->get_id_component()); $c = $c->container; } $id_stack = array_filter($id_stack); $this->properties['id'] = Utils::slugify(implode('_', $id_stack), '_'); } return isset($this->properties['id']) ? $this->get_setting('id_prefix', '') . $this->properties['id'] : null; }
public function form_publish_success(FormUI $form) { $post_id = 0; if (isset($this->handler_vars['id'])) { $post_id = intval($this->handler_vars['id']); } // If an id has been passed in, we're updating an existing post, otherwise we're creating one if (0 !== $post_id) { $post = Post::get(array('id' => $post_id, 'status' => Post::status('any'))); $this->theme->admin_page = sprintf(_t('Publish %s'), Plugins::filter('post_type_display', Post::type_name($post->content_type), 'singular')); // Verify that the post hasn't already been updated since the form was loaded if ($post->modified != $form->modified->value) { Session::notice(_t('The post %1$s was updated since you made changes. Please review those changes before overwriting them.', array(sprintf('<a href="%1$s">\'%2$s\'</a>', $post->permalink, Utils::htmlspecialchars($post->title))))); Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id)); exit; } // Don't try to update form values that have been removed by plugins $expected = array('title', 'tags', 'content'); foreach ($expected as $field) { if (isset($form->{$field})) { $post->{$field} = $form->{$field}->value; } } if ($form->newslug->value == '' && $post->status == Post::status('published')) { Session::notice(_t('A post slug cannot be empty. Keeping old slug.')); } elseif ($form->newslug->value != $form->slug->value) { $post->slug = $form->newslug->value; } // sorry, we just don't allow changing posts you don't have rights to if (!ACL::access_check($post->get_access(), 'edit')) { Session::error(_t('You don\'t have permission to edit that post')); $this->get_blank(); } // sorry, we just don't allow changing content types to types you don't have rights to $user = User::identify(); $type = 'post_' . Post::type_name($form->content_type->value); if ($form->content_type->value != $post->content_type && ($user->cannot($type) || !$user->can_any(array('own_posts' => 'edit', 'post_any' => 'edit', $type => 'edit')))) { Session::error(_t('Changing content types is not allowed')); $this->get_blank(); } $post->content_type = $form->content_type->value; // if not previously published and the user wants to publish now, change the pubdate to the current date/time unless a date has been explicitly set if ($post->status != Post::status('published') && $form->status->value == Post::status('published') && HabariDateTime::date_create($form->pubdate->value)->int == $form->updated->value) { $post->pubdate = HabariDateTime::date_create(); } else { $post->pubdate = HabariDateTime::date_create($form->pubdate->value); } $minor = $form->minor_edit->value && $post->status != Post::status('draft'); $post->status = $form->status->value; } else { $post = new Post(); // check the user can create new posts of the set type. $user = User::identify(); $type = 'post_' . Post::type_name($form->content_type->value); if (ACL::user_cannot($user, $type) || !ACL::user_can($user, 'post_any', 'create') && !ACL::user_can($user, $type, 'create')) { Session::error(_t('Creating that post type is denied')); $this->get_blank(); } $form->on_success(array($this, 'form_publish_success')); if (HabariDateTime::date_create($form->pubdate->value)->int != $form->updated->value) { $post->pubdate = HabariDateTime::date_create($form->pubdate->value); } $postdata = array('slug' => $form->newslug->value, 'user_id' => User::identify()->id, 'pubdate' => $post->pubdate, 'status' => $form->status->value, 'content_type' => $form->content_type->value); // Don't try to add form values that have been removed by plugins $expected = array('title', 'tags', 'content'); foreach ($expected as $field) { if (isset($form->{$field})) { $postdata[$field] = $form->{$field}->value; } } $minor = false; $post = Post::create($postdata); } if ($post->pubdate->int > HabariDateTime::date_create()->int && $post->status == Post::status('published')) { $post->status = Post::status('scheduled'); } $post->info->comments_disabled = !$form->comments_enabled->value; Plugins::act('publish_post', $post, $form); $post->update($minor); $permalink = $post->status != Post::status('published') ? $post->permalink . '?preview=1' : $post->permalink; Session::notice(sprintf(_t('The post %1$s has been saved as %2$s.'), sprintf('<a href="%1$s">\'%2$s\'</a>', $permalink, Utils::htmlspecialchars($post->title)), Post::status_name($post->status))); if ($post->slug != Utils::slugify($post->title) || $post->slug != $form->slug->value) { Session::notice(sprintf(_t('The content address is \'%1$s\'.'), $post->slug)); } Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id)); }
public function action_block_content_grayposts($block, $theme) { $criteria = new SuperGlobal(array()); if (User::identify()->loggedin) { $criteria['status'] = isset($_GET['preview']) ? Post::status('any') : Post::status('published'); } else { $criteria['status'] = Post::status('published'); } if ($block->content_type != '') { $criteria['content_type'] = $block->content_type; if ($block->content_type == 0) { unset($criteria['content_type']); } } if ($block->limit != '') { $criteria['limit'] = $block->limit; } if ($block->offset != '') { $criteria['offset'] = $block->offset; } if ($block->tag != '') { $criteria['tag'] = $block->tag; } if ($block->main) { $where_filters = Controller::get_handler()->handler_vars->filter_keys($this->valid_filters); if (array_key_exists('tag', $where_filters)) { $where_filters['tag_slug'] = Utils::slugify($where_filters['tag']); unset($where_filters['tag']); } $where_filters = Plugins::filter('template_where_filters', $where_filters); $criteria = $criteria->merge($where_filters); } $block->posts = Posts::get($criteria); //$block->posts = Posts::get('limit=5&status=2&content_type=0'); $block->criteria = $criteria; }
public static function save_versions($post = null, $versions = array()) { if (isset($post) && count($versions) !== 0) { $vocabulary = Vocabulary::get(self::CATALOG_VOCABULARY); $extant_terms = $vocabulary->get_associations($post->id, 'addon'); foreach ($versions as $key => $version) { $version_display = "{$version['habari_version']}-{$version['version']}"; echo "Incoming Version: {$version_display}\n\n"; $found = false; foreach ($extant_terms as $eterm) { $extant_display = "{$eterm->info->habari_version}-{$eterm->info->version}"; echo ">> Extant Version: {$extant_display}\n\n"; if ($extant_display == $version_display) { $found = true; $term = $eterm; break; } } if (!$found) { $term = new Term(array('term_display' => $version_display, 'term' => Utils::slugify("{$post->id} {$version_display} {$post->info->repo_url}", '-'))); } foreach ($version as $field => $value) { $term->info->{$field} = $value; } if ($found) { $term->update(); } else { $vocabulary->add_term($term); $term->associate('addon', $post->id); } } } else { // post didn't work or there was no version. } }
public function setup() { $this->slug = Utils::slugify( $this->text ); $this->tag = new Tag( array( 'term_display' => $this->text, 'term' => $this->slug ) ); }
/** * function get * Returns requested comments * @param array An associated array of parameters, or a querystring * @return array An array of Comment objects, one for each query result * * <code> * $comments = comments::get( array ( "author" => "skippy" ) ); * $comments = comments::get( array ( "slug" => "first-post", "status" => "1", "orderby" => "date ASC" ) ); * </code> * **/ public static function get($paramarray = array()) { $params = array(); $fns = array('get_results', 'get_row', 'get_value'); $select = ''; // what to select -- by default, everything foreach (Comment::default_fields() as $field => $value) { $select .= '' == $select ? "{comments}.{$field}" : ", {comments}.{$field}"; } // defaults $orderby = 'date DESC'; $limit = Options::get('pagination'); // Put incoming parameters into the local scope $paramarray = Utils::get_params($paramarray); // Transact on possible multiple sets of where information that is to be OR'ed if (isset($paramarray['where']) && is_array($paramarray['where'])) { $wheresets = $paramarray['where']; } else { $wheresets = array(array()); } $wheres = array(); $joins = array(); if (isset($paramarray['where']) && is_string($paramarray['where'])) { $wheres[] = $paramarray['where']; } else { foreach ($wheresets as $paramset) { // safety mechanism to prevent empty queries $where = array('1=1'); $paramset = array_merge((array) $paramarray, (array) $paramset); if (isset($paramset['id']) && (is_numeric($paramset['id']) || is_array($paramset['id']))) { if (is_numeric($paramset['id'])) { $where[] = "{comments}.id= ?"; $params[] = $paramset['id']; } else { if (is_array($paramset['id']) && !empty($paramset['id'])) { $id_list = implode(',', $paramset['id']); // Clean up the id list - remove all non-numeric or comma information $id_list = preg_replace("/[^0-9,]/", "", $id_list); // You're paranoid, ringmaster! :P $limit = count($paramset['id']); $where[] = '{comments}.id IN (' . addslashes($id_list) . ')'; } } } if (isset($paramset['status']) && FALSE !== $paramset['status']) { if (is_array($paramset['status'])) { $paramset['status'] = array_diff($paramset['status'], array('any')); array_walk($paramset['status'], create_function('&$a,$b', '$a = Comment::status( $a );')); $where[] = "{comments}.status IN (" . Utils::placeholder_string(count($paramset['status'])) . ")"; $params = array_merge($params, $paramset['status']); } else { $where[] = "{comments}.status= ?"; $params[] = Comment::status($paramset['status']); } } if (isset($paramset['type']) && FALSE !== $paramset['type']) { if (is_array($paramset['type'])) { $paramset['type'] = array_diff($paramset['type'], array('any')); array_walk($paramset['type'], create_function('&$a,$b', '$a = Comment::type( $a );')); $where[] = "type IN (" . Utils::placeholder_string(count($paramset['type'])) . ")"; $params = array_merge($params, $paramset['type']); } else { $where[] = "type= ?"; $params[] = Comment::type($paramset['type']); } } if (isset($paramset['name'])) { $where[] = "name= ?"; $params[] = $paramset['name']; } if (isset($paramset['email'])) { $where[] = "email= ?"; $params[] = $paramset['email']; } if (isset($paramset['url'])) { $where[] = "url= ?"; $params[] = $paramset['url']; } if (isset($paramset['post_id'])) { $where[] = "{comments}.post_id= ?"; $params[] = $paramset['post_id']; } if (isset($paramset['ip'])) { $where[] = "ip= ?"; $params[] = $paramset['ip']; } /* do searching */ if (isset($paramset['post_author'])) { $joins['posts'] = ' INNER JOIN {posts} ON {comments}.post_id = {posts}.id'; if (is_array($paramset['post_author'])) { $where[] = "{posts}.user_id IN (" . implode(',', array_fill(0, count($paramset['post_author']), '?')) . ")"; $params = array_merge($params, $paramset['post_author']); } else { $where[] = '{posts}.user_id = ?'; $params[] = (string) $paramset['post_author']; } } if (isset($paramset['criteria'])) { if (isset($paramset['criteria_fields'])) { // Support 'criteria_fields' => 'author,ip' rather than 'criteria_fields' => array( 'author', 'ip' ) if (!is_array($paramset['criteria_fields']) && is_string($paramset['criteria_fields'])) { $paramset['criteria_fields'] = explode(',', $paramset['criteria_fields']); } } else { $paramset['criteria_fields'] = array('content'); } $paramset['criteria_fields'] = array_unique($paramset['criteria_fields']); preg_match_all('/(?<=")([\\p{L}\\p{N}]+[^"]*)(?=")|([\\p{L}\\p{N}]+)/u', $paramset['criteria'], $matches); $where_search = array(); foreach ($matches[0] as $word) { foreach ($paramset['criteria_fields'] as $criteria_field) { $where_search[] .= "({comments}.{$criteria_field} LIKE CONCAT('%',?,'%'))"; $params[] = $word; } } if (count($where_search) > 0) { $where[] = '(' . implode(" \nOR\n ", $where_search) . ')'; } } /* * Build the pubdate * If we've got the day, then get the date. * If we've got the month, but no date, get the month. * If we've only got the year, get the whole year. * @todo Ensure that we've actually got all the needed parts when we query on them * @todo Ensure that the value passed in is valid to insert into a SQL date (ie '04' and not '4') */ if (isset($paramset['day'])) { /* Got the full date */ $where[] = 'date BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], $paramset['day']); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 day')->sql; } elseif (isset($paramset['month'])) { $where[] = 'date BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 month')->sql; } elseif (isset($paramset['year'])) { $where[] = 'date BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 year')->sql; } // Concatenate the WHERE clauses if (count($where) > 0) { $wheres[] = ' (' . implode(' AND ', $where) . ') '; } } } // Only show comments to which the current user has permission to read the associated post if (isset($paramset['ignore_permissions'])) { $master_perm_where = ''; } else { // This set of wheres will be used to generate a list of comment_ids that this user can read $perm_where = array(); $perm_where_denied = array(); $params_where = array(); $where = array(); // every condition here will require a join with the posts table $joins['posts'] = 'INNER JOIN {posts} ON {comments}.post_id={posts}.id'; // Get the tokens that this user is granted or denied access to read $read_tokens = isset($paramset['read_tokens']) ? $paramset['read_tokens'] : ACL::user_tokens(User::identify(), 'read', true); $deny_tokens = isset($paramset['deny_tokens']) ? $paramset['deny_tokens'] : ACL::user_tokens(User::identify(), 'deny', true); // If a user can read his own posts, let him if (User::identify()->can('own_posts', 'read')) { $perm_where['own_posts_id'] = '{posts}.user_id = ?'; $params_where[] = User::identify()->id; } // If a user can read any post type, let him if (User::identify()->can('post_any', 'read')) { $perm_where = array('post_any' => '(1=1)'); $params_where = array(); } else { // If a user can read specific post types, let him $permitted_post_types = array(); foreach (Post::list_active_post_types() as $name => $posttype) { if (User::identify()->can('post_' . Utils::slugify($name), 'read')) { $permitted_post_types[] = $posttype; } } if (count($permitted_post_types) > 0) { $perm_where[] = '{posts}.content_type IN (' . implode(',', $permitted_post_types) . ')'; } // If a user can read posts with specific tokens, let him see comments on those posts if (count($read_tokens) > 0) { $joins['post_tokens__allowed'] = ' LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN (' . implode(',', $read_tokens) . ')'; $perm_where['perms_join_null'] = 'pt_allowed.post_id IS NOT NULL'; } } // If a user is denied access to all posts, do so if (User::identify()->cannot('post_any')) { $perm_where_denied = array('(0=1)'); } else { // If a user is denied read access to specific post types, deny him $denied_post_types = array(); foreach (Post::list_active_post_types() as $name => $posttype) { if (User::identify()->cannot('post_' . Utils::slugify($name))) { $denied_post_types[] = $posttype; } } if (count($denied_post_types) > 0) { $perm_where_denied[] = '{posts}.content_type NOT IN (' . implode(',', $denied_post_types) . ')'; } } // If there are granted permissions to check, add them to the where clause if (count($perm_where) == 0 && !isset($joins['post_tokens__allowed'])) { // You have no grants. You get no comments. $where['perms_granted'] = '(0=1)'; } elseif (count($perm_where) > 0) { $where['perms_granted'] = ' (' . implode(' OR ', $perm_where) . ') '; $params = array_merge($params, $params_where); } if (count($deny_tokens) > 0) { $joins['post_tokens__denied'] = ' LEFT JOIN {post_tokens} pt_denied ON {posts}.id= pt_denied.post_id AND pt_denied.token_id IN (' . implode(',', $deny_tokens) . ')'; $perm_where_denied['perms_join_null'] = 'pt_denied.post_id IS NULL'; } // If there are denied permissions to check, add them to the where clause if (count($perm_where_denied) > 0) { $where['perms_denied'] = ' (' . implode(' AND ', $perm_where_denied) . ') '; } $master_perm_where = implode(' AND ', $where); } // Get any full-query parameters $possible = array('page', 'fetch_fn', 'count', 'month_cts', 'nolimit', 'limit', 'offset', 'orderby'); foreach ($possible as $varname) { if (isset($paramarray[$varname])) { ${$varname} = $paramarray[$varname]; } } if (isset($page) && is_numeric($page)) { $offset = (intval($page) - 1) * intval($limit); } if (isset($fetch_fn)) { if (!in_array($fetch_fn, $fns)) { $fetch_fn = $fns[0]; } } else { $fetch_fn = $fns[0]; } // is a count being request? if (isset($count)) { $select = "COUNT( 1 )"; $fetch_fn = 'get_value'; $orderby = ''; } // is a count of comments by month being requested? $groupby = ''; if (isset($month_cts)) { $select = 'MONTH(FROM_UNIXTIME(date)) AS month, YEAR(FROM_UNIXTIME(date)) AS year, COUNT({comments}.id) AS ct'; $groupby = 'year, month'; $orderby = 'year, month'; } if (isset($limit)) { $limit = " LIMIT {$limit}"; if (isset($offset)) { $limit .= " OFFSET {$offset}"; } } if (isset($nolimit) || isset($month_cts)) { $limit = ''; } // Build the final SQL statement $query = ' SELECT DISTINCT ' . $select . ' FROM {comments} ' . implode(' ', $joins); if (count($wheres) > 0) { $query .= ' WHERE (' . implode(" \nOR\n ", $wheres) . ')'; $query .= $master_perm_where == '' ? '' : ' AND (' . $master_perm_where . ')'; } elseif ($master_perm_where != '') { $query .= ' WHERE (' . $master_perm_where . ')'; } $query .= $groupby == '' ? '' : ' GROUP BY ' . $groupby; $query .= ($orderby == '' ? '' : ' ORDER BY ' . $orderby) . $limit; //Utils::debug( $query, $params ); DB::set_fetch_mode(PDO::FETCH_CLASS); DB::set_fetch_class('Comment'); $results = DB::$fetch_fn($query, $params, 'Comment'); if ('get_results' != $fetch_fn) { // return the results return $results; } elseif (is_array($results)) { $c = __CLASS__; $return_value = new $c($results); $return_value->get_param_cache = $paramarray; return $return_value; } }
/** * Generate a new slug for the post. * * @return string The slug */ private function setslug() { // determine the base value from: // - the new slug // If the slug is new and has a length if ( isset( $this->newfields['slug'] ) && $this->newfields['slug'] != '' ) { $value = $this->newfields['slug']; } // - the new empty slug whilst in draft or progressing directly to published or scheduled from draft. // - Also allow changing of slug whilst in scheduled state // // This happens when a draft is being updated, or a post is being directly published or scheduled, // or an existing scheduled or published post is being updated, but not made into a draft // // If a new slug is set, and it doesn't have a length elseif ( isset( $this->newfields['slug'] ) && $this->newfields['slug'] == '' ) { // If the existing status of the post is draft, no matter what status it is being changed to if ( $this->fields['status'] == Post::status( 'draft' ) || ( // or the existing status is not draft and the new status is not draft $this->fields['status'] != Post::status( 'draft' ) && $this->newfields['status'] != Post::status( 'draft' ) ) ) { // And a new title is set, use the new title if ( isset( $this->newfields['title'] ) && $this->newfields['title'] != '' ) { $value = $this->newfields['title']; } // Otherwise, use the existing title else { $value = $this->fields['title']; } } } // - the existing slug // If there is an existing slug, and it has a length elseif ( $this->fields['slug'] != '' ) { $value = $this->fields['slug']; } // - the new post title // If there is a new title, and it has a length elseif ( isset( $this->newfields['title'] ) && $this->newfields['title'] != '' ) { $value = $this->newfields['title']; } // - the existing post title // If there is an existing title, and it has a length elseif ( $this->fields['title'] != '' ) { $value = $this->fields['title']; } // - default //Nothing else worked. Default to 'Post' 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; }
/** * Returns a form for editing this post * @param string $context The context the form is being created in, most often 'admin' * @return FormUI A form appropriate for creating and updating this post. */ public function get_form($context) { $form = new FormUI('create-content'); $form->class[] = 'create'; $newpost = 0 === $this->id; // If the post has already been saved, add a link to its permalink if (!$newpost) { $post_links = $form->append('wrapper', 'post_links'); $permalink = $this->status != Post::status('published') ? $this->permalink . '?preview=1' : $this->permalink; $post_links->append('static', 'post_permalink', '<a href="' . $permalink . '" class="viewpost" >' . ($this->status != Post::status('published') ? _t('Preview Post') : _t('View Post')) . '</a>'); $post_links->class = 'container'; } // Store this post instance into a hidden field for later use when saving data $form->append('hidden', 'post', $this, _t('Title'), 'admincontrol_text'); // Create the Title field $form->append('text', 'title', 'null:null', _t('Title'), 'admincontrol_text'); $form->title->class[] = 'important'; $form->title->class[] = 'check-change'; $form->title->tabindex = 1; $form->title->value = $this->title_internal; // Create the silos if (count(Plugins::get_by_interface('MediaSilo'))) { $form->append('silos', 'silos'); $form->silos->silos = Media::dir(); } // Create the Content field $form->append('textarea', 'content', 'null:null', _t('Content'), 'admincontrol_textarea'); $form->content->class[] = 'resizable'; $form->content->class[] = 'check-change'; $form->content->tabindex = 2; $form->content->value = $this->content_internal; $form->content->raw = true; // Create the tags field $form->append('text', 'tags', 'null:null', _t('Tags, separated by, commas'), 'admincontrol_text'); $form->tags->class = 'check-change'; $form->tags->tabindex = 3; $tags = (array) $this->get_tags(); array_walk($tags, function (&$element, $key) { $element->term_display = MultiByte::strpos($element->term_display, ',') === false ? $element->term_display : $element->tag_text_searchable; }); $form->tags->value = implode(', ', $tags); // Create the splitter $publish_controls = $form->append('tabs', 'publish_controls'); // Create the publishing controls // pass "false" to list_post_statuses() so that we don't include internal post statuses $statuses = Post::list_post_statuses($this); unset($statuses[array_search('any', $statuses)]); $statuses = Plugins::filter('admin_publish_list_post_statuses', $statuses); $settings = $publish_controls->append('fieldset', 'settings', _t('Settings')); $settings->append('select', 'status', 'null:null', _t('Content State'), array_flip($statuses), 'tabcontrol_select'); $settings->status->value = $this->status; // hide the minor edit checkbox if the post is new if ($newpost) { $settings->append('hidden', 'minor_edit', 'null:null'); $settings->minor_edit->value = false; } else { $settings->append('checkbox', 'minor_edit', 'null:null', _t('Minor Edit'), 'tabcontrol_checkbox'); $settings->minor_edit->value = true; $form->append('hidden', 'modified', 'null:null')->value = $this->modified; } $settings->append('checkbox', 'comments_enabled', 'null:null', _t('Comments Allowed'), 'tabcontrol_checkbox'); $settings->comments_enabled->value = $this->info->comments_disabled ? false : true; $settings->append('text', 'pubdate', 'null:null', _t('Publication Time'), 'tabcontrol_text'); $settings->pubdate->value = $this->pubdate->format('Y-m-d H:i:s'); $settings->pubdate->helptext = _t('YYYY-MM-DD HH:MM:SS'); $settings->append('hidden', 'updated', 'null:null'); $settings->updated->value = $this->updated->int; $settings->append('text', 'newslug', 'null:null', _t('Content Address'), 'tabcontrol_text'); $settings->newslug->id = 'newslug'; $settings->newslug->value = $this->slug; // Create the button area $buttons = $form->append('fieldset', 'buttons'); $buttons->template = 'admincontrol_buttons'; $buttons->class[] = 'container'; $buttons->class[] = 'buttons'; $buttons->class[] = 'publish'; // Create the Save button $require_any = array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($this->content_type) => 'create'); if ($newpost && User::identify()->can_any($require_any) || !$newpost && ACL::access_check($this->get_access(), 'edit')) { $buttons->append('submit', 'save', _t('Save'), 'admincontrol_submit'); $buttons->save->tabindex = 4; } // Add required hidden controls $form->append('hidden', 'content_type', 'null:null'); $form->content_type->id = 'content_type'; $form->content_type->value = $this->content_type; $form->append('hidden', 'post_id', 'null:null'); $form->post_id->id = 'id'; $form->post_id->value = $this->id; $form->append('hidden', 'slug', 'null:null'); $form->slug->value = $this->slug; $form->slug->id = 'originalslug'; $form->on_success(array($this, 'form_publish_success')); // Let plugins alter this form Plugins::act('form_publish', $form, $this, $context); $content_types = array_flip(Post::list_active_post_types()); Plugins::act('form_publish_' . Utils::slugify($content_types[$this->content_type], '_'), $form, $this, $context); // Return the form object return $form; }
/** * Returns the count of times a tag is used. * * @param mixed The tag to count usage. * @return int The number of times a tag is used. **/ public static function post_count($tag) { if (is_int($tag)) { $tag = Tags::get_by_id($tag); } else { if (is_string($tag)) { $tag = Tags::get_by_slug(Utils::slugify($tag)); } } return DB::get_row('SELECT COUNT(tag_id) AS count FROM {tag2post} WHERE tag_id = ?', array($tag->id)); }
<?php if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); } ?> <ul class="menu"> <?php foreach($content->menus as $menu) : ?> <li class="<?php echo $menu['cssclass']; ?> block-<?php echo Utils::slugify($menu['caption']); ?>"><a href="<?php echo $menu['link']; ?>"><?php echo $menu['caption']; ?></a></li> <?php endforeach; ?> </ul>
/** * Returns a post or posts based on supplied parameters. * <b>THIS CLASS SHOULD CACHE QUERY RESULTS!</b> * * @param array $paramarry An associated array of parameters, or a querystring * @return array An array of Post objects, or a single post object, depending on request */ public static function get($paramarray = array()) { $join_params = array(); $params = array(); $fns = array('get_results', 'get_row', 'get_value'); $select_ary = array(); // Default fields to select, everything by default foreach (Post::default_fields() as $field => $value) { $select_ary[$field] = "{posts}.{$field} AS {$field}"; } // Default parameters $orderby = 'pubdate DESC'; // If $paramarray is a querystring, convert it to an array $paramarray = Utils::get_params($paramarray); // Define the WHERE sets to process and OR in the final SQL statement if (isset($paramarray['where']) && is_array($paramarray['where'])) { $wheresets = $paramarray['where']; } else { $wheresets = array(array()); } /* Start building the WHERE clauses */ $wheres = array(); $joins = array(); // If the request as a textual WHERE clause, skip the processing of the $wheresets since it's empty if (isset($paramarray['where']) && is_string($paramarray['where'])) { $wheres[] = $paramarray['where']; } else { foreach ($wheresets as $paramset) { // Safety mechanism to prevent empty queries $where = array(); $paramset = array_merge((array) $paramarray, (array) $paramset); // $nots= preg_grep( '%^not:(\w+)$%iu', (array) $paramset ); if (isset($paramset['id'])) { if (is_array($paramset['id'])) { array_walk($paramset['id'], create_function('&$a,$b', '$a = intval($a);')); $where[] = "{posts}.id IN (" . implode(',', array_fill(0, count($paramset['id']), '?')) . ")"; $params = array_merge($params, $paramset['id']); } else { $where[] = "{posts}.id = ?"; $params[] = (int) $paramset['id']; } } if (isset($paramset['not:id'])) { if (is_array($paramset['not:id'])) { array_walk($paramset['not:id'], create_function('&$a,$b', '$a = intval($a);')); $where[] = "{posts}.id NOT IN (" . implode(',', array_fill(0, count($paramset['not:id']), '?')) . ")"; $params = array_merge($params, $paramset['not:id']); } else { $where[] = "{posts}.id != ?"; $params[] = (int) $paramset['not:id']; } } if (isset($paramset['status']) && $paramset['status'] != 'any' && 0 !== $paramset['status']) { if (is_array($paramset['status'])) { // remove 'any' from the list if we have an array $paramset['status'] = array_diff($paramset['status'], array('any')); array_walk($paramset['status'], create_function('&$a,$b', '$a = Post::status($a);')); $where[] = "{posts}.status IN (" . implode(',', array_fill(0, count($paramset['status']), '?')) . ")"; $params = array_merge($params, $paramset['status']); } else { $where[] = "{posts}.status = ?"; $params[] = (int) Post::status($paramset['status']); } } if (isset($paramset['content_type']) && $paramset['content_type'] != 'any' && 0 !== $paramset['content_type']) { if (is_array($paramset['content_type'])) { // remove 'any' from the list if we have an array $paramset['content_type'] = array_diff($paramset['content_type'], array('any')); array_walk($paramset['content_type'], create_function('&$a,$b', '$a = Post::type($a);')); $where[] = "{posts}.content_type IN (" . implode(',', array_fill(0, count($paramset['content_type']), '?')) . ")"; $params = array_merge($params, $paramset['content_type']); } else { $where[] = "{posts}.content_type = ?"; $params[] = (int) Post::type($paramset['content_type']); } } if (isset($paramset['not:content_type'])) { if (is_array($paramset['not:content_type'])) { array_walk($paramset['not:content_type'], create_function('&$a,$b', '$a = Post::type($a);')); $where[] = "{posts}.content_type NOT IN (" . implode(',', array_fill(0, count($paramset['not:content_type']), '?')) . ")"; $params = array_merge($params, $paramset['not:content_type']); } else { $where[] = "{posts}.content_type != ?"; $params[] = (int) Post::type($paramset['not:content_type']); } } if (isset($paramset['slug'])) { if (is_array($paramset['slug'])) { $where[] = "{posts}.slug IN (" . implode(',', array_fill(0, count($paramset['slug']), '?')) . ")"; $params = array_merge($params, $paramset['slug']); } else { $where[] = "{posts}.slug = ?"; $params[] = (string) $paramset['slug']; } } if (isset($paramset['user_id']) && 0 !== $paramset['user_id']) { if (is_array($paramset['user_id'])) { array_walk($paramset['user_id'], create_function('&$a,$b', '$a = intval($a);')); $where[] = "{posts}.user_id IN (" . implode(',', array_fill(0, count($paramset['user_id']), '?')) . ")"; $params = array_merge($params, $paramset['user_id']); } else { $where[] = "{posts}.user_id = ?"; $params[] = (int) $paramset['user_id']; } } if (isset($paramset['tag']) || isset($paramset['tag_slug'])) { $joins['tag2post_posts'] = ' JOIN {object_terms} ON {posts}.id = {object_terms}.object_id'; $joins['tags_tag2post'] = ' JOIN {terms} ON {object_terms}.term_id = {terms}.id'; if (isset($paramset['tag'])) { if (is_array($paramset['tag'])) { $where[] = "{terms}.term_display IN (" . implode(',', array_fill(0, count($paramset['tag']), '?')) . ")" . ' AND {object_terms}.object_type_id = ?'; $params = array_merge($params, $paramset['tag']); } else { $where[] = '{terms}.term_display = ? AND {object_terms}.object_type_id = ?'; $params[] = (string) $paramset['tag']; } } if (isset($paramset['tag_slug'])) { if (is_array($paramset['tag_slug'])) { $where[] = "{terms}.term IN (" . implode(',', array_fill(0, count($paramset['tag_slug']), '?')) . ")" . ' AND {object_terms}.object_type_id = ?'; $params = array_merge($params, $paramset['tag_slug']); } else { $where[] = '{terms}.term= ? AND {object_terms}.object_type_id = ?'; $params[] = (string) $paramset['tag_slug']; } } $params[] = Vocabulary::object_type_id(Tags::object_type()); } if (isset($paramset['all:tag'])) { $joins['tag2post_posts'] = ' JOIN {object_terms} ON {posts}.id = {object_terms}.object_id'; $joins['tags_tag2post'] = ' JOIN {terms} ON {object_terms}.term_id = {terms}.id'; if (is_array($paramset['all:tag'])) { $where[] = '{terms}.term_display IN (' . Utils::placeholder_string($paramset['all:tag']) . ')' . ' AND {object_terms}.object_type_id = ?'; $params = array_merge($params, $paramset['all:tag']); $groupby = '{posts}.id'; $having = 'count(*) = ' . count($paramset['all:tag']); } else { // this is actually the same as plain 'tag' for a single tag search - go with it $where[] = '{terms}.term_display = ? AND {object_terms}.object_type_id = ?'; $params[] = $paramset['all:tag']; } $params[] = Vocabulary::object_type_id(Tags::object_type()); } if (isset($paramset['all:tag_slug'])) { $joins['tag2post_posts'] = ' JOIN {object_terms} ON {posts}.id = {object_terms}.object_id'; $joins['tags_tag2post'] = ' JOIN {terms} ON {object_terms}.term_id = {terms}.id'; if (is_array($paramset['all:tag_slug'])) { $where[] = '{terms}.term IN (' . Utils::placeholder_string($paramset['all:tag_slug']) . ')' . ' AND {object_terms}.object_type_id = ?'; $params = array_merge($params, $paramset['all:tag_slug']); $groupby = '{posts}.id'; $having = 'count(*) = ' . count($paramset['all:tag_slug']); } else { // this is actually the same as plain 'tag' for a single tag search - go with it $where[] = '{terms}.term = ? AND {object_terms}.object_type_id = ?'; $params[] = $paramset['all:tag_slug']; } $params[] = Vocabulary::object_type_id(Tags::object_type()); } if (isset($paramset['not:tag'])) { $nottag = Utils::single_array($paramset['not:tag']); $where[] = 'NOT EXISTS (SELECT 1 FROM {object_terms} INNER JOIN {terms} ON {terms}.id = {object_terms}.term_id WHERE {terms}.term_display IN (' . Utils::placeholder_string($nottag) . ') AND {object_terms}.object_id = {posts}.id AND {object_terms}.object_type_id = ?) '; $params = array_merge($params, $nottag); $params[] = Vocabulary::object_type_id(Tags::object_type()); } if (isset($paramset['not:tag_slug'])) { $nottag = Utils::single_array($paramset['not:tag_slug']); $where[] = 'NOT EXISTS (SELECT 1 FROM {object_terms} INNER JOIN {terms} ON {terms}.id = {object_terms}.term_id WHERE {terms}.term_display IN (' . Utils::placeholder_string($nottag) . ') AND {object_terms}.object_id = {posts}.id AND {object_terms}.object_type_id = ?) '; $params = array_merge($params, $nottag); $params[] = Vocabulary::object_type_id(Tags::object_type()); } if (isset($paramset['criteria'])) { preg_match_all('/(?<=")([\\p{L}\\p{N}]+[^"]*)(?=")|([\\p{L}\\p{N}]+)/u', $paramset['criteria'], $matches); foreach ($matches[0] as $word) { $where[] .= "({posts}.title LIKE CONCAT('%',?,'%') OR {posts}.content LIKE CONCAT('%',?,'%'))"; $params[] = $word; $params[] = $word; // Not a typo (there are two ? in the above statement) } } if (isset($paramset['all:info']) || isset($paramset['info'])) { // merge the two possibile calls together $infos = array_merge(isset($paramset['all:info']) ? $paramset['all:info'] : array(), isset($paramset['info']) ? $paramset['info'] : array()); if (Utils::is_traversable($infos)) { $pi_count = 0; foreach ($infos as $info_key => $info_value) { $pi_count++; $joins['info_' . $info_key] = " LEFT JOIN {postinfo} ipi{$pi_count} ON {posts}.id = ipi{$pi_count}.post_id AND ipi{$pi_count}.name = ? AND ipi{$pi_count}.value = ?"; $join_params[] = $info_key; $join_params[] = $info_value; $where[] = "ipi{$pi_count}.name <> ''"; $select_ary["info_{$info_key}_value"] = "ipi{$pi_count}.value AS info_{$info_key}_value"; } } } if (isset($paramset['any:info'])) { if (Utils::is_traversable($paramset['any:info'])) { $pi_count = 0; $pi_where = array(); foreach ($paramset['any:info'] as $info_key => $info_value) { $pi_count++; $join_params[] = $info_key; if (is_array($info_value)) { $joins['any_info_' . $info_key] = " LEFT JOIN {postinfo} aipi{$pi_count} ON {posts}.id = aipi{$pi_count}.post_id AND aipi{$pi_count}.name = ? AND aipi{$pi_count}.value IN (" . Utils::placeholder_string(count($info_value)) . ")"; $join_params = array_merge($join_params, $info_value); } else { $joins['any_info_' . $info_key] = " LEFT JOIN {postinfo} aipi{$pi_count} ON {posts}.id = aipi{$pi_count}.post_id AND aipi{$pi_count}.name = ? AND aipi{$pi_count}.value = ?"; $join_params[] = $info_value; } $pi_where[] = "aipi{$pi_count}.name <> ''"; $select_ary["info_{$info_key}_value"] = "aipi{$pi_count}.value AS info_{$info_key}_value"; } $where[] = '(' . implode(' OR ', $pi_where) . ')'; } } if (isset($paramset['has:info'])) { $the_ins = array(); $has_info = Utils::single_array($paramset['has:info']); $pi_count = 0; $pi_where = array(); foreach ($has_info as $info_name) { $pi_count++; $joins['has_info_' . $info_name] = " LEFT JOIN {postinfo} hipi{$pi_count} ON {posts}.id = hipi{$pi_count}.post_id AND hipi{$pi_count}.name = ?"; $join_params[] = $info_name; $pi_where[] = "hipi{$pi_count}.name <> ''"; $select_ary["info_{$info_name}_value"] = "hipi{$pi_count}.value AS info_{$info_name}_value"; } $where[] = '(' . implode(' OR ', $pi_where) . ')'; } if (isset($paramset['not:all:info']) || isset($paramset['not:info'])) { // merge the two possible calls together $infos = array_merge(isset($paramset['not:all:info']) ? $paramset['not:all:info'] : array(), isset($paramset['not:info']) ? $paramset['not:info'] : array()); if (Utils::is_traversable($infos)) { $the_ins = array(); foreach ($infos as $info_key => $info_value) { $the_ins[] = ' ({postinfo}.name = ? AND {postinfo}.value = ? ) '; $params[] = $info_key; $params[] = $info_value; } $where[] = ' {posts}.id NOT IN ( SELECT post_id FROM {postinfo} WHERE ( ' . implode(' OR ', $the_ins) . ' ) GROUP BY post_id HAVING COUNT(*) = ' . count($infos) . ' ) '; // see that hard-coded number? sqlite wets itself if we use a bound parameter... don't change that } } if (isset($paramset['not:any:info'])) { if (Utils::is_traversable($paramset['not:any:info'])) { foreach ($paramset['not:any:info'] as $info_key => $info_value) { $the_ins[] = ' ({postinfo}.name = ? AND {postinfo}.value = ? ) '; $params[] = $info_key; $params[] = $info_value; } $where[] = ' {posts}.id NOT IN ( SELECT post_id FROM {postinfo} WHERE ( ' . implode(' OR ', $the_ins) . ' ) ) '; } } /** * Build the statement needed to filter by pubdate: * If we've got the day, then get the date; * If we've got the month, but no date, get the month; * If we've only got the year, get the whole year. */ if (isset($paramset['day']) && isset($paramset['month']) && isset($paramset['year'])) { $where[] = 'pubdate BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], $paramset['day']); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 day')->sql; //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, $paramset['month'], $paramset['day'], $paramset['year'] ) ); //$params[] = date( 'Y-m-d H:i:s', mktime( 23, 59, 59, $paramset['month'], $paramset['day'], $paramset['year'] ) ); } elseif (isset($paramset['month']) && isset($paramset['year'])) { $where[] = 'pubdate BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 month')->sql; //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, $paramset['month'], 1, $paramset['year'] ) ); //$params[] = date( 'Y-m-d H:i:s', mktime( 23, 59, 59, $paramset['month'] + 1, 0, $paramset['year'] ) ); } elseif (isset($paramset['year'])) { $where[] = 'pubdate BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 year')->sql; //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, 1, 1, $paramset['year'] ) ); //$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, -1, 1, 1, $paramset['year'] + 1 ) ); } if (isset($paramset['after'])) { $where[] = 'pubdate > ?'; $params[] = HabariDateTime::date_create($paramset['after'])->sql; } if (isset($paramset['before'])) { $where[] = 'pubdate < ?'; $params[] = HabariDateTime::date_create($paramset['before'])->sql; } // Concatenate the WHERE clauses if (count($where) > 0) { $wheres[] = ' (' . implode(' AND ', $where) . ') '; } } } // Only show posts to which the current user has permission if (isset($paramset['ignore_permissions'])) { $master_perm_where = ''; } else { // This set of wheres will be used to generate a list of post_ids that this user can read $perm_where = array(); $perm_where_denied = array(); $params_where = array(); $where = array(); // Get the tokens that this user is granted or denied access to read $read_tokens = isset($paramset['read_tokens']) ? $paramset['read_tokens'] : ACL::user_tokens(User::identify(), 'read', true); $deny_tokens = isset($paramset['deny_tokens']) ? $paramset['deny_tokens'] : ACL::user_tokens(User::identify(), 'deny', true); // If a user can read his own posts, let him if (User::identify()->can('own_posts', 'read')) { $perm_where['own_posts_id'] = '{posts}.user_id = ?'; $params_where[] = User::identify()->id; } // If a user can read any post type, let him if (User::identify()->can('post_any', 'read')) { $perm_where = array('post_any' => '(1=1)'); $params_where = array(); } else { // If a user can read specific post types, let him $permitted_post_types = array(); foreach (Post::list_active_post_types() as $name => $posttype) { if (User::identify()->can('post_' . Utils::slugify($name), 'read')) { $permitted_post_types[] = $posttype; } } if (count($permitted_post_types) > 0) { $perm_where[] = '{posts}.content_type IN (' . implode(',', $permitted_post_types) . ')'; } // If a user can read posts with specific tokens, let him if (count($read_tokens) > 0) { $joins['post_tokens__allowed'] = ' LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN (' . implode(',', $read_tokens) . ')'; $perm_where['perms_join_null'] = 'pt_allowed.post_id IS NOT NULL'; } } // If a user is denied access to all posts, do so if (User::identify()->cannot('post_any')) { $perm_where_denied = array('(1=0)'); } else { // If a user is denied read access to specific post types, deny him $denied_post_types = array(); foreach (Post::list_active_post_types() as $name => $posttype) { if (User::identify()->cannot('post_' . Utils::slugify($name))) { $denied_post_types[] = $posttype; } } if (count($denied_post_types) > 0) { $perm_where_denied[] = '{posts}.content_type NOT IN (' . implode(',', $denied_post_types) . ')'; } } // If there are granted permissions to check, add them to the where clause if (count($perm_where) == 0 && !isset($joins['post_tokens__allowed'])) { // You have no grants. You get no posts. $where['perms_granted'] = '(1=0)'; } elseif (count($perm_where) > 0) { $where['perms_granted'] = ' (' . implode(' OR ', $perm_where) . ') '; $params = array_merge($join_params, $params, $params_where); } if (count($deny_tokens) > 0) { $joins['post_tokens__denied'] = ' LEFT JOIN {post_tokens} pt_denied ON {posts}.id= pt_denied.post_id AND pt_denied.token_id IN (' . implode(',', $deny_tokens) . ')'; $perm_where_denied['perms_join_null'] = 'pt_denied.post_id IS NULL'; } // If there are denied permissions to check, add them to the where clause if (count($perm_where_denied) > 0) { $where['perms_denied'] = ' (' . implode(' AND ', $perm_where_denied) . ') '; } $master_perm_where = implode(' AND ', $where); } // Extract the remaining parameters which will be used onwards // For example: page number, fetch function, limit $paramarray = new SuperGlobal($paramarray); $extract = $paramarray->filter_keys('page', 'fetch_fn', 'count', 'orderby', 'groupby', 'limit', 'offset', 'nolimit', 'having'); foreach ($extract as $key => $value) { ${$key} = $value; } // Define the LIMIT if it does not exist, unless specific posts are requested if (!isset($limit) && !isset($paramset['id']) && !isset($paramset['slug'])) { $limit = Options::get('pagination') ? (int) Options::get('pagination') : 5; } elseif (!isset($limit)) { $selected_posts = 0; if (isset($paramset['id'])) { $selected_posts += count(Utils::single_array($paramset['id'])); } if (isset($paramset['slug'])) { $selected_posts += count(Utils::single_array($paramset['slug'])); } $limit = $selected_posts > 0 ? $selected_posts : ''; } // Calculate the OFFSET based on the page number if (isset($page) && is_numeric($page) && !isset($paramset['offset'])) { $offset = (intval($page) - 1) * intval($limit); } /** * Determine which fetch function to use: * If it is specified, make sure it is valid (based on the $fns array defined at the beginning of this function); * Else, use 'get_results' which will return a Posts array of Post objects. */ if (isset($fetch_fn)) { if (!in_array($fetch_fn, $fns)) { $fetch_fn = $fns[0]; } } else { $fetch_fn = $fns[0]; } /** * Turn the requested fields into a comma-separated SELECT field clause */ $select = implode(', ', $select_ary); /** * If a count is requested: * Replace the current fields to select with a COUNT(); * Change the fetch function to 'get_value'; * Remove the ORDER BY since it's useless. * Remove the GROUP BY (tag search added it) */ if (isset($count)) { $select = "COUNT({$count})"; $fetch_fn = 'get_value'; $orderby = ''; $groupby = ''; $having = ''; } // If the month counts are requested, replaced the select clause if (isset($paramset['month_cts'])) { if (isset($paramset['tag']) || isset($paramset['tag_slug'])) { $select = 'MONTH(FROM_UNIXTIME(pubdate)) AS month, YEAR(FROM_UNIXTIME(pubdate)) AS year, COUNT(DISTINCT {posts}.id) AS ct'; } else { $select = 'MONTH(FROM_UNIXTIME(pubdate)) AS month, YEAR(FROM_UNIXTIME(pubdate)) AS year, COUNT(*) AS ct'; } $groupby = 'year, month'; $orderby = 'year, month'; } // Remove the LIMIT if 'nolimit' or 'month_cts' is set // Doing this first should allow OFFSET to work if (isset($nolimit) || isset($paramset['month_cts'])) { $limit = ''; } // Define the LIMIT and add the OFFSET if it exists if (!empty($limit)) { $limit = " LIMIT {$limit}"; if (isset($offset)) { $limit .= " OFFSET {$offset}"; } } else { $limit = ''; } /* All SQL parts are constructed, on to real business! */ /** * Build the final SQL statement */ $query = ' SELECT DISTINCT ' . $select . ' FROM {posts} ' . implode(' ', $joins); if (count($wheres) > 0) { $query .= ' WHERE (' . implode(" \nOR\n ", $wheres) . ')'; $query .= $master_perm_where == '' ? '' : ' AND (' . $master_perm_where . ')'; } elseif ($master_perm_where != '') { $query .= ' WHERE (' . $master_perm_where . ')'; } $query .= !isset($groupby) || $groupby == '' ? '' : ' GROUP BY ' . $groupby; $query .= !isset($having) || $having == '' ? '' : ' HAVING ' . $having; $query .= ($orderby == '' ? '' : ' ORDER BY ' . $orderby) . $limit; /** * DEBUG: Uncomment the following line to display everything that happens in this function */ //print_R('<pre>'.$query.'</pre>'); //Utils::debug( $paramarray, $fetch_fn, $query, $params ); //Session::notice($query); /** * Execute the SQL statement using the PDO extension */ DB::set_fetch_mode(PDO::FETCH_CLASS); DB::set_fetch_class('Post'); $results = DB::$fetch_fn($query, $params, 'Post'); // Utils::debug( $paramarray, $fetch_fn, $query, $params, $results ); // var_dump( $query ); /** * Return the results */ if ('get_results' != $fetch_fn) { // Since a single result was requested, return a single Post object. return $results; } elseif (is_array($results)) { // With multiple results, return a Posts array of Post objects. $c = __CLASS__; $return_value = new $c($results); $return_value->get_param_cache = $paramarray; return $return_value; } }
/** * Return the content types that this object represents * * @see IsContent * @return array An array of strings representing the content type of this object */ public function content_type() { $types = array('block.' . $this->type, 'block'); if (isset($this->title)) { array_unshift($types, 'block.' . $this->type . '.' . Utils::slugify($this->title)); } if (isset($this->_area)) { $areas = array(); foreach ($types as $type) { $areas[] = $this->_area . '.' . $type; } $types = array_merge($areas, $types); } $types = Plugins::filter('block_content_type_' . $this->type, $types, $this); $types = Plugins::filter('block_content_type', $types, $this); return $types; }