public function set_cache($type, $result)
 {
     $cache_path = __DIR__ . '/../cache/' . $type . '.json';
     $period = c::get('kg.cache_period') ? c::get('kg.cache_period') : '30 Minutes';
     $cache = array('to' => strtotime($period), 'payload' => $result);
     \f::write($cache_path, json_encode($cache));
 }
Example #2
0
 function view()
 {
     events::observe('save', 'feedback');
     events::observer();
     $settings = settings::get('feedback');
     f::set($settings);
 }
Example #3
0
 public static function save()
 {
     if (!security::isLogged() || !USER_IS_ADMIN) {
         return;
     }
     $status = f::getParam("status");
     $clientId = f::getParam("client_id");
     $name = f::getParam("name");
     if ($status != 1 && $status != 0) {
         f::setError(400, "Invalid Client Status");
     }
     if (!$clientId && !$name) {
         f::setError(400, "Invalid Client Name");
     }
     $clientExists = f::dbRes("select 1 from fm_clients where id = {p:client_id}") == 1;
     if ($clientId && !$clientExists) {
         f::setError(400, "Invalid Client Id");
     }
     if (!f::hasErrors()) {
         if ($clientId) {
             f::dbQuery("update fm_clients set status = {p:status} where id = {p:client_id}");
         } else {
             f::dbQuery("insert into fm_clients set name = {p:name}, status = {p:status}");
         }
         f::setResponseJson(array("ok" => 1));
     }
 }
Example #4
0
 private static function validateFields($fields)
 {
     // validate fields
     $dataFields = array();
     foreach ($fields as $field) {
         if ($field["name"]) {
             if (!isset($field["type"])) {
                 $field["type"] = "string";
             }
             $validations = array();
             $validations[0] = $field["type"];
             if (isset($field["minlength"]) && $field["minlength"]) {
                 $validations[] = "minlength:{$field["minlength"]}";
             }
             if (isset($field["maxlength"]) && $field["maxlength"]) {
                 $validations[] = "maxlength:{$field["maxlength"]}";
             }
             if (isset($field["minvalue"]) && $field["minvalue"]) {
                 $validations[] = "minvalue:{$field["minvalue"]}";
             }
             if (isset($field["maxvalue"]) && $field["maxvalue"]) {
                 $validations[] = "maxvalue:{$field["maxvalue"]}";
             }
             if (!isset($field["errorMessage"])) {
                 $field["errorMessage"] = "Invalid {$field["name"]}";
             }
             f::validateParam($field["name"], $validations, $field["errorMessage"]);
             $dataFields[$field["name"]] = f::getParam($field["name"]);
         }
     }
     return $dataFields;
 }
Example #5
0
 public static function combine($type, $files, $compress = false)
 {
     $root = panel::instance()->roots()->assets() . DS . $type;
     $cache = new Media($root . DS . 'panel.' . $type);
     $media = new Collection(array_map(function ($file) use($root) {
         return new Media($root . DS . str_replace('/', DS, $file));
     }, $files));
     // get the max modification date
     $modified = max($media->pluck('modified'));
     if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) {
         $cache->remove();
         $content = '';
         foreach ($media as $asset) {
             $content .= $asset->read() . PHP_EOL;
         }
         if ($compress) {
             $content = static::compress($content);
         }
         f::write($root . DS . 'panel.' . $type, $content);
     }
     if ($cache->exists()) {
         return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version());
     }
     return $type(array_map(function ($item) use($type) {
         return 'panel/assets/' . $type . '/' . $item;
     }, $files));
 }
