本文整理汇总了PHP中Convert::raw2att方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::raw2att方法的具体用法?PHP Convert::raw2att怎么用?PHP Convert::raw2att使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Convert
的用法示例。
在下文中一共展示了Convert::raw2att方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContent
/**
* @return string
*/
public function getContent()
{
$doc = clone $this->getDocument();
$xp = new DOMXPath($doc);
// If there's no body, the content is empty string
if (!$doc->getElementsByTagName('body')->length) {
return '';
}
// saveHTML Percentage-encodes any URI-based attributes. We don't want this, since it interferes with
// shortcodes. So first, save all the attribute values for later restoration.
$attrs = array();
$i = 0;
foreach ($xp->query('//body//@*') as $attr) {
$key = "__HTMLVALUE_" . $i++;
$attrs[$key] = $attr->value;
$attr->value = $key;
}
// Then, call saveHTML & extract out the content from the body tag
$res = preg_replace(array('/^(.*?)<body>/is', '/<\\/body>(.*?)$/isD'), '', $doc->saveHTML());
// Then replace the saved attributes with their original versions
$res = preg_replace_callback('/__HTMLVALUE_(\\d+)/', function ($matches) use($attrs) {
return Convert::raw2att($attrs[$matches[0]]);
}, $res);
// Prevent being encoded as literal utf-8 characters
// Possible alternative solution: http://stackoverflow.com/questions/2142120/php-encoding-with-domdocument
$from = mb_convert_encoding(' ', 'utf-8', 'html-entities');
$res = str_replace($from, ' ', $res);
return $res;
}
示例2: testRaw2Att
/**
* Tests {@link Convert::raw2att()}
*/
public function testRaw2Att()
{
$val1 = '<input type="text">';
$this->assertEquals('<input type="text">', Convert::raw2att($val1), 'Special characters are escaped');
$val2 = 'This is some normal text.';
$this->assertEquals('This is some normal text.', Convert::raw2att($val2), 'Normal text is not escaped');
}
示例3: get
/**
* Build the Meta tags HTML
*
* @since version 1.0.0
*
* @return self Returns the current instance
**/
public function get()
{
if (!Controller::curr() instanceof Security && !Controller::curr() instanceof CMSMain) {
foreach ($this->model->HeadTags() as $tag) {
if ($tag->Type == 'name') {
$this->getMetaTag($tag->Name, $tag->Value);
break;
}
if ($tag->Type == 'link') {
$this->getLinkTag($tag->Name, $tag->Value);
break;
}
if ($tag->Type == 'property') {
$this->getPropertyTag($tag->Name, $tag->Value);
break;
}
}
}
// Add SilverStripe generated tags
// generator tag
$generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
if (!empty($generator)) {
$this->getMetaTag('generator', Convert::raw2att($generator));
}
// charset tag
$charset = Config::inst()->get('ContentNegotiator', 'encoding');
$this->getHttpEquivTag('Content-type', 'text/html; charset=' . $charset);
// CMS preview
if (Permission::check('CMS_ACCESS_CMSMain') && in_array('CMSPreviewable', class_implements($this)) && !$this instanceof ErrorPage && $this->ID > 0) {
$this->getMetaTag('x-page-id', $this->ID);
$this->getMetaTag('x-cms-edit-link', Controller::curr()->CMSEditLink());
}
return $this;
}
示例4: tree
/**
* @return string
*/
public function tree($request)
{
$data = array();
$class = $request->getVar('class');
$id = $request->getVar('id');
if ($id == 0) {
$items = singleton('WorkflowService')->getDefinitions();
$type = 'WorkflowDefinition';
} elseif ($class == 'WorkflowDefinition') {
$items = DataObject::get('WorkflowAction', '"WorkflowDefID" = ' . (int) $id);
$type = 'WorkflowAction';
} else {
$items = DataObject::get('WorkflowTransition', '"ActionID" = ' . (int) $id);
$type = 'WorkflowTransition';
}
if ($items) {
foreach ($items as $item) {
$new = array('data' => array('title' => $item->Title, 'attr' => array('href' => $this->Link("{$type}/{$item->ID}/edit")), 'icon' => $item->stat('icon')), 'attr' => array('id' => "{$type}_{$item->ID}", 'title' => Convert::raw2att($item->Title), 'data-id' => $item->ID, 'data-type' => $type, 'data-class' => $item->class));
if ($item->numChildren() > 0) {
$new['state'] = 'closed';
}
$data[] = $new;
}
}
return Convert::raw2json($data);
}
示例5: Field
function Field()
{
if ($this->description) {
$titleAttr = "title=\"" . Convert::raw2att($this->description) . "\"";
}
return "<input class=\"action\" id=\"" . $this->id() . "\" type=\"reset\" name=\"{$this->name}\" value=\"" . $this->attrTitle() . "\" {$titleAttr} />";
}
示例6: __construct
function __construct($controller, $name, $title = "Training")
{
if ($member = Member::currentUser()) {
} else {
$member = new Member();
}
$fields = new FieldList(new HeaderField($title));
$extraFields = $member->getTrainingFields();
foreach ($extraFields as $field) {
if ("Password" == $field->title() && $member->ID) {
} elseif ("Password" == $field->title()) {
$fields->push(new ConfirmedPasswordField("Password"));
} else {
$fields->push($field);
}
}
$actions = new FieldList(new FormAction("doSave", "Sign Up Now"));
$requiredFields = new RequiredFields("FirstName", "Surname", "Email", "Password");
if ($controller->Options) {
$array = array();
$explodedOptions = explode(",", $controller->Options);
foreach ($explodedOptions as $option) {
$option = trim(Convert::raw2att($option));
$array[$option] = $option;
}
if (count($array)) {
$fields->push(new DropdownField("SelectedOption", "Select Option", $array));
}
}
$fields->push(new TextField("BookingCode", "Booking Code (if any)"));
parent::__construct($controller, $name, $fields, $actions, $requiredFields);
$this->loadNonBlankDataFrom($member);
return $this;
}
示例7: Field
function Field($properties = array())
{
$options = '';
$odd = 0;
$source = $this->getSource();
foreach ($source as $key => $value) {
// convert the ID to an HTML safe value (dots are not replaced, as they are valid in an ID attribute)
$itemID = $this->id() . '_' . preg_replace('/[^\\.a-zA-Z0-9\\-\\_]/', '_', $key);
if ($key == $this->value) {
$useValue = false;
$checked = " checked=\"checked\"";
} else {
$checked = "";
}
$odd = ($odd + 1) % 2;
$extraClass = $odd ? "odd" : "even";
$extraClass .= " val" . preg_replace('/[^a-zA-Z0-9\\-\\_]/', '_', $key);
$disabled = $this->disabled || in_array($key, $this->disabledItems) ? "disabled=\"disabled\"" : "";
$ATT_key = Convert::raw2att($key);
$options .= "<li class=\"" . $extraClass . "\"><input id=\"{$itemID}\" name=\"{$this->name}\" type=\"radio\" value=\"{$key}\"{$checked} {$disabled} class=\"radio\" /> <label title=\"{$ATT_key}\" for=\"{$itemID}\">{$value}</label></li>\n";
}
// Add "custom" input field
$value = $this->value && !array_key_exists($this->value, $this->source) ? $this->value : null;
$checked = $value ? " checked=\"checked\"" : '';
$options .= "<li class=\"valCustom\">" . sprintf("<input id=\"%s_custom\" name=\"%s\" type=\"radio\" value=\"__custom__\" class=\"radio\" %s />", $itemID, $this->name, $checked) . sprintf('<label for="%s_custom">%s:</label>', $itemID, _t('MemberDatetimeOptionsetField.Custom', 'Custom')) . sprintf("<input class=\"customFormat\" name=\"%s_custom\" value=\"%s\" />\n", $this->name, $value) . sprintf("<input type=\"hidden\" class=\"formatValidationURL\" value=\"%s\" />", $this->Link() . '/validate');
$options .= $value ? sprintf('<span class="preview">(%s: "%s")</span>', _t('MemberDatetimeOptionsetField.Preview', 'Preview'), Zend_Date::now()->toString($value)) : '';
$options .= sprintf('<a class="cms-help-toggle" href="#%s">%s</a>', $this->id() . '_Help', _t('MemberDatetimeOptionsetField.TOGGLEHELP', 'Toggle formatting help'));
$options .= "<div id=\"" . $this->id() . "_Help\">";
$options .= $this->getFormattingHelpText();
$options .= "</div>";
$options .= "</li>\n";
$id = $this->id();
return "<ul id=\"{$id}\" class=\"optionset {$this->extraClass()}\">\n{$options}</ul>\n";
}
示例8: getHTMLFragments
public function getHTMLFragments($gridField)
{
$fragments = parent::getHTMLFragments($gridField);
$state = $gridField->getState(false);
$fragments['before'] .= '<input type="hidden" name="' . $gridField->getName() . '_skey" value="' . Convert::raw2att($gridField->getState(false)->getSessionKey()) . '"/>';
return $fragments;
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-statefulunsavedlist,代码行数:7,代码来源:StatefulGridFieldState.php
示例9: appendLink
/**
* Generates a <link /> element and appends it to a set of header tags
* @param string $tags The current tag string to append these to
* @param string $rel The rel attribute value
* @param string $link URL to the linked resource
* @param string $type Mime type of the resource, if known
*/
protected function appendLink(&$tags, $rel, $link, $type = null)
{
if (empty($rel) || empty($link)) {
return;
}
$tags .= sprintf("<link rel=\"%s\" href=\"%s\" type=\"%s\" />\n", Convert::raw2att($rel), Convert::raw2att($link), $type ? $type : $this->getMimeType($link));
}
示例10: getContent
/**
* @param string $content
* @return string
*/
public function getContent()
{
$doc = clone $this->getDocument();
$xp = new DOMXPath($doc);
// If there's no body, the content is empty string
if (!$doc->getElementsByTagName('body')->length) {
return '';
}
// saveHTML Percentage-encodes any URI-based attributes. We don't want this, since it interferes with
// shortcodes. So first, save all the attribute values for later restoration.
$attrs = array();
$i = 0;
foreach ($xp->query('//body//@*') as $attr) {
$key = "__HTMLVALUE_" . $i++;
$attrs[$key] = $attr->value;
$attr->value = $key;
}
// Then, call saveHTML & extract out the content from the body tag
$res = preg_replace(array('/^(.*?)<body>/is', '/<\\/body>(.*?)$/isD'), '', $doc->saveHTML());
// Then replace the saved attributes with their original versions
$res = preg_replace_callback('/__HTMLVALUE_(\\d+)/', function ($matches) use($attrs) {
return Convert::raw2att($attrs[$matches[0]]);
}, $res);
return $res;
}
示例11: MetaTags
/**
* 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
* @return string The XHTML metatags
*/
public function MetaTags($includeTitle = true)
{
$tags = "";
if ($includeTitle === true || $includeTitle == 'true') {
$tags .= "<title>" . Convert::raw2xml($this->Title) . "</title>\n";
}
$generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
if (!empty($generator)) {
$tags .= "<meta name=\"generator\" content=\"" . Convert::raw2att($generator) . "\" />\n";
}
$charset = Config::inst()->get('ContentNegotiator', '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";
}
if ($this->ExtraMeta) {
$tags .= $this->ExtraMeta . "\n";
}
if (Permission::check('CMS_ACCESS_CMSMain') && in_array('CMSPreviewable', class_implements($this)) && !$this instanceof ErrorPage) {
$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;
}
示例12: Field
public function Field($properties = array())
{
$content = '';
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(FRAMEWORK_DIR . "/javascript/ToggleField.js");
if ($this->startClosed) {
$this->addExtraClass('startClosed');
}
$valforInput = $this->value ? Convert::raw2att($this->value) : "";
$rawInput = Convert::html2raw($valforInput);
if ($this->charNum) {
$reducedVal = substr($rawInput, 0, $this->charNum);
} else {
$reducedVal = DBField::create_field('Text', $rawInput)->{$this->truncateMethod}();
}
// only create togglefield if the truncated content is shorter
if (strlen($reducedVal) < strlen($rawInput)) {
$content = <<<HTML
\t\t\t<div class="readonly typography contentLess" style="display: none">
\t\t\t\t{$reducedVal}
\t\t\t\t <a href="#" class="triggerMore">{$this->labelMore}</a>
\t\t\t</div>
\t\t\t<div class="readonly typography contentMore">
\t\t\t\t{$this->value}
\t\t\t\t <a href="#" class="triggerLess">{$this->labelLess}</a>
\t\t\t</div>\t
\t\t\t<br />
\t\t\t<input type="hidden" name="{$this->name}" value="{$valforInput}" />
HTML;
} else {
$this->dontEscape = true;
$content = parent::Field();
}
return $content;
}
示例13: redirectionLink
/**
* Return the link that we should redirect to.
* Only return a value if there is a legal redirection destination.
*/
function redirectionLink() {
if($this->RedirectionType == 'External') {
if($this->ExternalURL) {
return Convert::raw2att($this->ExternalURL);
}
} else {
$linkTo = $this->LinkToID ? DataObject::get_by_id("SiteTree", $this->LinkToID) : null;
if($linkTo) {
// We shouldn't point to ourselves - that would create an infinite loop! Return null since we have a
// bad configuration
if($this->ID == $linkTo->ID) {
return null;
// If we're linking to another redirectorpage then just return the URLSegment, to prevent a cycle of redirector
// pages from causing an infinite loop. Instead, they will cause a 30x redirection loop in the browser, but
// this can be handled sufficiently gracefully by the browser.
} elseif($linkTo instanceof RedirectorPage) {
return $linkTo->regularLink();
// For all other pages, just return the link of the page.
} else {
return $linkTo->Link();
}
}
}
}
示例14: childnodes
/**
* Request nodes from the server
*
* @param SS_HTTPRequest $request
* @return JSONString
*/
public function childnodes($request)
{
$data = array();
$rootObjectType = 'SiteTree';
if ($request->param('ID')) {
$rootObjectType = $request->param('ID');
}
if ($request->getVar('search')) {
return $this->performSearch($request->getVar('search'), $rootObjectType);
}
$parentId = $request->getVar('id');
if (!$parentId) {
$parentId = $rootObjectType . '-0';
}
$selectable = null;
if ($request->param('OtherID')) {
$selectable = explode(',', $request->param('OtherID'));
}
list($type, $id) = explode('-', $parentId);
if (!$type || $id < 0) {
$data = array(0 => array('data' => 'An error has occurred'));
} else {
$children = null;
if ($id == 0) {
$children = DataObject::get($rootObjectType, 'ParentID = 0');
} else {
$object = DataObject::get_by_id($type, $id);
$children = $this->childrenOfNode($object);
}
$data = array();
if ($children && count($children)) {
foreach ($children as $child) {
if ($child->ID < 0) {
continue;
}
$haskids = $child->numChildren() > 0;
$nodeData = array('title' => isset($child->MenuTitle) ? $child->MenuTitle : $child->Title);
if ($selectable && !in_array($child->ClassName, $selectable)) {
$nodeData['clickable'] = false;
}
$thumbs = null;
if ($child->ClassName == 'Image') {
$thumbs = $this->generateThumbnails($child);
$nodeData['icon'] = $thumbs['x16'];
} else {
if (!$haskids) {
$nodeData['icon'] = 'frontend-editing/images/page.png';
}
}
$nodeEntry = array('attributes' => array('id' => $child->ClassName . '-' . $child->ID, 'title' => Convert::raw2att($nodeData['title']), 'link' => $child->RelativeLink()), 'data' => $nodeData, 'state' => $haskids ? 'closed' : 'open');
if ($thumbs) {
$nodeEntry['thumbs'] = $thumbs;
}
$data[] = $nodeEntry;
}
}
}
return Convert::raw2json($data);
}
开发者ID:helpfulrobot,项目名称:silverstripe-australia-frontend-editing,代码行数:65,代码来源:SimpleTreeController.php
示例15: HolderAttributes
/**
* Returns the list of attributes suitable for an HTML tag
*
* @return string
*/
public function HolderAttributes()
{
$ret = "";
foreach ($this->holderAttributes as $k => $v) {
$ret .= "{$k}=\"" . Convert::raw2att($v) . "\" ";
}
return $ret;
}