Skip to content

Commit

Permalink
New feature, decide which templates that should be available for a ce…
Browse files Browse the repository at this point in the history
…rtain list
  • Loading branch information
Victor Josson committed Mar 4, 2015
1 parent 4484fc5 commit d90364c
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 144 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.40
Version: 3.1.beta.41
License: GPL2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/CMSInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function getRelationData($post_id);
/**
* Get all "widgets" that displays given Arlima list
* @param Arlima_List $list
* @return void
* @return array
*/
function loadRelatedWidgets($list);

Expand Down
47 changes: 36 additions & 11 deletions classes/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@ class Arlima_List

/**
* @var array
* @see Arlima_List::getDefaultOptions
*/
private $options = array(
'template' => 'article',
'pages_to_purge' => '',
'supports_sections' => "0", // translates to bool false
'allows_template_switching' => "1",
'before_title' => '<h2>',
'after_title' => '</h2>'
);
private $options = array();

/**
* @var Arlima_Article[]
Expand All @@ -101,11 +95,28 @@ class Arlima_List
*/
function __construct($exists = false, $id = 0, $is_imported = false)
{
$this->options = self::getDefaultListOptions();
$this->exists = $exists;
$this->is_imported = $is_imported;
$this->id = $id;
}

/**
* @return array
*/
static function getDefaultListOptions()
{
return array(
'template' => 'article',
'available_templates' => false, // not set meaning all will be available
'pages_to_purge' => '',
'supports_sections' => "0", // translates to bool false
'allows_template_switching' => "1",
'before_title' => '<h2>',
'after_title' => '</h2>'
);
}

/**
* Tells whether or not this arlima list exists in the database
* @return bool
Expand Down Expand Up @@ -151,6 +162,19 @@ public function isPublished()
return $this->getStatus() == self::STATUS_PUBLISHED;
}

/**
* Tells whether or not this list allows use of given template
* @param string $template
* @return bool
*/
public function isAvailable($template)
{
if( $this->hasOption('available_templates') ) {
return in_array(basename($template), $this->getOption('available_templates'));
}
return true;
}