Example #6
0
 private static function routes()
 {
     kirby()->routes(array(array('pattern' => self::$route, 'action' => function () {
         echo SplitviewTool::html();
     }), array('pattern' => self::$route . '/assets/css/tool.css', 'action' => function () {
         $path = self::$assets . 'css' . DS . 'tool.css';
         return new Response(f::read($path), 'css');
     }), array('pattern' => self::$route . '/assets/css/tool.min.css', 'action' => function () {
         $path = self::$assets . 'css' . DS . 'tool.min.css';
         return new Response(f::read($path), 'css');
     }), array('pattern' => self::$route . '/assets/js/dist/tool.js', 'action' => function () {
         $path = self::$assets . 'js' . DS . 'dist/tool.js';
         return new Response(f::read($path), 'js');
     }), array('pattern' => self::$route . '/assets/js/dist/tool.min.js', 'action' => function () {
         $path = self::$assets . 'js' . DS . 'dist/tool.min.js';
         return new Response(f::read($path), 'js');
     }), array('pattern' => self::$route . '/assets/js/src/site.js', 'action' => function () {
         $path = self::$assets . 'js' . DS . 'src/site/site.js';
         return new Response(f::read($path), 'js');
     }), array('pattern' => self::$route . '/assets/js/dist/site.min.js', 'action' => function () {
         $path = self::$assets . 'js' . DS . 'dist/site.min.js';
         return new Response(f::read($path), 'js');
     }), array('pattern' => self::$route . '/assets/fonts/font-awesome.woff', 'action' => function () {
         $path = self::$assets . 'fonts' . DS . 'font-awesome-4.5.0' . DS . 'fontawesome-webfont.woff';
         return new Response(f::read($path), 'woff');
     }), array('pattern' => self::$route . '/assets/fonts/source-sans-pro.woff', 'action' => function () {
         $path = self::$assets . 'fonts' . DS . 'source-sans-pro' . DS . 'SourceSansPro-Regular.otf.woff';
         return new Response(f::read($path), 'woff');
     })));
 }
Example #7
0
 function crawl()
 {
     $path = url::strip_query($this->raw);
     $path = (array) str::split($path, '/');
     if (a::first($path) == 'index.php') {
         array_shift($path);
     }
     // parse params
     foreach ($path as $p) {
         if (str::contains($p, ':')) {
             $parts = explode(':', $p);
             if (count($parts) < 2) {
                 continue;
             }
             $this->params->{$parts}[0] = $parts[1];
         } else {
             $this->path->_[] = $p;
         }
     }
     // get the extension from the last part of the path
     $this->extension = f::extension($this->path->last());
     if ($this->extension != false) {
         // remove the last part of the path
         $last = array_pop($this->path->_);
         $this->path->_[] = f::name($last);
     }
     return $this->path;
 }
Example #8
0
 function edit()
 {
     events::observe('save', 'templates', 'apps', '_save');
     events::observer();
     $tmpl_file = events::get('tmpl_file');
     $app = events::get('app');
     if (events::detect('restore')) {
         self::restoreVersion($app, $tmpl_file, events::get('restore'));
     }
     admin::components('tabs', 'validator');
     f::set('app', $app);
     f::set('tmpl_file', $tmpl_file);
     s::set('app', $app);
     s::set('tmpl_file', $tmpl_file);
     $file = SYS_ROOT . 'tmpls/' . ADMIN_SITE . '/' . $app . '/' . $tmpl_file;
     $code = files::get($file);
     f::set('tmpl_code', $code);
     self::getApps();
     /*
     	Load versions
     */
     db::table('templates_versions');
     db::where('app', $app);
     db::where('tmpl_file', $tmpl_file);
     db::order('version_date', 'DESC');
     $res = db::select();
     while ($row = mysql_fetch_assoc($res)) {
         $row['version_date'] = dt::date2print('%H:%i %d.%m.%Y', $row['version_date']);
         $row['version_code'] = '{non}' . htmlspecialchars($row['version_code']) . '{/non}';
         s::roll('versions', $row);
     }
 }
Example #9
0
 public static function extract($file, $line)
 {
     $content = f::read($file);
     $lines = preg_split('/\\r\\n|\\n|\\r/', $content);
     $begin = $line - 5;
     if ($begin < 0) {
         $begin = 0;
     }
     $end = 10;
     $lines = array_slice($lines, $begin, $end);
     $html = '';
     $n = $begin + 1;
     foreach ($lines as $l) {
         if (empty($l)) {
             $l = ' ';
         }
         $num = '<span class="code-line-number">' . $n . '</span>';
         if ($n == $line) {
             $html .= '<span class="code-line code-line-highlighted">' . $num . htmlspecialchars($l) . '</span>';
         } else {
             $html .= '<span class="code-line">' . $num . htmlspecialchars($l) . '</span>';
         }
         $n++;
     }
     return $html;
 }
