本文整理汇总了PHP中SSViewer::fromString方法的典型用法代码示例。如果您正苦于以下问题:PHP SSViewer::fromString方法的具体用法?PHP SSViewer::fromString怎么用?PHP SSViewer::fromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SSViewer
的用法示例。
在下文中一共展示了SSViewer::fromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _runtemplate
protected function _runtemplate($template, $data = null) {
if ($data === null) $data = $this->data;
if (is_array($data)) $data = $this->data->customise($data);
$viewer = SSViewer::fromString($template);
return $viewer->process($data);
}
示例2: doSearch
public function doSearch($gridField, $request)
{
$dataClass = $gridField->getList()->dataClass();
$allList = $this->searchList ? $this->searchList : DataList::create($dataClass);
$searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
if (!$searchFields) {
throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
}
$params = array();
foreach ($searchFields as $searchField) {
$name = strpos($searchField, ':') !== FALSE ? $searchField : "{$searchField}:StartsWith";
$params[$name] = $request->getVar('gridfield_relationsearch');
}
if (!$gridField->getList() instanceof UnsavedRelationList) {
$allList = $allList->subtract($gridField->getList());
}
$results = $allList->filterAny($params)->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getResultsLimit());
$json = array();
$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
Config::inst()->update('SSViewer', 'source_file_comments', false);
foreach ($results as $result) {
$json[$result->ID] = html_entity_decode(SSViewer::fromString($this->resultsFormat)->process($result));
}
Config::inst()->update('SSViewer', 'source_file_comments', $originalSourceFileComments);
return Convert::array2json($json);
}
示例3: render
/**
* Small helper to render templates from strings
* Cloned from SSViewerTest
*/
private function render($templateString, $data = null)
{
$t = SSViewer::fromString($templateString);
if (!$data) {
$data = new SSViewerTestFixture();
}
return $t->process($data);
}
示例4: testComments
function testComments()
{
$viewer = SSViewer::fromString(<<<SS
This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>This is the final content
SS
);
$output = $viewer->process(new ArrayData(array()));
$this->assertEquals("This is my templateThis is some contentThis is the final content", preg_replace("/\n?<!--.*-->\n?/U", '', $output));
}
示例5: getAttributes
/**
* @return Array
*/
public function getAttributes()
{
$attributes = array_merge(parent::getAttributes(), array('type' => 'hidden', 'data-searchurl' => $this->Link('search'), 'data-minimuminputlength' => $this->getConfig('minimumInputLength'), 'data-resultslimit' => $this->getConfig('resultsLimit'), 'data-placeholder' => $this->getConfig('placeholder'), 'data-multiple' => $this->getConfig('multiple')));
if ($this->Value() && ($object = DataObject::get($this->getConfig('classToSearch'))->byID($this->Value()))) {
$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
Config::inst()->update('SSViewer', 'source_file_comments', false);
$attributes['data-selectioncontent'] = html_entity_decode(SSViewer::fromString($this->getConfig('selectionFormat'))->process($object));
Config::inst()->update('SSViewer', 'source_file_comments', $originalSourceFileComments);
}
return $attributes;
}
示例6: __construct
function __construct($controller, $name, $class = 'Page', $limit = 30)
{
Requirements::javascript(ABC_PATH . '/javascript/child-list.js');
Requirements::css(ABC_PATH . '/css/child-list.css');
$do = new DataObject();
$do->DataSet = AddPaginator::get($limit)->fetch($class, "SiteTree.ParentID = " . $controller->ID, "PublicationDate DESC, Created DESC");
$do->Paginator = $do->DataSet->Paginator->dataForTemplate(null, null, '/admin/getitem?ID=' . $controller->ID);
$parser = SSViewer::fromString(SSViewer::getTemplateContent('ChildList'));
$str = $parser->process($do);
parent::__construct($name, $str);
}
示例7: execute
public function execute(WorkflowInstance $workflow)
{
$members = $workflow->getAssignedMembers();
if (!$members || !count($members)) {
return true;
}
$member = Member::currentUser();
$initiator = $workflow->Initiator();
$contextFields = $this->getContextFields($workflow->getTarget());
$memberFields = $this->getMemberFields($member);
$initiatorFields = $this->getMemberFields($initiator);
$variables = array();
foreach ($contextFields as $field => $val) {
$variables["\$Context.{$field}"] = $val;
}
foreach ($memberFields as $field => $val) {
$variables["\$Member.{$field}"] = $val;
}
foreach ($initiatorFields as $field => $val) {
$variables["\$Initiator.{$field}"] = $val;
}
$pastActions = $workflow->Actions()->sort('Created DESC');
$variables["\$CommentHistory"] = $this->customise(array('PastActions' => $pastActions, 'Now' => SS_Datetime::now()))->renderWith('CommentHistory');
$from = str_replace(array_keys($variables), array_values($variables), $this->EmailFrom);
$subject = str_replace(array_keys($variables), array_values($variables), $this->EmailSubject);
if ($this->config()->whitelist_template_variables) {
$item = new ArrayData(array('Initiator' => new ArrayData($initiatorFields), 'Member' => new ArrayData($memberFields), 'Context' => new ArrayData($contextFields), 'CommentHistory' => $variables["\$CommentHistory"]));
} else {
$item = $workflow->customise(array('Items' => $workflow->Actions(), 'Member' => $member, 'Context' => new ArrayData($contextFields), 'CommentHistory' => $variables["\$CommentHistory"]));
}
if ($this->ListingTemplateID) {
$template = DataObject::get_by_id('ListingTemplate', $this->ListingTemplateID);
$view = SSViewer::fromString($template->ItemTemplate);
} else {
$view = SSViewer::fromString($this->EmailTemplate);
}
$body = $view->process($item);
foreach ($members as $member) {
if ($member->Email) {
$email = new Email();
$email->setTo($member->Email);
$email->setSubject($subject);
$email->setFrom($from);
$email->setBody($body);
$email->send();
}
}
return true;
}
示例8: execute
public function execute(WorkflowInstance $workflow)
{
$email = new Email();
$members = $workflow->getAssignedMembers();
$emails = '';
if (!$members || !count($members)) {
return;
}
foreach ($members as $member) {
if ($member->Email) {
$emails .= "{$member->Email}, ";
}
}
$context = $this->getContextFields($workflow->getTarget());
$member = $this->getMemberFields();
$variables = array();
foreach ($context as $field => $val) {
$variables["\$Context.{$field}"] = $val;
}
foreach ($member as $field => $val) {
$variables["\$Member.{$field}"] = $val;
}
$subject = str_replace(array_keys($variables), array_values($variables), $this->EmailSubject);
if ($this->ListingTemplateID) {
$item = $workflow->customise(array('Items' => $workflow->Actions(), 'Member' => Member::currentUser(), 'Context' => $workflow->getTarget()));
$template = DataObject::get_by_id('ListingTemplate', $this->ListingTemplateID);
$view = SSViewer::fromString($template->ItemTemplate);
$body = $view->process($item);
} else {
$body = str_replace(array_keys($variables), array_values($variables), $this->EmailTemplate);
}
$email->setSubject($subject);
$email->setFrom($this->EmailFrom);
$email->setBcc(substr($emails, 0, -2));
$email->setBody($body);
$email->send();
return true;
}
示例9: doSearch
/**
* Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion
*
* @param GridField $gridField
* @param SS_HTTPRequest $request
* @return sting in JSON fromat
*/
public function doSearch($gridField, $request)
{
$dataClass = $gridField->getList()->dataClass();
$allList = $this->searchList ? $this->searchList : DataList::create($dataClass);
$searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
if (!$searchFields) {
throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
}
// TODO Replace with DataList->filterAny() once it correctly supports OR connectives
$stmts = array();
foreach ($searchFields as $searchField) {
$stmts[] .= sprintf('"%s" LIKE \'%s%%\'', $searchField, Convert::raw2sql($request->getVar('gridfield_relationsearch')));
}
$results = $allList->where(implode(' OR ', $stmts))->subtract($gridField->getList());
$results = $results->sort($searchFields[0], 'ASC');
$results = $results->limit($this->getResultsLimit());
if (!empty($this->filters)) {
$results = $results->addFilter($this->filters);
}
if (!empty($this->excludes)) {
switch (count($this->excludes)) {
case 1:
$key = key($this->excludes);
$results->exclude($key, $this->excludes[$key]);
break;
case 2:
$results->exclude($this->excludes);
break;
default:
throw new InvalidArgumentException('Incorrect number of arguments passed to filter()');
}
}
$json = array();
foreach ($results as $result) {
$json[$result->ID] = SSViewer::fromString($this->resultsFormat)->process($result);
}
return Convert::array2json($json);
}
示例10: doSearch
/**
* Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion
*
* @param GridField $gridField
* @param SS_HTTPRequest $request
*/
public function doSearch($gridField, $request)
{
$dataClass = $gridField->getList()->dataClass();
$allList = DataList::create($dataClass);
$filters = array();
$stmts = array();
$searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
if (!$searchFields) {
throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
}
// TODO Replace with DataList->filterAny() once it correctly supports OR connectives
foreach ($searchFields as $searchField) {
$stmts[] .= 'LOWER(' . $searchField . ') LIKE \'%' . strtolower(Convert::raw2sql($request->getVar('gridfield_relationsearch'))) . '%\'';
}
$results = $allList->where(implode(' OR ', $stmts));
$results = $results->sort($searchFields[0], 'ASC');
$results = $results->limit($this->getResultsLimit());
$json = array();
foreach ($results as $result) {
$json[$result->ID] = SSViewer::fromString($this->resultsFormat)->process($result);
}
return Convert::array2json($json);
}
开发者ID:helpfulrobot,项目名称:azt3k-abc-silverstripe,代码行数:29,代码来源:AbcGridFieldAddExistingAutocompleter.php
示例11: getCMSFields
/**
* Gets the {@link FieldList} for editing the record
* @return FieldList
*/
public function getCMSFields()
{
// Requirements for Ace editor
Requirements::javascript(PERMAMAIL_DIR . '/javascript/ace/ace.js');
Requirements::javascript(PERMAMAIL_DIR . '/javascript/ace/theme-chrome.js');
Requirements::javascript(PERMAMAIL_DIR . '/javascript/ace/mode-html.js');
Requirements::javascript(PERMAMAIL_DIR . '/javascript/jquery-ace.js');
Requirements::javascript(PERMAMAIL_DIR . '/javascript/ace-init.js');
$fields = FieldList::create(TabSet::create("Root"));
$fields->addFieldToTab('Root.Main', TextField::create('Identifier', 'Template name (no spaces, alphanumeric characters only)'));
$fields->addFieldToTab('Root.Main', TextField::create('Subject', 'Default subject (optional)'));
$fields->addFieldToTab('Root.Main', TextField::create('From', 'Default "from" address (optional)'));
$fields->addFieldToTab('Root.Main', CheckboxField::create('IsAbstractTemplate', 'Is this an abstract template?<br>Abstract templates can be inherited by other templates. Useful for similar layout templates.'));
$fields->addFieldToTab('Root.Main', DropdownField::create('ParentTemplate', 'Parent Abstract template. Useful for similar layout templates.', PermamailTemplate::get()->filter('IsAbstractTemplate', true)));
$fields->addFieldToTab('Root.Main', TextareaField::create('Content', 'Template content')->addExtraClass('ace')->setRows(30)->setColumns(100)->setFieldHolderTemplate('PermamailTemplateEditor'));
$vars = array();
foreach ($this->TestVariables() as $v) {
$value = $v->getVariableValue();
$vars[$v->Variable] = $value ? $value : '';
}
// Populate the Content field with default Content from file template
try {
$content = SSViewer::fromString($this->getContent());
$content = $content->process(new ViewableData(), $vars);
if ($this->IsAbstractTemplate && $this->MainTemplate()->exists()) {
$contentMain = SSViewer::fromString($this->MainTemplate()->getContent());
$content = $contentMain->process(new ViewableData(), array('Content' => $content));
}
} catch (SSTemplateParseException $e) {
$content = $e->getMessage();
}
$fields->addFieldToTab('Root.Main', new LabelField('ContentOutput', '<strong>Template Output</strong><br>
<div style="background-color:white; padding: 1em; border: 3px solid grey;">' . $content . '</div><br>'), 'Content');
$fields->addFieldsToTab("Root.Tests", array(EmailField::create('TestEmailAddress', 'Test email address'), GridField::create('TestVariables', 'Test variables', $this->TestVariables(), GridFieldConfig_RecordEditor::create())));
return $fields;
}
示例12: replacePlaceholders
/**
* Replaces placeholders within the $content property their actual value
*
* @param string $content
*
* @return string
*/
public function replacePlaceholders($content)
{
// Find placeholders
preg_match_all("/{{(.*?)}}/", $this->owner->Content, $matches);
// If placeholders found
if (!empty($matches[1])) {
// Fetch view templates
$templates = DataObject::get('ViewTemplate')->filter(['Title' => $matches[1]])->getIterator();
// Replace placeholders with their templates
foreach ($matches[0] as $key => $templateHolder) {
if ($templates->offsetExists($key)) {
// Remove <p> if TinyMCE added them
$content = str_replace('<p>' . $templateHolder . '</p>', $templateHolder, $content);
// Process the template
$template = SSViewer::fromString($templates->offsetGet($key)->ViewTemplate)->process($this->owner);
// Replace the placeholder with its template
$content = str_replace($templateHolder, $template, $content);
}
}
}
// Set and return content
$this->owner->Content = $content;
return $content;
}
示例13: doSearch
/**
* Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion
*
* @param GridField $gridField
* @param SS_HTTPRequest $request
*/
public function doSearch($gridField, $request)
{
$dataClass = $gridField->getList()->dataClass();
$allList = $this->searchList ? $this->searchList : DataList::create($dataClass);
$searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
if (!$searchFields) {
throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
}
$params = array();
foreach ($searchFields as $searchField) {
$name = strpos($searchField, ':') !== FALSE ? $searchField : "{$searchField}:StartsWith";
$params[$name] = $request->getVar('gridfield_relationsearch');
}
$results = $allList->subtract($gridField->getList())->filterAny($params)->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getResultsLimit());
$json = array();
foreach ($results as $result) {
$json[$result->ID] = SSViewer::fromString($this->resultsFormat)->process($result);
}
return Convert::array2json($json);
}
示例14: parseVariables
/**
* 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) {
if(!$this->parseVariables_done) {
$this->parseVariables_done = true;
// Parse $ variables in the base parameters
$data = $this->templateData();
foreach(array('from','to','subject','body', 'plaintext_body', 'cc', 'bcc') as $param) {
$template = SSViewer::fromString($this->$param);
$this->$param = $template->process($data);
}
// 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);
}
}
示例15: Content
public function Content()
{
if (!$this->ID) {
return '';
}
$action = Controller::has_curr() ? Controller::curr()->getRequest()->latestParam('Action') : null;
if ($this->ComponentFilterName && !$action) {
// For a list of relations like tags/categories/etc
$items = $this->ComponentListingItems();
$item = $this->customise(array('Items' => $items));
$view = SSViewer::fromString($this->ComponentListingTemplate()->ItemTemplate);
} else {
$items = $this->ListingItems();
$item = $this->customise(array('Items' => $items));
$view = SSViewer::fromString($this->ListingTemplate()->ItemTemplate);
}
$content = str_replace('<p>$Listing</p>', '$Listing', $this->Content);
return str_replace('$Listing', $view->process($item), $content);
}