private function get_migrations()
 {
     $migrations = array();
     foreach (moojon_files::directory_files(moojon_paths::get_project_migrations_directory()) as $migration) {
         $migration_file = moojon_migrator::get_migration_class_name($migration);
         $migrations[] = substr($migration_file, 0, strlen($migration_file) - 10);
     }
     return $migrations;
 }
 private function get_installed_pluggins()
 {
     $installed_pluggins = array();
     foreach (moojon_files::directory_directories(moojon_paths::get_project_pluggins_directory(), false, true) as $pluggin_directory) {
         if (file_exists($pluggin_directory . 'installed')) {
             $installed_pluggins[] = basename($pluggin_directory);
         }
     }
     return $installed_pluggins;
 }
Beispiel #3
0
 public static function render($path, $variables = array(), $uri = null)
 {
     if (moojon_cache::get_enabled() && $uri) {
         $cache_path = moojon_paths::get_cache_path($uri);
         if (moojon_cache::expired($uri)) {
             moojon_files::put_file_contents($cache_path, self::expose($path, $variables));
         }
         return moojon_files::get_file_contents($cache_path);
     } else {
         return self::expose($path, $variables);
     }
 }
Beispiel #4
0
 public function run($arguments)
 {
     if (!count($arguments)) {
         echo 'Moojon version: ' . MOOJON_VERSION . "\n";
     } else {
         $arguments = self::check_arguments('moojon_cli::run()', 4, $arguments);
         $this->try_define('PROJECT_DIRECTORY', $_SERVER['PWD'] . '/' . $this->prompt_until($arguments[0], 'Please enter a project name') . '/');
         $app = $this->prompt_until($arguments[1], 'Please enter an app name', moojon_config::get('default_app'));
         $controller = $this->prompt_until($arguments[2], 'Please enter a controller name', moojon_config::get('default_controller'));
         $action = $this->prompt_until($arguments[3], 'Please enter an action name', moojon_config::get('default_action'));
         moojon_files::attempt_mkdir(PROJECT_DIRECTORY);
         moojon_generator::project($app, $controller, $action);
     }
 }
 public static function run()
 {
     self::find_or_create_schema_migrations_table();
     $migrations = array();
     foreach (schema_migration::read(null, 'version') as $migration) {
         $migrations[] = $migration->version;
     }
     $migration_files = moojon_files::directory_files(moojon_paths::get_project_migrations_directory());
     sort($migration_files);
     foreach ($migration_files as $migration_file) {
         if (!in_array(basename($migration_file), $migrations)) {
             self::run_migration($migration_file, 'up');
         }
     }
 }
 protected function __construct()
 {
     $data = $_REQUEST;
     foreach (moojon_files::get_data() as $key => $value) {
         if (array_key_exists($key, $data)) {
             if (is_array($data[$key]) && is_array($value)) {
                 foreach ($value as $element_key => $element_value) {
                     if (!array_key_exists($element_key, $data[$key]) || $element_value->get_name()) {
                         $data[$key][$element_key] = $element_value;
                     }
                 }
             }
         } else {
             $data[$key] = $value;
         }
     }
     $this->data = $data;
 }
