예제 #1
0
 public function registerAction()
 {
     return $this->handleRequest(function () {
         $req = new Request();
         if ($req->isPost()) {
             $post = json_decode($req->getRawBody());
             $a = $this->getUserDocument();
             $user = new $a();
             $user->salt = Text::random(Text::RANDOM_ALNUM);
             $user->password = $this->hash($post->password, $user->salt);
             unset($post->password);
             $post = (array) $post;
             foreach ($post as $key => $value) {
                 $user->{$key} = $value;
             }
             $user->save();
             $this->session->set('user', $user);
         } else {
             if ($req->isOptions()) {
                 return '';
             }
         }
         return $this->jsonOutput($user);
     });
 }
예제 #2
0
 /**
  * Generate view
  */
 public function build()
 {
     $action = Text::uncamelize($this->_options['action']);
     $viewName = explode('-', str_replace('_', '-', Text::uncamelize($this->_options['name'])));
     if (count($viewName) > 1) {
         array_pop($viewName);
     }
     $viewName = implode('-', $viewName);
     $viewDir = $this->_options['directory'] . DIRECTORY_SEPARATOR . $viewName;
     $viewPath = $viewDir . DIRECTORY_SEPARATOR . $action . '.volt';
     $code = "<?php\n" . Tools::getCopyright() . "\n?>\n";
     $code = str_replace("\t", "    ", $code);
     if (!file_exists($viewPath) || $this->_options['force'] == true) {
         if (!is_dir($viewDir)) {
             mkdir($viewDir, 0777, true);
             chmod($viewDir, 0777);
         }
         if (!@file_put_contents($viewPath, $code)) {
             throw new \Exception("Unable to write to '{$viewPath}'");
         }
         chmod($viewPath, 0777);
     } else {
         throw new \Exception("The View '{$action}' already exists");
     }
     return $viewName;
 }
예제 #3
0
 public function eager($model, $field = null, $localKey = null, $foreignKey = '_id')
 {
     if ($field == null || $localKey == null) {
         $className = strtolower((new \ReflectionClass($model))->getShortName());
         if (Text::endsWith($className, 's')) {
             $className = substr($className, 0, -1);
         }
     }
     if ($field == null) {
         $field = $className;
     }
     if ($localKey == null) {
         $localKey = $className . '_id';
     }
     $keys = [];
     foreach ($this->array as $item) {
         if (!in_array($item->{$localKey}, $keys)) {
             $keys[] = $item->{$localKey};
         }
     }
     $result = $model::init()->find([$foreignKey => ['$in' => $keys]])->keyBy('_id');
     foreach ($this->array as $item) {
         $item->setRelation($field, $result[(string) $item->{$localKey}]);
     }
     return $this;
 }
예제 #4
0
 public function __invoke($uri, $query = null, $configKey = 'default')
 {
     if ($query) {
         if (true === is_array($query)) {
             $query = implode(',', $query);
         }
         if (false !== ($pos = strrpos($uri, '.'))) {
             $uri = explode('/', $uri);
             $fileName = array_pop($uri);
             $nameArray = explode('.', $fileName);
             $nameExt = array_pop($nameArray);
             $nameFinal = array_pop($nameArray);
             $nameFinal .= ',' . $query;
             array_push($nameArray, $nameFinal, $nameExt);
             $fileName = implode('.', $nameArray);
             array_push($uri, $fileName);
             $uri = implode('/', $uri);
         }
     }
     if (\Phalcon\Text::startsWith($uri, 'http://', false) || \Phalcon\Text::startsWith($uri, 'https://', false)) {
         return str_replace('http://api.wallstreetcn.com/', 'http://thumbnail.wallstreetcn.com/thumb/', $uri);
     }
     $config = self::getDI()->getConfig();
     if (isset($config->thumbnail->{$configKey}->baseUri) && ($baseUrl = $config->thumbnail->{$configKey}->baseUri)) {
         return $baseUrl . $uri;
     }
     return $uri;
 }
