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; }
public function testContains() { $this->assertTrue(str::contains($this->sample, 'Äwesøme')); $this->assertTrue(str::contains($this->sample, 'äwesøme')); // don't ignore upper/lowercase $this->assertFalse(str::contains($this->sample, 'äwesøme', false)); // check for something which isn't there $this->assertFalse(str::contains($this->sample, 'Peter')); }
/** * Returns a registry entry object by type * * @param string $type * @param string $subtype * @return Kirby\Registry\Entry */ public function entry($type, $subtype = null) { $class = 'kirby\\registry\\' . $type; if (!class_exists('kirby\\registry\\' . $type)) { if (str::contains($type, '::')) { $parts = str::split($type, '::'); $subtype = $parts[0]; $type = $parts[1]; return $this->entry($type, $subtype); } throw new Exception('Unsupported registry entry type: ' . $type); } return new $class($this, $subtype); }
public function run() { if (empty($this->query) or str::length($this->query) <= 1) { return false; } $data = $this->data(); foreach ($data['pages'] as $page) { if (str::contains($page['title'], $this->query) or str::contains($page['uri'], $this->query)) { $this->pages->append($page['uri'], $page); } } foreach ($data['users'] as $user) { if (str::contains($user['username'], $this->query) or str::contains($user['email'], $this->query)) { $this->users->append($user['username'], $user); } } $this->pages = $this->pages->limit(5); $this->users = $this->users->limit(5); }
public function start() { $src = get('source'); $target = get('target'); if (!v::url($src)) { throw new Exception('Invalid source'); } if (!v::url($target)) { throw new Exception('Invalid target'); } if (!str::contains($target, site()->url())) { throw new Exception('Invalid target'); } require_once dirname(__DIR__) . DS . 'vendor' . DS . 'mf2.php'; require_once dirname(__DIR__) . DS . 'vendor' . DS . 'comments.php'; $data = \Mf2\fetch($src); $result = \IndieWeb\comments\parse($data['items'][0], $src); if (empty($result)) { throw new Exception('Probably spam'); } $path = ltrim(str_replace(site()->url(), '', $target), '/'); if (!empty($path) and $page = page($path)) { if (!empty($result['published'])) { $time = strtotime($result['published']); } else { $time = time(); $result['published'] = date('c'); } $json = json_encode($result); $hash = sha1($json); $file = $page->root() . DS . '.webmentions' . DS . $time . '-' . $hash . '.json'; f::write($file, $json); return true; } else { throw new Exception('Invalid page'); } }
public function trigger($url) { $response = remote::get($url); $html = $response->content(); if (preg_match_all('!\\<link(.*?)\\>!i', $html, $links)) { foreach ($links[0] as $link) { if (!str::contains($link, 'rel="webmention"')) { continue; } if (!preg_match('!href="(.*?)"!', $link, $match)) { continue; } $endpoint = $match[1]; $src = $this->page->url(); $target = $url; // invalid endpoint if (!v::url($endpoint)) { continue; } remote::post($endpoint, array('data' => array('source' => $src, 'target' => $target))); return $endpoint; } } }
function js($url) { $url = str::contains($url, 'http://') || str::contains($url, 'https://') ? $url : url(ltrim($url, '/')); return '<script type="text/javascript" src="' . $url . '"></script>' . "\n"; }
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'); } } } } } } } } } } }
function filterBy() { $args = func_get_args(); $field = a::get($args, 0); $operator = '=='; $value = a::get($args, 1); $split = a::get($args, 2); if ($value === '!=' || $value === '==' || $value === '*=') { $operator = $value; $value = a::get($args, 2); $split = a::get($args, 3); } $files = array(); switch ($operator) { // ignore matching elements case '!=': foreach ($this->_ as $key => $file) { if ($split) { $values = str::split((string) $file->{$field}(), $split); if (!in_array($value, $values)) { $files[$key] = $file; } } else { if ($file->{$field}() != $value) { $files[$key] = $file; } } } break; // search // search case '*=': foreach ($this->_ as $key => $file) { if ($split) { $values = str::split((string) $file->{$field}(), $split); foreach ($values as $val) { if (str::contains($val, $value)) { $files[$key] = $file; break; } } } else { if (str::contains($file->{$field}(), $value)) { $files[$key] = $file; } } } // take all matching elements // take all matching elements default: foreach ($this->_ as $key => $file) { if ($split) { $values = str::split((string) $file->{$field}(), $split); if (in_array($value, $values)) { $files[$key] = $file; } } else { if ($file->{$field}() == $value) { $files[$key] = $file; } } } break; } return new files($files); }
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'); } }
static function parseName($name) { if (str::contains($name, '-')) { $match = str::match($name, '!^([0-9]+[\\-]+)!', 0); $uid = str_replace($match, '', $name); $num = trim(rtrim($match, '-')); } else { $num = false; $uid = $name; } return array('uid' => $uid, 'num' => $num); }
<div class="social col-xs-6 col-sm-2"> <iframe class="pull-right" src="//www.facebook.com/plugins/like.php?href=<?php echo $page->url(); ?> &send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=21&appId=110196125731861" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe> </div> </div> <div class="row"> <?php if ($page->images()->count() > 1) { ?> <div class="gallery"> <?php $images = $page->images()->filter(function ($image) { return !str::contains($image->filename(), 'sponsor') && !str::contains($image->filename(), 'thumbnail'); }); foreach ($images as $slide) { ?> <figure class="gallery-cell col-xs-12"> <img src="<?php echo $slide->url(); ?> "> </figure> <?php } ?> <div class="gallery-cell col-xs-12"> <div class="lead col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3"> <?php
/** * Determine whether or not to wrap a string in CDATA * * @param string string to check * @return bool */ public static function use_cdata($value) { if (is_numeric($value)) { return NO; } if (!str::contains($value, array("\n", "\r"))) { if (strlen(preg_replace("/[a-z0-9\\.\\_ ]+/i", "", $value)) == 0) { return NO; } } // We'll make this more extensive later on return YES; }
/** * Checks if the url contains a query string */ public static function hasQuery($url = null) { if (is_null($url)) { $url = static::current(); } return str::contains($url, '?'); }
<?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; }; }
public static function firewall($params = array()) { //default options $defaults = array('ignore' => array(c::get('account.login.folder'), c::get('account.logout.folder')), 'redirect' => site()->find(c::get('account.login.folder'))->url(), 'allow' => array(), 'deny' => array()); //merge defaults options with custom options $options = array_merge($defaults, $params); //get active page $page = site()->activePage(); //if this is a public accessible page (i.e., included in ignore array option) if (in_array($page->uid(), $options['ignore'])) { return true; } //get current user $user = Auth::loggedUser(); //if no user is logged in if (!$user) { //go to redirection page go(url($options['redirect'])); } //set expected schema for firewall allow and deny array $arraySchema = array('user' => '', 'role' => ''); //throw error if allow array doesn't conform to expected array schema if (array_diff_key($options['allow'], $arraySchema)) { throw new Exception('Firewall schema incorrect'); } //throw error if deny array doesn't conform to expected array schema if (array_diff_key($options['deny'], $arraySchema)) { throw new Exception('Firewall schema incorrect'); } //set default value of $passFirewall $passFirewall = false; //*** ALLOWED PAGES LOOP foreach ($options['allow'] as $key => $value) { //see if user's username is allowed if ($allow = str::contains($value, $user->username())) { break; } //see if user's group is allowed $allow = str::contains($value, $user->role()); } //*** DENIED PAGES LOOP foreach ($options['deny'] as $key => $value) { //see if user's username is denied if ($deny = str::contains($value, $user->username())) { break; } //see if user's group is denied $deny = str::contains($value, $user->role()); } //*** ALLOWED TESTS LOOP //if we are in the tests folder if ($page->parent()->uid() == c::get('tests.folder')) { //get session tests $allowedTests = yaml(site()->find(implode(DS, array(c::get('sessions.folder'), $user->session())))->tests()); //loop though session's tests foreach ($allowedTests as $test) { //if current test is included in session's tests list and user's session status points to it if ($allowTest = str::lower($page->uid()) == str::lower($test['Test']) && str::lower($page->uid()) == str::lower($user->status())) { break; } } } else { //set $allowTest to true since we are not in tests folder //and hence the firewall acts only on ALLOW and DENY loops $allowTest = true; } //re-determine $passFirewall $passFirewall = $allow && !$deny && $allowTest; //if $passFirewall evaluates to false if (!$passFirewall) { //go to homepage for logged users. //Non logged users were redirected to the login page before go(site()->language()->url()); } //just in case return true; }
$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) { if (str::contains($page->uri(), 'xx-') || str::contains($page->uri(), 'liste-des-intervenants/')) { return false; } return true; }) as $page) { if (in_array($page->slug(), $ignore)) { continue; } ?> <?php foreach ($site->languages() as $language) { ?> <?php if (isset($page->inventory()['content'][$language->code()])) { ?> <url>
public function __construct($field) { $this->field = $field; // array method if (is_array($field->options)) { $this->options = $field->options; // api method with valid url } else { if (v::url($field->options) or str::contains($field->options, '://localhost') or str::contains($field->options, '://127.0.0.1')) { $response = remote::get($field->options); $options = @json_decode($response->content(), true); if (is_array($options)) { $this->options = $options; } else { $this->options = array(); } // without a page object, no files or related pages can be fetched } else { if (!$field->page) { $this->options = array(); // query method to query any set of images or files } 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 { if ($query['page'] == '/') { $page = site(); } 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; } } }
public function isUrl($url) { return v::url($url) or str::contains($url, '://localhost') or str::contains($url, '://127.0.0.1'); }
?> " id="<?php echo $id; ?> "> <?php foreach ($rows as $row) { $class = empty($row['class']) ? '' : ' class="' . $row['class'] . '"'; $style = empty($row['style']) ? '' : ' style="' . $row['style'] . '"'; ?> <tr<?php echo $class; echo $style; ?> onmouseover="this.className= this.className + ' ep-hover'" onmouseout="this.className=this.className.replace(' ep-hover', '')"> <?php foreach ($columns as $index => $column) { $class = empty($column['class']) ? '' : ' class="' . $column['class'] . '"'; $style = empty($column['style']) ? '' : ' style="' . $column['style'] . '"'; $value = $row['data'][$index]; if (!str::contains($row['class'], "ep-no-formatting")) { $value = (is_array($value) or is_object($value)) ? '<pre>' . html::specialchars(print_r($value, YES)) . '</pre>' : html::specialchars($value); } echo '<td', $style, $class, '><span>', $value, '</span></td>'; } ?> </tr> <?php } ?> </table>
/** * Tries to find a file for the given url/uri * * @param string $url a full path to a file or just a filename for files form the current active page * @return object File */ public function file($url) { // if this is an absolute url cancel if (preg_match('!(http|https)\\:\\/\\/!i', $url)) { return false; } // skip urls without extensions if (!preg_match('!\\.[a-z0-9]+$!i', $url)) { return false; } // relative url if (str::contains($url, '/')) { $path = dirname($url); $filename = basename($url); if ($page = page($path) and $file = $page->file($filename)) { return $file; } else { return false; } } // try to get all files for the current page $files = $this->files(); // cancel if no files are available if (!$files) { return false; } // try to find the file return $files->find($url); }
/** * Checks if the URL has a query string attached * * @param string $url * @return boolean */ static function has_query($url) { return str::contains($url, '?') ? true : false; }
/** * Dirty browser sniffing for an ios device * * @return boolean */ public static function ios() { $ua = visitor::ua(); return str::contains($ua, 'iPod') or str::contains($ua, 'iPhone') or str::contains($ua, 'iPad'); }
public static function setup($defaultFieldsRoot, $customFieldsRoot = null) { static::$root['default'] = $defaultFieldsRoot; static::$root['custom'] = $customFieldsRoot; load(static::files()); spl_autoload_register(function ($class) use($defaultFieldsRoot, $customFieldsRoot) { $class = strtolower($class); if (str::contains($class, 'field')) { $type = str_replace('field', '', $class); $file = $type . DS . $type . '.php'; $custom = $customFieldsRoot . DS . $file; $default = $defaultFieldsRoot . DS . $file; if ($customFieldsRoot and file_exists($custom)) { include $custom; } else { if (file_exists($default)) { include $default; } } } }); }
/** * The widont function makes sure that there are no * typographical widows at the end of a paragraph – * that's a single word in the last line * * @param string $string * @return string */ public static function widont($string = '') { return preg_replace_callback('|([^\\s])\\s+([^\\s]+)\\s*$|', function ($matches) { if (str::contains($matches[2], '-')) { return $matches[1] . ' ' . str_replace('-', '‑', $matches[2]); } else { return $matches[1] . ' ' . $matches[2]; } }, $string); }
static function url($url) { if (str::contains($url, 'http://') || str::contains($url, 'https://')) { return $url; } if (!self::$obj) { global $site; // search for a matching $files = $site->pages()->active()->files(); } else { $files = self::$obj->files(); } if ($files) { $file = $files->find($url); $url = $file ? $file->url() : url($url); } return $url; }
*/ $uri =& $_SERVER['REQUEST_URI']; // passing as reference $base = 'http://' . $_SERVER['HTTP_HOST']; $path = str::split($uri, '/'); // echo 'uri:'; // dump($uri); // echo 'path:'; // dump($path); if ($uri === '/sitemap') { $uri = $uri; } else { if ($uri === '/feed') { $uri = $uri; } else { if (str::contains($uri, 'category') && !str::contains($uri, '.')) { $GLOBALS['category_name'] = ucwords($path[1]); if (isset($path[1])) { $GLOBALS['category_name'] = $path[1]; } else { $GLOBALS['category_name'] = 'all'; } if (isset($path[2])) { $GLOBALS['project_name'] = $path[2]; } $uri = '/category'; } else { $GLOBALS['category_name'] = 'all'; if (empty($path)) { //$uri = '/'; } else {