Skip to content

Commit

Permalink
General improvements... closing up on stable release
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Josson committed Mar 4, 2015
1 parent 6beba80 commit 4484fc5
Show file tree
Hide file tree
Showing 26 changed files with 500 additions and 333 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.1.beta.36
Version: 3.1.beta.40
License: GPL2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
4 changes: 2 additions & 2 deletions classes/AbstractListRenderingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function havePosts()
/**
* Render the list of articles
* @abstract
* @param bool $output[optional=true]
* @param bool $echo_output[optional=true]
* @return string
*/
abstract protected function generateListHtml($output = true);
abstract protected function generateListHtml($echo_output = true);

/**
* @param bool $output
Expand Down
1 change: 1 addition & 0 deletions classes/AbstractRepositoryDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected function removePrefix($array = array(), $prefix, $preserve_std_objects
}



/* * * * * * * * Abstract functions * * * * * * * * * */


Expand Down
3 changes: 3 additions & 0 deletions classes/CMSFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
class Arlima_CMSFacade {

/**
* @var Arlima_CMSInterface
*/
private static $instance = null;

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/CMSInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ function resetAfterPostLoop();

/**
* Get ID of the current post in
* @return mixed
* @return int
*/
function getPostIDInLoop();

/**
* @return mixed
* @return bool
*/
function havePostsInLoop();

Expand Down
87 changes: 49 additions & 38 deletions classes/CMSLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class Arlima_CMSLoop extends Arlima_ListTemplateRenderer
{

/**
* @var array
*/
Expand Down Expand Up @@ -78,78 +77,90 @@ function havePosts()
}

/**
* @param bool $output
* Set $echo_output to false to rendered list as a string
* @param bool $echo_output
* @return string
*/
function generateListHtml($output = true)
function generateListHtml($echo_output = true)
{
$article_counter = 0;
$content = '';

// Set default template
try {
$this->template_engine->setDefaultTemplate($this->list->getOption('template'));
} catch(Exception $e) {
$message = 'You are using a default template for the list "'.$this->list->getTitle().'" that could not be found';
if( $output ) {
if( $echo_output ) {
echo $message;
} else {
return $message;
}
}

while ( $this->cms->havePostsInLoop() ) {
if ( $this->getOffset() > $article_counter ) {
return $this->runArticleLoop($echo_output);
}

/**
* @param int $post_id
* @param int $article_counter
* @return Arlima_Article
*/
protected function createArticleFromPost($post_id, $article_counter)
{
$article = $this->cms->postToArlimaArticle($post_id, $this->default_article_props);
$article_data = $article->toArray();
$article_data['title'] = call_user_func($this->header_callback, $article_counter, $article, $post_id, $this->list);
$article_data['content'] = $this->cms->applyFilters('the_content', $this->cms->getContentOfPostInGlobalScope(), 'arlima-list');
$article_data['image'] = $this->cms->getArlimaArticleImageFromPost($post_id);

$article = new Arlima_Article($article_data);
$article = $this->cms->applyFilters('arlima_wp_loop_article', $article, $post_id); // Backwards compat
return $this->cms->applyFilters('arlima_cms_loop_article', $article, $post_id);
}

/**
* @param $arr
*/
public function setDefaultArticleProperties($arr)
{
$this->default_article_props = $arr;
}

/**
* @param bool $echo_output
* @return string|void
*/
private function runArticleLoop($echo_output)
{
$article_counter = 0;
$content = '';

while ($this->cms->havePostsInLoop()) {
if ($this->getOffset() > $article_counter) {
$article_counter++;
continue;
}

$post_id = $this->cms->getPostIDInLoop();
$template_data = $this->extractTemplateData($post_id, $article_counter);
$article = $this->createArticleFromPost($post_id, $article_counter);

if( $template_data && !in_array($post_id, $this->exclude_posts) ) {
if (!in_array($post_id, $this->exclude_posts)) {

list($article_counter, $article_content) = $this->renderArticle(
$template_data,
$article,
$article_counter
);

if ( $output ) {
if ($echo_output) {
echo $article_content;

} else {
$content .= $article_content;
}
}

if ( $article_counter >= 50 || ($this->getLimit() > -1 && $this->getLimit() <= $article_counter) ) {
if ($article_counter >= 50 || ($this->getLimit() > -1 && $this->getLimit() <= $article_counter)) {
break;
}
}

return $content;
}

/**
* @param int $post_id
* @param int $article_counter
* @return array
*/
protected function extractTemplateData($post_id, $article_counter)
{
$article = $this->cms->postToArlimaArticle($post_id, $this->default_article_props);
$article['html_title'] = call_user_func($this->header_callback, $article_counter, $article, $post_id, $this->list);
$article['html_content'] = $this->cms->applyFilters('the_content', $this->cms->getContentOfPostInGlobalScope(), 'arlima-list');
$article['image'] = $this->cms->getArlimaArticleImageFromPost($post_id);
$article = $this->cms->applyFilters('arlima_wp_loop_article', $article, $post_id); // Backwards compat
return $this->cms->applyFilters('arlima_cms_loop_article', $article, $post_id);
}

/**
* @param $arr
*/
public function setDefaultArticleProperties($arr)
{
$this->default_article_props = $arr;
}
}
2 changes: 0 additions & 2 deletions classes/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@


/**
* Wrapper for cache functions provided by the CMS
*
* @package Arlima
* @since 2.0
*/
Expand Down
Loading

0 comments on commit 4484fc5

Please sign in to comment.