public function testXhtmltagReplacement()
    {
        $tmpl1 = '<?xml version="1.0" encoding="UTF-8"?>
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html>
				<head><% base_tag %></head>
				<body>
				<form action="#">
					<select>
							<option>aa</option>
							<option selected = "selected">bb</option>
							<option selected="selected">cc</option>
							<option class="foo" selected>dd</option>
							<option>ee</option>
							<option selected value="">ll</option>
					</select>
					<input type="checkbox">ff
					<input type="checkbox" checked = "checked">gg
					<input type="checkbox" checked="checked">hh
					<input class="bar" type="checkbox" checked>ii
					<input type="checkbox" checked class="foo">jj
					<input type="submit">
				</form>
				<body>
			</html>';
        // Check that the content negotiator converts to the equally legal formats
        $negotiator = new ContentNegotiator();
        $response = new SS_HTTPResponse($this->render($tmpl1));
        $negotiator->xhtml($response);
        ////////////////////////
        // XHTML select options
        ////////////////////////
        $this->assertRegExp('/<option>aa<\\/option>/', $response->getBody());
        $this->assertRegExp('/<option selected = "selected">bb<\\/option>/', $response->getBody());
        $this->assertRegExp('/<option selected="selected">cc<\\/option>/', $response->getBody());
        // Just transform this
        $this->assertRegExp('/<option class="foo" selected="selected">dd<\\/option>/', $response->getBody());
        $this->assertRegExp('/<option selected="selected" value="">ll<\\/option>/', $response->getBody());
        ////////////////////////////////////////////////
        // XHTML checkbox options + XHTML input closure
        ////////////////////////////////////////////////
        $this->assertRegExp('/<input type="checkbox"\\/>ff/', $response->getBody());
        $this->assertRegExp('/<input type="checkbox" checked = "checked"\\/>g/', $response->getBody());
        $this->assertRegExp('/<input type="checkbox" checked="checked"\\/>hh/', $response->getBody());
        // Just transform this
        $this->assertRegExp('/<input class="bar" type="checkbox" checked="checked"\\/>ii/', $response->getBody());
        $this->assertRegExp('/<input type="checkbox" checked="checked" class="foo"\\/>jj/', $response->getBody());
    }
	public function index() {
		ContentNegotiator::disable();
		BasicAuth::disable();
		$request_count = count($_REQUEST);
		$get_count = count($_GET);
		$post_count = count($_POST);
		$request = '';
		foreach ($_REQUEST as $key=>$value) {
			$request .= "\t\t<request_item name=\"$key\">$value</request_item>\n";
		}
		$get = '';
		foreach ($_GET as $key => $value) {
			$get .= "\t\t<get_item name=\"$key\">$value</get_item>\n";
		}
		$post = '';
		foreach ($_POST as $key => $value) {
			$post .= "\t\t<post_item name=\"$key\">$value</post_item>\n";
		}
		$out = <<<XML
<?xml version="1.0"?>
<test>
	<request count="$request_count">
$request	</request>
	<get count="$get_count">
$get	</get>
	<post count="$post_count">
$post	</post>
</test>
XML;
		header('Content-type: text/xml');
		echo $out;
	}
 /**
  * Handles incoming requests to the kapost service
  */
 public function index()
 {
     //If the request is not a post request 404
     if (!$this->request->isPOST()) {
         return ErrorPage::response_for(404);
     }
     //If the request is not the kapost user agent 404
     if (self::config()->check_user_agent == true && $this->request->getHeader('User-Agent') != 'Kapost XMLRPC::Client') {
         return ErrorPage::response_for(404);
     }
     $methods = array_fill_keys($this->exposed_methods, array('function' => array($this, 'handleRPCMethod')));
     //Disable Content Negotiator and send the text/xml header (which kapost expects)
     ContentNegotiator::config()->enabled = false;
     $this->response->addHeader('Content-Type', 'text/xml');
     $server = new xmlrpc_server($methods, false);
     $server->compress_response = true;
     if (Director::isDev()) {
         $server->setDebug(3);
         //Base 64 encoded debug information is included in the response
         $server->exception_handling = 2;
         //Exception's sent to the client
     }
     //Force the internal encoding of the XMLRPC library to utf-8
     $GLOBALS['xmlrpc_internalencoding'] = self::config()->database_charset;
     return $server->service($this->request->getBody(), true);
 }
 /**
  * Refresh the list of attached files
  *
  * @return SSViewer
  */
 public function refresh()
 {
     ContentNegotiator::disable();
     $count = 0;
     $before = is_array($this->Value()) ? sizeof($this->Value()) : 0;
     if (isset($_REQUEST['FileIDs'])) {
         $ids = explode(",", $_REQUEST['FileIDs']);
         if (is_array($ids)) {
             $this->setValue($ids);
             $count = sizeof($ids) - $before;
         }
     }
     return Convert::array2json(array('html' => $this->renderWith('AttachedFiles'), 'success' => sprintf(_t('Uploadify.SUCCESSFULADDMULTI', 'Added files successfully.'), $count)));
 }
 /**
  * Handles incoming requests to the kapost service
  */
 public function index()
 {
     //If the request is not a post request 404
     if (!$this->request->isPOST()) {
         return ErrorPage::response_for(404);
     }
     //If the request is not the kapost user agent 404
     if (self::config()->check_user_agent == true && $this->request->getHeader('User-Agent') != 'Kapost XMLRPC::Client') {
         return ErrorPage::response_for(404);
     }
     $methods = array_fill_keys($this->exposed_methods, array('function' => array($this, 'handleRPCMethod')));
     //Disable Content Negotiator and send the text/xml header (which kapost expects)
     ContentNegotiator::config()->enabled = false;
     $this->response->addHeader('Content-Type', 'text/xml');
     $server = new xmlrpc_server($methods, false);
     $server->compress_response = true;
     if (Director::isDev()) {
         $server->setDebug(3);
         //Base 64 encoded debug information is included in the response
     }
     //Tell XML-RPC to re-throw the exception rather than trap it so we can allow the SilverStripe's normal error handling along side sending the xmlrpc response
     $server->exception_handling = 2;
     //Force the internal encoding of the XMLRPC library to utf-8
     $GLOBALS['xmlrpc_internalencoding'] = self::config()->database_charset;
     try {
         return $server->service($this->request->getBody(), true);
     } catch (Exception $e) {
         //Call on SS_Log to log the error
         SS_Log::log($e, SS_Log::ERR);
         //Allow exceptions to handle the response
         $results = $this->extend('onException', $e);
         if ($results && is_array($results)) {
             $results = array_filter($results, function ($v) {
                 return !is_null($v) && $v instanceof xmlrpcresp;
             });
             if (count($results) > 0) {
                 $this->generateErrorResponse($server, array_shift($results));
             }
         }
         //If we're in dev mode relay the actual message to the client
         if (Director::isDev()) {
             $response = new xmlrpcresp(0, $e->getCode() + 100, _t('KapostService.ERROR_MESSAGE', '_{message} in {file} line {line_number}', array('message' => $e->getMessage(), 'file' => $e->getFile(), 'line_number' => $e->getLine())));
         } else {
             $response = new xmlrpcresp(0, 17, _t('KapostService.SERVER_ERROR', '_Internal server error'));
         }
         return $this->generateErrorResponse($server, $response);
     }
 }
 public function MetaTags($includeTitle = true)
 {
     $customFields = array();
     if ($includeTitle === true || $includeTitle == 'true') {
         $customFields['AddHeaderTitle'] = true;
     }
     $customFields['Charset'] = ContentNegotiator::get_encoding();
     if (Permission::check('CMS_ACCESS_CMSMain') && in_array('CMSPreviewable', class_implements($this->owner->data())) && !$this->owner->data() instanceof ErrorPage && $this->owner->data()->ID > 0) {
         $customFields['CMSAccess'] = 1;
         $customFields['XPageID'] = $this->owner->data()->ID;
         $customFields['XCMSEditLink'] = $this->owner->data()->CMSEditLink();
     }
     $metadata = $this->owner->renderWith('MetaTags', $customFields);
     /* strip blank lines */
     $metadata = preg_replace('/(^[\\r\\n]*|[\\r\\n]+)[\\s\\t]*[\\r\\n]+/', "\n", $metadata);
     /* add tabs to neaten code */
     $metadata = preg_replace('/\\r?\\n</', "\n\t<", $metadata);
     return trim($metadata);
 }
 /**
  * Refresh the attached files box. This method may receive a list of IDs,
  * but it will only accept the last one in the list. 
  *
  * @param SS_HTTPRequest $request
  * @return SSViewer
  */
 public function refresh(SS_HTTPRequest $request)
 {
     ContentNegotiator::disable();
     if ($id = $request->requestVar('FileIDs')) {
         if (!is_numeric($id)) {
             $arr = explode(',', $id);
             if (is_array($arr)) {
                 $id = end($arr);
             }
         }
         $this->setValue($id);
         $name = null;
         if (is_numeric($id)) {
             if ($file = DataObject::get_by_id($this->baseFileClass, Convert::raw2sql($id))) {
                 $name = $file->Name;
             }
         }
     }
     return Convert::array2json(array('html' => $this->renderWith('AttachedFiles'), 'success' => sprintf(_t('Uploadify.SUCCESSFULADDSINGLE', 'Added file "%s" successfully.'), $name)));
 }