/**
* Whether or not admins can create "sections" in the list
* @return bool
Expand Down Expand Up @@ -250,12 +274,13 @@ public function setVersion($version_data)
}

/**
* @param $name
* @param string $name
* @param mixed $default
* @return string|null
*/
public function getOption($name)
public function getOption($name, $default=null)
{
return isset($this->options[$name]) ? $this->options[$name] : null;
return isset($this->options[$name]) ? $this->options[$name] : $default;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions classes/ListRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ public function load($id_or_slug)
$list->setTitle($list_data['title']);
$list->setSlug($list_data['slug']);
$list->setMaxlength($list_data['maxlength']);
$list->setOptions( unserialize($list_data['options']) );

// Need to sanitize options also when list is loaded due to make it backwards compat
$list->setOptions( self::sanitizeListOptions(unserialize($list_data['options'])) );

$this->cache->set('arlima_list_'.$list->getId(), $list);
}
}
Expand Down Expand Up @@ -230,10 +233,8 @@ private function sanitizeList( $list )
*/
private function sanitizeListOptions($options)
{
$empty_list = new Arlima_List();

// Override default options
foreach($empty_list->getOptions() as $name => $val) {
foreach(Arlima_List::getDefaultListOptions() as $name => $val) {
if( !isset($options[$name]) )
$options[$name] = $val;
}
Expand Down
6 changes: 4 additions & 2 deletions classes/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ isInScheduledInterval('*:*'); // All days of the week and all hours of the day
| public | <strong>abstract isPreloaded(</strong><em>int</em> <strong>$id</strong>)</strong> : <em>bool</em><br /><em>Tells whether or not a page/post with given id is preloaded</em> |
| public | <strong>abstract loadExternalURL(</strong><em>string</em> <strong>$url</strong>)</strong> : <em>array</em><br /><em>Load the contents of an external URL. This function returns an array with 'headers', 'body', 'response', 'cookies', 'filename' if request was successful, or throws an Exception if failed</em> |
| public | <strong>abstract loadRelatedPages(</strong><em>[\Arlima_List](#class-arlima_list)</em> <strong>$list</strong>)</strong> : <em>array</em><br /><em>Get an array with all pages that give list is related to</em> |
| public | <strong>abstract loadRelatedWidgets(</strong><em>[\Arlima_List](#class-arlima_list)</em> <strong>$list</strong>)</strong> : <em>void</em><br /><em>Get all "widgets" that displays given Arlima list</em> |
| public | <strong>abstract loadRelatedWidgets(</strong><em>[\Arlima_List](#class-arlima_list)</em> <strong>$list</strong>)</strong> : <em>array</em><br /><em>Get all "widgets" that displays given Arlima list</em> |
| public | <strong>abstract postToArlimaArticle(</strong><em>int/object</em> <strong>$post</strong>, <em>mixed/null/string</em> <strong>$text=null</strong>)</strong> : <em>[\Arlima_Article](#class-arlima_article)</em> |
| public | <strong>abstract preLoadPosts(</strong><em>array</em> <strong>$post_ids</strong>)</strong> : <em>mixed</em><br /><em>Preloads posts/pages with given ids. Use this function to lower the amount of db queries sent when using any of the post-functions provided by this class</em> |
| public | <strong>abstract prepare(</strong><em>string</em> <strong>$sql</strong>, <em>array</em> <strong>$params</strong>)</strong> : <em>mixed</em><br /><em>Prepare an SQL-statement.</em> |
Expand Down Expand Up @@ -293,9 +293,10 @@ isInScheduledInterval('*:*'); // All days of the week and all hours of the day
| public | <strong>getArticles()</strong> : <em>[\Arlima_Article](#class-arlima_article)[]</em> |
| public | <strong>getContainingPosts()</strong> : <em>array</em><br /><em>Returns a list with id numbers of the posts that has a connection to one or more articles in this list</em> |
| public | <strong>getCreated()</strong> : <em>int</em> |
| public static | <strong>getDefaultListOptions()</strong> : <em>array</em> |
| public | <strong>getId()</strong> : <em>int</em> |
| public | <strong>getMaxlength()</strong> : <em>int</em> |
| public | <strong>getOption(</strong><em>mixed</em> <strong>$name</strong>)</strong> : <em>string/null</em> |
| public | <strong>getOption(</strong><em>string</em> <strong>$name</strong>, <em>mixed</em> <strong>$default=null</strong>)</strong> : <em>string/null</em> |
| public | <strong>getOptions()</strong> : <em>array</em> |
| public | <strong>getPublishedVersions()</strong> : <em>array</em> |
| public | <strong>getScheduledVersions()</strong> : <em>array</em> |
Expand All @@ -308,6 +309,7 @@ isInScheduledInterval('*:*'); // All days of the week and all hours of the day
| public | <strong>getVersions()</strong> : <em>array</em><br /><em>A list with the latest created versions of this list</em> |
| public | <strong>hasOption(</strong><em>string</em> <strong>$name</strong>)</strong> : <em>bool</em> |
| public | <strong>id()</strong> : <em>int</em> |
| public | <strong>isAvailable(</strong><em>string</em> <strong>$template</strong>)</strong> : <em>bool</em><br /><em>Tells whether or not this list allows use of given template</em> |
| public | <strong>isImported()</strong> : <em>bool</em><br /><em>Tells whether or not this arlima list is loaded from a remote host</em> |
| public | <strong>isLatestPublishedVersion()</strong> : <em>bool</em> |
| public | <strong>isPreview()</strong> : <em>bool</em><br /><em>Tells whether or not the list contains a preview version</em> |
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_PLUGIN_VERSION', '3.1.beta.40');
define('ARLIMA_PLUGIN_VERSION', '3.1.beta.41');
define('ARLIMA_FILE_VERSION', ARLIMA_PLUGIN_VERSION .(ARLIMA_DEV_MODE ? '__'.time():''));

// Which type of tag to use for images in Arlima RSS feeds
Expand Down
2 changes: 1 addition & 1 deletion css/admin.css

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions css/admin.less
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,29 @@ img.schedule-clock {
}


#export-list {
.scroll-window {
width: 100%;
max-width: none;
background: #F2F2F2;
border: #E2E2E2 solid 1px;
height: 200px;
overflow-x: hidden;
overflow-y: scroll;
max-width: 65%;
}

#export-list p {
.scroll-window p {
padding: 8px 12px;
border-bottom: #E2E2E2 solid 1px;
border-top: #FFF solid 1px;
margin: 0;
margin: 0 !important;
line-height: 160%;
}

#export-list p:first-child {
.scroll-window p:first-child {
border-top: 0;
}

#export-list p input {
.scroll-window p input {
margin-right: 4px;
}

Expand All @@ -204,7 +205,7 @@ img.schedule-clock {
}
}

#export-list .gray-small {
.scroll-window .gray-small {
display: block;
}

Expand All @@ -214,6 +215,12 @@ img.schedule-clock {
*/

.wrap.arlima.arlima-edit {

p.small {
color :#777;
font-weight: normal;
}

.tablenav {
width: 600px;
text-align: right;
Expand Down
9 changes: 5 additions & 4 deletions js/arlima/arlima.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/arlima/dev/ArlimaArticleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ var ArlimaArticleForm = (function($, window, ArlimaArticlePreview, ArlimaUtils,
// Setup preview
ArlimaArticlePreview.setArticle(
this.article,
window.ArlimaTemplateLoader.templates[this.article.getTemplate()],
window.ArlimaTemplateLoader.templates[this.article.getTemplate()] || '!! unknown template "'+this.article.getTemplate()+'"',
list.data.previewWidth || 468,
false,
list.data.isImported
Expand Down
35 changes: 35 additions & 0 deletions js/arlima/dev/ArlimaArticleSettingsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,41 @@ var ArlimaArticleSettingsMenu = (function($, ArlimaUtils) {
} else {
// Make it possible to switch template
this.$dropDown.find('.nav.template .disabled').removeClass('disabled');
var $tmplItems = this.$dropDown.find('.nav.template .nav');

// Disable templates that isn't available in current list
if($.isArray(list.data.options.available_templates) && list.data.options.available_templates.length) {

$tmplItems.not(':eq(0)').addClass('disabled');
$.each(list.data.options.available_templates, function(i, template) {
$tmplItems.filter('[data-value="'+template+'"]')
.removeClass('disabled')
.insertAfter($tmplItems.eq(0));
});

// now also sorted, putting available first
this.$dropDown.attr('data-template-sort', 'available');

} else {
// sort templates by name
if( this.$dropDown.attr('data-template-sort') != 'name' ) {
this.$dropDown.attr('data-template-sort', 'name');
var clones = {},
cloneKeys = [];

$tmplItems.not(':eq(0)').each(function() {
var $node = $(this);
clones[$node.attr('data-value')] = $node.clone(true);
cloneKeys.push($node.attr('data-value'));
$node.remove();
});

cloneKeys.sort();
$.each(cloneKeys, function(i, key) {
$tmplItems.parent().append(clones[key]);
});
}
}
}

if( !article.canPreview() ) {
Expand Down
Binary file modified lang/arlima-sv_SE.mo
Binary file not shown.
109 changes: 5 additions & 104 deletions lang/arlima.pot
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ msgstr "Standardmall"

#: pages/edit.php:141
msgid "Allow editors to switch template on articles in the list manager"
msgstr "Tillåt redaktörer att byta mall på enskilda artiklar"
msgstr "Ska redaktörer kunna byta mall på enskilda artiklar?"

#: pages/edit.php:154
msgid "Should this list support sections (read wiki for more info)"
Expand Down Expand Up @@ -828,107 +828,8 @@ msgstr "Uppdaterad av"
msgid "Inverted"
msgstr "Inverterad"

#~ msgid "Scheduled list notice"
#~ msgstr "Tidsinställd lista"
msgid "Available templates"
msgstr "Tillgänliga mallar"

#~ msgid ""
#~ "Please note: a scheduled list is about to be published in %s seconds."
#~ msgstr ""
#~ "Notera: en tidsinställd lista är inställd att publiceras om %s sekunder. "

#~ msgid "The list will be refreshed automatically."
#~ msgstr "Listan kommer automatiskt att ladda om."

#~ msgid "Help"
#~ msgstr "Dokumentation"

#~ msgid "Here you will see the article list..."
#~ msgstr "Här kommer du att kunna se din artikellista."

#~ msgid ""
#~ "No list slug is defined. Please add custom field &quot;arlima&quot; to "
#~ "this page with the slug name of the list that you want to display"
#~ msgstr ""
#~ "Ingen lista är definerad. Du måste lägga till ett eget fält med namnet "
#~ "\"arlima\"innehållandes namnet på den artikellista du vill visa på den "
#~ "här sidan."

#~ msgid "It does not exist any arlima list with the slug"
#~ msgstr "Det finns ingen artikellista med namnet"

#~ msgid "Please feed me some articles, I'm hungry"
#~ msgstr "Det saknas artiklar!"

#~ msgid "Preview URL"
#~ msgstr "URL till förhandsgranskningssida"

#~ msgid "eg. \"/\" or \"/home\""
#~ msgstr "tex. \"/\" eller \"/min-sida\""

#~ msgid "Custom"
#~ msgstr "Egen text"

#~ msgid "Choose streamer"
#~ msgstr "Välj vinjett"

#~ msgid "Drag images to here"
#~ msgstr "Dra bilder hit"

#~ msgid "Align center"
#~ msgstr "Centrerad"

#~ msgid "Style"
#~ msgstr "Anpassad rubrik"

#~ msgid "Link"
#~ msgstr "Länk"

#~ msgid "Templates"
#~ msgstr "Mall"

#~ msgid "Arlima (article list manager)"
#~ msgstr "Arlima (article list manager)"

#~ msgid "Teaser templates"
#~ msgstr "Artikelmallar"

#~ msgid ""
#~ "This list is not related to any page! Create a new page with a custom "
#~ "field named arlima having %s as value."
#~ msgstr ""
#~ "Den här listan är inte kopplad till någon sida! Skapa en sida med ett "
#~ "eget fält som du ger namnet arlima och värdet %s "

#~ msgid "imported list"
#~ msgstr "importerad"

#~ msgid "This list is missing a preview page"
#~ msgstr "Den här listan saknar en förhandsgranskningssida"

#~ msgid "Interval"
#~ msgstr "Intervall"

#~ msgid "Quick Edit"
#~ msgstr "Snabbredigering"

#~ msgid ""
#~ "This is an experimental feature that makes it possible to edit articles "
#~ "directly on your front page."
#~ msgstr ""
#~ "Den här funktionen gör det möjligt att redigera artiklar direkt på "
#~ "startsidan."

#~ msgid "Enabled"
#~ msgstr "Aktivterad"

#~ msgid "Disabled"
#~ msgstr "Inaktivterad"

#~ msgid "Read more"
#~ msgstr "Läs mer"

#~ msgid "[open]"
#~ msgstr "[öppna]"

#~ msgid "Arguments (query string)"
#~ msgstr "Argument (query-sträng)"
msgid "Notice that templates hidden by the filter <em>arlima_hidden_templates</em> can not be made available in the list manager."
msgstr "Notera att man inte kan tillgängligöra mallar som döljts med filtret: <em>arlima_hidden_templates</em>."
Loading

0 comments on commit d90364c

Please sign in to comment.