本文整理汇总了PHP中DBField::create_field方法的典型用法代码示例。如果您正苦于以下问题:PHP DBField::create_field方法的具体用法?PHP DBField::create_field怎么用?PHP DBField::create_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBField
的用法示例。
在下文中一共展示了DBField::create_field方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GlobalNav
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;
}
示例2: testNice
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());
}
示例3: onBeforeWrite
function onBeforeWrite()
{
parent::onBeforeWrite();
if (!$this->DispatchedOn) {
$this->DispatchedOn = DBField::create_field('Date', date('Y-m-d'));
}
}
示例4: parse
/**
* 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)));
}
示例5: Tweets
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;
}
示例6: Languages
/**
* 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;
}
示例7: GlobalNav
/**
* @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;
}
示例8: renderRows
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;
}
示例9: handlePost
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;
}
示例10: 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;
}
示例11: getEventsAction
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);
}
示例12: getPostContent
/**
* @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;
}
示例13: writeToManipulation
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);
}
示例14: ConfirmTimeLimit
/**
* @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);
}
}
示例15: getNextRun
/**
* @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();
}