Exemplo n.º 8
0
 /**
  * Get all content as a javascript-compatible string (only if there is an Ajax-Request present).
  * Falls back to {non_ajax_content}, {redirect_url} or Director::redirectBack() (in this order).
  * 
  * @return string
  */
 static function respond()
 {
     // we don't want non-ajax calls to receive javascript
     if (isset($_REQUEST['forcehtml'])) {
         return self::$non_ajax_content;
     } else {
         if (isset($_REQUEST['forceajax']) || Director::is_ajax()) {
             ContentNegotiator::disable();
             // TODO figure out a way to stay backwards-compatible with Ajax.Evaluator and still use the automatic evaluating of Prototype
             //header("Content-type: text/javascript");
             return self::get_javascript();
         } elseif (!empty(self::$non_ajax_content)) {
             return self::$non_ajax_content;
         } elseif (!empty(self::$redirect_url)) {
             Director::redirect(self::$redirect_url);
             return null;
         } else {
             Director::redirectBack();
             return null;
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Return the title, description, keywords and language metatags.
  * 
  * @todo Move <title> tag in separate getter for easier customization and more obvious usage
  * 
  * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating
  * @param boolean $includeTitle Show default <title>-tag, set to false for
  *                              custom templating
  * @return string The XHTML metatags
  */
 public function MetaTags($includeTitle = true)
 {
     $tags = "";
     if ($includeTitle === true || $includeTitle == 'true') {
         $tags .= "<title>" . Convert::raw2xml($this->MetaTitle ? $this->MetaTitle : $this->Title) . "</title>\n";
     }
     $tags .= "<meta name=\"generator\" content=\"SilverStripe - http://silverstripe.org\" />\n";
     $charset = ContentNegotiator::get_encoding();
     $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset={$charset}\" />\n";
     if ($this->MetaKeywords) {
         $tags .= "<meta name=\"keywords\" content=\"" . Convert::raw2att($this->MetaKeywords) . "\" />\n";
     }
     if ($this->MetaDescription) {
         $tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
     }
     if ($this->ExtraMeta) {
         $tags .= $this->ExtraMeta . "\n";
     }
     if (Permission::check('CMS_ACCESS_CMSMain')) {
         $tags .= "<meta name='x-page-id' content='{$this->ID}' />\n";
     }
     $this->extend('MetaTags', $tags);
     return $tags;
 }
Exemplo n.º 10
0
 function run($requestParams)
 {
     if (isset($_GET['debug_profile'])) {
         Profiler::mark("Controller", "run");
     }
     $this->pushCurrent();
     $this->response = new HTTPResponse();
     $this->requestParams = $requestParams;
     $this->action = isset($this->urlParams['Action']) ? str_replace("-", "_", $this->urlParams['Action']) : "";
     if (!$this->action) {
         $this->action = 'index';
     }
     // Check security on the controller
     if (!$this->checkAccessAction($this->action)) {
         user_error("Disallowed action: '{$this->action}' on controller '{$this->class}'", E_USER_ERROR);
     }
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init().  Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         $this->popCurrent();
         return $this->response;
     }
     // Look at the action variables for forms
     $funcName = null;
     foreach ($this->requestParams as $paramName => $paramVal) {
         if (substr($paramName, 0, 7) == 'action_') {
             // Cleanup action_, _x and _y from image fields
             $funcName = preg_replace(array('/^action_/', '/_x$|_y$/'), '', $paramName);
             break;
         }
     }
     // Form handler
     if (isset($this->requestParams['executeForm']) && is_string($this->requestParams['executeForm'])) {
         if (isset($funcName)) {
             Form::set_current_action($funcName);
         }
         // Get the appropraite ocntroller: sometimes we want to get a form from another controller
         if (isset($this->requestParams['formController'])) {
             $formController = Director::getControllerForURL($this->requestParams['formController']);
             while (is_a($formController, 'NestedController')) {
                 $formController = $formController->getNestedController();
             }
         } else {
             $formController = $this;
         }
         // Create the form object
         $form = $formController;
         $formObjParts = explode('.', $this->requestParams['executeForm']);
         foreach ($formObjParts as $formMethod) {
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("Calling {$formMethod}", "on {$form->class}");
             }
             $form = $form->{$formMethod}();
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("Calling {$formMethod}", "on {$form->class}");
             }
             if (!$form) {
                 break;
             }
             //user_error("Form method '" . $this->requestParams['executeForm'] . "' returns null in controller class '$this->class' ($_SERVER[REQUEST_URI])", E_USER_ERROR);
         }
         // Populate the form
         if (isset($_GET['debug_profile'])) {
             Profiler::mark("Controller", "populate form");
         }
         if ($form) {
             $form->loadDataFrom($this->requestParams, true);
             // disregard validation if a single field is called
             if (!isset($_REQUEST['action_callfieldmethod'])) {
                 $valid = $form->beforeProcessing();
                 if (!$valid) {
                     $this->popCurrent();
                     return $this->response;
                 }
             } else {
                 $fieldcaller = $form->dataFieldByName($requestParams['fieldName']);
                 if (is_a($fieldcaller, "TableListField")) {
                     if ($fieldcaller->hasMethod('php')) {
                         $valid = $fieldcaller->php($requestParams);
                         if (!$valid) {
                             exit;
                         }
                     }
                 }
             }
             // If the action wasnt' set, choose the default on the form.
             if (!isset($funcName) && ($defaultAction = $form->defaultAction())) {
                 $funcName = $defaultAction->actionName();
             }
             if (isset($funcName)) {
                 $form->setButtonClicked($funcName);
             }
         } else {
             user_error("No form (" . Session::get('CMSMain.currentPage') . ") returned by {$formController->class}->{$_REQUEST['executeForm']}", E_USER_WARNING);
         }
         if (isset($_GET['debug_profile'])) {
             Profiler::unmark("Controller", "populate form");
         }
         if (!isset($funcName)) {
             user_error("No action button has been clicked in this form executon, and no default has been allowed", E_USER_ERROR);
         }
         // Protection against CSRF attacks
         if ($form->securityTokenEnabled()) {
             $securityID = Session::get('SecurityID');
             if (!$securityID || !isset($this->requestParams['SecurityID']) || $securityID != $this->requestParams['SecurityID']) {
                 // Don't show error on live sites, as spammers create a million of these
                 if (!Director::isLive()) {
                     trigger_error("Security ID doesn't match, possible CRSF attack.", E_USER_ERROR);
                 } else {
                     die;
                 }
             }
         }
         // First, try a handler method on the controller
         if ($this->hasMethod($funcName) || !$form) {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Found function {$funcName} on the controller");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("{$this->class}::{$funcName} (controller action)");
             }
             $result = $this->{$funcName}($this->requestParams, $form);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("{$this->class}::{$funcName} (controller action)");
             }
             // Otherwise, try a handler method on the form object
         } else {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Found function {$funcName} on the form object");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("{$form->class}::{$funcName} (form action)");
             }
             $result = $form->{$funcName}($this->requestParams, $form);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("{$form->class}::{$funcName} (form action)");
             }
         }
         // Normal action
     } else {
         if (!isset($funcName)) {
             $funcName = $this->action;
         }
         if ($this->hasMethod($funcName)) {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Found function {$funcName} on the {$this->class} controller");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("{$this->class}::{$funcName} (controller action)");
             }
             $result = $this->{$funcName}($this->urlParams);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("{$this->class}::{$funcName} (controller action)");
             }
         } else {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Running default action for {$funcName} on the {$this->class} controller");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("Controller::defaultAction({$funcName})");
             }
             $result = $this->defaultAction($funcName, $this->urlParams);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("Controller::defaultAction({$funcName})");
             }
         }
     }
     // If your controller function returns an array, then add that data to the
     // default template
     if (is_array($result)) {
         $extended = $this->customise($result);
         $viewer = $this->getViewer($funcName);
         $result = $viewer->process($extended);
     }
     $this->response->setBody($result);
     if ($result) {
         ContentNegotiator::process($this->response);
     }
     // Set up HTTP cache headers
     HTTP::add_cache_headers($this->response);
     if (isset($_GET['debug_profile'])) {
         Profiler::unmark("Controller", "run");
     }
     $this->popCurrent();
     return $this->response;
 }
 function SetUp()
 {
     parent::SetUp();
     self::$page = new UnsubscribeController();
     ContentNegotiator::disable();
 }
