コード例 #1
0
ファイル: PagesTest.php プロジェクト: getgrav/grav
 public function testGetList()
 {
     $list = $this->pages->getList();
     $this->assertTrue(is_array($list));
     $this->assertSame('Home', $list['/']);
     $this->assertSame('Blog', $list['/blog']);
 }
コード例 #2
0
ファイル: Collection.php プロジェクト: qbi/datenknoten.me
 /**
  * Creates new collection with only routable pages
  *
  * @return Collection The collection with only routable pages
  */
 public function routable()
 {
     $routable = [];
     foreach (array_keys($this->items) as $path => $slug) {
         $page = $this->pages->get($path);
         if ($page->routable()) {
             $routable[$path] = $slug;
         }
     }
     return new static($routable, $this->params, $this->pages);
 }
コード例 #3
0
ファイル: Collection.php プロジェクト: rdquintas/Alphalink
 /**
  * Creates new collection with only pages of one of the specified types
  *
  * @return Collection The collection
  */
 public function ofOneOfTheseTypes($types)
 {
     $items = [];
     foreach ($this->items as $path => $slug) {
         $page = $this->pages->get($path);
         if (in_array($page->template(), $types)) {
             $items[$path] = $slug;
         }
     }
     $this->items = $items;
     return $this;
 }
コード例 #4
0
 /**
  * Creates new collection with only non-routable pages
  *
  * @return Collection The collection with only non-routable pages
  */
 public function nonRoutable()
 {
     $routable = [];
     foreach ($this->items as $path => $slug) {
         $page = $this->pages->get($path);
         if (!$page->routable()) {
             $routable[$path] = $slug;
         }
     }
     $this->items = $routable;
     return $this;
 }
コード例 #5
0
ファイル: ExcerptsTest.php プロジェクト: getgrav/grav
 protected function _before()
 {
     $grav = Fixtures::get('grav');
     $this->grav = $grav();
     $this->pages = $this->grav['pages'];
     $this->config = $this->grav['config'];
     $this->uri = $this->grav['uri'];
     $this->language = $this->grav['language'];
     $this->old_home = $this->config->get('system.home.alias');
     $this->config->set('system.home.alias', '/item1');
     $this->config->set('system.absolute_urls', false);
     $this->config->set('system.languages.supported', []);
     unset($this->grav['language']);
     $this->grav['language'] = new Language($this->grav);
     /** @var UniformResourceLocator $locator */
     $locator = $this->grav['locator'];
     $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
     $this->pages->init();
     $defaults = ['extra' => false, 'auto_line_breaks' => false, 'auto_url_links' => false, 'escape_markup' => false, 'special_chars' => ['>' => 'gt', '<' => 'lt']];
     $this->page = $this->pages->dispatch('/item2/item2-2');
     $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
 }
コード例 #6
0
 /**
  * Initializes the URI object based on the url set on the object
  */
 public function init()
 {
     $grav = Grav::instance();
     $config = $grav['config'];
     $language = $grav['language'];
     // resets
     $this->paths = [];
     $this->params = [];
     $this->query = [];
     // get any params and remove them
     $uri = str_replace($this->root, '', $this->url);
     // process params
     $uri = $this->processParams($uri, $config->get('system.param_sep'));
     // set active language
     $uri = $language->setActiveFromUri($uri);
     // redirect to language specific homepage if configured to do so
     if ($uri == '/' && $language->enabled()) {
         if ($config->get('system.languages.home_redirect.include_route', true)) {
             $prefix = $config->get('system.languages.home_redirect.include_lang', true) ? $language->getLanguage() . '/' : '';
             $grav->redirect($prefix . Pages::getHomeRoute());
         } elseif ($config->get('system.languages.home_redirect.include_lang', true)) {
             $grav->redirect($language->getLanguage() . '/');
         }
     }
     // split the URL and params
     $bits = parse_url($uri);
     // process query string
     if (isset($bits['query'])) {
         parse_str($bits['query'], $this->query);
         $uri = $bits['path'];
     }
     // remove the extension if there is one set
     $parts = pathinfo($uri);
     // set the original basename
     $this->basename = $parts['basename'];
     $valid_page_types = implode('|', $config->get('system.pages.types'));
     if (preg_match("/\\.(" . $valid_page_types . ")\$/", $parts['basename'])) {
         $uri = rtrim(str_replace(DIRECTORY_SEPARATOR, DS, $parts['dirname']), DS) . '/' . $parts['filename'];
         $this->extension = $parts['extension'];
     }
     // set the new url
     $this->url = $this->root . $uri;
     $this->path = $uri;
     $this->content_path = trim(str_replace($this->base, '', $this->path), '/');
     if ($this->content_path != '') {
         $this->paths = explode('/', $this->content_path);
     }
 }
