Exemplo n.º 1
0
 protected function init_settings()
 {
     if (empty($this->settings)) {
         $this->settings = array();
     }
     $settings = array();
     foreach ($this->settings as $key => $setting) {
         $defaults = array('key' => $key, 'type' => 'text', 'label' => MvcInflector::titleize($key), 'value' => null, 'value_method' => null, 'default' => null, 'default_method' => null, 'options' => null, 'options_method' => null);
         $setting = array_merge($defaults, $setting);
         $settings[$key] = $setting;
     }
     $this->settings = $settings;
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function set_wp_title($original_title)
 {
     $separator = ' | ';
     $controller_name = MvcInflector::titleize($this->name);
     $object_name = null;
     $object = null;
     if ($this->action) {
         if ($this->action == 'show' && is_object($this->object)) {
             $object = $this->object;
             if (!empty($this->object->__name)) {
                 $object_name = $this->object->__name;
             }
         }
     }
     $pieces = array($object_name, $controller_name);
     $pieces = array_filter($pieces);
     $title = implode($separator, $pieces);
     $title = $title . $separator;
     $title_options = apply_filters('mvc_page_title', array('controller' => $controller_name, 'action' => $this->action, 'object_name' => $object_name, 'object' => $object, 'title' => $title));
     $title = $title_options['title'];
     return $title;
 }
Exemplo n.º 4
0
 protected function get_shell_meta($name)
 {
     $exclude_methods = array('__construct', '__call', 'init', 'out', 'nl', 'hr');
     $name = MvcInflector::underscore($name);
     $shell = new stdClass();
     $shell->name = $name;
     $shell->shell_name = $name . '_shell';
     $shell->class_name = MvcInflector::camelize($shell->shell_name);
     $shell->title = MvcInflector::titleize($shell->name);
     $shell->methods = array();
     $shell_path = 'shells/' . $shell->shell_name . '.php';
     $file_path = $this->file_includer->find_first_app_file_or_core_file($shell_path);
     if (!$file_path) {
         throw new InvalidArgumentException($shell->shell_name . " could not be found.\n");
     }
     $result = $this->file_includer->require_first_app_file_or_core_file($shell_path);
     $class = new ReflectionClass($shell->class_name);
     $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
     $shell->doc = $this->parse_doc_block($class->getDocComment());
     if (empty($shell->doc)) {
         $shell->doc = '(No Documentation)';
     }
     foreach ($methods as $method) {
         $method_name = $method->getName();
         $method_doc_block = $this->parse_doc_block($method->getDocComment());
         if (!in_array($method_name, $exclude_methods)) {
             if (empty($method_doc_block)) {
                 $method_doc_block = '(No Documentation)';
             }
             if ($method_name == 'main') {
                 $method_name = '(default)';
             }
             $shell->methods[$method_name] = $method_doc_block;
         }
     }
     ksort($shell->methods);
     return $shell;
 }
Exemplo n.º 5
0
 public static function pluralize_titleize($string)
 {
     $string = MvcInflector::pluralize(MvcInflector::titleize($string));
     return $string;
 }
Exemplo n.º 6
0
Arquivo: edit.php Projeto: RA2WP/RA2WP
<?php

$formatted_time = preg_replace('/:00$/', '', $object->time);
?>

<h2><?php 
echo MvcInflector::titleize($this->action);
?>
 <?php 
echo MvcInflector::titleize($model->name);
?>
</h2>

<?php 
echo $this->form->create($model->name);
echo $this->form->belongs_to_dropdown('Venue', $venues, array('style' => 'width: 200px;', 'empty' => true));
echo $this->form->input('date', array('label' => 'Date (YYYY-MM-DD)'));
echo $this->form->input('time', array('label' => 'Time (24-hour clock)', 'value' => $formatted_time));
echo $this->form->input('description');
echo $this->form->has_many_dropdown('Speaker', $speakers, array('style' => 'width: 200px;', 'empty' => true));
echo $this->form->input('is_public');
echo $this->form->end('Update');
Exemplo n.º 7
0
 public function add_settings_pages()
 {
     $this->init_settings();
     foreach ($this->settings as $settings_name => $settings) {
         $title = MvcInflector::titleize($settings_name);
         $title = str_replace(' Settings', '', $title);
         $instance = MvcSettingsRegistry::get_settings($settings_name);
         add_options_page($title, $title, 'manage_options', $instance->key, array($instance, 'page'));
     }
 }
Exemplo n.º 8
0
 private function process_message($message, $field)
 {
     $titleized_field = MvcInflector::titleize($field);
     $message = str_replace('{field}', $titleized_field, $message);
     return $message;
 }
Exemplo n.º 9
0
 protected function init_default_columns()
 {
     if (empty($this->default_columns)) {
         MvcError::fatal('No columns defined for this view.  Please define them in the controller, like this:
             <pre>
                 class ' . MvcInflector::camelize($this->name) . 'Controller extends MvcAdminController {
                     var $default_columns = array(\'id\', \'name\');
                 }
             </pre>');
     }
     $admin_columns = array();
     foreach ($this->default_columns as $key => $value) {
         if (is_array($value)) {
             if (!isset($value['label'])) {
                 $value['label'] = MvcInflector::titleize($key);
             }
         } else {
             if (is_integer($key)) {
                 $key = $value;
                 if ($value == 'id') {
                     $value = array('label' => 'ID');
                 } else {
                     $value = array('label' => MvcInflector::titleize($value));
                 }
             } else {
                 $value = array('label' => $value);
             }
         }
         $value['key'] = $key;
         $admin_columns[$key] = $value;
     }
     $this->default_columns = $admin_columns;
 }
Exemplo n.º 10
0
 private function init_admin_columns()
 {
     $admin_columns = array();
     foreach ($this->admin_columns as $key => $value) {
         if (is_array($value)) {
             if (!isset($value['label'])) {
                 $value['label'] = MvcInflector::titleize($key);
             }
         } else {
             if (is_integer($key)) {
                 $key = $value;
                 if ($value == 'id') {
                     $value = array('label' => 'ID');
                 } else {
                     $value = array('label' => MvcInflector::titleize($value));
                 }
             } else {
                 $value = array('label' => $value);
             }
         }
         $value['key'] = $key;
         $admin_columns[$key] = $value;
     }
     $this->admin_columns = $admin_columns;
 }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 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'] . ' &lsaquo; ' . $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++;
         }
     }
 }
Exemplo n.º 13
0
 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);
     }
 }
Exemplo n.º 14
0
<h2><?php 
echo MvcInflector::titleize($this->action);
?>
</h2>

<p>This is just an example of a custom action and view.</p>

<p>Here are all of the speakers, ordered by last name:</p>

<?php 
foreach ($speakers as $object) {
    ?>
	<?php 
    $this->render_view('speakers/_item', array('locals' => array('object' => $object)));
}