예제 #1
0
 public function buildSkin()
 {
     $skins = Util\File::getFolders(\Rebond\Config::getPath('siteFolder') . '/css/skin');
     $list = [];
     foreach ($skins as $skin) {
         $list[$skin] = $skin;
     }
     return Util\Form::buildDropDown('skin' . $this->unique, $list, $this->getModel()->getSkin());
 }
예제 #2
0
 public function generate()
 {
     $configFile = FULL_PATH . '/files/config.xml';
     if (!file_exists($configFile)) {
         Util\Error::kill(Util\Error::XML_CONFIG_NOT_FOUND, $configFile, __FILE__, __LINE__);
     }
     $conf = simplexml_load_string(file_get_contents($configFile));
     $configTpl = new Util\Template(Util\Template::SITE, ['generator', 'config']);
     foreach ($conf->servers->server as $server) {
         if (strpos($_SERVER['HTTP_HOST'], $server->attributes()->host->__toString()) === false) {
             continue;
         }
         $configTpl->set('httpHost', $server->attributes()->host);
         $configTpl->set('siteFolder', $server->siteFolder);
         $configTpl->set('adminFolder', $server->adminFolder);
         $configTpl->set('dbHost', $server->db->host);
         $configTpl->set('dbPort', $server->db->port);
         $configTpl->set('dbUsername', $server->db->username);
         $configTpl->set('dbPassword', $server->db->password);
         $configTpl->set('dbName', $server->db->name);
         $configTpl->set('type', $server->mail->type);
         $configTpl->set('email', $server->mail->email);
         if ($server->mail->type == 'smtp') {
             $configTpl->set('host', $server->mail->host);
             $configTpl->set('port', $server->mail->port);
             $configTpl->set('option', $server->mail->option);
             $configTpl->set('password', $server->mail->password);
         } else {
             $configTpl->set('host', '');
             $configTpl->set('port', '');
             $configTpl->set('option', '');
             $configTpl->set('password', '');
         }
         break;
     }
     $langs = [];
     foreach ($conf->languages->language as $language) {
         $tpl = new Util\Template(Util\Template::SITE, ['generator', 'config']);
         $tpl->set('lang', $language->attributes()->lang);
         $tpl->set('locale', $language->locale);
         $langs[] = $tpl->render('lang');
     }
     $configTpl->set('lang', implode('', $langs));
     $settings = [];
     foreach ($conf->settings->setting as $setting) {
         $tpl = new Util\Template(Util\Template::SITE, ['generator', 'config']);
         $tpl->set('key', $setting->attributes()->key);
         $tpl->set('value', $setting);
         $settings[] = $tpl->render('setting');
     }
     $configTpl->set('key', implode('', $settings));
     $configPath = \Rebond\Config::getPath('rebond') . 'Cache/Config.php';
     Util\File::save($configPath, 'w', str_replace('<#php', '<?php', $configTpl->render('config')));
 }
예제 #3
0
 private function produceService()
 {
     // Service template
     $serviceTpl = new Template(Template::SITE, ['generator', 'service']);
     $serviceTpl->set('package', $this->package);
     $serviceTpl->set('entity', $this->entity);
     $servicePath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/Service.php';
     if (!file_exists($servicePath)) {
         $render = str_replace('<#php', '<?php', $serviceTpl->render('service'));
         \Rebond\Util\File::save($servicePath, 'w', $render);
         $this->info[] = '<div>Service created.</div>';
     } else {
         $this->info[] = '<div class="exist">Service already exists.</div>';
     }
 }
예제 #4
0
 public static function log($code, $message, $file, $line)
 {
     $app = \Rebond\App::instance();
     $d = new \DateTime();
     $message = self::textify($message);
     if ($app->step() != \Rebond\Config::STEP_RUNNING) {
         $log = \Rebond\Config::getPath('log') . 'log.txt';
         $file = str_replace(FULL_PATH, '/', str_replace('\\', '/', $file));
         $trace = stripos($file, 'SplClassLoader') !== false ? self::textify(debug_backtrace()) : '';
         // date # code # message # trace # file # line
         $message = $d->format('Y-m-d H:i:s') . '#' . Error::value($code) . '#' . str_replace(FULL_PATH, '/', $message) . '#' . $trace . '#' . $file . '#' . $line . PHP_EOL;
         \Rebond\Util\File::save($log, 'a', $message);
     } else {
         if (!in_array($code, [Error::LANG_NOT_FOUND, Error::PAGE_NOT_FOUND]) && $app->env() == \Rebond\Config::ENV_PROD && $app->site()->getSendMailOnError()) {
             $emails = $app->site()->getMailListOnError();
             if ($emails != '') {
                 $emails = explode(',', $emails);
                 \Rebond\App\Error\Mail::error($app->site()->getTitle(), $emails, $code, $message, $file, $line);
             }
         }
         $log = null;
         if ($code == Error::LANG_NOT_FOUND) {
             $options = [];
             $options['where'][] = ['log.request_uri = ?', $_SERVER['REQUEST_URI']];
             $options['where'][] = ['log.message = ?', $message];
             $log = \Rebond\Core\Log\Data::load($options);
         }
         if (!isset($log)) {
             $log = new \Rebond\Core\Log\Model();
             $log->setCode($code);
             $log->setMessage($message);
             $log->setRequestUri($_SERVER['REQUEST_URI']);
         }
         $log->setUserId($app->userId());
         $log->setFile($file);
         $log->setLine($line);
         $log->setTrace(self::textify(debug_backtrace()));
         $log->setIp($_SERVER['REMOTE_ADDR']);
         $log->setReferer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
         return $log->save();
     }
     return 0;
 }
