Beispiel #1
0
 public function __construct($db)
 {
     $this->orm = $db;
     $this->db = $db->db();
     $this->table = $db->table();
     $dir = Config::get('dir.blizz.store', session_save_path());
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db));
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table));
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $file = $this->dir . DS . 'data.db';
     $new = false;
     if (!is_file($file)) {
         File::create($file);
         $new = true;
         File::put($this->dir . DS . 'age.blizz', '');
     }
     $link = new SQLite3($file);
     Now::set("blizz.link.{$this->db}.{$this->table}", $link);
     if ($new) {
         $this->init();
     }
 }
Beispiel #2
0
 public function model($data = [])
 {
     $view = false;
     $db = $this->db;
     $table = $this->table;
     $modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db) . DS . ucfirst(Inflector::lower($table)) . '.php';
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql')) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql');
     }
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models')) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models');
     }
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db))) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db));
     }
     if (!File::exists($modelFile)) {
         File::put($modelFile, str_replace('##class##', ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'SQLModel', File::read(__DIR__ . DS . 'dbModel.tpl')));
     }
     $class = '\\Thin\\' . ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'SQLModel';
     if (!class_exists($class)) {
         require_once $modelFile;
     }
     $model = $this;
     if (true === $view) {
         $model = self::instance($db, $table);
     }
     return new $class($model, $data);
 }
Beispiel #3
0
 public function write($name, $data = [])
 {
     $file = $this->getFile($name);
     File::delete($file);
     $data = is_array($data) ? var_export($data, 1) : var_export([$data], 1);
     File::put($file, "<?php\nreturn " . $data . ';');
     // touch($file, time() - 10);
     return $this;
 }
Beispiel #4
0
 public function write($name, $data = [])
 {
     $file = $this->getFile($name);
     if (File::exists($file)) {
         File::delete($file);
     }
     $data = is_array($data) ? var_export($data, 1) : var_export([$data], 1);
     $res = File::put($file, "<?php\nreturn " . $data . ';');
     return $this;
 }
Beispiel #5
0
 public function model($data = [])
 {
     $db = $this->db;
     $table = $this->table;
     $modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Fast' . DS . 'models' . DS . Inflector::lower($db) . DS . ucfirst(Inflector::lower($table)) . '.php';
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Fast' . DS . 'models' . DS . Inflector::lower($db))) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Fast' . DS . 'models' . DS . Inflector::lower($db));
     }
     if (!File::exists($modelFile)) {
         File::put($modelFile, str_replace('##class##', ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'ModelFast', File::read(__DIR__ . DS . 'dbModel.tpl')));
     }
     $class = '\\Thin\\' . ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'ModelFast';
     if (!class_exists($class)) {
         require_once $modelFile;
     }
     $model = $this;
     return new $class($model, $data);
 }
Beispiel #6
0
 private function nextId()
 {
     $id = File::read($this->ids);
     File::delete($this->ids);
     File::put($this->ids, $id + 1);
     return (int) $id;
 }
Beispiel #7
0
 private function makeId()
 {
     $file = $this->dir . DS . 'lastid.blazz';
     if (is_file($file)) {
         $last = File::read($file);
         $new = $last + 1;
         File::delete($file);
         File::put($file, $new);
         return $new;
     }
     File::put($file, 1);
     return 1;
 }
Beispiel #8
0
 private function cached($key, $value = null)
 {
     if (false === $this->cache) {
         return null;
     }
     $settings = isAke(self::$configs, $this->entity);
     $event = isAke($settings, 'cache');
     if (!empty($event)) {
         return $this->{$event}($key, $value);
     }
     $file = STORAGE_PATH . DS . 'cache' . DS . $key . '.eav';
     if (empty($value)) {
         if (File::exists($file)) {
             $age = filemtime($file);
             $maxAge = time() - $this->ttl;
             if ($maxAge < $age) {
                 return json_decode(File::get($file), true);
             } else {
                 File::delete($file);
                 return null;
             }
         }
     } else {
         if (File::exists($file)) {
             File::delete($file);
         }
         File::put($file, json_encode($value));
         return true;
     }
 }
