当前位置: 首页>>代码示例>>PHP>>正文


PHP Utils::startsWith方法代码示例

本文整理汇总了PHP中Grav\Common\Utils::startsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::startsWith方法的具体用法?PHP Utils::startsWith怎么用?PHP Utils::startsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grav\Common\Utils的用法示例。


在下文中一共展示了Utils::startsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 public function init()
 {
     $this->shortcode->getHandlers()->add('fa', function (ShortcodeInterface $sc) {
         // Load assets if required
         if ($this->config->get('plugins.shortcode-core.fontawesome.load', false)) {
             $this->shortcode->addAssets('css', $this->config->get('plugins.shortcode-core.fontawesome.url'));
         }
         // Get shortcode content and parameters
         $str = $sc->getContent();
         $icon = $sc->getParameter('icon', false);
         if (!$icon) {
             $icon = $sc->getParameter('fa', trim($sc->getParameterAt(0), '='));
         }
         if (!Utils::startsWith($icon, 'fa-')) {
             $icon = 'fa-' . $icon;
         }
         $extras = explode(',', $sc->getParameter('extras', ''));
         foreach ($extras as $extra) {
             if (!Utils::startsWith($extra, 'fa-')) {
                 $extra = 'fa-' . $extra;
             }
             $icon .= ' ' . $extra;
         }
         $output = '<i class="fa ' . $icon . '">' . $str . '</i>';
         return $output;
     });
 }
开发者ID:getgrav,项目名称:grav-plugin-shortcode-core,代码行数:27,代码来源:FontAwesomeShortcode.php

示例2: setup

 /**
  * If the admin path matches, initialize the Login plugin configuration and set the admin
  * as active.
  */
 public function setup()
 {
     // Autoloader
     spl_autoload_register(function ($class) {
         if (Utils::startsWith($class, 'Grav\\Plugin\\Admin')) {
             require_once __DIR__ . '/classes/' . strtolower(basename(str_replace("\\", "/", $class))) . '.php';
         }
     });
     $route = $this->config->get('plugins.admin.route');
     if (!$route) {
         return;
     }
     $this->base = '/' . trim($route, '/');
     $this->admin_route = rtrim($this->grav['pages']->base(), '/') . $this->base;
     $this->uri = $this->grav['uri'];
     // check for existence of a user account
     $account_dir = $file_path = $this->grav['locator']->findResource('account://');
     $user_check = glob($account_dir . '/*.yaml');
     // If no users found, go to register
     if ($user_check == false || count((array) $user_check) == 0) {
         if (!$this->isAdminPath()) {
             $this->grav->redirect($this->admin_route);
         }
         $this->template = 'register';
     }
     // Only activate admin if we're inside the admin path.
     if ($this->isAdminPath()) {
         $this->active = true;
         // Set cache based on admin_cache option
         if (method_exists($this->grav['cache'], 'setEnabled')) {
             $this->grav['cache']->setEnabled($this->config->get('plugins.admin.cache_enabled'));
         }
     }
 }
开发者ID:getgrav,项目名称:grav-plugin-admin,代码行数:38,代码来源:admin.php

示例3: testStartsWith

 public function testStartsWith()
 {
     $this->assertTrue(Utils::startsWith('english', 'en'));
     $this->assertTrue(Utils::startsWith('English', 'En'));
     $this->assertTrue(Utils::startsWith('ENGLISH', 'EN'));
     $this->assertTrue(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'EN'));
     $this->assertFalse(Utils::startsWith('english', 'En'));
     $this->assertFalse(Utils::startsWith('English', 'EN'));
     $this->assertFalse(Utils::startsWith('ENGLISH', 'en'));
     $this->assertFalse(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'e'));
 }
开发者ID:getgrav,项目名称:grav,代码行数:11,代码来源:UtilsTest.php

