Ejemplo n.º 1
0
 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     $columnFields = ['name', 'description', 'label'];
     $table = $this->describe->getTable($this->data['name']);
     foreach ($table as $column) {
         if ($column->isAutoIncrement()) {
             continue;
         }
         $field = strtolower($column->getField());
         $method = 'set_' . $field;
         $this->data['camel'][$field] = lcfirst(camelize($method));
         $this->data['underscore'][$field] = underscore($method);
         array_push($this->data['columns'], $field);
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = $referencedTable;
             array_push($this->data['models'], $referencedTable);
             $dropdown = ['list' => plural($referencedTable), 'table' => $referencedTable, 'field' => $field];
             if (!in_array($field, $columnFields)) {
                 $field = $this->describe->getPrimaryKey($referencedTable);
                 $dropdown['field'] = $field;
             }
             array_push($this->data['dropdowns'], $dropdown);
         }
     }
     return $this->data;
 }
Ejemplo n.º 2
0
 public function error_messages_for($object)
 {
     if ($object instanceof WaxForm) {
         if ($object->bound_to_model) {
             if ($object->bound_to_model->errors) {
                 $html = "<ul class='user_errors'>";
             }
             foreach ($object->bound_to_model->errors as $err => $mess) {
                 $html .= "<li>" . $mess[0];
             }
         } else {
             foreach ($object->elements as $el) {
                 foreach ($el->errors as $er) {
                     $html .= sprintf($er->error_template, $er);
                 }
             }
         }
         $html .= "</ul>";
         return $html;
     }
     if (strpos($object, "_")) {
         $object = camelize($object, 1);
     }
     $class = new $object();
     $errors = $class->get_errors();
     foreach ($errors as $error) {
         $html .= $this->content_tag("li", Inflections::humanize($error['field']) . " " . $error['message'], array("class" => "user_error"));
     }
     if (count($errors) > 0) {
         return $this->content_tag("ul", $html, array("class" => "user_errors"));
     }
     return false;
 }
Ejemplo n.º 3
0
 function __call($method, $args)
 {
     $sphinx_method = ucfirst(camelize($method));
     if (method_exists($this->client, $sphinx_method)) {
         return call_user_func_array(array($this->client, $sphinx_method), $args);
     }
 }
Ejemplo n.º 4
0
 /**
  * Transforms the field into the template.
  *
  * @param  string $field
  * @param  string $type
  * @return array
  */
 protected function transformField($field, $type)
 {
     if ($type == 'camelize') {
         return ['field' => lcfirst(camelize($field)), 'accessor' => lcfirst(camelize('get_' . $field)), 'mutator' => lcfirst(camelize('set_' . $field))];
     }
     return ['field' => lcfirst(underscore($field)), 'accessor' => lcfirst(underscore('get_' . $field)), 'mutator' => lcfirst(underscore('set_' . $field))];
 }
 public function test_camelize()
 {
     $strs = array('this is the string' => 'thisIsTheString', 'this is another one' => 'thisIsAnotherOne', 'i-am-playing-a-trick' => 'i-am-playing-a-trick', 'what_do_you_think-yo?' => 'whatDoYouThink-yo?');
     foreach ($strs as $str => $expect) {
         $this->assertEquals($expect, camelize($str));
     }
 }
Ejemplo n.º 6
0
 public static function generateLink($id, $name, $folder)
 {
     $images = array();
     foreach (array(self::IMAGE_ORIGINAL, self::IMAGE_LARGE, self::IMAGE_MEDIUM, self::IMAGE_SMALL, self::IMAGE_THUMB) as $size) {
         $images[camelize(strtolower($size))] = self::createLink($id, $size, $name, $folder);
     }
     return $images;
 }
Ejemplo n.º 7
0
 protected function camelize($string)
 {
     if (defined('STRICT_TYPES') && CAMEL_CASE == '1') {
         return (string) self::parameters(['string' => DT::STRING])->call(__FUNCTION__)->with($string)->returning(DT::STRING);
     } else {
         return (string) camelize($string);
     }
 }
