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


PHP Director::makeRelative方法代码示例

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


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

示例1: testRenderTemplatePlaceholder

 public function testRenderTemplatePlaceholder()
 {
     // Create page object
     $page = $this->objFromFixture('Page', 'page1');
     $templateTitle = 'template1';
     $templatePlaceHolder = '{{' . $templateTitle . '}}';
     // Assert: render page
     $this->assertContains($templatePlaceHolder, $page->Content());
     // Create template
     $template = $this->objFromFixture('ViewTemplate', $templateTitle);
     $templatePlaceHolder = '{{' . $template->Title . '}}';
     // Page disable template view
     $page->EnableViewTemplate = false;
     // Assert: render page without view template
     $this->assertContains($templatePlaceHolder, $page->Content());
     // Page enable template view
     $page->EnableViewTemplate = true;
     // Assert: render page with view template
     $this->assertNotContains($templatePlaceHolder, $page->Content());
     // Login admin
     $this->logInWithPermission('ADMIN');
     // Assert: Publish page
     $published = $page->doPublish();
     $this->assertTrue($published);
     // Assert: page visible to public with render view template
     Member::currentUser()->logOut();
     $response = Director::test(Director::makeRelative($page->Link()));
     $this->assertNotContains($templatePlaceHolder, $response->getBody());
     $this->assertContains($template->ViewTemplate, $response->getBody());
 }
开发者ID:helpfulrobot,项目名称:satrun77-viewtemplate,代码行数:30,代码来源:ViewTemplateTest.php

