Пример #1
0
/**
 * Gets the value of an environment variable. Supports boolean, empty and null.
 *
 * @param  string  $key
 * @param  mixed   $default
 * @return mixed
 */
function env($key, $default = null)
{
    $value = getenv($key);
    if ($value === false) {
        return $default;
    }
    switch (strtolower($value)) {
        case 'true':
        case '(true)':
            return true;
        case 'false':
        case '(false)':
            return false;
        case 'empty':
        case '(empty)':
            return '';
        case 'null':
        case '(null)':
            return;
    }
    if (\str::startsWith($value, '"') && \str::endsWith($value, '"')) {
        return substr($value, 1, -1);
    }
    return $value;
}
Пример #2
0
 public function data($key = null, $value = null)
 {
     if (is_null($key)) {
         $data = array();
         foreach ($this->attr as $key => $val) {
             if (str::startsWith($key, 'data-')) {
                 $data[$key] = $val;
             }
         }
         return $data;
     } else {
         if (is_array($key)) {
             foreach ($key as $k => $v) {
                 $this->data($k, $v);
             }
             return $this;
         } else {
             if (is_null($value)) {
                 return a::get($this->attr, 'data-' . $key);
             } else {
                 $this->attr['data-' . $key] = $value;
                 return $this;
             }
         }
     }
 }
Пример #3
0
 public function license()
 {
     $key = c::get('license');
     $type = 'trial';
     /**
      * Hey stranger, 
      * 
      * So this is the mysterious place where the panel checks for 
      * valid licenses. As you can see, this is not reporting
      * back to any server and the license keys are rather simple to 
      * hack. If you really feel like removing the warning in the panel
      * or tricking Kirby into believing you bought a valid license even 
      * if you didn't, go for it! But remember that literally thousands of 
      * hours of work have gone into Kirby in order to make your 
      * life as a developer, designer, publisher, etc. easier. If this 
      * doesn't mean anything to you, you are probably a lost case anyway. 
      * 
      * Have a great day! 
      * 
      * Bastian
      */
     if (str::startsWith($key, 'K2-PRO') and str::length($key) == 39) {
         $type = 'Kirby 2 Professional';
     } else {
         if (str::startsWith($key, 'K2-PERSONAL') and str::length($key) == 44) {
             $type = 'Kirby 2 Personal';
         } else {
             if (str::startsWith($key, 'MD-') and str::length($key) == 35) {
                 $type = 'Kirby 1';
             } else {
                 if (str::startsWith($key, 'BETA') and str::length($key) == 9) {
                     $type = 'Kirby 1';
                 } else {
                     if (str::length($key) == 32) {
                         $type = 'Kirby 1';
                     } else {
                         $key = null;
                     }
                 }
             }
         }
     }
     $localhosts = array('::1', '127.0.01', '0.0.0.0');
     return new Obj(array('key' => $key, 'local' => in_array(server::get('SERVER_ADDR'), $localhosts) or server::get('SERVER_NAME') == 'localhost', 'type' => $type));
 }