Ejemplo n.º 8
0
 function sub($commands)
 {
     $name = $commands[0];
     $error = new Error();
     $error->command_exists($name);
     $options = getopt(self::SHORTOPTS, self::LONGOPTS);
     $class_name = 'Pgit\\Command\\' . camelize(strtr($name, '-', '_'));
     $instance = new $class_name($commands, $options);
     $instance->run();
 }
Ejemplo n.º 9
0
 public function command_exists($name)
 {
     $class_name = 'Pgit\\Command\\' . camelize(strtr($name, '-', '_'));
     $filename = \Pgit\Autoloader::load_class_path($class_name);
     if (!file_exists($filename) or !preg_match("#^[a-z\\-]+\$#", $name)) {
         $message = sprintf("pgit: '%s' is not a git command. See 'pgit --help'\n", $name);
         echo $message;
         exit;
     }
 }
Ejemplo n.º 10
0
 public function getTableCols()
 {
     $dbCols = \Meta\Db::colInfo($this->table);
     $cols = array();
     foreach ($dbCols as $info) {
         $name = $info->Field;
         // ignore some fields
         if (in_array($name, array('password'))) {
             continue;
         }
         $cols[$info->Field] = $this->getColType($info, array('id' => $name, 'label' => camelize($info->Field)));
     }
     return $cols;
 }
Ejemplo n.º 11
0
 public function getTableFields()
 {
     $dbCols = \Meta\Db::colInfo($this->table);
     $fields = array();
     foreach ($dbCols as $info) {
         $name = $info->Field;
         // ignore some fields
         if (in_array($name, array('password'))) {
             continue;
         }
         $fields[$info->Field] = $this->getFieldType($info, array('name' => $name, 'label' => camelize($info->Field), 'isRequired' => $info->Null == 'NO'));
     }
     return $fields;
 }
Ejemplo n.º 12
0
 /**
  * Prepares the data before generation.
  *
  * @param  array $data
  * @return void
  */
 public function prepareData(array &$data)
 {
     $bootstrap = ['button' => 'btn btn-default', 'buttonPrimary' => 'btn btn-primary', 'formControl' => 'form-control', 'formGroup' => 'form-group col-lg-12 col-md-12 col-sm-12 col-xs-12', 'label' => 'control-label', 'table' => 'table table table-striped table-hover', 'textRight' => 'text-right'];
     if ($data['isBootstrap']) {
         $data['bootstrap'] = $bootstrap;
     }
     $data['camel'] = [];
     $data['underscore'] = [];
     $data['foreignKeys'] = [];
     $data['primaryKeys'] = [];
     $data['plural'] = plural($data['name']);
     $data['singular'] = singular($data['name']);
     $primaryKey = 'get_' . $this->describe->getPrimaryKey($data['name']);
     $data['primaryKey'] = $primaryKey;
     if ($this->data['isCamel']) {
         $data['primaryKey'] = camelize($data['primaryKey']);
     }
     $data['columns'] = $this->describe->getTable($data['name']);
 }
Ejemplo n.º 13
0
 /**
  * Loads and returns a db adapter instance.
  */
 static function get_adapter($name, $params)
 {
     // Adapter class name convention.
     $adapter_class = camelize($name) . 'Database';
     // Try to load adapter class.
     if (!class_exists($adapter_class)) {
         $adapter_file = APP_ROOT . "core/library/db/{$adapter_class}.php";
         if (is_file($adapter_file)) {
             require_once $adapter_file;
         }
     }
     // Instantiate the adapter.
     $adapter = new $adapter_class($params);
     // Make sure it extends Database.
     if ($adapter instanceof Database == false) {
         throw new Exception("{$name} is not a valid database adapter ({$adapter_class})");
     }
     return $adapter;
 }