예제 #5
0
 private function produceData()
 {
     $dataTplName = 'data';
     // Data class
     $dataTpl = new Template(Template::SITE, ['generator', 'data']);
     $dataTpl->set('package', $this->package);
     $dataTpl->set('entity', $this->entity);
     $dataPath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/Data.php';
     if (!file_exists($dataPath)) {
         if ($this->package == 'App') {
             $dataTplName = 'data-app';
         }
         $render = str_replace('<#php', '<?php', $dataTpl->render($dataTplName));
         \Rebond\Util\File::save($dataPath, 'w', $render);
         $this->info[] = '<div>Data created.</div>';
     } else {
         $this->info[] = '<div class="exist">Data already exists.</div>';
     }
 }
예제 #6
0
 public function cache()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.config.cache', true, '/configuration');
     // view
     $this->setTpl();
     // main
     $files = \Rebond\Util\File::getFiles('files/cache');
     $tplMain = new Template(Template::SITE, ['admin', 'configuration']);
     $tplMain->set('files', $files);
     $tplMain->set('cache', $this->app->site()->getCacheTime());
     $tplMain->set('cachePath', \Rebond\Config::getPath('cache'));
     // layout
     $this->tplLayout->set('column1', $tplMain->render('cache'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'configCache');
     return $this->tplMaster->render('tpl-default');
 }
예제 #7
0
 public static function deleteAllMedia($path, $filename)
 {
     $upload = File::getNoExtension($filename);
     if (file_exists(\Rebond\Config::getPath('media') . $path . $filename)) {
         unlink(\Rebond\Config::getPath('media') . $path . $filename);
     }
     $files = glob(\Rebond\Config::getPath('media') . $path . $upload . '-*.*');
     foreach ($files as $file) {
         unlink($file);
     }
 }
예제 #8
0
 private function produceModel()
 {
     $modelTplName = 'model';
     // Model template
     $modelTpl = new Template(Template::SITE, ['generator', 'model']);
     $modelTpl->set('package', $this->package);
     $modelTpl->set('entity', $this->entity);
     $modelPath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/Model.php';
     if (!file_exists($modelPath)) {
         if ($this->package == 'App') {
             $modelTplName = 'model-app';
         }
         $render = str_replace('<#php', '<?php', $modelTpl->render($modelTplName));
         \Rebond\Util\File::save($modelPath, 'w', $render);
         $this->info[] = '<div>Model created.</div>';
     } else {
         $this->info[] = '<div class="exist">Model already exists.</div>';
     }
 }
예제 #9
0
 public function backup($type = null)
 {
     $this->checkConnection();
     $backupPath = FULL_PATH . 'files/backup/';
     if (!is_dir($backupPath)) {
         mkdir($backupPath, 0777, true);
     }
     $tables = [];
     $res = $this->pdo->query('SHOW TABLES');
     while ($row = $res->fetch(\PDO::FETCH_NUM)) {
         $tables[] = $row[0];
     }
     $sqlFile = '';
     // cycle through
     foreach ($tables as $table) {
         $stmt = $this->pdo->prepare('SELECT * FROM ' . $table);
         $stmt->execute();
         $sqlFile .= '-- TABLE ' . $table . ";\n\n";
         $sqlFile .= 'DROP TABLE IF EXISTS ' . $table . ";\n";
         $result2 = $this->pdo->query('SHOW CREATE TABLE ' . $table);
         $row2 = $result2->fetch(\PDO::FETCH_NUM);
         $sqlFile .= "\n" . $row2[1] . ";\n\n";
         if (in_array($table, ['core_log'])) {
             $sqlFile .= 'TRUNCATE TABLE ' . $table . ";\n\n";
             continue;
         }
         $sqlFile .= $this->backupData($table, $stmt);
     }
     //save file
     $type = isset($type) ? $type . '-' : '';
     $backup = $backupPath . 'db-' . $type . date('Ymd-His') . '.sql';
     \Rebond\Util\File::save($backup, 'w', $sqlFile);
 }
