PluginProbe
Edit Flow / 0.7.3
Edit Flow v0.7.3
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / edit_flow.php

edit_flow.php in Edit Flow 0.7.3, at edit_flow.php

324 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Edit Flow
4 Plugin URI: http://editflow.org/
5 Description: Remixing the WordPress admin for better editorial workflow options.
6 Author: Daniel Bachhuber, Scott Bressler, Mohammad Jangda, Automattic, and others
7 Version: 0.7.3
8 Author URI: http://editflow.org/
9
10 Copyright 2009-2012 Mohammad Jangda, Daniel Bachhuber, et al.
11
12 GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
28 */
29
30 // Define contants
31 define( 'EDIT_FLOW_VERSION' , '0.7.3' );
32 define( 'EDIT_FLOW_ROOT' , dirname(__FILE__) );
33 define( 'EDIT_FLOW_FILE_PATH' , EDIT_FLOW_ROOT . '/' . basename(__FILE__) );
34 define( 'EDIT_FLOW_URL' , plugins_url( '/', __FILE__ ) );
35 define( 'EDIT_FLOW_SETTINGS_PAGE' , add_query_arg( 'page', 'ef-settings', get_admin_url( null, 'admin.php' ) ) );
36
37 // Core class
38 class edit_flow {
39
40 // Unique identified added as a prefix to all options
41 var $options_group = 'edit_flow_';
42 var $options_group_name = 'edit_flow_options';
43
44 /**
45 * Constructor
46 */
47 function __construct() {
48
49 load_plugin_textdomain( 'edit-flow', null, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
50
51 $this->modules = (object)array();
52
53 // Load all of our modules. 'ef_loaded' happens after 'plugins_loaded' so other plugins can
54 // hook into the action we have at the end
55 add_action( 'ef_loaded', array( $this, 'action_ef_loaded_load_modules' ) );
56
57 // Load the module options later on, and offer a function to happen way after init
58 add_action( 'init', array( $this, 'action_init' ) );
59 add_action( 'init', array( $this, 'action_init_after' ), 1000 );
60 add_action( 'admin_init', array( $this, 'action_admin_init' ) );
61
62 }
63
64 /**
65 * Include the common resources to Edit Flow and dynamically load the modules
66 */
67 function action_ef_loaded_load_modules() {
68
69 // We use the WP_List_Table API for some of the table gen
70 if ( !class_exists( 'WP_List_Table' ) )
71 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
72
73 // Edit Flow base module
74 require_once( EDIT_FLOW_ROOT . '/common/php/class-module.php' );
75
76 // Scan the modules directory and include any modules that exist there
77 $module_dirs = scandir( EDIT_FLOW_ROOT . '/modules/' );
78 $class_names = array();
79 foreach( $module_dirs as $module_dir ) {
80 if ( file_exists( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" ) ) {
81 include_once( EDIT_FLOW_ROOT . "/modules/{$module_dir}/$module_dir.php" );
82 // Prepare the class name because it should be standardized
83 $tmp = explode( '-', $module_dir );
84 $class_name = '';
85 $slug_name = '';
86 foreach( $tmp as $word ) {
87 $class_name .= ucfirst( $word ) . '_';
88 $slug_name .= $word . '_';
89 }
90 $slug_name = rtrim( $slug_name, '_' );
91 $class_names[$slug_name] = 'EF_' . rtrim( $class_name, '_' );
92 }
93 }
94
95 // Instantiate EF_Module as $helpers for back compat and so we can
96 // use it in this class
97 $this->helpers = new EF_Module();
98
99 // Other utils
100 require_once( EDIT_FLOW_ROOT . '/common/php/util.php' );
101
102 // Instantiate all of our classes onto the Edit Flow object
103 // but make sure they exist too
104 foreach( $class_names as $slug => $class_name ) {
105 if ( class_exists( $class_name ) ) {
106 $this->$slug = new $class_name();
107 }
108 }
109
110 // Supplementary plugins can hook into this, include their own modules
111 // and add them to the $edit_flow object
112 do_action( 'ef_modules_loaded' );
113
114 }
115
116 /**
117 * Inititalizes the Edit Flows!
118 * Loads options for each registered module and then initializes it if it's active
119 */
120 function action_init() {
121
122 // Load all of the module options
123 $this->load_module_options();
124
125 // Load all of the modules that are enabled.
126 // Modules won't have an options value if they aren't enabled
127 foreach ( $this->modules as $mod_name => $mod_data )
128 if ( isset( $mod_data->options->enabled ) && $mod_data->options->enabled == 'on' )
129 $this->$mod_name->init();
130
131 do_action( 'ef_init' );
132 }
133
134 /**
135 * Initialize the plugin for the admin
136 */
137 function action_admin_init() {
138
139 // Upgrade if need be but don't run the upgrade if the plugin has never been used
140 $previous_version = get_option( $this->options_group . 'version' );
141 if ( $previous_version && version_compare( $previous_version, EDIT_FLOW_VERSION, '<' ) ) {
142 foreach ( $this->modules as $mod_name => $mod_data ) {
143 if ( method_exists( $this->$mod_name, 'upgrade' ) )
144 $this->$mod_name->upgrade( $previous_version );
145 }
146 update_option( $this->options_group . 'version', EDIT_FLOW_VERSION );
147 } else if ( !$previous_version ) {
148 update_option( $this->options_group . 'version', EDIT_FLOW_VERSION );
149 }
150
151 // For each module that's been loaded, auto-load data if it's never been run before
152 foreach ( $this->modules as $mod_name => $mod_data ) {
153 // If the module has never been loaded before, run the install method if there is one
154 if ( !isset( $mod_data->options->loaded_once ) || !$mod_data->options->loaded_once ) {
155 if ( method_exists( $this->$mod_name, 'install' ) )
156 $this->$mod_name->install();
157 $this->update_module_option( $mod_name, 'loaded_once', true );
158 }
159 }
160
161 $this->register_scripts_and_styles();
162
163 }
164
165 /**
166 * Register a new module with Edit Flow
167 */
168 public function register_module( $name, $args = array() ) {
169
170 // A title and name is required for every module
171 if ( !isset( $args['title'], $name ) )
172 return false;
173
174 $defaults = array(
175 'title' => '',
176 'short_description' => '',
177 'extended_description' => '',
178 'img_url' => false,
179 'slug' => '',
180 'post_type_support' => '',
181 'default_options' => array(),
182 'options' => false,
183 'configure_page_cb' => false,
184 'configure_link_text' => __( 'Configure', 'edit-flow' ),
185 // These messages are applied to modules and can be overridden if custom messages are needed
186 'messages' => array(
187 'settings-updated' => __( 'Settings updated.', 'edit-flow' ),
188 'form-error' => __( 'Please correct your form errors below and try again.', 'edit-flow' ),
189 'nonce-failed' => __( 'Cheatin&#8217; uh?' ),
190 'invalid-permissions' => __( 'You do not have necessary permissions to complete this action.' ),
191 'missing-post' => __( 'Post does not exist', 'edit-flow' ),
192 ),
193 'autoload' => false, // autoloading a module will remove the ability to enable or disable it
194 'load_frontend' => false, // Whether or not the module should be loaded on the frontend too
195 );
196 if ( isset( $args['messages'] ) )
197 $args['messages'] = array_merge( (array)$args['messages'], $defaults['messages'] );
198 $args = array_merge( $defaults, $args );
199 $args['name'] = $name;
200 $args['options_group_name'] = $this->options_group . $name . '_options';
201 if ( !isset( $args['settings_slug'] ) )
202 $args['settings_slug'] = 'ef-' . $args['slug'] . '-settings';
203 if ( empty( $args['post_type_support'] ) )
204 $args['post_type_support'] = 'ef_' . $name;
205 // If there's a Help Screen registered for the module, make sure we
206 // auto-load it
207 if ( !empty( $args['settings_help_tab'] ) )
208 add_action( 'load-edit-flow_page_' . $args['settings_slug'], array( &$this->$name, 'action_settings_help_menu' ) );
209
210 $this->modules->$name = (object) $args;
211 do_action( 'ef_module_registered', $name );
212 return $this->modules->$name;
213 }
214
215 /**
216 * Load all of the module options from the database
217 * If a given option isn't yet set, then set it to the module's default (upgrades, etc.)
218 */
219 function load_module_options() {
220 foreach ( $this->modules as $mod_name => $mod_data ) {
221 // Don't load modules on the frontend unless they're explictly defined as such
222 if ( !is_admin() && !$mod_data->load_frontend )
223 continue;
224
225 $this->modules->$mod_name->options = get_option( $this->options_group . $mod_name . '_options' );
226 foreach ( $mod_data->default_options as $default_key => $default_value ) {
227 if ( !isset( $this->modules->$mod_name->options->$default_key ) )
228 $this->modules->$mod_name->options->$default_key = $default_value;
229 }
230
231 if ( isset( $this->modules->$mod_name->options->post_types ) )
232 $this->modules->$mod_name->options->post_types = $this->helpers->clean_post_type_options( $this->modules->$mod_name->options->post_types, $mod_data->post_type_support );
233
234 $this->$mod_name->module = $this->modules->$mod_name;
235 }
236 do_action( 'ef_module_options_loaded' );
237 }
238
239 /**
240 * Load the post type options again so we give add_post_type_support() a chance to work
241 *
242 * @see http://dev.editflow.org/2011/11/17/edit-flow-v0-7-alpha2-notes/#comment-232
243 */
244 function action_init_after() {
245 foreach ( $this->modules as $mod_name => $mod_data ) {
246 // Don't load modules on the frontend unless they're explictly defined as such
247 if ( !is_admin() && !$mod_data->load_frontend )
248 continue;
249
250 if ( isset( $this->modules->$mod_name->options->post_types ) )
251 $this->modules->$mod_name->options->post_types = $this->helpers->clean_post_type_options( $this->modules->$mod_name->options->post_types, $mod_data->post_type_support );
252
253 $this->$mod_name->module = $this->modules->$mod_name;
254 }
255 }
256
257 /**
258 * Get a module by one of its descriptive values
259 */
260 function get_module_by( $key, $value ) {
261 $module = false;
262 foreach ( $this->modules as $mod_name => $mod_data ) {
263
264 if ( $key == 'name' && $value == $mod_name ) {
265 $module = $this->modules->$mod_name;
266 } else {
267 foreach( $mod_data as $mod_data_key => $mod_data_value ) {
268 if ( $mod_data_key == $key && $mod_data_value == $value )
269 $module = $this->modules->$mod_name;
270 }
271 }
272 }
273 return $module;
274 }
275
276 /**
277 * Update the $edit_flow object with new value and save to the database
278 */
279 function update_module_option( $mod_name, $key, $value ) {
280 $this->modules->$mod_name->options->$key = $value;
281 $this->$mod_name->module = $this->modules->$mod_name;
282 return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options );
283 }
284
285 function update_all_module_options( $mod_name, $new_options ) {
286 if ( is_array( $new_options ) )
287 $new_options = (object)$new_options;
288 $this->modules->$mod_name->options = $new_options;
289 $this->$mod_name->module = $this->modules->$mod_name;
290 return update_option( $this->options_group . $mod_name . '_options', $this->modules->$mod_name->options );
291 }
292
293 /**
294 * Registers commonly used scripts + styles for easy enqueueing
295 */
296 function register_scripts_and_styles() {
297 wp_register_script( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/js/jquery.listfilterizer.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
298 wp_register_style( 'jquery-listfilterizer', EDIT_FLOW_URL . 'common/css/jquery.listfilterizer.css', false, EDIT_FLOW_VERSION, 'all' );
299
300 wp_register_script( 'jquery-quicksearch', EDIT_FLOW_URL . 'common/js/jquery.quicksearch.js', array( 'jquery' ), EDIT_FLOW_VERSION, true );
301
302 // @compat 3.3
303 // Register jQuery datepicker plugin if it doesn't already exist. Datepicker plugin was added in WordPress 3.3
304 global $wp_scripts;
305 if ( !isset( $wp_scripts->registered['jquery-ui-datepicker'] ) )
306 wp_register_script( 'jquery-ui-datepicker', EDIT_FLOW_URL . 'common/js/jquery.ui.datepicker.min.js', array( 'jquery', 'jquery-ui-core'), '1.8.16', true );
307 }
308
309 }
310
311 // Create new instance of the edit_flow object
312 global $edit_flow;
313 $edit_flow = new edit_flow();
314
315 /**
316 * ef_loaded()
317 * Allow dependent plugins and core actions to attach themselves in a safe way
318 */
319 function ef_loaded() {
320 do_action( 'ef_loaded' );
321 }
322 add_action( 'plugins_loaded', 'ef_loaded', 20 );
323
324 ?>