コード例 #7
0
ファイル: ParsedownTest.php プロジェクト: getgrav/grav
 public function testRootAbsoluteLinks()
 {
     $this->uri->initializeWithURL('http://testing.dev/')->init();
     $defaults = ['extra' => false, 'auto_line_breaks' => false, 'auto_url_links' => false, 'escape_markup' => false, 'special_chars' => ['>' => 'gt', '<' => 'lt']];
     $page = $this->pages->dispatch('/');
     $this->parsedown = new Parsedown($page, $defaults);
     $this->assertSame('<p><a href="/item1/item1-3">Down a Level</a></p>', $this->parsedown->text('[Down a Level](item1-3)'));
     $this->assertSame('<p><a href="/item2">Peer Page</a></p>', $this->parsedown->text('[Peer Page](../item2)'));
     $this->assertSame('<p><a href="/?foo=bar">With Query</a></p>', $this->parsedown->text('[With Query](?foo=bar)'));
     $this->assertSame('<p><a href="/foo:bar">With Param</a></p>', $this->parsedown->text('[With Param](/foo:bar)'));
     $this->assertSame('<p><a href="#foo">With Anchor</a></p>', $this->parsedown->text('[With Anchor](#foo)'));
     $this->config->set('system.languages.supported', ['fr', 'en']);
     unset($this->grav['language']);
     $this->grav['language'] = new Language($this->grav);
     $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
     $this->assertSame('<p><a href="/fr/item2">Peer Page</a></p>', $this->parsedown->text('[Peer Page](../item2)'));
     $this->assertSame('<p><a href="/fr/item1/item1-3">Down a Level</a></p>', $this->parsedown->text('[Down a Level](item1-3)'));
     $this->assertSame('<p><a href="/fr/?foo=bar">With Query</a></p>', $this->parsedown->text('[With Query](?foo=bar)'));
     $this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>', $this->parsedown->text('[With Param](/foo:bar)'));
     $this->assertSame('<p><a href="#foo">With Anchor</a></p>', $this->parsedown->text('[With Anchor](#foo)'));
 }
コード例 #8
0
ファイル: Collection.php プロジェクト: ulilu/grav-toctoc
 /**
  * Creates new collection with only pages of one of the specified access levels
  *
  * @param $accessLevels
  *
  * @return Collection The collection
  */
 public function ofOneOfTheseAccessLevels($accessLevels)
 {
     $items = [];
     foreach ($this->items as $path => $slug) {
         $page = $this->pages->get($path);
         if ($page !== null && isset($page->header()->access)) {
             if (is_array($page->header()->access)) {
                 //Multiple values for access
                 $valid = false;
                 foreach ($page->header()->access as $index => $accessLevel) {
                     if (is_array($accessLevel)) {
                         foreach ($accessLevel as $innerIndex => $innerAccessLevel) {
                             if (in_array($innerAccessLevel, $accessLevels)) {
                                 $valid = true;
                             }
                         }
                     } else {
                         if (in_array($index, $accessLevels)) {
                             $valid = true;
                         }
                     }
                 }
                 if ($valid) {
                     $items[$path] = $slug;
                 }
             } else {
                 //Single value for access
                 if (in_array($page->header()->access, $accessLevels)) {
                     $items[$path] = $slug;
                 }
             }
         }
     }
     $this->items = $items;
     return $this;
 }