예제 #10
0
 public function tpl_edit()
 {
     // auth
     Util\Auth::isAdminAuthorized($this->signedUser, 'admin.designer', true, '/');
     // check
     $file = Util\Converter::string('f');
     $app = Util\Converter::string('app');
     $save = Util\Converter::string('save', 'post');
     if (empty($file)) {
         Util\Session::adminError('itemNotFound', [$file], '/designer/tpl');
     }
     $validator = Util\Validate::validateFilename('file', $file, true);
     if (!$validator->isValid()) {
         Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl');
     }
     $filePath = FULL_PATH . 'views/www/';
     if (!empty($app)) {
         $filePath = FULL_PATH . 'Rebond/App/' . $app . '/template/';
         $validator = Util\Validate::validateAlphaNumeric('app', $app, true);
         if (!$validator->isValid()) {
             Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl');
         }
     }
     if (!file_exists($filePath)) {
         Util\Session::adminError('itemNotFound', [$filePath], '/designer/tpl');
     }
     // action
     if (isset($save)) {
         $filePost = Util\Converter::string('file', 'post');
         $tplFile = Util\Converter::string('tpl-file', 'post');
         $appPost = Util\Converter::string('app', 'post');
         $file = FULL_PATH . 'views/' . \Rebond\Config::getPath('siteFolder') . '/' . $filePost;
         if (!empty($appPost)) {
             $file = \Rebond\Config::getPath('rebond') . 'App/' . $appPost . '/template/' . $filePost;
         }
         if (!isset($file) || Util\File::getExtension($file) != 'tpl') {
             Util\Session::adminError('fileNotFoundOrValid', [$file], '/designer/css');
         }
         if (!copy($file, Util\File::getNoExtension($file) . '-' . Util\Format::date(time(), 'string') . '.bak')) {
             Util\Session::adminError('itemNotCopied', [$file], '/designer/css');
         }
         file_put_contents($file, $tplFile);
         Util\Session::adminSuccess('saved', '/designer/tpl');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'designer']);
     $tplMain->set('file', $file);
     $tplMain->set('app', $app);
     $tplMain->set('filePath', $filePath);
     $tplMain->set('editable', Util\File::getExtension($file) == 'tpl');
     // layout
     $this->tplLayout->set('column1', $tplMain->render('tpl-form'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'designerTpl');
     $this->tplMaster->addCss('/css/codemirror.css');
     $this->tplMaster->addJs('/js/codemirror/codemirror.js');
     $this->tplMaster->addJs('/js/codemirror/htmlmixed.js');
     $this->tplMaster->addJs('/js/codemirror/xml.js');
     $this->tplMaster->addJs('/js/codemirror/clike.js');
     $this->tplMaster->addJs('/js/codemirror/php.js');
     return $this->tplMaster->render('tpl-default');
 }
예제 #11
0
 public static function validate($field, $value, $validation)
 {
     foreach ($validation as $key => $condition) {
         switch ($key) {
             // required
             case 'required':
                 $resultField = self::validateRequired($field, $value, $condition);
                 break;
                 // file
             // file
             case 'image':
                 $resultField = File::validateImage($field, $condition);
                 break;
             case 'document':
                 $resultField = File::validateDocument($field, $condition);
                 break;
                 // type
             // type
             case 'date':
             case 'datetime':
                 $resultField = self::validateDate($field, $value, $condition);
                 break;
             case 'password':
             case 'string':
             case 'richtext':
             case 'text':
                 $resultField = self::validateString($field, $value, $condition);
                 break;
             case 'integer':
             case 'static':
             case 'enum':
             case 'status':
             case 'version':
                 $resultField = self::validateInteger($field, $value, $condition);
                 break;
             case 'multipleKey':
             case 'foreignKey':
             case 'singleKey':
             case 'media':
                 $resultField = self::validateForeignKey($field, $value, $condition);
                 break;
             case 'decimal':
                 $resultField = self::validateNumeric($field, $value, $condition);
                 break;
                 // other
             // other
             case 'exactLength':
                 $resultField = self::validateExactLength($field, $value, $condition);
                 break;
             case 'maxLength':
                 $resultField = self::validateMaxLength($field, $value, $condition);
                 break;
             case 'minLength':
                 $resultField = self::validateMinLength($field, $value, $condition);
                 break;
             case 'letters':
                 $resultField = self::validateLetters($field, $value, $condition);
                 break;
             case 'alphanumeric':
                 $resultField = self::validateAlphaNumeric($field, $value, $condition);
                 break;
             case 'filename':
                 $resultField = self::validateFilename($field, $value, $condition);
                 break;
             case 'username':
             case 'name':
                 $resultField = self::validateName($field, $value, $condition);
                 break;
             case 'url':
                 $resultField = self::validateUrl($field, $value, $condition);
                 break;
             case 'email':
                 $resultField = self::validateEmail($field, $value, $condition);
                 break;
             case 'phone':
                 $resultField = self::validatePhone($field, $value, $condition);
                 break;
             case 'equal':
                 $resultField = self::validateEqual($field, $value, $condition);
                 break;
             case 'different':
                 $resultField = self::validateDifferent($field, $value, $condition);
                 break;
             case 'maxValue':
                 $resultField = self::validateMaxValue($field, $value, $condition);
                 break;
             case 'minValue':
                 $resultField = self::validateMinValue($field, $value, $condition);
                 break;
             default:
                 Log::log(Error::VALIDATION, $key, __FILE__, __LINE__);
                 $resultField = new Field($field);
         }
         if ($resultField->getResult() == ResultType::ERROR) {
             return $resultField;
         }
     }
     return new Field($field);
 }