示例4: filecontent

 public function filecontent($path)
 {
     $path_info = pathinfo($path);
     $config = Grav::instance()['config']->get('plugins.file-content');
     if (in_array($path_info['extension'], $config['allowed_extensions'])) {
         if (Utils::startsWith($path, '/')) {
             if ($config['allow_in_grav'] && file_exists(GRAV_ROOT . $path)) {
                 return file_get_contents(GRAV_ROOT . $path);
             } elseif ($config['allow_in_filesystem'] && file_exists($path)) {
                 return file_get_contents($path);
             }
         } else {
             $page_path = Grav::instance()['page']->path() . '/' . $path;
             if ($config['allow_in_page'] && file_exists($page_path)) {
                 return file_get_contents($page_path);
             }
         }
     }
     return $path;
 }
开发者ID:getgrav,项目名称:grav-plugin-file-content,代码行数:20,代码来源:FileContentTwigExtension.php

示例5: onPagesInitialized

 /**
  * Build search results.
  */
 public function onPagesInitialized()
 {
     $page = $this->grav['page'];
     // If a page exists merge the configs
     if ($page) {
         $this->config->set('plugins.simplesearch', $this->mergeConfig($page));
     }
     /** @var Uri $uri */
     $uri = $this->grav['uri'];
     $query = $uri->param('query') ?: $uri->query('query');
     $route = $this->config->get('plugins.simplesearch.route');
     // performance check
     if ($route && $query && $route == $uri->path()) {
         $this->enable(['onTwigSiteVariables' => ['onTwigSiteVariables', 0]]);
     } else {
         return;
     }
     $this->query = explode(',', $query);
     /** @var Taxonomy $taxonomy_map */
     $taxonomy_map = $this->grav['taxonomy'];
     $taxonomies = [];
     $filters = (array) $this->config->get('plugins.simplesearch.filters');
     $operator = $this->config->get('plugins.simplesearch.filter_combinator', 'and');
     // see if the filter uses the new 'items-type' syntax
     $new_approach = false;
     foreach ($filters as $filter) {
         $filter_saved = $filter;
         if (is_array($filter)) {
             $filter = key($filter);
         }
         if (Utils::startsWith($filter, '@')) {
             if ($filter == '@self') {
                 $new_approach = true;
             }
             if ($filter == '@taxonomy') {
                 $taxonomies = $filter_saved[$filter];
             }
         }
     }
     if ($new_approach) {
         $params = $page->header()->content;
         $params['query'] = $this->config->get('plugins.simplesearch.query');
         $this->collection = $page->collection($params, false);
     } else {
         $this->collection = new Collection();
         $this->collection->append($taxonomy_map->findTaxonomy($filters, $operator)->toArray());
     }
     $extras = [];
     /** @var Page $cpage */
     foreach ($this->collection as $cpage) {
         foreach ($this->query as $query) {
             $query = trim($query);
             $taxonomy_match = false;
             if (!empty($taxonomies)) {
                 $page_taxonomies = $cpage->taxonomy();
                 foreach ((array) $taxonomies as $taxonomy) {
                     if (array_key_exists($taxonomy, $page_taxonomies)) {
                         $taxonomy_values = implode('|', $page_taxonomies[$taxonomy]);
                         if (stripos($taxonomy_values, $query) !== false) {
                             $taxonomy_match = true;
                             break;
                         }
                     }
                 }
             }
             if ($taxonomy_match === false && stripos($cpage->content(), $query) === false && stripos($cpage->title(), $query) === false) {
                 $this->collection->remove($cpage);
                 continue;
             }
             if ($cpage->modular()) {
                 $this->collection->remove($cpage);
                 $parent = $cpage->parent();
                 $extras[$parent->path()] = ['slug' => $parent->slug()];
             }
         }
     }
     if (!empty($extras)) {
         $this->collection->append($extras);
     }
     // use a configured sorting order if not already done
     if (!$new_approach) {
         $this->collection = $this->collection->order($this->config->get('plugins.simplesearch.order.by'), $this->config->get('plugins.simplesearch.order.dir'));
     }
     // if page doesn't have settings set, create a page
     if (!isset($page->header()->simplesearch)) {
         // create the search page
         $page = new Page();
         $page->init(new \SplFileInfo(__DIR__ . '/pages/simplesearch.md'));
         // override the template is set in the config
         $template_override = $this->config->get('plugins.simplesearch.template');
         if ($template_override) {
             $page->template($template_override);
         }
         // fix RuntimeException: Cannot override frozen service "page" issue
         unset($this->grav['page']);
         $this->grav['page'] = $page;
     }
//.........这里部分代码省略.........
开发者ID:retsoced,项目名称:grav-plugin-simplesearch,代码行数:101,代码来源:simplesearch.php

示例6: processImageExcerpt

 /**
  * Process an image excerpt
  *
  * @param $excerpt
  * @param $page
  * @return mixed
  */
 public static function processImageExcerpt($excerpt, $page)
 {
     $url = $excerpt['element']['attributes']['src'];
     $url_parts = parse_url(htmlspecialchars_decode(urldecode($url)));
     if (isset($url_parts['scheme']) && !Utils::startsWith($url_parts['scheme'], 'http')) {
         $stream_path = $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'];
         $url_parts['path'] = $stream_path;
         unset($url_parts['host']);
         unset($url_parts['scheme']);
     }
     $this_host = isset($url_parts['host']) && $url_parts['host'] == Grav::instance()['uri']->host();
     // if there is no host set but there is a path, the file is local
     if ((!isset($url_parts['host']) || $this_host) && isset($url_parts['path'])) {
         $path_parts = pathinfo($url_parts['path']);
         $media = null;
         // get the local path to page media if possible
         if ($path_parts['dirname'] == $page->url(false, false, false)) {
             // get the media objects for this page
             $media = $page->media();
         } else {
             // see if this is an external page to this one
             $base_url = rtrim(Grav::instance()['base_url_relative'] . Grav::instance()['pages']->base(), '/');
             $page_route = '/' . ltrim(str_replace($base_url, '', $path_parts['dirname']), '/');
             $ext_page = Grav::instance()['pages']->dispatch($page_route, true);
             if ($ext_page) {
                 $media = $ext_page->media();
             } else {
                 Grav::instance()->fireEvent('onMediaLocate', new Event(['route' => $page_route, 'media' => &$media]));
             }
         }
         // if there is a media file that matches the path referenced..
         if ($media && isset($media->all()[$path_parts['basename']])) {
             // get the medium object
             /** @var Medium $medium */
             $medium = $media->all()[$path_parts['basename']];
             // Process operations
             $medium = static::processMediaActions($medium, $url_parts);
             $alt = isset($excerpt['element']['attributes']['alt']) ? $excerpt['element']['attributes']['alt'] : '';
             $title = isset($excerpt['element']['attributes']['title']) ? $excerpt['element']['attributes']['title'] : '';
             $class = isset($excerpt['element']['attributes']['class']) ? $excerpt['element']['attributes']['class'] : '';
             $id = isset($excerpt['element']['attributes']['id']) ? $excerpt['element']['attributes']['id'] : '';
             $excerpt['element'] = $medium->parseDownElement($title, $alt, $class, $id, true);
         } else {
             // not a current page media file, see if it needs converting to relative
             $excerpt['element']['attributes']['src'] = Uri::buildUrl($url_parts);
         }
     }
     return $excerpt;
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:56,代码来源:Excerpts.php

示例7: isExternalUrl

 /**
  * Test if a URL is external
  *
  * @param  string  $url     The URL to test.
  * @param  array   $domains An array of domains to be seen as internal.
  *
  * @return boolean          Returns true, if the URL is external,
  *                          false otherwise.
  */
 protected function isExternalUrl($url, $domains = [])
 {
     static $allowed_protocols;
     static $pattern;
     // Statically store allowed protocols
     if (!isset($allowed_protocols)) {
         $allowed_protocols = array_flip(array('ftp', 'http', 'https', 'irc', 'mailto', 'news', 'nntp', 'rtsp', 'sftp', 'ssh', 'tel', 'telnet', 'webcal'));
     }
     // Statically store internal domains as a PCRE pattern.
     if (!isset($pattern) || count($domains) > 0) {
         $domains = array_merge($domains, array(self::getGrav()['base_url_absolute']));
         foreach ($domains as $domain) {
             $domains[] = preg_quote($domain, '#');
         }
         $pattern = '#(' . str_replace(array('\\*', '/*'), '.*?', implode('|', $domains)) . ')#i';
     }
     $external = false;
     if (!preg_match($pattern, $url)) {
         // Check if URL is external by extracting colon position
         $colonpos = strpos($url, ':');
         if ($colonpos > 0) {
             // We found a colon, possibly a protocol. Verify.
             $protocol = strtolower(substr($url, 0, $colonpos));
             if (isset($allowed_protocols[$protocol])) {
                 // The protocol turns out be an allowed protocol
                 $external = true;
             }
         } elseif (Utils::startsWith($url, 'www.')) {
             // We found an url without protocol, but with starting
             // 'www' (sub-)domain
             $external = true;
         }
     }
     // Only if a colon and a valid protocol was found return true
     return $colonpos !== false && $external;
 }
开发者ID:hibbittsdesign,项目名称:cmpt-363-153-website,代码行数:45,代码来源:ExternalLinks.php

示例8: redirect

 /**
  * Redirect to the route stored in $this->redirect
  */
 public function redirect()
 {
     if (!$this->redirect) {
         return;
     }
     $base = $this->admin->base;
     $this->redirect = '/' . ltrim($this->redirect, '/');
     $multilang = $this->isMultilang();
     $redirect = '';
     if ($multilang) {
         // if base path does not already contain the lang code, add it
         $langPrefix = '/' . $this->grav['session']->admin_lang;
         if (!Utils::startsWith($base, $langPrefix . '/')) {
             $base = $langPrefix . $base;
         }
         // now the first 4 chars of base contain the lang code.
         // if redirect path already contains the lang code, and is != than the base lang code, then use redirect path as-is
         if (Utils::pathPrefixedByLangCode($base) && Utils::pathPrefixedByLangCode($this->redirect) && substr($base, 0, 4) != substr($this->redirect, 0, 4)) {
             $redirect = $this->redirect;
         } else {
             if (!Utils::startsWith($this->redirect, $base)) {
                 $this->redirect = $base . $this->redirect;
             }
         }
     } else {
         if (!Utils::startsWith($this->redirect, $base)) {
             $this->redirect = $base . $this->redirect;
         }
     }
     if (!$redirect) {
         $redirect = $this->redirect;
     }
     $this->grav->redirect($redirect, $this->redirectCode);
 }
开发者ID:clee03,项目名称:metal,代码行数:37,代码来源:controller.php

示例9: recurse

 /**
  * Recursive function to load & build page relationships.
  *
  * @param string $directory
  * @param Page|null $parent
  * @return Page
  * @throws \RuntimeException
  * @internal
  */
 protected function recurse($directory, Page &$parent = null)
 {
     $directory = rtrim($directory, DS);
     $iterator = new \DirectoryIterator($directory);
     $page = new Page();
     /** @var Config $config */
     $config = $this->grav['config'];
     $page->path($directory);
     if ($parent) {
         $page->parent($parent);
     }
     $page->orderDir($config->get('system.pages.order.dir'));
     $page->orderBy($config->get('system.pages.order.by'));
     // Add into instances
     if (!isset($this->instances[$page->path()])) {
         $this->instances[$page->path()] = $page;
         if ($parent && $page->path()) {
             $this->children[$parent->path()][$page->path()] = array('slug' => $page->slug());
         }
     } else {
         throw new \RuntimeException('Fatal error when creating page instances.');
     }
     // set current modified of page
     $last_modified = $page->modified();
     // flat for content availability
     $content_exists = false;
     /** @var \DirectoryIterator $file */
     foreach ($iterator as $file) {
         if ($file->isDot()) {
             continue;
         }
         $name = $file->getFilename();
         if ($file->isFile()) {
             // Update the last modified if it's newer than already found
             if ($file->getBasename() !== '.DS_Store' && ($modified = $file->getMTime()) > $last_modified) {
                 $last_modified = $modified;
             }
             if (preg_match('/^[^.].*' . CONTENT_EXT . '$/', $name)) {
                 $page->init($file);
                 $content_exists = true;
                 if ($config->get('system.pages.events.page')) {
                     $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
                 }
             }
         } elseif ($file->isDir()) {
             if (!$page->path()) {
                 $page->path($file->getPath());
             }
             $path = $directory . DS . $name;
             $child = $this->recurse($path, $page);
             if (Utils::startsWith($name, '_')) {
                 $child->routable(false);
             }
             $this->children[$page->path()][$child->path()] = array('slug' => $child->slug());
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
             }
         }
     }
     // Set routability to false if no page found
     if (!$content_exists) {
         $page->routable(false);
     }
     // Override the modified and ID so that it takes the latest change into account
     $page->modified($last_modified);
     $page->id($last_modified . md5($page->filePath()));
     // Sort based on Defaults or Page Overridden sort order
     $this->children[$page->path()] = $this->sort($page);
     return $page;
 }
开发者ID:alexslack,项目名称:faith-game,代码行数:79,代码来源:Pages.php

示例10: adminLanguages

 /**
  * Return the languages available in the admin
  *
  * @return array
  */
 public static function adminLanguages()
 {
     $languages = [];
     $path = Grav::instance()['locator']->findResource('plugins://admin/languages');
     /** @var \DirectoryIterator $directory */
     foreach (new \DirectoryIterator($path) as $file) {
         if ($file->isDir() || $file->isDot() || Utils::startsWith($file->getBasename(), '.')) {
             continue;
         }
         $lang = basename($file->getBasename(), '.yaml');
         $languages[$lang] = LanguageCodes::getNativeName($lang);
     }
     return $languages;
 }
开发者ID:getgrav,项目名称:grav-plugin-admin,代码行数:19,代码来源:admin.php

示例11: cleanFilesData

 private function cleanFilesData($key, $file)
 {
     /** @var Page $page */
     $page = null;
     $blueprint = $this->items['fields'][$key]['files'];
     $cleanFiles[$key] = [];
     if (!isset($blueprint)) {
         return false;
     }
     $cleanFiles = [$key => []];
     foreach ((array) $file['error'] as $index => $error) {
         if ($error == UPLOAD_ERR_OK) {
             $tmp_name = $file['tmp_name'][$index];
             $name = $file['name'][$index];
             $type = $file['type'][$index];
             $destination = Folder::getRelativePath(rtrim($blueprint['destination'], '/'));
             if (!$this->match_in_array($type, $blueprint['accept'])) {
                 throw new \RuntimeException('File "' . $name . '" is not an accepted MIME type.');
             }
             if (Utils::startsWith($destination, '@page:')) {
                 $parts = explode(':', $destination);
                 $route = $parts[1];
                 $page = self::getGrav()['page']->find($route);
                 if (!$page) {
                     throw new \RuntimeException('Unable to upload file to destination. Page route not found.');
                 }
                 $destination = $page->relativePagePath();
             } else {
                 if ($destination == '@self') {
                     $page = self::getGrav()['page'];
                     $destination = $page->relativePagePath();
                 } else {
                     Folder::mkdir($destination);
                 }
             }
             if (move_uploaded_file($tmp_name, "{$destination}/{$name}")) {
                 $path = $page ? self::getGrav()['uri']->convertUrl($page, $page->route() . '/' . $name) : $destination . '/' . $name;
                 $cleanFiles[$key][$path] = ['name' => $file['name'][$index], 'type' => $file['type'][$index], 'size' => $file['size'][$index], 'file' => $destination . '/' . $name, 'route' => $page ? $path : null];
             } else {
                 throw new \RuntimeException('Unable to upload file(s). Error Code: ' . $error);
             }
         }
     }
     return $cleanFiles[$key];
 }
开发者ID:clee03,项目名称:metal,代码行数:45,代码来源:form.php

示例12: isExternalUrl

 /**
  * Test if a URL is external
  *
  * @param  string     $url      The URL to test.
  * @param  array      $domains  An array of domains to be seen as internal.
  * @param  null|Page  $page     Null or an instance of \Grav\Common\Page.
  *
  * @return mixed                Returns the URL as a string, if it is external,
  *                              false otherwise.
  */
 protected function isExternalUrl($url, $domains = [], $page = null)
 {
     static $allowed_protocols;
     static $pattern;
     /** @var Config $config */
     $config = self::getGrav()['config'];
     /** @var Page $page */
     $page = $page ?: self::getGrav()['page'];
     // Statically store allowed protocols
     if (!isset($allowed_protocols)) {
         $allowed_protocols = array_flip($config->get('plugins.external_links.links.schemes', ['http', 'https']));
     }
     // Statically store internal domains as a PCRE pattern.
     if (!isset($pattern) || count($domains) > 0) {
         $domains = array_merge($domains, array(self::getGrav()['base_url_absolute']));
         foreach ($domains as $domain) {
             $domains[] = preg_quote($domain, '#');
         }
         $pattern = '#(' . str_replace(array('\\*', '/*'), '.*?', implode('|', $domains)) . ')#i';
     }
     $external = false;
     // Check for URLs that don't match any excluded domain
     if (!preg_match($pattern, $url)) {
         // Check if URL is external by extracting colon position
         $colonpos = strpos($url, ':');
         if ($colonpos > 0) {
             // We found a colon, possibly a protocol. Verify.
             $protocol = strtolower(substr($url, 0, $colonpos));
             if (isset($allowed_protocols[$protocol])) {
                 // The protocol turns out be an allowed protocol
                 $external = $url;
             }
         } elseif ($config->get('plugins.external_links.links.www')) {
             // Remove possible path duplicate
             $route = self::getGrav()['base_url'] . $page->route();
             $href = Utils::startsWith($url, $route) ? ltrim(mb_substr($url, mb_strlen($route)), '/') : $url;
             // We found an url without protocol, but with starting 'www' (sub-)domain
             if (Utils::startsWith($url, 'www.')) {
                 $external = 'http://' . $url;
             } elseif (Utils::startsWith($href, 'www.')) {
                 $external = 'http://' . $href;
             }
         }
     }
     // Only if a valid protocol or an URL starting with 'www.' was found return true
     return $external;
 }
开发者ID:Deester4x4jr,项目名称:Grav-Intra,代码行数:57,代码来源:ExternalLinks.php

示例13: recurse

 /**
  * Recursive function to load & build page relationships.
  *
  * @param string $directory
  * @param null $parent
  * @return Page
  * @throws \RuntimeException
  * @internal
  */
 protected function recurse($directory = PAGES_DIR, Page &$parent = null)
 {
     $directory = rtrim($directory, DS);
     $iterator = new \DirectoryIterator($directory);
     $page = new Page();
     $config = $this->grav['config'];
     $page->path($directory);
     if ($parent) {
         $page->parent($parent);
     }
     $page->orderDir($config->get('system.pages.order.dir'));
     $page->orderBy($config->get('system.pages.order.by'));
     // Add into instances
     if (!isset($this->instances[$page->path()])) {
         $this->instances[$page->path()] = $page;
         if ($parent && $page->path()) {
             $this->children[$parent->path()][$page->path()] = array('slug' => $page->slug());
         }
     } else {
         throw new \RuntimeException('Fatal error when creating page instances.');
     }
     $last_modified = 0;
     /** @var \DirectoryIterator $file */
     foreach ($iterator as $file) {
         $name = $file->getFilename();
         $date = $file->getMTime();
         if ($date > $last_modified) {
             $last_modified = $date;
         }
         if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) {
             $page->init($file);
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
             }
         } elseif ($file->isDir() && !$file->isDot()) {
             if (!$page->path()) {
                 $page->path($file->getPath());
             }
             $path = $directory . DS . $name;
             $child = $this->recurse($path, $page);
             if (Utils::startsWith($name, '_')) {
                 $child->routable(false);
             }
             $this->children[$page->path()][$child->path()] = array('slug' => $child->slug());
             // set the modified time if not already set
             if (!$page->date()) {
                 $page->date($file->getMTime());
             }
             // set the last modified time on pages
             $this->lastModified($file->getMTime());
             if ($config->get('system.pages.events.page')) {
                 $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
             }
         }
     }
     // Override the modified and ID so that it takes the latest change
     // into account
     $page->modified($last_modified);
     $page->id($last_modified . md5($page->filePath()));
     // Sort based on Defaults or Page Overridden sort order
     $this->children[$page->path()] = $this->sort($page);
     return $page;
 }