Пример #4
0
 public function __construct($field)
 {
     $this->field = $field;
     if (is_array($field->options)) {
         $this->options = $field->options;
     } else {
         if (v::url($field->options)) {
             $response = remote::get($field->options);
             $options = @json_decode($response->content(), true);
             if (is_array($options)) {
                 $this->options = $options;
             } else {
                 $this->options = array();
             }
         } else {
             if (!$field->page) {
                 $this->options = array();
             } else {
                 if ($field->options == 'query') {
                     $defaults = array('page' => $field->page->id(), 'fetch' => 'children', 'value' => '{{uid}}', 'text' => '{{title}}', 'flip' => false, 'template' => false);
                     $query = array_merge($defaults, $field->query);
                     // dynamic page option
                     // ../
                     // ../../ etc.
                     if (str::startsWith($query['page'], '../')) {
                         $currentPage = $field->page;
                         $path = $query['page'];
                         while (str::startsWith($path, '../')) {
                             if ($parent = $currentPage->parent()) {
                                 $currentPage = $parent;
                             } else {
                                 break;
                             }
                             $path = str::substr($path, 3);
                         }
                         $page = $currentPage;
                     } else {
                         $page = page($query['page']);
                     }
                     $items = $this->items($page, $query['fetch']);
                     if ($query['template']) {
                         $items = $items->filter(function ($item) use($query) {
                             return in_array(str::lower($item->intendedTemplate()), array_map('str::lower', (array) $query['template']));
                         });
                     }
                     if ($query['flip']) {
                         $items = $items->flip();
                     }
                     foreach ($items as $item) {
                         $value = $this->tpl($query['value'], $item);
                         $text = $this->tpl($query['text'], $item);
                         $this->options[$value] = $text;
                     }
                 } else {
                     if ($items = $this->items($field->page, $field->options)) {
                         foreach ($items as $item) {
                             if (is_a($item, 'Page')) {
                                 $this->options[$item->uid()] = (string) $item->title();
                             } else {
                                 if (is_a($item, 'File')) {
                                     $this->options[$item->filename()] = (string) $item->filename();
                                 }
                             }
                         }
                     } else {
                         $this->options = array();
                     }
                 }
             }
         }
     }
     // sorting
     if (!empty($this->field->sort)) {
         switch (strtolower($this->field->sort)) {
             case 'asc':
                 asort($this->options);
                 break;
             case 'desc':
                 arsort($this->options);
                 break;
         }
     }
 }