예제 #12
0
 public function quickedit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.tools', true, '/');
     // check
     $module = Converter::string('module');
     $id = Converter::int('id');
     $id2 = Converter::int('id2');
     $save = Converter::string('save', 'post');
     if ($module == '') {
         header('Location: /tools/quickview');
         exit;
     }
     $busModel = '\\Rebond\\Bus\\' . $module . '\\Model';
     $busData = '\\Rebond\\Bus\\' . $module . '\\Data';
     $busForm = '\\Rebond\\Bus\\' . $module . '\\Form';
     if ($id == 0) {
         $entity = new $busModel();
     } else {
         if ($id2 != 0) {
             $entity = $busData::loadById($id, $id2);
         } else {
             $entity = $busData::loadById($id);
         }
         if (!isset($entity)) {
             $entity = new $busModel();
         }
     }
     $form = new $busForm($entity);
     // action
     if (isset($save)) {
         if ($form->setFromPost()->validate()->isValid()) {
             $entity->save();
             Session::adminSuccess('saved', '/tools/quickview/#!/' . $module);
         }
         Session::set('adminError', $form->getValidation()->getMessage());
     }
     // view
     $this->setTpl();
     // nav
     $entities = \Rebond\Util\File::getFolders('Rebond/Bus/');
     $tplNav = new Template(Template::SITE, ['admin', 'tools']);
     $tplNav->set('entities', $entities);
     $tplNav->set('active', $module);
     // main
     $tplMain = new Template(Template::MODULE, ['Bus', $module]);
     $tplMain->set('item', $form);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('bus-editor'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('navSide', $tplNav->render('nav'));
     $this->tplMaster->set('page', 'tools');
     $this->tplMaster->addJs('/js/tinymce/tinymce.min.js');
     $this->tplMaster->set('jsLauncher', 'toolsQuickEdit');
     return $this->tplMaster->render('tpl-default');
 }
예제 #13
0
 public function reinitialize()
 {
     // auth
     Util\Auth::isAdminAuthorized($this->signedUser, 'admin.dev', true, '/');
     // check
     $action = Util\Converter::string('action');
     if (isset($action)) {
         $result = [];
         $result['status'] = true;
         $result['message'] = '';
         $site = \Rebond\Core\Site\Data::loadById(1);
         $db = new \Rebond\Util\Data();
         switch ($action) {
             case 'file':
                 \Rebond\Core\Site\Service::resetFiles();
                 break;
             case 'restore':
                 $files = \Rebond\Util\File::getFiles('files/backup');
                 $fileFound = false;
                 foreach ($files as $file) {
                     if (stripos($file, 'launch') !== false) {
                         $fileFound = true;
                         $result = $db->restore($file);
                         break;
                     }
                 }
                 if (!$fileFound) {
                     $result['status'] = false;
                     $result['message'] = Util\Lang::lang('dbLaunchFileNotFound');
                 } else {
                     \Rebond\Core\Site\Service::resetFiles();
                 }
                 break;
             case 'full':
                 \Rebond\Core\Site\Service::resetFiles();
                 $result = $db->reset();
                 Util\Session::adminSuccess('resetSuccessful', '/');
                 break;
         }
         if ($result['status']) {
             Util\Session::set('adminSuccess', Util\Lang::lang('resetSuccessful'));
         } else {
             Util\Session::set('adminError', $result['message']);
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'dev']);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('reinitialize'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'dev');
     return $this->tplMaster->render('tpl-default');
 }
예제 #14
0
 private function generateJavascript(array $xmlLangs)
 {
     foreach (\Rebond\Config::getLang() as $lang => $locale) {
         $adminList = [];
         $siteList = [];
         $langTpl = new Template(Template::SITE, ['generator', 'lang']);
         $langTpl->set('lang', $lang);
         foreach ($xmlLangs as $xmlLang) {
             $valueList = $xmlLang->getElementsByTagName('language')->item(0);
             if (isset($valueList) && $valueList->hasChildNodes()) {
                 foreach ($valueList->childNodes as $node) {
                     if (in_array($node->nodeType, [XML_COMMENT_NODE, XML_TEXT_NODE])) {
                         continue;
                     }
                     if ($node->getAttribute('js') == 'both' || $node->getAttribute('js') == 'admin') {
                         $message = $node->getElementsByTagName($lang)->item(0)->nodeValue;
                         $adminList[] = str_repeat(' ', 4) . $node->nodeName . ' : "' . addslashes(ucfirst($message)) . '",' . chr(10);
                     }
                     if ($node->getAttribute('js') == 'both' || $node->getAttribute('js') == 'site') {
                         $message = $node->getElementsByTagName($lang)->item(0)->nodeValue;
                         $siteList[] = str_repeat(' ', 4) . $node->nodeName . ' : "' . addslashes(ucfirst($message)) . '",' . chr(10);
                     }
                 }
             }
         }
         $langTpl->set('list', implode('', $adminList));
         $adminLangPath = \Rebond\Config::getPath('admin') . 'js/lang-' . $lang . '.js';
         File::save($adminLangPath, 'w', $langTpl->render('js'));
         $langTpl->set('list', implode('', $siteList));
         $siteLangPath = \Rebond\Config::getPath('site') . 'js/lang-' . $lang . '.js';
         File::save($siteLangPath, 'w', $langTpl->render('js'));
     }
 }