示例2: handleRequest

 /**
  * Process all incoming requests passed to this controller, checking
  * that the file exists and passing the file through if possible.
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     // Copied from Controller::handleRequest()
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $url = array_key_exists('url', $_GET) ? $_GET['url'] : $_SERVER['REQUEST_URI'];
     // remove any relative base URL and prefixed slash that get appended to the file path
     // e.g. /mysite/assets/test.txt should become assets/test.txt to match the Filename field on File record
     $url = Director::makeRelative(ltrim(str_replace(BASE_URL, '', $url), '/'));
     $file = File::find($url);
     if ($this->canDownloadFile($file)) {
         // If we're trying to access a resampled image.
         if (preg_match('/_resampled\\/[^-]+-/', $url)) {
             // File::find() will always return the original image, but we still want to serve the resampled version.
             $file = new Image();
             $file->Filename = $url;
         }
         $this->extend('onBeforeSendFile', $file);
         return $this->sendFile($file);
     } else {
         if ($file instanceof File) {
             // Permission failure
             Security::permissionFailure($this, 'You are not authorised to access this resource. Please log in.');
         } else {
             // File doesn't exist
             $this->response = new SS_HTTPResponse('File Not Found', 404);
         }
     }
     return $this->response;
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce-downloadableproduct,代码行数:37,代码来源:DownloadableFileController.php

示例3: format

 public function format($event)
 {
     $errno = $event['message']['errno'];
     $errstr = $event['message']['errstr'];
     $errfile = $event['message']['errfile'];
     $errline = $event['message']['errline'];
     $errcontext = $event['message']['errcontext'];
     switch ($event['priorityName']) {
         case 'ERR':
             $errtype = 'Error';
             break;
         case 'WARN':
             $errtype = 'Warning';
             break;
         case 'NOTICE':
             $errtype = 'Notice';
             break;
     }
     $urlSuffix = '';
     $relfile = Director::makeRelative($errfile);
     if ($relfile[0] == '/') {
         $relfile = substr($relfile, 1);
     }
     if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] && isset($_SERVER['REQUEST_URI'])) {
         $urlSuffix = " (http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']})";
     }
     return '[' . date('d-M-Y h:i:s') . "] {$errtype} at {$relfile} line {$errline}: {$errstr}{$urlSuffix}" . PHP_EOL;
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:28,代码来源:LogErrorFileFormatter.php

示例4: getPreviewThumbnail

 /**
  * Gets a thumbnail for this file given a size. If it's an Image,
  * it will render the actual file. If not, it will provide an icon based
  * on the extension.
  * @param  int $w The width of the image
  * @param  int $h The height of the image
  * @return Image_Cached
  */
 public function getPreviewThumbnail($w = null, $h = null)
 {
     if (!$w) {
         $w = $this->owner->config()->grid_thumbnail_width;
     }
     if (!$h) {
         $h = $this->owner->config()->grid_thumbnail_height;
     }
     if ($this->IsImage()) {
         return $this->owner->CroppedImage($w, $h);
     }
     $sizes = Config::inst()->forClass('FileAttachmentField')->icon_sizes;
     sort($sizes);
     foreach ($sizes as $size) {
         if ($w <= $size) {
             if ($this->owner instanceof Folder) {
                 $file = $this->getFilenameForType('_folder', $size);
             } else {
                 $file = $this->getFilenameForType($this->owner->getExtension(), $size);
             }
             if (!file_exists(BASE_PATH . '/' . $file)) {
                 $file = $this->getFilenameForType('_blank', $size);
             }
             return new Image_Cached(Director::makeRelative($file));
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-dropzone,代码行数:35,代码来源:DropzoneFile.php

示例5: rebuildCache

 /**
  * Rebuilds the static cache for the pages passed through via $urls
  * @param array $urls The URLs of pages to re-fetch and cache.
  */
 function rebuildCache($urls, $removeAll = true)
 {
     if (!is_array($urls)) {
         return;
     }
     // $urls must be an array
     if (!Director::is_cli()) {
         echo "<pre>\n";
     }
     echo "Rebuilding cache.\nNOTE: Please ensure that this page ends with 'Done!' - if not, then something may have gone wrong.\n\n";
     $page = singleton('Page');
     foreach ($urls as $i => $url) {
         $url = Director::makeRelative($url);
         if (substr($url, -1) == '/') {
             $url = substr($url, 0, -1);
         }
         $urls[$i] = $url;
     }
     $urls = array_unique($urls);
     if ($removeAll && file_exists("../cache")) {
         echo "Removing old cache... \n";
         flush();
         Filesystem::removeFolder("../cache", true);
         echo "done.\n\n";
     }
     echo "Republishing " . sizeof($urls) . " urls...\n\n";
     $page->publishPages($urls);
     echo "\n\n== Done! ==";
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:33,代码来源:RebuildStaticCacheTask.php

示例6: doPublish

 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  * @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
  * @param string $toStage Place to copy to. Must be a stage name.
  * @param boolean $createNewVersion Set this to true to create a new version number.  By default, the existing version number will be copied over.
  */
 function doPublish()
 {
     parent::doPublish();
     // Run the page (reset the theme, it might've been disabled by LeftAndMain::init())
     $oldTheme = SSViewer::current_theme();
     SSViewer::set_theme(SSViewer::current_custom_theme());
     $response = Director::test(Director::makeRelative($this->Link()));
     SSViewer::set_theme($oldTheme);
     $errorContent = $response->getBody();
     // Make the base tag dynamic.
     // $errorContent = preg_replace('/<base[^>]+href="' . str_replace('/','\\/', Director::absoluteBaseURL()) . '"[^>]*>/i', '<base href="$BaseURL" />', $errorContent);
     // Check we have an assets base directory, creating if it we don't
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH, 02775);
     }
     // if the page is published in a language other than default language,
     // write a specific language version of the HTML page
     $filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
     if ($fh = fopen($filePath, "w")) {
         fwrite($fh, $errorContent);
         fclose($fh);
     } else {
         $fileErrorText = sprintf(_t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"%s\" for writing. Please check file permissions."), $errorFile);
         FormResponse::status_message($fileErrorText, 'bad');
         FormResponse::respond();
         return;
     }
 }
开发者ID:Raiser,项目名称:Praktikum,代码行数:36,代码来源:ErrorPage.php

示例7: _write

 /**
  * Write the log message to the file path set
  * in this writer.
  */
 public function _write($event)
 {
     //Ignore Exceptions New Relic Catches these on it's own
     if (preg_match('/Uncaught ([A-Za-z]*)Exception: /', trim($errstr)) == true) {
         return;
     }
     $errno = $event['message']['errno'];
     $errstr = $event['message']['errstr'];
     $errfile = $event['message']['errfile'];
     $errline = $event['message']['errline'];
     $errcontext = $event['message']['errcontext'];
     switch ($event['priorityName']) {
         case 'ERR':
             $errtype = 'Error';
             break;
         case 'WARN':
             $errtype = 'Warning';
             break;
         case 'NOTICE':
             $errtype = 'Notice';
             break;
         default:
             $errtype = $event['priorityName'];
     }
     $relfile = Director::makeRelative($errfile);
     if ($relfile && $relfile[0] == '/') {
         $relfile = substr($relfile, 1);
     }
     //If it's not an exception notice the error
     newrelic_notice_error($errno, "[{$errtype}] {$errstr} in {$relfile} line {$errline}", $errfile, $errline, $errcontext);
 }
开发者ID:webbuilders-group,项目名称:silverstripe-new-relic,代码行数:35,代码来源:NewRelicErrorLogger.php

示例8: testCanViewProductGroupPage

 function testCanViewProductGroupPage()
 {
     $g1 = $this->objFromFixture('ProductGroup', 'g1');
     $g2 = $this->objFromFixture('ProductGroup', 'g2');
     $this->get(Director::makeRelative($g1->Link()));
     $this->get(Director::makeRelative($g2->Link()));
 }
开发者ID:riddler7,项目名称:silverstripe-ecommerce,代码行数:7,代码来源:EcommerceTest.php

示例9: _write

 /**
  * @param array $event
  */
 public function _write($event)
 {
     $debugbar = DebugBar::getDebugBar();
     if (!$debugbar) {
         return;
     }
     /* @var $messagesCollector DebugBar\DataCollector\MessagesCollector */
     $messagesCollector = $debugbar['messages'];
     if (!$messagesCollector) {
         return;
     }
     $level = $event['priorityName'];
     // Gather info
     if (isset($event['message']['errstr'])) {
         $str = $event['message']['errstr'];
         $file = $event['message']['errfile'];
         $line = $event['message']['errline'];
     } else {
         $str = $event['message']['function'];
         $file = $event['message']['file'];
         $line = isset($event['message']['line']) ? $event['message']['line'] : 0;
     }
     $relfile = Director::makeRelative($file);
     // Save message
     $message = "{$level} - {$str} ({$relfile}:{$line})";
     // Escape \ for proper js display
     $message = str_replace('\\', '\\\\', $message);
     $messagesCollector->addMessage($message, false);
 }
开发者ID:lekoala,项目名称:silverstripe-debugbar,代码行数:32,代码来源:DebugBarLogWriter.php

示例10: requireDefaultRecords

 /**
  * Create an {@link ErrorPage} for status code 503
  * 
  * @see UnderConstruction_Extension::onBeforeInit()
  * @see DataObjectDecorator::requireDefaultRecords()
  * @return Void
  */
 function requireDefaultRecords()
 {
     // Ensure that an assets path exists before we do any error page creation
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH);
     }
     $pageUnderConstructionErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '503'");
     $pageUnderConstructionErrorPageExists = $pageUnderConstructionErrorPage && $pageUnderConstructionErrorPage->exists() ? true : false;
     $pageUnderConstructionErrorPagePath = ErrorPage::get_filepath_for_errorcode(503);
     if (!($pageUnderConstructionErrorPageExists && file_exists($pageUnderConstructionErrorPagePath))) {
         if (!$pageUnderConstructionErrorPageExists) {
             $pageUnderConstructionErrorPage = new ErrorPage();
             $pageUnderConstructionErrorPage->ErrorCode = 503;
             $pageUnderConstructionErrorPage->Title = _t('UnderConstruction.TITLE', 'Under Construction');
             $pageUnderConstructionErrorPage->Content = _t('UnderConstruction.CONTENT', '<p>Sorry, this site is currently under construction.</p>');
             $pageUnderConstructionErrorPage->Status = 'New page';
             $pageUnderConstructionErrorPage->write();
             $pageUnderConstructionErrorPage->publish('Stage', 'Live');
         }
         // Ensure a static error page is created from latest error page content
         $response = Director::test(Director::makeRelative($pageUnderConstructionErrorPage->Link()));
         if ($fh = fopen($pageUnderConstructionErrorPagePath, 'w')) {
             $written = fwrite($fh, $response->getBody());
             fclose($fh);
         }
         if ($written) {
             DB::alteration_message('503 error page created', 'created');
         } else {
             DB::alteration_message(sprintf('503 error page could not be created at %s. Please check permissions', $pageUnderConstructionErrorPagePath), 'error');
         }
     }
 }