Пример #5
0
 protected function checkUpload($file, $blueprint)
 {
     if (strtolower($file->extension()) == kirby()->option('content.file.extension', 'txt')) {
         throw new Exception('Content files cannot be uploaded');
     } else {
         if (strtolower($file->extension()) == 'php' or str::contains($file->extension(), 'php') or in_array($file->mime(), f::$mimes['php'])) {
             throw new Exception('PHP files cannot be uploaded');
         } else {
             if (strtolower($file->extension()) == 'html' or $file->mime() == 'text/html') {
                 throw new Exception('HTML files cannot be uploaded');
             } else {
                 if (strtolower($file->extension()) == 'exe' or $file->mime() == 'application/x-msdownload') {
                     throw new Exception('EXE files cannot be uploaded');
                 } else {
                     if (strtolower($file->filename()) == '.htaccess') {
                         throw new Exception('htaccess files cannot be uploaded');
                     } else {
                         if (str::startsWith($file->filename(), '.')) {
                             throw new Exception('Invisible files cannot be uploaded');
                             // Files blueprint option 'type'
                         } else {
                             if (count($blueprint->files()->type()) > 0 and !in_array($file->type(), $blueprint->files()->type())) {
                                 throw new Exception('Page only allows: ' . implode(', ', $blueprint->files()->type()));
                                 // Files blueprint option 'size'
                             } else {
                                 if ($blueprint->files()->size() and f::size($file->root()) > $blueprint->files()->size()) {
                                     throw new Exception('Page only allows file size of ' . f::niceSize($blueprint->files()->size()));
                                     // Files blueprint option 'width'
                                 } else {
                                     if ($file->type() == 'image' and $blueprint->files()->width() and $file->width() > $blueprint->files()->width()) {
                                         throw new Exception('Page only allows image width of ' . $blueprint->files()->width() . 'px');
                                         // Files blueprint option 'height'
                                     } else {
                                         if ($file->type() == 'image' and $blueprint->files()->height() and $file->height() > $blueprint->files()->height()) {
                                             throw new Exception('Page only allows image height of ' . $blueprint->files()->height() . 'px');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #6
0
 /**
  * @param array $event the 'raw' event array of fields.
  * @return the array of fields without the 'private' fields with keys
  */
 private static function filterFields($event)
 {
     foreach (array_keys($event) as $key) {
         if (str::startsWith($key, '_')) {
             unset($event[$key]);
         }
     }
     return $event;
 }
Пример #7
0
 *
 * @param Page $parent 
 * @return Collection A collection of Section objects
 * @author fenixkim
 */
function sections(Page $parent = null)
{
    // Fetchs the current page if $parent is null
    return new Sections($parent ?: page());
}
$kirby->set('page::method', 'sections', function ($page) {
    return new Sections($page ?: page());
});
$kirby->set('page::method', 'isSection', function ($page) {
    return Sections::pageIsSection($page);
});
$kirby->set('page::method', 'countSections', function ($page) {
    return $page->sections()->count();
});
$kirby->set('page::method', 'hasSections', function ($page) {
    return $page->sections()->count() > 0;
});
$kirby->set('page::method', 'avoidDirectLink', function ($page, $redirectToParent = true, $addHash = true) {
    Sections::avoidDirectLink($page, $redirectToParent, $addHash);
    return $page;
});
$kirby->set('pages::method', 'notSections', function ($pages) {
    return $pages->filter(function ($child) {
        return !str::startsWith($child->template(), Sections::prefix());
    });
});
Пример #8
0
<table>
	<thead>
		<tr>
			<th>Field</th>
			<th>Value</th>
		</tr>
	</thead>
	<tbody>
<?php 
foreach ($form as $field => $value) {
    if (str::startsWith($field, '_')) {
        continue;
    }
    if (is_array($value)) {
        $value = implode(', ', array_filter($value, function ($i) {
            return $i !== '';
        }));
    }
    ?>
		<tr>
			<td><?php 
    echo ucfirst($field);
    ?>
</td>
			<td><?php 
    echo $value;
    ?>
</td>
		</tr>
<?php 
}
Пример #9
0
 public function clean($root)
 {
     if (!is_dir($root)) {
         throw new Exception('The given directory does not exist');
     }
     if (!str::startsWith($root, $this->root)) {
         throw new Exception('Invalid directory. Must be within the library');
     }
     while ($root != $this->root) {
         $files = dir::read($root);
         if (count($files) === 0) {
             dir::remove($root);
         } else {
             break;
         }
         $root = dirname($root);
     }
 }
Пример #10
0
 public function reset()
 {
     if ($this->field) {
         return $this->store()->reset();
     } else {
         foreach (s::get() as $key => $value) {
             if (str::startsWith($key, $this->id)) {
                 s::remove($key);
             }
         }
     }
 }
Пример #11
0
 public function checkUpload($file)
 {
     $filesettings = $this->blueprint->files();
     $forbiddenExtensions = array('php', 'html', 'htm', 'exe', kirby()->option('content.file.extension', 'txt'));
     $forbiddenMimes = array_merge(f::$mimes['php'], array('text/html', 'application/x-msdownload'));
     $extension = strtolower($file->extension());
     // files without extension are not allowed
     if (empty($extension)) {
         throw new Exception(l('files.add.error.extension.missing'));
     }
     // block forbidden extensions
     if (in_array($extension, $forbiddenExtensions)) {
         throw new Exception(l('files.add.error.extension.forbidden'));
     }
     // especially block any connection that contains php
     if (str::contains($extension, 'php')) {
         throw new Exception(l('files.add.error.extension.forbidden'));
     }
     // block forbidden mimes
     if (in_array(strtolower($file->mime()), $forbiddenMimes)) {
         throw new Exception(l('files.add.error.mime.forbidden'));
     }
     // Block htaccess files
     if (strtolower($file->filename()) == '.htaccess') {
         throw new Exception(l('files.add.error.htaccess'));
     }
     // Block invisible files
     if (str::startsWith($file->filename(), '.')) {
         throw new Exception(l('files.add.error.invisible'));
     }
     // Files blueprint option 'type'
     if (count($filesettings->type()) > 0 and !in_array($file->type(), $filesettings->type())) {
         throw new Exception(l('files.add.blueprint.type.error') . implode(', ', $filesettings->type()));
     }
     // Files blueprint option 'size'
     if ($filesettings->size() and f::size($file->root()) > $filesettings->size()) {
         throw new Exception(l('files.add.blueprint.size.error') . f::niceSize($filesettings->size()));
     }
     // Files blueprint option 'width'
     if ($file->type() == 'image' and $filesettings->width() and $file->width() > $filesettings->width()) {
         throw new Exception('Page only allows image width of ' . $filesettings->width() . 'px');
     }
     // Files blueprint option 'height'
     if ($file->type() == 'image' and $filesettings->height() and $file->height() > $filesettings->height()) {
         throw new Exception('Page only allows image height of ' . $filesettings->height() . 'px');
     }
 }
 function isPatterns()
 {
     return str::startsWith(url::current(), $this->url_patterns);
 }
Пример #13
0
 /**
  * Load plugin options.
  *
  * @return array
  */
 public function load()
 {
     // Retrieve all plugin options from the configuration starting with a
     // prefix matching the plugin name
     $prefix = $this->namespace . '.';
     $keys = array_keys(c::$data);
     $keys = array_filter($keys, function ($key) use($prefix) {
         return str::startsWith($key, $prefix);
     });
     // Remove prefix and collect data
     $options = array();
     foreach ($keys as $key) {
         $option = str::substr($key, str::length($prefix));
         $options[$option] = c::$data[$key];
     }
     // Merge plugin settings with defaults
     $defaults = $this->defaults();
     if (is_array($defaults) && !empty($defaults)) {
         $options = array_merge($defaults, $options);
     }
     return $options;
 }
Пример #14
0
 /**
  * Check if a Page is a Section
  *
  * @param Page $page 
  * @return bool
  * @author fenixkim
  */
 public static function pageIsSection(Page $page)
 {
     return str::startsWith($page->template(), static::prefix());
 }
Пример #15
0
<?php

if (c::get('cdn.content')) {
    kirby()->urls()->content = c::get('cdn.content');
}
if (c::get('cdn.thumbs')) {
    thumb::$defaults['url'] = c::get('cdn.thumbs');
}
if (c::get('cdn.assets')) {
    $original = url::$to;
    url::$to = function () use($original) {
        $url = call($original, func_get_args());
        if (!str::startsWith($url, kirby()->urls()->index())) {
            return $url;
        }
        if (str::contains($url, '/panel/assets')) {
            return $url;
        }
        $url = preg_replace_callback('!.*?\\/assets\\/(.*)$!', function ($match) {
            return c::get('cdn.assets') . '/' . $match[1];
        }, $url);
        return $url;
    };
}
Пример #16
0
    $lang_codes[$i]['locale'] = $language->locale();
    $i++;
}
//////////////////////////////////////////////////////////
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"<?php 
if (c::get('images.in.sitemap')) {
    ?>
 xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"<?php 
}
?>
>
<?php 
foreach ($pages->index()->filter(function ($page) {
    return !str::startsWith($page->dirname(), 'xx');
}) as $page) {
    if (in_array($page->slug(), $ignore)) {
        continue;
    }
    ?>
	<?php 
    foreach ($site->languages() as $language) {
        ?>
		<?php 
        if (isset($page->inventory()['content'][$language->code()])) {
            ?>
			<url>
				<loc><?php 
            echo html($page->url($language->code()));
            ?>
Пример #17
0
 public function page($uri)
 {
     if (str::startsWith($uri, '../')) {
         if ($currentPage = $this->field->page) {
             $path = $uri;
             while (str::startsWith($path, '../')) {
                 if ($parent = $currentPage->parent()) {
                     $currentPage = $parent;
                 } else {
                     $currentPage = site();
                 }
                 $path = str::substr($path, 3);
             }
             if (!empty($path)) {
                 $currentPage = $currentPage->find($path);
             }
             $page = $currentPage;
         } else {
             $page = null;
         }
     } else {
         if ($uri == '/') {
             $page = site();
         } else {
             $page = page($uri);
         }
     }
     return $page;
 }
Пример #18
0
 /**
  * Registers all routes
  *
  * @param array $routes New routes
  * @return array
  */
 public function routes($routes = array())
 {
     // extend the existing routes
     if (!empty($routes) and is_array($routes)) {
         return $this->options['routes'] = array_merge($this->options['routes'], $routes);
     }
     $routes = $this->options['routes'];
     $kirby = $this;
     $site = $this->site();
     if ($site->multilang()) {
         foreach ($site->languages() as $lang) {
             $routes[] = array('pattern' => ltrim($lang->url . '/(:all?)', '/'), 'method' => 'ALL', 'lang' => $lang, 'action' => function ($path = null) use($kirby, $site) {
                 return $site->visit($path, $kirby->route->lang->code());
             });
         }
         // fallback for the homepage
         $routes[] = array('pattern' => '/', 'method' => 'ALL', 'action' => function () use($kirby, $site) {
             // check if the language detector is activated
             if ($kirby->option('language.detect')) {
                 if (s::get('language') and $language = $kirby->site()->sessionLanguage()) {
                     // $language is already set but the user wants to
                     // select the default language
                     $referer = r::referer();
                     if (!empty($referer) && str::startsWith($referer, $this->urls()->index())) {
                         $language = $kirby->site()->defaultLanguage();
                     }
                 } else {
                     // detect the user language
                     $language = $kirby->site()->detectedLanguage();
                 }
             } else {
                 // always use the default language if the detector is disabled
                 $language = $kirby->site()->defaultLanguage();
             }
             // redirect to the language homepage if necessary
             if ($language->url != '/' and $language->url != '') {
                 go($language->url());
             }
             // plain home pages
             return $site->visit('/', $language->code());
         });
     }
     // tinyurl handling
     if ($this->options['tinyurl.enabled']) {
         $routes['tinyurl'] = array('pattern' => $this->options['tinyurl.folder'] . '/(:any)/(:any?)', 'action' => function ($hash, $lang = null) use($site) {
             // make sure the language is set
             $site->visit('/', $lang);
             // find the page by it's tiny hash
             if ($page = $site->index()->findBy('hash', $hash)) {
                 go($page->url($lang));
             } else {
                 return $site->errorPage();
             }
         });
     }
     // all other urls
     $routes['others'] = array('pattern' => '(:all)', 'method' => 'ALL', 'action' => function ($path = null) use($site) {
         // visit the currently active page
         $page = $site->visit($path);
         // react on errors for invalid URLs
         if ($page->isErrorPage() and $page->uri() != $path) {
             // get the filename
             $filename = basename($path);
             $pagepath = dirname($path);
             // check if there's a page for the parent path
             if ($page = $site->find($pagepath)) {
                 // check if there's a file for the last element of the path
                 if ($file = $page->file($filename)) {
                     // TODO: put asset pipe here
                     // redirect to the real file url to make this snappy
                     go($file->url());
                 }
             }
             // return the error page if there's no such page
             return $site->errorPage();
         }
         return $page;
     });
     return $routes;
 }
Пример #19
0
 /**
  * Checks if an URL is absolute
  *
  * @return boolean
  */
 public static function isAbsolute($url)
 {
     // don't convert absolute urls
     return str::startsWith($url, 'http://') or str::startsWith($url, 'https://') or str::startsWith($url, '//');
 }
Пример #20
0
 /**
  * Bundles the form data to an e-mail body and sends it.
  */
 private function sendForm()
 {
     $mailBody = "";
     $snippet = $this->options['snippet'];
     if (empty($snippet)) {
         foreach ($this->data as $key => $value) {
             if (str::startsWith($key, '_')) {
                 continue;
             }
             $mailBody .= ucfirst($key) . ': ' . $value . "\n\n";
         }
     } else {
         $mailBody = snippet($snippet, array('data' => $this->data), true);
         if ($mailBody === false) {
             throw new Exception("The email snippet '" . $snippet . "' does not exist!");
         }
     }
     $params = array('service' => $this->options['service'], 'options' => $this->options['service-options'], 'to' => $this->options['to'], 'from' => a::get($this->data, 'name', '') . ' <' . a::get($this->data, '_from') . '>', 'subject' => $this->options['subject'], 'body' => $mailBody);
     $email = email($params);
     if ($email->send()) {
         $params['subject'] = l::get('sendform-email-copy') . ' ' . $params['subject'];
         // if everything was ok, send the copies
         foreach ($this->options['copy'] as $address) {
             $params['to'] = $address;
             email($params)->send();
         }
         $this->message = l::get('sendform-send-success');
         $this->sentSuccessful = true;
         // now this form send session is over, so destroy the token
         $this->destroyToken();
     } else {
         $this->message = l::get('sendform-send-error') . " " . $email->error();
     }
 }
Пример #21
0
    }
}
/* DEFAULT ACTIONS */
/*
 * The action to send the form data as an email.
 */
uniform::$actions['email'] = function ($form, $actionOptions) {
    $options = array('subject' => str::template(a::get($actionOptions, 'subject', l::get('uniform-email-subject')), $form), 'snippet' => a::get($actionOptions, 'snippet', false), 'to' => a::get($actionOptions, 'to'), 'sender' => a::get($actionOptions, 'sender'), 'service' => a::get($actionOptions, 'service', 'mail'), 'service-options' => a::get($actionOptions, 'service-options', array()));
    // remove newlines to prevent malicious modifications of the email
    // header
    $options['subject'] = str_replace("\n", '', $options['subject']);
    $mailBody = "";
    $snippet = $options['snippet'];
    if (empty($snippet)) {
        foreach ($form as $key => $value) {
            if (str::startsWith($key, '_')) {
                continue;
            }
            $mailBody .= ucfirst($key) . ': ' . $value . "\n\n";
        }
    } else {
        $mailBody = snippet($snippet, compact('form', 'options'), true);
        if ($mailBody === false) {
            throw new Exception('Uniform email action: The email snippet "' . $snippet . '" does not exist!');
        }
    }
    $params = array('service' => $options['service'], 'options' => $options['service-options'], 'to' => $options['to'], 'from' => $options['sender'], 'replyTo' => a::get($form, 'name', '') . ' <' . a::get($form, '_from') . '>', 'subject' => $options['subject'], 'body' => $mailBody);
    $email = email($params);
    if (array_key_exists('_receive_copy', $form)) {
        $params['subject'] = l::get('uniform-email-copy') . ' ' . $params['subject'];
        $params['to'] = $params['replyTo'];
Пример #22
0
 protected function checkUpload($file)
 {
     if (strtolower($file->extension()) == kirby()->option('content.file.extension', 'txt')) {
         throw new Exception('Content files cannot be uploaded');
     } else {
         if (strtolower($file->extension()) == 'php' or in_array($file->mime(), f::$mimes['php'])) {
             throw new Exception('PHP files cannot be uploaded');
         } else {
             if (strtolower($file->extension()) == 'html' or $file->mime() == 'text/html') {
                 throw new Exception('HTML files cannot be uploaded');
             } else {
                 if (strtolower($file->extension()) == 'exe' or $file->mime() == 'application/x-msdownload') {
                     throw new Exception('EXE files cannot be uploaded');
                 } else {
                     if (strtolower($file->filename()) == '.htaccess') {
                         throw new Exception('htaccess files cannot be uploaded');
                     } else {
                         if (str::startsWith($file->filename(), '.')) {
                             throw new Exception('Invisible files cannot be uploaded');
                         }
                     }
                 }
             }
         }
     }
 }
Пример #23
0
 /**
  * Registers all routes
  *
  * @param array $routes New routes
  * @return array
  */
 public function routes($routes = array())
 {
     // extend the existing routes
     if (!empty($routes) and is_array($routes)) {
         return $this->options['routes'] = array_merge($this->options['routes'], $routes);
     }
     $routes = $this->options['routes'];
     $kirby = $this;
     $site = $this->site();
     if ($site->multilang()) {
         foreach ($site->languages() as $lang) {
             $routes[] = array('pattern' => ltrim($lang->url . '/(:all?)', '/'), 'method' => 'ALL', 'lang' => $lang, 'action' => function ($path = null) use($kirby, $site) {
                 return $site->visit($path, $kirby->route->lang->code());
             });
         }
         // fallback for the homepage
         $routes[] = array('pattern' => '/', 'method' => 'ALL', 'action' => function () use($kirby, $site) {
             // check if the language detector is activated
             if ($kirby->option('language.detect')) {
                 if (s::get('language') and $language = $kirby->site()->sessionLanguage()) {
                     // $language is already set but the user wants to
                     // select the default language
                     $referer = r::referer();
                     if (!empty($referer) && str::startsWith($referer, $this->urls()->index())) {
                         $language = $kirby->site()->defaultLanguage();
                     }
                 } else {
                     // detect the user language
                     $language = $kirby->site()->detectedLanguage();
                 }
             } else {
                 // always use the default language if the detector is disabled
                 $language = $kirby->site()->defaultLanguage();
             }
             // redirect to the language homepage if necessary
             if ($language->url != '/' and $language->url != '') {
                 go($language->url());
             }
             // plain home pages
             return $site->visit('/', $language->code());
         });
     }
     // tinyurl handling
     $routes['tinyurl'] = $this->component('tinyurl')->route();
     // home redirect
     $routes['homeRedirect'] = array('pattern' => $this->options['home'], 'action' => function () {
         redirect::send(page('home')->url(), 307);
     });
     // plugin assets
     $routes['pluginAssets'] = array('pattern' => 'assets/plugins/(:any)/(:all)', 'method' => 'GET', 'action' => function ($plugin, $path) use($kirby) {
         $root = $kirby->roots()->plugins() . DS . $plugin . DS . 'assets' . DS . $path;
         $file = new Media($root);
         if ($file->exists()) {
             return new Response(f::read($root), f::extension($root));
         } else {
             return new Response('The file could not be found', f::extension($path), 404);
         }
     });
     // all other urls
     $routes['others'] = array('pattern' => '(:all)', 'method' => 'ALL', 'action' => function ($path = null) use($site, $kirby) {
         // visit the currently active page
         $page = $site->visit($path);
         // react on errors for invalid URLs
         if ($page->isErrorPage() and $page->uri() != $path) {
             // get the filename
             $filename = rawurldecode(basename($path));
             $pagepath = dirname($path);
             // check if there's a page for the parent path
             if ($page = $site->find($pagepath)) {
                 // check if there's a file for the last element of the path
                 if ($file = $page->file($filename)) {
                     go($file->url());
                 }
             }
             // return the error page if there's no such page
             return $site->errorPage();
         }
         return $page;
     });
     return $routes;
 }
Пример #24
0
 public function isOpen($path)
 {
     if ($path == $this->path) {
         return true;
     } else {
         if (str::startsWith($path, $this->path)) {
             return true;
         }
     }
 }
Пример #25
0
 public function license()
 {
     $key = c::get('license');
     $type = 'trial';
     if (str::startsWith($key, 'K2-PRO') and str::length($key) == 39) {
         $type = 'Kirby 2 Professional';
     } else {
         if (str::startsWith($key, 'K2-PERSONAL') and str::length($key) == 44) {
             $type = 'Kirby 2 Personal';
         } else {
             if (str::length($key) == 32) {
                 $type = 'Kirby 1';
             } else {
                 $key = null;
             }
         }
     }
     $localhosts = array('::1', '127.0.01', '0.0.0.0');
     return new Obj(array('key' => $key, 'local' => in_array(server::get('SERVER_ADDR'), $localhosts), 'type' => $type));
 }
Пример #26
0
 /**
  * Checks if the asset is a thumbnail
  * 
  * @return boolean
  */
 public function isThumb()
 {
     return str::startsWith($this->url(), $this->kirby->urls()->thumbs());
 }