コード例 #9
0
ファイル: controller.php プロジェクト: clee03/metal
 /**
  * Handles filtering the page by modular/visible/routable in the pages list.
  */
 protected function taskFilterPages()
 {
     if (!$this->authorizeTask('filter pages', ['admin.pages', 'admin.super'])) {
         return;
     }
     $data = $this->post;
     $flags = !empty($data['flags']) ? array_map('strtolower', explode(',', $data['flags'])) : [];
     $queries = !empty($data['query']) ? explode(',', $data['query']) : [];
     /** @var Collection $collection */
     $collection = $this->grav['pages']->all();
     if (count($flags)) {
         // Filter by state
         $pageStates = array('modular', 'nonmodular', 'visible', 'nonvisible', 'routable', 'nonroutable', 'published', 'nonpublished');
         if (count(array_intersect($pageStates, $flags)) > 0) {
             if (in_array('modular', $flags)) {
                 $collection = $collection->modular();
             }
             if (in_array('nonmodular', $flags)) {
                 $collection = $collection->nonModular();
             }
             if (in_array('visible', $flags)) {
                 $collection = $collection->visible();
             }
             if (in_array('nonvisible', $flags)) {
                 $collection = $collection->nonVisible();
             }
             if (in_array('routable', $flags)) {
                 $collection = $collection->routable();
             }
             if (in_array('nonroutable', $flags)) {
                 $collection = $collection->nonRoutable();
             }
             if (in_array('published', $flags)) {
                 $collection = $collection->published();
             }
             if (in_array('nonpublished', $flags)) {
                 $collection = $collection->nonPublished();
             }
         }
         foreach ($pageStates as $pageState) {
             if (($pageState = array_search($pageState, $flags)) !== false) {
                 unset($flags[$pageState]);
             }
         }
         // Filter by page type
         if (count($flags)) {
             $types = [];
             $pageTypes = Pages::pageTypes();
             foreach ($pageTypes as $pageType) {
                 if (($pageType = array_search($pageType, $flags)) !== false) {
                     $types[] = $pageType;
                     unset($flags[$pageType]);
                 }
             }
             if (count($types)) {
                 $collection = $collection->ofOneOfTheseTypes($types);
             }
         }
         // Filter by page type
         if (count($flags)) {
             $accessLevels = $flags;
             $collection = $collection->ofOneOfTheseAccessLevels($accessLevels);
         }
     }
     if (!empty($queries)) {
         foreach ($collection as $page) {
             foreach ($queries as $query) {
                 $query = trim($query);
                 if (stripos($page->getRawContent(), $query) === false && stripos($page->title(), $query) === false) {
                     $collection->remove($page);
                 }
             }
         }
     }
     $results = [];
     foreach ($collection as $path => $page) {
         $results[] = $page->route();
     }
     $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.PAGES_FILTERED'), 'results' => $results];
     $this->admin->collection = $collection;
 }
コード例 #10
0
ファイル: admin.php プロジェクト: getgrav/grav-plugin-admin
 /**
  * Get all modular template types
  *
  * @return array
  */
 public function modularTypes()
 {
     return Pages::modularTypes();
 }
コード例 #11
0
ファイル: Uri.php プロジェクト: sunilkgrao/grav-test
 /**
  * Initializes the URI object based on the url set on the object
  */
 public function init()
 {
     $grav = Grav::instance();
     $config = $grav['config'];
     $language = $grav['language'];
     // resets
     $this->paths = [];
     $this->params = [];
     $this->query = [];
     // get any params and remove them
     $uri = str_replace($this->root, '', $this->url);
     // remove the setup.php based base if set:
     $setup_base = $grav['pages']->base();
     if ($setup_base) {
         $uri = str_replace($setup_base, '', $uri);
     }
     // If configured to, redirect trailing slash URI's with a 301 redirect
     if ($config->get('system.pages.redirect_trailing_slash', false) && $uri != '/' && Utils::endsWith($uri, '/')) {
         $grav->redirect(rtrim($uri, '/'), 301);
     }
     // process params
     $uri = $this->processParams($uri, $config->get('system.param_sep'));
     // set active language
     $uri = $language->setActiveFromUri($uri);
     // redirect to language specific homepage if configured to do so
     if ($uri == '/' && $language->enabled()) {
         if ($config->get('system.languages.home_redirect.include_route', true)) {
             $prefix = $config->get('system.languages.home_redirect.include_lang', true) ? $language->getLanguage() . '/' : '';
             $grav->redirect($prefix . Pages::getHomeRoute());
         } elseif ($config->get('system.languages.home_redirect.include_lang', true)) {
             $grav->redirect($language->getLanguage() . '/');
         }
     }
     // split the URL and params
     $bits = parse_url($uri);
     // process query string
     if (isset($bits['query'])) {
         $this->query = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
         $uri = $bits['path'];
     }
     // remove the extension if there is one set
     $parts = pathinfo($uri);
     // set the original basename
     $this->basename = $parts['basename'];
     $valid_page_types = implode('|', $config->get('system.pages.types'));
     if (preg_match("/\\.(" . $valid_page_types . ")\$/", $parts['basename'])) {
         $uri = rtrim(str_replace(DIRECTORY_SEPARATOR, DS, $parts['dirname']), DS) . '/' . $parts['filename'];
         $this->extension = $parts['extension'];
     }
     // set the new url
     $this->url = $this->root . $uri;
     $this->path = $uri;
     $this->content_path = trim(str_replace($this->base, '', $this->path), '/');
     if ($this->content_path != '') {
         $this->paths = explode('/', $this->content_path);
     }
 }
