Пример #1
0
	function graph() {
		SSViewer::set_source_file_comments(false);
		$dotContent = $this->renderWith("ModelViewer_dotsrc");
		$CLI_dotContent = escapeshellarg($dotContent);
		
		$output= `echo $CLI_dotContent | neato -Tpng:gd &> /dev/stdout`;
		if(substr($output,1,3) == 'PNG') header("Content-type: image/png");
		else header("Content-type: text/plain");
		echo $output;
	}
 private function jsonPacket($data)
 {
     $this->response->addHeader('Content-Type', 'application/json');
     SSViewer::set_source_file_comments(false);
     $json = json_encode($data);
     $json = str_replace('\\t', " ", $json);
     $json = str_replace('\\r', " ", $json);
     $json = str_replace('\\n', " ", $json);
     $json = preg_replace('/\\s\\s+/', ' ', $json);
     return $json;
 }
Пример #3
0
    public function testRenderWithSourceFileComments()
    {
        $origType = Director::get_environment_type();
        Director::set_environment_type('dev');
        SSViewer::set_source_file_comments(true);
        $view = new SSViewer(array('SSViewerTestCommentsFullSource'));
        $data = new ArrayData(array());
        $result = $view->process($data);
        $expected = '<!doctype html>
<html><!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss -->
	<head></head>
	<body></body>
<!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsFullSource.ss --></html>
';
        $this->assertEquals($result, $expected);
        $view = new SSViewer(array('SSViewerTestCommentsPartialSource'));
        $data = new ArrayData(array());
        $result = $view->process($data);
        $expected = '<!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsPartialSource.ss -->' . '<div class=\'typography\'></div><!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsPartialSource.ss -->';
        $this->assertEquals($result, $expected);
        $view = new SSViewer(array('SSViewerTestCommentsWithInclude'));
        $data = new ArrayData(array());
        $result = $view->process($data);
        $expected = '<!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsWithInclude.ss -->' . '<div class=\'typography\'><!-- include \'SSViewerTestCommentsInclude\' --><!-- template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsInclude.ss -->Included<!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsInclude.ss -->' . '<!-- end include \'SSViewerTestCommentsInclude\' --></div><!-- end template ' . FRAMEWORK_PATH . '/tests/templates/SSViewerTestCommentsWithInclude.ss -->';
        $this->assertEquals($result, $expected);
        SSViewer::set_source_file_comments(false);
        Director::set_environment_type($origType);
    }
Пример #4
0
 /**
  *@return String (HTML Snippet)
  **/
 function EcommerceMenuTitle()
 {
     $count = 0;
     $order = ShoppingCart::current_order();
     if ($order) {
         $count = $order->TotalItems();
         $oldSSViewer = SSViewer::get_source_file_comments();
         SSViewer::set_source_file_comments(false);
         $this->customise(array("Count" => $count, "OriginalMenuTitle" => $this->MenuTitle));
         $s = $this->renderWith("AjaxNumItemsInCart");
         SSViewer::set_source_file_comments($oldSSViewer);
         return $s;
     }
     return $this->OriginalMenuTitle();
 }
Пример #5
0
 /**
  * Load all the template variables into the internal variables, including
  * the template into body.	Called before send() or debugSend()
  * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used
  * and it won't be plain email :) 
  */
 protected function parseVariables($isPlain = false)
 {
     SSViewer::set_source_file_comments(false);
     if (!$this->parseVariables_done) {
         $this->parseVariables_done = true;
         // Parse $ variables in the base parameters
         $data = $this->templateData();
         // Process a .SS template file
         $fullBody = $this->body;
         if ($this->ss_template && !$isPlain) {
             // Requery data so that updated versions of To, From, Subject, etc are included
             $data = $this->templateData();
             $template = new SSViewer($this->ss_template);
             if ($template->exists()) {
                 $fullBody = $template->process($data);
             }
         }
         // Rewrite relative URLs
         $this->body = HTTP::absoluteURLs($fullBody);
     }
 }