예제 #5
0
 public function beforeValidationOnCreate()
 {
     $this->createdAt = time();
     if (!$this->slug) {
         $this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
     }
 }
예제 #6
0
 /**
  * Return menu options
  *
  * @return array
  */
 public function getMenuOptions()
 {
     $this->_limitParamValue = 100;
     $rows = $this->getColumnData();
     $acl = $this->_di->get('acl');
     $viewer = $this->_di->get('viewer');
     $options = [];
     foreach ($rows as $row) {
         $option = [];
         $option['id'] = $row['id'];
         $option['text'] = $row['title'];
         if ($row['module'] && $row['controller']) {
             if (!$acl->isAllowed($viewer->getRole(), \Engine\Acl\Dispatcher::ACL_ADMIN_MODULE, \Engine\Acl\Dispatcher::ACL_ADMIN_CONTROLLER, '*') && !$acl->isAllowed($viewer->getRole(), \Engine\Acl\Dispatcher::ACL_ADMIN_MODULE, \Engine\Acl\Dispatcher::ACL_ADMIN_CONTROLLER, 'read')) {
                 if (!$acl->isAllowed($viewer->getRole(), $row['module'], $row['controller'], 'read')) {
                     continue;
                 }
             }
             $option['controller'] = \Phalcon\Text::camelize($row['module']) . ".controller." . \Phalcon\Text::camelize($row['controller']);
             $option['moduleName'] = \Phalcon\Text::camelize($row['module']);
             $option['controllerName'] = \Phalcon\Text::camelize($row['controller']);
             $option['leaf'] = true;
             $option['cls'] = 'window-list-item';
             $option['iconCls'] = 'window-list-item-icon';
         }
         $option['qtip'] = $row['description'];
         $options[] = $option;
     }
     return $options;
 }
예제 #7
0
파일: Ui.php 프로젝트: skullab/area51
 public function __get($name)
 {
     if ($this->getDI()->has($name)) {
         return parent::__get($name);
     }
     return $this->{lcfirst(\Phalcon\Text::camelize("get_{$name}"))}();
 }
 public function resetAction()
 {
     $connection = new \Phalcon\Db\Adapter\Pdo\Mysql($this->config->database->toArray());
     $tables = $connection->listTables();
     foreach ($tables as $table) {
         $tablename = \Phalcon\Text::camelize($table);
         $fd = fopen("{$this->config->application->formsDir}/{$tablename}Form.php", "w");
         fwrite($fd, "<?php" . self::NL . self::NL);
         // Begin class
         fwrite($fd, "class {$tablename}Form {" . self::NL);
         $columns = $connection->describeColumns($table);
         foreach ($columns as $column) {
             if ($column instanceof \Phalcon\Db\Column) {
                 // Escape if column is primary
                 if ($column->isPrimary()) {
                     continue;
                 }
                 // Begin method
                 $columnname = \Phalcon\Text::camelize($column->getName());
                 fwrite($fd, self::TAB . "private function _{$columnname}() {" . self::NL);
                 // Write element
                 $columntype_base = $this->_getBaseType($column->getType());
                 $columntype = $this->_getType($columntype_base, $column);
                 fwrite($fd, self::TAB . self::TAB . "\$element = new \\Phalcon\\Forms\\Element\\{$columntype}(\"{$columnname}\");" . self::NL);
                 fwrite($fd, self::TAB . self::TAB . "\$element->setLabel(\"{$columnname}\");" . self::NL);
                 // Add empty selection for select fields
                 if ($columntype == "Select") {
                     fwrite($fd, self::TAB . self::TAB . "\$element->setOptions([]);" . self::NL);
                 }
                 // Add validator on text fields
                 if ($columntype == "Text" && $column->getSize() > 0) {
                     fwrite($fd, self::TAB . self::TAB . "\$element->addValidator(new \\Phalcon\\Validation\\Validator\\StringLength([" . self::NL);
                     fwrite($fd, self::TAB . self::TAB . self::TAB . "\"max\" => {$column->getSize()}" . self::NL);
                     fwrite($fd, self::TAB . self::TAB . "]));" . self::NL);
                 }
                 // End method
                 fwrite($fd, self::TAB . self::TAB . "return \$element;" . self::NL);
                 fwrite($fd, self::TAB . "}" . self::NL);
             }
         }
         // Final method : construction of the form
         fwrite($fd, self::TAB . "public function setFields() {" . self::NL);
         foreach ($columns as $column) {
             if ($column instanceof \Phalcon\Db\Column) {
                 if ($column->isPrimary()) {
                     continue;
                 }
                 $columnname = \Phalcon\Text::camelize($column->getName());
                 fwrite($fd, self::TAB . self::TAB . "\$this->add(\$this->_{$columnname}());" . self::NL);
             }
         }
         fwrite($fd, self::TAB . "}" . self::NL);
         // End class
         fwrite($fd, "}" . self::NL . self::NL);
         fclose($fd);
     }
     $this->view->disable();
     echo "done!";
     return FALSE;
 }