Beispiel #9
0
 private function csv($data)
 {
     $csv = implode("\n", $data);
     $name = date('d_m_Y_H_i_s') . '_' . $this->table . '_export.csv';
     $file = TMP_PUBLIC_PATH . DS . $name;
     File::delete($file);
     File::put($file, $csv);
     Utils::go(str_replace(['jma_dev.php', 'jma_prod.php'], '', URLSITE) . 'tmp/' . $name);
 }
Beispiel #10
0
 public function distantAsset($src)
 {
     $ext = strtolower(Arrays::last(explode('.', $src)));
     $file = Config::get('app.module.assets') . DS . 'cache' . DS . sha1($src) . '.' . $ext;
     $render = '/assets/cache/' . sha1($src) . '.' . $ext;
     if (!file_exists($file)) {
         $ctn = file_get_contents($src);
         File::put($file, $ctn);
     }
     return $render;
 }
Beispiel #11
0
 public function editpageAction()
 {
     $id = request()->getId();
     if (!is_null($id)) {
         $permission = 'cms';
         $auth = auth()->can($permission);
         if (true === $auth || true === $this->isAdmin) {
             $dirPages = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'content' . DS . SITE_NAME . DS . 'pages');
             $dirPartials = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'content' . DS . SITE_NAME . DS . 'partials');
             if (!strlen($dirPages) || !strlen($dirPartials)) {
                 $this->forward('home');
             }
             $pages = File::readdir($dirPages);
             $partials = File::readdir($dirPartials);
             $pages = array_merge($pages, $partials);
             $key = $id - 1;
             $file = isset($pages[$key]) ? $pages[$key] : false;
             if (false !== $file) {
                 if ($this->isPost()) {
                     $html = request()->getHtml();
                     $config = request()->getConfig();
                     $content = "/*\n    {$config}\n*/\n{$html}";
                     File::delete($file);
                     File::put($file, $content);
                     $this->forward('pagelist');
                 } else {
                     $content = fgc($file);
                     $this->view->configPage = repl(array('/*', '*/'), '', $this->getConfigPage($content));
                     $this->view->htmlPage = $this->getHtml($content);
                     $this->view->title = 'Mettre à jour une page';
                 }
             } else {
                 $this->forward('pagelist');
             }
         } else {
             $this->forward('pagelist');
         }
     } else {
         $this->forward('pagelist');
     }
 }
