Permalink
Browse files

conversion to using views for admin UI

  • Loading branch information...
1 parent bfd1170 commit 055d3304937d9f6ccf2ec3b1cb2817b66a1f13f2 @alexkingorg alexkingorg committed Dec 11, 2011
Showing with 117 additions and 144 deletions.
  1. BIN assets/img/bg-clouds.png
  2. +1 −85 classes/aktt_account.php
  3. +11 −0 twitter-tools.php
  4. +9 −4 views/admin-account.php
  5. +96 −55 views/admin.php
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -79,101 +79,17 @@ public static function load($acct = null) {
}
function __construct($acct = null) {
-
// Set our ID
$this->id = $acct->id();
- // Set the account (stdClass Obj)
+ // Set the account (Social_Service_Twitter_Account)
$this->social_acct = $acct;
// For convenience, set a reference to the service which has all the account methods
$this->service = &Social::instance()->service('twitter');
}
- function settings_form() {
- $name = $this->social_acct->name();
- $avatar = $this->social_acct->avatar();
- $img = empty($avatar) ? '' : '<img class="avatar" src="'.esc_url($avatar).'" />';
-?>
- <li class="aktt_acct_item">
- <h3><?php echo esc_html($name); ?></h3>
- <?php echo $img; ?>
- <ul class="aktt-account-settings">
-<?php
- foreach (AKTT_Account::$settings as $key => $setting) {
- $this->output_setting_item($key, $setting);
- }
-?>
- </ul><!-- /aktt-account-settings -->
- </li>
-<?php
- }
-
- function output_setting_item($key, $setting) {
- // Build our complex option name
- $name = 'aktt_v3_accounts['.$this->id.'][settings]['.$key.']';
-
- // Get our label's HTML
- $label_html = '<label for="'.esc_attr($name).'" class="aktt-account-setting">'.$setting['label'].'</label>';
-
- // Get our field's HTML
- ob_start();
- switch ($key) {
- case 'enabled':
- case 'create_posts':
- case 'exclude_reply_tweets':
- ?>
- <input type="checkbox" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($name); ?>" value="1"<?php checked('1', $this->option($key)); ?> />
- <?php
- break;
- case 'post_author':
- wp_dropdown_users(array(
- 'name' => $name,
- 'id' => $name,
- 'selected' => $this->option($key),
- 'who' => 'authors',
- ));
- break;
- case 'post_category':
- wp_dropdown_categories(array(
- 'name' => $name,
- 'id' => $name,
- 'selected' => $this->option($key),
- 'hide_empty' => 0,
- 'taxonomy' => 'category',
- ));
- break;
- case 'post_tags':
- // The DB value is a comma separated list
- ?>
- <input type="text" class="type-ahead" data-tax="post_tag" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($name); ?>" value="<?php echo esc_attr($this->option($key)); ?>" /> <?php _e('(comma separated)', 'twitter-tools'); ?>
- <?php
- break;
- case 'hashtag':
- default:
- ?>
- <input type="text" name="<?php echo esc_attr($name); ?>" id="<?php echo esc_attr($name); ?>" value="<?php echo esc_attr($this->option($key)); ?>" />
- <?php
- break;
- }
- // Get our field's HTML
- $field_html = ob_get_clean();
-
- ?>
- <li>
- <?php
- if ($setting['label_first']) {
- echo $label_html.$field_html;
- }
- else {
- echo $field_html.$label_html;
- }
- ?>
- </li>
- <?php
- }
-
/**
* Get an option from the DB, and fall back to the default setting
View
@@ -22,6 +22,17 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************
+$aktt_file = __FILE__;
+if (isset($plugin)) {
+ $aktt_file = $plugin;
+}
+else if (isset($mu_plugin)) {
+ $aktt_file = $mu_plugin;
+}
+else if (isset($network_plugin)) {
+ $aktt_file = $network_plugin;
+}
+@define('AKTT_FILE', $aktt_file);
@define('AKTT_PATH', plugin_dir_path(__FILE__));
require_once(AKTT_PATH.'/classes/aktt.php');
View
@@ -21,7 +21,11 @@
<fieldset class="depends-on-create-posts">
<h4><?php _e('Settings for blog posts', 'twitter-tools'); ?></h4>
<p>
- <label for="<?php echo esc_attr(sprintf($name, 'post_author')); ?>"><?php _e('Author', 'twitter-tools'); ?></label>
+ <label class="left" for="<?php echo esc_attr(sprintf($name, 'blog_post_title')); ?>"><?php _e('Title prefix', 'twitter-tools'); ?></label>
+ <input type="text" name="<?php echo esc_attr(sprintf($name, 'post_tags')); ?>" id="<?php echo esc_attr(sprintf($name, 'blog_post_title')); ?>" value="<?php echo esc_attr($account->option('blog_post_title')); ?>" /> <span class="help"><?php _e('("Tweet:" = "<b>Tweet:</b> This is my tweet...")', 'twitter-tools'); ?></span>
+ </p>
+ <p>
+ <label class="left" for="<?php echo esc_attr(sprintf($name, 'post_author')); ?>"><?php _e('Author', 'twitter-tools'); ?></label>
<?php
wp_dropdown_users(array(
'name' => sprintf($name, 'post_author'),
@@ -32,7 +36,7 @@
?>
</p>
<p>
- <label for="<?php echo esc_attr(sprintf($name, 'post_category')); ?>"><?php _e('Category', 'twitter-tools'); ?></label>
+ <label class="left" for="<?php echo esc_attr(sprintf($name, 'post_category')); ?>"><?php _e('Category', 'twitter-tools'); ?></label>
<?php
wp_dropdown_categories(array(
'name' => sprintf($name, 'post_category'),
@@ -44,10 +48,11 @@
?>
</p>
<p>
- <label for="<?php echo esc_attr(sprintf($name, 'post_tags')); ?>"><?php _e('Tags', 'twitter-tools'); ?></label>
+ <label class="left" for="<?php echo esc_attr(sprintf($name, 'post_tags')); ?>"><?php _e('Tags', 'twitter-tools'); ?></label>
<input type="text" class="type-ahead" data-tax="post_tag" name="<?php echo esc_attr(sprintf($name, 'post_tags')); ?>" id="<?php echo esc_attr(sprintf($name, 'post_tags')); ?>" value="<?php echo esc_attr($account->option('post_tags')); ?>" /> <span class="help"><?php _e('(comma separated)', 'twitter-tools'); ?></span>
+ </p>
<p>
- <label for="<?php echo esc_attr(sprintf($name, 'exclude_reply_tweets')); ?>">
+ <label class="right" for="<?php echo esc_attr(sprintf($name, 'exclude_reply_tweets')); ?>">
<input type="checkbox" name="<?php echo esc_attr(sprintf($name, 'exclude_reply_tweets')); ?>" id="<?php echo esc_attr(sprintf($name, 'exclude_reply_tweets')); ?>" value="1" <?php checked('1', $account->option('exclude_reply_tweets')); ?> />
<?php _e('Don\'t create posts for reply tweets', 'twitter-tools'); ?>
</label>
View
@@ -2,10 +2,21 @@
.dim {
opacity: .5;
}
+.button-secondary {
+ margin-left: 10px;
+}
+.aktt-form {
+ margin-bottom: 40px;
+}
.aktt-upgrade-needed {
- background: #ffc;
+ background: #c5e0ef url(<?php echo esc_url(plugins_url('assets/img/bg-clouds.png', AKTT_FILE)); ?>) bottom center repeat-x;
margin-top: 20px;
- padding: 20px;
+ padding: 15px 10px 5px;
+}
+.aktt-upgrade-needed h3,
+.aktt-upgrade-needed p {
+ margin: 0;
+ padding: 0 0 10px;
}
table.form-table {
margin: 20px 0;
@@ -43,59 +54,30 @@
}
.depends-on-create-posts {
background: #eee;
+ margin: 0 0 10px;
+ padding: 10px 10px 0;
}
.depends-on-create-posts.dim {
background: transparent;
}
-</style>
-<script>
-function akttSetState(elem) {
- var $account = jQuery(elem);
- var $settings = $account.find('.settings');
- var $enabled = $account.find('input.enabled');
- var $createPosts = $account.find('input.create-posts');
-// toggle enabled icon
- if (!$settings.is(':visible')) {
- if ($enabled.is(':checked')) {
- $account.addClass('aktt-account-enabled');
- }
- else {
- $account.addClass('dim');
- }
- }
-// toggle enabled/dimmed for enabled dependent fields
- if ($enabled.is(':checked')) {
- $account.find('.depends-on-enabled').removeClass('dim');
- }
- else {
- $account.find('.depends-on-enabled').addClass('dim');
- }
-// toggle enabled/dimmed for create blog posts dependent fields
- if ($createPosts.is(':checked')) {
- $account.find('.depends-on-create-posts').removeClass('dim');
- }
- else {
- $account.find('.depends-on-create-posts').addClass('dim');
- }
+.depends-on-create-posts h4,
+.depends-on-create-posts p {
+ margin: 0 0 10px;
+ padding: 0;
}
-jQuery(function($) {
-// toggle settings
- $('.aktt-account').each(function() {
- var $account = $(this);
- akttSetState($account);
- $account.find('h3').click(function() {
- $account.removeClass('dim aktt-account-enabled').find('.settings').slideToggle(function() {
- akttSetState($account);
- });
- }).end().find('input[type="checkbox"].enabled, input[type="checkbox"].create-posts').change(function() {
- akttSetState($account);
- });
- });
- $('#aktt-account-list').css({
- visibility: 'visible'
- });
-});
-</script>
+.depends-on-create-posts label.right {
+ display: block;
+ padding-left: 150px;
+}
+.depends-on-create-posts label.left {
+ display: block;
+ float: left;
+ width: 150px;
+}
+table.form-table .depends-on-create-posts .help {
+ color: #666;
+}
+</style>
<div class="wrap" id="<?php echo AKTT::$prefix.'options_page'; ?>">
<?php screen_icon(); ?>
<h2><?php _e('Twitter Tools', 'twitter-tools'); ?></h2>
@@ -105,13 +87,15 @@ function akttSetState(elem) {
if ($upgrade_needed || 1) {
?>
<div class="aktt-upgrade-needed">
- <a href="<?php echo esc_url(admin_url('index.php?aktt_action=upgrade-3.0')); ?>" class="aktt-upgrade-3.0 button-secondary"><?php _e('Upgrade Previous Twitter Tools Data', 'twitter-tools'); ?></a>
+ <h3><?php _e('Upgrade Needed!', 'twitter-tools'); ?></h3>
+ <p><?php _e('Looks like you have upgraded from a previous version of Twitter Tools.', 'twitter-tools'); ?>
+ <a href="<?php echo esc_url(admin_url('index.php?aktt_action=upgrade-3.0')); ?>" class="aktt-upgrade-3.0 button-secondary"><?php _e('Upgrade Your Tweets', 'twitter-tools'); ?></a></p>
</div>
<?php
}
?>
- <form method="post" action="<?php echo esc_url(admin_url('options.php')); ?>">
+ <form class="aktt-form" method="post" action="<?php echo esc_url(admin_url('options.php')); ?>">
<table class="form-table">
<?php
foreach (AKTT::$settings as $setting) {
@@ -184,11 +168,68 @@ function akttSetState(elem) {
</form>
<h3><?php _e('Download Tweets', 'twitter-tools'); ?></h3>
-
- <a href="<?php echo esc_url(AKTT::get_manual_update_url()); ?>" class="aktt-manual-update button-secondary"><?php _e('Download Tweets Now', 'twitter-tools'); ?></a>
+ <p>
+ <?php _e('Tweets are downloaded automatically every 15 minutes. Can\'t wait?', 'twitter-tools'); ?>
+ <a href="<?php echo esc_url(AKTT::get_manual_update_url()); ?>" class="aktt-manual-update button-secondary"><?php _e('Download Tweets Now', 'twitter-tools'); ?></a>
+ </p>
<?php
}
?>
</div><!-- /wrap -->
-
+<script>
+function akttSetState(elem) {
+ var $account = jQuery(elem);
+ var $settings = $account.find('.settings');
+ var $enabled = $account.find('input.enabled');
+ var $createPosts = $account.find('input.create-posts');
+// toggle enabled icon
+ if (!$settings.is(':visible')) {
+ if ($enabled.is(':checked')) {
+ $account.addClass('aktt-account-enabled');
+ }
+ else {
+ $account.addClass('dim');
+ }
+ }
+// toggle enabled/dimmed for enabled dependent fields
+ if ($enabled.is(':checked')) {
+ $account.find('.depends-on-enabled').removeClass('dim');
+ }
+ else {
+ $account.find('.depends-on-enabled').addClass('dim');
+ }
+// toggle enabled/dimmed for create blog posts dependent fields
+ if ($createPosts.is(':checked')) {
+ $account.find('.depends-on-create-posts').removeClass('dim');
+ }
+ else {
+ $account.find('.depends-on-create-posts').addClass('dim');
+ }
+}
+jQuery(function($) {
+// toggle settings
+ $('.aktt-account').each(function() {
+ var $account = $(this);
+ akttSetState($account);
+ $account.find('h3').click(function() {
+ $account.removeClass('dim aktt-account-enabled').find('.settings').slideToggle(function() {
+ akttSetState($account);
+ });
+ }).end().find('input[type="checkbox"].enabled, input[type="checkbox"].create-posts').change(function() {
+// if ($(this).filter('.create-posts').size()) {
+// if ($(this).is(':checked')) {
+// $account.find('.depends-on-create-posts').slideDown();
+// }
+// else {
+// $account.find('.depends-on-create-posts').slideUp();
+// }
+// }
+ akttSetState($account);
+ });
+ });
+ $('#aktt-account-list').css({
+ visibility: 'visible'
+ });
+});
+</script>

0 comments on commit 055d330

Please sign in to comment.