/**
  * @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 &nbsp; being encoded as literal utf-8 characters
     // Possible alternative solution: http://stackoverflow.com/questions/2142120/php-encoding-with-domdocument
     $from = mb_convert_encoding('&nbsp;', 'utf-8', 'html-entities');
     $res = str_replace($from, '&nbsp;', $res);
     return $res;
 }
 /**
  * Tests {@link Convert::raw2att()}
  */
 public function testRaw2Att()
 {
     $val1 = '<input type="text">';
     $this->assertEquals('&lt;input type=&quot;text&quot;&gt;', 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');
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
 /**
  * @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);
 }
Exemplo n.º 5
0
 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} />";
 }
 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;
 }
 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";
 }
 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;
 }
 /**
  * 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));
 }
Exemplo n.º 10
0
 /**
  * @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;
 }
 /**
  * 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;
 }
Exemplo n.º 12
0
    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&nbsp;<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&nbsp;<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;
    }
Exemplo n.º 13
0
	/**
	 * 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();
				}
			}
		}
	}
 /**
  * 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);
 }
 /**
  * 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;
 }
 public function Image($url, $alt = '')
 {
     $altattr = Convert::raw2att($alt);
     $imageSRC = Convert::raw2att(Director::absoluteURL($url));
     $width = $this->getWidth($url);
     $height = $this->getHeight($url);
     return "<img\n\t\t\t\tborder=\"0\"\n\t\t\t\tsrc=\"{$imageSRC}\"\n\t\t\t\twidth=\"{$width}\"\n\t\t\t\theight=\"{$height}\"\n\t\t\t\talt=\"{$altattr}\"\n\t\t\t/>";
 }
 public function Field($properties = array())
 {
     $url = Convert::raw2att($this->validateURL);
     if ($this->restrictedRegex) {
         $restrict = "<input type=\"hidden\" class=\"hidden\" name=\"{$this->name}Restricted\" id=\"" . $this->id() . "RestrictedRegex\" value=\"{$this->restrictedRegex}\" />";
     }
     $attributes = array('type' => 'text', 'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), 'name' => $this->getName(), 'value' => $this->Value(), 'tabindex' => $this->getAttribute('tabindex'), 'maxlength' => $this->maxLength ? $this->maxLength : null);
     return FormField::create_tag('input', $attributes);
 }
Exemplo n.º 18
0
 public function getDataAttributes()
 {
     $attributes = "";
     $this->options['url'] = $this->calendar->Link();
     foreach ($this->options as $opt => $value) {
         $attributes .= sprintf('data-%s="%s" ', $opt, Convert::raw2att($value));
     }
     return $attributes;
 }
 public function columns()
 {
     return array("Created" => "Checked", 'Link' => array('title' => 'External Link', 'formatting' => function ($value, $item) {
         return sprintf('<a target="_blank" href="%s">%s</a>', Convert::raw2att($item->Link), Convert::raw2xml($item->Link));
     }), 'HTTPCodeDescription' => 'HTTP Error Code', "Title" => array("title" => 'Page link is on', 'formatting' => function ($value, $item) {
         $page = $item->Page();
         return sprintf('<a href="%s">%s</a>', Convert::raw2att($page->CMSEditLink()), Convert::raw2xml($page->Title));
     }));
 }
Exemplo n.º 20
0
 public function close()
 {
     $id = $this->getVar($this->attributes['name'] . 'ID');
     if (!$id) {
         return;
     }
     $image = DataObject::get_by_id('Image', $id);
     if ($image) {
         /* image specific attribute handling */
         if (!empty($this->attributes['width'])) {
             $newimage = $image->setWidth($this->attributes['width']);
             if ($newimage) {
                 $image = $newimage;
             }
         }
         if (!empty($this->attributes['height'])) {
             $newimage = $image->setHeight($this->attributes['height']);
             if ($newimage) {
                 $image = $newimage;
             }
         }
         $path = $image->Filename;
         $url = $image->getURL();
         if (strpos($url, 'http://') !== 0) {
             $url = '/' . ltrim($url, '/');
         }
         /*				if(substr($path,0,1) !== '/') 
         					$path = HOME_PATH . '/../userhomes/' . NSite::current_site()->PathName . '/' . $path;
         
         				$url = '/' . ltrim(Director::makeRelative(realpath($path)), '/');
         			}
         */
         if (file_exists($path)) {
             if (parse_url($url, PHP_URL_HOST) == '') {
                 // Convert relative url to absolute
                 $url = Director::protocolAndHost() . '/' . $url;
             }
             $title = $image->Title ? $image->Title : $image->Filename;
             if ($title) {
                 $title = Convert::raw2att($title);
             } else {
                 if (preg_match("/([^\\/]*)\\.[a-zA-Z0-9]{1,6}\$/", $title, $matches)) {
                     $title = Convert::raw2att($matches[1]);
                 }
             }
             echo "<img src=\"{$url}\" alt=\"{$title}\"";
             $copy_attributes = array('style', 'align');
             foreach ($copy_attributes as $name) {
                 if (isset($this->attributes[$name])) {
                     echo ' ' . $name . '="' . Convert::raw2att($this->attributes[$name]) . '"';
                 }
             }
             echo " />";
         }
     }
 }
 /**
  * Generate an HTML list which provides links to where a file is used.
  *
  * @return string
  */
 public function BackLinkHTMLList()
 {
     $html = '<em>' . _t('SiteTreeFileExtension.BACKLINK_LIST_DESCRIPTION', 'This list shows all pages where the file has been added through a WYSIWYG editor.') . '</em>';
     $html .= '<ul>';
     foreach ($this->BackLinkTracking() as $backLink) {
         // Add the page link and CMS link
         $html .= sprintf('<li><a href="%s" target="_blank">%s</a> &ndash; <a href="%s">%s</a></li>', Convert::raw2att($backLink->Link()), Convert::raw2xml($backLink->MenuTitle), Convert::raw2att($backLink->CMSEditLink()), _t('SiteTreeFileExtension.EDIT', 'Edit'));
     }
     return $html .= '</ul>';
 }
 public function Image($url, $alt = '')
 {
     $id = uniqid();
     $altattr = Convert::raw2att($alt);
     $width = $this->getWidth($url);
     $height = $this->getHeight($url);
     $filename = $this->useFile($url);
     $localPath = $this->foldername . '/' . $filename;
     $absPath = Director::absoluteURL($url);
     return "<!--[if gte vml 1]>\n\t\t\t\t<v:shape id=\"{$id}\" type=\"#_x0000_t75\" alt=\"{$altattr}\" style='width:{$width};height:{$height}'>\n\t\t\t\t\t<v:imagedata src=\"{$localPath}\" o:href=\"{$absPath}\" />\n\t\t\t\t</v:shape>\n\t\t\t<![endif]-->\n\t\t\t<![if !vml]>\n\t\t\t\t<img border=0 width=\"{$width}\" height=\"{$height}\" src=\"{$localPath}\" alt=\"{$altattr}\" v:shapes=\"{$id}\">\n\t\t\t<![endif]>";
 }
 /**
  * Generate metadata elements.
  *
  * @param int $context As in PaginatedList::PaginationSummary, how many pages 
  *		are to be displayed around the currently active page.
  * @param string $pjaxHeader Enable PJAX fetching with the assigned header.
  */
 function PaginationMetadata($context = null, $pjaxHeader = null)
 {
     $meta = 'data-page-start="' . (int) $this->getPageStart() . '" ' . 'data-page-length="' . (int) $this->getPageLength() . '" ' . 'data-total-items="' . (int) $this->getTotalItems() . '" ' . 'data-get-param="' . Convert::raw2att($this->getPaginationGetVar()) . '"';
     if ($context) {
         $meta .= ' data-context="' . (int) $context . '"';
     }
     if ($this->getPjaxHeader()) {
         $meta .= ' data-pjax-header="' . Convert::raw2att($this->getPjaxHeader()) . '"';
     }
     return $meta;
 }
