public function action_form_publish($form, $post)
 {
     $selector = $form->append('wrapper', 'type_selector');
     $selector->class = 'container';
     // Utils::debug( 'bob' );
     if (Controller::get_var('to_type') != NULL && $post->content_type != Controller::get_var('to_type')) {
         /* set type */
         $post->content_type = Post::type(Controller::get_var('to_type'));
         $post->update();
         Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
         // Refresh view
     }
     foreach (Post::list_active_post_types() as $type) {
         if ($type != 0) {
             if ($post->id == 0) {
                 $url = URL::get('admin', 'page=publish&content_type=' . Post::type_name($type));
             } else {
                 $url = URL::get('admin', 'page=publish&to_type=' . Post::type_name($type) . '&id=' . $post->id);
             }
             $html = '<a href="' . $url . '"';
             if (Post::type_name($type) == $post->content_type || $type == $post->content_type) {
                 $html .= ' class="active"';
             }
             $html .= '>' . Post::type_name($type) . '</a>';
             $selector->append('static', 'type_selector_' . $type, $html);
         }
     }
     $selector->move_before($selector, $form);
     return $form;
 }
Example #2
0
 public function filter_body_class($body_class, $theme)
 {
     if (isset($theme->posts) && count($theme->posts) === 1 && $theme->posts instanceof Post) {
         $body_class[] = Post::type_name($theme->posts->content_type) . '-' . $theme->posts->slug;
         $body_class[] = 'single';
     }
     return $body_class;
 }
Example #3
0
	/**
	 * Returns an access Bitmask for the given user on this post
	 * @param User $user The user mask to fetch
	 * @return Bitmask
	 */
	public function get_access( $user = null )
	{
		if ( ! $user instanceof User ) {
			$user = User::identify();
		}

		if ( $user->can( 'super_user' ) ) {
			return ACL::get_bitmask( 'full' );
		}

		// Collect a list of applicable tokens
		$tokens = array(
			'post_any',
			'post_' . Post::type_name( $this->content_type ),
		);

		if ( $user->id == $this->user_id ) {
			$tokens[] = 'own_posts';
		}

		$tokens = array_merge( $tokens, $this->get_tokens() );

		// collect all possible token accesses on this post
		$token_accesses = array();
		foreach ( $tokens as $token ) {
			$access = ACL::get_user_token_access( $user, $token );
			if ( $access instanceof Bitmask ) {
				$token_accesses[] = ACL::get_user_token_access( $user, $token )->value;
			}
		}

		// now that we have all the accesses, loop through them to build the access to the particular post
		if ( in_array( 0, $token_accesses ) ) {
			return ACL::get_bitmask( 0 );
		}
		return ACL::get_bitmask( Utils::array_or( $token_accesses ) );
	}
Example #4
0
 /**
  * Returns an access Bitmask for the given user on this comment. Read access is determined
  * by the associated post. Update/delete is determined by the comment management tokens.
  * @param User $user The user mask to fetch
  * @return Bitmask
  */
 public function get_access($user = null)
 {
     if (!$user instanceof User) {
         $user = User::identify();
     }
     // these tokens automatically grant full access to the comment
     if ($user->can('super_user') || $user->can('manage_all_comments') || $user->id == $this->post->user_id && $user->can('manage_own_post_comments')) {
         return ACL::get_bitmask('full');
     }
     /* If we got this far, we can't update or delete a comment. We still need to check if we have
      * read access to it. Collect a list of applicable tokens
      */
     $tokens = array('post_any', 'post_' . Post::type_name($this->post->content_type));
     if ($user->id == $this->post->user_id) {
         $tokens[] = 'own_posts';
     }
     $tokens = array_merge($tokens, $this->post->get_tokens());
     $token_accesses = array();
     // grab the access masks on these tokens
     foreach ($tokens as $token) {
         $access = ACL::get_user_token_access($user, $token);
         if ($access instanceof Bitmask) {
             $token_accesses[] = ACL::get_user_token_access($user, $token)->value;
         }
     }
     // now that we have all the accesses, loop through them to build the access to the particular post
     if (in_array(0, $token_accesses)) {
         return ACL::get_bitmask(0);
     }
     if (ACL::get_bitmask(Utils::array_or($token_accesses))->read) {
         return ACL::get_bitmask('read');
     }
     // if we haven't returned by this point, we can neither manage the comment nor read it
     return ACL::get_bitmask(0);
 }