Example #10
0
 public static function edit()
 {
     if (!security::isLogged() || !USER_IS_ADMIN) {
         return;
     }
     $name = f::getParam("name");
     $availableFrom = f::date2sql(f::getParam("available_from"));
     $availableTo = f::date2sql(f::getParam("available_to"));
     $status = f::getParam("status");
     if ($status != 1 && $status != 0 && $status != 2) {
         f::setError(400, "Wrong Status");
     }
     if (!$name) {
         f::setError(400, "Invalid form name");
     }
     $clientExists = f::dbRes("select 1 from fm_clients where id = {p:client_id}");
     if (!$clientExists) {
         f::setError(400, "Client does not Exist");
     }
     if (!f::hasErrors()) {
         if (f::getParam("form_id")) {
             f::dbQuery("insert into fm_forms_log (created_date, form_id, client_id, name, enabled_domains, detail, available_from, available_to, status, description)\n\t\t\t\t\tselect now(), id, client_id, name, enabled_domains, detail, available_from, available_to, status, description from fm_forms where id = {p:form_id}");
             f::dbQuery("update fm_forms set name = {p:name}, detail = {p:detail}, available_from = {availableFrom}, available_to = {availableTo}, status = {p:status} where id = {p:form_id}", array("availableFrom" => $availableFrom, "availableTo" => $availableTo));
         } else {
             f::dbQuery("insert into fm_forms set client_id = {p:client_id}, name = {p:name}, detail = {p:detail}, available_from = {availableFrom}, available_to = {availableTo}, status = {p:status} ", array("availableFrom" => $availableFrom, "availableTo" => $availableTo));
         }
         f::setResponseJson(array("ok" => 1));
     }
 }
Example #11
0
 function view()
 {
     events::observe('save', 'pages', 'settings', 'save');
     events::observer();
     $settings = settings::get('pages');
     f::set($settings);
 }
Example #12
0
 /**
  * Sets up all curl options and sends the request
  *
  * @return object Response
  */
 protected function send()
 {
     // start a curl request
     $curl = curl_init();
     // curl options
     $params = array(CURLOPT_URL => $this->options['url'], CURLOPT_ENCODING => $this->options['encoding'], CURLOPT_CONNECTTIMEOUT => $this->options['timeout'], CURLOPT_TIMEOUT => $this->options['timeout'], CURLOPT_AUTOREFERER => true, CURLOPT_RETURNTRANSFER => $this->options['body'], CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => array($this, 'header'));
     // add the progress
     if (is_callable($this->options['progress'])) {
         $params[CURLOPT_NOPROGRESS] = false;
         $params[CURLOPT_PROGRESSFUNCTION] = $this->options['progress'];
     }
     // add all headers
     if (!empty($this->options['headers'])) {
         $params[CURLOPT_HTTPHEADER] = $this->options['headers'];
     }
     // add the user agent
     if (!empty($this->options['agent'])) {
         $params[CURLOPT_USERAGENT] = $this->options['agent'];
     }
     // do some request specific stuff
     switch (strtolower($this->options['method'])) {
         case 'post':
             $params[CURLOPT_POST] = true;
             $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
             break;
         case 'put':
             $params[CURLOPT_CUSTOMREQUEST] = 'PUT';
             $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
             // put a file
             if ($this->options['file']) {
                 $params[CURLOPT_INFILE] = fopen($this->options['file'], 'r');
                 $params[CURLOPT_INFILESIZE] = f::size($this->options['file']);
             }
             break;
         case 'delete':
             $params[CURLOPT_CUSTOMREQUEST] = 'DELETE';
             $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
             break;
         case 'head':
             $params[CURLOPT_CUSTOMREQUEST] = 'HEAD';
             $params[CURLOPT_POSTFIELDS] = $this->postfields($this->options['data']);
             $params[CURLOPT_NOBODY] = true;
             break;
     }
     curl_setopt_array($curl, $params);
     $content = curl_exec($curl);
     $error = curl_errno($curl);
     $message = curl_error($curl);
     $info = curl_getinfo($curl);
     curl_close($curl);
     $this->response = new RemoteResponse();
     $this->response->headers = $this->headers;
     $this->response->error = $error;
     $this->response->message = $message;
     $this->response->content = $content;
     $this->response->code = $info['http_code'];
     $this->response->info = $info;
     return $this->response;
 }