Пример #6
0
 public function setUp()
 {
     // We cannot run the tests on this abstract class.
     if (get_class($this) == "SapphireTest") {
         $this->skipTest = true;
     }
     if ($this->skipTest) {
         $this->markTestSkipped(sprintf('Skipping %s ', get_class($this)));
         return;
     }
     // Mark test as being run
     $this->originalIsRunningTest = self::$is_running_test;
     self::$is_running_test = true;
     // i18n needs to be set to the defaults or tests fail
     i18n::set_locale(i18n::default_locale());
     i18n::set_date_format(null);
     i18n::set_time_format(null);
     // Set default timezone consistently to avoid NZ-specific dependencies
     date_default_timezone_set('UTC');
     // Remove password validation
     $this->originalMemberPasswordValidator = Member::password_validator();
     $this->originalRequirements = Requirements::backend();
     Member::set_password_validator(null);
     Cookie::set_report_errors(false);
     if (class_exists('RootURLController')) {
         RootURLController::reset();
     }
     if (class_exists('Translatable')) {
         Translatable::reset();
     }
     Versioned::reset();
     DataObject::reset();
     if (class_exists('SiteTree')) {
         SiteTree::reset();
     }
     Hierarchy::reset();
     if (Controller::has_curr()) {
         Controller::curr()->setSession(new Session(array()));
     }
     Security::$database_is_ready = null;
     $this->originalTheme = SSViewer::current_theme();
     if (class_exists('SiteTree')) {
         // Save nested_urls state, so we can restore it later
         $this->originalNestedURLsState = SiteTree::nested_urls();
     }
     $className = get_class($this);
     $fixtureFile = eval("return {$className}::\$fixture_file;");
     $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
     // Todo: this could be a special test model
     $this->model = DataModel::inst();
     // Set up fixture
     if ($fixtureFile || $this->usesDatabase || !self::using_temp_db()) {
         if (substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) {
             //echo "Re-creating temp database... ";
             self::create_temp_db();
             //echo "done.\n";
         }
         singleton('DataObject')->flushCache();
         self::empty_temp_db();
         foreach ($this->requireDefaultRecordsFrom as $className) {
             $instance = singleton($className);
             if (method_exists($instance, 'requireDefaultRecords')) {
                 $instance->requireDefaultRecords();
             }
             if (method_exists($instance, 'augmentDefaultRecords')) {
                 $instance->augmentDefaultRecords();
             }
         }
         if ($fixtureFile) {
             $pathForClass = $this->getCurrentAbsolutePath();
             $fixtureFiles = is_array($fixtureFile) ? $fixtureFile : array($fixtureFile);
             $i = 0;
             foreach ($fixtureFiles as $fixtureFilePath) {
                 // Support fixture paths relative to the test class, rather than relative to webroot
                 // String checking is faster than file_exists() calls.
                 $isRelativeToFile = strpos('/', $fixtureFilePath) === false || preg_match('/^\\.\\./', $fixtureFilePath);
                 if ($isRelativeToFile) {
                     $resolvedPath = realpath($pathForClass . '/' . $fixtureFilePath);
                     if ($resolvedPath) {
                         $fixtureFilePath = $resolvedPath;
                     }
                 }
                 $fixture = new YamlFixture($fixtureFilePath);
                 $fixture->saveIntoDatabase($this->model);
                 $this->fixtures[] = $fixture;
                 // backwards compatibility: Load first fixture into $this->fixture
                 if ($i == 0) {
                     $this->fixture = $fixture;
                 }
                 $i++;
             }
         }
         $this->logInWithPermission("ADMIN");
     }
     // Set up email
     $this->originalMailer = Email::mailer();
     $this->mailer = new TestMailer();
     Email::set_mailer($this->mailer);
     Email::send_all_emails_to(null);
     // Preserve memory settings
     $this->originalMemoryLimit = ini_get('memory_limit');
     // turn off template debugging
     SSViewer::set_source_file_comments(false);
     // Clear requirements
     Requirements::clear();
 }
Пример #7
0
	/**
	 * Return the content of the RSS feed
	 */
	function feedContent() {
		SSViewer::set_source_file_comments(false);
		return str_replace('&nbsp;', '&#160;', $this->renderWith('RSSFeed'));
	}
Пример #8
0
 /**
  * Return the content of the RSS feed.
  * 
  * Also temporarily disabled source file comments, and restores
  * to previous state once content has been rendered.
  * 
  * @return string
  */
 function feedContent()
 {
     $prevState = SSViewer::get_source_file_comments();
     SSViewer::set_source_file_comments(false);
     $content = str_replace('&nbsp;', '&#160;', $this->renderWith($this->getTemplate()));
     SSViewer::set_source_file_comments($prevState);
     return $content;
 }
 public function init()
 {
     SSViewer::set_source_file_comments(false);
     parent::init();
 }
Пример #10
0
<?php