Example #5
0
	/**
	 * Output an Atom collection of comments based on the supplied parameters.
	 *
	 * @param array $params An array of parameters passed to Comments::get() to retrieve comments
	 */
	function get_comments( $params = array() )
	{
		$comments = null;
		$comments_count = null;

		// Assign self link.
		$self = '';

		// Assign alternate link.
		$alternate = '';

		$updated = HabariDateTime::date_create();

		// Check if this is a feed for a single post
		if ( isset( $params['slug'] ) || isset( $params['id'] ) ) {
			if ( isset( $params['slug'] ) ) {
				$post = Post::get( array( 'slug' => $params['slug'] ) );
			}
			elseif ( isset( $params['id'] ) ) {
				$post = Post::get( array( 'id' => $params['id'] ) );
			}

			// If the post doesn't exist, send a 404
			if ( !$post instanceOf Post ) {
				header( 'HTTP/1.1 404 Not Found', true, 404 );
				die('The post could not be found');
			}

			$comments = $post->comments->approved;
			$comments_count = count( $comments );
			$content_type = Post::type_name( $post->content_type );
			$self = URL::get( "atom_feed_{$content_type}_comments", $post, false );
			$alternate = URL::get( "display_{$content_type}", $post, false );
			if ( $comments_count ) {
				$updated = $comments[$comments_count - 1]->date;
			}
		}
		else {
			$self = URL::get( 'atom_feed_comments' );
			$alternate = URL::get( 'display_home' );
			$params['status'] = Comment::STATUS_APPROVED;
			$comments = Comments::get( $params );
			$comments_count = Comments::count_total( Comment::status( 'approved' ) );
			if ( $comments_count ) {
				$updated = $comments[0]->date;
			}
		}

		$id = isset( $params['slug'] ) ? $params['slug'] : 'atom_comments';

		$xml = $this->create_atom_wrapper( $alternate, $self, $id, $updated );

		$xml = $this->add_pagination_links( $xml, $comments_count );

		$xml = $this->add_comments( $xml, $comments );

		Plugins::act( 'atom_get_comments', $xml, $params, $this->handler_vars );
		$xml = $xml->asXML();

		ob_clean();
		header( 'Content-Type: application/atom+xml' );
		print $xml;
	}
Example #6
0
    echo $wsse['digest'];
    ?>
">'))
			.attr('action', '<?php 
    URL::out('admin', array('page' => 'delete_post', 'id' => $post->id));
    ?>
')
			.submit();
	});
	<?php 
}
?>

	// If the post hasn't been published, add a publish button
	<?php 
