PluginProbe
Autover / 1.2
Autover v1.2
1.9 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
autover / autover.php

autover.php in Autover 1.2, at autover.php

282 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: AutoVer
4 * Plugin URI: http://wordpress.org/extend/plugins/autover/
5 * Description: Automatically version your CSS and JS files.
6 * Author: PressLabs
7 * Version: 1.2
8 * Author URI: http://www.presslabs.com/
9 */
10
11 //--------------------------------------------------------------------
12
13 function autover_activate() {
14 add_option('autover_dev_mode', array('1','1') );
15 }
16 register_activation_hook(__FILE__,'autover_activate');
17
18 //--------------------------------------------------------------------
19
20 function autover_deactivate() {
21 delete_option('autover_dev_mode');
22 }
23 register_deactivation_hook(__FILE__,'autover_deactivate');
24
25 //--------------------------------------------------------------------
26 //
27 // Add settings link on plugin page.
28 //
29 function autover_settings_link($links) {
30 $plugin = plugin_basename(__FILE__);
31 $settings_link = '<a href="tools.php?page='.$plugin.'">Settings</a>';
32 array_unshift($links, $settings_link);
33
34 return $links;
35 }
36
37 $plugin = plugin_basename(__FILE__);
38 add_filter("plugin_action_links_$plugin", 'autover_settings_link' );
39
40 //--------------------------------------------------------------------
41 //
42 // Return the string between 'start' and 'end' from 'conent'.
43 //
44 function autover_str_between( $start, $end, $content ) {
45 $r = explode($start, $content);
46
47 if (isset($r[1])) {
48 $r = explode($end, $r[1]);
49 return $r[0];
50 }
51
52 return '';
53 }
54
55 //--------------------------------------------------------------------
56 //
57 // Return the file with the new version.
58 //
59 function autover_version_filter($src) {
60 //
61 // Parse the url of the input file.
62 //
63 $src_parsed = parse_url( $src );
64 $src_path = $src_parsed["path"];
65
66 $filename = $_SERVER['DOCUMENT_ROOT'] . $src_path;
67 if ( is_file($filename) )
68 {
69 //
70 // Extract the modification time of the input file.
71 //
72 $timestamp_version = filemtime( $filename );
73
74 if ( $timestamp_version == NULL )
75 $timestamp_version = filemtime( utf8_decode($filename) );
76 } else {
77 return $src;
78 }
79
80 //
81 // If the file is not on the server then return the input file.
82 //
83 if ( ($timestamp_version == '') || ($timestamp_version == NULL) )
84 return $src;
85
86 //
87 // Remove the old version if exist.
88 //
89 $src_query = autover_str_between( '?', '#', $src . '#' ); // Find the query.
90 $src_with_no_query = str_replace( $src_query, '', $src ); // Remove query if exist.
91 $src_with_no_query = str_replace( '?', '', $src_with_no_query ); // Remove '?' char.
92
93 //
94 // Create the new version.
95 //
96 $src_with_new_version = $src_with_no_query . '?ver=' . $timestamp_version;
97
98 return $src_with_new_version;
99 }
100
101 //
102 // ASctivate/deactivate the filter if the options are set.
103 //
104 $autover_dev_mode = get_option('autover_dev_mode', array('','') );
105
106 if ( $autover_dev_mode[0] > '' )
107 add_filter( 'style_loader_src', 'autover_version_filter', 10, 1 );
108
109 if ( $autover_dev_mode[1] > '' )
110 add_filter( 'script_loader_src', 'autover_version_filter', 10, 1 );
111
112 //--------------------------------------------------------------------
113
114 function autover_update_options() {
115 $autover_dev_mode_value = array( '', '' );
116
117 $status = false;
118 if ( isset( $_POST['autover_dev_mode_style'] ) ) {
119 $autover_dev_mode_value[0] = '1';
120 $status = true;
121 }
122 if ( isset( $_POST['autover_dev_mode_script'] ) ) {
123 $autover_dev_mode_value[1] = '1';
124 $status = true;
125 }
126 update_option('autover_dev_mode', $autover_dev_mode_value);
127 //if ( ($autover_dev_mode_value[0]=='') && ($autover_dev_mode_value[1]=='') )
128 //$status = false;
129
130 if ($status) { ?>
131 <div id="message" class="updated fade">
132 <p><strong>Saved options!</strong></p>
133 </div>
134 <?php } else { ?>
135 <div id="message" class="error fade">
136 <p>
137 <strong>
138 <span style="color:brown;">
139 This plugin is currently not used!
140 </span>
141 </strong>
142 </p>
143 </div>
144 <?php }
145 }
146
147 //--------------------------------------------------------------------
148
149 function autover_options() {
150 isset( $_GET['tab'] ) ? $tab = $_GET['tab'] : $tab = 'important' ;
151
152 if ( isset( $_POST['submit_settings'] ) ) {
153 autover_update_options();
154 }
155 ?>
156
157 <div class="wrap">
158
159 <div id="icon-tools" class="icon32">&nbsp;</div>
160 <h2 class="nav-tab-wrapper">
161 <a class="nav-tab<?php if($tab=='important')echo' nav-tab-active';?>" href="tools.php?page=autover/autover.php&tab=important">
162 <span style="color:red;">IMPORTANT!</span></a>
163 <a class="nav-tab<?php if($tab=='settings')echo' nav-tab-active';?>" href="tools.php?page=autover/autover.php&tab=settings">Settings</a>
164 </h2>
165
166
167
168
169
170
171
172 <?php if ( $tab == 'important' ) { ?>
173
174 <p>
175 <h3><span style="color:red;font-weight:bold;">IMPORTANT !!!</span></h3>
176 If you want to use the functionality of this plugin you must add
177 <strong>CSS styles</strong> and <strong>JS scripts</strong> with WordPress function
178 <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script" target="_blank"><strong>'wp_enqueue_script'</strong></a> and
179 <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style" target="_blank"><strong>'wp_enqueue_style'</strong></a>.
180 </p>
181
182
183 <p>
184 <h3><span style="color:black;font-weight:bold;">Example:</span></h3>
185
186 <h3><span style="color:green;font-weight:bold;">YES</span></h3>
187 <img src="<?php echo plugins_url('/img/wp-enqueue.png', __FILE__); ?>" alt="wp-enqueue" title="CORRECT CODE">
188
189 <h3><span style="color:red;font-weight:bold;">NO</span></h3>
190 <img src="<?php echo plugins_url('/img/wp-head.png', __FILE__); ?>" alt="wp-head" title="DO NOT USE THIS CODE">
191
192 <h3 style="font-weight:normal;">If you want to use <strong>'wp_enqueue_style'</strong> to add your <strong>'style.css'</strong> of your theme.<br />Add the next code to your theme file <strong>'functions.php'</strong> <span style="color:red;font-weight:bold;">and remove your &lt;link&gt; tag</span> from <strong>'header.php'</strong> which refer to your <strong>'style.css'</strong>.</h3>
193 <img src="<?php echo plugins_url('/img/my-theme-name.png', __FILE__); ?>" alt="my-theme-name" title="add this code to 'functions.php' file">
194 </p>
195
196 <?php } ?>
197
198
199
200
201
202
203
204
205
206 <?php if ( $tab == 'settings' ) { ?>
207
208 <?php
209 $autover_dev_mode = get_option('autover_dev_mode');
210 $dev_mode_checked = array('','');
211 for ( $k = 0; $k < 2; $k++ )
212 if ( $autover_dev_mode[$k] == '1' )
213 $dev_mode_checked[$k] = ' checked="checked"';
214 ?>
215
216 <form method="post">
217 <table class="form-table">
218 <tbody>
219 <tr valign="top">
220 <th scope="row">
221 <label for="autover_dev_mode">Developer mode</label>
222 </th>
223 <td>
224 <fieldset>
225
226 <legend class="screen-reader-text"><span>Developer mode</span></legend>
227 <label for="autover_dev_mode_style">
228 <input name="autover_dev_mode_style" id="autover_dev_mode_style" value="<?php echo$autover_dev_mode[0];?>" type="checkbox"<?php echo$dev_mode_checked[0];?>>
229 <span>CSS files</span>
230 </label><br />
231
232 <label for="autover_dev_mode_script">
233 <input name="autover_dev_mode_script" id="autover_dev_mode_script" value="<?php echo$autover_dev_mode[1];?>" type="checkbox"<?php echo$dev_mode_checked[1];?>>
234 <span>JavaScript files</span>
235 </label><br />
236
237 <p class="description">The file type you want to rewrite the version.</p>
238
239 </fieldset>
240 </td>
241 </tr>
242
243 <tr valign="top">
244 <td>
245 </td>
246 </tr>
247 </tbody>
248 </table>
249
250 <p class="submit">
251 <input type="submit" class="button button-primary" name="submit_settings" value="Save Changes">
252 </p>
253
254 </form>
255
256 <?php } ?>
257
258
259
260
261
262
263
264
265
266 </div><!-- .wrap -->
267 <?php }
268
269 //--------------------------------------------------------------------
270
271 function autover_menu() {
272 add_management_page(
273 'AutoVer - Options', //'custom menu title',
274 'AutoVer', //'custom menu',
275 'administrator', //'add_users',
276 __FILE__, //$menu_slug,
277 'autover_options'
278 );
279 }
280 add_action('admin_menu', 'autover_menu');
281
282