define('LITECMS', basename(dirname(__FILE__)));
SSViewer::set_source_file_comments(false);
CMSMenu::remove_menu_item("CommentAdmin");
CMSMenu::remove_menu_item("ReportAdmin");
CMSMenu::remove_menu_item("SecurityAdmin");
CMSMenu::remove_menu_item("Help");
Object::add_extension('SiteConfig', 'LiteCMSBaseConfig');
Object::add_extension('LeftAndMain', 'LiteCMS');
Object::add_extension('SiteConfig', 'LiteCMSMaintenance');
Object::add_extension('Page', 'LiteCMSMaintenanceController_Decorator');
GD::set_default_quality(100);
LeftAndMain::setApplicationName("LiteCMS");
LeftAndMain::require_css('litecms/css/lite.css');
Image::add_extension('LiteCMSImage');
File::add_extension('LiteCMSAttachment');
Пример #11
0
 /**
  * Builds json object to be returned via ajax.
  *
  *@return JSON
  **/
 public function ReturnCartData($messages = array(), $data = null, $status = "success")
 {
     //add header
     $this->addHeader('Content-Type', 'application/json');
     SSViewer::set_source_file_comments(false);
     if ($status != "success") {
         $messagesImploded = '';
         foreach ($messages as $messageArray) {
             $messagesImploded .= '<span class="' . $messageArray["Type"] . '">' . $messageArray["Message"] . '</span>';
         }
         $this->setStatusCode(400, $messagesImploded);
     }
     //init Order - IMPORTANT
     $currentOrder = ShoppingCart::current_order();
     $currentOrder->calculateOrderAttributes(true);
     //now we have done the calculations you may find that we need to reload...
     $ajaxObject = $currentOrder->AJAXDefinitions();
     // populate Javascript
     $js = array();
     //order items
     $inCartArray = array();
     if ($items = $currentOrder->Items()) {
         foreach ($items as $item) {
             $item->updateForAjax($js);
             $buyable = $item->Buyable(true);
             if ($buyable) {
                 //products in cart
                 $inCartArray[] = $buyable->AJAXDefinitions()->UniqueIdentifier();
                 //HACK TO INCLUDE PRODUCT IN PRODUCT VARIATION
                 if ($buyable instanceof ProductVariation) {
                     $inCartArray[] = $buyable->Product()->AJAXDefinitions()->UniqueIdentifier();
                 }
             }
         }
     }
     //in cart items
     $js[] = array("t" => "replaceclass", "s" => $inCartArray, "p" => ".productActions.inCart", "v" => "inCart", "without" => "notInCart");
     if (isset($_REQUEST["loadingindex"])) {
         $js[] = array("t" => "loadingindex", "v" => $_REQUEST["loadingindex"]);
     }
     //order modifiers
     if ($modifiers = $currentOrder->Modifiers()) {
         foreach ($modifiers as $modifier) {
             $modifier->updateForAjax($js);
         }
     }
     //order
     $currentOrder->updateForAjax($js);
     //messages
     if (is_array($messages)) {
         $messagesImploded = '';
         foreach ($messages as $messageArray) {
             $messagesImploded .= '<span class="' . $messageArray["Type"] . '">' . $messageArray["Message"] . '</span>';
         }
         $js[] = array("t" => "id", "s" => $ajaxObject->TableMessageID(), "p" => "innerHTML", "v" => $messagesImploded, "isOrderMessage" => true);
         $js[] = array("t" => "id", "s" => $ajaxObject->TableMessageID(), "p" => "hide", "v" => 0);
     } else {
         $js[] = array("t" => "id", "s" => $ajaxObject->TableMessageID(), "p" => "hide", "v" => 1);
     }
     //TO DO: set it up in such a way that ir specifically requests one of these
     //tiny cart
     $js[] = array("t" => "class", "s" => $ajaxObject->TinyCartClassName(), "p" => "innerHTML", "v" => $currentOrder->renderWith("CartTinyInner"));
     //add basic cart
     $js[] = array("t" => "id", "s" => $ajaxObject->SmallCartID(), "p" => "innerHTML", "v" => $currentOrder->renderWith("CartShortInner"));
     //side bar cart
     $js[] = array("t" => "id", "s" => $ajaxObject->SideBarCartID(), "p" => "innerHTML", "v" => $currentOrder->renderWith("Sidebar_Cart_Inner"));
     //now can check if it needs to be reloaded
     if (self::$force_reload) {
         $js = array("reload" => 1);
     } else {
         $js[] = array("reload" => 0);
     }
     //merge and return
     if (is_array($data)) {
         $js = array_merge($js, $data);
     }
     //TODO: remove doubles!
     $json = Convert::array2json($js);
     $json = str_replace('\\t', " ", $json);
     $json = str_replace('\\r', " ", $json);
     $json = str_replace('\\n', " ", $json);
     $json = preg_replace('/\\s\\s+/', ' ', $json);
     $json = str_replace("{", "\r\n{", $json);
     return $json;
 }