예제 #15
0
 public function produceViews()
 {
     foreach ($this->views as $view) {
         $viewPath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/template/' . $view . '.tpl';
         if (file_exists($viewPath) && in_array($view, ['filter', 'form-success'])) {
             $this->info[] = '<div class="exist">' . $view . ' already exists.</div>';
             continue;
         }
         $propertyList = [];
         $propertyList2 = [];
         $multipleKey = [];
         $primaryKey = null;
         $viewTpl = new Template(Template::SITE, ['generator', 'views']);
         $viewTpl->set('package', $this->package);
         $viewTpl->set('entity', $this->entity);
         $viewTpl->set('isGenerated', false);
         $viewTpl->set('hasStatus', false);
         if (!in_array($view, ['filter'])) {
             foreach ($this->xmlProperties as $property) {
                 $type = $property->getAttribute('type');
                 $viewList = $property->getAttribute('view-list') == 'false' ? false : true;
                 $skip = $property->getAttribute('persistent') == 'false' ? true : false;
                 $skip = in_array($view, ['listing', 'bus-listing', 'admin-listing', 'admin-trail']) && (!$viewList || in_array($type, ['foreignKeyLink', 'singleKeyList'])) ? true : $skip;
                 if ($skip) {
                     continue;
                 }
                 $propertyName = Converter::toCamelCase($property->getAttribute('name'));
                 if ($type == 'primaryKey') {
                     $propertyName = $this->package == 'App' ? 'appId' : 'id';
                     $primaryKey = $propertyName;
                     $viewTpl->set('primaryKey', $primaryKey);
                 }
                 if ($type == 'multipleKey') {
                     $multipleKey[] = $propertyName . 'Id';
                 }
                 if ($type == 'status') {
                     $viewTpl->set('hasStatus', true);
                 }
                 $propertyList[] = $this->addViewList($this->package, $this->entity, $propertyName, $type, $propertyName == $this->main, $view);
                 if (in_array($view, ['listing', 'admin-listing', 'bus-listing', 'admin-trail'])) {
                     $propertyList2[] = $this->addViewList($this->package, $this->entity, $propertyName, $type, $propertyName == $this->main, $view . '-2');
                 }
             }
             $viewTpl->set('propertyList', implode('', $propertyList));
             if (in_array($view, ['listing', 'admin-listing', 'bus-listing', 'admin-trail'])) {
                 $viewTpl->set('propertyList2', implode('', $propertyList2));
             }
         }
         $realView = $view;
         if (in_array($view, ['bus-editor', 'editor'])) {
             if (!isset($primaryKey)) {
                 $realView .= '-nokey';
             }
         } else {
             if (in_array($view, ['bus-listing', 'listing'])) {
                 if (count($multipleKey) > 0) {
                     $viewTpl->set('multipleKey', $multipleKey);
                     $realView .= '-multikey';
                 } else {
                     if (!isset($primaryKey)) {
                         $realView .= '-nokey';
                     }
                 }
             }
         }
         if (file_exists($viewPath) && in_array($view, ['editor', 'view', 'listing', 'form', 'list', 'detail', 'single'])) {
             if (!$this->generate) {
                 continue;
             }
             $fileNoExt = \Rebond\Util\File::getNoExtension($viewPath);
             $viewPath = $fileNoExt . '-generated.tpl';
             $viewTpl->set('isGenerated', true);
             $this->info[] = '<div class="exist">' . $view . ' already exists. ' . $view . '-generated has been created.</div>';
         } else {
             $this->info[] = '<div>' . $view . ' created.</div>';
         }
         $render = str_replace('<#php', '<?php', $viewTpl->render($realView));
         \Rebond\Util\File::save($viewPath, 'w', $render);
     }
 }
예제 #16
0
 private static function validateFilename($serverPath, $path, $filename)
 {
     if ($filename == '' || !file_exists($serverPath . $path . $filename)) {
         return ['', 'default.png'];
     }
     $ext = File::getExtension($filename);
     switch ($ext) {
         case 'png':
         case 'gif':
         case 'jpg':
         case 'jpeg':
             return [$path, $filename];
             break;
         case 'doc':
         case 'docx':
             return ['', 'doc.png'];
             break;
         case 'pdf':
             return ['', 'pdf.png'];
             break;
         case 'txt':
         case 'xml':
             return ['', 'txt.png'];
             break;
         case 'mp3':
             return ['', 'music.png'];
             break;
         case 'mp4':
         case 'avi':
             return ['', 'video.png'];
             break;
         case 'xls':
         case 'xlsx':
             return ['', 'xls.png'];
             break;
     }
     return ['', 'default.png'];
 }