예제 #9
0
파일: helper.php 프로젝트: xueron/pails
 /**
  * Gets the value of an environment variable. Supports boolean, empty and null.
  *
  * @param  string $key
  * @param  mixed $default
  * @return mixed
  */
 function env($key, $default = null)
 {
     $value = getenv($key);
     if ($value === false) {
         return value($default);
     }
     switch (strtolower($value)) {
         case 'true':
         case '(true)':
             return true;
         case 'false':
         case '(false)':
             return false;
         case 'empty':
         case '(empty)':
             return '';
         case 'null':
         case '(null)':
             return;
     }
     if (Text::startsWith($value, '"') && Text::endsWith($value, '"')) {
         return substr($value, 1, -1);
     }
     return $value;
 }
예제 #10
0
파일: Loader.php 프로젝트: szytko/core
 /**
  * Extract Vegas modules from composer vegas-cmf vendors.
  *
  * @param $modulesList
  * @return mixed
  */
 private function dumpModulesFromVendor(array &$modulesList)
 {
     if (!file_exists(APP_ROOT . '/composer.json')) {
         return $modulesList;
     }
     $fileContent = file_get_contents(APP_ROOT . DIRECTORY_SEPARATOR . 'composer.json');
     $json = json_decode($fileContent, true);
     $vendorDir = realpath(APP_ROOT . (isset($json['config']['vendor-dir']) ? DIRECTORY_SEPARATOR . $json['config']['vendor-dir'] : DIRECTORY_SEPARATOR . 'vendor'));
     $vendorDir .= DIRECTORY_SEPARATOR . 'vegas-cmf';
     $directoryIterator = new \DirectoryIterator($vendorDir);
     foreach ($directoryIterator as $libDir) {
         if ($libDir->isDot()) {
             continue;
         }
         //creates path to Module.php file
         $moduleSettingsFile = implode(DIRECTORY_SEPARATOR, [$vendorDir, $libDir, 'module', self::MODULE_SETTINGS_FILE]);
         if (!file_exists($moduleSettingsFile)) {
             continue;
         }
         $baseName = Text::camelize($libDir->getBasename());
         if (!isset($modulesList[$baseName])) {
             $modulesList[$baseName] = ['className' => $baseName . '\\' . pathinfo(self::MODULE_SETTINGS_FILE, PATHINFO_FILENAME), 'path' => $moduleSettingsFile];
         }
     }
     return $modulesList;
 }
 public function translate($idElement, $key, $default)
 {
     $this->message = "";
     if (Text::startsWith($this->language, "en", true)) {
         return $default;
     }
     $trans = $this->translations->filter(function ($object) use($idElement, $key) {
         if (Text::startsWith($this->language, $object->getLang(), true) && $object->getIdElement() == $idElement && $object->getName() == $key) {
             return $object;
         }
     });
     if (is_array($trans)) {
         if (sizeof($trans) > 0) {
             $trans = $trans[0];
         } else {
             $this->message = $this->translate(1, "translate.info", "");
             return $default;
         }
     }
     if (is_a($trans, "Translation")) {
         return $trans->getText();
     } else {
         $this->message = $this->translate(1, "translate.info", "");
         return $default;
     }
 }