Exemplo n.º 24
0
 function Link()
 {
     if ($this->RedirectionType == 'External') {
         return Convert::raw2att($this->ExternalURL);
     } else {
         $linkTo = $this->LinkToID ? DataObject::get_by_id("SiteTree", $this->LinkToID) : null;
         if ($linkTo) {
             return $linkTo->Link();
         }
     }
 }
Exemplo n.º 25
0
 public function Field($properties = array())
 {
     Requirements::javascript('pixlr/javascript/pixlr.js');
     Requirements::javascript('pixlr/javascript/pixlr.jquery.js');
     Requirements::javascript('pixlr/javascript/pixlr-image-field.js');
     $fieldAttributes = array('id' => $this->id(), 'class' => 'pixlrTrigger', 'value' => Convert::raw2att($this->label), 'type' => 'button');
     $targetUrl = strlen($this->targetUrl) ? $this->targetUrl : Director::absoluteURL('pixlr/saveimage');
     $exitUrl = strlen($this->exitUrl) ? $this->exitUrl : Director::absoluteURL('pixlr/closepixlr');
     // now add any additional parameters onto the end of the target string
     $sep = strpos($targetUrl, '?') ? '&amp;' : '?';
     foreach ($this->returnParams as $param => $v) {
         $targetUrl .= $sep . $param . '=' . $v;
         $sep = '&';
     }
     $loc = ($m = Member::currentUser()) ? i18n::get_lang_from_locale($m->Locale) : 'en';
     $title = isset($this->returnParams['title']) ? $this->returnParams['title'] : 'New Image';
     $opts = array('referrer' => Convert::raw2js('SilverStripe CMS'), 'loc' => $loc, 'title' => $this->value && is_object($this->value) ? Convert::raw2js($this->value->Name) : $title, 'locktarget' => 'true', 'exit' => $exitUrl, 'target' => $targetUrl, 'method' => 'get', 'copy' => false);
     // where should we open the editor? as in, which window is it rooted in?
     $openin = 'window';
     if ($this->value) {
         if ($this->config()->use_credentials) {
             $opts['credentials'] = 'true';
             $opts['image'] = Convert::raw2js(Director::absoluteBaseURL() . $this->value->Filename);
         } else {
             // need to post the image to their server first, so we'll stick the image ID into the
             // page, and let the jquery plugin handle uploading it to pixlr first
             if (is_object($this->value)) {
                 $opts['id'] = $this->value->ID;
             } else {
                 $opts['id'] = $this->value;
             }
             $opts['preload'] = Director::absoluteURL('pixlr/sendimage');
             // In silverstripe, when editing an image it actually occurs in an iframe popup contained within
             // another iframe. Because we want the editor to appear mounted in the top level window,
             // we have to explicitly add it to the correct location
             //				$openin = 'window.parent.parent';
         }
         $opts['locktitle'] = 'true';
         $opts['mode'] = 'popup';
     }
     $opts['service'] = $this->editorMode;
     //		$opts = Convert::raw2json($opts);
     $opts['openobjname'] = $openin;
     $fieldAttributes['data-pixlr-editor'] = json_encode($opts);
     //		$script = <<<JSCRIPT
     //jQuery().ready(function () {
     //var opts = $opts;
     //opts.openin = $openin;
     //jQuery('#{$this->id()}').pixlrize(opts);
     //});
     //JSCRIPT;
     //		Requirements::customScript($script, 'pixlr-'.$this->id());
     return $this->createTag('input', $fieldAttributes);
 }
 public function Link()
 {
     if (self::$use_js_tracking) {
         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
         Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
         Requirements::javascript('advertisements/javascript/advertisements.js');
         $link = Convert::raw2att($this->InternalPageID ? $this->InternalPage()->AbsoluteLink() : $this->TargetURL);
     } else {
         $link = Controller::join_links(Director::baseURL(), 'adclick/go/' . $this->ID);
     }
     return $link;
 }