Example #13
0
 public function render()
 {
     $file = $this->root . DS . str_replace('.', DS, $this->file) . '.php';
     if (!file_exists($file)) {
         throw new Exception('Invalid view: ' . $this->file);
     }
     return f::load($file, $this->data);
 }
Example #14
0
 protected function delete($name, $output)
 {
     if ($file = f::resolve($this->root() . DS . $name, ['yaml', 'yml', 'php'])) {
         f::remove($file);
     }
     $output->writeln('<comment>The "' . $name . '" blueprint has been deleted!</comment>');
     $output->writeln('');
 }
Example #15
0
 public static function write($file, $data, $type = null)
 {
     // type autodetection
     if (is_null($type)) {
         $type = f::extension($file);
     }
     return f::write($file, data::encode($data, $type));
 }
Example #16
0
 function view()
 {
     events::observe('save', 'system', 'users', 'saveProfile');
     events::observer();
     admin::components('validator');
     admin::addHeader(' ' . adminUser::get('user_login'));
     f::set(adminUser::gets());
 }
Example #17
0
 public function assets($type, $root, $files)
 {
     $output = array();
     foreach ($files as $filename) {
         $output[] = f::read(dirname($root) . DS . 'assets' . DS . $type . DS . $filename);
     }
     $this->{$type} .= implode(PHP_EOL . PHP_EOL, $output);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->user = $this->createAdmin();
     $this->user->login('test');
     $this->page = $this->site->children()->create('test', 'test');
     f::copy($this->roots->dummy . DS . 'images' . DS . 'forrest.jpg', $this->page->root() . DS . '1.jpg');
     f::copy($this->roots->dummy . DS . 'images' . DS . 'forrest.jpg', $this->page->root() . DS . '2.jpg');
 }
Example #19
0
 public function language()
 {
     if (!is_null($this->language)) {
         return $this->language;
     }
     $codes = $this->page->site()->languages()->codes();
     $code = f::extension(f::name($this->root));
     return $this->language = in_array($code, $codes) ? $this->page->site()->languages()->find($code) : false;
 }
Example #20
0
 public function to()
 {
     $source = $this->source();
     $name = f::name($source['name']);
     $extension = f::extension($source['name']);
     $safeName = f::safeName($name);
     $safeExtension = str_replace('jpeg', 'jpg', str::lower($extension));
     return str::template($this->options['to'], array('name' => $name, 'filename' => $source['name'], 'safeName' => $safeName, 'safeFilename' => $safeName . '.' . $safeExtension, 'extension' => $extension, 'safeExtension' => $safeExtension));
 }
Example #21
0
 public function testRebuild()
 {
     $a = $this->library->create('test');
     $b = $this->library->create('test');
     // delete the index
     f::remove($this->library->root() . DS . 'library.sqlite');
     $this->library->rebuild();
     $this->assertEquals(2, $this->library->count());
     $this->assertInstanceOf('Library\\Item', $this->library->find($b->id()));
 }
Example #22
0
 public function listAcciones()
 {
     if (f::isEmpty(self::$accion)) {
         $this->db->setQuery("\n                SELECT\n                    idAccion\n                  , nombre\n                  , descripcion\n                  , mensaje\n                  , orden\n                  , 0 as estado\n                FROM _accion\n                ORDER BY orden ASC\n            ");
         //f::message($this->db->getQuery());
         $this->db->executeQuery();
         self::$accion = $this->db->getTable();
     }
     return self::$accion;
 }
Example #23
0
 public function runTests($result)
 {
     $root = TEST_ROOT_ETC . DS . 'kirbytext';
     $dirs = dir::read($root);
     foreach ($dirs as $dir) {
         $testFile = $root . DS . $dir . DS . 'test.txt';
         $expectedFile = $root . DS . $dir . DS . 'expected.html';
         $this->assertEquals(f::read($expectedFile), $result(f::read($testFile)), 'test: ' . $dir);
     }
 }