예제 #12
0
 public function getSource()
 {
     $nowClassName = get_class($this);
     $trueClassName = str_replace(__NAMESPACE__ . '\\', '', $nowClassName);
     $trueClassName = Text::uncamelize($trueClassName);
     return DB_PREFIX . strtolower($trueClassName);
 }
예제 #13
0
 public function pageAction()
 {
     $pageSlug = $this->getUriParameter('pageSlug');
     $pageTitle = \Phalcon\Text::camelize($pageSlug);
     $this->tag->setTitle($pageTitle);
     $this->view->pick('pages/' . $pageSlug);
 }
예제 #14
0
파일: Uppercase.php 프로젝트: arius86/core
 /**
  * {@inheritdoc}
  */
 public function resolve(&$value)
 {
     if (is_string($value) && strlen($value) > 0) {
         $value = \Phalcon\Text::upper($value);
     }
     return $value;
 }
예제 #15
0
 public function initialize()
 {
     foreach (self::$routes as $route => $controller) {
         $name = str_replace('_', '-', Text::uncamelize($controller));
         $this->add($route, $controller)->setName($name);
     }
 }
예제 #16
0
 private function addFunction($jsCode)
 {
     if (!Text::startsWith($jsCode, "function")) {
         $jsCode = "%function(){" . $jsCode . "}%";
     }
     return $jsCode;
 }
예제 #17
0
 public function indexAction()
 {
     // No view needed since this is all backend stuff.
     $this->view->disable();
     // Generate random ids until we find one not in use.
     // This will cause one additional SQL query at minimum when creating a paste.
     do {
         $id = Text::random(Text::RANDOM_ALNUM, rand(5, 13));
     } while (Paste::findFirstByid($id));
     $paste = new Paste();
     $paste->id = $id;
     $paste->content = rtrim($this->request->getPost("content"));
     $paste->lang = $this->request->getPost("lang") == null ? "auto" : $this->request->getPost("lang");
     // No sanitisation needed if we accept anything at all to mean true and nothing to mean false.
     // Also addresses http://stackoverflow.com/a/14067312
     $paste->private = $this->request->getPost("private") == null ? 0 : 1;
     $paste->owner_addr = $this->request->getClientAddress();
     $paste->size_bytes = strlen($paste->content);
     if (!$paste->save()) {
         foreach ($paste->getMessages() as $message) {
             $this->flash->error($message->getMessage());
         }
         return $this->response->redirect();
     }
     return $this->response->redirect($this->url->get("v/{$id}"));
 }
예제 #18
0
 public function beforeValidationOnCreate()
 {
     $this->createdAt = $this->createdAt ? $this->createdAt : time();
     if (!$this->slug) {
         $this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
     }
     $this->title = \Eva\EvaEngine\Text\Substring::substrCn(strip_tags($this->getContentHtml()), 100);
 }
예제 #19
0
파일: myTools.php 프로젝트: huoybb/support
 public static function camelize($title)
 {
     $words = explode(' ', trim($title));
     foreach ($words as $key => $word) {
         $words[$key] = \Phalcon\Text::camelize($word);
     }
     return implode(' ', $words);
 }
예제 #20
0
파일: Post.php 프로젝트: skybird/phalcon
 public function beforeValidationOnCreate()
 {
     $this->createdAt = $this->createdAt ? $this->createdAt : time();
     if (!$this->slug) {
         $this->slug = \Phalcon\Text::random(\Phalcon\Text::RANDOM_ALNUM, 8);
     }
     $this->validate(new Uniqueness(array('field' => 'slug')));
 }
