public function GlobalNav()
 {
     Requirements::css(Controller::join_links(GlobalNavSiteTreeExtension::get_toolbar_hostname(), Config::inst()->get('GlobalNav', 'css_path')));
     $html = DBField::create_field('HTMLText', $this->globalNav);
     $html->setOptions(array('shortcodes' => false));
     return $html;
 }
Beispiel #2
0
 public function testNice()
 {
     $time = DBField::create_field('Time', '17:15:55');
     $this->assertEquals('5:15pm', $time->Nice());
     Config::inst()->update('Time', 'nice_format', 'H:i:s');
     $this->assertEquals('17:15:55', $time->Nice());
 }
 function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if (!$this->DispatchedOn) {
         $this->DispatchedOn = DBField::create_field('Date', date('Y-m-d'));
     }
 }
 /**
  * Parses the snippet short code
  * @example [snippet id=123]
  * @example [snippet id=123 version=456]
  */
 public static function parse($arguments, $content = null, $parser = null)
 {
     //Ensure ID is pressent in the arguments
     if (!array_key_exists('id', $arguments)) {
         return '<p><b><i>' . _t('CodeBankShortCode.MISSING_ID_ATTRIBUTE', '_Short Code missing the id attribute') . '</i></b></p>';
     }
     //Fetch Snippet
     $snippet = Snippet::get()->byID(intval($arguments['id']));
     if (empty($snippet) || $snippet === false || $snippet->ID == 0) {
         return '<p><b><i>' . _t('CodeBankShortCode.SNIPPET_NOT_FOUND', '_Snippet not found') . '</i></b></p>';
     }
     //Fetch Text
     $snippetText = $snippet->SnippetText;
     //If the version exists fetch it, and replace the text with that of the version
     if (array_key_exists('version', $arguments)) {
         $version = $snippet->Version(intval($arguments['version']));
         if (empty($version) || $version === false || $version->ID == 0) {
             $snippetText = $version->Text;
         }
     }
     //Load CSS Requirements
     Requirements::css(CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCore.css');
     Requirements::css(CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCoreDefault.css');
     Requirements::css(CB_DIR . '/javascript/external/syntaxhighlighter/themes/shThemeDefault.css');
     //Load JS Requirements
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(CB_DIR . '/javascript/external/syntaxhighlighter/brushes/shCore.js');
     Requirements::javascript(CB_DIR . '/javascript/external/syntaxhighlighter/brushes/' . self::getBrushName($snippet->Language()->HighlightCode) . '.js');
     Requirements::javascriptTemplate(CB_DIR . '/javascript/CodeBankShortCode.template.js', array('ID' => $snippet->ID), 'snippet-highlightinit-' . $snippet->ID);
     //Render the snippet
     $obj = new ViewableData();
     return $obj->renderWith('CodeBankShortCode', array('ID' => $snippet->ID, 'Title' => $snippet->getField('Title'), 'Description' => $snippet->getField('Description'), 'SnippetText' => DBField::create_field('Text', $snippetText), 'HighlightCode' => strtolower($snippet->Language()->HighlightCode)));
 }
 public function Tweets()
 {
     $twitterApp = TwitterApp::get()->first();
     if (!$twitterApp) {
         return null;
     }
     $siteConfig = SiteConfig::current_site_config();
     $twitter = $twitterApp->getTwitter();
     $twitter->setAccess(new OAuthToken($twitterApp->TwitterAccessToken, $twitterApp->TwitterAccessSecret));
     if ($twitter->hasAccess()) {
         $result = $twitter->api("1.1/statuses/user_timeline.json", "GET", array("screen_name" => $this->TwitterHandle, "count" => $this->NumberOfTweets));
         if ($result->statusCode() == 200) {
             $rawTweets = json_decode($result->body(), true);
             if (count($rawTweets) > 0) {
                 $tweets = new ArrayList();
                 foreach ($rawTweets as $tweet) {
                     // Parse tweet links, users and hashtags.
                     $parsed = preg_replace("#(^|[\n ])([\\w]+?://[\\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" target=\"_blank\">\\2</a>'", $tweet['text']);
                     $parsed = preg_replace("#(^|[\n ])@([A-Za-z0-9\\_]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" target=\"_blank\">@\\2</a>'", $parsed);
                     $parsed = preg_replace("#(^|[\n ])\\#([A-Za-z0-9]*)#ise", "'\\1<a href=\"http://www.twitter.com/search?q=\\2\" target=\"_blank\">#\\2</a>'", $parsed);
                     $t = new ArrayData(array());
                     $t->Tweet = DBField::create_field("HTMLText", $parsed, "Tweet");
                     $t->TweetDate = DBField::create_field("SS_Datetime", strtotime($tweet['created_at']));
                     $t->TweetLink = DBField::create_field("Varchar", "http://www.twitter.com/" . rawurlencode($tweet['user']['screen_name']) . "/status/" . rawurlencode($tweet['id_str']));
                     $tweets->push($t);
                 }
                 return $tweets;
             }
         }
     }
     return null;
 }
 /**
  * Get a set of content languages (for quick language navigation)
  * @example
  * <code>
  * <!-- in your template -->
  * <ul class="langNav">
  * 		<% loop Languages %>
  * 		<li><a href="$Link" class="$LinkingMode" title="$Title.ATT">$Language</a></li>
  * 		<% end_loop %>
  * </ul>
  * </code>
  *
  * @return ArrayList|null
  */
 public function Languages()
 {
     $locales = TranslatableUtility::get_content_languages();
     // there's no need to show a navigation when there's less than 2 languages. So return null
     if (count($locales) < 2) {
         return null;
     }
     $currentLocale = Translatable::get_current_locale();
     $homeTranslated = null;
     if ($home = SiteTree::get_by_link('home')) {
         /** @var SiteTree $homeTranslated */
         $homeTranslated = $home->getTranslation($currentLocale);
     }
     /** @var ArrayList $langSet */
     $langSet = ArrayList::create();
     foreach ($locales as $locale => $name) {
         Translatable::set_current_locale($locale);
         /** @var SiteTree $translation */
         $translation = $this->owner->hasTranslation($locale) ? $this->owner->getTranslation($locale) : null;
         $langSet->push(new ArrayData(array('Locale' => $locale, 'RFC1766' => i18n::convert_rfc1766($locale), 'Language' => DBField::create_field('Varchar', strtoupper(i18n::get_lang_from_locale($locale))), 'Title' => DBField::create_field('Varchar', html_entity_decode(i18n::get_language_name(i18n::get_lang_from_locale($locale), true), ENT_NOQUOTES, 'UTF-8')), 'LinkingMode' => $currentLocale == $locale ? 'current' : 'link', 'Link' => $translation ? $translation->AbsoluteLink() : ($homeTranslated ? $homeTranslated->Link() : ''))));
     }
     Translatable::set_current_locale($currentLocale);
     i18n::set_locale($currentLocale);
     return $langSet;
 }
 /**
  * @param   $key The nav key, e.g. "doc", "userhelp"
  * @return HTMLText
  */
 public static function GlobalNav($key)
 {
     $baseURL = GlobalNavSiteTreeExtension::get_toolbar_baseurl();
     Requirements::css(Controller::join_links($baseURL, Config::inst()->get('GlobalNav', 'css_path')));
     // If this method haven't been called before, get the toolbar and cache it
     if (self::$global_nav_html === null) {
         // Set the default to empty
         self::$global_nav_html = '';
         // Prevent recursion from happening
         if (empty($_GET['globaltoolbar'])) {
             $host = GlobalNavSiteTreeExtension::get_toolbar_hostname();
             $path = Director::makeRelative(GlobalNavSiteTreeExtension::get_navbar_filename($key));
             if (Config::inst()->get('GlobalNav', 'use_localhost')) {
                 self::$global_nav_html = file_get_contents(BASE_PATH . $path);
             } else {
                 $url = Controller::join_links($baseURL, $path, '?globaltoolbar=true');
                 $connectionTimeout = Config::inst()->get('GlobalNavTemplateProvider', 'connection_timeout');
                 $transferTimeout = Config::inst()->get('GlobalNavTemplateProvider', 'transfer_timeout');
                 // Get the HTML and cache it
                 self::$global_nav_html = self::curl_call($url, $connectionTimeout, $transferTimeout);
             }
         }
     }
     $html = DBField::create_field('HTMLText', self::$global_nav_html);
     $html->setOptions(array('shortcodes' => false));
     return $html;
 }
 protected function renderRows($rows, ArrayIterator $splitcontent, &$pos = -1)
 {
     $output = "";
     $rownumber = 0;
     foreach ($rows as $row) {
         if ($row->cols) {
             $columns = array();
             foreach ($row->cols as $col) {
                 $nextcontent = $splitcontent->current();
                 $isholder = !isset($col->rows);
                 if ($isholder) {
                     $splitcontent->next();
                     //advance iterator if there are no sub-rows
                     $pos++;
                     //wrap split content in a HTMLText object
                     $dbObject = DBField::create_field('HTMLText', $nextcontent, "Content");
                     $dbObject->setOptions(array("shortcodes" => true));
                     $nextcontent = $dbObject;
                 }
                 $width = $col->width ? (int) $col->width : 1;
                 //width is at least 1
                 $columns[] = new ArrayData(array("Width" => $width, "EnglishWidth" => $this->englishWidth($width), "Content" => $isholder ? $nextcontent : $this->renderRows($col->rows, $splitcontent, $pos), "IsHolder" => $isholder, "GridPos" => $pos, "ExtraClasses" => isset($col->extraclasses) ? $col->extraclasses : null));
             }
             $output .= ArrayData::create(array("Columns" => new ArrayList($columns), "RowNumber" => (string) $rownumber++, "ExtraClasses" => isset($row->extraclasses) ? $row->extraclasses : null))->renderWith($this->template);
         } else {
             //every row should have columns!!
         }
     }
     return $output;
 }
Beispiel #9
0
 protected function handlePost(array $data, $settings = [])
 {
     $post = ['ID' => isset($data['id']) && isset($data['id']['videoId']) ? $data['id']['videoId'] : '0', 'Author' => isset($data['snippet']) && isset($data['snippet']['channelTitle']) ? \FormField::name_to_label($data['snippet']['channelTitle']) : '', 'AuthorID' => isset($data['snippet']) && isset($data['snippet']['channelId']) ? $data['snippet']['channelId'] : 0, 'AuthorURL' => isset($data['snippet']) && isset($data['snippet']['channelId']) ? \Controller::join_links($this->url, 'channel', $data['snippet']['channelId']) : '', 'Title' => isset($data['snippet']) && isset($data['snippet']['title']) ? $data['snippet']['title'] : '', 'Content' => isset($data['snippet']) && isset($data['snippet']['description']) ? $this->textParser()->text($data['snippet']['description']) : '', 'Priority' => isset($data['snippet']) && isset($data['snippet']['publishedAt']) ? strtotime($data['snippet']['publishedAt']) : 0, 'Posted' => isset($data['snippet']) && isset($data['snippet']['publishedAt']) ? \DBField::create_field('SS_Datetime', strtotime($data['snippet']['publishedAt'])) : null];
     if (isset($data['snippet']) && isset($data['snippet']['thumbnails'])) {
         if (isset($data['snippet']['thumbnails']['high']) && isset($data['snippet']['thumbnails']['high']['url'])) {
             $post['Cover'] = $data['snippet']['thumbnails']['high']['url'];
         } else {
             if (isset($data['snippet']['thumbnails']['medium']) && isset($data['snippet']['thumbnails']['medium']['url'])) {
                 $post['Cover'] = $data['snippet']['thumbnails']['medium']['url'];
             } else {
                 if (isset($data['snippet']['thumbnails']['default']) && isset($data['snippet']['thumbnails']['default']['url'])) {
                     $post['Cover'] = $data['snippet']['thumbnails']['default']['url'];
                 }
             }
         }
     }
     if ($post['ID']) {
         $params = (array) singleton('env')->get('Youtube.video_params');
         if (isset($settings['videoParams'])) {
             $params = array_merge($params, (array) $settings['videoParams']);
         }
         $params['v'] = $post['ID'];
         $post['Link'] = \Controller::join_links($this->url, 'watch', '?' . http_build_query($params));
         $this->setFromEmbed($post);
     }
     if (isset($post['ObjectDescription']) && $post['ObjectDescription'] == $post['Content']) {
         unset($post['ObjectDescription']);
     }
     if (isset($post['Description']) && $post['Description'] == $post['Content']) {
         unset($post['Description']);
     }
     return $post;
 }
    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;
    }
 public function getEventsAction(SS_HTTPRequest $request)
 {
     // Search date
     $date = DBField::create_field("SS_Datetime", $request->param("SearchDate"));
     if (!$date->getValue()) {
         $date = SS_Datetime::now();
     }
     // Get event data
     $cache = SS_Cache::factory(self::EVENTS_CACHE_NAME);
     $cacheKey = $date->Format('Y_m_d');
     if ($result = $cache->load($cacheKey)) {
         $data = unserialize($result);
     } else {
         $data = EventsDataUtil::get_events_data_for_day($date);
         $cache->save(serialize($data), $cacheKey);
     }
     // Get init data
     if ($request->param("GetAppConfig")) {
         $cache = SS_Cache::factory(self::CONFIG_CACHE_NAME);
         $cacheKey = 'APP_CONFIG';
         if ($result = $cache->load($cacheKey)) {
             $configData = unserialize($result);
         } else {
             $configData = AppConfigDataUtil::get_config_data();
             $cache->save(serialize($configData), $cacheKey);
         }
         $data['appConfig'] = $configData;
     }
     return $this->sendResponse($data);
 }
 /** 
  * @return HTMLText
  */
 public function getPostContent($post)
 {
     $text = isset($post->text) ? $post->text : '';
     $text = preg_replace('/(https?:\\/\\/[a-z0-9\\.\\/]+)/i', '<a href="$1" target="_blank">$1</a>', $text);
     $result = DBField::create_field('HTMLText', $text);
     return $result;
 }
 public function writeToManipulation(&$manipulation)
 {
     // Write ID, checking that the value is valid
     $manipulation['fields'][$this->name . 'ID'] = $this->exists() ? $this->prepValueForDB($this->getIDValue()) : $this->nullValue();
     // Write class
     $classObject = DBField::create_field('Enum', $this->getClassValue(), $this->name . 'Class');
     $classObject->writeToManipulation($manipulation);
 }
 /**
  * @return SS_Datetime
  */
 public function ConfirmTimeLimit()
 {
     $unconfirmed = $this->Status == 'Unconfirmed';
     $limit = $this->Time()->Event()->ConfirmTimeLimit;
     if ($unconfirmed && $limit) {
         return DBField::create_field('SS_Datetime', strtotime($this->Created) + $limit);
     }
 }
 /**
  * @return string Date time string of next run for this task
  */
 public function getNextRun()
 {
     if (!$this->isEnabled()) {
         return '';
     }
     $cron = CronExpression::factory($this->ScheduleString);
     return DBField::create_field('SS_Datetime', $cron->getNextRunDate()->Format('U'))->getValue();
 }
 /**
  * Converts an array of tweets into a template-compatible format
  * 
  * @param array $tweets
  * @return ArrayList
  */
 protected function viewableTweets($tweets)
 {
     $items = new ArrayList();
     foreach ($tweets as $tweet) {
         $tweet['DateObject'] = DBField::create_field('SS_DateTime', $tweet['Date']);
         $items->push(new ArrayData($tweet));
     }
     return $items;
 }
 function getIcon()
 {
     $icon = $this->AlternativeIcon();
     if ($icon->exists()) {
         return $icon->SetHeight(16);
     }
     $html = '<img src="' . SS_SHARETHIS_DIR . '/images/icons/' . strtolower($this->Title) . ".png\" alt=\"{$this->Title}\"/>";
     return DBField::create_field("HTMLText", $html);
 }
 /**
  * Initialise the controller
  */
 function init()
 {
     Requirements::themedCSS('Forum', 'forum', 'all');
     $member = $this->Member() ? $this->Member() : null;
     $nicknameText = $member ? $member->Nickname . '\'s ' : '';
     //$this->Title = DBField::create('HTMLText',Convert::raw2xml($nicknameText) . _t('ForumMemberProfile.USERPROFILE', 'User Profile'));
     $this->Title = DBField::create_field('HTMLText', Convert::raw2xml($nicknameText) . _t('ForumMemberProfile.USERPROFILE', 'User Profile'));
     parent::init();
 }
 /**
  * @param string $entity
  * @param string $string
  * @param array $injectionArray
  * @return string
  */
 public static function dt($entity, $string = '', $injectionArray = array())
 {
     $adapter = static::get_translation_adapter();
     $translated = $adapter->translate($entity, $string, $injectionArray);
     // Don't escape HTML tags
     $field = DBField::create_field('HTMLText', $translated);
     $field->setOptions(array('shortcodes' => false));
     return $field;
 }
 public function writeToManipulation(&$manipulation)
 {
     if ($this->getAddress()) {
         $manipulation['fields'][$this->name . 'Address'] = $this->prepValueForDB($this->getAddress());
     } else {
         $manipulation['fields'][$this->name . 'Address'] = DBField::create_field('Varchar', $this->getAddress())->nullValue();
     }
     parent::writeToManipulation($manipulation);
 }
 /**
  * Return the current search query.
  *
  * @return HTMLText|null
  */
 public function getSearchQuery()
 {
     if (isset($_REQUEST['Search'])) {
         return DBField::create_field('HTMLText', $_REQUEST['Search']);
     } else {
         if (isset($_REQUEST['q'])) {
             return DBField::create_field('HTMLText', $_REQUEST['q']);
         }
     }
 }
 public function testSafelyCast()
 {
     $field1 = new OptionsetField('Options', 'Options', array(1 => 'One', 2 => 'Two & Three', 3 => DBField::create_field('HTMLText', 'Four &amp; Five &amp; Six')));
     $fieldHTML = (string) $field1->Field();
     $this->assertContains('One', $fieldHTML);
     $this->assertContains('Two &amp; Three', $fieldHTML);
     $this->assertNotContains('Two & Three', $fieldHTML);
     $this->assertContains('Four &amp; Five &amp; Six', $fieldHTML);
     $this->assertNotContains('Four & Five & Six', $fieldHTML);
 }
 function getIconHTML()
 {
     $icon = $this->Icon();
     if ($icon && $icon->exists()) {
         $html = $icon->SetHeight(32);
     } else {
         $html = DBField::create_field("HTMLText", '<img src="/' . SS_SHARETHIS_DIR . "/images/icons/{$this->Code}.png\" alt=\"{$this->Code}\"/>");
     }
     return $html;
 }
Beispiel #24
0
 public function writeToManipulation(&$manipulation)
 {
     foreach ($this->config()->composite_db as $point => $type) {
         if ($this->{$point}) {
             $manipulation['fields'][$this->name . $point] = \DBField::create_field($type, $this->{$point})->prepValueForDB($this->{$point});
         } else {
             $manipulation['fields'][$this->name . $point] = \DBField::create_field($type, $this->{$point})->nullValue();
         }
     }
 }
Beispiel #25
0
 /**
  * Return the value of this field for inclusion into things such as 
  * reports.
  * 
  * @return string
  */
 public function getFormattedValue()
 {
     $name = $this->getName();
     $link = $this->getLink();
     $title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
     if ($link) {
         return DBField::create_field('HTMLText', sprintf('%s - <a href="%s" target="_blank">%s</a>', $name, $link, $title));
     }
     return false;
 }
 /**
  * @return SS_Datetime
  */
 public function getExpiryDateTime()
 {
     if ($this->getSession()->RegistrationID) {
         $created = strtotime($this->getSession()->Registration()->Created);
         $limit = $this->controller->getDateTime()->Event()->RegistrationTimeLimit;
         if ($limit) {
             return DBField::create_field('SS_Datetime', $created + $limit);
         }
     }
 }
 /**
  * @return Date
  */
 public function process($value, $record)
 {
     switch ($this->Type) {
         case 'datetime':
             return DBField::create_field('SS_Datetime', $value);
         case 'date':
             return DBField::create_field('Date', $value);
         case 'time':
             return DBField::create_field('Time', $value);
     }
 }
 public static function toArray(ISummitPackage $package)
 {
     $res = array();
     $res['id'] = (int) $package->getIdentifier();
     $res['title'] = $package->Title;
     $res['cost'] = DBField::create_field('Currency', $package->Cost)->Nice();
     $res['max_available'] = (int) $package->MaxAvailable;
     $res['available'] = (int) $package->CurrentlyAvailable;
     $res['show_availability'] = (bool) $package->ShowQuantity;
     return $res;
 }
 public function init()
 {
     parent::init();
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript('googlesitesearch/javascript/uri.js');
     Requirements::javascript('googlesitesearch/javascript/googlesitesearch.js');
     Requirements::css('googlesitesearch/css/googlesitesearch.css');
     if (isset($_GET['Search'])) {
         $this->GoogleSiteSearchText = DBField::create_field('HTMLText', $_GET['Search']);
     }
 }
 /**
  * Generate RSS Content and allow extending
  */
 public function RssContent()
 {
     $thumbnail = false;
     $t = $this->Thumbnail();
     if ($t->ID) {
         $thumbnail = '<p><a href="' . $t->URL . '"><img src="' . $t->setWidth(self::$rss_thumb_width)->URL . '" alt="' . htmlspecialchars($t->Title) . '" /></a></p>';
     }
     $html = DBField::create_field('HTMLText', $thumbnail . $this->Content);
     $this->extend('updateRssContent', $html);
     return $html;
 }