コード例 #12
0
 protected function inlineImage($excerpt)
 {
     if (preg_match($this->twig_link_regex, $excerpt['text'], $matches)) {
         $excerpt['text'] = str_replace($matches[1], '/', $excerpt['text']);
         $excerpt = parent::inlineImage($excerpt);
         $excerpt['element']['attributes']['src'] = $matches[1];
         $excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
         return $excerpt;
     } else {
         $excerpt['type'] = 'image';
         $excerpt = parent::inlineImage($excerpt);
     }
     // Some stuff we will need
     $actions = [];
     $media = null;
     // if this is an image
     if (isset($excerpt['element']['attributes']['src'])) {
         $alt = $excerpt['element']['attributes']['alt'] ?: '';
         $title = $excerpt['element']['attributes']['title'] ?: '';
         $class = isset($excerpt['element']['attributes']['class']) ? $excerpt['element']['attributes']['class'] : '';
         //get the url and parse it
         $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['src']));
         $this_host = isset($url['host']) && $url['host'] == $this->uri->host();
         // if there is no host set but there is a path, the file is local
         if ((!isset($url['host']) || $this_host) && isset($url['path'])) {
             $path_parts = pathinfo($url['path']);
             // get the local path to page media if possible
             if ($path_parts['dirname'] == $this->page->url(false, false, false)) {
                 // get the media objects for this page
                 $media = $this->page->media();
             } else {
                 // see if this is an external page to this one
                 $base_url = rtrim(self::getGrav()['base_url_relative'] . self::getGrav()['pages']->base(), '/');
                 $page_route = '/' . ltrim(str_replace($base_url, '', $path_parts['dirname']), '/');
                 $ext_page = $this->pages->dispatch($page_route, true);
                 if ($ext_page) {
                     $media = $ext_page->media();
                 }
             }
             // if there is a media file that matches the path referenced..
             if ($media && isset($media->all()[$path_parts['basename']])) {
                 // get the medium object
                 $medium = $media->all()[$path_parts['basename']];
                 // 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]) ? $parts[1] : null;
                         $carry[] = ['method' => $parts[0], 'params' => $value];
                         return $carry;
                     }, []);
                 }
                 // loop through actions for the image and call them
                 foreach ($actions as $action) {
                     $medium = call_user_func_array([$medium, $action['method']], explode(',', urldecode($action['params'])));
                 }
                 if (isset($url['fragment'])) {
                     $medium->urlHash($url['fragment']);
                 }
                 $excerpt['element'] = $medium->parseDownElement($title, $alt, $class, true);
             } else {
                 // not a current page media file, see if it needs converting to relative
                 $excerpt['element']['attributes']['src'] = Uri::buildUrl($url);
             }
         }
     }
     return $excerpt;
 }
コード例 #13
0
ファイル: Collection.php プロジェクト: miguelramos/grav
 /**
  * Reorder collection.
  *
  * @param string $by
  * @param string $dir
  * @param array  $manual
  * @return $this
  */
 public function order($by, $dir = 'asc', $manual = null)
 {
     $this->items = $this->pages->sortCollection($this, $by, $dir, $manual);
     return $this;
 }