Changeset 451789
- Timestamp:
- 10/17/2011 01:36:52 AM (14 years ago)
- Location:
- wp-mvc
- Files:
-
- 38 edited
-
tags/1.1.1/README.md (modified) (1 diff)
-
tags/1.1.1/core/controllers/mvc_controller.php (modified) (5 diffs)
-
tags/1.1.1/core/functions/functions.php (modified) (1 diff)
-
tags/1.1.1/core/helpers/mvc_form_helper.php (modified) (4 diffs)
-
tags/1.1.1/core/helpers/mvc_helper.php (modified) (8 diffs)
-
tags/1.1.1/core/models/mvc_data_validation_error.php (modified) (1 diff)
-
tags/1.1.1/core/models/mvc_database.php (modified) (1 diff)
-
tags/1.1.1/core/models/mvc_database_adapter.php (modified) (4 diffs)
-
tags/1.1.1/core/models/mvc_model.php (modified) (18 diffs)
-
tags/1.1.1/core/mvc_dispatcher.php (modified) (1 diff)
-
tags/1.1.1/core/mvc_file_includer.php (modified) (8 diffs)
-
tags/1.1.1/core/mvc_loader.php (modified) (15 diffs)
-
tags/1.1.1/core/mvc_plugin_loader.php (modified) (2 diffs)
-
tags/1.1.1/core/mvc_router.php (modified) (2 diffs)
-
tags/1.1.1/core/mvc_templater.php (modified) (1 diff)
-
tags/1.1.1/core/shells/generate_shell.php (modified) (1 diff)
-
tags/1.1.1/core/shells/mvc_shell.php (modified) (1 diff)
-
tags/1.1.1/core/templates/plugin/app/views/index.php (modified) (1 diff)
-
tags/1.1.1/readme.txt (modified) (1 diff)
-
trunk/README.md (modified) (1 diff)
-
trunk/core/controllers/mvc_controller.php (modified) (5 diffs)
-
trunk/core/functions/functions.php (modified) (1 diff)
-
trunk/core/helpers/mvc_form_helper.php (modified) (4 diffs)
-
trunk/core/helpers/mvc_helper.php (modified) (8 diffs)
-
trunk/core/models/mvc_data_validation_error.php (modified) (1 diff)
-
trunk/core/models/mvc_database.php (modified) (1 diff)
-
trunk/core/models/mvc_database_adapter.php (modified) (4 diffs)
-
trunk/core/models/mvc_model.php (modified) (18 diffs)
-
trunk/core/mvc_dispatcher.php (modified) (1 diff)
-
trunk/core/mvc_file_includer.php (modified) (8 diffs)
-
trunk/core/mvc_loader.php (modified) (15 diffs)
-
trunk/core/mvc_plugin_loader.php (modified) (2 diffs)
-
trunk/core/mvc_router.php (modified) (2 diffs)
-
trunk/core/mvc_templater.php (modified) (1 diff)
-
trunk/core/shells/generate_shell.php (modified) (1 diff)
-
trunk/core/shells/mvc_shell.php (modified) (1 diff)
-
trunk/core/templates/plugin/app/views/index.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-mvc/tags/1.1.1/README.md
r390557 r451789 21 21 1. Upload `wp-mvc` to the `wp-content/plugins/` directory 22 22 1. Activate the plugin through the 'Plugins' menu in WordPress 23 1. Make sure that [Pretty Permalinks](http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks) are enabled and working 23 24 1. Either set up the example plugin to see how WP MVC works or start creating an application using the code generation utility `wpmvc`: 24 25 -
wp-mvc/tags/1.1.1/core/controllers/mvc_controller.php
r390534 r451789 21 21 22 22 $models = MvcModelRegistry::get_models(); 23 foreach ($models as $model_name => $model) {23 foreach ($models as $model_name => $model) { 24 24 $underscore = MvcInflector::underscore($model_name); 25 25 $tableize = MvcInflector::tableize($model_name); … … 108 108 109 109 protected function load_models($model_names) { 110 foreach ($model_names as $model_name) {110 foreach ($model_names as $model_name) { 111 111 $this->load_model($model_name); 112 112 } … … 135 135 $this->set_view_var($variable_name_or_array, $data); 136 136 } else if (is_array($variable_name_or_array)) { 137 foreach ($variable_name_or_array as $key => $value) {137 foreach ($variable_name_or_array as $key => $value) { 138 138 $this->set_view_var($key, $value); 139 139 } … … 199 199 if (!empty($options['collection'])) { 200 200 $var_name = empty($options['as']) ? 'object' : $options['as']; 201 foreach ($options['collection'] as $object) {201 foreach ($options['collection'] as $object) { 202 202 $view_vars = array(); 203 203 $view_vars[$var_name] = $object; … … 273 273 $html = ''; 274 274 if (!empty($flashes)) { 275 foreach ($flashes as $type => $message) {275 foreach ($flashes as $type => $message) { 276 276 $classes = array(); 277 277 $classes[] = $type; -
wp-mvc/tags/1.1.1/core/functions/functions.php
r390534 r451789 72 72 $plugins = mvc_get_plugins(); 73 73 if (in_array($plugin, $plugins)) { 74 foreach ($plugins as $key => $existing_plugin) {74 foreach ($plugins as $key => $existing_plugin) { 75 75 if ($plugin == $existing_plugin) { 76 76 unset($plugins[$key]); -
wp-mvc/tags/1.1.1/core/helpers/mvc_form_helper.php
r437103 r451789 6 6 $defaults = array( 7 7 'action' => $this->controller->action, 8 'controller' => MvcInflector::tableize($model_name) 8 'controller' => MvcInflector::tableize($model_name), 9 'public' => false 9 10 ); 10 11 $options = array_merge($defaults, $options); … … 18 19 $router_options['id'] = $object_id; 19 20 } 20 $html = '<form action="'.MvcRouter::admin_url($router_options).'" method="post">'; 21 22 if ($options['public']) { 23 $html = '<form action="'.MvcRouter::public_url($router_options).'" method="post">'; 24 } else { 25 $html = '<form action="'.MvcRouter::admin_url($router_options).'" method="post">'; 26 } 27 21 28 if ($object_id) { 22 29 $html .= '<input type="hidden" id="'.$this->input_id('hidden_id').'" name="'.$this->input_name('id').'" value="'.$object_id.'" />'; … … 141 148 $html .= '<option value="">'.$empty_name.'</option>'; 142 149 } 143 foreach ($options['options'] as $key => $value) {150 foreach ($options['options'] as $key => $value) { 144 151 if (is_object($value)) { 145 152 $key = $value->__id; … … 223 230 224 231 $html .= '<ul id="'.$options['list_id'].'">'; 225 foreach ($associated_objects as $associated_object) {232 foreach ($associated_objects as $associated_object) { 226 233 $html .= ' 227 234 <li> -
wp-mvc/tags/1.1.1/core/helpers/mvc_helper.php
r437103 r451789 82 82 'align', 83 83 'alt', 84 'autocomplete', 84 85 'checked', 85 86 'class', … … 90 91 'maxlength', 91 92 'name', 93 'placeholder', 92 94 'readonly', 95 'required', 93 96 'size', 94 97 'src', … … 109 112 'id', 110 113 'lang', 114 'maxlength', 111 115 'name', 112 116 'readonly', … … 135 139 ); 136 140 137 foreach ($valid_attributes_by_tag as $key => $valid_attributes) {141 foreach ($valid_attributes_by_tag as $key => $valid_attributes) { 138 142 $valid_attributes = array_merge($event_attributes['standard'], $valid_attributes); 139 143 $valid_attributes = self::array_flatten($valid_attributes); … … 146 150 147 151 $attributes_html = ''; 148 foreach ($attributes as $key => $value) {152 foreach ($attributes as $key => $value) { 149 153 $attributes_html .= ' '.$key.'="'.esc_attr($value).'"'; 150 154 } … … 157 161 public function admin_header_cells($model) { 158 162 $html = ''; 159 foreach ($model->admin_columns as $key => $column) {163 foreach ($model->admin_columns as $key => $column) { 160 164 $html .= $this->admin_header_cell($column['label']); 161 165 } … … 171 175 public function admin_table_cells($model, $objects) { 172 176 $html = ''; 173 foreach ($objects as $object) {177 foreach ($objects as $object) { 174 178 $html .= '<tr>'; 175 foreach ($model->admin_columns as $key => $column) {179 foreach ($model->admin_columns as $key => $column) { 176 180 $html .= $this->admin_table_cell($model, $object, $column); 177 181 } … … 207 211 private function array_flatten($array) { 208 212 209 foreach ($array as $key => $value){213 foreach ($array as $key => $value){ 210 214 $array[$key] = (array)$value; 211 215 } -
wp-mvc/tags/1.1.1/core/models/mvc_data_validation_error.php
r376739 r451789 27 27 } 28 28 $html = ''; 29 foreach ($this->errors as $error) {29 foreach ($this->errors as $error) { 30 30 $html .= ' 31 31 <div class="mvc-validation-error"> -
wp-mvc/tags/1.1.1/core/models/mvc_database.php
r371344 r451789 32 32 33 33 public function escape_array($array) { 34 foreach ($array as $key => $value) {34 foreach ($array as $key => $value) { 35 35 $array[$key] = $this->escape($value); 36 36 } -
wp-mvc/tags/1.1.1/core/models/mvc_database_adapter.php
r390534 r451789 67 67 $joins = array($joins); 68 68 } 69 foreach ($joins as $join) {69 foreach ($joins as $join) { 70 70 $type = empty($join['type']) ? 'JOIN' : $join['type']; 71 71 $clauses[] = $type.' '.$join['table'].' '.$join['alias'].' ON '.$join['on']; … … 89 89 $use_table_alias = isset($options['use_table_alias']) ? $options['use_table_alias'] : true; 90 90 $sql_clauses = array(); 91 foreach ($conditions as $key => $value) {91 foreach ($conditions as $key => $value) { 92 92 if (is_array($value)) { 93 93 $clauses = $this->get_where_sql_clauses($value); … … 123 123 public function get_set_sql($data) { 124 124 $clauses = array(); 125 foreach ($data as $key => $value) {125 foreach ($data as $key => $value) { 126 126 if (is_string($value) || is_numeric($value)) { 127 127 $clauses[] = $key.' = "'.$this->db->escape($value).'"'; … … 141 141 public function get_insert_values_sql($data) { 142 142 $values = array(); 143 foreach ($data as $value) {143 foreach ($data as $value) { 144 144 $values[] = '"'.$this->db->escape($value).'"'; 145 145 } -
wp-mvc/tags/1.1.1/core/models/mvc_model.php
r438768 r451789 12 12 public $validation_error = null; 13 13 public $validation_error_html = null; 14 public $hide_menu = false; 14 15 private $data_validator = null; 15 16 private $db_adapter = null; … … 37 38 ); 38 39 39 foreach ($defaults as $key => $value) {40 foreach ($defaults as $key => $value) { 40 41 $this->{$key} = $value; 41 42 } … … 55 56 public function new_object($data) { 56 57 $object = false; 57 foreach ($data as $field => $value) {58 foreach ($data as $field => $value) { 58 59 $object->{$field} = $value; 59 60 } … … 179 180 } 180 181 $formatted_fields = array(); 181 foreach ($fields as $field) {182 foreach ($fields as $field) { 182 183 if (strpos($field, '.') === false) { 183 184 $field = $this->name.'.'.$field; … … 190 191 $field_reference = 'CONCAT('.implode(', ', $formatted_fields).')'; 191 192 } 192 foreach ($keywords as $keyword) {193 foreach ($keywords as $keyword) { 193 194 $conditions[] = array($field_reference.' LIKE' => '%'.$keyword.'%'); 194 195 } … … 210 211 $options['joins'] = array($options['joins']); 211 212 } 212 foreach ($options['joins'] as $key => $join) {213 foreach ($options['joins'] as $key => $join) { 213 214 if (is_string($join)) { 214 215 $join_model_name = $join; … … 263 264 private function update_associations($id, $model_data) { 264 265 if (!empty($this->associations)) { 265 foreach ($this->associations as $association) {266 foreach ($this->associations as $association) { 266 267 switch($association['type']) { 267 268 case 'has_many': … … 298 299 )); 299 300 if (!empty($model_data[$association_name]['ids'])) { 300 foreach ($model_data[$association_name]['ids'] as $association_id) {301 foreach ($model_data[$association_name]['ids'] as $association_id) { 301 302 if (!empty($association_id)) { 302 303 $this->db_adapter->insert( … … 319 320 $rules = $this->validate; 320 321 if (!empty($rules)) { 321 foreach ($rules as $field => $rule) {322 foreach ($rules as $field => $rule) { 322 323 if (isset($data[$field])) { 323 324 $valid = $this->data_validator->validate($field, $data[$field], $rule); … … 350 351 } 351 352 $admin_pages = array(); 352 foreach ($this->admin_pages as $key => $value) {353 foreach ($this->admin_pages as $key => $value) { 353 354 if (is_int($key)) { 354 355 $key = $value; … … 372 373 private function init_admin_columns() { 373 374 $admin_columns = array(); 374 foreach ($this->admin_columns as $key => $value) {375 foreach ($this->admin_columns as $key => $value) { 375 376 if (is_array($value)) { 376 377 if (!isset($value['label'])) { … … 412 413 // Instantiate associated models, so that they don't need to be instantiated multiple times in the subsequent for loop 413 414 $models = array(); 414 foreach ($includes as $key => $include) {415 foreach ($includes as $key => $include) { 415 416 $model_name = is_string($include) ? $include : $key; 416 417 $models[$model_name] = new $model_name(); … … 420 421 $recursive = isset($options['recursive']) ? $options['recursive'] - 1 : 2; 421 422 422 foreach ($objects as $key => $object) {423 foreach ($objects as $key => $object) { 423 424 424 425 if (!empty($this->primary_key)) { … … 427 428 428 429 if (!empty($includes) && $recursive != 0) { 429 foreach ($includes as $include_key => $include) {430 foreach ($includes as $include_key => $include) { 430 431 if (is_string($include)) { 431 432 $model_name = $include; … … 514 515 $schema = array(); 515 516 516 foreach ($results as $result) {517 foreach ($results as $result) { 517 518 $field = $result->Field; 518 519 $type_schema = explode('(', $result->Type); … … 535 536 protected function init_associations() { 536 537 if (!empty($this->belongs_to)) { 537 foreach ($this->belongs_to as $key => $value) {538 foreach ($this->belongs_to as $key => $value) { 538 539 $config = null; 539 540 if (is_string($value)) { … … 565 566 } 566 567 if (!empty($this->has_many)) { 567 foreach ($this->has_many as $association) {568 foreach ($this->has_many as $association) { 568 569 if (is_string($association)) { 569 570 if (!is_array($this->associations)) { … … 582 583 } 583 584 if (!empty($this->has_and_belongs_to_many)) { 584 foreach ($this->has_and_belongs_to_many as $association_name => $association) {585 foreach ($this->has_and_belongs_to_many as $association_name => $association) { 585 586 if (!is_array($this->associations)) { 586 587 $this->associations = array(); 587 588 } 588 589 if (isset($association['fields'])) { 589 foreach ($association['fields'] as $key => $field) {590 foreach ($association['fields'] as $key => $field) { 590 591 $association['fields'][$key] = $association_name.'.'.$field; 591 592 } -
wp-mvc/tags/1.1.1/core/mvc_dispatcher.php
r390534 r451789 45 45 private function escape_params($params) { 46 46 if (is_array($params)) { 47 foreach ($params as $key => $value) {47 foreach ($params as $key => $value) { 48 48 if (is_string($value)) { 49 49 $params[$key] = stripslashes($value); -
wp-mvc/tags/1.1.1/core/mvc_file_includer.php
r390534 r451789 12 12 13 13 public function find_first_app_file_or_core_file($filepath) { 14 foreach ($this->plugin_app_paths as $plugin_app_path) {14 foreach ($this->plugin_app_paths as $plugin_app_path) { 15 15 if (file_exists($plugin_app_path.$filepath)) { 16 16 return $plugin_app_path.$filepath; … … 49 49 50 50 public function require_first_app_file($filepath) { 51 foreach ($this->plugin_app_paths as $plugin_app_path) {51 foreach ($this->plugin_app_paths as $plugin_app_path) { 52 52 if ($this->include_file($plugin_app_path.$filepath)) { 53 53 return true; … … 59 59 public function include_all_app_files($filepath) { 60 60 $included = false; 61 foreach ($this->plugin_app_paths as $plugin_app_path) {61 foreach ($this->plugin_app_paths as $plugin_app_path) { 62 62 if ($this->include_file($plugin_app_path.$filepath)) { 63 63 $included = true; … … 72 72 73 73 public function include_first_app_file($filepath) { 74 foreach ($this->plugin_app_paths as $plugin_app_path) {74 foreach ($this->plugin_app_paths as $plugin_app_path) { 75 75 if ($this->include_file($plugin_app_path.$filepath)) { 76 76 return true; … … 81 81 82 82 public function include_first_app_file_or_core_file($filepath) { 83 foreach ($this->plugin_app_paths as $plugin_app_path) {83 foreach ($this->plugin_app_paths as $plugin_app_path) { 84 84 if ($this->include_file($plugin_app_path.$filepath)) { 85 85 return true; … … 96 96 public function require_all_app_files($filepath) { 97 97 $included = false; 98 foreach ($this->plugin_app_paths as $plugin_app_path) {98 foreach ($this->plugin_app_paths as $plugin_app_path) { 99 99 if ($this->include_require_file($plugin_app_path.$filepath)) { 100 100 $included = true; … … 125 125 $filepaths = array(); 126 126 127 foreach ($filenames as $filename) {127 foreach ($filenames as $filename) { 128 128 $filepath = $directory.$filename; 129 129 $filepaths[] = $filepath; … … 156 156 $files = array(); 157 157 158 foreach ($file_tmp as $item){158 foreach ($file_tmp as $item){ 159 159 if (substr($item, -1) != DIRECTORY_SEPARATOR) { 160 160 $files[] = $item; -
wp-mvc/tags/1.1.1/core/mvc_loader.php
r390534 r451789 60 60 ); 61 61 62 foreach ($files as $file) {62 foreach ($files as $file) { 63 63 require_once $this->core_path.$file.'.php'; 64 64 } … … 70 70 $plugins = $this->get_ordered_plugins(); 71 71 $plugin_app_paths = array(); 72 foreach ($plugins as $plugin) {72 foreach ($plugins as $plugin) { 73 73 $plugin_app_paths[$plugin] = rtrim(WP_PLUGIN_DIR, '/').'/'.$plugin.'/app/'; 74 74 } … … 127 127 private function load_controllers() { 128 128 129 foreach ($this->plugin_app_paths as $plugin_app_path) {129 foreach ($this->plugin_app_paths as $plugin_app_path) { 130 130 131 131 $admin_controller_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path.'controllers/admin/'); 132 132 $public_controller_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path.'controllers/'); 133 133 134 foreach ($admin_controller_filenames as $filename) {134 foreach ($admin_controller_filenames as $filename) { 135 135 if (preg_match('/admin_([^\/]+)_controller\.php/', $filename, $match)) { 136 136 $this->admin_controller_names[] = $match[1]; … … 138 138 } 139 139 140 foreach ($public_controller_filenames as $filename) {140 foreach ($public_controller_filenames as $filename) { 141 141 if (preg_match('/([^\/]+)_controller\.php/', $filename, $match)) { 142 142 $this->public_controller_names[] = $match[1]; … … 150 150 private function load_libs() { 151 151 152 foreach ($this->plugin_app_paths as $plugin_app_path) {152 foreach ($this->plugin_app_paths as $plugin_app_path) { 153 153 154 154 $this->file_includer->require_php_files_in_directory($plugin_app_path.'libs/'); … … 162 162 $models = array(); 163 163 164 foreach ($this->plugin_app_paths as $plugin_app_path) {164 foreach ($this->plugin_app_paths as $plugin_app_path) { 165 165 166 166 $model_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path.'models/'); 167 167 168 foreach ($model_filenames as $filename) {168 foreach ($model_filenames as $filename) { 169 169 $models[] = MvcInflector::class_name_from_filename($filename); 170 170 } … … 174 174 $this->model_names = array(); 175 175 176 foreach ($models as $model) {176 foreach ($models as $model) { 177 177 $this->model_names[] = $model; 178 178 $model_class = MvcInflector::camelize($model); … … 219 219 do_action('mvc_admin_init', $mvc_admin_init_args); 220 220 221 $title = MvcInflector::titleize($controller);221 $title = MvcInflector::titleize($controller); 222 222 if (!empty($action) && $action != 'index') { 223 223 $title = MvcInflector::titleize($action).' ‹ '.$title; … … 237 237 $menu_position = apply_filters('mvc_menu_position', $menu_position); 238 238 239 foreach ($this->model_names as $model_name) {239 foreach ($this->model_names as $model_name) { 240 240 241 241 $model = MvcModelRegistry::get_model($model_name); 242 $tableized = MvcInflector::tableize($model_name); 243 $pluralized = MvcInflector::pluralize($model_name); 244 $titleized = MvcInflector::titleize($model_name); 245 $pluralize_titleized = MvcInflector::pluralize_titleize($model_name); 246 247 $controller_name = 'admin_'.$tableized; 248 249 $top_level_handle = 'mvc_'.$tableized; 250 251 $admin_pages = $model->admin_pages; 252 253 $method = $controller_name.'_index'; 254 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "index"));'); 255 add_menu_page( 256 $pluralize_titleized, 257 $pluralize_titleized, 258 'administrator', 259 $top_level_handle, 260 array($this->dispatcher, $method), 261 null, 262 $menu_position 263 ); 264 265 foreach($admin_pages as $key => $admin_page) { 242 243 if (!$model->hide_menu) { 244 $tableized = MvcInflector::tableize($model_name); 245 $pluralized = MvcInflector::pluralize($model_name); 246 $titleized = MvcInflector::titleize($model_name); 247 $pluralize_titleized = MvcInflector::pluralize_titleize($model_name); 248 249 $controller_name = 'admin_'.$tableized; 250 251 $top_level_handle = 'mvc_'.$tableized; 252 253 $admin_pages = $model->admin_pages; 254 255 $method = $controller_name.'_index'; 256 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "index"));'); 257 add_menu_page( 258 $pluralize_titleized, 259 $pluralize_titleized, 260 'administrator', 261 $top_level_handle, 262 array($this->dispatcher, $method), 263 null, 264 $menu_position 265 ); 266 267 foreach ($admin_pages as $key => $admin_page) { 266 268 267 $method = $controller_name.'_'.$admin_page['action'];269 $method = $controller_name.'_'.$admin_page['action']; 268 270 269 if (!method_exists($this->dispatcher, $method)) { 270 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "'.$admin_page['action'].'"));'); 271 if (!method_exists($this->dispatcher, $method)) { 272 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "'.$admin_page['action'].'"));'); 273 } 274 275 $page_handle = $top_level_handle.'-'.$key; 276 277 if ($admin_page['in_menu']) { 278 add_submenu_page( 279 $top_level_handle, 280 $admin_page['label'].' ‹ '.$pluralize_titleized, 281 $admin_page['label'], 282 $admin_page['capability'], 283 $page_handle, 284 array($this->dispatcher, $method) 285 ); 286 } else { 287 // It looks like there isn't a more native way of creating an admin page without 288 // having it show up in the menu, but if there is, it should be implemented here. 289 // To do: set up capability handling and page title handling for these pages that aren't in the menu 290 $hookname = get_plugin_page_hookname($page_handle,''); 291 if (!empty($hookname)) { 292 add_action($hookname, array($this->dispatcher, $method)); 293 } 294 $_registered_pages[$hookname] = true; 295 } 296 271 297 } 272 273 $page_handle = $top_level_handle.'-'.$key; 274 275 if ($admin_page['in_menu']) { 276 add_submenu_page( 277 $top_level_handle, 278 $admin_page['label'].' ‹ '.$pluralize_titleized, 279 $admin_page['label'], 280 $admin_page['capability'], 281 $page_handle, 282 array($this->dispatcher, $method) 283 ); 284 } else { 285 // It looks like there isn't a more native way of creating an admin page without 286 // having it show up in the menu, but if there is, it should be implemented here. 287 // To do: set up capability handling and page title handling for these pages that aren't in the menu 288 $hookname = get_plugin_page_hookname($page_handle,''); 289 if (!empty($hookname)) { 290 add_action($hookname, array($this->dispatcher, $method)); 291 } 292 $_registered_pages[$hookname] = true; 293 } 294 295 } 296 $menu_position++; 297 298 $menu_position++; 299 300 } 298 301 } 299 302 … … 321 324 } 322 325 323 foreach ($routes as $route) {326 foreach ($routes as $route) { 324 327 325 328 $route_path = $route[0]; … … 327 330 328 331 if (strpos($route_path, '{:controller}') !== false) { 329 foreach ($this->public_controller_names as $controller) {332 foreach ($this->public_controller_names as $controller) { 330 333 $route_rules = $this->get_rewrite_rules($route_path, $route_defaults, $controller); 331 334 $new_rules = array_merge($new_rules, $route_rules); … … 354 357 // and append them to the match string for use in a WP rewrite rule 355 358 preg_match_all('/{:(.+?)(:.*?)?}/', $rewrite_path, $matches); 356 foreach ($matches[1] as $query_var) {359 foreach ($matches[1] as $query_var) { 357 360 $query_var = 'mvc_'.$query_var; 358 361 if ($query_var != 'mvc_controller') { … … 365 368 // Do the same as above for route params that are defined as route defaults (e.g. array('action' => 'show')) 366 369 if (!empty($route_defaults)) { 367 foreach ($route_defaults as $query_var => $value) {370 foreach ($route_defaults as $query_var => $value) { 368 371 $query_var = 'mvc_'.$query_var; 369 372 if ($query_var != 'mvc_controller') { … … 404 407 $query_params = $wp_query->query; 405 408 $params = array(); 406 foreach ($query_params as $key => $value) {409 foreach ($query_params as $key => $value) { 407 410 $key = preg_replace('/^(mvc_)/', '', $key); 408 411 $params[$key] = $value; … … 429 432 $routes = MvcRouter::get_admin_ajax_routes(); 430 433 if (!empty($routes)) { 431 foreach ($routes as $route) {434 foreach ($routes as $route) { 432 435 $route['is_admin_ajax'] = true; 433 436 $method = 'admin_ajax_'.$route['wp_action']; -
wp-mvc/tags/1.1.1/core/mvc_plugin_loader.php
r390534 r451789 39 39 $plugins = $this->get_plugins(); 40 40 if (in_array($plugin, $plugins)) { 41 foreach ($plugins as $key => $existing_plugin) {41 foreach ($plugins as $key => $existing_plugin) { 42 42 if ($plugin == $existing_plugin) { 43 43 unset($plugins[$key]); … … 57 57 58 58 protected function filter_nonexistent_plugins($plugins) { 59 foreach ($plugins as $key => $plugin) {59 foreach ($plugins as $key => $plugin) { 60 60 if (!is_dir(WP_PLUGIN_DIR.'/'.$plugin)) { 61 61 unset($plugins[$key]); -
wp-mvc/tags/1.1.1/core/mvc_router.php
r390534 r451789 22 22 } 23 23 } 24 foreach ($routes as $route) {24 foreach ($routes as $route) { 25 25 $route_path = $route[0]; 26 26 $route_defaults = $route[1]; … … 36 36 preg_match_all('/{:([\w]+).*?}/', $path_pattern, $matches, PREG_SET_ORDER); 37 37 $path = $path_pattern; 38 foreach ($matches as $match) {38 foreach ($matches as $match) { 39 39 $pattern = $match[0]; 40 40 $option_key = $match[1]; -
wp-mvc/tags/1.1.1/core/mvc_templater.php
r371570 r451789 14 14 $this->set_template_var($variable_name_or_array, $data); 15 15 } else if (is_array($variable_name_or_array)) { 16 foreach ($variable_name_or_array as $key => $value) {16 foreach ($variable_name_or_array as $key => $value) { 17 17 $this->set_template_var($key, $value); 18 18 } -
wp-mvc/tags/1.1.1/core/shells/generate_shell.php
r437103 r451789 62 62 'views/admin' 63 63 ); 64 foreach ($app_directories as $path) {64 foreach ($app_directories as $path) { 65 65 $directory->create($plugin_app_path.$path.'/'); 66 66 } -
wp-mvc/tags/1.1.1/core/shells/mvc_shell.php
r390534 r451789 52 52 53 53 protected function load_models($model_names) { 54 foreach ($model_names as $model_name) {54 foreach ($model_names as $model_name) { 55 55 $this->load_model($model_name); 56 56 } -
wp-mvc/tags/1.1.1/core/templates/plugin/app/views/index.php
r390534 r451789 2 2 <?php 3 3 echo ' 4 <?php foreach ($objects as $object): ?>4 <?php foreach ($objects as $object): ?> 5 5 6 6 <?php $this->render_view(\'_item\', array(\'locals\' => array(\'object\' => $object))); ?> -
wp-mvc/tags/1.1.1/readme.txt
r437103 r451789 24 24 1. Upload `wp-mvc` to the `wp-content/plugins/` directory 25 25 1. Activate the plugin through the 'Plugins' menu in WordPress 26 1. Make sure that [Pretty Permalinks](http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks) are enabled and working 26 27 1. Either set up the example plugin to see how WP MVC works or start creating an application using the code generation utility `wpmvc`: 27 28 -
wp-mvc/trunk/README.md
r390557 r451789 21 21 1. Upload `wp-mvc` to the `wp-content/plugins/` directory 22 22 1. Activate the plugin through the 'Plugins' menu in WordPress 23 1. Make sure that [Pretty Permalinks](http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks) are enabled and working 23 24 1. Either set up the example plugin to see how WP MVC works or start creating an application using the code generation utility `wpmvc`: 24 25 -
wp-mvc/trunk/core/controllers/mvc_controller.php
r390534 r451789 21 21 22 22 $models = MvcModelRegistry::get_models(); 23 foreach ($models as $model_name => $model) {23 foreach ($models as $model_name => $model) { 24 24 $underscore = MvcInflector::underscore($model_name); 25 25 $tableize = MvcInflector::tableize($model_name); … … 108 108 109 109 protected function load_models($model_names) { 110 foreach ($model_names as $model_name) {110 foreach ($model_names as $model_name) { 111 111 $this->load_model($model_name); 112 112 } … … 135 135 $this->set_view_var($variable_name_or_array, $data); 136 136 } else if (is_array($variable_name_or_array)) { 137 foreach ($variable_name_or_array as $key => $value) {137 foreach ($variable_name_or_array as $key => $value) { 138 138 $this->set_view_var($key, $value); 139 139 } … … 199 199 if (!empty($options['collection'])) { 200 200 $var_name = empty($options['as']) ? 'object' : $options['as']; 201 foreach ($options['collection'] as $object) {201 foreach ($options['collection'] as $object) { 202 202 $view_vars = array(); 203 203 $view_vars[$var_name] = $object; … … 273 273 $html = ''; 274 274 if (!empty($flashes)) { 275 foreach ($flashes as $type => $message) {275 foreach ($flashes as $type => $message) { 276 276 $classes = array(); 277 277 $classes[] = $type; -
wp-mvc/trunk/core/functions/functions.php
r390534 r451789 72 72 $plugins = mvc_get_plugins(); 73 73 if (in_array($plugin, $plugins)) { 74 foreach ($plugins as $key => $existing_plugin) {74 foreach ($plugins as $key => $existing_plugin) { 75 75 if ($plugin == $existing_plugin) { 76 76 unset($plugins[$key]); -
wp-mvc/trunk/core/helpers/mvc_form_helper.php
r437103 r451789 6 6 $defaults = array( 7 7 'action' => $this->controller->action, 8 'controller' => MvcInflector::tableize($model_name) 8 'controller' => MvcInflector::tableize($model_name), 9 'public' => false 9 10 ); 10 11 $options = array_merge($defaults, $options); … … 18 19 $router_options['id'] = $object_id; 19 20 } 20 $html = '<form action="'.MvcRouter::admin_url($router_options).'" method="post">'; 21 22 if ($options['public']) { 23 $html = '<form action="'.MvcRouter::public_url($router_options).'" method="post">'; 24 } else { 25 $html = '<form action="'.MvcRouter::admin_url($router_options).'" method="post">'; 26 } 27 21 28 if ($object_id) { 22 29 $html .= '<input type="hidden" id="'.$this->input_id('hidden_id').'" name="'.$this->input_name('id').'" value="'.$object_id.'" />'; … … 141 148 $html .= '<option value="">'.$empty_name.'</option>'; 142 149 } 143 foreach ($options['options'] as $key => $value) {150 foreach ($options['options'] as $key => $value) { 144 151 if (is_object($value)) { 145 152 $key = $value->__id; … … 223 230 224 231 $html .= '<ul id="'.$options['list_id'].'">'; 225 foreach ($associated_objects as $associated_object) {232 foreach ($associated_objects as $associated_object) { 226 233 $html .= ' 227 234 <li> -
wp-mvc/trunk/core/helpers/mvc_helper.php
r437103 r451789 82 82 'align', 83 83 'alt', 84 'autocomplete', 84 85 'checked', 85 86 'class', … … 90 91 'maxlength', 91 92 'name', 93 'placeholder', 92 94 'readonly', 95 'required', 93 96 'size', 94 97 'src', … … 109 112 'id', 110 113 'lang', 114 'maxlength', 111 115 'name', 112 116 'readonly', … … 135 139 ); 136 140 137 foreach ($valid_attributes_by_tag as $key => $valid_attributes) {141 foreach ($valid_attributes_by_tag as $key => $valid_attributes) { 138 142 $valid_attributes = array_merge($event_attributes['standard'], $valid_attributes); 139 143 $valid_attributes = self::array_flatten($valid_attributes); … … 146 150 147 151 $attributes_html = ''; 148 foreach ($attributes as $key => $value) {152 foreach ($attributes as $key => $value) { 149 153 $attributes_html .= ' '.$key.'="'.esc_attr($value).'"'; 150 154 } … … 157 161 public function admin_header_cells($model) { 158 162 $html = ''; 159 foreach ($model->admin_columns as $key => $column) {163 foreach ($model->admin_columns as $key => $column) { 160 164 $html .= $this->admin_header_cell($column['label']); 161 165 } … … 171 175 public function admin_table_cells($model, $objects) { 172 176 $html = ''; 173 foreach ($objects as $object) {177 foreach ($objects as $object) { 174 178 $html .= '<tr>'; 175 foreach ($model->admin_columns as $key => $column) {179 foreach ($model->admin_columns as $key => $column) { 176 180 $html .= $this->admin_table_cell($model, $object, $column); 177 181 } … … 207 211 private function array_flatten($array) { 208 212 209 foreach ($array as $key => $value){213 foreach ($array as $key => $value){ 210 214 $array[$key] = (array)$value; 211 215 } -
wp-mvc/trunk/core/models/mvc_data_validation_error.php
r376739 r451789 27 27 } 28 28 $html = ''; 29 foreach ($this->errors as $error) {29 foreach ($this->errors as $error) { 30 30 $html .= ' 31 31 <div class="mvc-validation-error"> -
wp-mvc/trunk/core/models/mvc_database.php
r371344 r451789 32 32 33 33 public function escape_array($array) { 34 foreach ($array as $key => $value) {34 foreach ($array as $key => $value) { 35 35 $array[$key] = $this->escape($value); 36 36 } -
wp-mvc/trunk/core/models/mvc_database_adapter.php
r390534 r451789 67 67 $joins = array($joins); 68 68 } 69 foreach ($joins as $join) {69 foreach ($joins as $join) { 70 70 $type = empty($join['type']) ? 'JOIN' : $join['type']; 71 71 $clauses[] = $type.' '.$join['table'].' '.$join['alias'].' ON '.$join['on']; … … 89 89 $use_table_alias = isset($options['use_table_alias']) ? $options['use_table_alias'] : true; 90 90 $sql_clauses = array(); 91 foreach ($conditions as $key => $value) {91 foreach ($conditions as $key => $value) { 92 92 if (is_array($value)) { 93 93 $clauses = $this->get_where_sql_clauses($value); … … 123 123 public function get_set_sql($data) { 124 124 $clauses = array(); 125 foreach ($data as $key => $value) {125 foreach ($data as $key => $value) { 126 126 if (is_string($value) || is_numeric($value)) { 127 127 $clauses[] = $key.' = "'.$this->db->escape($value).'"'; … … 141 141 public function get_insert_values_sql($data) { 142 142 $values = array(); 143 foreach ($data as $value) {143 foreach ($data as $value) { 144 144 $values[] = '"'.$this->db->escape($value).'"'; 145 145 } -
wp-mvc/trunk/core/models/mvc_model.php
r438768 r451789 12 12 public $validation_error = null; 13 13 public $validation_error_html = null; 14 public $hide_menu = false; 14 15 private $data_validator = null; 15 16 private $db_adapter = null; … … 37 38 ); 38 39 39 foreach ($defaults as $key => $value) {40 foreach ($defaults as $key => $value) { 40 41 $this->{$key} = $value; 41 42 } … … 55 56 public function new_object($data) { 56 57 $object = false; 57 foreach ($data as $field => $value) {58 foreach ($data as $field => $value) { 58 59 $object->{$field} = $value; 59 60 } … … 179 180 } 180 181 $formatted_fields = array(); 181 foreach ($fields as $field) {182 foreach ($fields as $field) { 182 183 if (strpos($field, '.') === false) { 183 184 $field = $this->name.'.'.$field; … … 190 191 $field_reference = 'CONCAT('.implode(', ', $formatted_fields).')'; 191 192 } 192 foreach ($keywords as $keyword) {193 foreach ($keywords as $keyword) { 193 194 $conditions[] = array($field_reference.' LIKE' => '%'.$keyword.'%'); 194 195 } … … 210 211 $options['joins'] = array($options['joins']); 211 212 } 212 foreach ($options['joins'] as $key => $join) {213 foreach ($options['joins'] as $key => $join) { 213 214 if (is_string($join)) { 214 215 $join_model_name = $join; … … 263 264 private function update_associations($id, $model_data) { 264 265 if (!empty($this->associations)) { 265 foreach ($this->associations as $association) {266 foreach ($this->associations as $association) { 266 267 switch($association['type']) { 267 268 case 'has_many': … … 298 299 )); 299 300 if (!empty($model_data[$association_name]['ids'])) { 300 foreach ($model_data[$association_name]['ids'] as $association_id) {301 foreach ($model_data[$association_name]['ids'] as $association_id) { 301 302 if (!empty($association_id)) { 302 303 $this->db_adapter->insert( … … 319 320 $rules = $this->validate; 320 321 if (!empty($rules)) { 321 foreach ($rules as $field => $rule) {322 foreach ($rules as $field => $rule) { 322 323 if (isset($data[$field])) { 323 324 $valid = $this->data_validator->validate($field, $data[$field], $rule); … … 350 351 } 351 352 $admin_pages = array(); 352 foreach ($this->admin_pages as $key => $value) {353 foreach ($this->admin_pages as $key => $value) { 353 354 if (is_int($key)) { 354 355 $key = $value; … … 372 373 private function init_admin_columns() { 373 374 $admin_columns = array(); 374 foreach ($this->admin_columns as $key => $value) {375 foreach ($this->admin_columns as $key => $value) { 375 376 if (is_array($value)) { 376 377 if (!isset($value['label'])) { … … 412 413 // Instantiate associated models, so that they don't need to be instantiated multiple times in the subsequent for loop 413 414 $models = array(); 414 foreach ($includes as $key => $include) {415 foreach ($includes as $key => $include) { 415 416 $model_name = is_string($include) ? $include : $key; 416 417 $models[$model_name] = new $model_name(); … … 420 421 $recursive = isset($options['recursive']) ? $options['recursive'] - 1 : 2; 421 422 422 foreach ($objects as $key => $object) {423 foreach ($objects as $key => $object) { 423 424 424 425 if (!empty($this->primary_key)) { … … 427 428 428 429 if (!empty($includes) && $recursive != 0) { 429 foreach ($includes as $include_key => $include) {430 foreach ($includes as $include_key => $include) { 430 431 if (is_string($include)) { 431 432 $model_name = $include; … … 514 515 $schema = array(); 515 516 516 foreach ($results as $result) {517 foreach ($results as $result) { 517 518 $field = $result->Field; 518 519 $type_schema = explode('(', $result->Type); … … 535 536 protected function init_associations() { 536 537 if (!empty($this->belongs_to)) { 537 foreach ($this->belongs_to as $key => $value) {538 foreach ($this->belongs_to as $key => $value) { 538 539 $config = null; 539 540 if (is_string($value)) { … … 565 566 } 566 567 if (!empty($this->has_many)) { 567 foreach ($this->has_many as $association) {568 foreach ($this->has_many as $association) { 568 569 if (is_string($association)) { 569 570 if (!is_array($this->associations)) { … … 582 583 } 583 584 if (!empty($this->has_and_belongs_to_many)) { 584 foreach ($this->has_and_belongs_to_many as $association_name => $association) {585 foreach ($this->has_and_belongs_to_many as $association_name => $association) { 585 586 if (!is_array($this->associations)) { 586 587 $this->associations = array(); 587 588 } 588 589 if (isset($association['fields'])) { 589 foreach ($association['fields'] as $key => $field) {590 foreach ($association['fields'] as $key => $field) { 590 591 $association['fields'][$key] = $association_name.'.'.$field; 591 592 } -
wp-mvc/trunk/core/mvc_dispatcher.php
r390534 r451789 45 45 private function escape_params($params) { 46 46 if (is_array($params)) { 47 foreach ($params as $key => $value) {47 foreach ($params as $key => $value) { 48 48 if (is_string($value)) { 49 49 $params[$key] = stripslashes($value); -
wp-mvc/trunk/core/mvc_file_includer.php
r390534 r451789 12 12 13 13 public function find_first_app_file_or_core_file($filepath) { 14 foreach ($this->plugin_app_paths as $plugin_app_path) {14 foreach ($this->plugin_app_paths as $plugin_app_path) { 15 15 if (file_exists($plugin_app_path.$filepath)) { 16 16 return $plugin_app_path.$filepath; … … 49 49 50 50 public function require_first_app_file($filepath) { 51 foreach ($this->plugin_app_paths as $plugin_app_path) {51 foreach ($this->plugin_app_paths as $plugin_app_path) { 52 52 if ($this->include_file($plugin_app_path.$filepath)) { 53 53 return true; … … 59 59 public function include_all_app_files($filepath) { 60 60 $included = false; 61 foreach ($this->plugin_app_paths as $plugin_app_path) {61 foreach ($this->plugin_app_paths as $plugin_app_path) { 62 62 if ($this->include_file($plugin_app_path.$filepath)) { 63 63 $included = true; … … 72 72 73 73 public function include_first_app_file($filepath) { 74 foreach ($this->plugin_app_paths as $plugin_app_path) {74 foreach ($this->plugin_app_paths as $plugin_app_path) { 75 75 if ($this->include_file($plugin_app_path.$filepath)) { 76 76 return true; … … 81 81 82 82 public function include_first_app_file_or_core_file($filepath) { 83 foreach ($this->plugin_app_paths as $plugin_app_path) {83 foreach ($this->plugin_app_paths as $plugin_app_path) { 84 84 if ($this->include_file($plugin_app_path.$filepath)) { 85 85 return true; … … 96 96 public function require_all_app_files($filepath) { 97 97 $included = false; 98 foreach ($this->plugin_app_paths as $plugin_app_path) {98 foreach ($this->plugin_app_paths as $plugin_app_path) { 99 99 if ($this->include_require_file($plugin_app_path.$filepath)) { 100 100 $included = true; … … 125 125 $filepaths = array(); 126 126 127 foreach ($filenames as $filename) {127 foreach ($filenames as $filename) { 128 128 $filepath = $directory.$filename; 129 129 $filepaths[] = $filepath; … … 156 156 $files = array(); 157 157 158 foreach ($file_tmp as $item){158 foreach ($file_tmp as $item){ 159 159 if (substr($item, -1) != DIRECTORY_SEPARATOR) { 160 160 $files[] = $item; -
wp-mvc/trunk/core/mvc_loader.php
r390534 r451789 60 60 ); 61 61 62 foreach ($files as $file) {62 foreach ($files as $file) { 63 63 require_once $this->core_path.$file.'.php'; 64 64 } … … 70 70 $plugins = $this->get_ordered_plugins(); 71 71 $plugin_app_paths = array(); 72 foreach ($plugins as $plugin) {72 foreach ($plugins as $plugin) { 73 73 $plugin_app_paths[$plugin] = rtrim(WP_PLUGIN_DIR, '/').'/'.$plugin.'/app/'; 74 74 } … … 127 127 private function load_controllers() { 128 128 129 foreach ($this->plugin_app_paths as $plugin_app_path) {129 foreach ($this->plugin_app_paths as $plugin_app_path) { 130 130 131 131 $admin_controller_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path.'controllers/admin/'); 132 132 $public_controller_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path.'controllers/'); 133 133 134 foreach ($admin_controller_filenames as $filename) {134 foreach ($admin_controller_filenames as $filename) { 135 135 if (preg_match('/admin_([^\/]+)_controller\.php/', $filename, $match)) { 136 136 $this->admin_controller_names[] = $match[1]; … … 138 138 } 139 139 140 foreach ($public_controller_filenames as $filename) {140 foreach ($public_controller_filenames as $filename) { 141 141 if (preg_match('/([^\/]+)_controller\.php/', $filename, $match)) { 142 142 $this->public_controller_names[] = $match[1]; … … 150 150 private function load_libs() { 151 151 152 foreach ($this->plugin_app_paths as $plugin_app_path) {152 foreach ($this->plugin_app_paths as $plugin_app_path) { 153 153 154 154 $this->file_includer->require_php_files_in_directory($plugin_app_path.'libs/'); … … 162 162 $models = array(); 163 163 164 foreach ($this->plugin_app_paths as $plugin_app_path) {164 foreach ($this->plugin_app_paths as $plugin_app_path) { 165 165 166 166 $model_filenames = $this->file_includer->require_php_files_in_directory($plugin_app_path.'models/'); 167 167 168 foreach ($model_filenames as $filename) {168 foreach ($model_filenames as $filename) { 169 169 $models[] = MvcInflector::class_name_from_filename($filename); 170 170 } … … 174 174 $this->model_names = array(); 175 175 176 foreach ($models as $model) {176 foreach ($models as $model) { 177 177 $this->model_names[] = $model; 178 178 $model_class = MvcInflector::camelize($model); … … 219 219 do_action('mvc_admin_init', $mvc_admin_init_args); 220 220 221 $title = MvcInflector::titleize($controller);221 $title = MvcInflector::titleize($controller); 222 222 if (!empty($action) && $action != 'index') { 223 223 $title = MvcInflector::titleize($action).' ‹ '.$title; … … 237 237 $menu_position = apply_filters('mvc_menu_position', $menu_position); 238 238 239 foreach ($this->model_names as $model_name) {239 foreach ($this->model_names as $model_name) { 240 240 241 241 $model = MvcModelRegistry::get_model($model_name); 242 $tableized = MvcInflector::tableize($model_name); 243 $pluralized = MvcInflector::pluralize($model_name); 244 $titleized = MvcInflector::titleize($model_name); 245 $pluralize_titleized = MvcInflector::pluralize_titleize($model_name); 246 247 $controller_name = 'admin_'.$tableized; 248 249 $top_level_handle = 'mvc_'.$tableized; 250 251 $admin_pages = $model->admin_pages; 252 253 $method = $controller_name.'_index'; 254 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "index"));'); 255 add_menu_page( 256 $pluralize_titleized, 257 $pluralize_titleized, 258 'administrator', 259 $top_level_handle, 260 array($this->dispatcher, $method), 261 null, 262 $menu_position 263 ); 264 265 foreach($admin_pages as $key => $admin_page) { 242 243 if (!$model->hide_menu) { 244 $tableized = MvcInflector::tableize($model_name); 245 $pluralized = MvcInflector::pluralize($model_name); 246 $titleized = MvcInflector::titleize($model_name); 247 $pluralize_titleized = MvcInflector::pluralize_titleize($model_name); 248 249 $controller_name = 'admin_'.$tableized; 250 251 $top_level_handle = 'mvc_'.$tableized; 252 253 $admin_pages = $model->admin_pages; 254 255 $method = $controller_name.'_index'; 256 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "index"));'); 257 add_menu_page( 258 $pluralize_titleized, 259 $pluralize_titleized, 260 'administrator', 261 $top_level_handle, 262 array($this->dispatcher, $method), 263 null, 264 $menu_position 265 ); 266 267 foreach ($admin_pages as $key => $admin_page) { 266 268 267 $method = $controller_name.'_'.$admin_page['action'];269 $method = $controller_name.'_'.$admin_page['action']; 268 270 269 if (!method_exists($this->dispatcher, $method)) { 270 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "'.$admin_page['action'].'"));'); 271 if (!method_exists($this->dispatcher, $method)) { 272 $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "'.$controller_name.'", "action" => "'.$admin_page['action'].'"));'); 273 } 274 275 $page_handle = $top_level_handle.'-'.$key; 276 277 if ($admin_page['in_menu']) { 278 add_submenu_page( 279 $top_level_handle, 280 $admin_page['label'].' ‹ '.$pluralize_titleized, 281 $admin_page['label'], 282 $admin_page['capability'], 283 $page_handle, 284 array($this->dispatcher, $method) 285 ); 286 } else { 287 // It looks like there isn't a more native way of creating an admin page without 288 // having it show up in the menu, but if there is, it should be implemented here. 289 // To do: set up capability handling and page title handling for these pages that aren't in the menu 290 $hookname = get_plugin_page_hookname($page_handle,''); 291 if (!empty($hookname)) { 292 add_action($hookname, array($this->dispatcher, $method)); 293 } 294 $_registered_pages[$hookname] = true; 295 } 296 271 297 } 272 273 $page_handle = $top_level_handle.'-'.$key; 274 275 if ($admin_page['in_menu']) { 276 add_submenu_page( 277 $top_level_handle, 278 $admin_page['label'].' ‹ '.$pluralize_titleized, 279 $admin_page['label'], 280 $admin_page['capability'], 281 $page_handle, 282 array($this->dispatcher, $method) 283 ); 284 } else { 285 // It looks like there isn't a more native way of creating an admin page without 286 // having it show up in the menu, but if there is, it should be implemented here. 287 // To do: set up capability handling and page title handling for these pages that aren't in the menu 288 $hookname = get_plugin_page_hookname($page_handle,''); 289 if (!empty($hookname)) { 290 add_action($hookname, array($this->dispatcher, $method)); 291 } 292 $_registered_pages[$hookname] = true; 293 } 294 295 } 296 $menu_position++; 297 298 $menu_position++; 299 300 } 298 301 } 299 302 … … 321 324 } 322 325 323 foreach ($routes as $route) {326 foreach ($routes as $route) { 324 327 325 328 $route_path = $route[0]; … … 327 330 328 331 if (strpos($route_path, '{:controller}') !== false) { 329 foreach ($this->public_controller_names as $controller) {332 foreach ($this->public_controller_names as $controller) { 330 333 $route_rules = $this->get_rewrite_rules($route_path, $route_defaults, $controller); 331 334 $new_rules = array_merge($new_rules, $route_rules); … … 354 357 // and append them to the match string for use in a WP rewrite rule 355 358 preg_match_all('/{:(.+?)(:.*?)?}/', $rewrite_path, $matches); 356 foreach ($matches[1] as $query_var) {359 foreach ($matches[1] as $query_var) { 357 360 $query_var = 'mvc_'.$query_var; 358 361 if ($query_var != 'mvc_controller') { … … 365 368 // Do the same as above for route params that are defined as route defaults (e.g. array('action' => 'show')) 366 369 if (!empty($route_defaults)) { 367 foreach ($route_defaults as $query_var => $value) {370 foreach ($route_defaults as $query_var => $value) { 368 371 $query_var = 'mvc_'.$query_var; 369 372 if ($query_var != 'mvc_controller') { … … 404 407 $query_params = $wp_query->query; 405 408 $params = array(); 406 foreach ($query_params as $key => $value) {409 foreach ($query_params as $key => $value) { 407 410 $key = preg_replace('/^(mvc_)/', '', $key); 408 411 $params[$key] = $value; … … 429 432 $routes = MvcRouter::get_admin_ajax_routes(); 430 433 if (!empty($routes)) { 431 foreach ($routes as $route) {434 foreach ($routes as $route) { 432 435 $route['is_admin_ajax'] = true; 433 436 $method = 'admin_ajax_'.$route['wp_action']; -
wp-mvc/trunk/core/mvc_plugin_loader.php
r390534 r451789 39 39 $plugins = $this->get_plugins(); 40 40 if (in_array($plugin, $plugins)) { 41 foreach ($plugins as $key => $existing_plugin) {41 foreach ($plugins as $key => $existing_plugin) { 42 42 if ($plugin == $existing_plugin) { 43 43 unset($plugins[$key]); … … 57 57 58 58 protected function filter_nonexistent_plugins($plugins) { 59 foreach ($plugins as $key => $plugin) {59 foreach ($plugins as $key => $plugin) { 60 60 if (!is_dir(WP_PLUGIN_DIR.'/'.$plugin)) { 61 61 unset($plugins[$key]); -
wp-mvc/trunk/core/mvc_router.php
r390534 r451789 22 22 } 23 23 } 24 foreach ($routes as $route) {24 foreach ($routes as $route) { 25 25 $route_path = $route[0]; 26 26 $route_defaults = $route[1]; … … 36 36 preg_match_all('/{:([\w]+).*?}/', $path_pattern, $matches, PREG_SET_ORDER); 37 37 $path = $path_pattern; 38 foreach ($matches as $match) {38 foreach ($matches as $match) { 39 39 $pattern = $match[0]; 40 40 $option_key = $match[1]; -
wp-mvc/trunk/core/mvc_templater.php
r371570 r451789 14 14 $this->set_template_var($variable_name_or_array, $data); 15 15 } else if (is_array($variable_name_or_array)) { 16 foreach ($variable_name_or_array as $key => $value) {16 foreach ($variable_name_or_array as $key => $value) { 17 17 $this->set_template_var($key, $value); 18 18 } -
wp-mvc/trunk/core/shells/generate_shell.php
r437103 r451789 62 62 'views/admin' 63 63 ); 64 foreach ($app_directories as $path) {64 foreach ($app_directories as $path) { 65 65 $directory->create($plugin_app_path.$path.'/'); 66 66 } -
wp-mvc/trunk/core/shells/mvc_shell.php
r390534 r451789 52 52 53 53 protected function load_models($model_names) { 54 foreach ($model_names as $model_name) {54 foreach ($model_names as $model_name) { 55 55 $this->load_model($model_name); 56 56 } -
wp-mvc/trunk/core/templates/plugin/app/views/index.php
r390534 r451789 2 2 <?php 3 3 echo ' 4 <?php foreach ($objects as $object): ?>4 <?php foreach ($objects as $object): ?> 5 5 6 6 <?php $this->render_view(\'_item\', array(\'locals\' => array(\'object\' => $object))); ?> -
wp-mvc/trunk/readme.txt
r437103 r451789 24 24 1. Upload `wp-mvc` to the `wp-content/plugins/` directory 25 25 1. Activate the plugin through the 'Plugins' menu in WordPress 26 1. Make sure that [Pretty Permalinks](http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks) are enabled and working 26 27 1. Either set up the example plugin to see how WP MVC works or start creating an application using the code generation utility `wpmvc`: 27 28
Note: See TracChangeset
for help on using the changeset viewer.