开发者ID:miguelramos,项目名称:grav,代码行数:72,代码来源:Pages.php

示例14: inlineLink

 protected function inlineLink($excerpt)
 {
     if (isset($excerpt['type'])) {
         $type = $excerpt['type'];
     } else {
         $type = 'link';
     }
     // do some trickery to get around Parsedown requirement for valid URL if its Twig in there
     if (preg_match($this->twig_link_regex, $excerpt['text'], $matches)) {
         $excerpt['text'] = str_replace($matches[1], '/', $excerpt['text']);
         $excerpt = parent::inlineLink($excerpt);
         $excerpt['element']['attributes']['href'] = $matches[1];
         $excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
         return $excerpt;
     } else {
         $excerpt = parent::inlineLink($excerpt);
     }
     // if this is a link
     if (isset($excerpt['element']['attributes']['href'])) {
         $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['href']));
         // if there is a query, then parse it and build action calls
         if (isset($url['query'])) {
             $actions = array_reduce(explode('&', $url['query']), function ($carry, $item) {
                 $parts = explode('=', $item, 2);
                 $value = isset($parts[1]) ? rawurldecode($parts[1]) : true;
                 $carry[$parts[0]] = $value;
                 return $carry;
             }, []);
             // valid attributes supported
             $valid_attributes = ['rel', 'target', 'id', 'class', 'classes'];
             // Unless told to not process, go through actions
             if (array_key_exists('noprocess', $actions)) {
                 unset($actions['noprocess']);
             } else {
                 // loop through actions for the image and call them
                 foreach ($actions as $attrib => $value) {
                     $key = $attrib;
                     if (in_array($attrib, $valid_attributes)) {
                         // support both class and classes
                         if ($attrib == 'classes') {
                             $attrib = 'class';
                         }
                         $excerpt['element']['attributes'][$attrib] = str_replace(',', ' ', $value);
                         unset($actions[$key]);
                     }
                 }
             }
             $url['query'] = http_build_query($actions, null, '&', PHP_QUERY_RFC3986);
         }
         // if no query elements left, unset query
         if (empty($url['query'])) {
             unset($url['query']);
         }
         // set path to / if not set
         if (empty($url['path'])) {
             $url['path'] = '';
         }
         // if special scheme, just return
         if (isset($url['scheme']) && !Utils::startsWith($url['scheme'], 'http')) {
             return $excerpt;
         }
         // handle paths and such
         $url = Uri::convertUrl($this->page, $url, $type);
         // build the URL from the component parts and set it on the element
         $excerpt['element']['attributes']['href'] = Uri::buildUrl($url);
     }
     return $excerpt;
 }
开发者ID:dweelie,项目名称:grav,代码行数:68,代码来源:ParsedownGravTrait.php

示例15: isRemoteLink

 /**
  * Determine whether a link is local or remote.
  *
  * Understands both "http://" and "https://" as well as protocol agnostic links "//"
  *
  * @param  string $link
  *
  * @return bool
  */
 protected function isRemoteLink($link)
 {
     $base = Grav::instance()['uri']->rootUrl(true);
     // sanity check for local URLs with absolute URL's enabled
     if (Utils::startsWith($link, $base)) {
         return false;
     }
     return 'http://' === substr($link, 0, 7) || 'https://' === substr($link, 0, 8) || '//' === substr($link, 0, 2);
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:18,代码来源:Assets.php


注:本文中的Grav\Common\Utils::startsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。