本文整理汇总了PHP中File::putContent方法的典型用法代码示例。如果您正苦于以下问题:PHP File::putContent方法的具体用法?PHP File::putContent怎么用?PHP File::putContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::putContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
protected function generate()
{
if (!is_dir(TL_ROOT . '/' . $this->cacheDirectory)) {
$this->makeCacheDirectory();
}
$file = new \File($this->cacheFile);
$file->truncate();
$file->putContent($file->path, json_encode($this->cacheUrl));
$automator = new \Automator();
$automator->purgePageCache();
}
示例2: createCSS
/**
* create CSS File
* file :: assets/css/divElements.css
*/
public function createCSS()
{
// create File if doesn`t exists
$file = new \File('system/modules/swatchBook/assets/css/divElements.css');
// result Color
$groupPalette = \Database::getInstance()->execute("SELECT pid,count(pid) AS count FROM tl_swatchBookColors GROUP BY pid")->fetchAllAssoc();
$palettes = \Database::getInstance()->execute("SELECT id,pid,title,color FROM tl_swatchBookColors")->fetchAllAssoc();
foreach ($groupPalette as $c) {
$i = 1;
foreach ($palettes as $v) {
if ($c['pid'] == $v['pid']) {
$css[] = sprintf("#sb-container-%s div:nth-child(%s){background-color: #%s;box-shadow: -1px -1px 3px rgba(0,0,0,0.1), %spx %spx %spx rgba(0,0,0,0.1);-webkit-box-shadow: -1px -1px 3px rgba(0,0,0,0.1), %spx %spx %spx rgba(0,0,0,0.1);-moz-box-shadow: -1px -1px 3px rgba(0,0,0,0.1), %spx %spx %spx rgba(0,0,0,0.1);}", $v['pid'], $i <= $c['count'] ? $i : $c['count'], $v['color'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id']);
$i++;
}
}
}
\File::putContent('system/modules/swatchBook/assets/css/divElements.css', implode("\n", $css));
}
示例3: writeCSS
/**
* create/update CSS File
* file :: web/bundles/swatchbook/css/divElements.css
*/
public function writeCSS()
{
$this->syncSwatchbookColors();
$objTemplate = new BackendTemplate('be_swatchbookSync');
$objTemplate->hrefBack = ampersand(str_replace('&key=sync', '', \Environment::get('request')));
$objTemplate->goBack = $GLOBALS['TL_LANG']['MSC']['goBack'];
if (!$this->isUpdate) {
$objTemplate->headline = $GLOBALS['TL_LANG']['swatchbook']['syncHeadlineNo'];
return $objTemplate->parse();
} else {
/**
* load File if doesn`t exists
*/
$file = new \File('src/CtEye/swatchbook-bundle/src/Resources/public/css/divElements.css');
/**
* result Color
*/
$groupPallets = \Database::getInstance()->execute("SELECT pid,count(pid) AS count FROM tl_swatchbookColors GROUP BY pid")->fetchAllAssoc();
$pallets = \Database::getInstance()->execute("SELECT id,pid,title,color FROM tl_swatchbookColors")->fetchAllAssoc();
foreach ($groupPallets as $c) {
$i = 1;
foreach ($pallets as $v) {
if ($c['pid'] == $v['pid']) {
$pal[$v['pid']] = $v['pid'];
$css[] = sprintf("#sb-container-%s div:nth-child(%s){background-color: #%s;box-shadow: -1px -1px 3px rgba(0,0,0,0.1), %spx %spx %spx rgba(0,0,0,0.1);-webkit-box-shadow: -1px -1px 3px rgba(0,0,0,0.1), %spx %spx %spx rgba(0,0,0,0.1);-moz-box-shadow: -1px -1px 3px rgba(0,0,0,0.1), %spx %spx %spx rgba(0,0,0,0.1);}", $v['pid'], $i <= $c['count'] ? $i : $c['count'], $v['color'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id'], $v['id']);
$i++;
}
}
}
/**
* write CSS content
*/
\File::putContent('src/CtEye/swatchbook-bundle/src/Resources/public/css/divElements.css', implode("\n", $css));
$objTemplate->headline = $GLOBALS['TL_LANG']['swatchbook']['syncHeadline'];
$objTemplate->pallets = $i > 1 ? sprintf($GLOBALS['TL_LANG']['swatchbook']['syncPalletMulti'], $i) : sprintf($GLOBALS['TL_LANG']['swatchbook']['syncPalletSingle'], $i);
return $objTemplate->parse();
}
}
示例4: generateFiles
//.........这里部分代码省略.........
$GLOBALS['NEWS_FILTER_CATEGORIES'] = true;
$GLOBALS['NEWS_FILTER_DEFAULT'] = $arrCategories;
} else {
$GLOBALS['NEWS_FILTER_CATEGORIES'] = false;
}
// Get the items
if ($arrFeed['maxItems'] > 0) {
$objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
} else {
$objArticle = \NewsModel::findPublishedByPids($arrArchives);
}
// Parse the items
if ($objArticle !== null) {
$arrUrls = array();
while ($objArticle->next()) {
$jumpTo = $objArticle->getRelated('pid')->jumpTo;
// No jumpTo page set (see #4784)
if (!$jumpTo) {
continue;
}
// Get the jumpTo URL
if (!isset($arrUrls[$jumpTo])) {
$objParent = \PageModel::findWithDetails($jumpTo);
// A jumpTo page is set but does no longer exist (see #5781)
if ($objParent === null) {
$arrUrls[$jumpTo] = false;
} else {
$arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/%s' : '/items/%s', $objParent->language);
}
}
// Skip the event if it requires a jumpTo URL but there is none
if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
continue;
}
// Get the categories
if ($arrFeed['categories_show']) {
$arrCategories = array();
if (($objCategories = NewsCategoryModel::findPublishedByIds(deserialize($objArticle->categories, true))) !== null) {
$arrCategories = $objCategories->fetchEach('title');
}
}
$strUrl = $arrUrls[$jumpTo];
$objItem = new \FeedItem();
// Add the categories to the title
if ($arrFeed['categories_show'] == 'title') {
$objItem->title = sprintf('[%s] %s', implode(', ', $arrCategories), $objArticle->headline);
} else {
$objItem->title = $objArticle->headline;
}
$objItem->link = $this->getLink($objArticle, $strUrl, $strLink);
$objItem->published = $objArticle->date;
$objItem->author = $objArticle->authorName;
// Prepare the description
if ($arrFeed['source'] == 'source_text') {
$strDescription = '';
$objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
if ($objElement !== null) {
while ($objElement->next()) {
$strDescription .= $this->getContentElement($objElement->id);
}
}
} else {
$strDescription = $objArticle->teaser;
}
// Add the categories to the description
if ($arrFeed['categories_show'] == 'text_before' || $arrFeed['categories_show'] == 'text_after') {
$strCategories = '<p>' . $GLOBALS['TL_LANG']['MSC']['newsCategories'] . ' ' . implode(', ', $arrCategories) . '</p>';
if ($arrFeed['categories_show'] == 'text_before') {
$strDescription = $strCategories . $strDescription;
} else {
$strDescription .= $strCategories;
}
}
$strDescription = $this->replaceInsertTags($strDescription, false);
$objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
// Add the article image as enclosure
if ($objArticle->addImage) {
$objFile = \FilesModel::findByUuid($objArticle->singleSRC);
if ($objFile !== null) {
$objItem->addEnclosure($objFile->path);
}
}
// Enclosures
if ($objArticle->addEnclosure) {
$arrEnclosure = deserialize($objArticle->enclosure, true);
if (is_array($arrEnclosure)) {
$objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
if ($objFile !== null) {
while ($objFile->next()) {
$objItem->addEnclosure($objFile->path);
}
}
}
}
$objFeed->addItem($objItem);
}
}
// Create the file
\File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
}
示例5: extractThemeFiles
/**
* Extract the theme files and write the data to the database
*
* @param array $arrFiles
* @param array $arrDbFields
*/
protected function extractThemeFiles($arrFiles, $arrDbFields)
{
foreach ($arrFiles as $strZipFile) {
$xml = null;
// Open the archive
$objArchive = new \ZipReader($strZipFile);
// Extract all files
while ($objArchive->next()) {
// Load the XML file
if ($objArchive->file_name == 'theme.xml') {
$xml = new \DOMDocument();
$xml->preserveWhiteSpace = false;
$xml->loadXML($objArchive->unzip());
continue;
}
// Limit file operations to files and the templates directory
if (strncmp($objArchive->file_name, 'files/', 6) !== 0 && strncmp($objArchive->file_name, 'tl_files/', 9) !== 0 && strncmp($objArchive->file_name, 'templates/', 10) !== 0) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'], $objArchive->file_name));
continue;
}
// Extract the files
try {
\File::putContent($this->customizeUploadPath($objArchive->file_name), $objArchive->unzip());
} catch (\Exception $e) {
\Message::addError($e->getMessage());
}
}
// Continue if there is no XML file
if (!$xml instanceof \DOMDocument) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['tl_theme']['missing_xml'], basename($strZipFile)));
continue;
}
$arrMapper = array();
$tables = $xml->getElementsByTagName('table');
$arrNewFolders = array();
// Extract the folder names from the XML file
for ($i = 0; $i < $tables->length; $i++) {
if ($tables->item($i)->getAttribute('name') == 'tl_theme') {
$fields = $tables->item($i)->childNodes->item(0)->childNodes;
for ($k = 0; $k < $fields->length; $k++) {
if ($fields->item($k)->getAttribute('name') == 'folders') {
$arrNewFolders = deserialize($fields->item($k)->nodeValue);
break;
}
}
break;
}
}
// Sync the new folder(s)
if (!empty($arrNewFolders) && is_array($arrNewFolders)) {
foreach ($arrNewFolders as $strFolder) {
\Dbafs::addResource($this->customizeUploadPath($strFolder));
}
}
// Lock the tables
$arrLocks = array('tl_files' => 'WRITE', 'tl_theme' => 'WRITE', 'tl_style_sheet' => 'WRITE', 'tl_style' => 'WRITE', 'tl_module' => 'WRITE', 'tl_layout' => 'WRITE', 'tl_image_size' => 'WRITE', 'tl_image_size_item' => 'WRITE');
// Load the DCAs of the locked tables (see #7345)
foreach (array_keys($arrLocks) as $table) {
$this->loadDataContainer($table);
}
$this->Database->lockTables($arrLocks);
// Get the current auto_increment values
$tl_files = $this->Database->getNextId('tl_files');
$tl_theme = $this->Database->getNextId('tl_theme');
$tl_style_sheet = $this->Database->getNextId('tl_style_sheet');
$tl_style = $this->Database->getNextId('tl_style');
$tl_module = $this->Database->getNextId('tl_module');
$tl_layout = $this->Database->getNextId('tl_layout');
$tl_image_size = $this->Database->getNextId('tl_image_size');
$tl_image_size_item = $this->Database->getNextId('tl_image_size_item');
// Loop through the tables
for ($i = 0; $i < $tables->length; $i++) {
$rows = $tables->item($i)->childNodes;
$table = $tables->item($i)->getAttribute('name');
// Skip invalid tables
if (!in_array($table, array_keys($arrLocks))) {
continue;
}
// Get the order fields
$objDcaExtractor = \DcaExtractor::getInstance($table);
$arrOrder = $objDcaExtractor->getOrderFields();
// Loop through the rows
for ($j = 0; $j < $rows->length; $j++) {
$set = array();
$fields = $rows->item($j)->childNodes;
// Loop through the fields
for ($k = 0; $k < $fields->length; $k++) {
$value = $fields->item($k)->nodeValue;
$name = $fields->item($k)->getAttribute('name');
// Skip NULL values
if ($value == 'NULL') {
continue;
} elseif ($name == 'id') {
$id = ${$table}++;
//.........这里部分代码省略.........
示例6: unprotect
/**
* Unprotect the folder by adding a .public file
*/
public function unprotect()
{
if (!file_exists(TL_ROOT . '/' . $this->strFolder . '/.public')) {
\File::putContent($this->strFolder . '/.public', '');
}
}
示例7: protect
/**
* Protect the folder by adding an .htaccess file
*/
public function protect()
{
if (!file_exists(TL_ROOT . '/' . $this->strFolder . '/.htaccess')) {
\File::putContent($this->strFolder . '/.htaccess', "<IfModule !mod_authz_core.c>\n Order deny,allow\n Deny from all\n</IfModule>\n<IfModule mod_authz_core.c>\n Require all denied\n</IfModule>");
}
}
示例8: generateFiles
//.........这里部分代码省略.........
* @param array
*/
protected function generateFiles($arrFeed)
{
$arrArchives = deserialize($arrFeed['archives']);
if (!is_array($arrArchives) || empty($arrArchives)) {
return;
}
switch ($arrFeed['format']) {
case 'rss':
$strType = 'generateRss';
break;
case 'atom':
$strType = 'generateAtom';
break;
case 'podcast':
$strType = 'generatePodcast';
break;
}
$strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
$strFile = $arrFeed['feedName'];
$objFeed = new FeedPodcast($strFile);
$objFeed->link = $strLink;
$objFeed->title = $arrFeed['title'];
$objFeed->description = $arrFeed['description'];
$objFeed->language = $arrFeed['language'];
$objFeed->published = $arrFeed['tstamp'];
//Add Feed Image
if ($arrFeed['format'] == 'podcast') {
$objFile = \FilesModel::findByUuid($arrFeed['podcastSingleSRC']);
if ($objFile !== null) {
$objFeed->imageUrl = \Environment::get('base') . $objFile->path;
}
}
// Get the items
if ($arrFeed['maxItems'] > 0) {
$objSermons = \SermonerItemsModel::findPublishedByPids($arrArchives, $arrFeed['maxItems']);
} else {
$objSermons = \SermonerItemsModel::findPublishedByPids($arrArchives);
}
// Parse the items
if ($objSermons !== null) {
$arrUrls = array();
while ($objSermons->next()) {
$jumpTo = $objSermons->getRelated('pid')->jumpTo;
// No jumpTo page set (see #4784)
if (!$jumpTo) {
continue;
}
// Get the jumpTo URL
if (!isset($arrUrls[$jumpTo])) {
$objParent = \PageModel::findWithDetails($jumpTo);
// A jumpTo page is set but does no longer exist (see #5781)
if ($objParent === null) {
$arrUrls[$jumpTo] = false;
} else {
$arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/%s' : '/items/%s', $objParent->language);
}
}
// Skip the event if it requires a jumpTo URL but there is none
if ($arrUrls[$jumpTo] === false && $objSermons->source == 'default') {
continue;
}
$strUrl = $arrUrls[$jumpTo];
$objItem = new \FeedItem();
$objItem->title = $objSermons->title;
$objItem->link = $strLink . sprintf($strUrl, $objSermons->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objSermons->alias : $objSermons->id);
$objItem->published = $objSermons->date;
$objItem->author = $objSermons->speaker;
// Prepare the description
if ($arrFeed['format'] == 'podcast') {
$objItem->description = $this->replaceSermonInsertTags($arrFeed['podcastSubtitle'], $objSermons);
}
// Add the article image as enclosure
if ($objSermons->addImage) {
$objFile = \FilesModel::findByUuid($objSermons->singleSRC);
if ($objFile !== null) {
$objItem->addEnclosure($objFile->path);
}
}
// Add the Sermon Audio File
if ($objSermons->audioSingleSRC) {
$objFile = \FilesModel::findByUuid($objSermons->audioSingleSRC);
if ($objFile !== null) {
$objItem->addEnclosure($objFile->path);
//Prepare the duration if it's a podcast
if ($arrFeed['format'] == 'podcast') {
$this->import('getid3');
$getID3 = new \getID3();
$mp3FileInfo = $getID3->analyze(TL_ROOT . '/' . $objFile->path);
$objItem->duration = @$mp3FileInfo['playtime_string'];
}
}
}
$objFeed->addItem($objItem);
}
}
// Create the file
\File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}()));
}
示例9: compile
/**
* Generate module
*/
protected function compile()
{
// Create files
if (\Input::post('FORM_SUBMIT') == 'tl_extension') {
$objModule = $this->Database->prepare("SELECT * FROM tl_extension WHERE id=?")->limit(1)->execute($this->objDc->id);
if ($objModule->numRows < 1) {
return;
}
// Disable the debug mode (see #7068)
\Config::set('debugMode', false);
// config/config.php
$tplConfig = $this->newTemplate('dev_config', $objModule);
\File::putContent('system/modules/' . $objModule->folder . '/config/config.php', $tplConfig->parse());
// config/autoload.ini
$tplConfig = $this->newTemplate('dev_ini', $objModule);
\File::putContent('system/modules/' . $objModule->folder . '/config/autoload.ini', $tplConfig->parse());
// Back end
if ($objModule->addBeMod) {
$arrClasses = array_filter(trimsplit(',', $objModule->beClasses));
// Classes
foreach ($arrClasses as $strClass) {
$tplClass = $this->newTemplate('dev_beClass', $objModule);
$tplClass->class = $strClass;
\File::putContent('system/modules/' . $objModule->folder . '/' . $this->guessSubfolder($strClass) . '/' . $strClass . '.php', $tplClass->parse());
}
$arrTables = array_filter(trimsplit(',', $objModule->beTables));
// Back end data container files
foreach ($arrTables as $strTable) {
$tplTable = $this->newTemplate('dev_dca', $objModule);
$tplTable->table = $strTable;
\File::putContent('system/modules/' . $objModule->folder . '/dca/' . $strTable . '.php', $tplTable->parse());
}
$arrTemplates = array_filter(trimsplit(',', $objModule->beTemplates));
// Templates
foreach ($arrTemplates as $strTemplate) {
$tplTemplate = $this->newTemplate('dev_beTemplate', $objModule);
\File::putContent('system/modules/' . $objModule->folder . '/templates/' . $strTemplate . '.html5', $tplTemplate->parse());
}
}
$arrTables = array();
// Front end
if ($objModule->addFeMod) {
$arrClasses = array_filter(trimsplit(',', $objModule->feClasses));
// Classes
foreach ($arrClasses as $strClass) {
$tplClass = $this->newTemplate('dev_feClass', $objModule);
$tplClass->class = $strClass;
$tplClass->extends = $this->guessParentClass($strClass);
\File::putContent('system/modules/' . $objModule->folder . '/' . $this->guessSubfolder($strClass) . '/' . $strClass . '.php', $tplClass->parse());
}
$arrTables = array_filter(trimsplit(',', $objModule->feTables));
// Front end data container files
foreach ($arrTables as $strTable) {
$tplTable = $this->newTemplate('dev_feDca', $objModule);
$tplTable->table = $strTable;
\File::putContent('system/modules/' . $objModule->folder . '/dca/' . $strTable . '.php', $tplTable->parse());
}
// Models
foreach ($arrTables as $strTable) {
$strModel = \Model::getClassFromTable($strTable);
$tplTable = $this->newTemplate('dev_model', $objModule);
$tplTable->table = $strTable;
$tplTable->class = $strModel;
\File::putContent('system/modules/' . $objModule->folder . '/models/' . $strModel . '.php', $tplTable->parse());
}
$arrTemplates = array_filter(trimsplit(',', $objModule->feTemplates));
// Templates
foreach ($arrTemplates as $strTemplate) {
$tplTemplate = $this->newTemplate('dev_feTemplate', $objModule);
$objTemplate = new \File('system/modules/' . $objModule->folder . '/templates/' . $strTemplate . '.html5', true);
$objTemplate->write($tplTemplate->parse());
$objTemplate->close();
$objTemplate->copyTo('system/modules/' . $objModule->folder . '/templates/' . $strTemplate . '.xhtml');
}
}
// Language packs
if ($objModule->addLanguage) {
$arrLanguages = array_filter(trimsplit(',', $objModule->languages));
foreach ($arrLanguages as $strLanguage) {
// languages/xx/default.php
$tplLanguage = $this->newTemplate('dev_default', $objModule);
$tplLanguage->language = $strLanguage;
\File::putContent('system/modules/' . $objModule->folder . '/languages/' . $strLanguage . '/default.php', $tplLanguage->parse());
// languages/xx/modules.php
$tplLanguage = $this->newTemplate('dev_modules', $objModule);
$tplLanguage->language = $strLanguage;
\File::putContent('system/modules/' . $objModule->folder . '/languages/' . $strLanguage . '/modules.php', $tplLanguage->parse());
// languages/xx/<table>.php
foreach ($arrTables as $strTable) {
$tplLanguage = $this->newTemplate('dev_table', $objModule);
$tplLanguage->language = $strLanguage;
$tplLanguage->table = $strTable;
\File::putContent('system/modules/' . $objModule->folder . '/languages/' . $strLanguage . '/' . $strTable . '.php', $tplLanguage->parse());
}
}
}
// Public folder
//.........这里部分代码省略.........
示例10: generateFiles
/**
* Generate an XML files and save them to the root directory
*
* @param array $arrFeed
*/
protected function generateFiles($arrFeed)
{
$arrArchives = deserialize($arrFeed['archives']);
if (!is_array($arrArchives) || empty($arrArchives)) {
return;
}
$strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
$strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
$strFile = $arrFeed['feedName'];
$objFeed = new \Feed($strFile);
$objFeed->link = $strLink;
$objFeed->title = $arrFeed['title'];
$objFeed->description = $arrFeed['description'];
$objFeed->language = $arrFeed['language'];
$objFeed->published = $arrFeed['tstamp'];
// Get the items
if ($arrFeed['maxItems'] > 0) {
$objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
} else {
$objArticle = \NewsModel::findPublishedByPids($arrArchives);
}
// Parse the items
if ($objArticle !== null) {
$arrUrls = array();
while ($objArticle->next()) {
/** @var \PageModel $objPage */
$objPage = $objArticle->getRelated('pid');
$jumpTo = $objPage->jumpTo;
// No jumpTo page set (see #4784)
if (!$jumpTo) {
continue;
}
// Get the jumpTo URL
if (!isset($arrUrls[$jumpTo])) {
$objParent = \PageModel::findWithDetails($jumpTo);
// A jumpTo page is set but does no longer exist (see #5781)
if ($objParent === null) {
$arrUrls[$jumpTo] = false;
} else {
$arrUrls[$jumpTo] = $objParent->getFrontendUrl(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s');
}
}
// Skip the event if it requires a jumpTo URL but there is none
if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
continue;
}
$strUrl = $arrUrls[$jumpTo];
$objItem = new \FeedItem();
$objItem->title = $objArticle->headline;
$objItem->link = $this->getLink($objArticle, $strUrl, $strLink);
$objItem->published = $objArticle->date;
$objItem->author = $objArticle->authorName;
// Prepare the description
if ($arrFeed['source'] == 'source_text') {
$strDescription = '';
$objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
if ($objElement !== null) {
// Overwrite the request (see #7756)
$strRequest = \Environment::get('request');
\Environment::set('request', $objItem->link);
while ($objElement->next()) {
$strDescription .= $this->getContentElement($objElement->current());
}
\Environment::set('request', $strRequest);
}
} else {
$strDescription = $objArticle->teaser;
}
$strDescription = $this->replaceInsertTags($strDescription, false);
$objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
// Add the article image as enclosure
if ($objArticle->addImage) {
$objFile = \FilesModel::findByUuid($objArticle->singleSRC);
if ($objFile !== null) {
$objItem->addEnclosure($objFile->path, $strLink);
}
}
// Enclosures
if ($objArticle->addEnclosure) {
$arrEnclosure = deserialize($objArticle->enclosure, true);
if (is_array($arrEnclosure)) {
$objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
if ($objFile !== null) {
while ($objFile->next()) {
$objItem->addEnclosure($objFile->path, $strLink);
}
}
}
}
$objFeed->addItem($objItem);
}
}
// Create the file
\File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
}
示例11: putContentForCacheFile
protected function putContentForCacheFile()
{
$this->cacheFile->truncate();
$this->cacheFile->putContent($this->cacheFile->path, json_encode($this->cacheUrl));
}
示例12: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var \PageModel $objPage */
global $objPage;
// Mark the x and y parameter as used (see #4277)
if (isset($_GET['x'])) {
\Input::get('x');
\Input::get('y');
}
// Trigger the search module from a custom form
if (!isset($_GET['keywords']) && \Input::post('FORM_SUBMIT') == 'tl_search') {
$_GET['keywords'] = \Input::post('keywords');
$_GET['query_type'] = \Input::post('query_type');
$_GET['per_page'] = \Input::post('per_page');
}
$blnFuzzy = $this->fuzzy;
$strQueryType = \Input::get('query_type') ?: $this->queryType;
$strKeywords = trim(\Input::get('keywords'));
/** @var \FrontendTemplate|object $objFormTemplate */
$objFormTemplate = new \FrontendTemplate($this->searchType == 'advanced' ? 'mod_search_advanced' : 'mod_search_simple');
$objFormTemplate->uniqueId = $this->id;
$objFormTemplate->queryType = $strQueryType;
$objFormTemplate->keyword = specialchars($strKeywords);
$objFormTemplate->keywordLabel = $GLOBALS['TL_LANG']['MSC']['keywords'];
$objFormTemplate->optionsLabel = $GLOBALS['TL_LANG']['MSC']['options'];
$objFormTemplate->search = specialchars($GLOBALS['TL_LANG']['MSC']['searchLabel']);
$objFormTemplate->matchAll = specialchars($GLOBALS['TL_LANG']['MSC']['matchAll']);
$objFormTemplate->matchAny = specialchars($GLOBALS['TL_LANG']['MSC']['matchAny']);
$objFormTemplate->id = \Config::get('disableAlias') && \Input::get('id') ? \Input::get('id') : false;
$objFormTemplate->action = ampersand(\Environment::get('indexFreeRequest'));
// Redirect page
if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
$objFormTemplate->action = $this->generateFrontendUrl($objTarget->row());
}
$this->Template->form = $objFormTemplate->parse();
$this->Template->pagination = '';
$this->Template->results = '';
// Execute the search if there are keywords
if ($strKeywords != '' && $strKeywords != '*' && !$this->jumpTo) {
// Reference page
if ($this->rootPage > 0) {
$intRootId = $this->rootPage;
$arrPages = $this->Database->getChildRecords($this->rootPage, 'tl_page');
array_unshift($arrPages, $this->rootPage);
} else {
$intRootId = $objPage->rootId;
$arrPages = $this->Database->getChildRecords($objPage->rootId, 'tl_page');
}
// HOOK: add custom logic (see #5223)
if (isset($GLOBALS['TL_HOOKS']['customizeSearch']) && is_array($GLOBALS['TL_HOOKS']['customizeSearch'])) {
foreach ($GLOBALS['TL_HOOKS']['customizeSearch'] as $callback) {
$this->import($callback[0]);
$this->{$callback[0]}->{$callback[1]}($arrPages, $strKeywords, $strQueryType, $blnFuzzy);
}
}
// Return if there are no pages
if (!is_array($arrPages) || empty($arrPages)) {
$this->log('No searchable pages found', __METHOD__, TL_ERROR);
return;
}
$arrResult = null;
$strChecksum = md5($strKeywords . $strQueryType . $intRootId . $blnFuzzy);
$query_starttime = microtime(true);
$strCacheFile = 'system/cache/search/' . $strChecksum . '.json';
// Load the cached result
if (file_exists(TL_ROOT . '/' . $strCacheFile)) {
$objFile = new \File($strCacheFile, true);
if ($objFile->mtime > time() - 1800) {
$arrResult = json_decode($objFile->getContent(), true);
} else {
$objFile->delete();
}
}
// Cache the result
if ($arrResult === null) {
try {
$objSearch = \Search::searchFor($strKeywords, $strQueryType == 'or', $arrPages, 0, 0, $blnFuzzy);
$arrResult = $objSearch->fetchAllAssoc();
} catch (\Exception $e) {
$this->log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
$arrResult = array();
}
\File::putContent($strCacheFile, json_encode($arrResult));
}
$query_endtime = microtime(true);
// Sort out protected pages
if (\Config::get('indexProtected') && !BE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
foreach ($arrResult as $k => $v) {
if ($v['protected']) {
if (!FE_USER_LOGGED_IN) {
unset($arrResult[$k]);
} else {
$groups = deserialize($v['groups']);
if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) {
unset($arrResult[$k]);
}
//.........这里部分代码省略.........
示例13: generateFiles
//.........这里部分代码省略.........
{
$arrArchives = deserialize($arrFeed['archives']);
if (!is_array($arrArchives) || empty($arrArchives)) {
return;
}
$strType = 'generateItunes';
$strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
$strFile = $arrFeed['feedName'];
$objFeed = new iTunesFeed($strFile);
$objFeed->link = $strLink;
$objFeed->podcastUrl = $strLink . 'share/' . $strFile . '.xml';
$objFeed->title = $arrFeed['title'];
$objFeed->subtitle = $arrFeed['subtitle'];
$objFeed->description = $this->cleanHtml($arrFeed['description']);
$objFeed->explicit = $arrFeed['explicit'];
$objFeed->language = $arrFeed['language'];
$objFeed->author = $arrFeed['author'];
$objFeed->owner = $arrFeed['owner'];
$objFeed->email = $arrFeed['email'];
$objFeed->category = $arrFeed['category'];
$objFeed->published = $arrFeed['tstamp'];
//Add Feed Image
$objFile = \FilesModel::findByUuid($arrFeed['image']);
if ($objFile !== null) {
$objFeed->imageUrl = \Environment::get('base') . $objFile->path;
}
// Get the items
if ($arrFeed['maxItems'] > 0) {
$objPodcasts = \NewsPodcastsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
} else {
$objPodcasts = \NewsPodcastsModel::findPublishedByPids($arrArchives);
}
// Parse the items
if ($objPodcasts !== null) {
$arrUrls = array();
while ($objPodcasts->next()) {
$jumpTo = $objPodcasts->getRelated('pid')->jumpTo;
// No jumpTo page set (see #4784)
if (!$jumpTo) {
continue;
}
// Get the jumpTo URL
if (!isset($arrUrls[$jumpTo])) {
$objParent = \PageModel::findWithDetails($jumpTo);
// A jumpTo page is set but does no longer exist (see #5781)
if ($objParent === null) {
$arrUrls[$jumpTo] = false;
} else {
$arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/%s' : '/items/%s', $objParent->language);
}
}
// Skip the event if it requires a jumpTo URL but there is none
if ($arrUrls[$jumpTo] === false && $objPodcasts->source == 'default') {
continue;
}
$strUrl = $arrUrls[$jumpTo];
$objItem = new \FeedItem();
$objItem->headline = $this->cleanHtml($objPodcasts->headline);
$objItem->subheadline = $this->cleanHtml($objPodcasts->subheadline !== null ? $objPodcasts->subheadline : $objPodcasts->description);
$objItem->link = $strLink . sprintf($strUrl, $objPodcasts->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objPodcasts->alias : $objPodcasts->id);
$objItem->published = $objPodcasts->date;
$objAuthor = $objPodcasts->getRelated('author');
$objItem->author = $objAuthor->name;
$objItem->description = $this->cleanHtml($objPodcasts->teaser);
$objItem->explicit = $objPodcasts->explicit;
// Add the article image as enclosure
$objItem->addEnclosure($objFeed->imageUrl);
// Add the Audio File
if ($objPodcasts->podcast) {
$objFile = \FilesModel::findByUuid($objPodcasts->podcast);
if ($objFile !== null) {
// Add statistics service
if (!empty($arrFeed['addStatistics'])) {
// If no trailing slash given, add one
$statisticsPrefix = rtrim($arrFeed['statisticsPrefix'], '/') . '/';
$podcastPath = $statisticsPrefix . \Environment::get('host') . '/' . preg_replace('(^https?://)', '', $objFile->path);
} else {
$podcastPath = \Environment::get('base') . \System::urlEncode($objFile->path);
}
$objItem->podcastUrl = $podcastPath;
// Prepare the duration / prefer linux tool mp3info
$mp3file = new GetMp3Duration(TL_ROOT . '/' . $objFile->path);
if ($this->checkMp3InfoInstalled()) {
$shell_command = 'mp3info -p "%S" ' . escapeshellarg(TL_ROOT . '/' . $objFile->path);
$duration = shell_exec($shell_command);
} else {
$duration = $mp3file->getDuration();
}
$objPodcastFile = new \File($objFile->path, true);
$objItem->length = $objPodcastFile->size;
$objItem->type = $objPodcastFile->mime;
$objItem->duration = $mp3file->formatTime($duration);
}
}
$objFeed->addItem($objItem);
}
}
// Create the file
\File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
}
示例14: generateFiles
/**
* Generate the XML files and save them to the root directory
* @param array
*/
protected function generateFiles($arrFeed)
{
$arrConfigs = deserialize($arrFeed['configs']);
if (!is_array($arrConfigs) || count($arrConfigs) < 1) {
return;
}
$strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
$strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
$strFile = $arrFeed['feedName'];
$objFeed = new \Feed($strFile);
$objFeed->link = $strLink;
$objFeed->title = $arrFeed['title'];
$objFeed->description = $arrFeed['description'];
$objFeed->language = $arrFeed['language'];
$objFeed->published = $arrFeed['tstamp'];
$objJumpTo = \PageModel::findByPk($arrFeed['jumpTo']);
// find the source attributes
$objDescriptionAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['descriptionField']);
$objPublishedAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['publishedField']);
$objTitleAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['titleField']);
$objAuthorAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['authorField']);
$objImageAttribute = \PCT\CustomElements\Core\AttributeFactory::fetchById($arrFeed['imageField']);
$arrFields = array('id', 'pid', 'tstamp', 'description' => $objDescriptionAttribute->alias, 'title' => $objTitleAttribute->alias, 'published' => $objPublishedAttribute->alias, 'author' => $objAuthorAttribute->alias, 'singleSRC' => $objImageAttribute->alias);
foreach ($arrConfigs as $config_id) {
$objCC = CustomCatalogFactory::findById($config_id);
if ($objCC === null) {
continue;
}
// set visibles to source attribute only
$objCC->setVisibles(array_filter(array_values($arrFields)));
if ($arrFeed['maxItems'] > 0) {
$objCC->setLimit($arrFeed['maxItems']);
}
// fetch the entries
$objEntries = $objCC->prepare();
if ($objEntries->numRows < 1) {
continue;
}
while ($objEntries->next()) {
$objItem = new \FeedItem();
$objItem->title = $objEntries->{$arrFields['title']};
$objItem->link = $strLink . $objCC->generateDetailsUrl($objEntries, $objJumpTo);
$objItem->published = $objEntries->{$arrFields['published']} ?: $objEntries->tstamp;
$objItem->author = $objEntries->{$arrFields['author']} ?: '';
$strDescription = $this->replaceInsertTags($objEntries->{$arrFields['description']}, false);
$objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
if ($objEntries->{$arrFields['singleSRC']} && $objImageAttribute->published) {
$objFile = \FilesModel::findByUuid($objEntries->{$arrFields['singleSRC']});
if ($objFile !== null) {
$objItem->addEnclosure($objFile->path);
}
}
// add feed item
$objFeed->addItem($objItem);
}
}
// create file
\File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
}
示例15: getCombinedFile
/**
* Generate the combined file and return its path
*
* @param string $strUrl An optional URL to prepend
*
* @return string The path to the combined file
*/
public function getCombinedFile($strUrl = null)
{
if ($strUrl === null) {
$strUrl = TL_ASSETS_URL;
}
$strTarget = substr($this->strMode, 1);
$strKey = substr(md5($this->strKey), 0, 12);
// Do not combine the files in debug mode (see #6450)
if (\Config::get('debugMode')) {
$return = array();
foreach ($this->arrFiles as $arrFile) {
$content = file_get_contents(TL_ROOT . '/' . $arrFile['name']);
// Compile SCSS/LESS files into temporary files
if ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) {
$strPath = 'assets/' . $strTarget . '/' . str_replace('/', '_', $arrFile['name']) . $this->strMode;
$objFile = new \File($strPath, true);
$objFile->write($this->handleScssLess($content, $arrFile));
$objFile->close();
$return[] = $strPath;
} else {
$name = $arrFile['name'];
// Add the media query (see #7070)
if ($arrFile['media'] != '' && $arrFile['media'] != 'all' && strpos($content, '@media') === false) {
$name .= '" media="' . $arrFile['media'];
}
$return[] = $name;
}
}
if ($this->strMode == self::JS) {
return implode('"></script><script src="', $return);
} else {
return implode('"><link rel="stylesheet" href="', $return);
}
}
// Load the existing file
if (file_exists(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode)) {
return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode;
}
// Create the file
$objFile = new \File('assets/' . $strTarget . '/' . $strKey . $this->strMode, true);
$objFile->truncate();
foreach ($this->arrFiles as $arrFile) {
$content = file_get_contents(TL_ROOT . '/' . $arrFile['name']);
// HOOK: modify the file content
if (isset($GLOBALS['TL_HOOKS']['getCombinedFile']) && is_array($GLOBALS['TL_HOOKS']['getCombinedFile'])) {
foreach ($GLOBALS['TL_HOOKS']['getCombinedFile'] as $callback) {
$this->import($callback[0]);
$content = $this->{$callback}[0]->{$callback}[1]($content, $strKey, $this->strMode, $arrFile);
}
}
if ($arrFile['extension'] == self::CSS) {
$content = $this->handleCss($content, $arrFile);
} elseif ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) {
$content = $this->handleScssLess($content, $arrFile);
}
$objFile->append($content);
}
unset($content);
$objFile->close();
// Create a gzipped version
if (\Config::get('gzipScripts') && function_exists('gzencode')) {
\File::putContent('assets/' . $strTarget . '/' . $strKey . $this->strMode . '.gz', gzencode(file_get_contents(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode), 9));
}
return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode;
}