Skip to content

Commit

Permalink
Add post summary field rather than trimming full content
Browse files Browse the repository at this point in the history
  • Loading branch information
rbertram90 committed Nov 17, 2018
1 parent c94a190 commit cb243c2
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 26 deletions.
16 changes: 10 additions & 6 deletions app/envsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,27 @@

spl_autoload_register(function ($class) {
$split = explode('\\', $class);
if (count($split) < 5) error_log('Unable to load class '. $class);
if (count($split) < 4) error_log('Unable to load class '. $class);
$type = strtolower($split[3]);
include SERVER_MODULES_PATH ."/{$split[2]}/src/{$type}/{$split[4]}.php";
if ($type == 'controller' || $type == 'model') {
include SERVER_MODULES_PATH ."/{$split[2]}/src/{$type}/{$split[4]}.php";
}
else {
include SERVER_MODULES_PATH ."/{$split[2]}/src/{$split[3]}.php";
}
});

// Include core classes
require_once SERVER_ROOT .'/app/response.php';
require_once SERVER_ROOT .'/app/menu.php';
require_once SERVER_ROOT .'/app/menulink.php';
require_once SERVER_ROOT .'/app/module.php';
require_once SERVER_ROOT .'/app/cms.php';
require_once SERVER_ROOT .'/app/abstractcontroller.php';

// Smarty
require_once SERVER_ROOT .'/app/vendor/smarty/smarty/libs/Smarty.class.php';

// Generic controller class
require_once SERVER_ROOT .'/app/abstractcontroller.php';


// Import view functions
require_once SERVER_ROOT .'/app/view/page_header.php';

