本文整理汇总了PHP中Craft::hasPackage方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::hasPackage方法的具体用法?PHP Craft::hasPackage怎么用?PHP Craft::hasPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::hasPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllSections
/**
* Returns all sections.
*
* @param string|null $indexBy
* @return array
*/
public function getAllSections($indexBy = null)
{
if (!$this->_fetchedAllSections) {
$criteria = new \CDbCriteria();
if (!Craft::hasPackage(CraftPackage::PublishPro)) {
$criteria->limit = 1;
}
$sectionRecords = SectionRecord::model()->ordered()->findAll($criteria);
$this->_sectionsById = SectionModel::populateModels($sectionRecords, 'id');
$this->_fetchedAllSections = true;
}
if ($indexBy == 'id') {
$sections = $this->_sectionsById;
} else {
if (!$indexBy) {
$sections = array_values($this->_sectionsById);
} else {
$sections = array();
foreach ($this->_sectionsById as $section) {
$sections[$section->{$indexBy}] = $section;
}
}
}
return $sections;
}
示例2: actionSaveSource
/**
* Saves an asset source.
*/
public function actionSaveSource()
{
craft()->userSession->requireAdmin();
$this->requirePostRequest();
$existingSourceId = craft()->request->getPost('sourceId');
if ($existingSourceId) {
$source = craft()->assetSources->getSourceById($existingSourceId);
} else {
$source = new AssetSourceModel();
}
$source->name = craft()->request->getPost('name');
if (Craft::hasPackage(CraftPackage::Cloud)) {
$source->type = craft()->request->getPost('type');
}
$typeSettings = craft()->request->getPost('types');
if (isset($typeSettings[$source->type])) {
if (!$source->settings) {
$source->settings = array();
}
$source->settings = array_merge($source->settings, $typeSettings[$source->type]);
}
// Did it save?
if (craft()->assetSources->saveSource($source)) {
craft()->userSession->setNotice(Craft::t('Source saved.'));
$this->redirectToPostedUrl();
} else {
craft()->userSession->setError(Craft::t('Couldn’t save source.'));
}
// Send the source back to the template
craft()->urlManager->setRouteVariables(array('source' => $source));
}
示例3: defineRelations
/**
* @return array
*/
public function defineRelations()
{
$relations = array('element' => array(static::BELONGS_TO, 'ElementRecord', 'id', 'required' => true, 'onDelete' => static::CASCADE), 'section' => array(static::BELONGS_TO, 'SectionRecord', 'required' => true, 'onDelete' => static::CASCADE), 'author' => array(static::BELONGS_TO, 'UserRecord', 'required' => true, 'onDelete' => static::CASCADE));
if (Craft::hasPackage(CraftPackage::PublishPro)) {
$relations['versions'] = array(static::HAS_MANY, 'EntryVersionRecord', 'elementId');
}
return $relations;
}
示例4: getAllSourceTypes
/**
* Returns all installed source types.
*
* @return array
*/
public function getAllSourceTypes()
{
if (Craft::hasPackage(CraftPackage::Cloud)) {
return craft()->components->getComponentsByType(ComponentType::AssetSource);
} else {
return array(craft()->components->getComponentByTypeAndClass(ComponentType::AssetSource, 'Local'));
}
}
示例5: defineRelations
/**
* @return array
*/
public function defineRelations()
{
$relations = array('element' => array(static::BELONGS_TO, 'ElementRecord', 'id', 'required' => true, 'onDelete' => static::CASCADE), 'preferredLocale' => array(static::BELONGS_TO, 'LocaleRecord', 'preferredLocale', 'onDelete' => static::SET_NULL, 'onUpdate' => static::CASCADE));
if (Craft::hasPackage(CraftPackage::Users)) {
$relations['groups'] = array(static::MANY_MANY, 'UserGroupRecord', 'usergroups_users(userId, groupId)');
}
$relations['sessions'] = array(static::HAS_MANY, 'SessionRecord', 'userId');
return $relations;
}
示例6: getTitle
/**
* Gets the widget's title.
*
* @return string
*/
public function getTitle()
{
if (Craft::hasPackage(CraftPackage::PublishPro)) {
$section = $this->_getSection();
if ($section) {
return Craft::t('Post a new {section} entry', array('section' => $section->name));
}
}
return $this->getName();
}
示例7: getSources
/**
* Returns this element type's sources.
*
* @param string|null $context
* @return array|false
*/
public function getSources($context = null)
{
$sources = array('*' => array('label' => Craft::t('All users')));
if (Craft::hasPackage(CraftPackage::Users)) {
foreach (craft()->userGroups->getAllGroups() as $group) {
$key = 'group:' . $group->id;
$sources[$key] = array('label' => $group->name, 'criteria' => array('groupId' => $group->id));
}
}
return $sources;
}
示例8: getBodyHtml
/**
* Gets the widget's body HTML.
*
* @return string
*/
public function getBodyHtml()
{
$params = array();
if (Craft::hasPackage(CraftPackage::PublishPro)) {
$sectionId = $this->getSettings()->section;
if (is_numeric($sectionId)) {
$params['sectionId'] = (int) $sectionId;
}
}
$js = 'new Craft.RecentEntriesWidget(' . $this->model->id . ', ' . JsonHelper::encode($params) . ');';
craft()->templates->includeJsResource('js/RecentEntriesWidget.js');
craft()->templates->includeJs($js);
craft()->templates->includeTranslations('by {author}');
return craft()->templates->render('_components/widgets/RecentEntries/body', array('settings' => $this->getSettings()));
}
示例9: actionSaveSection
/**
* Saves a section
*/
public function actionSaveSection()
{
$this->requirePostRequest();
$section = new SectionModel();
// Set the simple stuff
$section->id = craft()->request->getPost('sectionId');
$section->name = craft()->request->getPost('name');
$section->handle = craft()->request->getPost('handle');
$section->titleLabel = craft()->request->getPost('titleLabel');
$section->hasUrls = (bool) craft()->request->getPost('hasUrls');
$section->template = craft()->request->getPost('template');
// Set the locales and URL formats
$locales = array();
$urlFormats = craft()->request->getPost('urlFormat');
if (Craft::hasPackage(CraftPackage::Localize)) {
$localeIds = craft()->request->getPost('locales');
} else {
$primaryLocaleId = craft()->i18n->getPrimarySiteLocaleId();
$localeIds = array($primaryLocaleId);
}
foreach ($localeIds as $localeId) {
$locales[$localeId] = SectionLocaleModel::populateModel(array('locale' => $localeId, 'urlFormat' => isset($urlFormats[$localeId]) ? $urlFormats[$localeId] : null));
}
$section->setLocales($locales);
// Set the field layout
$fieldLayout = craft()->fields->assembleLayoutFromPost();
$fieldLayout->type = ElementType::Entry;
$section->setFieldLayout($fieldLayout);
// Save it
if (craft()->sections->saveSection($section)) {
craft()->userSession->setNotice(Craft::t('Section saved.'));
// TODO: Remove for 2.0
if (isset($_POST['redirect']) && strpos($_POST['redirect'], '{sectionId}') !== false) {
Craft::log('The {sectionId} token within the ‘redirect’ param on sections/saveSection requests has been deprecated. Use {id} instead.', LogLevel::Warning);
$_POST['redirect'] = str_replace('{sectionId}', '{id}', $_POST['redirect']);
}
$this->redirectToPostedUrl($section);
} else {
craft()->userSession->setError(Craft::t('Couldn’t save section.'));
}
// Send the section back to the template
craft()->urlManager->setRouteVariables(array('section' => $section));
}
示例10: actionSaveMessage
/**
* Saves an email message
*/
public function actionSaveMessage()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$message = new RebrandEmailModel();
$message->key = craft()->request->getRequiredPost('key');
$message->subject = craft()->request->getRequiredPost('subject');
$message->body = craft()->request->getRequiredPost('body');
if (Craft::hasPackage(CraftPackage::Localize)) {
$message->locale = craft()->request->getPost('locale');
} else {
$message->locale = craft()->language;
}
if (craft()->emailMessages->saveMessage($message)) {
$this->returnJson(array('success' => true));
} else {
$this->returnErrorJson(Craft::t('There was a problem saving your message.'));
}
}
示例11: nav
/**
* Get the sections of the CP.
*
* @return array
*/
public function nav()
{
$nav['dashboard'] = array('name' => Craft::t('Dashboard'));
if (craft()->sections->getTotalEditableSections()) {
$nav['entries'] = array('name' => Craft::t('Entries'));
}
if (craft()->globals->getTotalEditableSets()) {
$nav['globals'] = array('name' => Craft::t('Globals'));
}
if (craft()->assetSources->getTotalViewableSources()) {
$nav['assets'] = array('name' => Craft::t('Assets'));
}
if (Craft::hasPackage(CraftPackage::Users) && craft()->userSession->checkPermission('editUsers')) {
$nav['users'] = array('name' => Craft::t('Users'));
}
// Add any Plugin nav items
$plugins = craft()->plugins->getPlugins();
foreach ($plugins as $plugin) {
if ($plugin->hasCpSection()) {
if (craft()->userSession->checkPermission('accessPlugin-' . $plugin->getClassHandle())) {
$lcHandle = strtolower($plugin->getClassHandle());
$nav[$lcHandle] = array('name' => $plugin->getName());
}
}
}
if (craft()->userSession->checkPermission('performUpdates')) {
$totalAvailableUpdates = craft()->updates->getTotalAvailableUpdates();
if ($totalAvailableUpdates > 0) {
$nav['updates'] = array('name' => Craft::t('Updates'), 'badge' => $totalAvailableUpdates);
} else {
$nav['updates'] = array('name' => Craft::t('Updates'));
}
}
if (craft()->userSession->isAdmin()) {
$nav['settings'] = array('name' => Craft::t('Settings'));
}
return $nav;
}
示例12: sendEmailByKey
/**
* Sends an email by its key.
*
* @param UserModel $user
* @param string $key
* @param array $variables
* @return bool
* @throws Exception
*/
public function sendEmailByKey(UserModel $user, $key, $variables = array())
{
$emailModel = new EmailModel();
if (Craft::hasPackage(CraftPackage::Rebrand)) {
$message = craft()->emailMessages->getMessage($key, $user->preferredLocale);
$emailModel->subject = $message->subject;
$emailModel->body = $message->body;
} else {
$emailModel->subject = Craft::t($key . '_subject', null, null, 'en_us');
$emailModel->body = Craft::t($key . '_body', null, null, 'en_us');
}
$tempTemplatesPath = '';
if (Craft::hasPackage(CraftPackage::Rebrand)) {
// Is there a custom HTML template set?
$settings = $this->getSettings();
if (!empty($settings['template'])) {
$tempTemplatesPath = craft()->path->getSiteTemplatesPath();
$template = $settings['template'];
}
}
if (empty($template)) {
$tempTemplatesPath = craft()->path->getCpTemplatesPath();
$template = '_special/email';
}
if (!$emailModel->htmlBody) {
// Auto-generate the HTML content
$emailModel->htmlBody = StringHelper::parseMarkdown($emailModel->body);
}
$emailModel->htmlBody = "{% extends '{$template}' %}\n" . "{% set body %}\n" . $emailModel->htmlBody . "{% endset %}\n";
// Temporarily swap the templates path
$originalTemplatesPath = craft()->path->getTemplatesPath();
craft()->path->setTemplatesPath($tempTemplatesPath);
// Send the email
$return = $this->_sendEmail($user, $emailModel, $variables);
// Return to the original templates path
craft()->path->setTemplatesPath($originalTemplatesPath);
return $return;
}
示例13: _setPackageComponents
/**
* Sets the package components.
*/
private function _setPackageComponents()
{
// Set the appropriate package components
if (isset($this->_packageComponents)) {
foreach ($this->_packageComponents as $packageName => $packageComponents) {
if (Craft::hasPackage($packageName)) {
$this->setComponents($packageComponents);
}
}
unset($this->_packageComponents);
}
}
示例14: tryPackage
/**
* @param TryPackageModel $model
* @return bool
*/
public function tryPackage(TryPackageModel $model)
{
$et = new Et(static::StartPackageTrial);
$et->setData($model);
$etResponse = $et->phoneHome();
if (!empty($etResponse->data['success'])) {
// Install the package.
if (!Craft::hasPackage($model->packageHandle)) {
Craft::installPackage($model->packageHandle);
}
return true;
} else {
// Did they at least say why?
if (!empty($etResponse->errors)) {
switch ($etResponse->errors[0]) {
// Validation errors
case 'package_doesnt_exist':
$error = Craft::t('The selected package doesn’t exist anymore.');
break;
case 'cannot_trial_package':
$error = Craft::t('Your license key is invalid.');
break;
default:
$error = $etResponse->errors[0];
}
} else {
// Something terrible must have happened!
$error = Craft::t('Craft is unable to trial packages at this time.');
}
$model->addError('response', $error);
}
return false;
}
示例15: _getEmailSettingsFromPost
/**
* Returns the email settings from the post data.
*
* @access private
* @return array
*/
private function _getEmailSettingsFromPost()
{
$emailSettings = new EmailSettingsModel();
$gMailSmtp = 'smtp.gmail.com';
$emailSettings->protocol = craft()->request->getPost('protocol');
$emailSettings->host = craft()->request->getPost('host');
$emailSettings->port = craft()->request->getPost('port');
$emailSettings->smtpAuth = (bool) craft()->request->getPost('smtpAuth');
if ($emailSettings->smtpAuth && $emailSettings->protocol !== EmailerType::Gmail) {
$emailSettings->username = craft()->request->getPost('smtpUsername');
$emailSettings->password = craft()->request->getPost('smtpPassword');
} else {
$emailSettings->username = craft()->request->getPost('username');
$emailSettings->password = craft()->request->getPost('password');
}
$emailSettings->smtpKeepAlive = (bool) craft()->request->getPost('smtpKeepAlive');
$emailSettings->smtpSecureTransportType = craft()->request->getPost('smtpSecureTransportType');
$emailSettings->timeout = craft()->request->getPost('timeout');
$emailSettings->emailAddress = craft()->request->getPost('emailAddress');
$emailSettings->senderName = craft()->request->getPost('senderName');
// Validate user input
if (!$emailSettings->validate()) {
return $emailSettings;
}
$settings['protocol'] = $emailSettings->protocol;
$settings['emailAddress'] = $emailSettings->emailAddress;
$settings['senderName'] = $emailSettings->senderName;
if (Craft::hasPackage(CraftPackage::Rebrand)) {
$settings['template'] = craft()->request->getPost('template');
}
switch ($emailSettings->protocol) {
case EmailerType::Smtp:
if ($emailSettings->smtpAuth) {
$settings['smtpAuth'] = 1;
$settings['username'] = $emailSettings->username;
$settings['password'] = $emailSettings->password;
}
$settings['smtpSecureTransportType'] = $emailSettings->smtpSecureTransportType;
$settings['port'] = $emailSettings->port;
$settings['host'] = $emailSettings->host;
$settings['timeout'] = $emailSettings->timeout;
if ($emailSettings->smtpKeepAlive) {
$settings['smtpKeepAlive'] = 1;
}
break;
case EmailerType::Pop:
$settings['port'] = $emailSettings->port;
$settings['host'] = $emailSettings->host;
$settings['username'] = $emailSettings->username;
$settings['password'] = $emailSettings->password;
$settings['timeout'] = $emailSettings->timeout;
break;
case EmailerType::Gmail:
$settings['host'] = $gMailSmtp;
$settings['smtpAuth'] = 1;
$settings['smtpSecureTransportType'] = 'ssl';
$settings['username'] = $emailSettings->username;
$settings['password'] = $emailSettings->password;
$settings['port'] = $emailSettings->smtpSecureTransportType == 'tls' ? '587' : '465';
$settings['timeout'] = $emailSettings->timeout;
break;
}
return $settings;
}