Exemplo n.º 1
0
 private function get_plugin_path($plugin_name)
 {
     $plugin_underscored = MvcInflector::underscore($plugin_name);
     $plugin_hyphenized = str_replace('_', '-', $plugin_underscored);
     $plugin_path = WP_PLUGIN_DIR . '/' . $plugin_hyphenized . '/';
     return $plugin_path;
 }
Exemplo n.º 2
0
 function __construct()
 {
     $this->name = get_class($this);
     $this->title = MvcInflector::titleize($this->name);
     $this->key = 'mvc_' . MvcInflector::underscore($this->name);
     $this->init_settings();
 }
Exemplo n.º 3
0
 protected function load_model($model_name)
 {
     $model_underscore = MvcInflector::underscore($model_name);
     $this->file_includer->require_first_app_file_or_core_file('models/' . $model_underscore . '.php');
     if (class_exists($model_name)) {
         $this->{$model_name} = new $model_name();
     }
 }
Exemplo n.º 4
0
function mvc_setting($settings_name, $setting_key)
{
    $settings_name = 'mvc_' . MvcInflector::underscore($settings_name);
    $option = get_option($settings_name);
    if (isset($option[$setting_key])) {
        return $option[$setting_key];
    }
    return null;
}
Exemplo n.º 5
0
 /**
  * Get a list of the available shells.
  * Also is executed if the wpmvc console is run with no arguments.
  * 
  * @param mixed $args 
  */
 public function main($args)
 {
     $shells = $this->get_available_shells();
     $this->out('Available Shells:');
     $table = new Console_Table(CONSOLE_TABLE_ALIGN_LEFT, ' ', 1, null, true);
     foreach ($shells as $plugin => $shells) {
         $plugin_label = MvcInflector::camelize(MvcInflector::underscore($plugin));
         for ($i = 0; $i < count($shells); $i++) {
             if ($i > 0) {
                 $plugin_label = ' ';
             }
             $shell_name = MvcInflector::camelize($shells[$i]);
             $table->addRow(array($plugin_label, Console_Color::convert('%_' . $shell_name . '%n')));
         }
         $table->addSeparator();
     }
     $this->out($table->getTable());
     $this->out('To get information about a shell try:');
     $this->out("\n\twpmvc help shell <name_of_shell>");
 }
Exemplo n.º 6
0
 public static function tableize($string)
 {
     $string = MvcInflector::underscore($string);
     $string = MvcInflector::pluralize($string);
     return $string;
 }
Exemplo n.º 7
0
 protected function init_associations()
 {
     if (!empty($this->belongs_to)) {
         foreach ($this->belongs_to as $key => $value) {
             $config = null;
             if (is_string($value)) {
                 $association = $value;
                 $config = array('type' => 'belongs_to', 'name' => $association, 'class' => $association, 'foreign_key' => MvcInflector::underscore($association) . '_id', 'includes' => null);
             } else {
                 if (is_string($key) && is_array($value)) {
                     $association = $key;
                     $config = array('type' => 'belongs_to', 'name' => empty($value['name']) ? $association : $value['name'], 'class' => empty($value['class']) ? $association : $value['class'], 'foreign_key' => empty($value['foreign_key']) ? MvcInflector::underscore($association) . '_id' : $value['foreign_key'], 'includes' => null);
                 }
             }
             if (!empty($config)) {
                 if (!is_array($this->associations)) {
                     $this->associations = array();
                 }
                 $this->associations[$association] = $config;
             }
         }
     }
     if (!empty($this->has_many)) {
         foreach ($this->has_many as $association) {
             if (is_string($association)) {
                 if (!is_array($this->associations)) {
                     $this->associations = array();
                 }
                 $config = array('type' => 'has_many', 'name' => $association, 'class' => $association, 'foreign_key' => MvcInflector::underscore($this->name) . '_id', 'includes' => null);
                 $this->associations[$association] = $config;
             }
         }
     }
     if (!empty($this->has_and_belongs_to_many)) {
         foreach ($this->has_and_belongs_to_many as $association_name => $association) {
             if (!is_array($this->associations)) {
                 $this->associations = array();
             }
             if (isset($association['fields'])) {
                 foreach ($association['fields'] as $key => $field) {
                     $association['fields'][$key] = $association_name . '.' . $field;
                 }
             }
             $config = array('type' => 'has_and_belongs_to_many', 'name' => $association_name, 'class' => $association_name, 'foreign_key' => isset($association['foreign_key']) ? $association['foreign_key'] : MvcInflector::underscore($this->name) . '_id', 'association_foreign_key' => isset($association['association_foreign_key']) ? $association['association_foreign_key'] : MvcInflector::underscore($association_name) . '_id', 'join_table' => $this->process_table_name($association['join_table']), 'fields' => isset($association['fields']) ? $association['fields'] : null, 'includes' => isset($association['includes']) ? $association['includes'] : null);
             $this->associations[$association_name] = $config;
         }
     }
 }
Exemplo n.º 8
0
 private function input_name($field_name)
 {
     return 'data[' . $this->model_name . '][' . MvcInflector::underscore($field_name) . ']';
 }
Exemplo n.º 9
0
 protected function init_properties()
 {
     $this->properties = array();
     foreach ($this->associations as $association_name => $association) {
         $property_name = null;
         if ($association['type'] == 'belongs_to') {
             $property_name = MvcInflector::underscore($association_name);
         } else {
             if (in_array($association['type'], array('has_many', 'has_and_belongs_to_many'))) {
                 $property_name = MvcInflector::tableize($association_name);
             }
         }
         if ($property_name) {
             $this->properties[$property_name] = array('type' => 'association', 'association' => $association);
         }
     }
 }
Exemplo n.º 10
0
 public function get_post_type_key($model)
 {
     $key = empty($model->wp_post['post_type']['key']) ? MvcInflector::underscore($model->name) : $model->wp_post['post_type']['key'];
     $key = $this->format_post_type_key($key);
     return $key;
 }