Expand Down
3 changes: 3 additions & 0 deletions app/modules/BlogPosts/src/controller/PostsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function create()
$newPost = [
'title' => $this->request->getString('title'),
'content' => $this->request->get('content'),
'summary' => $this->request->getString('summary'),
'tags' => $this->request->getString('tags'),
'teaser_image' => $this->request->getString('teaserimage'),
'blog_id' => $this->blog['id'],
Expand Down Expand Up @@ -143,6 +144,7 @@ public function edit()
'id' => $postID,
'type' => $post['type'],
'title' => $this->request->getString('title'),
'summary' => $this->request->getString('summary'),
'content' => $this->request->get('content'),
'tags' => $this->request->getString('tags'),
'teaser_image' => $this->request->getString('teaserImage'),
Expand Down Expand Up @@ -221,6 +223,7 @@ public function autosave()

$data = [
'title' => $this->request->getString('title'),
'summary' => $this->request->getString('summary'),
'content' => $this->request->getString('content'),
'tags' => $this->request->getString('tags'),
'allowcomments' => $this->request->getInt('allowcomments'),
Expand Down
1 change: 1 addition & 0 deletions app/modules/BlogPosts/src/model/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function __construct($modelManager)
$this->fields = [
'id' => 'number',
'title' => 'string',
'summary' => 'memo',
'content' => 'memo',
'blog_id' => 'number',
'link' => 'string',
Expand Down
1 change: 1 addition & 0 deletions app/modules/BlogPosts/src/templates/edit-form/actions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
blogID: {$blog.id},
postID: parseInt($("#post_id").val()),
title: $("#post_title").val(),
summary: $("#summary").val(),
content: $("#post_content").val(),
tags: $("#post_tags").val(),
date: $("#post_date").val(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="field">
<label for="summary">Summary <a href="javascript:alert('This is the excerpt from your body content to show on the front page.');" title="Help">[?]</a></label>
<textarea name="summary" id="summary">{if $post}{$post['summary']}{/if}</textarea>
</div>
14 changes: 10 additions & 4 deletions app/modules/LayoutPost/LayoutPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ public function onViewEditPost($args) {
public function runTemplate($args)
{
$post = $args['post'];

if ($args['template'] == 'postTeaser' && $post['type'] == 'layout') {
$layout = JSONHelper::JSONtoArray($post['content']);
$args['post']['trimmedContent'] = $this->generateLayoutMarkup($layout);
if ($post['type'] !== 'layout') return;

switch ($args['template']) {
case 'singlePost':
$layout = JSONHelper::JSONtoArray($post['content']);
$args['post']['trimmedContent'] = $this->generateLayoutMarkup($layout);
break;
case 'postTeaser':
$args['post']['trimmedContent'] = $post['summary'];
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/modules/LayoutPost/src/templates/layoutpost.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

<div class="ten wide column">
{include 'edit-form/title.tpl'}

{include 'edit-form/teaser-summary.tpl'}

<div class="field">
<label for="fld_postcontent">Content</label>
Expand Down
12 changes: 9 additions & 3 deletions app/modules/MarkdownPost/MarkdownPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ public function onViewEditPost($args) {
public function runTemplate($args)
{
$post = $args['post'];
if ($post['type'] !== 'standard') return;

if (($args['template'] == 'postTeaser' || $args['template'] == 'singlePost') && $post['type'] == 'standard') {
$content = Markdown::defaultTransform($post['content']);
$args['post']['trimmedContent'] = $content; // $this->trimContent($content, $summarylength);
switch ($args['template']) {
case 'singlePost':
$content = Markdown::defaultTransform($post['content']);
$args['post']['trimmedContent'] = $content;
break;
case 'postTeaser':
$args['post']['trimmedContent'] = $post['summary'];
break;
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/modules/MarkdownPost/src/templates/standardpost.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{* We are editing the post *}
{$formAction = "/cms/posts/edit/{$post['id']}"}
{$fieldTitle = $post['title']}
{$fieldSummary = $post['summary']}
{$fieldContent = $post['content']}
{$teaserImage = $post['teaser_image']}
{$fieldTags = str_replace("+"," ",$post['tags'])}
Expand Down Expand Up @@ -45,6 +46,8 @@
<div class="ten wide column">
{include 'edit-form/title.tpl'}

{include 'edit-form/teaser-summary.tpl'}

<div class="field">
<label for="post_content">Content</label>
<button type="button" id="upload_post_image" class="ui icon button" title="Insert Image">
Expand Down
30 changes: 17 additions & 13 deletions app/modules/VideoPost/VideoPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ public function onViewEditPost($args) {
public function runTemplate($args)
{
$post = $args['post'];
if ($post['type'] !== 'video') return;

if (($args['template'] == 'postTeaser' || $args['template'] == 'singlePost') && $post['type'] == 'video') {
$content = Markdown::defaultTransform($post['content']);
$videoContent = '';
switch($post['videosource']) {
case 'youtube':
$videoContent = '<iframe width="100%" style="max-width:560px;" height="315" src="//www.youtube.com/embed/'. $post['videoid'] .'" frameborder="0" allowfullscreen></iframe>';
break;

switch($post['videosource']) {
case 'youtube':
$videoContent = '<iframe width="100%" style="max-width:560px;" height="315" src="//www.youtube.com/embed/'. $post['videoid'] .'" frameborder="0" allowfullscreen></iframe>';
break;

case 'vimeo':
$videoContent = '<iframe src="//player.vimeo.com/video/'. $post['videoid'] .'?title=0&amp;byline=0&amp;portrait=0&amp;color=fafafa" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
break;
}
case 'vimeo':
$videoContent = '<iframe src="//player.vimeo.com/video/'. $post['videoid'] .'?title=0&amp;byline=0&amp;portrait=0&amp;color=fafafa" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
break;
}

$args['post']['trimmedContent'] = $videoContent . $content;
switch ($args['template']) {
case 'singlePost':
$content = Markdown::defaultTransform($post['content']);
$args['post']['trimmedContent'] = $videoContent . $content;
break;
case 'postTeaser':
$args['post']['trimmedContent'] = $videoContent . $post['summary'];
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/modules/VideoPost/src/templates/videopost.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<div class="ten wide column">
{include 'edit-form/title.tpl'}

{include 'edit-form/teaser-summary.tpl'}

<div class="field">
<label for="video_source">Video Source</label>
<select name="video_source" id="video_source" class="ui dropdown">
Expand Down

0 comments on commit cb243c2

Please sign in to comment.