예제 #21
0
 /**
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     $getter = 'get' . \Phalcon\Text::camelize($name);
     if (method_exists($this, $getter)) {
         return $this->{$getter}();
     }
     return null;
 }
예제 #22
0
 private function correctCase($key)
 {
     if (strpos($key, '_')) {
         return lcfirst(Text::camelize($key));
     } else {
         return $key;
     }
 }
예제 #23
0
 public function createAction($r_controller = null, $r_action = null, $r_id = null)
 {
     $mapServerConfig = $this->getDI()->getConfig()->mapserver;
     $fileName = $mapServerConfig->mapfileCacheDir . $mapServerConfig->contextesCacheDir . $this->request->getPost("code") . ".map";
     //Ne pas créer le contexte si il y en a déjà un avec le même code
     if (file_exists($fileName)) {
         $this->flash->error("Le fichier {$fileName} existe déjà!");
         return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "new", "param" => !is_null($r_id) ? "/" . $r_controller . "/" . $r_action . "/" . $r_id : ""));
     }
     $idContexteADupliquer = $this->request->getPost('id_contexte_a_dupliquer');
     //On désire dupliquer un contexte
     if ($idContexteADupliquer) {
         if (!$this->peutDupliquerContexte($idContexteADupliquer)) {
             $this->flash->error("Vous n'avez pas la permission de dupliquer le contexte {$idContexteADupliquer}.");
             return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "new", "param" => !is_null($r_id) ? "/" . $r_controller . "/" . $r_action . "/" . $r_id : ""));
         }
     }
     $this->traiterCodeOnlineRessource();
     $igoContexte = new IgoContexte();
     $igoContexte->mode = $this->request->getPost("mode");
     $igoContexte->position = $this->request->getPost("position");
     $igoContexte->zoom = $this->request->getPost("zoom");
     $igoContexte->code = $this->request->getPost("code");
     $igoContexte->nom = $this->request->getPost("nom");
     $igoContexte->description = $this->request->getPost("description");
     $igoContexte->mf_map_def = $this->request->getPost("mf_map_def");
     $igoContexte->date_modif = $this->request->getPost("date_modif");
     $igoContexte->json = $this->request->getPost("json");
     $igoContexte->mf_map_projection = $this->request->getPost("mf_map_projection");
     $igoContexte->profil_proprietaire_id = $this->request->getPost("profil_proprietaire_id");
     if ($igoContexte->profil_proprietaire_id == "") {
         $igoContexte->profil_proprietaire_id = null;
     }
     //Valider la sélection ou pas du profil propriétaire
     if (!$this->validationProfilProprietaire($igoContexte->profil_proprietaire_id, $messageErreurProfilProprietaire)) {
         foreach ($messageErreurProfilProprietaire as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "new", "param" => !is_null($r_id) ? "/" . $r_controller . "/" . $r_action . "/" . $r_id : ""));
     }
     $igoContexte->mf_map_meta_onlineresource = $this->request->getPost("mf_map_meta_onlineresource");
     $igoContexte->generer_onlineresource = $this->request->getPost("generer_onlineResource");
     try {
         if (!$igoContexte->save()) {
             foreach ($igoContexte->getMessages() as $message) {
                 $this->flash->error($message);
             }
             return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "new", "param" => !is_null($r_id) ? "/" . $r_controller . "/" . $r_action . "/" . $r_id : ""));
         }
         if ($idContexteADupliquer) {
             $this->dupliquerContexte($idContexteADupliquer, $igoContexte->id);
         }
         $this->flash->success(Text::camelize(str_replace("igo_", "", $this->ctlName)) . " " . $igoContexte->id . " créé avec succès");
     } catch (\Exception $e) {
         $this->flash->error($e->getMessage());
         return $this->dispatcher->forward(array("controller" => $this->ctlName, "action" => "new", "param" => !is_null($r_id) ? "/" . $r_controller . "/" . $r_action . "/" . $r_id : ""));
     }
 }
예제 #24
0
 /**
  * @param $parameters
  */
 public function run($parameters)
 {
     $name = $this->getOption(array('name', 1));
     $className = Text::camelize(isset($parameters[1]) ? $parameters[1] : $name);
     $fileName = Text::uncamelize($className);
     $schema = $this->getOption('schema');
     $modelBuilder = new ModelBuilder(array('name' => $name, 'schema' => $schema, 'className' => $className, 'fileName' => $fileName, 'genSettersGetters' => $this->isReceivedOption('get-set'), 'genDocMethods' => $this->isReceivedOption('doc'), 'namespace' => $this->getOption('namespace'), 'directory' => $this->getOption('directory'), 'modelsDir' => $this->getOption('output'), 'extends' => $this->getOption('extends'), 'excludeFields' => $this->getOption('excludefields'), 'force' => $this->isReceivedOption('force'), 'mapColumn' => $this->isReceivedOption('mapcolumn')));
     $modelBuilder->build();
 }