Exemplo n.º 12
0
	/**
	 * Handles HTTP requests.
	 * 
	 * If you are going to overload handleRequest, make sure that you start the method with $this->pushCurrent()
	 * and end the method with $this->popCurrent().  Failure to do this will create weird session errors.
	 * 
	 * @param $request The {@link HTTPRequest} object that is responsible for distributing request parsing.
	 */
	function handleRequest(HTTPRequest $request) {
		if(!$request) user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
		
		$this->pushCurrent();
		$this->urlParams = $request->allParams();
		$this->request = $request;
		$this->response = new HTTPResponse();

		// Init
		$this->baseInitCalled = false;	
		$this->init();
		if(!$this->baseInitCalled) user_error("init() method on class '$this->class' doesn't call Controller::init().  Make sure that you have parent::init() included.", E_USER_WARNING);

		// If we had a redirection or something, halt processing.
		if($this->response->isFinished()) {
			$this->popCurrent();
			return $this->response;
		}

		$body = parent::handleRequest($request);
		if($body instanceof HTTPResponse) {
			if(isset($_REQUEST['debug_request'])) Debug::message("Request handler returned HTTPResponse object to $this->class controller; returning it without modification.");
			$this->response = $body;
			
		} else {
			if(is_object($body)) {
				if(isset($_REQUEST['debug_request'])) Debug::message("Request handler $body->class object to $this->class controller;, rendering with template returned by $body->class::getViewer()");
			   $body = $body->getViewer($request->latestParam('Action'))->process($body);
			}
			
			$this->response->setBody($body);
		}


		ContentNegotiator::process($this->response);
		HTTP::add_cache_headers($this->response);

		$this->popCurrent();
		return $this->response;
	}
 /**
  * Generate custom metatags to display on the DataObject Item page
  */
 public function MetaTags($includeTitle = true)
 {
     $tags = "";
     if ($includeTitle === true || $includeTitle == 'true') {
         $tags .= "<title>" . Convert::raw2xml($this->MetaTitle ? $this->MetaTitle : $this->Title) . "</title>\n";
     }
     $tags .= "<meta name=\"generator\" content=\"SilverStripe - http://silverstripe.org\" />\n";
     $charset = ContentNegotiator::get_encoding();
     $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset={$charset}\" />\n";
     if ($this->MetaDescription) {
         $tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
     }
     $this->extend('MetaTags', $tags);
     return $tags;
 }