Example #24
0
 public static final function redirectSystem()
 {
     f::setSession('FrontController.HTTP_REFERER', @$_SERVER['HTTP_REFERER']);
     InterceptingFilter::resetSessionSystem();
     InterceptingFilter::encodeMethodGet();
     InterceptingFilter::refreshMethodPost();
     if (InterceptingFilter::validaIP()) {
         c::getViewSystem('index.php');
     }
 }
Example #25
0
 public function testSize()
 {
     dir::make($this->tmpDir);
     f::write($this->tmpDir . DS . 'testfile-1.txt', str::random(5));
     f::write($this->tmpDir . DS . 'testfile-2.txt', str::random(5));
     f::write($this->tmpDir . DS . 'testfile-3.txt', str::random(5));
     $this->assertEquals(15, dir::size($this->tmpDir));
     $this->assertEquals('15 b', dir::niceSize($this->tmpDir));
     dir::remove($this->tmpDir);
 }
Example #26
0
 function edit()
 {
     events::observe('save', 'news', 'save');
     events::observer();
     admin::components('validator', 'redactor');
     db::table('news');
     db::where('news_id', admin::get('id'));
     $row = db::assoc();
     f::set($row);
 }
Example #27
0
 public function logoff()
 {
     f::setSession('idUsuario', null);
     f::setSession('nombre', null);
     v::setTrueJSON();
     v::setJSON('tag', 'body');
     v::setJSON('ubicacion', 'up');
     v::setJSON('descripcion', c::getViewSystem('modulos/login/index.php', false));
     v::printJSON();
 }
 function sublime($params)
 {
     global $site;
     $page = $this->obj;
     $id = @$params['sublime'];
     $class = @$params['class'];
     $videos = array();
     $poster = false;
     // gather all video files which match the given id/name
     foreach ($page->videos() as $v) {
         if (preg_match('!^' . preg_quote($id) . '!i', $v->name())) {
             $extension = f::extension($v->name());
             $mobile = $extension == 'mobile' ? $v->mobile = true : ($v->mobile = false);
             $hd = $extension == 'hd' ? $v->hd = true : ($v->hd = false);
             $videos[] = $v;
         }
     }
     if (empty($videos)) {
         return false;
     }
     // find the poster for this video
     foreach ($page->images() as $i) {
         if (preg_match('!^' . preg_quote($id) . '!i', $i->name())) {
             $poster = $i;
             break;
         }
     }
     $defaults = array('uid' => $id, 'name' => $id);
     $options = array_merge($defaults, $params);
     $width = html($options['width']);
     $height = html($options['height']);
     $uid = html($options['uid']);
     $name = html($options['name']);
     if (!$width) {
         $width = c::get('kirbytext.video.width');
     }
     if (!$height) {
         $height = c::get('kirbytext.video.height');
     }
     // create an additional css class if specified
     if (!empty($class)) {
         $class = ' ' . html($class);
     }
     // check for a poster
     $poster = $poster ? ' poster="' . $poster->url() . '"' : false;
     $html = '<video class="sublime' . $class . '"' . $poster . ' width="' . $width . '" height="' . $height . '" data-uid="' . $uid . '" data-name="' . $name . '" preload="none">';
     foreach ($videos as $video) {
         // check for hd quality
         $hd = $video->hd() ? ' data-quality="hd"' : '';
         // generate the source tag for each video
         $html .= '<source src="' . $video->url() . '"' . $hd . ' />';
     }
     $html .= '</video>';
     return $html;
 }
Example #29
0
 public function _extend($params)
 {
     $extends = $params['extends'];
     $snippet = f::resolve(kirby()->roots()->blueprints() . DS . 'fields' . DS . $extends, array('yml', 'php', 'yaml'));
     if (empty($snippet)) {
         throw new Exception(l('fields.error.extended'));
     }
     $yaml = data::read($snippet, 'yaml');
     $params = a::merge($yaml, $params);
     return $params;
 }
 /**
  * Retreives a registered blueprint file path 
  * 
  * @param string $name
  * @return string 
  */
 public function get($name = null)
 {
     if (is_null($name)) {
         return static::$blueprints;
     }
     $file = f::resolve($this->kirby->roots()->blueprints() . DS . str_replace('/', DS, $name), ['php', 'yml', 'yaml']);
     if (file_exists($file)) {
         return $file;
     } else {
         return a::get(static::$blueprints, $name);
     }
 }