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


PHP r::referer方法代码示例

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


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

示例1: routes

 /**
  * 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;
 }
开发者ID:kgchoy,项目名称:main-portfolio-website,代码行数:87,代码来源:kirby.php

示例2: last

 /**
  * Return the last url the user has been on if detectable
  *
  * @return string
  */
 public static function last()
 {
     return r::referer();
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:9,代码来源:url.php

示例3: routes

 /**
  * 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;
 }
开发者ID:biggtfish,项目名称:Clean-Blog-Kirby-Theme,代码行数:86,代码来源:kirby.php

示例4: testReferer

 public function testReferer()
 {
     $this->assertNull(r::referer());
 }
开发者ID:aoimedia,项目名称:kosmonautensofa,代码行数:4,代码来源:RTest.php


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