Exemplo n.º 14
0
 static function disable()
 {
     self::$enabled = false;
 }
Exemplo n.º 15
0
    public function invalid()
    {
        ContentNegotiator::disable();
        BasicAuth::protect_entire_site(false);
        $out = <<<XML
<?xml version="1.0"?>
<test>
\t<fail><invalid>
</test>
XML;
        header('Content-type: text/xml');
        echo $out;
    }
Exemplo n.º 16
0
 /**
  * This handler acts as the switchboard for the controller.
  * Since no $Action url-param is set, all requests are sent here.
  */
 function index()
 {
     ContentNegotiator::disable();
     if (!isset($this->urlParams['ClassName'])) {
         return $this->notFound();
     }
     $className = $this->urlParams['ClassName'];
     $id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : null;
     $relation = isset($this->urlParams['Relation']) ? $this->urlParams['Relation'] : null;
     // Check input formats
     if (!class_exists($className)) {
         return $this->notFound();
     }
     if ($id && !is_numeric($id)) {
         return $this->notFound();
     }
     if ($relation && !preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $relation)) {
         return $this->notFound();
     }
     // if api access is disabled, don't proceed
     $apiAccess = singleton($className)->stat('api_access');
     if (!$apiAccess) {
         return $this->permissionFailure();
     }
     // authenticate through HTTP BasicAuth
     $this->member = $this->authenticate();
     // handle different HTTP verbs
     if ($this->request->isGET() || $this->request->isHEAD()) {
         return $this->getHandler($className, $id, $relation);
     }
     if ($this->request->isPOST()) {
         return $this->postHandler($className, $id, $relation);
     }
     if ($this->request->isPUT()) {
         return $this->putHandler($className, $id, $relation);
     }
     if ($this->request->isDELETE()) {
         return $this->deleteHandler($className, $id, $relation);
     }
     // if no HTTP verb matches, return error
     return $this->methodNotAllowed();
 }