예제 #17
0
 private function produceGadget()
 {
     // Base class
     $gadgetTpl = new Template(Template::SITE, ['generator', 'gadget']);
     $gadgetTpl->set('entity', $this->entity);
     $gadgetTpl->set('hasContent', $this->hasContent);
     $viewList = [];
     $detail = false;
     foreach ($this->xmlViews as $xmlView) {
         $view = $xmlView->getAttribute('name');
         if ($view == '') {
             continue;
         }
         if ($view == 'list') {
             $view = 'full-list';
         }
         $viewList[] = $view;
         if (!$detail && in_array($view, ['full-list', 'filtered-list'])) {
             $detail = true;
             $viewList[] = 'detail';
         }
     }
     // add component
     $component = new \Rebond\Cms\Component\Model();
     $component->setModuleId($this->id);
     $component->setStatus(0);
     foreach ($viewList as $view) {
         $component->setId(0);
         switch ($view) {
             case 'full-list':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::LISTING];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(1);
                     $component->setTitle('full listing');
                     $component->setSummary('full listing');
                     $component->setMethod('fullList');
                     $component->save();
                 }
                 break;
             case 'filtered-list':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::FILTERED_LISTING];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(2);
                     $component->setTitle('filtered listing');
                     $component->setSummary('filtered listing');
                     $component->setMethod('filteredList');
                     $component->save();
                 }
                 break;
             case 'single':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::SINGLE_ITEM];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(0);
                     $component->setTitle('single item');
                     $component->setSummary('single item');
                     $component->setMethod('single');
                     $component->save();
                 }
                 break;
             case 'form':
                 $options = [];
                 $options['where'][] = ['component.type = ?', ComponentType::GENERIC];
                 $options['where'][] = ['component.module_id = ?', $this->id];
                 $options['where'][] = 'component.method = \'form\'';
                 if (\Rebond\Cms\Component\Data::count($options) == 0) {
                     $component->setType(4);
                     $component->setTitle('form');
                     $component->setSummary('form');
                     $component->setMethod('form');
                     $component->save();
                 }
                 break;
         }
     }
     $gadgetTpl->set('viewList', $viewList);
     $gadgetPath = \Rebond\Config::getPath('rebond') . 'App/' . $this->entity . '/Gadget.php';
     if (!file_exists($gadgetPath)) {
         $render = str_replace('<#php', '<?php', $gadgetTpl->render('gadget'));
         \Rebond\Util\File::save($gadgetPath, 'w', $render);
         $this->info[] = '<div>Gadget created.</div>';
     } else {
         $this->info[] = '<div class="exist">Gadget already exists.</div>';
     }
 }
