本文整理汇总了PHP中craft函数的典型用法代码示例。如果您正苦于以下问题:PHP craft函数的具体用法?PHP craft怎么用?PHP craft使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了craft函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCheckRequirements
public function actionCheckRequirements()
{
$dependencies = craft()->socialPoster_plugin->checkRequirements();
if ($dependencies) {
$this->renderTemplate('socialposter/_special/dependencies', array('dependencies' => $dependencies));
}
}
示例2: actionHandle
/**
* Action Handle
*
* @param array $variables Variables
*
* @return void
*/
public function actionHandle(array $variables = [])
{
$request = craft()->httpMessages->getRequest($variables);
$response = craft()->httpMessages->getResponse();
$response = craft()->httpMessages->handle($request, $response);
$response->send();
}
示例3: updateAdminbarSettings
private function updateAdminbarSettings(array $settings = array())
{
$plugin = craft()->plugins->getPlugin('Adminbar');
$savedSettings = $plugin->getSettings()->getAttributes();
$newSettingsRow = array_merge($savedSettings, $settings);
return craft()->plugins->savePluginSettings($plugin, $newSettingsRow);
}
示例4: getTriggerHtml
/**
* @inheritDoc IElementAction::getTriggerHtml()
*
* @return string|null
*/
public function getTriggerHtml()
{
$js = <<<EOT
(function()
{
\tvar trigger = new Craft.ElementActionTrigger({
\t\thandle: 'View',
\t\tbatch: false,
\t\tvalidateSelection: function(\$selectedItems)
\t\t{
\t\t\tvar \$element = \$selectedItems.find('.element');
\t\t\treturn (
\t\t\t\t\$element.data('url') &&
\t\t\t\t(\$element.data('status') == 'enabled' || \$element.data('status') == 'live')
\t\t\t);
\t\t},
\t\tactivate: function(\$selectedItems)
\t\t{
\t\t\twindow.open(\$selectedItems.find('.element').data('url'));
\t\t}
\t});
})();
EOT;
craft()->templates->includeJs($js);
}
示例5: getMinElapsedTime
protected function getMinElapsedTime()
{
if ($elapsedTime = craft()->sproutInvisibleCaptcha->getMethodOption('elapsedTime')) {
return $elapsedTime;
}
return self::MIN_ELAPSED_TIME;
}
示例6: normalizeDataForElementsTable
/**
* Normalize Submission For Elements Table
*
*/
public function normalizeDataForElementsTable()
{
$data = json_decode($this->submission, true);
// Pop off the first (4) items from the data array
$data = array_slice($data, 0, 4);
$newData = '<ul>';
foreach ($data as $key => $value) {
$fieldHandle = craft()->fields->getFieldByHandle($key);
$capitalize = ucfirst($key);
$removeUnderscore = str_replace('_', ' ', $key);
$valueArray = is_array($value);
if ($valueArray == '1') {
$newData .= '<li class="left icon" style="margin-right:10px;"><strong>' . $fieldHandle . '</strong>: ';
foreach ($value as $item) {
if ($item != '') {
$newData .= $item;
if (next($value) == true) {
$newData .= ', ';
}
}
}
} else {
if ($value != '') {
$newData .= '<li class="left icon" style="margin-right:10px;"><strong>' . $fieldHandle . '</strong>: ' . $value . '</li>';
}
}
}
$newData .= '</ul>';
$this->__set('submission', $newData);
return $this;
}
示例7: getElementType
/**
* Returns an element type.
*
* @param string $class
*
* @return ElementTypeVariable|null
*/
public function getElementType($class)
{
$elementType = craft()->elements->getElementType($class);
if ($elementType) {
return new ElementTypeVariable($elementType);
}
}
示例8: _getParsedown
/**
* Returns a new ParsedownExtra instance.
*
* @access private
* @return \ParsedownExtra
*/
private function _getParsedown()
{
if (!class_exists('\\ParsedownExtra')) {
require_once craft()->path->getPluginsPath() . 'markdown/vendor/autoload.php';
}
return new \ParsedownExtra();
}
示例9: getOptimizedMeta
/**
* Prioritize our meta data
* ------------------------------------------------------------
*
* Loop through and select the highest ranking value for each attribute in our SproutSeo_MetaData model
*
* 1) Entry Override (Set by adding `id` override in Twig template code and using Meta Fields)
* 2) On-Page Override (Set in Twig template code)
* 3) Default (Set in control panel)
* 4) Global Fallback (Set in control panel)
* 5) Blank (Automatic)
*
* Once we have added all the content we need to be outputting to our array we will loop through that array and create the HTML we will output to our page.
*
* While we don't define HTML in our PHP as much as possible, the goal here is to be as easy to use as possible on the front end so we want to simplify the front end code to a single function and wrangle what we need to here.
*
* @return array
* @throws \Exception
*/
public function getOptimizedMeta()
{
$entryOverrideMetaModel = new SproutSeo_MetaModel();
$codeOverrideMetaModel = new SproutSeo_MetaModel();
$defaultMetaModel = new SproutSeo_MetaModel();
$globalFallbackMetaModel = new SproutSeo_MetaModel();
// Prepare a SproutSeo_MetaModel for each of our levels of priority
$entryOverrideMetaModel = $entryOverrideMetaModel->setMeta('entry', $this->getMeta());
$codeOverrideMetaModel = $codeOverrideMetaModel->setMeta('code', $this->getMeta());
$defaultMetaModel = $defaultMetaModel->setMeta('default', $this->getMeta());
$globalFallbackMetaModel = $globalFallbackMetaModel->setMeta('fallback');
$prioritizedMetaModel = new SproutSeo_MetaModel();
$this->divider = craft()->plugins->getPlugin('sproutseo')->getSettings()->seoDivider;
// Default to the Current URL
$prioritizedMetaModel->canonical = SproutSeoMetaHelper::prepareCanonical($prioritizedMetaModel);
foreach ($prioritizedMetaModel->getAttributes() as $key => $value) {
// Test for a value on each of our models in their order of priority
if ($entryOverrideMetaModel->getAttribute($key)) {
$prioritizedMetaModel[$key] = $entryOverrideMetaModel[$key];
} elseif ($codeOverrideMetaModel->getAttribute($key)) {
$prioritizedMetaModel[$key] = $codeOverrideMetaModel[$key];
} elseif ($defaultMetaModel->getAttribute($key)) {
$prioritizedMetaModel[$key] = $defaultMetaModel->getAttribute($key);
} elseif ($globalFallbackMetaModel->getAttribute($key)) {
$prioritizedMetaModel[$key] = $globalFallbackMetaModel->getAttribute($key);
} else {
$prioritizedMetaModel[$key] = $prioritizedMetaModel->getAttribute($key);
}
}
// @todo - reorganize how this stuff works / robots need love.
$prioritizedMetaModel->title = SproutSeoMetaHelper::prepareAppendedSiteName($prioritizedMetaModel, $defaultMetaModel, $globalFallbackMetaModel);
$prioritizedMetaModel->robots = SproutSeoMetaHelper::prepRobotsAsString($prioritizedMetaModel->robots);
return $prioritizedMetaModel;
}
示例10: setMockElementsService
/**
* Mock ElementsService.
*/
private function setMockElementsService()
{
$mock = $this->getMockBuilder('Craft\\ElementsService')->disableOriginalConstructor()->setMethods(array('getCriteria'))->getMock();
$criteria = $this->getMockElementCriteriaModel();
$mock->expects($this->any())->method('getCriteria')->willReturn($criteria);
$this->setComponent(craft(), 'elements', $mock);
}
示例11: init
function init()
{
if (craft()->request->isCpRequest() && craft()->userSession->isLoggedIn()) {
craft()->templates->includeJsResource("zipassets/js/zipassets.js");
craft()->templates->includeCssResource("zipassets/css/zipassets.css");
}
}
示例12: download
/**
* Download zipfile.
*
* @param array $files
* @param string $filename
*
* @return string
*/
public function download($files, $filename)
{
// Get assets
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = $files;
$criteria->limit = null;
$assets = $criteria->find();
// Set destination zip
$destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
// Create the zipfile
IOHelper::createFile($destZip);
// Loop through assets
foreach ($assets as $asset) {
// Get asset source
$source = $asset->getSource();
// Get asset source type
$sourceType = $source->getSourceType();
// Get asset file
$file = $sourceType->getLocalCopy($asset);
// Add to zip
Zip::add($destZip, $file, dirname($file));
}
// Return zip destination
return $destZip;
}
示例13: safeUp
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
if (!craft()->db->columnExists('entryversions', 'num')) {
// Add the `num` column
$columnConfig = array('maxLength' => 6, 'decimals' => 0, 'column' => 'smallint', 'unsigned' => true);
$this->addColumnAfter('entryversions', 'num', $columnConfig, 'locale');
$versionCountsByEntryIdAndLocale = array();
// Populate it in batches
$offset = 0;
do {
$versions = craft()->db->createCommand()->select('id, entryId, locale')->from('entryversions')->order('dateCreated asc')->offset($offset)->limit(100)->queryAll();
foreach ($versions as $version) {
$entryId = $version['entryId'];
$locale = $version['locale'];
if (!isset($versionCountsByEntryIdAndLocale[$entryId][$locale])) {
$versionCountsByEntryIdAndLocale[$entryId][$locale] = 1;
} else {
$versionCountsByEntryIdAndLocale[$entryId][$locale]++;
}
$this->update('entryversions', array('num' => $versionCountsByEntryIdAndLocale[$entryId][$locale]), array('id' => $version['id']));
}
$offset += 100;
} while (count($versions) == 100);
// Set the `num` column to NOT NULL
$columnConfig['null'] = false;
$this->alterColumn('entryversions', 'num', $columnConfig);
}
return true;
}
示例14: locateEntry
/**
* Given a path, look for an obsolete URL from the revisions
*
* @return EntryModel or null
*/
public function locateEntry($path)
{
$slug = array_pop($path);
$prefix = join("/", $path);
// Check that there's even a slug to work with
if ($slug === '') {
return false;
}
// Element conditions
$element_conditions = array('and', 'elements_i18n.enabled = 1', 'elements.enabled = 1', 'elements.archived = 0');
// Slug conditions
$slug_conditions = array('like', 'entryversions.data', '%"slug":"' . $slug . '"%');
// Query for (or against) a path prefix
if (empty($prefix)) {
// Ensure the prefixed segments do NOT exist in the URI
$path_conditions = array('not like', 'elements_i18n.uri', '%/%');
} else {
// Ensure the prefixed segments DO exist in the URI
$path_conditions = array('like', 'elements_i18n.uri', $prefix . '/%');
}
// Query for matching revisions
$query = craft()->db->createCommand()->select('elements.id')->from('elements elements')->join('elements_i18n elements_i18n', 'elements_i18n.elementId = elements.id')->join('entryversions entryversions', 'entryversions.entryId = elements.id')->where($element_conditions)->andWhere($slug_conditions)->andWhere($path_conditions)->order('entryversions.dateUpdated DESC')->limit(1);
// ObsoleteRedirectPlugin::log($query->text);
$result = $query->queryRow();
if ($result) {
// Get the element's EntryModel
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->id = $result['id'];
// Return the actual element
return $criteria->first();
}
}
示例15: safeUp
public function safeUp()
{
$tableName = 'plainform_entries';
if (!craft()->db->columnExists($tableName, 'ip')) {
$this->addColumn($tableName, 'ip', array('column' => ColumnType::Varchar, 'null' => true, 'default' => null));
}
}