Exemplo n.º 17
0
	/**
	 * Return the title, description, keywords and language metatags.
	 * 
	 * @todo Move <title> tag in separate getter for easier customization and more obvious usage
	 * 
	 * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating
	 * @param boolean $includeTitle Show default <title>-tag, set to false for
	 *                              custom templating
	 * @return string The XHTML metatags
	 */
	public function MetaTags($includeTitle = true) {
		$tags = "";
		if($includeTitle === true || $includeTitle == 'true') {
			$tags .= "<title>" . Convert::raw2xml(($this->MetaTitle)
				? $this->MetaTitle
				: $this->Title) . "</title>\n";
		}

		$tags .= "<meta name=\"generator\" content=\"SilverStripe - http://silverstripe.org\" />\n";

		$charset = ContentNegotiator::get_encoding();
		$tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\" />\n";
		if($this->MetaKeywords) {
			$tags .= "<meta name=\"keywords\" content=\"" . Convert::raw2att($this->MetaKeywords) . "\" />\n";
		}
		if($this->MetaDescription) {
			$tags .= "<meta name=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
		}
		if($this->ExtraMeta) { 
			$tags .= $this->ExtraMeta . "\n";
		} 
		
		if(Permission::check('CMS_ACCESS_CMSMain') && in_array('CMSPreviewable', class_implements($this))) {
			$tags .= "<meta name=\"x-page-id\" content=\"{$this->ID}\" />\n";
			$tags .= "<meta name=\"x-cms-edit-link\" content=\"" . $this->CMSEditLink() . "\" />\n";
		}

		$this->extend('MetaTags', $tags);

		return $tags;
	}