Beispiel #12
0
 public static function generate($model, $overwrite = false)
 {
     $file = APPLICATION_PATH . DS . 'models' . DS . 'Crud' . DS . ucfirst(Inflector::camelize($model)) . '.php';
     if (!File::exists($file) || $overwrite) {
         $db = model($model);
         $crud = new Crud($db);
         File::delete($file);
         $tplModel = fgc(__DIR__ . DS . 'Model.tpl');
         $tplField = fgc(__DIR__ . DS . 'Field.tpl');
         $fields = $crud->fields();
         $singular = ucfirst($model);
         $plural = $singular . 's';
         $default_order = $crud->pk();
         $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel);
         $fieldsSection = '';
         foreach ($fields as $field) {
             if ($field != $crud->pk()) {
                 $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
                 $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
Beispiel #13
0
 private function prepare()
 {
     $results = $collection = [];
     $hash = $this->db->getHash();
     $this->cursor = $this->db->motor()->getPath() . DS . 'cursors' . DS . $hash;
     if (is_dir($this->cursor)) {
         $ageCursor = filemtime($this->cursor . DS . '.');
         $ageDb = $this->db->getAge();
         if ($ageDb < $ageCursor) {
             $this->count = count(glob($this->cursor . DS . '*.php', GLOB_NOSORT));
             return;
         } else {
             File::rmdir($this->cursor);
         }
     }
     File::mkdir($this->db->motor()->getPath() . DS . 'cursors');
     File::mkdir($this->db->motor()->getPath() . DS . 'cursors' . DS . $hash);
     if (empty($this->db->wheres)) {
         $ids = $this->db->motor()->ids('datas');
         foreach ($ids as $id) {
             $results[$id] = [];
         }
         unset($ids);
     } else {
         $results = $this->db->results;
     }
     $this->count = count($results);
     if (empty($results)) {
         File::rmdir($this->cursor);
         return true;
     } else {
         $index = 0;
         foreach ($results as $id => $row) {
             if (false !== $id) {
                 $file = $this->cursor . DS . $index . '.php';
                 $data = $this->db->motor()->read('datas.' . $id);
                 File::put($file, "<?php\nreturn " . var_export($data, 1) . ';');
                 $index++;
             }
         }
     }
 }
Beispiel #14
0
 private static function _buffer($key, $data = null)
 {
     if (false === static::$_buffer) {
         return false;
     }
     $timeToBuffer = false !== static::$_cache ? static::$_cache * 60 : 2;
     $ext = false !== static::$_cache ? 'cache' : 'buffer';
     $file = CACHE_PATH . DS . $key . '_nosql.' . $ext;
     if (File::exists($file)) {
         $age = time() - File::modified($file);
         if ($age > $timeToBuffer) {
             File::delete($file);
         } else {
             return static::unserialize(static::load($file));
         }
     }
     if (null === $data) {
         return false;
     }
     File::put($file, static::serialize($data));
 }
Beispiel #15
0
 protected function compiled($compile = false)
 {
     $viewRedis = container()->getViewRedis();
     if (true !== $viewRedis) {
         $file = CACHE_PATH . DS . md5($this->_viewFile) . '.compiled';
         if (false !== $compile) {
             if (File::exists($file)) {
                 File::delete($file);
             }
             File::put($file, $this->makeCompile($compile));
         }
         return $file;
     } else {
         $redis = redis();
         $keyAge = sha1($this->_viewFile) . '::age';
         $keyTpl = sha1($this->_viewFile) . '::html';
         if (false !== $compile) {
             $redis->set($keyAge, time());
             $content = $this->makeCompile($compile);
             $redis->set($keyTpl, $content);
             return $content;
         } else {
             return $redis->get($keyTpl);
         }
     }
 }
Beispiel #16
0
 public function delete($k)
 {
     $tab = $this->unserialize(File::read($this->file));
     unset($tab[$k]);
     File::delete($this->file);
     File::put($this->file, $this->serialize($tab));
     return $this;
 }
Beispiel #17
0
 public function expire($key, $ttl = 0)
 {
     $key = $this->key($key);
     $ttl = 0 < $ttl ? $ttl + time() : $ttl;
     $file = $this->getFile($key);
     if (File::exists($file)) {
         $file = $this->getFile('expires.' . $ttl . '.' . $key);
         File::delete($file);
         File::put($file, '');
         return true;
     }
     return false;
 }
Beispiel #18
0
 private function makeId()
 {
     $file = $this->getFile('coreids');
     if (File::exists($file)) {
         $last = (int) File::read($file);
         $new = $last + 1;
     } else {
         $new = 1;
     }
     File::delete($file);
     File::put($file, (int) $new);
     return $new;
 }
Beispiel #19
0
 function tpl($tpl)
 {
     $view = container()->getView();
     $view = !is_object($view) ? context()->getView() : $view;
     $tab = explode(DS, $view->_viewFile);
     $path = repl(DS . Arrays::last($tab), '', $view->_viewFile);
     $path = repl($tab[count($tab) - 2], 'partials' . DS . $tpl, $path);
     if (File::exists($path)) {
         $content = fgc($path);
         $content = repl('$this->', '$view->', View::cleanCode($content));
         $file = CACHE_PATH . DS . sha1($content) . '.display';
         File::put($file, $content);
         ob_start();
         include $file;
         $html = ob_get_contents();
         ob_end_clean();
         File::delete($file);
         echo $html;
     }
 }
Beispiel #20
0
    private function export($type, $rows)
    {
        $fieldInfos = isAke($this->config, 'fields');
        $fields = $this->fields();
        if ('excel' == $type) {
            $excel = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
        xmlns:x="urn:schemas-microsoft-com:office:excel"
        xmlns="http://www.w3.org/TR/REC-html40">

            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                <meta name="ProgId" content="Excel.Sheet">
                <meta name="Generator" content="Microsoft Excel 11">
                <style id="Classeur1_17373_Styles">
                <!--table
                    {mso-displayed-decimal-separator:"\\,";
                    mso-displayed-thousand-separator:" ";}
                .xl1517373
                    {padding-top:1px;
                    padding-right:1px;
                    padding-left:1px;
                    mso-ignore:padding;
                    color:windowtext;
                    font-size:10.0pt;
                    font-weight:400;
                    font-style:normal;
                    text-decoration:none;
                    font-family:Arial;
                    mso-generic-font-family:auto;
                    mso-font-charset:0;
                    mso-number-format:General;
                    text-align:general;
                    vertical-align:bottom;
                    mso-background-source:auto;
                    mso-pattern:auto;
                    white-space:nowrap;}
                .xl2217373
                    {padding-top:1px;
                    padding-right:1px;
                    padding-left:1px;
                    mso-ignore:padding;
                    color:#FFFF99;
                    font-size:10.0pt;
                    font-weight:700;
                    font-style:normal;
                    text-decoration:none;
                    font-family:Arial, sans-serif;
                    mso-font-charset:0;
                    mso-number-format:General;
                    text-align:center;
                    vertical-align:bottom;
                    background:#003366;
                    mso-pattern:auto none;
                    white-space:nowrap;}
                -->
                </style>
            </head>

                <body>
                <!--[if !excel]>&nbsp;&nbsp;<![endif]-->

                <div id="Classeur1_17373" align="center" x:publishsource="Excel">

                <table x:str border="0" cellpadding="0" cellspacing="0" width=640 style="border-collapse:
                 collapse; table-layout: fixed; width: 480pt">
                 <col width="80" span=8 style="width: 60pt">
                 <tr height="17" style="height:12.75pt">
                  ##headers##
                 </tr>
                 ##content##
                </table>
                </div>
            </body>
        </html>';
            $tplHeader = '<td class="xl2217373">##value##</td>';
            $tplData = '<td>##value##</td>';
            $headers = [];
            foreach ($fields as $field) {
                $fieldSettings = isAke($fieldInfos, $field);
                $exportable = isAke($fieldSettings, 'is_exportable', true);
                $label = isAke($fieldSettings, 'label', ucfirst($field));
                if (true === $exportable) {
                    $headers[] = \Thin\Html\Helper::display($label);
                }
            }
            $xlsHeader = '';
            foreach ($headers as $header) {
                $xlsHeader .= str_replace('##value##', $header, $tplHeader);
            }
            $excel = str_replace('##headers##', $xlsHeader, $excel);
            $xlsContent = '';
            foreach ($rows as $item) {
                $xlsContent .= '<tr>';
                foreach ($fields as $field) {
                    $fieldSettings = isAke($fieldInfos, $field);
                    $exportable = isAke($fieldSettings, 'is_exportable', true);
                    if (true === $exportable) {
                        $value = isAke($item, $field, '&nbsp;');
                        if (Arrays::exists('content_list', $fieldSettings)) {
                            $closure = $fieldSettings['content_list'];
                            if (is_callable($closure)) {
                                $value = call_user_func_array($closure, array($item));
                            }
                        }
                        if (empty($value)) {
                            $value = '&nbsp;';
                        }
                        $xlsContent .= str_replace('##value##', \Thin\Html\Helper::display($value), $tplData);
                    }
                }
                $xlsContent .= '</tr>';
            }
            $excel = str_replace('##content##', $xlsContent, $excel);
            $name = 'extraction_' . $this->model->db . '_' . $this->model->table . '_' . date('d_m_Y_H_i_s') . '.xlsx';
            $file = TMP_PUBLIC_PATH . DS . $name;
            File::delete($file);
            File::put($file, $excel);
            Utils::go(URLSITE . '/tmp/' . $name);
        } elseif ('pdf' == $type) {
            $pdf = '<html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <link href="//fonts.googleapis.com/css?family=Abel" rel="stylesheet" type="text/css" />
                <title>Extraction ' . $this->model->db . ' - ' . $this->model->table . '</title>
                <style>
                    *
                    {
                        font-family: Abel, ubuntu, verdana, tahoma, arial, sans serif;
                        font-size: 11px;
                    }
                    h1
                    {
                        text-transform: uppercase;
                        font-size: 135%;
                    }
                    th
                    {
                        font-size: 120%;
                        color: #fff;
                        background-color: #394755;
                        text-transform: uppercase;
                    }
                    td
                    {
                        border: solid 1px #394755;
                    }

                    a, a:visited, a:hover
                    {
                        color: #000;
                        text-decoration: underline;
                    }
                </style>
            </head>
            <body>
                <center><h1>Extraction &laquo ' . $this->model->db . ' - ' . $this->model->table . ' &raquo;</h1></center>
                <p></p>
                <table width="100%" cellpadding="5" cellspacing="0" border="0">
                <tr>
                    ##headers##
                </tr>
                ##content##
                </table>
                <p>&copy; GP 1996 - ' . date('Y') . ' </p>
            </body>
            </html>';
            $tplHeader = '<th>##value##</th>';
            $tplData = '<td>##value##</td>';
            $headers = [];
            foreach ($fields as $field) {
                $fieldSettings = isAke($fieldInfos, $field, []);
                $exportable = isAke($fieldSettings, 'is_exportable', true);
                if (true === $exportable) {
                    $label = isAke($fieldSettings, 'label', ucfirst($field));
                    $headers[] = \Thin\Html\Helper::display($label);
                }
            }
            $pdfHeader = '';
            foreach ($headers as $header) {
                $pdfHeader .= str_replace('##value##', $header, $tplHeader);
            }
            $pdf = str_replace('##headers##', $pdfHeader, $pdf);
            $pdfContent = '';
            foreach ($rows as $item) {
                $pdfContent .= '<tr>';
                foreach ($fields as $field) {
                    $fieldSettings = isAke($fieldInfos, $field, []);
                    $exportable = isAke($fieldSettings, 'is_exportable', true);
                    if (true === $exportable) {
                        $value = isAke($item, $field, '&nbsp;');
                        if (Arrays::exists('content_list', $fieldSettings)) {
                            $closure = $fieldSettings['content_list'];
                            if (is_callable($closure)) {
                                $value = call_user_func_array($closure, array($item));
                            }
                        }
                        if (empty($value)) {
                            $value = '&nbsp;';
                        }
                        $pdfContent .= str_replace('##value##', \Thin\Html\Helper::display($value), $tplData);
                    }
                }
                $pdfContent .= '</tr>';
            }
            $pdf = str_replace('##content##', $pdfContent, $pdf);
            return \Thin\Pdf::make($pdf, "extraction_" . $this->model->db . "_" . $this->model->table . "_" . date('d_m_Y_H_i_s'), false);
        }
    }
Beispiel #21
0
 public static function dispatch()
 {
     header("Access-Control-Allow-Origin: *");
     static::$method = Request::method();
     $uri = substr(str_replace('/mobi/', '/', $_SERVER['REQUEST_URI']), 1);
     $tab = explode('/', $uri);
     if (!strlen($uri) || $uri == '/') {
         $namespace = 'static';
         $controller = 'home';
         $action = 'index';
     } else {
         if (count($tab) < 3) {
             self::isForbidden();
         }
         $namespace = current($tab);
         $controller = $tab[1];
         $action = $tab[2];
         $tab = array_slice($tab, 3);
         $count = count($tab);
         if (0 < $count && $count % 2 == 0) {
             for ($i = 0; $i < $count; $i += 2) {
                 $_REQUEST[$tab[$i]] = $tab[$i + 1];
             }
         }
     }
     $file = APPLICATION_PATH . DS . 'mobi' . DS . $namespace . DS . 'controllers' . DS . $controller . '.php';
     // dd($file);
     if (!File::exists($file)) {
         self::is404();
     }
     require_once $file;
     $class = 'Thin\\' . ucfirst($controller) . 'Mobi';
     $i = new $class();
     $methods = get_class_methods($i);
     $call = strtolower(static::$method) . ucfirst($action);
     if (!Arrays::in($call, $methods)) {
         self::is404();
     }
     if (Arrays::in('init', $methods)) {
         $i->init($call);
     }
     $i->{$call}();
     if ($i->view === true) {
         $tpl = APPLICATION_PATH . DS . 'mobi' . DS . $namespace . DS . 'views' . DS . $controller . DS . $action . '.phtml';
         if (File::exists($tpl)) {
             $content = File::read($tpl);
             $content = str_replace('$this->', '$i->', $content);
             $fileTpl = CACHE_PATH . DS . sha1($content) . '.display';
             File::put($fileTpl, $content);
             ob_start();
             include $fileTpl;
             $html = ob_get_contents();
             ob_end_clean();
             File::delete($fileTpl);
             self::render($html);
         } else {
             self::render('OK');
         }
     }
     if (Arrays::in('after', $methods)) {
         $i->after();
     }
 }
Beispiel #22
0
 public static function generate($database, $model, $fields = [], $overwrite = false)
 {
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw')) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw');
     }
     $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)) . DS . ucfirst(Inflector::camelize($model)) . '.php';
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)))) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudRaw' . DS . ucfirst(Inflector::camelize($database)));
     }
     if (!File::exists($file) || $overwrite) {
         $db = Db::instance($database, $model);
         $crud = Crud::instance($db);
         File::delete($file);
         $tplModel = File::read(__DIR__ . DS . 'Model.tpl');
         $tplField = File::read(__DIR__ . DS . 'Field.tpl');
         $fields = empty($fields) ? $crud->fields() : $fields;
         $singular = ucfirst($model);
         $plural = $singular . 's';
         $default_order = $crud->pk();
         $tplModel = str_replace(['##singular##', '##plural##', '##default_order##', '##foreigns##', '##uniques##', '##soft_delete##', '##before_create##', '##after_create##', '##before_update##', '##after_update##', '##before_read##', '##after_read##', '##before_delete##', '##after_delete##', '##before_list##', '##after_list##'], [$singular, $plural, $default_order, '[]', '[]', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false'], $tplModel);
         $fieldsSection = '';
         foreach ($fields as $field) {
             if ($field != $crud->pk()) {
                 $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
                 $fieldsSection .= str_replace(['##field##', '##form_type##', '##helper##', '##required##', '##form_plus##', '##length##', '##is_listable##', '##is_exportable##', '##is_searchable##', '##is_sortable##', '##is_readable##', '##is_creatable##', '##is_updatable##', '##is_deletable##', '##content_view##', '##content_list##', '##content_search##', '##content_create##', '##label##'], [$field, 'text', 'false', 'true', 'false', 'false', 'true', 'true', 'true', 'true', 'true', 'true', 'true', 'true', 'false', 'false', 'false', 'false', $label], $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
Beispiel #23
0
 public function hset($hash, $key, $value)
 {
     $file = $this->getHashFile($hash, $key);
     if (File::exists($file)) {
         File::delete($file);
     }
     File::put($file, serialize($value));
     return $this;
 }
Beispiel #24
0
 public function makeBackup($database = null)
 {
     set_time_limit(0);
     $database = is_null($database) ? SITE_NAME : $database;
     $db = $this->getOdm();
     $collections = $db->getCollectionNames();
     $key = array_search('zelift.ages', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.counters', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.tuples', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.caching', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $key = array_search('zelift.ages', $collections);
     if (strlen($key)) {
         unset($collections[$key]);
     }
     $i = 0;
     foreach ($collections as $coll) {
         $path = \Thin\Config::get('application.backup_dir');
         if (!is_dir($path)) {
             return false;
         }
         list($collDb, $collTable) = explode('.', $coll, 2);
         if ($collDb != $database) {
             continue;
         }
         $path = $path . DS . $collDb;
         if (!is_dir($path)) {
             File::mkdir($path);
         }
         $path = $path . DS . $collTable;
         if (!is_dir($path)) {
             File::mkdir($path);
         }
         $model = self::instance($collDb, $collTable);
         $cursor = $model->cursor();
         while ($row = $cursor->fetch()) {
             if (isset($row['id'])) {
                 $file = $path . DS . $row['id'] . '.json';
                 File::put($file, json_encode($row));
                 $i++;
             }
         }
     }
     $now = date("d_m_Y_H_i_s");
     $path = \Thin\Config::get('application.backup_dir', false);
     $user = \Thin\Config::get('redis.ftp.backup.user', false);
     $password = \Thin\Config::get('redis.ftp.backup.password', false);
     $host = \Thin\Config::get('redis.ftp.backup.host', false);
     if (false !== $path && false !== $user && false !== $password && false !== $host) {
         $cmd = "cd {$path} && tar cfvz zelift_{$now}.tar.gz {$path}\nlftp -e 'put {$path}/zelift_{$now}.tar.gz; bye' -u \"{$user}\",{$password} {$host}\nrm zelift_{$now}.tar.gz\necho 'done'";
         passthru($cmd);
     }
     vd($i);
     dd(Timer::get());
 }
Beispiel #25
0
 public function putInCache($key, $data)
 {
     $file = $this->cacheDir . DS . $key;
     File::delete($file);
     File::put($file, serialize($data));
 }
Beispiel #26
0
 public function check($id, $html)
 {
     require_once __DIR__ . DS . 'dom.php';
     $str = str_get_html($html);
     $segLangs = $str->find('lang');
     foreach ($segLangs as $segLang) {
         $default = $segLang->innertext;
         $args = $segLang->args;
         if (!empty($args)) {
             $controller = Now::get('instance.controller');
             $replace = "<lang args=\"{$args}\">{$default}</lang>";
             $file = path('cache') . DS . sha1(serialize($args)) . '.display';
             File::put($file, '<?php namespace Thin; ?>' . $args);
             ob_start();
             include $file;
             $args = ob_get_contents();
             ob_end_clean();
             File::delete($file);
         } else {
             $args = '[]';
             $replace = "<lang>{$default}</lang>";
         }
         $by = '<?php __(\'' . $default . '\', \'' . $id . '.' . Inflector::urlize($default, '-') . '\', ' . $args . '); ?>';
         $html = str_replace($replace, $by, $html);
     }
     return $html;
 }
Beispiel #27
0
 /**
  * Write the contents of a file.
  *
  * @param  string  $path
  * @param  string  $contents
  * @return int
  */
 public function put($path, $contents)
 {
     return File::put($path, $contents);
 }
Beispiel #28
0
 public function cached($key, $data = null)
 {
     $file = CACHE_PATH . DS . $key . '_sql';
     if (!empty($data)) {
         File::put($file, serialize($data));
         return $data;
     }
     if (File::exists($file)) {
         $age = time() - filemtime($file);
         if ($age > $this->_tts) {
             File::delete($file);
         } else {
             return unserialize(fgc($file));
         }
     }
 }
Beispiel #29
0
 private function csv($data)
 {
     $csv = implode("\n", $data);
     $name = date('d_m_Y_H_i_s') . '_' . $this->entity . '_export.csv';
     $file = TMP_PUBLIC_PATH . DS . $name;
     File::delete($file);
     File::put($file, $csv);
     Utils::go(repl('nma.php', '', URLSITE) . 'tmp/' . $name);
 }
Beispiel #30
0
 private function commit()
 {
     File::delete($this->db);
     File::put($this->db, json_encode($this->buffer));
     return $this;
 }