Skip to content

Commit

Permalink
Merge pull request #17 from Factlink/change-admin-page-options-layout
Browse files Browse the repository at this point in the history
Change admin page options layout
  • Loading branch information
Martijn Russchen committed Apr 7, 2014
2 parents 910cbb5 + 83177ba commit 288c3c4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 79 deletions.
4 changes: 0 additions & 4 deletions trunk/app/capability/admin_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public function initialize()
// register the options that can be updated through the view
// needs to be called, otherwise the settings won't register and a strange page will be displayed
$this->settings->enabled_for_pages->register();
$this->settings->enabled_for_all_pages->register();

$this->settings->enabled_for_posts->register();
$this->settings->enabled_for_all_posts->register();

$this->settings->disable_global_comments->register();
}

Expand Down
23 changes: 2 additions & 21 deletions trunk/app/capability/include_factlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,8 @@ public function initialize()
{
$id = get_queried_object_id();

if ($this->settings->enabled_for_pages->get() == 1 &&

is_page() &&

($this->settings->enabled_for_all_pages->get() == 0 && $this->settings->page_meta->get($id) == 1) ||

$this->settings->enabled_for_all_pages->get() == 1

) {
$this->render();
}

if ($this->settings->enabled_for_posts->get() == 1 &&

is_single() &&

($this->settings->enabled_for_all_posts->get() == 0 && $this->settings->post_meta->get($id) == 1) ||

$this->settings->enabled_for_all_posts->get() == 1
) {
// render factlink
if ($this->settings->is_enabled_for_post($id))
{
$this->render();
}
}
Expand Down
18 changes: 9 additions & 9 deletions trunk/app/capability/meta_box.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class MetaBox extends \vg\wordpress_plugin\capability\Capability
public $meta_name;
public $meta_value;

public $is_published;

public function initialize($post_type, $post)
{
$this->meta_name = $this->settings->post_meta->name;
Expand All @@ -22,18 +24,16 @@ public function initialize($post_type, $post)
$title = 'FactLink settings';
$context = 'advanced';

if (
$this->settings->enabled_for_pages->get() == 1 &&
$post_type == 'page' &&
$this->settings->enabled_for_all_pages->get() == 0
) {
// get the post status of the current post
$this->is_published = get_post_status(get_queried_object_id()) == 'publish';

if ($this->settings->enabled_for_pages->get() == 1 && $post_type == 'page')
{
add_meta_box($id, $title, array($this, 'render_page_meta_box'), 'page', $context);
}

if ($this->settings->enabled_for_posts->get() == 1 &&
$post_type == 'post' &&
$this->settings->enabled_for_all_posts->get() == 0
) {
if ($this->settings->enabled_for_posts->get() == 1 && $post_type == 'post')
{
add_meta_box($id, $title, array($this, 'render_post_meta_box'), 'post', $context);
}
}
Expand Down
41 changes: 30 additions & 11 deletions trunk/app/model/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
class Settings extends \vg\wordpress_plugin\model\Model
{
public $enabled_for_posts;
public $enabled_for_all_posts;

public $enabled_for_pages;
public $enabled_for_all_pages;

public $is_configured;
public $disable_global_comments;
Expand All @@ -29,16 +26,10 @@ function initialize()
$this->menu_url = get_admin_url(null, $this->menu_parent_slug . "?page=" . $this->menu_slug);

// setting if factlink is enabled for all the posts
$this->enabled_for_posts = $this->create_option_meta('enabled_for_posts', 'global_settings', 1, array('int'));

// setting to determine if default factlink is enabled for a post or default is disabled
$this->enabled_for_all_posts = $this->create_option_meta('enabled_for_all_posts', 'global_settings', 1, array('int'));
$this->enabled_for_posts = $this->create_option_meta('enabled_for_posts', 'global_settings', 2, array('int'));

// setting if factlink is enabled for all the pages
$this->enabled_for_pages = $this->create_option_meta('enabled_for_pages', 'global_settings', 1, array('int'));

// setting to determine if default factlink is enabled for a page or default is disabled
$this->enabled_for_all_pages = $this->create_option_meta('enabled_for_all_pages', 'global_settings', 1, array('int'));
$this->enabled_for_pages = $this->create_option_meta('enabled_for_pages', 'global_settings', 2, array('int'));

// setting to display configuration message as long factlink isn't configured
$this->is_configured = $this->create_option_meta('is_configured', 'global_settings', 0, array('int'));
Expand All @@ -59,4 +50,32 @@ public function activate()
// set the state of the is_configured to 0 -> not configured
$this->is_configured->set(0);
}

public function is_enabled_for_post($post_id)
{
// 1 means only selected posts
if ($this->enabled_for_pages->get() == 1 && $this->page_meta->get($post_id) == 1 && is_page())
{
return true;
}

// 2 means enabled for all pages
if ($this->enabled_for_pages->get() == 2 && is_page())
{
return true;
}

// is_single means if the current page is a single post
if ($this->enabled_for_posts->get() == 1 && $this->post_meta->get($post_id) == 1 && is_single())
{
return true;
}

if ($this->enabled_for_posts->get() == 2 && is_single())
{
return true;
}

return false;
}
}
62 changes: 29 additions & 33 deletions trunk/app/view/admin_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,68 @@
<table class="form-table">

<tr>
<th scope="row">Posts</th>
<th scope="row">Enable discussions on posts:</th>
<td>
<fieldset>
<input type="hidden" name="<?php echo $this->settings->enabled_for_posts->name(); ?>" value="0">
<input type="checkbox"
name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
id="<?php echo $this->settings->enabled_for_posts->name(); ?>"
value="1"
<?php if ($this->settings->enabled_for_posts->get() == 1) {
echo 'checked';
} ?>>
<label for="<?php echo $this->settings->enabled_for_posts->name(); ?>">Enabled for posts</label>

<br/>
<label>
<input type="radio" name="<?php echo $this->settings->enabled_for_all_posts->name(); ?>"
value="1" <?php if ($this->settings->enabled_for_all_posts->get() == "1") {
<input type="radio" name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
value="2" <?php if ($this->settings->enabled_for_posts->get() == "2") {
echo "checked";
} ?>>
All posts
</label>
<br/>

<label>
<input type="radio" name="<?php echo $this->settings->enabled_for_all_posts->name(); ?>"
value="0" <?php if ($this->settings->enabled_for_all_posts->get() == "0") {
<input type="radio" name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
value="1" <?php if ($this->settings->enabled_for_posts->get() == "1") {
echo "checked";
} ?>>
Selected posts
</label>
<br/>

<label>
<input type="radio" name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
value="0" <?php if ($this->settings->enabled_for_posts->get() == "0") {
echo "checked";
} ?>>
No posts
</label>
</fieldset>
</td>
</tr>

<tr>
<th scope="row">Pages</th>
<th scope="row">Enable discussions on pages:</th>
<td>
<fieldset>
<input type="hidden" name="<?php echo $this->settings->enabled_for_pages->name(); ?>" value="0">
<input type="checkbox"
name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
id="<?php echo $this->settings->enabled_for_pages->name(); ?>"
value="1"
<?php if ($this->settings->enabled_for_pages->get() == 1) {
echo 'checked';
} ?>>
<label for="<?php echo $this->settings->enabled_for_pages->name(); ?>">Enabled for pages</label>

<br/>
<label>
<input type="radio" name="<?php echo $this->settings->enabled_for_all_pages->name(); ?>"
value="1" <?php if ($this->settings->enabled_for_all_pages->get() == "1") {
<input type="radio" name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
value="2" <?php if ($this->settings->enabled_for_pages->get() == "2") {
echo "checked";
} ?>>
All pages
</label>
<br/>

<label>
<input type="radio" name="<?php echo $this->settings->enabled_for_all_pages->name(); ?>"
value="0" <?php if ($this->settings->enabled_for_all_pages->get() == "0") {
<input type="radio" name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
value="1" <?php if ($this->settings->enabled_for_pages->get() == "1") {
echo "checked";
} ?>>
Selected pages
</label>
<br/>

<label>
<input type="radio" name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
value="0" <?php if ($this->settings->enabled_for_pages->get() == "0") {
echo "checked";
} ?>>
No pages
</label>
</fieldset>
</td>
</tr>
Expand All @@ -99,8 +96,7 @@
} ?> id="<?php echo $this->settings->disable_global_comments->name(); ?>" value="1">
<label for="<?php echo $this->settings->disable_global_comments->name(); ?>">Disable the default Wordpress comments.</label>
</fieldset>
<p class="description">Note: Disables the Wordpress ability to add new comments, but doesn't remove the
existing ones.</p>
<p class="description">Note: Disables the Wordpress ability to add new comments, but still shows the existing ones.</p>
</td>
</tr>

Expand Down
2 changes: 1 addition & 1 deletion trunk/app/view/meta_box.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<input type="hidden" name="<?php echo $this->meta_name; ?>" value="0">
<input type="checkbox" name="<?php echo $this->meta_name; ?>" value="1"
id="<?php echo $this->meta_name; ?>" <?php if ($this->meta_value == 1) {
id="<?php echo $this->meta_name; ?>" <?php if ($this->meta_value == 1 || !$this->is_published) {
echo 'checked';
} ?>>
<label for="<?php echo $this->meta_name; ?>">Enable Factlink for this item</label>
Expand Down
1 change: 1 addition & 0 deletions trunk/lib/model/meta/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct($name, $default_value, $validators, $model)
$this->default_value = $default_value;
$this->validators = $validators;
$this->model = $model;
$this->prefix = $this->model->meta_prefix;
}

public function get()
Expand Down

0 comments on commit 288c3c4

Please sign in to comment.