Exemplo n.º 18
0
 public function handleRequest($request)
 {
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->pushCurrent();
     if ($request->getUrl() == 'Paste') {
         $this->submitPaste($request->postVars());
     }
     $paste = $this->getCurrentPaste();
     $id = trim($this->request->getVar('url'), '/');
     if (strpos($id, '/') !== FALSE) {
         list($id, $func, $view) = explode('/', $id) + array('', '', '');
         $func = DataObject::get_one('PHPVersion', 'FuncName = \'' . Convert::raw2sql($func) . '\'');
     }
     if (!empty($func)) {
         $this->response->setBody($func->executePaste($paste->Filename, $view));
     } else {
         $this->response->setBody($paste->renderWith(array('Paste', 'Paste')));
     }
     ContentNegotiator::process($this->response);
     $this->popCurrent();
     return $this->response;
 }
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->setDataModel($model);
     // Find our action or set to index if not found
     $action = $this->request->param("Action");
     if (!$action) {
         $action = "index";
     }
     $result = $this->{$action}($request);
     // Try to determine what response we are dealing with
     if ($result instanceof SS_HTTPResponse) {
         $this->response = $result;
     } else {
         $this->response = new SS_HTTPResponse();
         $this->response->setBody($result);
     }
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         return $this->response;
     }
     ContentNegotiator::process($this->response);
     HTTP::add_cache_headers($this->response);
     return $this->response;
 }
Exemplo n.º 20
0
 /**
  * Prepare the response (we can receive an assortment of response types (strings/objects/HTTPResponses) and
  * changes the controller response object appropriately
  *
  * @param SS_HTTPResponse|Object $response
  */
 protected function prepareResponse($response)
 {
     if ($response instanceof SS_HTTPResponse) {
         if (isset($_REQUEST['debug_request'])) {
             Debug::message("Request handler returned SS_HTTPResponse object to {$this->class} controller;" . "returning it without modification.");
         }
         $this->setResponse($response);
     } else {
         if ($response instanceof Object && $response->hasMethod('getViewer')) {
             if (isset($_REQUEST['debug_request'])) {
                 Debug::message("Request handler {$response->class} object to {$this->class} controller;" . "rendering with template returned by {$response->class}::getViewer()");
             }
             $response = $response->getViewer($this->getAction())->process($response);
         }
         $this->getResponse()->setbody($response);
     }
     //deal with content if appropriate
     ContentNegotiator::process($this->getResponse());
     //add cache headers
     HTTP::add_cache_headers($this->getResponse());
 }
Exemplo n.º 21
0
	/**
	 * Return the title, description, keywords and language metatags.
	 * 
	 * @todo Move <title> tag in separate getter for easier customization and more obvious usage
	 * 
	 * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating
	 * @param boolean $includeTitle Show default <title>-tag, set to false for
	 *                              custom templating
	 * @return string The XHTML metatags
	 */
	public function MetaTags($includeTitle = true) {
		$tags = "";
		if($includeTitle === true || $includeTitle == 'true') {
			$tags .= "<title>" . Convert::raw2xml(($this->MetaTitle)
				? $this->MetaTitle
				: $this->Title) . "</title>\n";
		}
		$version = new SapphireInfo();

		$tags .= "<meta name=\"generator\" http-equiv=\"generator\" content=\"SilverStripe ". $version->Version() ." - http://www.silverstripe.com\" />\n";

		$charset = ContentNegotiator::get_encoding();
		$tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\" />\n";
		if($this->MetaKeywords) {
			$tags .= "<meta name=\"keywords\" http-equiv=\"keywords\" content=\"" .
				Convert::raw2att($this->MetaKeywords) . "\" />\n";
		}
		if($this->MetaDescription) {
			$tags .= "<meta name=\"description\" http-equiv=\"description\" content=\"" .
				Convert::raw2att($this->MetaDescription) . "\" />\n";
		}
		if($this->ExtraMeta) { 
			$tags .= $this->ExtraMeta . "\n";
		} 
		$tags .= "<meta http-equiv=\"Content-Language\" content=\"". Translatable::current_lang() ."\"/>\n";
		
		// DEPRECATED 2.3: Use MetaTags
		$this->extend('updateMetaTags', $tags);
		
		$this->extend('MetaTags', $tags);

		return $tags;
	}