Beispiel #7
0
function uploaded_file_tag(moojon_base_model $model, $column_name, $mime_type_column = null)
{
    $value = $model->{$column_name};
    if ($value) {
        if (!$mime_type_column) {
            $mime_type_column = $column_name . '_' . moojon_config::get('mime_type_column');
        }
        $mime_type = $model->has_column($mime_type_column) ? $model->{$mime_type_column} : moojon_files::get_mime_content_type($value);
        $path = moojon_paths::get_public_column_upload_path($model, $column_name);
        if (substr($mime_type, 0, 5) == 'image') {
            $content = img_tag($path, $model);
        } else {
            $content = $path;
        }
        return a_tag($content, $path, array('target' => '_blank'));
    } else {
        return p_tag('Not set');
    }
}
Beispiel #8
0
 public static function expired($path, $absolute = false, $cache_for = null)
 {
     if (!$cache_for) {
         $cache_for = moojon_config::get('cache_for');
     }
     if (!$absolute) {
         $path = moojon_paths::get_cache_path($path);
     }
     if (file_exists($path)) {
         if (time() > filectime($path) + $cache_for) {
             moojon_files::unlink($path);
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
Beispiel #9
0
 public static function read($directory)
 {
     $data = array();
     $instance = self::fetch();
     if (is_dir($directory)) {
         foreach (moojon_files::directory_files($directory, true) as $file) {
             if (moojon_files::has_suffix($file, 'config')) {
                 if (!array_key_exists($file, $instance->data_archive)) {
                     $instance->data_archive[$file] = (require_once $file);
                 }
                 $array = $instance->data_archive[$file];
                 if (is_array($array)) {
                     foreach ($array as $key => $value) {
                         $data[$key] = $value;
                     }
                 }
             }
         }
     }
     return $data;
 }
 public static function scaffold($app, $model, $controller)
 {
     self::try_define('APP', $app);
     self::try_define('CONTROLLER', $controller);
     if (moojon_routes::has_rest_route($model)) {
         $route = moojon_routes::get_rest_route($model);
         if (APP != $route->get_app()) {
             throw new moojon_exception("Scaffold app & route app must be the same (" . APP . ' != ' . $route->get_app() . ")");
         }
         $id_property = $route->get_id_property();
     } else {
         $id_property = moojon_primary_key::NAME;
         self::add_route("new moojon_rest_route('{$model}', array('app' => '" . APP . "')),");
     }
     $swaps = array();
     $swaps['plural'] = moojon_inflect::pluralize($model);
     $swaps['singular'] = moojon_inflect::singularize($model);
     $swaps['Human'] = str_replace('_', ' ', ucfirst(moojon_inflect::singularize($model)));
     $swaps['human'] = str_replace('_', ' ', moojon_inflect::singularize($model));
     $swaps['Humans'] = str_replace('_', ' ', ucfirst(moojon_inflect::pluralize($model)));
     $swaps['humans'] = str_replace('_', ' ', moojon_inflect::pluralize($model));
     $swaps['id_property'] = $id_property;
     $views_path = moojon_paths::get_project_views_app_controller_directory(APP, CONTROLLER);
     moojon_files::attempt_mkdir($views_path);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . 'controller.template', moojon_paths::get_project_controllers_app_directory(APP, CONTROLLER) . "{$controller}.controller.class.php", $swaps, false, true);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . '_form.template', $views_path . '_form.php', $swaps, false, true);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . 'new.view.template', $views_path . 'new.view.php', $swaps, false, true);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . 'delete.view.template', $views_path . 'delete.view.php', $swaps, false, true);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . 'index.view.template', $views_path . 'index.view.php', $swaps, false, true);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . 'show.view.template', $views_path . 'show.view.php', $swaps, false, true);
     self::run(moojon_paths::get_moojon_templates_scaffolds_directory() . 'edit.view.template', $views_path . 'edit.view.php', $swaps, false, true);
 }
 private function prompt_for_controller($app, $initial)
 {
     return $this->prompt_until_in($initial, moojon_files::get_app_controllers($app), 'Which controller');
 }
 public function valid($data)
 {
     return in_array(moojon_files::get_ext(basename($data['data'])), $this->exts);
 }
Beispiel #13
0
 public static function get_class_paths()
 {
     $paths = array();
     if (defined('PROJECT_DIRECTORY')) {
         $library_directory = self::get_project_library_directory();
         if (is_dir($library_directory)) {
             foreach (moojon_files::directory_directories($library_directory, false, true) as $directory) {
                 $paths[] = $directory;
                 $paths = array_merge($paths, moojon_files::directory_directories($directory, true, true));
             }
         }
         $pluggins_directory = self::get_project_pluggins_directory();
         if (is_dir($pluggins_directory)) {
             foreach (moojon_files::directory_directories($pluggins_directory, false, true) as $directory) {
                 $paths[] = $directory;
                 $paths = array_merge($paths, moojon_files::directory_directories($directory, true, true));
             }
         }
         if (moojon_config::has('db_driver')) {
             $paths[] = self::get_db_driver_directory();
             $paths[] = self::get_columns_directory();
         }
         $paths[] = self::get_project_migrations_directory();
         $paths[] = self::get_moojon_migrations_directory();
     }
     $paths[] = self::get_classes_directory();
     $paths[] = self::get_validations_directory();
     $paths[] = self::get_tags_directory();
     $paths[] = self::get_tag_attributes_directory();
     return $paths;
 }
Beispiel #14
0
 private static function colate_views($paths)
 {
     $views = array();
     foreach ($paths as $path) {
         if (is_dir($path)) {
             foreach (moojon_files::directory_files($path, false, false) as $file) {
                 if (moojon_files::has_suffix($file, 'view', 'php')) {
                     $views[] = $file;
                 }
             }
         }
     }
     return $views;
 }