/** * Return all image attributes * @param object * @return array */ public function getImageAttributes($objDC) { $options = array('column' => 'type', 'operation' => 'FIND_IN_SET', 'value' => array('image')); $objResult = \PCT\CustomElements\Core\AttributeFactory::fetchMultipleByCustomElement($objDC->activeRecord->pid, $options); if ($objResult->numRows < 1) { return array(); } $arrReturn = array(); while ($objResult->next()) { $arrReturn[$objResult->id] = $objResult->title . ' [' . $objResult->type . ']'; } return $arrReturn; }
/** * 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)); }