Skip to content

Commit

Permalink
Fix for future posts..
Browse files Browse the repository at this point in the history
  • Loading branch information
victorjonsson committed Jun 4, 2014
1 parent c83d747 commit cbc94a9
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 34 deletions.
2 changes: 1 addition & 1 deletion arlima.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://github.com/victorjonsson/Arlima
Description: Manage the order of posts on your front page, or any page you want. This is a plugin suitable for online newspapers that's in need of a fully customizable front page.
Author: VK (<a href="http://twitter.com/chredd">@chredd</a>, <a href="http://twitter.com/znoid">@znoid</a>, <a href="http://twitter.com/victor_jonsson">@victor_jonsson</a>, <a href="http://twitter.com/lefalque">@lefalque</a>)
Version: 3.0.beta.33
Version: 3.0.beta.34
License: GPL2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
30 changes: 29 additions & 1 deletion classes/AbstractListRenderingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,40 @@ protected function renderArticle($article_data, $index)

// Future article
if ( !empty($article_data['published']) && $article_data['published'] > time() ) {
return array($index, $this->system->applyFilters('arlima_future_post', $post, $article_data, $this->list, $index));
return array($index, $this->getFutureArticleContent($article_data, $index, $post));
}

return array($index+1, $this->generateArticleHtml($article_data, $index, $post, $is_empty));
}

/**
* @param $article_data
* @param $index
* @param $post
* @return mixed
*/
protected function getFutureArticleContent($article_data, $index, $post)
{
$filtered = $this->system->applyFilters('arlima_future_post', array(
'post' => $post,
'article' => $article_data,
'list' => $this->list,
'count' => $index,
'content' => ''
));

if( empty($filtered['content']) && $filtered['content'] !== false) {
$url = $article_data['post'] ? admin_url('post.php?action=edit&amp;post=' . $post->ID) : $article_data['url'];
$filtered['content'] = '<div class="arlima future-post"><p>
Hey dude, <a href="' . $url . '" target="_blank">&quot;'.$article_data['title'].'&quot;</a> is
connected to a post that isn\'t published yet. The article will become public in '.
human_time_diff(time(), $article_data['published']).'.</p>
</div>';
}

return $filtered['content'];
}

/**
* @param $article_data
* @param $index
Expand Down
117 changes: 117 additions & 0 deletions classes/Article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php


/**
* Object representing an (read-only) Arlima article
*/
class Arlima_Article implements ArrayAccess {

/**
* @var array
*/
private $data = array();

/**
* @param array $data
*/
public function __construct($data)
{
$this->data = $data;
}

/**
* @param string $opt
* @return string
*/
function opt($opt)
{
return isset($this->data['options'][$opt]) ? $this->data['options'][$opt]:null;
}

/**
* @return bool|string
*/
public function url()
{
if( $overriding = $this->opt('overridingURL') ) {
return $overriding;
} elseif( $this->hasPost() ) {
return get_permalink($this->data['post']);
}
return '';
}

/**
* @return bool
*/
function hasPost()
{
return !empty($this->data['post']);
}

/**
* @return bool
*/
function isPublished()
{
return $this->data['published'] >= time();
}

/**
* @return bool
*/
function isScheduled()
{
return $this->opt('scheduled') ? true:false;
}

/**
* @return bool
*/
function isScheduledForLater()
{
return $this->isScheduled() && !$this->isInScheduledInterval($this->opt('scheduledInterval'));
}


/* * * * * ArrayAccess Impl * * * * */



public function offsetSet($offset, $value)
{
throw new Exception('Modifying the Arlima article object is not allowed');
}

public function offsetExists($offset)
{
return isset($this->data[$offset]);
}

public function offsetUnset($offset)
{
unset($this->data[$offset]);
}

public function offsetGet($offset)
{
if( $offset == 'url' ) {
return $this->url();
}
return isset($this->data[$offset]) ? $this->data[$offset] : null;
}



/* * * * Setter/getters * * * */


public function __get($key) {
return $this->offsetGet($key);
}

public function __set($key, $val) {
return $this->offsetGet($key, $val);
}

}
1 change: 1 addition & 0 deletions classes/ListFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ public static function createArticleDataArray($override=array())
$data[$key] = $val;
}