Exemplo n.º 22
0
 /**
  * Return the title, description, keywords and language metatags.
  * 
  * @todo Move <title> tag in separate getter for easier customization and more obvious usage
  * 
  * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating
  * @param boolean $includeTitle Show default <title>-tag, set to false for
  *                              custom templating
  * @return string The XHTML metatags
  */
 public function MetaTags($includeTitle = true)
 {
     $tags = "";
     if ($includeTitle === true || $includeTitle == 'true') {
         $tags .= "<title>" . Convert::raw2xml($this->MetaTitle ? $this->MetaTitle : $this->Title) . "</title>\n";
     }
     $version = new SapphireInfo();
     $tags .= "<meta name=\"generator\" http-equiv=\"generator\" content=\"SilverStripe - http://www.silverstripe.com\" />\n";
     $charset = ContentNegotiator::get_encoding();
     $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset={$charset}\" />\n";
     if ($this->MetaKeywords) {
         $tags .= "<meta name=\"keywords\" http-equiv=\"keywords\" content=\"" . Convert::raw2att($this->MetaKeywords) . "\" />\n";
     }
     if ($this->MetaDescription) {
         $tags .= "<meta name=\"description\" http-equiv=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
     }
     if ($this->ExtraMeta) {
         $tags .= $this->ExtraMeta . "\n";
     }
     // get the "long" lang name suitable for the HTTP content-language flag (with hyphens instead of underscores)
     $currentLang = $this->hasExtension('Translatable') ? Translatable::get_current_locale() : i18n::get_locale();
     $tags .= "<meta http-equiv=\"Content-Language\" content=\"" . i18n::convert_rfc1766($currentLang) . "\"/>\n";
     // DEPRECATED 2.3: Use MetaTags
     $this->extend('updateMetaTags', $tags);
     $this->extend('MetaTags', $tags);
     return $tags;
 }
Exemplo n.º 23
0
	function wsdl() {
		ContentNegotiator::disable();
		header("Content-type: text/xml");
		return array();
	}
Exemplo n.º 24
0
 function index($url)
 {
     if (self::$enabled) {
         SSViewer::set_source_file_comments(false);
         // We need to override the default content-type
         ContentNegotiator::disable();
         $this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
         // But we want to still render.
         return array();
     } else {
         return new HTTPResponse('Not allowed', 405);
     }
 }
Exemplo n.º 25
0
    public function testBaseTagGeneration()
    {
        // XHTML wil have a closed base tag
        $tmpl1 = '<?xml version="1.0" encoding="UTF-8"?>
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
			<html>
				<head><% base_tag %></head>
				<body><p>test</p><body>
			</html>';
        $this->assertRegExp('/<head><base href=".*" \\/><\\/head>/', $this->render($tmpl1));
        // HTML4 and 5 will only have it for IE
        $tmpl2 = '<!DOCTYPE html>
			<html>
				<head><% base_tag %></head>
				<body><p>test</p><body>
			</html>';
        $this->assertRegExp('/<head><base href=".*"><!--\\[if lte IE 6\\]><\\/base><!\\[endif\\]--><\\/head>/', $this->render($tmpl2));
        $tmpl3 = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
			<html>
				<head><% base_tag %></head>
				<body><p>test</p><body>
			</html>';
        $this->assertRegExp('/<head><base href=".*"><!--\\[if lte IE 6\\]><\\/base><!\\[endif\\]--><\\/head>/', $this->render($tmpl3));
        // Check that the content negotiator converts to the equally legal formats
        $negotiator = new ContentNegotiator();
        $response = new SS_HTTPResponse($this->render($tmpl1));
        $negotiator->html($response);
        $this->assertRegExp('/<head><base href=".*"><!--\\[if lte IE 6\\]><\\/base><!\\[endif\\]--><\\/head>/', $response->getBody());
        $response = new SS_HTTPResponse($this->render($tmpl1));
        $negotiator->xhtml($response);
        $this->assertRegExp('/<head><base href=".*" \\/><\\/head>/', $response->getBody());
    }
Exemplo n.º 26
0
 static function disable()
 {
     self::$disabled = true;
 }