开发者ID:helpfulrobot,项目名称:frankmullenger-underconstruction,代码行数:39,代码来源:UnderConstruction.php

示例11: getSmileyDir

 public static function getSmileyDir()
 {
     $smileyDir = Director::makeRelative(realpath(dirname(__FILE__) . "/../images/smileys/"));
     $smileyDir = str_replace("\\", "/", $smileyDir);
     $smileyDir = Director::baseURL() . $smileyDir;
     return $smileyDir;
 }
开发者ID:helpfulrobot,项目名称:cheesesucker-guestbook,代码行数:7,代码来源:Smiley.php

示例12: FieldHolder

 /**
  * @param array $properties
  *
  * @return string - HTML
  */
 public function FieldHolder($properties = array())
 {
     $moduleDir = substr(Director::makeRelative(dirname(dirname(dirname(__FILE__)))), 1);
     Requirements::css($moduleDir . '/css/WidgetAreaEditor.css');
     Requirements::javascript($moduleDir . '/javascript/WidgetAreaEditor.js');
     return $this->renderWith("WidgetAreaEditor");
 }
开发者ID:JayDevlin,项目名称:silverstripe-widgets,代码行数:12,代码来源:WidgetAreaEditor.php

示例13: find_or_make

 /**
  * Find the given folder or create it both as {@link Folder} database records
  * and on the filesystem. If necessary, creates parent folders as well.
  * 
  * @param $folderPath string Absolute or relative path to the file.
  *  If path is relative, its interpreted relative to the "assets/" directory.
  * @return Folder
  */
 public static function find_or_make($folderPath)
 {
     // Create assets directory, if it is missing
     if (!file_exists(ASSETS_PATH)) {
         Filesystem::makeFolder(ASSETS_PATH);
     }
     $folderPath = trim(Director::makeRelative($folderPath));
     // replace leading and trailing slashes
     $folderPath = preg_replace('/^\\/?(.*)\\/?$/', '$1', $folderPath);
     $parts = explode("/", $folderPath);
     $parentID = 0;
     $item = null;
     foreach ($parts as $part) {
         if (!$part) {
             continue;
         }
         // happens for paths with a trailing slash
         $item = DataObject::get_one("Folder", sprintf("\"Name\" = '%s' AND \"ParentID\" = %d", Convert::raw2sql($part), (int) $parentID));
         if (!$item) {
             $item = new Folder();
             $item->ParentID = $parentID;
             $item->Name = $part;
             $item->Title = $part;
             $item->write();
         }
         if (!file_exists($item->getFullPath())) {
             Filesystem::makeFolder($item->getFullPath());
         }
         $parentID = $item->ID;
     }
     return $item;
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:40,代码来源:Folder.php

示例14: GlobalNav

 /**
  * @param   $key The nav key, e.g. "doc", "userhelp"
  * @return HTMLText
  */
 public static function GlobalNav($key)
 {
     $baseURL = GlobalNavSiteTreeExtension::get_toolbar_baseurl();
     Requirements::css(Controller::join_links($baseURL, Config::inst()->get('GlobalNav', 'css_path')));
     // If this method haven't been called before, get the toolbar and cache it
     if (self::$global_nav_html === null) {
         // Set the default to empty
         self::$global_nav_html = '';
         // Prevent recursion from happening
         if (empty($_GET['globaltoolbar'])) {
             $host = GlobalNavSiteTreeExtension::get_toolbar_hostname();
             $path = Director::makeRelative(GlobalNavSiteTreeExtension::get_navbar_filename($key));
             if (Config::inst()->get('GlobalNav', 'use_localhost')) {
                 self::$global_nav_html = file_get_contents(BASE_PATH . $path);
             } else {
                 $url = Controller::join_links($baseURL, $path, '?globaltoolbar=true');
                 $connectionTimeout = Config::inst()->get('GlobalNavTemplateProvider', 'connection_timeout');
                 $transferTimeout = Config::inst()->get('GlobalNavTemplateProvider', 'transfer_timeout');
                 // Get the HTML and cache it
                 self::$global_nav_html = self::curl_call($url, $connectionTimeout, $transferTimeout);
             }
         }
     }
     $html = DBField::create_field('HTMLText', self::$global_nav_html);
     $html->setOptions(array('shortcodes' => false));
     return $html;
 }
开发者ID:newleeland,项目名称:silverstripe-globaltoolbar,代码行数:31,代码来源:GlobalNavTemplateProvider.php

示例15: browse

	/**
	 * Browse all enabled test cases in the environment
	 */
	function browse() {
		self::$default_reporter->writeHeader();
		self::$default_reporter->writeInfo('Available Tests', false);
		if(Director::is_cli()) {
			$tests = ClassInfo::subclassesFor('SapphireTest');
			$relativeLink = Director::makeRelative($this->Link());
			echo "sake {$relativeLink}all: Run all " . count($tests) . " tests\n";
			echo "sake {$relativeLink}coverage: Runs all tests and make test coverage report\n";
			foreach ($tests as $test) {
				echo "sake {$relativeLink}$test: Run $test\n";
			}
		} else {
			echo '<div class="trace">';
			$tests = ClassInfo::subclassesFor('SapphireTest');
			asort($tests);
			echo "<h3><a href=\"" . $this->Link() . "all\">Run all " . count($tests) . " tests</a></h3>";
			echo "<h3><a href=\"" . $this->Link() . "coverage\">Runs all tests and make test coverage report</a></h3>";
			echo "<hr />";
			foreach ($tests as $test) {
				echo "<h3><a href=\"" . $this->Link() . "$test\">Run $test</a></h3>";
			}
			echo '</div>';
		}
		
		self::$default_reporter->writeFooter();
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:29,代码来源:TestRunner.php


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