private function generate_views($plugin, $name) { $plugin_app_path = $this->get_plugin_app_path($plugin); $name_tableized = MvcInflector::tableize($name); $name_titleized = MvcInflector::titleize($name); $name_titleized_pluralized = MvcInflector::pluralize($name_titleized); $name_underscored = MvcInflector::underscore($name); $directory = new MvcDirectory(); $public_directory = $plugin_app_path . 'views/' . $name_tableized . '/'; $directory->create($public_directory); $admin_directory = $plugin_app_path . 'views/admin/' . $name_tableized . '/'; $directory->create($admin_directory); $vars = array('name_tableized' => $name_tableized, 'name_titleized' => $name_titleized, 'name_titleized_pluralized' => $name_titleized_pluralized, 'name_underscored' => $name_underscored); $this->templater->create('views/_item', $public_directory . '_item.php', $vars); $this->templater->create('views/index', $public_directory . 'index.php', $vars); $this->templater->create('views/show', $public_directory . 'show.php', $vars); $this->templater->create('views/admin/add', $admin_directory . '/add.php', $vars); $this->templater->create('views/admin/edit', $admin_directory . '/edit.php', $vars); }
public static function pluralize_titleize($string) { $string = MvcInflector::pluralize(MvcInflector::titleize($string)); return $string; }
<?php if (is_page()) { echo 'single'; } ?> <h2><?php echo MvcInflector::pluralize($model->name); ?> </h2> <?php foreach ($objects as $object) { ?> <?php $this->render_view('_item', array('locals' => array('object' => $object))); ?> <?php } ?> <?php echo $this->pagination();
public function has_many_dropdown($model_name, $select_options, $options = array()) { $defaults = array('select_id' => $this->model_name . '_' . $model_name . '_select', 'select_name' => $this->model_name . '_' . $model_name . '_select', 'list_id' => $this->model_name . '_' . $model_name . '_list', 'ids_input_name' => 'data[' . $this->model_name . '][' . $model_name . '][ids]', 'label' => MvcInflector::pluralize(MvcInflector::titleize($model_name)), 'options' => $select_options); $options = array_merge($defaults, $options); $select_options = $options; $select_options['id'] = $select_options['select_id']; $html = $this->before_input($options['select_name'], $select_options); $html .= $this->select_tag($options['select_name'], $select_options); $associated_objects = empty($this->object->{MvcInflector::tableize($model_name)}) ? array() : $this->object->{MvcInflector::tableize($model_name)}; // An empty value is necessary to ensure that data with name $options['ids_input_name'] is submitted; otherwise, // if no association objects were selected the save() method wouldn't know that this association data is being // updated and that it should, as a result, delete existing association data. $html .= '<input type="hidden" name="' . $options['ids_input_name'] . '[]" value="" />'; $html .= '<ul id="' . $options['list_id'] . '">'; foreach ($associated_objects as $associated_object) { $html .= ' <li> ' . $associated_object->__name . ' <a href="#" class="remove-item">Remove</a> <input type="hidden" name="' . $options['ids_input_name'] . '[]" value="' . $associated_object->__id . '" /> </li>'; } $html .= '</ul>'; $html .= ' <script type="text/javascript"> jQuery(document).ready(function(){ jQuery("#' . $options['select_id'] . '").change(function() { var option = jQuery(this).find("option:selected"); var id = option.attr("value"); if (id) { var name = option.text(); var list_item = \'<li><input type="hidden" name="' . $options['ids_input_name'] . '[]" value="\'+id+\'" />\'+name+\' <a href="#" class="remove-item">Remove</a></li>\'; jQuery("#' . $options['list_id'] . '").append(list_item); jQuery(this).val(\'\'); } return false; }); jQuery(".remove-item").live("click", function() { jQuery(this).parents("li:first").remove(); return false; }); }); </script> '; $html .= $this->after_input($options['select_name'], $select_options); return $html; }
public function add_menu_pages() { global $_registered_pages; $menu_position = 12; $menu_position = apply_filters('mvc_menu_position', $menu_position); foreach ($this->model_names as $model_name) { $model = MvcModelRegistry::get_model($model_name); if (!$model->hide_menu) { $tableized = MvcInflector::tableize($model_name); $pluralized = MvcInflector::pluralize($model_name); $titleized = MvcInflector::titleize($model_name); $pluralize_titleized = MvcInflector::pluralize_titleize($model_name); $controller_name = 'admin_' . $tableized; $top_level_handle = 'mvc_' . $tableized; $admin_pages = $model->admin_pages; $method = $controller_name . '_index'; $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "' . $controller_name . '", "action" => "index"));'); add_menu_page($pluralize_titleized, $pluralize_titleized, 'administrator', $top_level_handle, array($this->dispatcher, $method), null, $menu_position); foreach ($admin_pages as $key => $admin_page) { $method = $controller_name . '_' . $admin_page['action']; if (!method_exists($this->dispatcher, $method)) { $this->dispatcher->{$method} = create_function('', 'MvcDispatcher::dispatch(array("controller" => "' . $controller_name . '", "action" => "' . $admin_page['action'] . '"));'); } $page_handle = $top_level_handle . '-' . $key; if ($admin_page['in_menu']) { add_submenu_page($top_level_handle, $admin_page['label'] . ' ‹ ' . $pluralize_titleized, $admin_page['label'], $admin_page['capability'], $page_handle, array($this->dispatcher, $method)); } else { // It looks like there isn't a more native way of creating an admin page without // having it show up in the menu, but if there is, it should be implemented here. // To do: set up capability handling and page title handling for these pages that aren't in the menu $hookname = get_plugin_page_hookname($page_handle, ''); if (!empty($hookname)) { add_action($hookname, array($this->dispatcher, $method)); } $_registered_pages[$hookname] = true; } } $menu_position++; } } }
public function register_post_type($model) { $default_settings = array('post_type' => array()); $settings = array_merge($default_settings, $model->wp_post); $default_post_type_settings = array('args' => array(), 'fields' => array()); if (!is_array($settings['post_type'])) { $settings['post_type'] = array(); } $settings['post_type'] = array_merge($default_post_type_settings, $settings['post_type']); if (!empty($settings['post_type']['key'])) { $settings['post_type']['key'] = $this->format_post_type_key($settings['post_type']['key']); } else { $settings['post_type']['key'] = $this->get_post_type_key($model); } if (!post_type_exists($settings['post_type']['key'])) { $title = MvcInflector::titleize($model->name); $title_plural = MvcInflector::pluralize($title); $title_lowercase = strtolower($title); $title_lowercase_plural = strtolower($title_plural); $default_labels = array('name' => _x($title_plural, 'post type general name'), 'singular_name' => _x($title, 'post type singular name'), 'add_new' => _x('Add New', $title_lowercase), 'add_new_item' => __('Add New ' . $title), 'edit_item' => __('Edit ' . $title), 'new_item' => __('New ' . $title), 'all_items' => __('All ' . $title_plural), 'view_item' => __('View ' . $title), 'search_items' => __('Search ' . $title_plural), 'not_found' => __('No ' . $title_lowercase_plural . ' found'), 'not_found_in_trash' => __('No ' . $title_lowercase_plural . ' found in Trash'), 'parent_item_colon' => '', 'menu_name' => $title_plural); $labels = empty($settings['post_type']['args']['labels']) ? array() : $settings['post_type']['args']['labels']; $labels = array_merge($default_labels, $labels); $default_args = array('labels' => $labels, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_ui' => false, 'show_in_menu' => false, 'show_in_nav_menus' => true, 'hierarchical' => false, 'supports' => array('title', 'editor')); $args = is_array($settings['post_type']['args']) ? $settings['post_type']['args'] : array(); $args = array_merge($default_args, $args); register_post_type($settings['post_type']['key'], $args); } }