$show_publish = $post->id == 0 && User::identify()->can_any(array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($post->content_type) => 'create')) || $post->id != 0 && ACL::access_check($post->get_access(), 'edit');
if (isset($statuses['published']) && $post->status != $statuses['published'] && $show_publish) {
    ?>
	$('.container.buttons').prepend($('<input type="button" id="publish" class="button publish" tabindex="5" value="<?php 
    _e('Publish');
    ?>
">'));
	$('#publish').click( function() {
		// alert("asdasd");
		$('#status').val(<?php 
    echo $statuses['published'];
    ?>
);
	});
	<?php 
}
Example #7
0
 /**
  * Checks if the currently logged in user has access to a page and post type.
  */
 private function access_allowed($page, $type)
 {
     $user = User::identify();
     $require_any = array();
     $result = false;
     switch ($page) {
         case 'comment':
         case 'comments':
         case 'ajax_comments':
         case 'ajax_in_edit':
         case 'ajax_update_comment':
             $require_any = array('manage_all_comments' => true, 'manage_own_post_comments' => true);
             break;
         case 'tags':
         case 'ajax_tags':
             $require_any = array('manage_tags' => true);
             break;
         case 'options':
             $require_any = array('manage_options' => true);
             break;
         case 'themes':
             $require_any = array('manage_themes' => true, 'manage_theme_config' => true);
             break;
         case 'activate_theme':
             $require_any = array('manage_themes' => true);
             break;
         case 'preview_theme':
             $require_any = array('manage_themes' => true);
             break;
         case 'plugins':
             $require_any = array('manage_plugins' => true, 'manage_plugins_config' => true);
             break;
         case 'plugin_toggle':
             $require_any = array('manage_plugins' => true);
             break;
         case 'import':
             $require_any = array('manage_import' => true);
             break;
         case 'users':
         case 'ajax_update_users':
         case 'ajax_users':
             $require_any = array('manage_users' => true);
             break;
         case 'user':
             $require_any = array('manage_users' => true, 'manage_self' => true);
             break;
         case 'groups':
         case 'group':
         case 'ajax_update_groups':
         case 'ajax_groups':
             $require_any = array('manage_groups' => true);
             break;
         case 'logs':
         case 'ajax_delete_logs':
         case 'ajax_logs':
             $require_any = array('manage_logs' => true);
             break;
         case 'publish':
         case 'ajax_media':
         case 'ajax_media_panel':
             $type = Post::type_name($type);
             $require_any = array('post_any' => array(ACL::get_bitmask('create'), ACL::get_bitmask('edit')), 'post_' . $type => array(ACL::get_bitmask('create'), ACL::get_bitmask('edit')), 'own_posts' => array(ACL::get_bitmask('create'), ACL::get_bitmask('edit')));
             break;
         case 'delete_post':
             $type = Post::type_name($type);
             $require_any = array('post_any' => ACL::get_bitmask('delete'), 'post_' . $type => ACL::get_bitmask('delete'), 'own_posts' => ACL::get_bitmask('delete'));
             break;
         case 'posts':
         case 'ajax_posts':
         case 'ajax_delete_entries':
         case 'ajax_update_entries':
             $require_any = array('post_any' => array(ACL::get_bitmask('delete'), ACL::get_bitmask('edit')), 'own_posts' => array(ACL::get_bitmask('delete'), ACL::get_bitmask('edit')));
             foreach (Post::list_active_post_types() as $type => $type_id) {
                 $require_any['post_' . $type] = array(ACL::get_bitmask('delete'), ACL::get_bitmask('edit'));
             }
             break;
         case 'sysinfo':
             $require_any = array('super_user' => true);
             break;
         case 'dashboard':
         case 'ajax_dashboard':
             $result = true;
             break;
         case 'ajax_add_block':
             $result = true;
             break;
         case 'ajax_delete_block':
             $result = true;
             break;
         case 'configure_block':
             $result = true;
             break;
         case 'ajax_save_areas':
             $result = true;
             break;
         default:
             break;
     }
     $require_any = Plugins::filter('admin_access_tokens', $require_any, $page, $type);
     foreach ($require_any as $token => $access) {
         $access = Utils::single_array($access);
         foreach ($access as $mask) {
             if (is_bool($mask) && $user->can($token)) {
                 $result = true;
                 break;
             } elseif ($user->can($token, $mask)) {
                 $result = true;
                 break 2;
             }
         }
     }
     $result = Plugins::filter('admin_access', $result, $page, $type);
     return $result;
 }
Example #8
0
 /**
  * Grabs post data and inserts that data into the internal
  * handler_vars array, which eventually gets extracted into
  * the theme's ( and thereby the template_engine's ) local
  * symbol table for use in the theme's templates
  *
  * This is the default, generic function to grab posts.  To
  * "filter" the posts retrieved, simply pass any filters to
  * the handler_vars variables associated with the post retrieval.
  * For instance, to filter by tag, ensure that handler_vars['tag']
  * contains the tag to filter by.  Simple as that.
  */
 public function act_display($paramarray = array('user_filters' => array()))
 {
     Utils::check_request_method(array('GET', 'HEAD', 'POST'));
     // Get any full-query parameters
     $possible = array('user_filters', 'fallback', 'posts', 'post', 'content_type');
     foreach ($possible as $varname) {
         if (isset($paramarray[$varname])) {
             ${$varname} = $paramarray[$varname];
         }
     }
     /**
      * Since handler_vars no longer contains $_GET and $_POST, we have broken out our valid filters into
      * an array based upon where we should expect them to be. We then only merge those specific pieces together.
      *
      * These are ordered so that handler vars gets overwritten by POST, which gets overwritten by GET, should the
      * same key exist multiple places. This seemed logical to me at the time, but needs further thought.
      */
     $where_filters = array();
     $where_filters_hv = Controller::get_handler_vars()->filter_keys($this->valid_filters['handler_vars']);
     $where_filters_post = $_POST->filter_keys($this->valid_filters['POST']);
     $where_filters_get = $_GET->filter_keys($this->valid_filters['GET']);
     $where_filters = $where_filters_hv->merge($where_filters_post, $where_filters_get);
     $where_filters['vocabulary'] = array();
     if (array_key_exists('tag', $where_filters)) {
         $tags = Tags::parse_url_tags($where_filters['tag']);
         $not_tag = $tags['exclude_tag'];
         $all_tag = $tags['include_tag'];
         if (count($not_tag) > 0) {
             $where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':not:term' => $not_tag));
         }
         if (count($all_tag) > 0) {
             $where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':all:term' => $all_tag));
         }
         $where_filters['tag_slug'] = Utils::slugify($where_filters['tag']);
         unset($where_filters['tag']);
     }
     if (!isset($_GET['preview'])) {
         $where_filters['status'] = Post::status('published');
     }
     if (!isset($posts)) {
         $user_filters = Plugins::filter('template_user_filters', $user_filters);
         // Work around the tags parameters to Posts::get() being subsumed by the vocabulary parameter
         if (isset($user_filters['not:tag'])) {
             $user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':not:term' => $user_filters['not:tag']);
             unset($user_filters['not:tag']);
         }
         if (isset($user_filters['tag'])) {
             $user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':term_display' => $user_filters['tag']);
             unset($user_filters['tag']);
         }
         $where_filters = $where_filters->merge($user_filters);
         $where_filters = Plugins::filter('template_where_filters', $where_filters);
         $posts = Posts::get($where_filters);
     }
     $this->assign('posts', $posts);
     if ($posts !== false && count($posts) > 0) {
         if (count($posts) == 1) {
             $post = $posts instanceof Post ? $posts : reset($posts);
             Stack::add('body_class', Post::type_name($post->content_type) . '-' . $post->id);
             Stack::add('body_class', 'single');
         } else {
             $post = reset($posts);
             Stack::add('body_class', 'multiple');
         }
         $this->assign('post', $post);
         $type = Post::type_name($post->content_type);
     } elseif ($posts === false || isset($where_filters['page']) && $where_filters['page'] > 1 && count($posts) == 0) {
         if ($this->template_exists('404')) {
             $fallback = array('404');
             // Replace template variables with the 404 rewrite rule
             $this->request->{URL::get_matched_rule()->name} = false;
             $this->request->{URL::set_404()->name} = true;
             $this->matched_rule = URL::get_matched_rule();
             // 404 status header sent in act_display_404, but we're past
             // that, so send it now.
             header('HTTP/1.1 404 Not Found', true, 404);
         } else {
             $this->display('header');
             echo '<h2>';
             _e("Whoops! 404. The page you were trying to access is not really there. Please try again.");
             echo '</h2>';
             header('HTTP/1.1 404 Not Found', true, 404);
             $this->display('footer');
             die;
         }
     }
     $extract = $where_filters->filter_keys('page', 'type', 'id', 'slug', 'posttag', 'year', 'month', 'day', 'tag', 'tag_slug');
     foreach ($extract as $key => $value) {
         ${$key} = $value;
     }
     $this->assign('page', isset($page) ? $page : 1);
     if (!isset($fallback)) {
         // Default fallbacks based on the number of posts
         $fallback = array('{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}');
         if (count($posts) > 1) {
             $fallback[] = '{$type}.multiple';
             $fallback[] = 'multiple';
         } else {
             $fallback[] = '{$type}.single';
             $fallback[] = 'single';
         }
     }
     $searches = array('{$id}', '{$slug}', '{$year}', '{$month}', '{$day}', '{$type}', '{$tag}');
     $replacements = array(isset($post) && $post instanceof Post ? $post->id : '-', isset($post) && $post instanceof Post ? $post->slug : '-', isset($year) ? $year : '-', isset($month) ? $month : '-', isset($day) ? $day : '-', isset($type) ? $type : '-', isset($tag_slug) ? $tag_slug : '-');
     $fallback[] = 'home';
     $fallback = Plugins::filter('template_fallback', $fallback, $posts, isset($post) ? $post : null);
     $fallback = array_values(array_unique(MultiByte::str_replace($searches, $replacements, $fallback)));
     for ($z = 0; $z < count($fallback); $z++) {
         if (MultiByte::strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) {
             $replacements = array();
             if ($alltags = $post->tags) {
                 foreach ($alltags as $current_tag) {
                     $replacements[] = MultiByte::str_replace('{$posttag}', $current_tag->term, $fallback[$z]);
                 }
                 array_splice($fallback, $z, 1, $replacements);
             } else {
                 break;
             }
         }
     }
     return $this->display_fallback($fallback);
 }
