本文整理汇总了PHP中Craft::isInstalled方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::isInstalled方法的具体用法?PHP Craft::isInstalled怎么用?PHP Craft::isInstalled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::isInstalled方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defineAttributes
/**
* @access protected
* @return array
*/
protected function defineAttributes()
{
$requiredTitle = isset($this->_requiredFields) && in_array('title', $this->_requiredFields);
$attributes = array('id' => AttributeType::Number, 'elementId' => AttributeType::Number, 'locale' => AttributeType::Locale, 'title' => array(AttributeType::String, 'required' => $requiredTitle));
if (Craft::isInstalled() && !craft()->isConsole()) {
$allFields = craft()->fields->getAllFields();
foreach ($allFields as $field) {
$fieldType = craft()->fields->populateFieldType($field);
if ($fieldType) {
$attributeConfig = $fieldType->defineContentAttribute();
}
// Default to Mixed
if (!$fieldType || !$attributeConfig) {
$attributeConfig = AttributeType::Mixed;
}
$attributeConfig = ModelHelper::normalizeAttributeConfig($attributeConfig);
$attributeConfig['label'] = $field->name;
if (isset($this->_requiredFields) && in_array($field->id, $this->_requiredFields)) {
$attributeConfig['required'] = true;
}
$attributes[$field->handle] = $attributeConfig;
}
}
return $attributes;
}
示例2: init
/**
* Init
*
* @throws HttpException
*/
public function init()
{
// Return a 404 if Craft is already installed
if (!craft()->config->get('devMode') && Craft::isInstalled()) {
throw new HttpException(404);
}
}
示例3: init
/**
*
*/
public function init()
{
parent::init();
$admin = false;
if (!craft()->isConsole() && Craft::isInstalled()) {
// Set whether the currently logged in user is an admin.
if (isset(craft()->userSession)) {
if (($currentUser = craft()->userSession->getUser()) !== null) {
$admin = $currentUser->admin == 1 ? true : false;
}
}
}
$this->_devMode = craft()->config->get('devMode') || $admin;
}
示例4: getUser
/**
* Gets the currently logged-in user.
*
* @return UserModel|null
*/
public function getUser()
{
// Does a user appear to be logged in?
if (Craft::isInstalled() && $this->getState('__id') !== null) {
if (!isset($this->_user)) {
$userRow = $this->_getUserRow($this->getId());
if ($userRow) {
$this->_userModel = UserModel::populateModel($userRow);
} else {
$this->_userModel = false;
}
}
return $this->_userModel ? $this->_userModel : null;
}
}
示例5: run
/**
* Installs Craft!
*
* @param array $inputs
* @throws Exception
* @throws \Exception
* @return void
*/
public function run($inputs)
{
craft()->config->maxPowerCaptain();
if (Craft::isInstalled()) {
throw new Exception(Craft::t('Craft is already installed.'));
}
// Set the language to the desired locale
craft()->setLanguage($inputs['locale']);
$records = $this->findInstallableRecords();
// Start the transaction
$transaction = craft()->db->beginTransaction();
try {
Craft::log('Installing Craft.');
// Create the tables
$this->_createTablesFromRecords($records);
$this->_createForeignKeysFromRecords($records);
$this->_createContentTable();
$this->_createRelationsTable();
$this->_createShunnedMessagesTable();
$this->_createSearchIndexTable();
$this->_createAndPopulateInfoTable($inputs);
$this->_createAssetTransformIndexTable();
$this->_createRackspaceAccessTable();
Craft::log('Committing the transaction.');
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}
// Craft, you are installed now.
Craft::setIsInstalled();
$this->_populateMigrationTable();
$this->_addLocale($inputs['locale']);
$this->_addUser($inputs);
if (!craft()->isConsole()) {
$this->_logUserIn($inputs);
}
$this->_saveDefaultMailSettings($inputs['email'], $inputs['siteName']);
$this->_createDefaultContent($inputs);
Craft::log('Finished installing Craft.');
}
示例6: _getTargetLanguage
/**
* Returns the target app language.
*
* @access private
* @return string
*/
private function _getTargetLanguage()
{
if (Craft::isInstalled()) {
// Will any locale validation be necessary here?
if ($this->request->isCpRequest() || defined('CRAFT_LOCALE')) {
if ($this->request->isCpRequest()) {
$locale = 'auto';
} else {
$locale = strtolower(CRAFT_LOCALE);
}
// Get the list of actual site locale IDs
$siteLocaleIds = $this->i18n->getSiteLocaleIds();
// Is it set to "auto"?
if ($locale == 'auto') {
// If the user is logged in *and* has a primary language set, use that
$user = $this->userSession->getUser();
if ($user && $user->preferredLocale) {
return $user->preferredLocale;
}
// Otherwise check if the browser's preferred language matches any of the site locales
$browserLanguages = $this->request->getBrowserLanguages();
if ($browserLanguages) {
foreach ($browserLanguages as $language) {
if (in_array($language, $siteLocaleIds)) {
return $language;
}
}
}
} else {
if (in_array($locale, $siteLocaleIds)) {
return $locale;
}
}
}
// Use the primary site locale by default
return $this->i18n->getPrimarySiteLocaleId();
} else {
// Just try to find a match between the browser's preferred locales
// and the locales Craft has been translated into.
$browserLanguages = $this->request->getBrowserLanguages();
if ($browserLanguages) {
$appLocaleIds = $this->i18n->getAppLocaleIds();
foreach ($browserLanguages as $language) {
if (in_array($language, $appLocaleIds)) {
return $language;
}
}
}
// Default to the source language.
return $this->sourceLanguage;
}
}
示例7: _getMatchedElementRoute
/**
* Attempts to match a path with an element in the database.
*
* @access private
* @param string $path
* @return mixed
*/
private function _getMatchedElementRoute($path)
{
if (!isset($this->_matchedElementRoute)) {
$this->_matchedElement = false;
$this->_matchedElementRoute = false;
if (Craft::isInstalled() && craft()->request->isSiteRequest()) {
$query = craft()->db->createCommand()->select('elements.id, elements.type')->from('elements elements')->join('elements_i18n elements_i18n', 'elements_i18n.elementId = elements.id');
$conditions = array('and', 'elements_i18n.uri = :path', 'elements.enabled = 1', 'elements.archived = 0');
$params = array(':path' => $path);
$localeIds = array_unique(array_merge(array(craft()->language), craft()->i18n->getSiteLocaleIds()));
if (count($localeIds) == 1) {
$conditions[] = 'elements_i18n.locale = :locale';
$params[':locale'] = $localeIds[0];
} else {
$quotedLocales = array();
$localeOrder = array();
foreach ($localeIds as $localeId) {
$quotedLocale = craft()->db->quoteValue($localeId);
$quotedLocales[] = $quotedLocale;
$localeOrder[] = "(elements_i18n.locale = {$quotedLocale}) DESC";
}
$conditions[] = "elements_i18n.locale IN (" . implode(', ', $quotedLocales) . ')';
$query->order($localeOrder);
}
$query->where($conditions, $params);
$row = $query->queryRow();
if ($row) {
$elementCriteria = craft()->elements->getCriteria($row['type']);
$elementCriteria->id = $row['id'];
$element = $elementCriteria->first();
if ($element) {
$elementType = $elementCriteria->getElementType();
$route = $elementType->routeRequestForMatchedElement($element);
if ($route) {
$this->_matchedElement = $element;
$this->_matchedElementRoute = $route;
}
}
}
}
}
return $this->_matchedElementRoute;
}
示例8: tableExists
/**
* Returns whether a table exists.
*
* @param string $table
* @param bool $refresh
* @return bool
*/
public function tableExists($table, $refresh = null)
{
// Default to refreshing the tables if Craft isn't installed yet
if ($refresh || $refresh === null && !Craft::isInstalled()) {
$this->getSchema()->refresh();
}
$table = DbHelper::addTablePrefix($table);
return in_array($table, $this->getSchema()->getTableNames());
}
示例9: getGlobals
/**
* Returns a list of global variables to add to the existing list.
*
* @return array An array of global variables
*/
public function getGlobals()
{
// Keep the 'blx' variable around for now
$craftVariable = new CraftVariable();
$globals['craft'] = $craftVariable;
$globals['blx'] = $craftVariable;
$globals['now'] = DateTimeHelper::currentUTCDateTime();
$globals['loginUrl'] = UrlHelper::getUrl(craft()->config->getLoginPath());
$globals['logoutUrl'] = UrlHelper::getUrl(craft()->config->getLogoutPath());
if (Craft::isInstalled()) {
$globals['siteName'] = Craft::getSiteName();
$globals['siteUrl'] = Craft::getSiteUrl();
$globals['user'] = craft()->userSession->getUser();
if (craft()->request->isSiteRequest()) {
foreach (craft()->globals->getAllSets() as $globalSet) {
$globalSet->locale = craft()->language;
$globals[$globalSet->handle] = $globalSet;
}
}
} else {
$globals['siteName'] = null;
$globals['siteUrl'] = null;
$globals['user'] = null;
}
return $globals;
}