本文整理汇总了PHP中Craft::t方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::t方法的具体用法?PHP Craft::t怎么用?PHP Craft::t使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::t方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSaveNote
/**
* Save a note.
*/
public function actionSaveNote()
{
$this->requirePostRequest();
// Get note if available
$noteId = craft()->request->getPost('noteId');
if ($noteId) {
$note = craft()->amForms_notes->getNoteById($noteId);
if (!$note) {
throw new Exception(Craft::t('No note exists with the ID “{id}”.', array('id' => $noteId)));
}
} else {
$note = new AmForms_NoteModel();
}
// Note attributes
$note->submissionId = craft()->request->getPost('submissionId');
$note->name = craft()->request->getPost('name');
$note->text = craft()->request->getPost('text');
// Save note
if (craft()->amForms_notes->saveNote($note)) {
craft()->userSession->setNotice(Craft::t('Note saved.'));
$this->redirectToPostedUrl($note);
} else {
craft()->userSession->setError(Craft::t('Couldn’t save note.'));
// Send the note back to the template
craft()->urlManager->setRouteVariables(array('note' => $note));
}
}
示例2: actionAdd
public function actionAdd()
{
$this->requirePostRequest();
//required fields
$listId = craft()->request->getParam('listId');
$email = craft()->request->getParam('email');
//optional fields with defaults
$name = craft()->request->getParam('name') ?: '';
$customFields = craft()->request->getParam('customFields') ?: array();
$resubscribe = craft()->request->getParam('resubscribe') ?: true;
$error = null;
try {
craft()->oneCampaignMonitor_subscribers->add($listId, $email, $name, $customFields, $resubscribe);
} catch (Exception $e) {
$error = $e->getMessage();
}
//return json for ajax requests, redirect to posted url otherwise
if (craft()->request->isAjaxRequest()) {
$this->returnJson(['success' => is_null($error), 'error' => $error]);
} else {
craft()->userSession->setFlash('oneCampaignMonitor_addSubscriberSuccess', is_null($error));
craft()->userSession->setFlash('oneCampaignMonitor_addSubscriberMessage', Craft::t($error ?: 'Success!'));
$this->redirectToPostedUrl();
}
}
示例3: actionReset
/**
* Reset count
*/
public function actionReset()
{
$entryId = craft()->request->getRequiredParam('entryId');
craft()->entryCount->reset($entryId);
craft()->userSession->setNotice(Craft::t('Entry count reset.'));
$this->redirect('entrycount');
}
示例4: actionSaveRule
/**
* Saves a new or existing rule.
*
* @return null
*/
public function actionSaveRule()
{
$this->requirePostRequest();
$rule = new AutoExpire_RuleModel();
$rule->id = craft()->request->getPost('id');
$rule->name = craft()->request->getPost('name');
$rule->sectionId = craft()->request->getPost('sectionId');
$rule->dateTemplate = craft()->request->getPost('dateTemplate');
$rule->allowOverwrite = craft()->request->getPost('allowOverwrite');
// Extract the entry type and the field from sections array
$sections = craft()->request->getPost('sections');
if (isset($sections[$rule->sectionId])) {
$rule->entryTypeId = $sections[$rule->sectionId]['entryTypeId'];
$rule->fieldHandle = $sections[$rule->sectionId][$rule->entryTypeId]['fieldHandle'];
}
// Did it save?
if (craft()->autoExpire->saveRule($rule)) {
craft()->userSession->setNotice(Craft::t('Rule saved.'));
$this->redirectToPostedUrl();
} else {
craft()->userSession->setError(Craft::t('Couldn’t save rule.'));
}
// Send the rule back to the template
craft()->urlManager->setRouteVariables(array('rule' => $rule));
}
示例5: defineTableAttributes
/**
* @inheritDoc IElementType::defineTableAttributes()
*
* @param string|null $source
*
* @return array
*/
public function defineTableAttributes($source = null)
{
$attributes = array('title' => Craft::t('Title'));
// Allow plugins to modify the attributes
craft()->plugins->call('modifyTagManagerTableAttributes', array(&$attributes, $source));
return $attributes;
}
示例6: save
/**
* @param Market_TaxRateModel $model
*
* @return bool
* @throws Exception
* @throws \CDbException
* @throws \Exception
*/
public function save(Market_TaxRateModel $model)
{
if ($model->id) {
$record = Market_TaxRateRecord::model()->findById($model->id);
if (!$record) {
throw new Exception(Craft::t('No tax rate exists with the ID “{id}”', ['id' => $model->id]));
}
} else {
$record = new Market_TaxRateRecord();
}
$record->name = $model->name;
$record->rate = $model->rate;
$record->include = $model->include;
$record->showInLabel = $model->showInLabel;
$record->taxCategoryId = $model->taxCategoryId;
$record->taxZoneId = $model->taxZoneId;
$record->validate();
if (!$record->getError('taxZoneId')) {
$taxZone = craft()->market_taxZone->getById($record->taxZoneId);
if ($record->include && !$taxZone->default) {
$record->addError('include', 'Included rates allowed for default tax zone only');
}
}
$model->validate();
$model->addErrors($record->getErrors());
if (!$model->hasErrors()) {
// Save it!
$record->save(false);
// Now that we have a record ID, save it on the model
$model->id = $record->id;
return true;
} else {
return false;
}
}
示例7: getSettingsHtml
public function getSettingsHtml()
{
// if not set, create a default row for custom links table
if (!$this->_customLinks) {
$this->_customLinks = array(array('linkLabel' => '', 'linkUrl' => '', 'adminOnly' => ''));
}
// generate table for custom links
$customLinksTable = craft()->templates->renderMacro('_includes/forms', 'editableTableField', array(array('label' => Craft::t('Custom Links'), 'instructions' => Craft::t('Add your own links to the Admin Bar.'), 'id' => 'customLinks', 'name' => 'customLinks', 'cols' => array('linkLabel' => array('heading' => Craft::t('Label'), 'type' => 'singleline'), 'linkUrl' => array('heading' => Craft::t('URL'), 'type' => 'singleline'), 'adminOnly' => array('heading' => Craft::t('Admins Only'), 'type' => 'checkbox')), 'rows' => $this->_customLinks, 'addRowLabel' => Craft::t('Add a link'))));
// get links from other plugins
$pluginLinksHook = craft()->plugins->call('addAdminBarLinks');
$pluginLinks = array();
foreach ($pluginLinksHook as $key => $link) {
$pluginName = craft()->plugins->getPlugin($key)->getName();
for ($i = 0; $i < count($link); $i++) {
if (isset($link[$i]['title']) && isset($link[$i]['url']) && isset($link[$i]['type'])) {
$link[$i]['id'] = str_replace(' ', '', $link[$i]['title']) . $link[$i]['url'] . $link[$i]['type'];
$link[$i]['originator'] = $pluginName;
array_push($pluginLinks, $link[$i]);
}
}
}
$this->clearAdminBarCache();
// output settings template
return craft()->templates->render('adminbar/settings', array('autoEmbedValue' => $this->getSettings()->autoEmbed, 'autoEmbedStickyValue' => $this->getSettings()->autoEmbedSticky, 'defaultColorValue' => $this->getSettings()->defaultColor, 'customLinksTable' => $customLinksTable, 'pluginLinks' => $pluginLinks, 'enabledLinks' => $this->getSettings()->enabledLinks));
}
示例8: getProperFieldTypes
/**
* Get support fields.
*
* @param array $fieldTypes
*
* @return array
*/
public function getProperFieldTypes($fieldTypes)
{
$basicFields = array();
$advancedFields = array();
$fieldTypeGroups = array();
// Supported & unsupported fields
$supported = $this->getSupportedFieldTypes();
$unsupported = $this->getUnsupportedFieldTypes();
// Set allowed fields
foreach ($fieldTypes as $key => $fieldType) {
if (in_array($key, $supported)) {
$basicFields[$key] = $fieldType;
} elseif (in_array($key, $unsupported)) {
$advancedFields[$key] = $fieldType;
}
}
$fieldTypeGroups['basic'] = array('optgroup' => Craft::t('Basic fields'));
foreach ($basicFields as $key => $fieldType) {
$fieldTypeGroups[$key] = $fieldType;
}
$fieldTypeGroups['advanced'] = array('optgroup' => Craft::t('Advanced fields'));
foreach ($advancedFields as $key => $fieldType) {
$fieldTypeGroups[$key] = $fieldType;
}
return $fieldTypeGroups;
}
示例9: getSettingsHtml
public function getSettingsHtml()
{
$pluginSettings = craft()->plugins->getPlugin('placid')->getSettings();
// Get placid requests and send them to the widget settings
$requests = craft()->placid_requests->findAllRequests();
$requestsArray = array('' => 'No request selected');
foreach ($requests as $request) {
$requestsArray[$request->handle] = $request->name;
}
$templatesPath = craft()->path->getSiteTemplatesPath() . $pluginSettings->widgetTemplatesPath;
$templates = IOHelper::getFolderContents($templatesPath, TRUE);
$templatesArray = array('' => Craft::t('No template selected'));
if (!$templates) {
$templatesArray = array('' => 'Cannot find templates');
Craft::log('Cannot find templates in path "' . $templatesPath . '"', LogLevel::Error);
} else {
// Turn array into ArrayObject
$templates = new \ArrayObject($templates);
// Iterate over template list
// * Remove full path
// * Remove folders from list
for ($list = $templates->getIterator(); $list->valid(); $list->next()) {
$filename = $list->current();
$filename = str_replace($templatesPath, '', $filename);
$filenameIncludingSubfolder = $filename;
$isTemplate = preg_match("/(.html|.twig)\$/u", $filename);
if ($isTemplate) {
$templatesArray[$filenameIncludingSubfolder] = $filename;
}
}
}
return craft()->templates->render('placid/_widgets/request/settings', array('requests' => $requestsArray, 'templates' => $templatesArray, 'settings' => $this->getSettings()));
}
示例10: getInputHtml
/**
* Returns the field's input HTML.
*
* @param string $name
* @param mixed $value
* @return string
*/
public function getInputHtml($name, $value)
{
$id = craft()->templates->formatInputId($name);
craft()->templates->includeCssResource('twitter/css/tweet.css');
craft()->templates->includeJsResource('twitter/js/TweetInput.js');
craft()->templates->includeJs('new TweetInput("' . craft()->templates->namespaceInputId($id) . '");');
$tweet = $value;
$html = "";
if ($tweet && isset($tweet['id_str'])) {
$url = 'https://twitter.com/' . $tweet['user']['screen_name'] . '/status/' . $tweet['id_str'];
if (craft()->request->isSecureConnection()) {
$profileImageUrl = $tweet['user']['profile_image_url_https'];
} else {
$profileImageUrl = $tweet['user']['profile_image_url'];
}
if (craft()->twitter_plugin->checkDependencies()) {
$html .= '<div class="tweet-preview">' . '<div class="tweet-image" style="background-image: url(' . $profileImageUrl . ');"></div> ' . '<div class="tweet-user">' . '<span class="tweet-user-name">' . $tweet['user']['name'] . '</span> ' . '<a class="tweet-user-screenname light" href="http://twitter.com/' . $tweet['user']['screen_name'] . '" target="_blank">@' . $tweet['user']['screen_name'] . '</a>' . '</div>' . '<div class="tweet-text">' . $tweet['text'] . '</div>' . '</div>';
}
} else {
$url = $value;
$preview = '';
}
if (!craft()->twitter_plugin->checkDependencies()) {
$html .= '<p class="light">' . Craft::t("Twitter plugin is not configured properly. Please check {url} for more informations.", array('url' => Craft::t('<a href="' . UrlHelper::getUrl('twitter/settings') . '">{title}</a>', array('title' => 'Twitter plugin settings')))) . '</p>';
}
return '<div class="tweet">' . craft()->templates->render('_includes/forms/text', array('id' => $id, 'name' => $name, 'value' => $url, 'placeholder' => Craft::t('Enter a tweet URL or ID'))) . '<div class="spinner hidden"></div>' . $html . '</div>';
}
示例11: actionExpressUpload
/**
* Uploads a file directly to a field for an entry.
*
* @throws Exception
* @return null
*/
public function actionExpressUpload()
{
$this->requireAjaxRequest();
$fieldId = craft()->request->getPost('fieldId');
$elementId = craft()->request->getPost('elementId');
if (empty($_FILES['files']) || !isset($_FILES['files']['error'][0]) || $_FILES['files']['error'][0] != 0) {
throw new Exception(Craft::t('The upload failed.'));
}
$field = craft()->fields->populateFieldType(craft()->fields->getFieldById($fieldId));
if (!$field instanceof AssetsFieldType) {
throw new Exception(Craft::t('That is not an Assets field.'));
}
if ($elementId) {
$field->element = craft()->elements->getElementById($elementId);
}
$targetFolderId = $field->resolveSourcePath();
try {
$this->_checkUploadPermissions($targetFolderId);
} catch (Exception $e) {
$this->returnErrorJson($e->getMessage());
}
$fileName = $_FILES['files']['name'][0];
$fileLocation = AssetsHelper::getTempFilePath(pathinfo($fileName, PATHINFO_EXTENSION));
move_uploaded_file($_FILES['files']['tmp_name'][0], $fileLocation);
$response = craft()->assets->insertFileByLocalPath($fileLocation, $fileName, $targetFolderId, AssetConflictResolution::KeepBoth);
$fileId = $response->getDataItem('fileId');
// Render and return
$element = craft()->elements->getElementById($fileId);
$html = craft()->templates->render('_elements/element', array('element' => $element));
$css = craft()->templates->getHeadHtml();
$this->returnJson(array('html' => $html, 'css' => $css));
}
示例12: getInputHtml
public function getInputHtml($name, $value)
{
$settings = $this->getSettings();
if ($value) {
$value = new DateTime($value);
}
$dayRange = range(1, 31);
$dayOption = array('label' => Craft::t('day'), 'disabled' => true);
$dayVariables = array('name' => $name . '[day]', 'value' => $value ? $value->format('d') : false, 'options' => array($dayOption) + array_combine($dayRange, $dayRange));
$monthRange = range(1, 12);
$monthOption = array('label' => Craft::t('month'), 'disabled' => true);
$monthVariables = array('name' => $name . '[month]', 'value' => $value ? $value->format('m') : false, 'options' => array($monthOption) + array_combine($monthRange, $monthRange));
$yearStart = is_numeric($settings->yearRangeStart) ? $settings->yearRangeStart : date('Y', strtotime($settings->yearRangeStart));
$yearEnd = is_numeric($settings->yearRangeEnd) ? $settings->yearRangeEnd : date('Y', strtotime($settings->yearRangeEnd));
$yearRange = range($yearEnd, $yearStart);
$yearOption = array('label' => Craft::t('year'), 'disabled' => true);
$yearVariables = array('name' => $name . '[year]', 'value' => $value ? $value->format('Y') : false, 'options' => array($yearOption) + array_combine($yearRange, $yearRange));
$input = '';
$input .= craft()->templates->render('_includes/forms/select', $dayVariables);
$input .= ' ';
$input .= craft()->templates->render('_includes/forms/select', $monthVariables);
$input .= ' ';
$input .= craft()->templates->render('_includes/forms/select', $yearVariables);
return $input;
}
示例13: performAction
/**
* @inheritDoc IElementAction::performAction()
*
* @param ElementCriteriaModel $criteria
*
* @return bool
*/
public function performAction(ElementCriteriaModel $criteria)
{
$status = $this->getParams()->status;
//False by default
$enable = 0;
switch ($status) {
case SproutSeo_RedirectStatuses::ON:
$enable = '1';
break;
case SproutSeo_RedirectStatuses::OFF:
$enable = '0';
break;
}
$elementIds = $criteria->ids();
// Update their statuses
craft()->db->createCommand()->update('elements', array('enabled' => $enable), array('in', 'id', $elementIds));
if ($status == SproutSeo_RedirectStatuses::ON) {
// Enable their locale as well
craft()->db->createCommand()->update('elements_i18n', array('enabled' => $enable), array('and', array('in', 'elementId', $elementIds), 'locale = :locale'), array(':locale' => $criteria->locale));
}
// Clear their template caches
craft()->templateCache->deleteCachesByElementId($elementIds);
// Fire an 'onSetStatus' event
$this->onSetStatus(new Event($this, array('criteria' => $criteria, 'elementIds' => $elementIds, 'status' => $status)));
$this->setMessage(Craft::t('Statuses updated.'));
return true;
}
示例14: validate
/**
* @param null $attributes
* @param bool $clearErrors
* @return bool|void
*/
public function validate($attributes = null, $clearErrors = true)
{
//ClearErrors?
if ($clearErrors) {
$this->clearErrors();
}
//Any recipients specified?
if ($this->sendto_usergroups == false && $this->sendto_users == false) {
$this->addError('sendto', Craft::t('No recipients specified'));
}
//UserGroup recipients
if ($this->sendto_usergroups) {
if (!$this->usergroups) {
$this->addError('usergroups', Craft::t('No usergroups specified'));
} elseif (array_filter($this->usergroups, 'is_int') === $this->usergroups) {
$this->addError('usergroups', Craft::t('Invalid usergroups specified'));
}
}
//User recipients
if ($this->sendto_users) {
if (!$this->users) {
$this->addError('users', Craft::t('No users specified'));
} elseif (array_filter($this->users, 'is_int') === $this->users) {
$this->addError('users', Craft::t('Invalid users specified'));
}
}
//Return
return parent::validate($attributes, false);
}
示例15: save
/**
* @param Market_TaxCategoryModel $model
*
* @return bool
* @throws Exception
* @throws \CDbException
* @throws \Exception
*/
public function save(Market_TaxCategoryModel $model)
{
if ($model->id) {
$record = Market_TaxCategoryRecord::model()->findById($model->id);
if (!$record) {
throw new Exception(Craft::t('No tax category exists with the ID “{id}”', ['id' => $model->id]));
}
} else {
$record = new Market_TaxCategoryRecord();
}
$record->name = $model->name;
$record->code = $model->code;
$record->description = $model->description;
$record->default = $model->default;
$record->validate();
$model->addErrors($record->getErrors());
if (!$model->hasErrors()) {
// Save it!
$record->save(false);
// Now that we have a record ID, save it on the model
$model->id = $record->id;
//If this was the default make all others not the default.
if ($model->default) {
Market_TaxCategoryRecord::model()->updateAll(['default' => 0], 'id != ?', [$record->id]);
}
return true;
} else {
return false;
}
}