PluginProbe
FeedWordPress / trunk
FeedWordPress vtrunk
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpresssettingsui.class.php

feedwordpresssettingsui.class.php in FeedWordPress trunk, at feedwordpresssettingsui.class.php

194 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * class FeedWordPressSettingsUI: Module to package several functions related to the
4 * WordPress administrative / settings interface.
5 */
6 class FeedWordPressSettingsUI {
7 /**
8 * Checks if current user is an administrator with permissions to
9 * see the FWP dashboard.
10 *
11 * @return bool True if current user is an administrator.
12 *
13 * @uses is_admin()
14 * @uses FeedWordPress::path()
15 * @uses MyPHP::request()
16 */
17 static function is_admin() {
18 $admin_page = false; // Innocent until proven guilty
19 if ( ! is_null( MyPHP::request( 'page' ) ) ) :
20 $fwp = preg_quote( FeedWordPress::path() );
21 $admin_page = (
22 is_admin()
23 and preg_match( "|^{$fwp}/|", MyPHP::request( 'page' ) )
24 );
25 endif;
26 return $admin_page;
27 }
28
29 /**
30 * Enqueues JavaScript for the administration dashboard.
31 */
32 static function admin_scripts() {
33 wp_enqueue_script( 'post' ); // for magic tag and category boxes
34 wp_enqueue_script( 'admin-forms' ); // for checkbox selection
35
36 wp_register_script( 'feedwordpress-elements', plugins_url( 'assets/js/feedwordpress-elements.js', __FILE__ ) );
37 wp_enqueue_script( 'feedwordpress-elements' );
38 }
39
40 /**
41 * Sets the CSS for the administration dashboard.
42 *
43 * @todo At some point in the future, these ought to be changed to modern designs,
44 * i.e. either Dashicons or the upcoming SVG icon fonts. (gwyneth 20210717)
45 */
46 static function admin_styles() {
47 ?>
48 <style type="text/css">
49 #feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x {
50 content: "\f153"; /* dashicons-dismiss */
51 color: var(--wp-components-color-foreground,#1e1e1e);
52 background-color: var(--wp-components-color-background);
53 }
54 #feedwordpress-admin-feeds .link-rss-params-remove:hover .x, .feedwordpress-admin .remove-it:hover .x {
55 content: "\f153"; /* dashicons-dismiss */
56 color: var(--wp-components-color-accent);
57 background-color: var(--wp-components-color-background);
58 }
59
60 /* Note: the old images referred here were deprecated around 2009 or so and are *not*
61 part of the WordPress core any more; see https://core.trac.wordpress.org/ticket/20980
62 I have placed these missing images on the images folder instead (gwyneth 20210717) */
63 .fwpfs {
64 background-image: url(<?php echo esc_url( plugins_url( 'assets/images/fav.png', __FILE__ ) ); ?>);
65 background-repeat: repeat-x;
66 background-position: left center;
67 background-attachment: scroll;
68 }
69 .fwpfs.slide-down {
70 background-image: url(<?php echo esc_url( plugins_url( 'assets/images/fav-top.png', __FILE__ ) ); ?>);
71 background-position: 0 top;
72 background-repeat: repeat-x;
73 }
74 .update-results {
75 max-width: 100%;
76 overflow: auto;
77 }
78 </style>
79 <?php
80 } /* FeedWordPressSettingsUI::admin_styles () */
81
82 /**
83 * Makes sure we have nonce active.
84 *
85 * @uses wp_nonce_field()
86 */
87 static function ajax_nonce_fields() {
88 if ( function_exists( 'wp_nonce_field' ) ) :
89 echo "<form style='display: none' method='get' action=''>\n<p>\n";
90 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
91 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
92 echo "</p>\n</form>\n";
93 endif;
94 } /* FeedWordPressSettingsUI::ajax_nonce_fields () */
95
96 static function fix_toggles_js ($context) {
97 ?>
98 <script type="text/javascript">
99 jQuery(document).ready( function($) {
100 // In case someone got here first...
101 $('.postbox h3, .postbox .handlediv').unbind('click');
102 $('.postbox h3 a').unbind('click');
103 $('.hide-postbox-tog').unbind('click');
104 $('.columns-prefs input[type="radio"]').unbind('click');
105 $('.meta-box-sortables').sortable('destroy');
106
107 postboxes.add_postbox_toggles('<?php print esc_attr( $context ); ?>');
108 } );
109 </script>
110 <?php
111 } /* FeedWordPressSettingsUI::fix_toggles_js () */
112
113 /**
114 * get_template_part: load a template (usually templated HTML) from the FeedWordPress plugins
115 * directory, in a way similar to the WordPress theme function get_template_part() loads a
116 * template module from the theme directory.
117 *
118 * @param string $slug The slug name for the generic template
119 * @param string $name The name of the specialized template
120 * @param array $args Additional arguments passed to the template.
121 */
122 static public function get_template_part( $slug, $name = null, $type = null, $args = array() ) {
123 global $feedwordpress;
124
125 do_action( "feedwordpress_get_template_part_{$slug}", $slug, $name, $type, $args );
126
127 $templates = array();
128 $name = (string) $name;
129 $type = (string) $type;
130
131 $ext = ".php";
132 if ( strlen( $type ) > 0 ):
133 $ext = ".{$type}{$ext}";
134 endif;
135
136 if ( strlen( $name ) > 0 ) :
137 $templates[] = "{$slug}-{$name}{$ext}";
138 endif;
139 $templates[] = "{$slug}{$ext}";
140
141 do_action( "feedwordpress_get_template_part", $slug, $name, $type, $args );
142
143 // locate_template
144 $located = '';
145 foreach ( $templates as $template_name ) :
146 if ( !! $template_name ) :
147 $templatePath = $feedwordpress->plugin_dir_path( 'templates/' . $template_name );
148 if ( is_readable( $templatePath ) ) :
149 $located = $templatePath;
150 break;
151 endif;
152 endif;
153 endforeach;
154
155 if ( strlen( $located ) > 0 ) :
156 load_template( $located, /*require_once=*/ false, /*args=*/ $args );
157 endif;
158 } /* FeedWordPressSettingsUI::get_template_part () */
159
160 /**
161 * Generates contextual hovering text with tips for the form fields.
162 *
163 * How exactly this works is beyond myself. (gwyneth 20230916)
164 *
165 * @param string $id Apparently it's the field's id attribute.
166 *
167 */
168 static function magic_input_tip_js( $id ) {
169 if ( ! preg_match( '/^[.#]/', $id ) ) :
170 $id = '#' . $id;
171 endif;
172 ?>
173 <script type="text/javascript">
174 jQuery( document ).ready( function () {
175 var inputBox = jQuery( "<?php print esc_attr( $id ); ?>" );
176 var boxEl = inputBox.get( 0 );
177 if ( boxEl.value == boxEl.defaultValue ) {
178 inputBox.addClass( 'form-input-tip' );
179 }
180 inputBox.focus(function() {
181 if ( this.value == this.defaultValue )
182 jQuery( this ).val( '' ).removeClass( 'form-input-tip' );
183 });
184 inputBox.blur( function() {
185 if ( this.value == '' )
186 jQuery( this ).val( this.defaultValue ).addClass( 'form-input-tip' );
187 });
188 } );
189 </script>
190 <?php
191 } /* FeedWordPressSettingsUI::magic_input_tip_js () */
192 } /* class FeedWordPressSettingsUI */
193
194