Ejemplo n.º 14
0
 protected function _run_middlewares()
 {
     $this->load->helper('inflector');
     $middlewares = $this->middleware();
     foreach ($middlewares as $middleware) {
         $middlewareArray = explode('|', str_replace(' ', '', $middleware));
         $middlewareName = $middlewareArray[0];
         $runMiddleware = true;
         if (isset($middlewareArray[1])) {
             $options = explode(':', $middlewareArray[1]);
             $type = $options[0];
             $methods = explode(',', $options[1]);
             if ($type == 'except') {
                 if (in_array($this->router->method, $methods)) {
                     $runMiddleware = false;
                 }
             } else {
                 if ($type == 'only') {
                     if (!in_array($this->router->method, $methods)) {
                         $runMiddleware = false;
                     }
                 }
             }
         }
         $filename = ucfirst(camelize($middlewareName)) . 'Middleware';
         if ($runMiddleware == true) {
             if (file_exists(APPPATH . 'middlewares/' . $filename . '.php')) {
                 require APPPATH . 'middlewares/' . $filename . '.php';
                 $ci =& get_instance();
                 $object = new $filename($this, $ci);
                 $object->run();
                 $this->middlewares[$middlewareName] = $object;
             } else {
                 if (ENVIRONMENT == 'development') {
                     show_error('Unable to load middleware: ' . $filename . '.php');
                 } else {
                     show_error('Sorry something went wrong.');
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
 function delete_model($name)
 {
     $results = array();
     $name = singularize($name);
     $uploader_class_suffix = 'ImageUploader';
     $image_uploader_class_suffix = 'ImageUploader';
     $file_uploader_class_suffix = 'FileUploader';
     $uploaders_path = FCPATH . 'application/third_party/orm_uploaders/';
     $model_path = FCPATH . 'application/models/' . ucfirst(camelize($name)) . EXT;
     $content = read_file($model_path);
     preg_match_all('/OrmImageUploader::bind\\s*\\((?P<k>.*)\\);/', $content, $image_uploaders);
     $image_uploaders = array_map(function ($image_uploader) use($name, $image_uploader_class_suffix) {
         return isset($image_uploader[1]) ? $image_uploader[1] : ucfirst(camelize($name)) . $image_uploader_class_suffix;
     }, array_map(function ($image_uploader) {
         $pattern = '/(["\'])(?P<kv>(?>[^"\'\\\\]++|\\\\.|(?!\\1)["\'])*)\\1?/';
         preg_match_all($pattern, $image_uploader, $image_uploaders);
         return $image_uploaders['kv'];
     }, $image_uploaders['k']));
     array_map(function ($image_uploader) use($uploaders_path, &$results) {
         if (delete_file($uploaders_path . $image_uploader . EXT)) {
             array_push($results, $uploaders_path . $image_uploader . EXT);
         }
     }, $image_uploaders);
     preg_match_all('/OrmFileUploader::bind\\s*\\((?P<k>.*)\\);/', $content, $file_uploaders);
     $file_uploaders = array_map(function ($file_uploader) use($name, $file_uploader_class_suffix) {
         return isset($file_uploader[1]) ? $file_uploader[1] : ucfirst(camelize($name)) . $file_uploader_class_suffix;
     }, array_map(function ($file_uploader) {
         $pattern = '/(["\'])(?P<kv>(?>[^"\'\\\\]++|\\\\.|(?!\\1)["\'])*)\\1?/';
         preg_match_all($pattern, $file_uploader, $file_uploaders);
         return $file_uploaders['kv'];
     }, $file_uploaders['k']));
     array_map(function ($file_uploader) use($uploaders_path, &$results) {
         if (delete_file($uploaders_path . $file_uploader . EXT)) {
             array_push($results, $uploaders_path . $file_uploader . EXT);
         }
     }, $file_uploaders);
     if (delete_file($model_path)) {
         array_push($results, $model_path);
     }
     return $results;
 }
Ejemplo n.º 16
0
 /**
  * Generates set of code based on data.
  * 
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $accessor = 'get_' . $field;
         $mutator = 'set_' . $field;
         $this->data['camel'][$field] = ['field' => lcfirst(camelize($field)), 'accessor' => lcfirst(camelize($accessor)), 'mutator' => lcfirst(camelize($mutator))];
         $this->data['underscore'][$field] = ['field' => lcfirst(underscore($field)), 'accessor' => lcfirst(underscore($accessor)), 'mutator' => lcfirst(underscore($mutator))];
         if ($column->isForeignKey()) {
             $field = $column->getField();
             array_push($this->data['indexes'], $field);
             $this->data['primaryKeys'][$field] = 'get_' . $this->describe->getPrimaryKey($column->getReferencedTable());
             if ($this->data['isCamel']) {
                 $this->data['primaryKeys'][$field] = camelize($this->data['primaryKeys'][$field]);
             }
         }
         $column->setReferencedTable(Tools::stripTableSchema($column->getReferencedTable()));
     }
     return $this->data;
 }
Ejemplo n.º 17
0
 public static function handle_request()
 {
     self::setup();
     SilkRoute::load_routes();
     $params = array();
     try {
         $params = SilkRoute::match_route(SilkRequest::get_requested_page());
         $class_name = camelize($params['controller'] . '_controller');
         if (class_exists($class_name)) {
             $controller = new $class_name();
         } else {
             throw new SilkControllerNotFoundException();
         }
         echo $controller->run_action($params['action'], $params);
     } catch (SilkRouteNotMatchedException $ex) {
         die("route not found");
     } catch (SilkControllerNotFoundException $ex) {
         die("controller not found");
     } catch (SilkViewNotFoundException $ex) {
         die("template not found");
     }
 }
Ejemplo n.º 18
0
 public function test_camelize_with_underscores()
 {
     $this->assertEquals("CamelCase", self::$inflector->camelize('Camel_Case'));
     $this->assertEquals("CamelCase", camelize('Camel_Case'));
 }
Ejemplo n.º 19
0
    foreach ($images as $image) {
        ?>
    OrmImageUploader::bind ('<?php 
        echo $image;
        ?>
', '<?php 
        echo ucfirst(camelize($name)) . ucfirst($image) . $image_uploader_class_suffix;
        ?>
');
<?php 
    }
}
?>

<?php 
if ($files) {
    foreach ($files as $file) {
        ?>
    OrmFileUploader::bind ('<?php 
        echo $file;
        ?>
', '<?php 
        echo ucfirst(camelize($name)) . ucfirst($file) . $file_uploader_class_suffix;
        ?>
');
<?php 
    }
}
?>
  }
}
Ejemplo n.º 20
0
Archivo: Admin.php Proyecto: eadz/chyrp
 /**
  * Function: display
  * Renders the page.
  *
  * Parameters:
  *     $action - The template file to display, in (theme dir)/pages.
  *     $context - Context for the template.
  *     $title - The title for the page. Defaults to a camlelization of the action, e.g. foo_bar -> Foo Bar.
  */
 public function display($action, $context = array(), $title = "")
 {
     $this->displayed = true;
     fallback($title, camelize($action, true));
     $this->context = array_merge($context, $this->context);
     $trigger = Trigger::current();
     $trigger->filter($this->context, array("admin_context", "admin_context_" . str_replace("/", "_", $action)));
     # Are there any extension-added pages?
     foreach (array("write" => array(), "manage" => array("import", "export"), "settings" => array(), "extend" => array("modules", "feathers", "themes")) as $main_nav => $val) {
         ${$main_nav} = $val;
         $trigger->filter(${$main_nav}, $main_nav . "_pages");
     }
     $visitor = Visitor::current();
     $route = Route::current();
     $this->context["theme"] = Theme::current();
     $this->context["flash"] = Flash::current();
     $this->context["trigger"] = $trigger;
     $this->context["title"] = $title;
     $this->context["site"] = Config::current();
     $this->context["visitor"] = $visitor;
     $this->context["logged_in"] = logged_in();
     $this->context["route"] = $route;
     $this->context["hide_admin"] = isset($_SESSION["hide_admin"]);
     $this->context["now"] = time();
     $this->context["version"] = CHYRP_VERSION;
     $this->context["debug"] = DEBUG;
     $this->context["feathers"] = Feathers::$instances;
     $this->context["modules"] = Modules::$instances;
     $this->context["admin_theme"] = $this->admin_theme;
     $this->context["theme_url"] = Config::current()->chyrp_url . "/admin/themes/" . $this->admin_theme;
     $this->context["POST"] = $_POST;
     $this->context["GET"] = $_GET;
     $this->context["navigation"] = array();
     $show = array("write" => array($visitor->group->can("add_draft", "add_post", "add_page")), "manage" => array($visitor->group->can("view_own_draft", "view_draft", "edit_own_draft", "edit_own_post", "edit_post", "delete_own_draft", "delete_own_post", "delete_post", "add_page", "edit_page", "delete_page", "add_user", "edit_user", "delete_user", "add_group", "edit_group", "delete_group")), "settings" => array($visitor->group->can("change_settings")), "extend" => array($visitor->group->can("toggle_extensions")));
     foreach ($show as $name => &$arr) {
         $trigger->filter($arr, $name . "_nav_show");
     }
     $this->context["navigation"]["write"] = array("title" => __("Write"), "show" => in_array(true, $show["write"]), "selected" => in_array($action, $write) or match("/^write_/", $action));
     $this->context["navigation"]["manage"] = array("title" => __("Manage"), "show" => in_array(true, $show["manage"]), "selected" => in_array($action, $manage) or match(array("/^manage_/", "/^edit_/", "/^delete_/", "/^new_/"), $action));
     $this->context["navigation"]["settings"] = array("title" => __("Settings"), "show" => in_array(true, $show["settings"]), "selected" => in_array($action, $settings) or match("/_settings\$/", $action));
     $this->context["navigation"]["extend"] = array("title" => __("Extend"), "show" => in_array(true, $show["extend"]), "selected" => in_array($action, $extend));
     $this->subnav_context($route->action);
     $trigger->filter($this->context["selected"], "nav_selected");
     $this->context["sql_debug"] = SQL::current()->debug;
     $file = MAIN_DIR . "/admin/themes/%s/pages/" . $action . ".twig";
     $template = file_exists(sprintf($file, $this->admin_theme)) ? sprintf($file, $this->admin_theme) : sprintf($file, "default");
     $config = Config::current();
     if (!file_exists($template)) {
         foreach (array(MODULES_DIR => $config->enabled_modules, FEATHERS_DIR => $config->enabled_feathers) as $path => $try) {
             foreach ($try as $extension) {
                 if (file_exists($path . "/" . $extension . "/pages/admin/" . $action . ".twig")) {
                     $template = $path . "/" . $extension . "/pages/admin/" . $action . ".twig";
                 }
             }
         }
         if (!file_exists($template)) {
             error(__("Template Missing"), _f("Couldn't load template: <code>%s</code>", array($template)));
         }
     }
     # Try the theme first
     try {
         $this->theme->getTemplate($template)->display($this->context);
     } catch (Exception $t) {
         # Fallback to the default
         try {
             $this->default->getTemplate($template)->display($this->context);
         } catch (Exception $e) {
             $prettify = preg_replace("/([^:]+): (.+)/", "\\1: <code>\\2</code>", $e->getMessage());
             $trace = debug_backtrace();
             $twig = array("file" => $e->filename, "line" => $e->lineno);
             array_unshift($trace, $twig);
             error(__("Error"), $prettify, $trace);
         }
     }
 }
Ejemplo n.º 21
0
 /**
  * Function: filter
  * Filters the post attributes through filter_post and any Feather filters.
  */
 private function filter()
 {
     $trigger = Trigger::current();
     $class = camelize($this->feather);
     $trigger->filter($this, "filter_post");
     if (isset(Feathers::$custom_filters[$class])) {
         # Run through feather-specified filters, first.
         foreach (Feathers::$custom_filters[$class] as $custom_filter) {
             $varname = $custom_filter["field"] . "_unfiltered";
             if (!isset($this->{$varname})) {
                 $this->{$varname} = @$this->{$custom_filter}["field"];
             }
             $this->{$custom_filter}["field"] = call_user_func_array(array(Feathers::$instances[$this->feather], $custom_filter["name"]), array($this->{$custom_filter}["field"], $this));
         }
     }
     if (isset(Feathers::$filters[$class])) {
         # Now actually filter it.
         foreach (Feathers::$filters[$class] as $filter) {
             $varname = $filter["field"] . "_unfiltered";
             if (!isset($this->{$varname})) {
                 $this->{$varname} = @$this->{$filter}["field"];
             }
             if (isset($this->{$filter}["field"]) and !empty($this->{$filter}["field"])) {
                 $trigger->filter($this->{$filter}["field"], $filter["name"], $this);
             }
         }
     }
 }
Ejemplo n.º 22
0
/**
 * Function: init_extensions
 * Initialize all Modules and Feathers.
 */
function init_extensions()
{
    $config = Config::current();
    # Instantiate all Modules.
    foreach ($config->enabled_modules as $index => $module) {
        if (!file_exists(MODULES_DIR . "/" . $module . "/" . $module . ".php")) {
            unset($config->enabled_modules[$index]);
            continue;
        }
        if (file_exists(MODULES_DIR . "/" . $module . "/locale/" . $config->locale . ".mo")) {
            load_translator($module, MODULES_DIR . "/" . $module . "/locale/" . $config->locale . ".mo");
        }
        require MODULES_DIR . "/" . $module . "/" . $module . ".php";
        $camelized = camelize($module);
        if (!class_exists($camelized)) {
            continue;
        }
        Modules::$instances[$module] = new $camelized();
        Modules::$instances[$module]->safename = $module;
        foreach (YAML::load(MODULES_DIR . "/" . $module . "/info.yaml") as $key => $val) {
            Modules::$instances[$module]->{$key} = is_string($val) ? __($val, $module) : $val;
        }
    }
    # Instantiate all Feathers.
    foreach ($config->enabled_feathers as $index => $feather) {
        if (!file_exists(FEATHERS_DIR . "/" . $feather . "/" . $feather . ".php")) {
            unset($config->enabled_feathers[$index]);
            continue;
        }
        if (file_exists(FEATHERS_DIR . "/" . $feather . "/locale/" . $config->locale . ".mo")) {
            load_translator($feather, FEATHERS_DIR . "/" . $feather . "/locale/" . $config->locale . ".mo");
        }
        require FEATHERS_DIR . "/" . $feather . "/" . $feather . ".php";
        $camelized = camelize($feather);
        if (!class_exists($camelized)) {
            continue;
        }
        Feathers::$instances[$feather] = new $camelized();
        Feathers::$instances[$feather]->safename = $feather;
        foreach (YAML::load(FEATHERS_DIR . "/" . $feather . "/info.yaml") as $key => $val) {
            Feathers::$instances[$feather]->{$key} = is_string($val) ? __($val, $feather) : $val;
        }
    }
    # Initialize all modules.
    foreach (Feathers::$instances as $feather) {
        if (method_exists($feather, "__init")) {
            $feather->__init();
        }
    }
    foreach (Modules::$instances as $module) {
        if (method_exists($module, "__init")) {
            $module->__init();
        }
    }
}
Ejemplo n.º 23
0
 /**
  * Retrieve method by name. Method is saved to $_methods
  *
  * @param string $code
  * @return Axis_Checkout_Model_Total_Abstract
  */
 public function getMethod($code)
 {
     if (false === function_exists('camelize')) {
         function camelize($str)
         {
             $str = ltrim(str_replace(" ", "", ucwords(str_replace("_", " ", $str))));
             return (string) (strtolower(substr($str, 0, 1)) . substr($str, 1));
         }
     }
     if (!isset($this->_methods[$code])) {
         $className = 'Axis_Checkout_Model_Total_' . ucfirst(camelize($code));
         $this->_methods[$code] = new $className();
     }
     return $this->_methods[$code];
 }
Ejemplo n.º 24
0
        exit('{ notifications: [' . (!empty($info["notifications"]) ? '"' . implode('", "', $info["notifications"]) . '"' : "") . '] }');
        break;
    case "disable_module":
    case "disable_feather":
        $type = $_POST['action'] == "disable_module" ? "module" : "feather";
        if (!$visitor->group->can("change_settings")) {
            if ($type == "module") {
                exit("{ notifications: ['" . __("You do not have sufficient privileges to enable/disable modules.") . "'] }");
            } else {
                exit("{ notifications: ['" . __("You do not have sufficient privileges to enable/disable feathers.") . "'] }");
            }
        }
        if ($type == "module" and !module_enabled($_POST['extension']) or $type == "feather" and !feather_enabled($_POST['extension'])) {
            exit("{ notifications: [] }");
        }
        $class_name = camelize($_POST["extension"]);
        if (method_exists($class_name, "__uninstall")) {
            call_user_func(array($class_name, "__uninstall"), $_POST['confirm'] == "1");
        }
        $enabled_array = $type == "module" ? "enabled_modules" : "enabled_feathers";
        $config->set($enabled_array, array_diff($config->{$enabled_array}, array($_POST['extension'])));
        exit('{ notifications: [] }');
        break;
    case "reorder_feathers":
        $reorder = oneof(@$_POST['list'], $config->enabled_feathers);
        foreach ($reorder as &$value) {
            $value = preg_replace("/feathers\\[([^\\]]+)\\]/", "\\1", $value);
        }
        $config->set("enabled_feathers", $reorder);
        break;
}
Ejemplo n.º 25
0
 public function find_first($params = array())
 {
     $params = array_merge($params, array("limit" => "1"));
     $sql = $this->build_query($params);
     $newtable = camelize($this->table);
     $item = new $newtable($this->pdo);
     $item->row = $this->query($sql, "one");
     if (!$item->row) {
         return false;
     }
     $item->constraints = $this->constraints;
     return $item;
 }
Ejemplo n.º 26
0
/**
 * Converts string to camelized class name. First letter is always upper case
 *
 * @param string $string
 *
 * @return string
 * @author Aurimas Niekis <*****@*****.**>
 */
function classify($string)
{
    return camelize($string, true);
}
Ejemplo n.º 27
0
 function create_model($temp_path, $name, $images, $files)
 {
     $results = array();
     $name = singularize($name);
     $image_uploader_class_suffix = 'ImageUploader';
     $file_uploader_class_suffix = 'FileUploader';
     $uploaders_path = FCPATH . 'application/third_party/orm_uploaders/';
     $models_path = FCPATH . 'application/models/';
     $models = array_map(function ($t) {
         return basename($t, EXT);
     }, directory_map($models_path, 1));
     if ($models && in_array(ucfirst($name), $models)) {
         console_error("名稱重複!");
     }
     if (!is_writable($models_path)) {
         console_error("無法有寫入的權限!");
     }
     $uploaders = array_map(function ($t) {
         return basename($t, EXT);
     }, directory_map($uploaders_path, 1));
     if (!is_writable($uploaders_path)) {
         console_error("Uploader 無法有寫入的權限!");
     }
     $images = array_filter(array_map(function ($image) use($name, $uploaders_path, $uploaders, $image_uploader_class_suffix, $temp_path, &$results) {
         $image = strtolower($image);
         $uploader = ucfirst(camelize($name)) . ucfirst($image) . $image_uploader_class_suffix;
         if (!in_array($uploader, $uploaders) && write_file($uploader_path = $uploaders_path . $uploader . EXT, load_view($temp_path . 'image_uploader.php', array('name' => $uploader))) && array_push($results, $uploader_path)) {
             return $image;
         }
         return null;
     }, $images));
     $files = array_filter(array_map(function ($file) use($name, $uploaders_path, $uploaders, $file_uploader_class_suffix, $temp_path, &$results) {
         $file = strtolower($file);
         $uploader = ucfirst(camelize($name)) . ucfirst($file) . $file_uploader_class_suffix;
         if (!in_array($uploader, $uploaders) && write_file($uploader_path = $uploaders_path . $uploader . EXT, load_view($temp_path . 'file_uploader.php', array('name' => $uploader))) && array_push($results, $uploader_path)) {
             return $file;
         }
         return null;
     }, $files));
     $date = load_view($temp_path . 'model.php', array('name' => $name, 'images' => $images, 'files' => $files, 'image_uploader_class_suffix' => $image_uploader_class_suffix, 'file_uploader_class_suffix' => $file_uploader_class_suffix));
     if (!write_file($model_path = $models_path . ucfirst(camelize($name)) . EXT, $date)) {
         array_map(function ($column) use($name, $uploaders_path, $uploader_class_suffix) {
             delete_file($uploaders_path . ucfirst(camelize($name)) . ucfirst($column) . $uploader_class_suffix . EXT);
         }, $columns);
         console_error("新增 model 失敗!");
     }
     array_push($results, $model_path);
     return $results;
 }
Ejemplo n.º 28
0
 /**
  * Protected helper method that returns common variables that get used during the parsing of a template
  *
  * @access	protected
  * @param	string	The module name
  * @return	array
  */
 protected function _common_vars($name)
 {
     $vars = array();
     $vars['module'] = $name;
     $vars['model'] = $name;
     $vars['table'] = $name;
     $vars['module_name'] = ucwords(humanize($name));
     $vars['model_name'] = ucfirst($name);
     $vars['model_record'] = ucfirst(preg_replace('#ie$#', 'y', rtrim($name, 's')));
     $vars['ModuleName'] = ucfirst(camelize($name));
     $vars['MODULE_NAME'] = strtoupper($name);
     if ($vars['model_name'] == $vars['model_record']) {
         $vars['model_record'] = $vars['model_record'] . '_item';
     }
     return $vars;
 }
Ejemplo n.º 29
0
 /**
  * Magic method that will automatically look on the <a href="http://php.net/manual/en/class.reflectionclass.php" target="_blank">Reflection class object</a>
  *  for a camelized version of the method name
  *
  * @access	public
  * @param	string	The method name
  * @param	array	An array of arguments to pass to the Reflection class method being called
  * @return	boolean
  */
 public function __call($name, $args)
 {
     if (!preg_match('#^get|is|set#', $name)) {
         $name = 'get_' . $name;
     }
     if (strpos($name, '_') !== FALSE) {
         $name = camelize($name);
     }
     if (method_exists($this->reflection, $name)) {
         if (!empty($args)) {
             return $this->reflection->{$name}($args);
         } else {
             return $this->reflection->{$name}();
         }
     } else {
         //throw new Exception(lang('error_method_does_not_exist', $name));
         return FALSE;
     }
 }
Ejemplo n.º 30
0
{<{<{ if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author      OA Wu <*****@*****.**>
 * @copyright   Copyright (c) 2016 OA Wu Design
 */

class <?php 
echo ucfirst(camelize($name . $class_suffix));
?>
 extends ElasticaSearch {
  static $primary_key = 'id';
  static $type_name = '<?php 
echo pluralize($name);
?>
';

  public function __construct ($data = array ()) {
    parent::__construct ($data);
  }
}