Пример #12
0
 /**
  * Output the feed to the browser
  */
 public function outputToBrowser()
 {
     $prevState = SSViewer::get_source_file_comments();
     SSViewer::set_source_file_comments(false);
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     if (!headers_sent()) {
         HTTP::add_cache_headers();
         header("Content-type: text/xml");
     }
     SSViewer::set_source_file_comments($prevState);
     return $this->renderWith($this->getTemplate());
 }
 function index($url)
 {
     if (self::$enabled) {
         SSViewer::set_source_file_comments(false);
         $this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
         // But we want to still render.
         return array();
     } else {
         return new SS_HTTPResponse('Not allowed', 405);
     }
 }
Пример #14
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);
     }
 }
 /**
  * Builds json object to be returned via ajax.
  * @param Array $message (Type, Message)
  * @param Array $additionalData
  * @param String $status
  * @return HEADER + JSON
  **/
 public function ReturnCartData(array $messages = array(), array $additionalData = null, $status = "success")
 {
     //add header
     if ($this->includeHeaders) {
         $this->addHeader('Content-Type', 'application/json');
     }
     SSViewer::set_source_file_comments(false);
     //merge messages
     $messagesImploded = '';
     if (is_array($messages) && count($messages)) {
         foreach ($messages as $messageArray) {
             $messagesImploded .= '<span class="' . $messageArray["Type"] . '">' . $messageArray["Message"] . '</span>';
         }
     }
     //bad status
     if ($status != "success") {
         $this->setStatusCode(400, $messagesImploded);
     }
     //init Order - IMPORTANT
     $currentOrder = ShoppingCart::current_order();
     //THIS LINE TAKES UP MOST OF THE TIME OF THE RESPONSE!!!
     $currentOrder->calculateOrderAttributes($force = false);
     $ajaxObject = $currentOrder->AJAXDefinitions();
     // populate Javascript
     $js = array();
     //must be first
     if (isset($_REQUEST["loadingindex"])) {
         $js[] = array("t" => "loadingindex", "v" => $_REQUEST["loadingindex"]);
     }
     //order items
     $inCartArray = array();
     $items = $currentOrder->Items();
     if ($items->count()) {
         foreach ($items as $item) {
             $js = $item->updateForAjax($js);
             $buyable = $item->Buyable(true);
             if ($buyable) {
                 //products in cart
                 $inCartArray[] = $buyable->AJAXDefinitions()->UniqueIdentifier();
                 //HACK TO INCLUDE PRODUCT IN PRODUCT VARIATION
                 if (is_a($buyable, "ProductVariation")) {
                     $inCartArray[] = $buyable->Product()->AJAXDefinitions()->UniqueIdentifier();
                 }
             }
         }
     }
     //in cart items
     $js[] = array("t" => "replaceclass", "s" => $inCartArray, "p" => $currentOrder->AJAXDefinitions()->ProductListItemClassName(), "v" => $currentOrder->AJAXDefinitions()->ProductListItemInCartClassName(), "without" => $currentOrder->AJAXDefinitions()->ProductListItemNotInCartClassName());
     //order modifiers
     $modifiers = $currentOrder->Modifiers();
     if ($modifiers->count()) {
         foreach ($modifiers as $modifier) {
             $js = $modifier->updateForAjax($js);
         }
     }
     //order
     $js = $currentOrder->updateForAjax($js);
     //messages
     if (is_array($messages)) {
         $js[] = array("t" => "id", "s" => $ajaxObject->TableMessageID(), "p" => "innerHTML", "v" => $messagesImploded, "isOrderMessage" => true);
         $js[] = array("t" => "id", "s" => $ajaxObject->TableMessageID(), "p" => "hide", "v" => 0);
     } else {
         $js[] = array("t" => "id", "s" => $ajaxObject->TableMessageID(), "p" => "hide", "v" => 1);
     }
     //TO DO: set it up in such a way that it specifically requests one of these
     $templates = EcommerceConfig::get("CartResponse", "cart_responses_required");
     foreach ($templates as $idMethod => $template) {
         $selector = $ajaxObject->{$idMethod}();
         $classOrID = "id";
         if (strpos($selector, "ID") === null || strpos($selector, "ClassName") !== null) {
             $selector = "class";
         }
         $js[] = array("t" => $classOrID, "s" => $ajaxObject->{$idMethod}(), "p" => "innerHTML", "v" => " " . $currentOrder->renderWith($template));
     }
     //now can check if it needs to be reloaded
     if (self::$force_reload) {
         $js = array("reload" => 1);
     } else {
         $js[] = array("reload" => 0);
     }
     //merge and return
     if (is_array($additionalData) && count($additionalData)) {
         $js = array_merge($js, $additionalData);
     }
     //TODO: remove doubles?
     //turn HTMLText (et al.) objects into text
     foreach ($js as $key => $node) {
         if (isset($node["v"])) {
             if ($node["v"] instanceof DBField) {
                 $js[$key]["v"] = $node["v"]->forTemplate();
             }
         }
     }
     $json = json_encode($js);
     $json = str_replace('\\t', " ", $json);
     $json = str_replace('\\r', " ", $json);
     $json = str_replace('\\n', " ", $json);
     $json = preg_replace('/\\s\\s+/', ' ', $json);
     if (Director::isDev()) {
         $json = str_replace("{", "\r\n{", $json);
     }
     return $json;
 }
 function getversion()
 {
     $id = $this->urlParams['ID'];
     $version = str_replace('&ajax=1', '', $this->urlParams['OtherID']);
     $record = Versioned::get_version("SiteTree", $id, $version);
     if ($record) {
         if ($record && !$record->canView()) {
             return Security::permissionFailure($this);
         }
         $fields = $record->getCMSFields($this);
         $fields->removeByName("Status");
         $fields->push(new HiddenField("ID"));
         $fields->push(new HiddenField("Version"));
         $versionAuthor = DataObject::get_by_id('Member', $record->AuthorID);
         if (!$versionAuthor) {
             $versionAuthor = new ArrayData(array('Title' => 'Unknown author'));
         }
         $fields->insertBefore(new LiteralField('YouAreViewingHeader', '<p class="message notice">' . sprintf(_t('CMSMain.VIEWING', "You are viewing version #%s, created %s by %s", PR_MEDIUM, 'Version number is a linked string, created is a relative time (e.g. 2 days ago), by a specific author'), "<a href=\"admin/getversion/{$record->ID}/{$version}\" title=\"" . ($versionAuthor ? $versionAuthor->Title : '') . "\">{$version}</a>", $record->obj('LastEdited')->Ago(), $versionAuthor ? $versionAuthor->Title : '') . '</p>'), 'Root');
         $actions = new FieldSet(new FormAction("email", _t('CMSMain.EMAIL', "Email")), new FormAction("rollback", _t('CMSMain.ROLLBACK', "Roll back to this version")));
         // encode the message to appear in the body of the email
         $archiveURL = Director::absoluteBaseURL() . $record->URLSegment . '?archiveDate=' . $record->obj('LastEdited')->URLDatetime();
         // Ensure that source file comments are disabled
         SSViewer::set_source_file_comments(false);
         $archiveEmailMessage = urlencode($this->customise(array('ArchiveDate' => $record->obj('LastEdited'), 'ArchiveURL' => $archiveURL))->renderWith('ViewArchivedEmail'));
         $archiveEmailMessage = preg_replace('/\\+/', '%20', $archiveEmailMessage);
         $fields->push(new HiddenField('ArchiveEmailMessage', '', $archiveEmailMessage));
         $fields->push(new HiddenField('ArchiveEmailSubject', '', preg_replace('/\\+/', '%20', urlencode('Archived version of ' . $record->Title))));
         $fields->push(new HiddenField('ArchiveURL', '', $archiveURL));
         $form = new Form($this, "EditForm", $fields, $actions);
         $form->loadDataFrom($record);
         $form->loadDataFrom(array("ID" => $id, "Version" => $version));
         // historical version shouldn't be editable
         $readonlyFields = $form->Fields()->makeReadonly();
         $form->setFields($readonlyFields);
         $templateData = $this->customise(array("EditForm" => $form));
         SSViewer::setOption('rewriteHashlinks', false);
         if (Director::is_ajax()) {
             $result = $templateData->renderWith($this->class . '_right');
             $parts = split('</?form[^>]*>', $result);
             $content = $parts[sizeof($parts) - 2];
             if ($this->ShowSwitchView()) {
                 $content .= '<div id="AjaxSwitchView">' . $this->SwitchView($record) . '</div>';
             }
             return $content;
         } else {
             return $templateData->renderWith('LeftAndMain');
         }
     }
 }
 function json($request)
 {
     SSViewer::set_source_file_comments(false);
     if (isset($_GET['flush']) || !$this->JSON) {
         return $this->createJSON();
     }
     return $this->JSON;
 }