//return new Arlima_Article($data);
return $data;
}

Expand Down
5 changes: 3 additions & 2 deletions classes/ListTemplateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function generateArticleHtml($article_data, $index, $post, $is_empty)
* @param array $articles
* @return string
*/
private function renderChildArticles(array $articles)
private function renderChildArticles($articles)
{
$child_articles = '';
$count = 0;
Expand Down Expand Up @@ -151,7 +151,7 @@ private function renderChildArticles(array $articles)

list($post, $article, $is_empty) = $this->setup($article_data);

if ( is_object($post) && $post->post_status == 'future' ) {
if ( !empty($article['published']) && $article['published'] > time() ) {
if( ARLIMA_GROUP_CHILD_ARTICLES && $has_open_child_wrapper && $first_or_last_class == ' last' ) {
$child_articles .= '</div>';
$has_open_child_wrapper = false;
Expand All @@ -160,6 +160,7 @@ private function renderChildArticles(array $articles)
}

$template_name = $this->getTemplateToUse($article);

$child_articles .= $this->template_engine->renderArticle($template_name, -1, $article, $is_empty, $post, '', $first_or_last_class, $is_child_split);

$count++;
Expand Down
26 changes: 1 addition & 25 deletions classes/WPLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class Arlima_WPLoop extends Arlima_ListTemplateRenderer
*/
private $exclude_posts = array();

/**
* @var string
*/
private $filter_suffix;

/**
* @var callable
*/
Expand All @@ -32,13 +27,11 @@ class Arlima_WPLoop extends Arlima_ListTemplateRenderer

/**
* @param string $template_path - Optional path to directory where templates should exists (see readme.txt about how to add your own template paths from the theme)
* @param string $filter_suffix
*/
function __construct($template_path = null, $filter_suffix='')
function __construct($template_path = null)
{
$list = new Arlima_List();
$list->setOption('title', 'WP Arlima Loop');
$this->filter_suffix = $filter_suffix;
parent::__construct($list, $template_path);
}

Expand All @@ -58,22 +51,6 @@ public function getExcludePosts()
return $this->exclude_posts;
}

/**
* @param string $filter_suffix
*/
public function setFilterSuffix($filter_suffix)
{
$this->filter_suffix = $filter_suffix;
}

/**
* @return string
*/
public function getFilterSuffix()
{
return $this->filter_suffix;
}

/**
* @param int $article_counter
* @param array $article
Expand Down Expand Up @@ -101,7 +78,6 @@ function havePosts()
return have_posts();
}


/**
* @param bool $output
* @return string
Expand Down
2 changes: 1 addition & 1 deletion constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
or define('ARLIMA_COMPILE_LESS_IN_BROWSER', ARLIMA_DEV_MODE);

// Plugin version (only edit this via grunt!)
define('ARLIMA_FILE_VERSION', '3.0.beta.33' .(ARLIMA_DEV_MODE ? '__'.time():''));
define('ARLIMA_FILE_VERSION', '3.0.beta.34' .(ARLIMA_DEV_MODE ? '__'.time():''));

// Which type of tag to use for images in Arlima RSS feeds
defined('ARLIMA_RSS_IMG_TAG')
Expand Down
4 changes: 2 additions & 2 deletions js/arlima/arlima.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/arlima/dev/ArlimaBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var ArlimaBackend = (function($, ArlimaUtils, ArlimaJS) {
* @param {Function} [callback]
*/
connectAttachmentToPost : function(postId, attachId, callback) {
this._ajax('arlima_connect_attach_to_post', {attachment:attachId, post:postId}, callback);
this._ajax('arlima_connect_attach_to_post', {attachment:attachId, post_id:postId}, callback);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: @chredd, @znoid, @victor_jonsson, @lefalque, @aaslun
Tags: CMS, e-paper, e-magazine, magazine, newspaper, front page, wysiwyg
Requires at least: 3.8
Tested up to: 3.9.1
Stable tag: 3.0.beta.33
Stable tag: 3.0.beta.34
License: GPL2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down

0 comments on commit cbc94a9

Please sign in to comment.