예제 #18
0
 public function index()
 {
     // check
     $this->db = new \Rebond\Util\Data();
     $this->authFile = \Rebond\Config::getPath('config') . 'authentication.txt';
     $this->queryTables = 'SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = \'' . \Rebond\Config::getDb('name') . '\'';
     $this->queryCheckUser = '******';
     $this->info = [];
     $isAuth = Session::int('auth');
     $action = Converter::string('action');
     // action
     if ($isAuth == 0) {
         $this->step = 'auth';
         // check auth
         if (!file_exists($this->authFile)) {
             $auth = \Rebond\Util\Security::encrypt(time());
             File::save($this->authFile, 'w', $auth);
         } else {
             $auth = File::read($this->authFile, 'r');
         }
         if (isset($_POST['submitAuth'])) {
             if ($auth == $_POST['auth']) {
                 Session::set('auth', 1);
                 $isAuth = 1;
                 unlink($this->authFile);
                 $this->step = 'db';
                 $this->info[] = '<p class="bg-success">You have been authenticated!</p>';
             } else {
                 $this->info[] = '<p class="bg-error">The identification number you entered is incorrect. Please try again.</p>';
             }
         }
     }
     if ($isAuth == 1) {
         // check db
         $tableCount = $this->db->count($this->queryTables);
         $userTable = $this->db->selectOne($this->queryCheckUser);
         if ($tableCount != 0 && $tableCount !== self::TABLECOUNT) {
             $this->info[] = '<p class="bg-error">Your database contains ' . $tableCount . ' table(s). A fresh install of Rebond should contain ' . self::TABLECOUNT . ' tables. Please check your database name to make sure that you want to install Rebond in this database.</p>';
         }
         if (count($userTable) == 0) {
             $this->step = 'db';
             if ($action == 'db') {
                 $scripts = \Rebond\Util\File::getFiles('files/install');
                 sort($scripts);
                 foreach ($scripts as $script) {
                     $result = $this->db->runScript('files/install', $script);
                     if ($result['status'] == \Rebond\Core\ResultType::SUCCESS) {
                         $this->info[] = '<p>' . $script . '... success.</p>';
                     } else {
                         $this->info[] = '<p>' . $script . '... failed: <span class="error">' . $result['message'] . '</span></p>';
                         break;
                     }
                 }
                 $tableCount = $this->db->count($this->queryTables);
                 $userTable = $this->db->selectOne($this->queryCheckUser);
                 if (count($userTable) == 0) {
                     $this->info[] = '<p class="bg-error">The database has NOT been installed correctly. Please try to reinstall the database.</p>';
                 } else {
                     $this->info[] = '<p class="bg-success">The database has been installed successfully.</p>';
                     $this->step = 'db-ok';
                 }
             }
             // check user
         } else {
             if (\Rebond\Core\User\Data::count() == 0) {
                 $this->step = 'user';
                 $user = new \Rebond\Core\User\Model();
                 $userForm = new \Rebond\Core\User\Form($user);
                 if (isset($_POST['submitUser'])) {
                     if ($userForm->setFromPost()->validate()->isValid()) {
                         $user->setPassword(Security::encryptPassword($user->getPassword()));
                         $user->setIsAdmin(true);
                         $user->setIsDev(true);
                         $user->save();
                         $this->step = 'ready';
                     } else {
                         Session::set('adminError', $userForm->getValidation()->getMessage());
                     }
                 }
                 // ready
             } else {
                 $this->step = 'ready';
                 if ($action == 'launch') {
                     $adminPath = \Rebond\Config::getPath('admin');
                     $sitePath = \Rebond\Config::getPath('site');
                     rename($adminPath . 'index.php', $adminPath . 'index_install.php');
                     rename($adminPath . 'index_admin.php', $adminPath . 'index.php');
                     rename($sitePath . 'index.php', $sitePath . 'index_install.php');
                     rename($sitePath . 'index_cms.php', $sitePath . 'index.php');
                     $db = new \Rebond\Util\Data();
                     $db->backup('launch');
                     Session::kill('auth');
                     Session::setAndRedirect('signedUser', 1, '/configuration/site');
                 }
             }
         }
     }
     // menu
     $tplMenu = new Template(Template::SITE, ['admin', 'install']);
     $tplMenu->set('menuAuth', $this->step == 'auth' ? ' class="active"' : '');
     $tplMenu->set('menuDb', in_array($this->step, ['db', 'db-ok']) ? ' class="active"' : '');
     $tplMenu->set('menuUser', $this->step == 'user' ? ' class="active"' : '');
     $tplMenu->set('menuReady', $this->step == 'ready' ? ' class="active"' : '');
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'install']);
     // layout
     $this->tplLayout->set('column1', $tplMenu->render('menu'));
     $this->tplLayout->add('column1', implode($this->info));
     if ($this->step == 'user') {
         if (!isset($user)) {
             $userForm = new \Rebond\Core\User\Form();
             $userForm->setFromPost();
         }
         $tplMain->set('form', $userForm);
     }
     $this->tplLayout->add('column1', $tplMain->render($this->step));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'install');
     $this->tplMaster->addCss('/css/normalize.css');
     $this->tplMaster->addCss('/css/rebond.css');
     $this->tplMaster->addCss('/css/custom.css');
     $this->tplMaster->addJs('//code.jquery.com/jquery-2.1.3.min.js');
     $this->tplMaster->addJs('/js/rebond.js');
     $this->tplMaster->addJs('/js/custom.js');
     return $this->tplMaster->render('tpl-install');
 }
예제 #19
0
 public function generated_photos()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.media.image', true, '/media');
     $photos = \Rebond\Util\File::getFiles('www/media');
     $generated = [];
     $pattern = '/-(.*).(.*)/';
     $count = count($photos);
     for ($i = 0; $i < $count; $i++) {
         if (preg_match($pattern, $photos[$i])) {
             $generated[] = $photos[$i];
             unset($photos[$i]);
         }
     }
     $cleanup = Converter::bool('cleanup');
     if ($cleanup) {
         foreach ($generated as $photo) {
             \Rebond\Util\File::deleteAllMedia('', $photo);
         }
         Session::adminSuccess('generatedPhotosDeleted', '/media/generated-photos');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'media']);
     $tplMain->set('photos', $photos);
     $tplMain->set('generated', $generated);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('generated-photos'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-default');
 }
예제 #20
0
 private static function compact(array $files, $filepath)
 {
     $buffer = '';
     foreach ($files as $file) {
         $buffer .= file_get_contents($file);
     }
     // Remove comments and spaces
     $expr = '/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:|\\\\)\\/\\/.*))/';
     $buffer = preg_replace($expr, '', $buffer);
     $buffer = str_replace(["\r\n", "\r", "\n", "\t", '  '], '', $buffer);
     $buffer = str_replace([': ', ' :', ' : '], ':', $buffer);
     $buffer = str_replace(['= ', ' =', ' = '], '=', $buffer);
     $buffer = str_replace(['+ ', ' +', ' + '], '+', $buffer);
     $buffer = str_replace(['+= ', ' +=', ' += '], '+', $buffer);
     $buffer = str_replace(['} ', ' }', ' } '], '}', $buffer);
     $buffer = str_replace(['{ ', ' {', ' { '], '{', $buffer);
     $buffer = str_replace([', ', ' ,', ' , '], ',', $buffer);
     \Rebond\Util\File::save($filepath, 'w', $buffer);
 }
