Example #1
0
 private function _viewBlogArticle(BlogModel $blog, BlogArticleModel $article)
 {
     $view = $this->getView();
     /** @var $page PageModel */
     $page = $article->getLink('Page');
     //$articles = $blog->getLink('BlogArticle');
     $manager = \Core\user()->checkAccess('p:/blog/manage_all');
     $editor = \Core\user()->checkAccess($blog->get('manage_articles_permission ')) || $manager;
     $author = UserModel::Construct($article->get('authorid'));
     //$authorid = $author->get('id');
     //var_dump($page->getMeta('keywords')); die();
     if (!$article->isPublished()) {
         // Is it actually not published, or just marked for a future publish date?
         if ($article->get('status') == 'published') {
             $publishdate = new CoreDateTime($article->get('published'));
             Core::SetMessage('Article is set to be published on ' . $publishdate->getFormatted('F jS, Y \\a\\t h:ia'), 'info');
         } else {
             Core::SetMessage('Article not published yet!', 'info');
         }
     }
     //$view->templatename = $page->get('page_template') ? $page->get('page_template') : 'pages/blog/article_view.tpl';
     $view->templatename = 'pages/blog/article_view.tpl';
     //$view->addBreadcrumb($blog->get('title'), $blog->get('rewriteurl'));
     $view->title = $article->get('title');
     $view->meta['title'] = $article->get('title');
     $view->updated = $article->get('updated');
     $view->canonicalurl = \Core\resolve_link($article->get('rewriteurl'));
     $view->meta['og:type'] = 'article';
     if ($article->get('image')) {
         $image = \Core\Filestore\Factory::File($article->get('image'));
         $view->meta['og:image'] = $image->getPreviewURL('200x200');
     }
     //if($author){
     //	/** @var $author User */
     //	//$view->meta['author'] = $author->getDisplayName();
     //	$view->meta['author'] = $author;
     //}
     $view->meta['description'] = $article->getTeaser();
     $view->assign('author', $author->exists() ? $author : null);
     $view->assign('article', $article);
     $view->assign('body', \Core\parse_html($article->get('body')));
     if ($editor) {
         $view->addControl('Edit Article', '/blog/article/update/' . $article->get('id'), 'edit');
         if ($article->get('status') == 'draft') {
             $view->addControl(['title' => 'Publish Article', 'link' => '/blog/article/publish/' . $blog->get('id') . '/' . $article->get('id'), 'icon' => 'arrow-up', 'confirm' => 'Publish article?']);
         }
         $view->addControl(array('title' => 'Delete Article', 'link' => '/blog/article/delete/' . $article->get('id'), 'icon' => 'remove', 'confirm' => 'Remove blog article?'));
     }
     // Add the extra view types for this page
     $view->addHead('<link rel="alternate" type="application/atom+xml" title="' . $page->get('title') . ' Atom Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.atom"/>');
     $view->addHead('<link rel="alternate" type="application/rss+xml" title="' . $page->get('title') . ' RSS Feed" href="' . \Core\resolve_link($blog->get('baseurl')) . '.rss"/>');
     $view->addControl('RSS Feed', \Core\resolve_link($blog->get('baseurl')) . '.rss', 'rss');
 }
Example #2
0
 /**
  * Widget to display a simple site search box
  */
 public function execute()
 {
     $view = $this->getView();
     $view->assign('title', $this->getSetting('title'));
     $view->assign('content', \Core\parse_html($this->getSetting('content')));
 }
/**
 * Primary method for a block of user-customizable content inside a template.
 *
 * Insertables are the core method of injecting blocks of user-customizable content into a template.
 *
 * An insertable must be on a template that has a registered page URL, as the baseurl is what is tracked as one of the main primary keys.
 * The other PK is the insertable's name, which must be unique on that one template.
 *
 * #### Smarty Parameters
 *
 *  * name
 *    * The key name of this input value, must be present and unique on this template.
 *  * assign
 *    * Assign the value instead of outputting to the screen.
 *  * title
 *    * When editing the insertable, the title displayed along side the input field.
 *  * type
 *
 * #### Example Usage
 *
 * <pre>
 * {insertable name="body" title="Body Content"}
 * <p>
 * This is some example content!
 * </p>
 * {/insertable}
 * </pre>
 *
 * <pre>
 * {insertable name="img1" title="Large Image" assign="img1"}
 * {img src="`$img1`" placeholder="generic" dimensions="800x400"}
 * {/insertable}
 * </pre>
 *
 * @param array       $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param string|null $content Null on opening pass, rendered source of the contents inside the block on closing pass
 * @param Smarty      $smarty  Parent Smarty template object
 * @param boolean     $repeat  True at the first call of the block-function (the opening tag) and
 * false on all subsequent calls to the block function (the block's closing tag).
 * Each time the function implementation returns with $repeat being TRUE,
 * the contents between {func}...{/func} are evaluated and the function implementation
 * is called again with the new block contents in the parameter $content.
 *
 * @return string
 */
function smarty_block_insertable($params, $content, $smarty, &$repeat){

	$assign = (isset($params['assign']))? $params['assign'] : false;

	// This only needs to be called once.
	// If a value is being assigned, then it's on the first pass so the value will be assigned by the time the content is hit.
	if($assign){
		if($repeat){
			// Running the first time with an assign variable, OK!
		}
		else{
			return $content;
		}
	}
	else{
		// No assign requested, run on the second only.
		if($repeat){
			return '';
		}
		else{
			// Continue!
		}
	}

	$page = PageRequest::GetSystemRequest()->getPageModel();

	// I need to use the parent to lookup the current base url.
	$baseurl = PageRequest::GetSystemRequest()->getBaseURL();

	if(!isset($params['name'])) return '';

	$i = InsertableModel::Construct($page->get('site'), $baseurl, $params['name']);

	if($i->exists()){
		$value = $i->get('value');
	}
	else{
		$value = $content;
	}

	if(isset($params['type']) && $params['type'] == 'markdown'){
		// Convert this markdown code to HTML via the built-in Michielf library.
		$value = Core\MarkdownProcessor::defaultTransform($value);
		//$value = Michelf\MarkdownExtra::defaultTransform($value);
	}
	else{
		// Coreify the string
		$value = \Core\parse_html($value);
	}

	if($assign){
		$smarty->assign($assign, $value);
	}
	else{
		return $value;
	}
}