| 1 |
<?php |
| 2 |
/** |
| 3 |
* class FeedWordPressSettingsUI: Module to package several functions related to the |
| 4 |
* WordPress administrative / settings interface. |
| 5 |
*/ |
| 6 |
class FeedWordPressSettingsUI { |
| 7 |
static function is_admin () { |
| 8 |
|
| 9 |
$admin_page = false; // Innocent until proven guilty |
| 10 |
if (!is_null(MyPHP::request('page'))) : |
| 11 |
$fwp = preg_quote(FeedWordPress::path()); |
| 12 |
$admin_page = ( |
| 13 |
is_admin() |
| 14 |
and preg_match("|^${fwp}/|", MyPHP::request('page')) |
| 15 |
); |
| 16 |
endif; |
| 17 |
return $admin_page; |
| 18 |
} |
| 19 |
|
| 20 |
static function admin_scripts () { |
| 21 |
wp_enqueue_script('post'); // for magic tag and category boxes |
| 22 |
wp_enqueue_script('admin-forms'); // for checkbox selection |
| 23 |
|
| 24 |
wp_register_script('feedwordpress-elements', plugins_url( 'assets/js/feedwordpress-elements.js', __FILE__ ) ); |
| 25 |
wp_enqueue_script('feedwordpress-elements'); |
| 26 |
} |
| 27 |
|
| 28 |
static function admin_styles () { |
| 29 |
?> |
| 30 |
<style type="text/css"> |
| 31 |
#feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x { |
| 32 |
background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll 0 0 transparent; |
| 33 |
} |
| 34 |
|
| 35 |
#feedwordpress-admin-feeds .link-rss-params-remove:hover .x, .feedwordpress-admin .remove-it:hover .x { |
| 36 |
background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll -10px 0 transparent; |
| 37 |
} |
| 38 |
|
| 39 |
.fwpfs { |
| 40 |
background-image: url(<?php print admin_url('images/fav.png'); ?>); |
| 41 |
background-repeat: repeat-x; |
| 42 |
background-position: left center; |
| 43 |
background-attachment: scroll; |
| 44 |
} |
| 45 |
.fwpfs.slide-down { |
| 46 |
background-image:url(<?php print admin_url('images/fav-top.png'); ?>); |
| 47 |
background-position:0 top; |
| 48 |
background-repeat:repeat-x; |
| 49 |
} |
| 50 |
|
| 51 |
.update-results { |
| 52 |
max-width: 100%; |
| 53 |
overflow: auto; |
| 54 |
} |
| 55 |
|
| 56 |
</style> |
| 57 |
<?php |
| 58 |
} /* FeedWordPressSettingsUI::admin_styles () */ |
| 59 |
|
| 60 |
static function ajax_nonce_fields () { |
| 61 |
if (function_exists('wp_nonce_field')) : |
| 62 |
echo "<form style='display: none' method='get' action=''>\n<p>\n"; |
| 63 |
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
| 64 |
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
| 65 |
echo "</p>\n</form>\n"; |
| 66 |
endif; |
| 67 |
} /* FeedWordPressSettingsUI::ajax_nonce_fields () */ |
| 68 |
|
| 69 |
static function fix_toggles_js ($context) { |
| 70 |
?> |
| 71 |
<script type="text/javascript"> |
| 72 |
jQuery(document).ready( function($) { |
| 73 |
// In case someone got here first... |
| 74 |
$('.postbox h3, .postbox .handlediv').unbind('click'); |
| 75 |
$('.postbox h3 a').unbind('click'); |
| 76 |
$('.hide-postbox-tog').unbind('click'); |
| 77 |
$('.columns-prefs input[type="radio"]').unbind('click'); |
| 78 |
$('.meta-box-sortables').sortable('destroy'); |
| 79 |
|
| 80 |
postboxes.add_postbox_toggles('<?php print $context; ?>'); |
| 81 |
} ); |
| 82 |
</script> |
| 83 |
<?php |
| 84 |
} /* FeedWordPressSettingsUI::fix_toggles_js () */ |
| 85 |
|
| 86 |
/** |
| 87 |
* get_template_part: load a template (usually templated HTML) from the FeedWordPress plugins |
| 88 |
* directory, in a way similar to the WordPress theme function get_template_part() loads a |
| 89 |
* template module from the theme directory. |
| 90 |
* |
| 91 |
* @param string $slug The slug name for the generic template |
| 92 |
* @param string $name The name of the specialized template |
| 93 |
* @param array $args Additional arguments passed to the template. |
| 94 |
*/ |
| 95 |
static public function get_template_part ( $slug, $name = null, $type = null, $args = array() ) { |
| 96 |
global $feedwordpress; |
| 97 |
|
| 98 |
do_action( "feedwordpress_get_template_part_${slug}", $slug, $name, $type, $args ); |
| 99 |
|
| 100 |
$templates = array(); |
| 101 |
$name = (string) $name; |
| 102 |
$type = (string) $type; |
| 103 |
|
| 104 |
$ext = ".php"; |
| 105 |
if ( strlen($type) > 0 ): |
| 106 |
$ext = ".${type}${ext}"; |
| 107 |
endif; |
| 108 |
|
| 109 |
if ( strlen($name) > 0 ) : |
| 110 |
$templates[] = "${slug}-${name}${ext}"; |
| 111 |
endif; |
| 112 |
$templates[] = "${slug}${ext}"; |
| 113 |
|
| 114 |
do_action( "feedwordpress_get_template_part", $slug, $name, $type, $args ); |
| 115 |
|
| 116 |
// locate_template |
| 117 |
$located = ''; |
| 118 |
foreach ( $templates as $template_name ) : |
| 119 |
if ( !! $template_name ) : |
| 120 |
$templatePath = $feedwordpress->plugin_dir_path('templates/' . $template_name); |
| 121 |
if ( is_readable( $templatePath ) ) : |
| 122 |
$located = $templatePath; |
| 123 |
break; |
| 124 |
endif; |
| 125 |
endif; |
| 126 |
endforeach; |
| 127 |
|
| 128 |
if ( strlen($located) > 0 ) : |
| 129 |
load_template( $located, /*require_once=*/ false, /*args=*/ $args ); |
| 130 |
endif; |
| 131 |
} /* FeedWordPressSettingsUI::get_template_part () */ |
| 132 |
|
| 133 |
static function magic_input_tip_js ($id) { |
| 134 |
if (!preg_match('/^[.#]/', $id)) : |
| 135 |
$id = '#'.$id; |
| 136 |
endif; |
| 137 |
?> |
| 138 |
<script type="text/javascript"> |
| 139 |
jQuery(document).ready( function () { |
| 140 |
var inputBox = jQuery("<?php print $id; ?>"); |
| 141 |
var boxEl = inputBox.get(0); |
| 142 |
if (boxEl.value==boxEl.defaultValue) { inputBox.addClass('form-input-tip'); } |
| 143 |
inputBox.focus(function() { |
| 144 |
if ( this.value == this.defaultValue ) |
| 145 |
jQuery(this).val( '' ).removeClass( 'form-input-tip' ); |
| 146 |
}); |
| 147 |
inputBox.blur(function() { |
| 148 |
if ( this.value == '' ) |
| 149 |
jQuery(this).val( this.defaultValue ).addClass( 'form-input-tip' ); |
| 150 |
}); |
| 151 |
} ); |
| 152 |
</script> |
| 153 |
<?php |
| 154 |
} /* FeedWordPressSettingsUI::magic_input_tip_js () */ |
| 155 |
} /* class FeedWordPressSettingsUI */ |
| 156 |
|
| 157 |
|