예제 #25
0
 public function run($parameters)
 {
     $name = $this->getOption(array('name', 1));
     $className = Text::camelize(isset($parameters[2]) ? $parameters[2] : $name);
     $fileName = Text::uncamelize($className);
     $schema = $this->getOption('schema');
     $modelBuilder = new \Phalcon\Builder\Model(array('name' => $name, 'schema' => $schema, 'className' => $className, 'fileName' => $fileName, 'genSettersGetters' => $this->isReceivedOption('get-set'), 'genDocMethods' => $this->isReceivedOption('doc'), 'namespace' => $this->getOption('namespace'), 'directory' => $this->getOption('directory'), 'force' => $this->isReceivedOption('force')));
     $modelBuilder->build();
 }
예제 #26
0
 /**
  * Icons to display, with or without text (see text option).
  * By default, the primary icon is displayed on the left of the label text and the secondary is displayed on the right.
  * The positioning can be controlled via CSS.
  * The value for the primary and secondary properties must match an icon class name, e.g., "ui-icon-gear".
  * For using only one icon: icons: { primary: "ui-icon-locked" }. For using two icons: icons: { primary: "ui-icon-gear", secondary: "ui-icon-triangle-1-s" }.
  * @param String $value default : { primary: null, secondary: null }
  * @return $this
  */
 public function setIcons($value)
 {
     if (is_string($value)) {
         if (Text::startsWith($value, "{")) {
         }
         $value = "%" . $value . "%";
     }
     return $this->setParam("icons", $value);
 }
예제 #27
0
 /**
  * Define source property with an ajax request based on $url
  * $url must return a JSON array of values
  * @param String $url
  * @return $this
  */
 public function setAjaxSource($url)
 {
     if (Text::startsWith($url, "/")) {
         $u = $this->js->getDi()->get("url");
         $url = $u->getBaseUri() . $url;
     }
     $ajax = "%function (request, response) {\n\t\t\t\$.ajax({\n\t\t\t\turl: '{$url}',\n\t\t\t\tdataType: 'jsonp',\n\t\t\t\tdata: {q : request.term},\n\t\t\t\tsuccess: function(data) {response(data);}\n\t\t\t});\n\t\t}%";
     return $this->setParam("source", $ajax);
 }
예제 #28
0
 /**
  * @param Event               $event
  * @param DispatcherInterface $dispatcher
  */
 public function beforeDispatchLoop(Event $event, DispatcherInterface $dispatcher, $data)
 {
     if ($dispatcher->getActionName()) {
         $actionName = $dispatcher->getActionName();
         $actionName = Text::camelize($actionName);
         $actionName = lcfirst($actionName);
         $dispatcher->setActionName($actionName);
     }
 }
예제 #29
0
 public static function camelize($module)
 {
     $tmpModuleNameArr = explode('-', $module);
     $moduleName = '';
     foreach ($tmpModuleNameArr as $part) {
         $moduleName .= \Phalcon\Text::camelize($part);
     }
     return $moduleName;
 }
예제 #30
0
 /**
  * @param VoltCompiler $compiler
  */
 public static function install($compiler)
 {
     foreach (get_class_methods(get_called_class()) as $method) {
         if ($method != __METHOD__) {
             $compiler->addFunction(Text::uncamelize($method), function ($resolvedArgs, $exprArgs) use($method) {
                 return get_called_class() . '::' . $method . '(' . $resolvedArgs . ')';
             });
         }
     }
 }