예제 #21
0
 public function produceScript()
 {
     $scriptTpl = new Template(Template::SITE, ['generator', 'mysql']);
     $scriptTpl->set('table', $this->table);
     $fieldList = [];
     $multipleKey = [];
     foreach ($this->xmlProperties as $property) {
         if ($this->ignoreColumn($property)) {
             continue;
         }
         $type = $property->getAttribute('type');
         $propertyName = $property->getAttribute('name');
         $sqlType = $this->getDefaultMysqlType($property->getAttribute('mysql'), $type);
         $maxLength = $this->maxLength;
         $validations = $property->getElementsByTagName('validation');
         foreach ($validations as $validation) {
             if ($validation->getAttribute('condition') == 'maxLength') {
                 $maxLength = $validation->getAttribute('value');
                 break;
             }
         }
         if ($type == 'primaryKey') {
             $propertyName = $this->package == 'App' ? 'app_id' : 'id';
             $primaryKey = $propertyName;
             $scriptTpl->set('primaryKey', $primaryKey);
         }
         if ($type == 'multipleKey') {
             $multipleKey[] = $propertyName . '_id';
         }
         $fieldList[] = $this->fieldList('field', $propertyName, $type, $sqlType, $maxLength);
     }
     $scriptTpl->set('multipleKey', implode(', ', $multipleKey));
     $scriptTpl->set('fieldList', implode(',', $fieldList));
     $scriptPath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/mysql.sql';
     \Rebond\Util\File::save($scriptPath, 'w', $scriptTpl->render('table'));
     $this->info[] = '<div>SQL scripts created.</div>';
     $existQuery = 'SHOW TABLES LIKE \'?\'';
     $exist = count($this->db->selectOne($existQuery, [$this->table]));
     if ($exist == 0) {
         $this->db->runScript('Rebond/' . $this->package . '/' . $this->entity . '/', 'mysql.sql');
         $this->info[] = '<div>SQL table created.</div>';
     } else {
         if ($exist > 0 && $this->db->count('SELECT COUNT(*) FROM ' . $this->table) == 0) {
             $this->db->execute('DROP TABLE ' . $this->table);
             $this->db->runScript('Rebond/' . $this->package . '/' . $this->entity . '/', 'mysql.sql');
             $this->info[] = '<div>SQL table recreated.</div>';
         } else {
             $sqlCols = $this->db->select('SHOW COLUMNS FROM ' . $this->table)->fetchAll();
             $updated = self::updateColumns($sqlCols);
             if ($updated) {
                 $sqlCols = $this->db->select('SHOW COLUMNS FROM ' . $this->table)->fetchAll();
             }
             self::removeColumns($sqlCols);
             self::addColumns($sqlCols);
             $this->info[] = '<div>SQL table updated.</div>';
         }
     }
 }
예제 #22
0
 public function uploadify()
 {
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $id = Converter::int('userId', 'post', 0);
     $this->signedUser = \Rebond\Core\User\Data::loadById($id);
     if (!isset($this->signedUser)) {
         $json['message'] = Lang::lang('accessNonAuthorized');
         return json_encode($json);
     }
     if (!$this->hasPrivilege('admin.media.upload')) {
         return $this->noPrivilege('admin.media.upload');
     }
     $folderId = Converter::int('folderId', 'post');
     $isSelectable = Converter::int('isSelectable', 'post', 1);
     if (!isset($folderId)) {
         $json['message'] = Lang::lang('errorInvalidParameters');
         return json_encode($json);
     }
     $upload = \Rebond\Util\Media::upload('', $_FILES['Filedata']);
     $originalName = $_FILES['Filedata']['name'];
     if ($upload == ResultType::ERROR) {
         $json['message'] = Lang::lang('errorFileUpload', [$originalName]);
         Log::log(Error::MEDIA_NOT_SAVED, $json['message'], __FILE__, __LINE__);
         return json_encode($json);
     }
     list($w, $h) = getimagesize(\Rebond\Config::getPath('media') . $upload);
     $ext = \Rebond\Util\File::getExtension(\Rebond\Config::getPath('media') . $upload);
     $noExt = \Rebond\Util\File::getNoExtension($originalName);
     $media = new \Rebond\Core\Media\Model();
     $media->setFolderId($folderId);
     $media->setTitle($noExt);
     $media->setAlt($noExt);
     $media->setOriginalFilename($originalName);
     $media->setExtension($ext);
     $media->setWidth($w);
     $media->setHeight($h);
     $media->setFilesize(filesize(\Rebond\Config::getPath('media') . $upload));
     $mimeType = new \finfo(FILEINFO_MIME_TYPE);
     $media->setMimetype($mimeType->file(\Rebond\Config::getPath('media') . $upload));
     $media->setUpload($upload);
     $media->setIsSelectable($isSelectable);
     $media->save();
     $json['result'] = ResultType::SUCCESS;
     $json['id'] = $media->getId();
     $json['message'] = Lang::lang('mediaUploaded', [$originalName]);
     return json_encode($json);
 }