Exemplo n.º 27
0
 function TitleField()
 {
     // return new TextField( "Fields[".$this->ID."][Title]", null, $this->Title );
     $titleAttr = Convert::raw2att($this->Title);
     $readOnlyAttr = '';
     if ($this->readonly) {
         $readOnlyAttr = ' disabled="disabled"';
     } else {
         $readOnlyAttr = '';
     }
     return "<input type=\"text\" class=\"text\" title=\"(" . _t('EditableFormField.ENTERQUESTION', 'Enter Question') . ")\" value=\"{$titleAttr}\" name=\"Fields[{$this->ID}][Title]\"{$readOnlyAttr} />";
 }
 /**
  * Gets the fields for displaying in the cms
  * @param {string} $url Vidyard Video URL
  * @param {VidyardInsertMedia_Embed} $file Vidyard Insert Media Embed Object
  * @return {FieldList} Field List of fields used in the cms
  */
 protected function getFieldsForVidyard($url, VidyardInsertMedia_Embed $file)
 {
     $thumbnailURL = Convert::raw2att($file->Oembed->thumbnail_url);
     $fileName = Convert::raw2att($file->Name);
     $fields = new FieldList($filePreview = CompositeField::create(CompositeField::create(new LiteralField("ImageFull", "<img id='thumbnailImage' class='thumbnail-preview' " . "src='{$thumbnailURL}?r=" . rand(1, 100000) . "' alt='{$fileName}' />\n"))->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'), CompositeField::create(CompositeField::create(new ReadonlyField("FileType", _t('AssetTableField.TYPE', 'File type') . ':', $file->Type), $urlField = ReadonlyField::create('ClickableURL', _t('AssetTableField.URL', 'URL'), sprintf('<a href="%s" target="_blank" class="file">%s</a>', Convert::raw2att($url), Convert::raw2att($url)))->addExtraClass('text-wrap')))->setName("FilePreviewData")->addExtraClass('cms-file-info-data'))->setName("FilePreview")->addExtraClass('cms-file-info'), DropdownField::create('CSSClass', _t('HtmlEditorField.CSSCLASS', 'Alignment / style'), array('leftAlone' => _t('HtmlEditorField.CSSCLASSLEFTALONE', 'On the left, on its own.'), 'center' => _t('HtmlEditorField.CSSCLASSCENTER', 'Centered, on its own.'), 'left' => _t('HtmlEditorField.CSSCLASSLEFT', 'On the left, with text wrapping around.'), 'right' => _t('HtmlEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.')))->addExtraClass('last'), new CheckboxField('UseLightbox', _t('VidyardInsertMedia.USE_LIGHTBOX', '_Use the Lightbox Display')));
     if ($file->Width != null) {
         $fields->push(FieldGroup::create(_t('HtmlEditorField.IMAGEDIMENSIONS', 'Dimensions'), TextField::create('Width', _t('HtmlEditorField.IMAGEWIDTHPX', 'Width'), $file->InsertWidth)->setMaxLength(5), TextField::create('Height', _t('HtmlEditorField.IMAGEHEIGHTPX', 'Height'), $file->InsertHeight)->setMaxLength(5))->addExtraClass('dimensions last'));
     }
     $urlField->dontEscape = true;
     $fields->push(new HiddenField('URL', false, $file->getURL()));
     return $fields;
 }
 public function getHTMLFragments($gridField)
 {
     $singleton = singleton($gridField->getModelClass());
     if (!$singleton->canCreate() || !singleton('SiteTree')->canCreate()) {
         return [];
     }
     if (!$this->buttonName) {
         // provide a default button name, can be changed by calling {@link setButtonName()} on this component
         $this->buttonName = _t('Link.COPY_CHILDREN_FROM_ROOT', 'Copy children from root');
     }
     return [$this->targetFragment => \GridField_FormAction::create($gridField, 'CopyChildrenFromRoot-' . \Convert::raw2att($this->urlSegment), $this->buttonName, $this->urlSegment, [])->addExtraClass('gridfield-button-copyChildrenFromRoot')->setAttribute('title', $this->buttonName)->setDescription($this->buttonName)->Field()];
 }
Exemplo n.º 30
0
 function Field()
 {
     Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
     Requirements::javascript(SAPPHIRE_DIR . "/javascript/UniqueFields.js");
     $this->jsValidation();
     $url = Convert::raw2att($this->validateURL);
     if ($this->restrictedRegex) {
         $restrict = "<input type=\"hidden\" class=\"hidden\" name=\"{$this->name}Restricted\" id=\"" . $this->id() . "RestrictedRegex\" value=\"{$this->restrictedRegex}\" />";
     }
     $attributes = array('type' => 'text', 'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), 'name' => $this->Name(), 'value' => $this->Value(), 'tabindex' => $this->getTabIndex(), 'maxlength' => $this->maxLength ? $this->maxLength : null);
     return $this->createTag('input', $attributes);
 }