Example #9
0
<?php

include 'header.php';
?>
		<div id="content" role="main">
			<div id="posts" class="hfeed">
				<article id="<?php 
echo Post::type_name($post->content_type);
?>
-<?php 
echo $post->slug;
?>
" class="<?php 
echo $post->css_class();
?>
">
					<header>
						<h1 class="entry-title"><a href="<?php 
echo $post->permalink;
?>
" rel="bookmark"><?php 
echo $post->title_out;
?>
</a></h1>
					</header>
					<section class="entry-content">
						<?php 
echo $post->content_out;
?>
					</section>
					<footer>
Example #10
0
 public function theme_body_class($theme)
 {
     // Assigning <body> class(es)
     $body_class = array();
     if ($this->request->display_home) {
         $body_class[] = 'home';
         $body_class[] = 'multiple';
     } else {
         if ($this->request->display_entries) {
             $body_class[] = 'multiple';
         } else {
             if ($this->request->display_entries_by_date) {
                 $body_class[] = 'date-archive';
                 $body_class[] = 'archive';
                 $body_class[] = 'multiple';
             } else {
                 if ($this->request->display_entries_by_tag) {
                     $body_class[] = 'tag-archive';
                     $body_class[] = 'archive';
                     $body_class[] = 'multiple';
                 } else {
                     if ($this->request->display_entry) {
                         $body_class[] = 'entry-' . $this->posts->slug;
                         $body_class[] = 'entry';
                         $body_class[] = 'single';
                     } else {
                         if ($this->request->display_page) {
                             $body_class[] = 'page-' . $this->posts->slug;
                             $body_class[] = 'page';
                             $body_class[] = 'single';
                         } else {
                             if ($this->request->display_post) {
                                 // Other content-types
                                 $post_type_name = Post::type_name($this->posts->content_type);
                                 $body_class[] = $post_type_name . '-' . $this->posts->slug;
                                 $body_class[] = $post_type_name;
                                 $body_class[] = 'single';
                             } else {
                                 if ($this->request->display_search) {
                                     $body_class[] = 'search';
                                     $body_class[] = 'multiple';
                                 } else {
                                     if ($this->request->display_404) {
                                         $body_class[] = 'four04';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     //Get unique items
     $body_class = array_flip(array_flip($body_class));
     return count($body_class) > 0 ? ' class="' . implode(' ', $body_class) . '"' : '';
 }
Example #11
0
 /**
  * Returns the permalink for this post's comments RSS feed
  * @return string The permalink of this post's comments RSS feed
  **/
 public function filter_post_comment_feed_rss_link($out, $post)
 {
     $content_type = Post::type_name($post->content_type);
     return URL::get(array("rss_feed_{$content_type}_comments"), $post, false);
 }
 /**
  * Altered copy of AdminHandler::post_publish():
  * - Throws exceptions rather than Session notices so we can return errors to AJAX calls;
  * - Does not redirect but echo a JSON object with the post's ID and slug
  *
  * @see AdminHandler::post_publish()
  *
  * @param AjaxHandler $that The AjaxHandler instance
  */
 public function action_auth_ajax_autosave($handler)
 {
     // @todo until ACL checks forr this are added, make inoperable
     return null;
     $response = array();
     try {
         $post_id = 0;
         if (isset($handler->handler_vars['id'])) {
             $post_id = intval($handler->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'));
             $form = $post->get_form('ajax');
             $post->title = $form->title->value;
             if ($form->newslug->value == '') {
                 Session::notice(_t('A post slug cannot be empty. Keeping old slug.'));
             } elseif ($form->newslug->value != $form->slug->value) {
                 $post->slug = $form->newslug->value;
             }
             $post->tags = $form->tags->value;
             $post->content = $form->content->value;
             $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
             // if the post pubdate is <= the current date/time.
             if ($post->status != Post::status('published') && $form->status->value == Post::status('published') && HabariDateTime::date_create($form->pubdate->value)->int <= HabariDateTime::date_create()->int) {
                 $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();
             $form = $post->get_form('ajax');
             $form->set_option('form_action', URL::get('admin', 'page=publish'));
             $postdata = array('slug' => $form->newslug->value, 'title' => $form->title->value, 'tags' => $form->tags->value, 'content' => $form->content->value, 'user_id' => User::identify()->id, 'pubdate' => HabariDateTime::date_create($form->pubdate->value), 'status' => $form->status->value, 'content_type' => $form->content_type->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, htmlspecialchars($post->title)), Post::status_name($post->status)));
         if ($post->slug != Utils::slugify($post->title)) {
             Session::notice(sprintf(_t('The content address is \'%1$s\'.'), $post->slug));
         }
         $response['post_id'] = $post->id;
         $response['post_slug'] = $post->slug;
         $response['messages'] = Session::messages_get(true, 'array');
         ob_end_clean();
         echo json_encode($response);
         // Prevent rest of adminhandler to run, we only wanted to save!
         exit;
     } catch (Exception $e) {
         $response['error'] = $e->getMessage();
         ob_end_clean();
         echo json_encode($response);
         // Prevent rest of adminhandler to run, we only wanted to save!
         exit;
     }
 }
Example #13
0
 /**
  * Assign values needed to display the posts page to the theme based on handlervars and parameters
  *
  */
 private function fetch_posts($params = array())
 {
     // Make certain handler_vars local with defaults, and add them to the theme output
     $locals = array('do_update' => false, 'post_ids' => null, 'nonce' => '', 'timestamp' => '', 'password_digest' => '', 'change' => '', 'user_id' => 0, 'type' => Post::type('any'), 'status' => Post::status('any'), 'limit' => 20, 'offset' => 0, 'search' => '');
     foreach ($locals as $varname => $default) {
         ${$varname} = isset($this->handler_vars[$varname]) ? $this->handler_vars[$varname] : (isset($params[$varname]) ? $params[$varname] : $default);
         $this->theme->{$varname} = ${$varname};
     }
     // numbers submitted by HTTP forms are seen as strings
     // but we want the integer value for use in Posts::get,
     // so cast these two values to (int)
     if (isset($this->handler_vars['type'])) {
         $type = (int) $this->handler_vars['type'];
     }
     if (isset($this->handler_vars['status'])) {
         $status = (int) $this->handler_vars['status'];
     }
     // if we're updating posts, let's do so:
     if ($do_update && isset($post_ids)) {
         $okay = true;
         if (empty($nonce) || empty($timestamp) || empty($password_digest)) {
             $okay = false;
         }
         $wsse = Utils::WSSE($nonce, $timestamp);
         if ($password_digest != $wsse['digest']) {
             $okay = false;
         }
         if ($okay) {
             foreach ($post_ids as $id) {
                 $ids[] = array('id' => $id);
             }
             $to_update = Posts::get(array('where' => $ids, 'nolimit' => 1));
             foreach ($to_update as $post) {
                 switch ($change) {
                     case 'delete':
                         if (ACL::access_check($post->get_access(), 'delete')) {
                             $post->delete();
                         }
                         break;
                     case 'publish':
                         if (ACL::access_check($post->get_access(), 'edit')) {
                             $post->publish();
                         }
                         break;
                     case 'unpublish':
                         if (ACL::access_check($post->get_access(), 'edit')) {
                             $post->status = Post::status('draft');
                             $post->update();
                         }
                         break;
                 }
             }
             unset($this->handler_vars['change']);
         }
     }
     // we load the WSSE tokens
     // for use in the delete button
     $this->theme->wsse = Utils::WSSE();
     $arguments = array('content_type' => $type, 'status' => $status, 'limit' => $limit, 'offset' => $offset, 'user_id' => $user_id);
     if ('' != $search) {
         $arguments = array_merge($arguments, Posts::search_to_get($search));
     }
     $this->theme->posts = Posts::get($arguments);
     // setup keyword in search field if a status or type was passed in POST
     $this->theme->search_args = '';
     if ($status != Post::status('any')) {
         $this->theme->search_args = 'status:' . Post::status_name($status) . ' ';
     }
     if ($type != Post::type('any')) {
         $this->theme->search_args .= 'type:' . Post::type_name($type) . ' ';
     }
     if ($user_id != 0) {
         $this->theme->search_args .= 'author:' . User::get_by_id($user_id)->username . ' ';
     }
     if ($search != '') {
         $this->theme->search_args .= $search;
     }
     $monthcts = Posts::get(array_merge($arguments, array('month_cts' => true, 'nolimit' => true)));
     $years = array();
     foreach ($monthcts as $month) {
         if (isset($years[$month->year])) {
             $years[$month->year][] = $month;
         } else {
             $years[$month->year] = array($month);
         }
     }
     $this->theme->years = $years;
 }
Example #14
0
 /**
  * Grabs post data and inserts that data into the internal
  * handler_vars array, which eventually gets extracted into
  * the theme's ( and thereby the template_engine's ) local
  * symbol table for use in the theme's templates
  *
  * This is the default, generic function to grab posts.  To
  * "filter" the posts retrieved, simply pass any filters to
  * the handler_vars variables associated with the post retrieval.
  * For instance, to filter by tag, ensure that handler_vars['tag']
  * contains the tag to filter by.  Simple as that.
  */
 public function act_display($paramarray = array('user_filters' => array()))
 {
     Utils::check_request_method(array('GET', 'HEAD', 'POST'));
     // Get any full-query parameters
     $possible = array('user_filters', 'fallback', 'posts', 'post', 'content_type');
     foreach ($possible as $varname) {
         if (isset($paramarray[$varname])) {
             ${$varname} = $paramarray[$varname];
         }
     }
     $where_filters = array();
     $where_filters = Controller::get_handler()->handler_vars->filter_keys($this->valid_filters);
     //$where_filters['status'] = Post::status( 'published' );
     if (array_key_exists('tag', $where_filters)) {
         $tags = explode(' ', $where_filters['tag']);
         $not_tag = array();
         $all_tag = array();
         foreach ($tags as $tag) {
             if ($tag[0] == '-') {
                 $tag = substr($tag, 1);
                 $not_tag[] = Utils::slugify($tag);
             } else {
                 $all_tag[] = Utils::slugify($tag);
             }
         }
         if (count($not_tag) > 0) {
             $where_filters['not:tag_slug'] = $not_tag;
         }
         if (count($all_tag) > 0) {
             $where_filters['all:tag_slug'] = $all_tag;
         }
         unset($where_filters['tag']);
     }
     if (User::identify()->loggedin) {
         $where_filters['status'] = isset($_GET['preview']) ? Post::status('any') : Post::status('published');
     } else {
         $where_filters['status'] = Post::status('published');
     }
     if (!isset($posts)) {
         $user_filters = Plugins::filter('template_user_filters', $user_filters);
         $user_filters = array_intersect_key($user_filters, array_flip($this->valid_filters));
         $where_filters = $where_filters->merge($user_filters);
         $where_filters = Plugins::filter('template_where_filters', $where_filters);
         $posts = Posts::get($where_filters);
     }
     $this->assign('posts', $posts);
     /*
     		   if( !isset( $this->page ) ) {
     		   if( isset( $page ) ) {
     		   $this->assign( 'page', $page );
     		   }
     		   elseif( isset( Controller::get_handler()->handler_vars['page'] ) ) {
     		   $this->assign( 'page', Controller::get_handler()->handler_vars['page'] );
     		   }
     		   }*/
     if ($posts !== false && count($posts) > 0) {
         if (count($posts) == 1) {
             $post = $posts;
             Stack::add('body_class', Post::type_name($post->content_type) . '-' . $post->id);
         } else {
             $post = reset($posts);
             Stack::add('body_class', 'multiple');
         }
         $this->assign('post', $post);
         $type = Post::type_name($post->content_type);
     } elseif ($posts === false || isset($where_filters['page']) && $where_filters['page'] > 1 && count($posts) == 0) {
         if ($this->template_exists('404')) {
             $fallback = array('404');
             // Replace template variables with the 404 rewrite rule
             $this->request->{URL::get_matched_rule()->name} = false;
             $this->request->{URL::set_404()->name} = true;
             $this->matched_rule = URL::get_matched_rule();
             // 404 status header sent in act_display_404, but we're past
             // that, so send it now.
             header('HTTP/1.1 404 Not Found', true, 404);
         } else {
             $this->display('header');
             echo '<h2>';
             _e("Whoops! 404. The page you were trying to access is not really there. Please try again.");
             echo '</h2>';
             header('HTTP/1.1 404 Not Found', true, 404);
             $this->display('footer');
             die;
         }
     }
     $extract = $where_filters->filter_keys('page', 'type', 'id', 'slug', 'posttag', 'year', 'month', 'day', 'tag', 'tag_slug');
     foreach ($extract as $key => $value) {
         ${$key} = $value;
     }
     $this->assign('page', isset($page) ? $page : 1);
     if (!isset($fallback)) {
         // Default fallbacks based on the number of posts
         $fallback = array('{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}');
         if (count($posts) > 1) {
             $fallback[] = '{$type}.multiple';
             $fallback[] = 'multiple';
         } else {
             $fallback[] = '{$type}.single';
             $fallback[] = 'single';
         }
     }
     $searches = array('{$id}', '{$slug}', '{$year}', '{$month}', '{$day}', '{$type}', '{$tag}');
     $replacements = array(isset($post) && $post instanceof Post ? $post->id : '-', isset($post) && $post instanceof Post ? $post->slug : '-', isset($year) ? $year : '-', isset($month) ? $month : '-', isset($day) ? $day : '-', isset($type) ? $type : '-', isset($tag_slug) ? $tag_slug : '-');
     $fallback[] = 'home';
     $fallback = Plugins::filter('template_fallback', $fallback);
     $fallback = array_values(array_unique(str_replace($searches, $replacements, $fallback)));
     for ($z = 0; $z < count($fallback); $z++) {
         if (strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) {
             $replacements = array();
             if ($alltags = $post->tags) {
                 foreach ($alltags as $tag_slug => $tag_text) {
                     $replacements[] = str_replace('{$posttag}', $tag_slug, $fallback[$z]);
                 }
                 array_splice($fallback, $z, 1, $replacements);
             } else {
                 break;
             }
         }
     }
     return $this->display_fallback($fallback);
 }
 /**
  * Display a custom publish page for handled content types
  *
  * @param AdminHandler $handler The admin handler object
  * @param Theme $theme The admin theme object
  */
 function action_admin_theme_get_publish($handler, $theme)
 {
     $handled = Options::get('cctypes_types');
     if (isset($handler->handler_vars['id'])) {
         $post = Post::get(array('id' => $handler->handler_vars['id'], 'status' => Post::status('any')));
         $ctype = Post::type_name($post->content_type);
     } else {
         if (isset($handler->handler_vars['content_type'])) {
             $ctype = $handler->handler_vars['content_type'];
         }
     }
     if (isset($ctype) && in_array($ctype, $handled)) {
         $template_name = 'admin_publish_' . $ctype;
         if ($theme->template_exists($template_name)) {
             $theme->display($template_name);
             exit;
         }
     }
 }
Example #16
0
 /**
  * Handles POST values from /manage/posts.
  * Used to control what content to show / manage.
  */
 public function post_posts()
 {
     // Simply pass $_GET to the function, it's save as only values we understand will be read
     $this->fetch_posts($_GET);
     // Check which values have been passed and translate them for the faceted seach
     $search_values = array();
     foreach ($this->locals as $varname => $default) {
         if (isset($_GET[$varname])) {
             switch ($varname) {
                 case 'type':
                     $search_values[] = 'type: ' . Post::type_name($_GET['type']);
                     break;
                 case 'status':
                     $search_values[] = 'status: ' . Post::status_name($_GET['status']);
                     break;
                 case 'tag':
                     $tags = explode(',', $_GET['tag']);
                     foreach ($tags as $tag) {
                         $search_values[] = 'tag: ' . $tag;
                     }
                     break;
                 case 'author':
                     $search_values[] = 'author: ' . User::get($_GET['author'])->username;
                     break;
                 default:
                     $search_values[] = $varname . ': ' . $_GET[$varname];
             }
         }
     }
     if (count($search_values) > 0) {
         $search_value = implode(' ', $search_values);
     } else {
         $search_value = '';
     }
     // Create search controls and global buttons for the manage page
     $search = FormControlFacet::create('search');
     $search->set_value($search_value)->set_property('data-facet-config', array('onsearch' => '$(".posts").manager("update", self.data("visualsearch").searchQuery.facets());', 'facetsURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'manage', 'component' => 'facets')), 'valuesURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'manage', 'component' => 'values'))));
     $navigation = FormControlStatic::create('navigation')->set_static('<a href="" id="nav_prev" class="navigation">' . _t('Previous page') . '</a>' . '<a href="" id="nav_next" class="navigation">' . _t('Next page') . '</a>');
     $aggregate = FormControlAggregate::create('selected_items')->set_selector('.post_item')->label('None Selected');
     $page_actions = FormControlDropbutton::create('page_actions');
     $page_actions->append(FormControlSubmit::create('delete')->set_caption(_t('Delete Selected'))->set_properties(array('onclick' => 'itemManage.update(\'delete\');return false;', 'title' => _t('Delete Selected'))));
     Plugins::act('posts_manage_actions', $page_actions);
     $form = new FormUI('manage');
     $form->append($search);
     $form->append($navigation);
     $form->append($aggregate);
     $form->append($page_actions);
     $this->theme->form = $form;
     $this->theme->admin_page = _t('Manage Posts');
     $this->theme->admin_title = _t('Manage Posts');
     Stack::add('admin_header_javascript', 'visualsearch');
     Stack::add('admin_header_javascript', 'manage-js');
     Stack::add('admin_stylesheet', 'visualsearch-css');
     Stack::add('admin_stylesheet', 'visualsearch-datauri-css');
     $this->display('posts');
 }