Exemplo n.º 27
0
 /**
  * Return the title, description, keywords and language metatags.
  * @param boolean|string $includeTitle Show default <title>-tag, set to false for custom templating
  *
  * @param boolean $includeTitle Show default <title>-tag, set to false for
  *                              custom templating
  * @return string The XHTML metatags
  */
 public function MetaTags($includeTitle = true)
 {
     $tags = "";
     if ($includeTitle === true || $includeTitle == 'true') {
         $tags .= "<title>" . Convert::raw2xml($this->MetaTitle ? $this->MetaTitle : $this->Title) . "</title>\n";
     }
     $tags .= "<meta name=\"generator\" http-equiv=\"generator\" content=\"SilverStripe 2.0 - http://www.silverstripe.com\" />\n";
     $charset = ContentNegotiator::get_encoding();
     $tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset={$charset}\" />\n";
     if ($this->MetaKeywords) {
         $tags .= "<meta name=\"keywords\" http-equiv=\"keywords\" content=\"" . Convert::raw2att($this->MetaKeywords) . "\" />\n";
     }
     if ($this->MetaDescription) {
         $tags .= "<meta name=\"description\" http-equiv=\"description\" content=\"" . Convert::raw2att($this->MetaDescription) . "\" />\n";
     }
     if ($this->ExtraMeta) {
         $tags .= $this->ExtraMeta . "\n";
     }
     $tags .= "<meta http-equiv=\"Content-Language\" content=\"" . Translatable::current_lang() . "\"/>\n";
     return $tags;
 }
Exemplo n.º 28
0
 /**
  * Executes this controller, and return an {@link SS_HTTPResponse} object with the result.
  * 
  * This method first does a few set-up activities:
  *  - Push this controller ont to the controller stack - 
  *    see {@link Controller::curr()} for information about this.
  *  - Call {@link init()}
  *  - Defer to {@link RequestHandler->handleRequest()} to determine which action
  *    should be executed
  * 
  * Note: $requestParams['executeForm'] support was removed, 
  * make the following change in your URLs: 
  * "/?executeForm=FooBar" -> "/FooBar" 
  * Also make sure "FooBar" is in the $allowed_actions of your controller class.
  * 
  * Note: You should rarely need to overload run() - 
  * this kind of change is only really appropriate for things like nested
  * controllers - {@link ModelAsController} and {@link RootURLController} 
  * are two examples here.  If you want to make more
  * orthodox functionality, it's better to overload {@link init()} or {@link index()}.
  * 
  * Important: If you are going to overload handleRequest, 
  * make sure that you start the method with $this->pushCurrent()
  * and end the method with $this->popCurrent().  
  * Failure to do this will create weird session errors.
  * 
  * @param $request The {@link SS_HTTPRequest} object that is responsible 
  *  for distributing request parsing.
  * @return SS_HTTPResponse The response that this controller produces, 
  *  including HTTP headers such as redirection info
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $this->extend('onBeforeInit');
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init()." . "Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     $this->extend('onAfterInit');
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         $this->popCurrent();
         return $this->response;
     }
     $body = parent::handleRequest($request, $model);
     if ($body instanceof SS_HTTPResponse) {
         if (isset($_REQUEST['debug_request'])) {
             Debug::message("Request handler returned SS_HTTPResponse object to {$this->class} controller;" . "returning it without modification.");
         }
         $this->response = $body;
     } else {
         if ($body instanceof Object && $body->hasMethod('getViewer')) {
             if (isset($_REQUEST['debug_request'])) {
                 Debug::message("Request handler {$body->class} object to {$this->class} controller;" . "rendering with template returned by {$body->class}::getViewer()");
             }
             $body = $body->getViewer($request->latestParam('Action'))->process($body);
         }
         $this->response->setBody($body);
     }
     ContentNegotiator::process($this->response);
     HTTP::add_cache_headers($this->response);
     $this->popCurrent();
     return $this->response;
 }
Exemplo n.º 29
0
 function index($url)
 {
     // We need to override the default content-type
     ContentNegotiator::disable();
     header('Content-type: application/xml; charset="utf-8"');
     // But we want to still render.
     return array();
 }
Exemplo n.º 30
0
 /**
  * Show the content of the upload iframe.  The form is specified by a template.
  */
 function uploadiframe()
 {
     Requirements::clear();
     Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
     Requirements::javascript(THIRDPARTY_DIR . "/loader.js");
     Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
     Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
     Requirements::javascript(THIRDPARTY_DIR . "/layout_helpers.js");
     Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain.js");
     Requirements::javascript(THIRDPARTY_DIR . "/multifile/multifile.js");
     Requirements::css(THIRDPARTY_DIR . "/multifile/multifile.css");
     Requirements::css(CMS_DIR . "/css/typography.css");
     Requirements::css(CMS_DIR . "/css/layout.css");
     Requirements::css(CMS_DIR . "/css/cms_left.css");
     Requirements::css(CMS_DIR . "/css/cms_right.css");
     if (isset($data['ID']) && $data['ID'] != 'root') {
         $folder = DataObject::get_by_id("Folder", $data['ID']);
     } else {
         $folder = singleton('Folder');
     }
     // Don't modify the output of the template, or it will become invalid
     ContentNegotiator::disable();
     return array('CanUpload' => $folder->canEdit());
 }