diff --git a/CHANGELOG.md b/CHANGELOG.md index b38d95e0..cd33e8be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ ## Changelog +#### 1.4.0 + +- Craft 2.5 support, including release feed and icons. +- Code cleanup and refactoring field-mapping logic for performance and sanity. +- Rewritten Matrix/Table mapping and processing logic. **Matrix and Table fields will need to be re-mapped**. +- Fix for mapping multiple Matrix blocks being out of order from original feed. +- Removed Super Table native support - please ensure you have the 0.3.9 release of Super Table. **Super Table fields will need to be re-mapped**. +- Modified third-party hooks `prepForFeedMeFieldType` so it actually works! Thanks go to [@lindseydiloreto](https://github.com/lindseydiloreto). +- Added `registerFeedMeMappingOptions` for third-party fieldtypes to control the options for mapping feed nodes to field data. +- Added `postForFeedMeFieldType` for third-party fieldtypes to modify entry data before being saved to entry. +- Added documentation for hooks. Refer to [Wiki](https://github.com/engram-design/FeedMe/wiki/Hooks). +- Less strict user matching - should match against almost any value related to user. +- Allow for Environment Variables to be used in the feed url. + +#### 1.3.6 + +- Removed `file_get_contents` as default method of fetching feed data in favour of Curl. +- Better error logging when trying to consume feed data. +- Fix for when mapping to Matrix field, commas were escaping content into new blocks. +- Ensure fields within Matrix and SuperTable are parsed through necessary field processing functions. +- Added `prepForFeedMeFieldType` hook for other plugins to handle their own fields. + #### 1.3.5 - Minor fix for logging. When Delete duplication option was set, import success was never recorded in the logs. @@ -104,4 +126,3 @@ #### 1.0 - Initial release. - diff --git a/README.md b/README.md index d9fc8a4c..81c274db 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ A common use-case for this plugin is to consume external feeds (news, events), b - Database backups before each feed processing. - Troubleshoot feed processing issues with logs. - Grab feed data directly from your twig templates. +- Craft 2.5 compatible. ## Install @@ -28,6 +29,7 @@ A common use-case for this plugin is to consume external feeds (news, events), b - Change the plugin name as it appear in the CP navigation. - Set the default cache (for calls using the template tag only). +- Enable or disable specific tabs for Feed Me. ## Usage @@ -47,6 +49,8 @@ Enter the required details to configure your feed: Then, select what data from the feed you wish to capture, and what fields to map it to, depending on your Section and Entry Type selection. Here you'll be able to choose which fields (can be more than one) you'd like to compare to determine if a feed item is a duplicate. +You must map data to at least the Title field, or any other required field for your entry. + Save the feed for later, or start the import. @@ -77,6 +81,11 @@ Feed Me supports mapping data from your feeds to the following Fieldtypes: - Tags - Users +**Third-Party** + +- Super Table +- SmartMap + ###Element Creation @@ -84,15 +93,19 @@ For certain elements, it may be benefitial to create the element's data, if not Currently, Feed Me handles the following applicable fields in these ways: -**Assets:** Only supports mapping existing assets to this entry. Must provide filename (without extension) to successfully map. +**Assets:** Only supports mapping existing assets to this entry. -**Categories:** Are created if they do not exist, or mapped if they do. The value provided in the feed data must be the Name for the category. +**Categories:** Are created if they do not exist, or mapped if they do. **Entries:** Only supports mapping existing entries to this entry. The feed field must contain either the Title or Slug of the entry to successfully map. **Tags:** Are always created. -**Users:** Only supports mapping existing users to this entry. The feed field must contain either the users email or username to successfully map. +**Users:** Only supports mapping existing users to this entry. + +Internally, Feed Me uses Craft's element search to match against the value in your feed for an element. For example, if you have `my_filename.png` as a value in your feed, and you are mapping to an Asset, ensure that searching through the Assets index screen actually returns what you expect. + +For troubleshooting, ensure you have completed the Rebuild Search Indexes task. We plan to include options for whether you would like to do this on a per-field basis. @@ -194,6 +207,11 @@ For XML-based feeds, you will also have access to all attributes for a particula If you're looking to consume REST feeds, APIs or other third-party platforms (Facebook, Twitter, etc), I would highly recommend using [alecritson's Placid](https://github.com/alecritson/Placid) plugin, which supports a great deal more than this plugin offers. +## Hooks + +For third-party field type integration, consult the [Wiki](https://github.com/engram-design/FeedMe/wiki/Hooks). + + ## Roadmap - Improve mapping by: @@ -208,7 +226,7 @@ If you're looking to consume REST feeds, APIs or other third-party platforms (Fa - Allow feed processing to be reverted - Support authentication for feed access (Basic, OAuth, Token) - Organise documentation into Wiki -- Fix issue with mapping of Assets and the source not being set to All. +- Fix issue with mapping of Assets and the source not being set to All (not reproducible). Have a suggestion? We'd love to hear about it! [Make a suggestion](https://github.com/engram-design/FeedMe/issues) @@ -224,20 +242,11 @@ Otherwise, either [Submit an issue](https://github.com/engram-design/FeedMe/issu ## Thanks / Contributions -A massive thanks to [Bob Olde Hampsink](https://github.com/boboldehampsink) and his amazing work on the [Import](https://github.com/boboldehampsink/import) plugin, which this plugin is clearly influenced by, and [Clearbold](https://github.com/clearbold) for [Craft Import](https://github.com/clearbold/craftimport). +A massive thanks to [Bob Olde Hampsink](https://github.com/boboldehampsink) and his amazing work on the [Import](https://github.com/boboldehampsink/import) plugin, which this plugin is clearly influenced by, and [Clearbold](https://github.com/clearbold) for [Craft Import](https://github.com/clearbold/craftimport), along with all the great users who have helped provide feedback, testing and bug reports. [Pixel & Tonic](https://github.com/pixelandtonic) for their amazing support, assistance, and of course for creating Craft. ## Changelog -#### 1.3.6 - -- Removed `file_get_contents` as default method of fetching feed data in favour of Curl. -- Better error logging when trying to consume feed data. -- Fix for when mapping to Matrix field, commas were escaping content into new blocks. -- Ensure fields within Matrix and SuperTable are parsed through necessary field processing functions. -- Added `prepForFeedMeFieldType` hook for other plugins to handle their own fields. - - -[View Full Changelog](https://github.com/engram-design/FeedMe/blob/master/CHANGELOG.md) +[View JSON Changelog](https://github.com/engram-design/FeedMe/blob/master/changelog.json) diff --git a/changelog.json b/changelog.json new file mode 100644 index 00000000..36fa5524 --- /dev/null +++ b/changelog.json @@ -0,0 +1,24 @@ +[ + { + "version": "1.4.0", + "downloadUrl": "https://github.com/engram-design/FeedMe/archive/1.4.0.zip", + "date": "2015-11-26 00:00:00", + "notes": [ + "[Added] Craft 2.5 support, including release feed and icons.", + "[Improved] Code cleanup and refactoring field-mapping logic for performance and sanity.", + "[Improved] Rewritten Matrix/Table mapping and processing logic. **Matrix and Table fields will need to be re-mapped**.", + "[Improved] Removed Super Table native support - please ensure you have the 0.3.9 release of Super Table. **Super Table fields will need to be re-mapped**.", + "[Improved] Less strict user matching - should match against almost any value related to user.", + "[Improved] Allow for Environment Variables to be used in the feed url." + "[Improved] Better feedback on feed failure. Will fail task if _any_ feed node encounters an issue, and will show the red failed task indicator (prompting you to look at the logs)." + "[Fixed] Fix for mapping multiple Matrix blocks being out of order from original feed.", + "[Fixed] Fix issue with task not firing when running from Control Panel. In some cases, this meant not even logging information was being recorded if something went wrong. This did not effect running directly.", + + "# Third-Party Hooks", + "[Added] Added `registerFeedMeMappingOptions` for third-party fieldtypes to control the options for mapping feed nodes to field data.", + "[Added] Added `postForFeedMeFieldType` for third-party fieldtypes to modify entry data before being saved to entry.", + "[Added] Added documentation for hooks. Refer to [Wiki](https://github.com/engram-design/FeedMe/wiki/Hooks).", + "[Improved] Modified third-party hooks `prepForFeedMeFieldType` so it actually works! Thanks go to [@lindseydiloreto](https://github.com/lindseydiloreto).", + ] + } +] diff --git a/composer.json b/composer.json deleted file mode 100644 index 0e4367e5..00000000 --- a/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "engram-design/feedme", - "description": "A Craft CMS plugin which makes it easy to import entries and entry data from XML, RSS or ATOM feeds.", - "homepage": "https://github.com/engram-design/FeedMe", - "type": "craft-plugin", - "keywords": ["craft","plugin"], - "license": "MIT", - "authors": [{ - "name": "S. Group", - "email": "joshua@sgroup.com.au", - "homepage": "http://sgroup.com.au/" - }], - "require": { - "composer/installers": "~1.0" - } -} diff --git a/feedme/FeedMePlugin.php b/feedme/FeedMePlugin.php index fa07630a..c62bc9d8 100644 --- a/feedme/FeedMePlugin.php +++ b/feedme/FeedMePlugin.php @@ -10,9 +10,9 @@ class FeedMePlugin extends BasePlugin { - /* -------------------------------------------------------------- - * PLUGIN INFO - * ------------------------------------------------------------ */ + // ========================================================================= + // PLUGIN INFO + // ========================================================================= public function getName() { @@ -22,9 +22,18 @@ public function getName() return ($pluginNameOverride) ? $pluginNameOverride : $pluginName; } + public function getDescription(){ + return ''; + } + public function getVersion() { - return '1.3.6'; + return '1.4.0'; + } + + public function getSchemaVersion() + { + return '1.0.0'; } public function getDeveloper() @@ -42,6 +51,16 @@ public function getPluginUrl() return 'https://github.com/engram-design/FeedMe'; } + public function getDocumentationUrl() + { + return $this->getPluginUrl() . '/blob/master/README.md'; + } + + public function getReleaseFeedUrl() + { + return $this->getPluginUrl() . '/blob/master/changelog.json'; + } + public function hasCpSection() { return true; @@ -76,26 +95,18 @@ public function registerCpRoutes() ); } - public function onAfterInstall() - { - $minBuild = '2636'; - - if (craft()->getBuild() < $minBuild) { - craft()->plugins->disablePlugin($this->getClassHandle()); - - craft()->plugins->uninstallPlugin($this->getClassHandle()); - - craft()->userSession->setError(Craft::t('{plugin} only works on Craft build {build} or higher', array( - 'plugin' => $this->getName(), - 'build' => $minBuild, - ))); + public function onBeforeInstall() + { + // Craft 2.3.2636 fixed an issue with BaseEnum::getConstants() + if (version_compare(craft()->getVersion() . '.' . craft()->getBuild(), '2.3.2636', '<')) { + throw new Exception($this->getName() . ' requires Craft CMS 2.3.2636+ in order to run.'); } } - /* -------------------------------------------------------------- - * HOOKS - * ------------------------------------------------------------ */ + // ========================================================================= + // HOOKS + // ========================================================================= public function addTwigExtension() { diff --git a/feedme/controllers/FeedMeController.php b/feedme/controllers/FeedMeController.php index f971eca4..b6edb5ce 100644 --- a/feedme/controllers/FeedMeController.php +++ b/feedme/controllers/FeedMeController.php @@ -3,6 +3,9 @@ class FeedMeController extends BaseController { + // Public Methods + // ========================================================================= + public function actionGetEntryTypes() { // Only ajax post requests diff --git a/feedme/controllers/FeedMe_FeedsController.php b/feedme/controllers/FeedMe_FeedsController.php index c91caf2c..c7a2e8b4 100644 --- a/feedme/controllers/FeedMe_FeedsController.php +++ b/feedme/controllers/FeedMe_FeedsController.php @@ -3,8 +3,15 @@ class FeedMe_FeedsController extends BaseController { + // Properties + // ========================================================================= + protected $allowAnonymous = array('actionRunTask'); + + // Public Methods + // ========================================================================= + public function actionFeedsIndex() { $variables['feeds'] = craft()->feedMe_feeds->getFeeds(); @@ -152,6 +159,9 @@ public function runImportTask($feedId) { // Create the import task craft()->tasks->createTask('FeedMe', $feed->name, $settings); + // Trigger the task to run right now! + $this->_runPendingTasks(); + // if not using the direct param for this request, so UI stuff craft()->userSession->setNotice(Craft::t('Feed processing started.')); @@ -165,13 +175,7 @@ public function runImportTask($feedId) { craft()->tasks->createTask('FeedMe', $feed->name, $settings); // Trigger the task to run right now! - if (!craft()->tasks->isTaskRunning()) { - $task = craft()->tasks->getNextPendingTask(); - - if ($task) { - craft()->tasks->runPendingTasks(); - } - } + $this->_runPendingTasks(); // Let the requester know whats going on. $this->returnJson(array('success' => 'Feed ID: '.$feed['id'].' - Task started')); @@ -179,6 +183,24 @@ public function runImportTask($feedId) { $this->returnJson(array('error' => 'Invalid Passkey')); } } + + + } + + + + // Private Methods + // ========================================================================= + + private function _runPendingTasks() + { + if (!craft()->tasks->isTaskRunning()) { + $task = craft()->tasks->getNextPendingTask(); + + if ($task) { + craft()->tasks->runPendingTasks(); + } + } } } diff --git a/feedme/controllers/FeedMe_LogsController.php b/feedme/controllers/FeedMe_LogsController.php index fd1e96bc..a0aed2df 100644 --- a/feedme/controllers/FeedMe_LogsController.php +++ b/feedme/controllers/FeedMe_LogsController.php @@ -3,6 +3,9 @@ class FeedMe_LogsController extends BaseController { + // Public Methods + // ========================================================================= + public function actionLogs() { craft()->config->maxPowerCaptain(); diff --git a/feedme/controllers/FeedMe_SupportController.php b/feedme/controllers/FeedMe_SupportController.php index bc3f714d..8125ec12 100644 --- a/feedme/controllers/FeedMe_SupportController.php +++ b/feedme/controllers/FeedMe_SupportController.php @@ -3,6 +3,9 @@ class FeedMe_SupportController extends BaseController { + // Public Methods + // ========================================================================= + public function actionSendSupportRequest() { $this->requirePostRequest(); diff --git a/feedme/resources/icon-mask.svg b/feedme/resources/icon-mask.svg new file mode 100644 index 00000000..86e096d6 --- /dev/null +++ b/feedme/resources/icon-mask.svg @@ -0,0 +1,18 @@ + + + + +icon-mask +Created with Sketch. + + + + + diff --git a/feedme/resources/icon.svg b/feedme/resources/icon.svg new file mode 100644 index 00000000..a6e03e82 --- /dev/null +++ b/feedme/resources/icon.svg @@ -0,0 +1,26 @@ + + + + +icon +Created with Sketch. + + + + + + + + + + + + + diff --git a/feedme/resources/js/task.js b/feedme/resources/js/task.js deleted file mode 100644 index 5bc87532..00000000 --- a/feedme/resources/js/task.js +++ /dev/null @@ -1,48 +0,0 @@ -// Wrap logics in a function for recursive execution -function checkForTask(task, file) -{ - - // Force task to run - Craft.cp.setRunningTaskInfo({ - "id": task, - "level": "0", - "description": "Feeding " + file, - "status": "running", - "progress": 0 - }); - Craft.cp.trackTaskProgress(); - - // Wait for jQuery to be ready - $(function() { - - // Check if the taskicon is active - if(!$('#taskicon').length) { - - // If not, check every 500ms if it is - setTimeout(function() { - checkForTask(task, file); - }, 500); - - } else { - - // If it is, open the task dialog - $('#taskicon').trigger('click'); - - // Run a task checker every 500ms - var taskCheck = setInterval(function() { - - // Check if the task is done - if((Craft.cp.runningTaskInfo && Craft.cp.runningTaskInfo.id != task) || Craft.cp.runningTaskInfo === null) { - - // Clear task and redirect - clearInterval(taskCheck); - - } - - }, 500); - - } - - }); - -} \ No newline at end of file diff --git a/feedme/services/FeedMeService.php b/feedme/services/FeedMeService.php index c3392e47..19eafbe9 100644 --- a/feedme/services/FeedMeService.php +++ b/feedme/services/FeedMeService.php @@ -3,6 +3,9 @@ class FeedMeService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function setupForImport($feed) { // Return a collection of only the fields we're mapping @@ -45,20 +48,25 @@ public function setupForImport($feed) public function importNode($nodes, $feed, $settings) { + $hasAnyErrors = false; + $time_start = microtime(true); FeedMePlugin::log($feed->name . ': Processing started', LogLevel::Info, true); foreach ($nodes as $key => $node) { - $this->importSingleNode($node, $feed, $settings); + $result = $this->importSingleNode($node, $feed, $settings); - //echo number_format(memory_get_usage()) . "
"; + // Report back if even one feed node failed + if (!$result) { + $hasAnyErrors = true; + } } $time_end = microtime(true); $execution_time = number_format(($time_end - $time_start), 2); FeedMePlugin::log($feed->name . ': Processing finished in ' . $execution_time . 's', LogLevel::Info, true); - return true; + return !$hasAnyErrors; } public function importSingleNode($node, $feed, $settings) @@ -80,14 +88,14 @@ public function importSingleNode($node, $feed, $settings) // Start looping through all the mapped fields - grab their data from the feed node - foreach ($fields as $itemNode => &$destination) { + foreach ($fields as $itemNode => $handle) { // Fetch the value for the field from the feed node. Deep-search. $data = craft()->feedMe_feed->getValueForNode($itemNode, $node); // While we're in the loop, lets check for unique data to match existing entries on. if (isset($feed['fieldUnique'][$itemNode]) && intval($feed['fieldUnique'][$itemNode]) == 1 && !empty($data)) { - $criteria->$destination = DbHelper::escapeParam($data); + $criteria->$handle = DbHelper::escapeParam($data); } // @@ -95,31 +103,21 @@ public function importSingleNode($node, $feed, $settings) // try { - // The field handle needs to be modified in some cases (Matrix and Table). Here, we don't override - // the original handle for future iterations. We use the original handle to identify Matrix/Table fields. - $handle = $destination; - // Grab the field's content - formatted specifically for it $content = craft()->feedMe_fields->prepForFieldType($data, $handle); - // Check to see if this is a Matrix field - need to merge any other fields mapped elsewhere in the feed - // along with fields we've processed already. Involved due to multiple blocks can be defined at once. - if (substr($destination, 0, 10) == '__matrix__') { - $content = craft()->feedMe_fields->handleMatrixData($fieldData, $handle, $content); - } + // The first key of $content will always be the field handle - grab that to create our field data. + $fieldHandle = array_keys($content)[0]; - // And another special case for Table data - if (substr($destination, 0, 9) == '__table__') { - $content = craft()->feedMe_fields->handleTableData($fieldData, $handle, $content); - } - - // And another special case for SuperTable data - if (substr($destination, 0, 14) == '__supertable__') { - $content = craft()->feedMe_fields->handleSuperTableData($fieldData, $handle, $content); + // Then, we check if we've already got any partial content for the field. Most commongly, this is + // the case for Matrix and Table fields, but also likely other Third-Party fields. So its important to + // combine values, rather than overwriting or omitting as each feed node contains just part of the data. + if (array_key_exists($fieldHandle, $fieldData) && is_array($fieldData[$fieldHandle])) { + $fieldData[$fieldHandle] = array_replace_recursive($fieldData[$fieldHandle], $content[$fieldHandle]); + } else { + $fieldData[$fieldHandle] = $content[$fieldHandle]; } - // Finally - we have our mapped data, formatted for the particular field as required - $fieldData[$handle] = $content; } catch (\Exception $e) { FeedMePlugin::log($feed->name . ': FeedMeError: ' . $e->getMessage() . '.', LogLevel::Error, true); @@ -127,6 +125,9 @@ public function importSingleNode($node, $feed, $settings) } } + // Any post-processing on our nice collection of entry-ready data. + craft()->feedMe_fields->postForFieldType($fieldData); + $existingEntry = $criteria->first(); @@ -168,7 +169,7 @@ public function importSingleNode($node, $feed, $settings) $entry->setContentFromPost($fieldData); //echo '
';
-            //print_r($entry->title);
+            //print_r($fieldData);
             //echo '
'; try { diff --git a/feedme/services/FeedMe_CacheService.php b/feedme/services/FeedMe_CacheService.php index afbb3a45..d1cfbf98 100644 --- a/feedme/services/FeedMe_CacheService.php +++ b/feedme/services/FeedMe_CacheService.php @@ -3,6 +3,9 @@ class FeedMe_CacheService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function set($url, $value, $duration) { return craft()->cache->set(base64_encode(urlencode($url)), $value, $duration, null); diff --git a/feedme/services/FeedMe_EntryService.php b/feedme/services/FeedMe_EntryService.php index deb4c515..b99807f4 100644 --- a/feedme/services/FeedMe_EntryService.php +++ b/feedme/services/FeedMe_EntryService.php @@ -3,6 +3,9 @@ class FeedMe_EntryService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function getGroups() { // Get editable sections for user @@ -44,21 +47,14 @@ public function setCriteria($settings) return $criteria; } - /*public function delete($elements) - { - return craft()->entries->deleteEntry($elements); - }*/ - // Prepare reserved ElementModel values public function prepForElementModel(&$fields, EntryModel $element) { - // Set author $author = FeedMe_Element::Author; if (isset($fields[$author])) { $user = craft()->users->getUserByUsernameOrEmail($fields[$author]); $element->$author = (is_numeric($fields[$author]) ? $fields[$author] : ($user ? $user->id : 1)); - //unset($fields[$author]); } else { $user = craft()->userSession->getUser(); $element->$author = ($element->$author ? $element->$author : ($user ? $user->id : 1)); @@ -68,7 +64,6 @@ public function prepForElementModel(&$fields, EntryModel $element) $slug = FeedMe_Element::Slug; if (isset($fields[$slug])) { $element->$slug = ElementHelper::createSlug($fields[$slug]); - //unset($fields[$slug]); } // Set postdate @@ -78,7 +73,6 @@ public function prepForElementModel(&$fields, EntryModel $element) $date_string = date('Y-m-d H:i:s', mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year'])); $element->$postDate = DateTime::createFromString($date_string, craft()->timezone); - //unset($fields[$postDate]); } // Set expiry date @@ -88,21 +82,18 @@ public function prepForElementModel(&$fields, EntryModel $element) $date_string = date('Y-m-d H:i:s', mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year'])); $element->$expiryDate = DateTime::createFromString($date_string, craft()->timezone); - //unset($fields[$expiryDate]); } // Set enabled $enabled = FeedMe_Element::Enabled; if (isset($fields[$enabled])) { $element->$enabled = (bool) $fields[$enabled]; - //unset($fields[$enabled]); } // Set title $title = FeedMe_Element::Title; if (isset($fields[$title])) { $element->getContent()->$title = $fields[$title]; - //unset($fields[$title]); } // Set parent or ancestors @@ -125,8 +116,6 @@ public function prepForElementModel(&$fields, EntryModel $element) $element->$parent = $criteria->first()->id; } } - - //unset($fields[$parent]); } elseif (isset($fields[$ancestors])) { $data = $fields[$ancestors]; @@ -143,7 +132,7 @@ public function prepForElementModel(&$fields, EntryModel $element) // Find matching element by URI (dirty, not all structures have URI's) $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->sectionId = $element->sectionId; - $criteria->uri = $sectionUrl.craft()->feedMe->slugify($data); + //$criteria->uri = $sectionUrl.craft()->feedMe->slugify($data); $criteria->limit = 1; // Return the first found element for connecting @@ -151,256 +140,9 @@ public function prepForElementModel(&$fields, EntryModel $element) $element->$parent = $criteria->first()->id; } } - - //unset($fields[$ancestors]); } // Return element return $element; } - - /*public function save(EntryModel &$element, $settings) - { - if (craft()->entries->saveEntry($element)) { - return true; - } - - return false; - }*/ - - public function saveEntry(EntryModel $entry) - { - $isNewEntry = !$entry->id; - - $hasNewParent = $this->_checkForNewParent($entry); - - if ($hasNewParent) - { - if ($entry->parentId) - { - $parentEntry = craft()->entries->getEntryById($entry->parentId, $entry->locale); - - if (!$parentEntry) - { - throw new Exception(Craft::t('No entry exists with the ID “{id}”.', array('id' => $entry->parentId))); - } - } - else - { - $parentEntry = null; - } - - $entry->setParent($parentEntry); - } - - // Get the entry record - if (!$isNewEntry) - { - $entryRecord = EntryRecord::model()->findById($entry->id); - - if (!$entryRecord) - { - throw new Exception(Craft::t('No entry exists with the ID “{id}”.', array('id' => $entry->id))); - } - } - else - { - $entryRecord = new EntryRecord(); - } - - // Get the section - $section = craft()->sections->getSectionById($entry->sectionId); - - if (!$section) - { - throw new Exception(Craft::t('No section exists with the ID “{id}”.', array('id' => $entry->sectionId))); - } - - // Verify that the section is available in this locale - $sectionLocales = $section->getLocales(); - - if (!isset($sectionLocales[$entry->locale])) - { - throw new Exception(Craft::t('The section “{section}” is not enabled for the locale {locale}', array('section' => $section->name, 'locale' => $entry->locale))); - } - - // Set the entry data - $entryType = $entry->getType(); - - $entryRecord->sectionId = $entry->sectionId; - - if ($section->type == SectionType::Single) - { - $entryRecord->authorId = $entry->authorId = null; - $entryRecord->expiryDate = $entry->expiryDate = null; - } - else - { - $entryRecord->authorId = $entry->authorId; - $entryRecord->postDate = $entry->postDate; - $entryRecord->expiryDate = $entry->expiryDate; - $entryRecord->typeId = $entryType->id; - } - - if ($entry->enabled && !$entryRecord->postDate) - { - // Default the post date to the current date/time - $entryRecord->postDate = $entry->postDate = DateTimeHelper::currentUTCDateTime(); - } - - $entryRecord->validate(); - $entry->addErrors($entryRecord->getErrors()); - - if ($entry->hasErrors()) - { - return false; - } - - if (!$entryType->hasTitleField) - { - $entry->getContent()->title = craft()->templates->renderObjectTemplate($entryType->titleFormat, $entry); - } - - $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null; - - try - { - - // Save the element - $success = craft()->elements->saveElement($entry); - - // If it didn't work, rollback the transaction in case something changed in onBeforeSaveEntry - if (!$success) - { - if ($transaction !== null) - { - $transaction->rollback(); - } - - // If "title" has an error, check if they've defined a custom title label. - if ($entry->getError('title')) - { - // Grab all of the original errors. - $errors = $entry->getErrors(); - - // Grab just the title error message. - $originalTitleError = $errors['title']; - - // Clear the old. - $entry->clearErrors(); - - // Create the new "title" error message. - $errors['title'] = str_replace('Title', $entryType->titleLabel, $originalTitleError); - - // Add all of the errors back on the model. - $entry->addErrors($errors); - } - - return false; - } - - // Now that we have an element ID, save it on the other stuff - if ($isNewEntry) - { - $entryRecord->id = $entry->id; - } - - // Save the actual entry row - $entryRecord->save(false); - - if ($section->type == SectionType::Structure) - { - // Has the parent changed? - if ($hasNewParent) - { - if (!$entry->parentId) - { - craft()->structures->appendToRoot($section->structureId, $entry); - } - else - { - craft()->structures->append($section->structureId, $entry, $parentEntry); - } - } - - // Update the entry's descendants, who may be using this entry's URI in their own URIs - //craft()->elements->updateDescendantSlugsAndUris($entry); - } - - // Save a new version - if (craft()->getEdition() >= Craft::Client && $section->enableVersioning) - { - //craft()->entryRevisions->saveVersion($entry); - } - - // Commit the transaction regardless of whether we saved the entry, in case something changed - // in onBeforeSaveEntry - if ($transaction !== null) - { - $transaction->commit(); - } - } - catch (\Exception $e) - { - if ($transaction !== null) - { - $transaction->rollback(); - } - - throw $e; - } - - return $success; - } - - private function _checkForNewParent(EntryModel $entry) - { - // Make sure this is a Structure section - if ($entry->getSection()->type != SectionType::Structure) - { - return false; - } - - // Is it a brand new entry? - if (!$entry->id) - { - return true; - } - - // Was a parentId actually submitted? - if ($entry->parentId === null) - { - return false; - } - - // Is it set to the top level now, but it hadn't been before? - if ($entry->parentId === '' && $entry->level != 1) - { - return true; - } - - // Is it set to be under a parent now, but didn't have one before? - if ($entry->parentId !== '' && $entry->level == 1) - { - return true; - } - - // Is the parentId set to a different entry ID than its previous parent? - $criteria = craft()->elements->getCriteria(ElementType::Entry); - $criteria->ancestorOf = $entry; - $criteria->ancestorDist = 1; - $criteria->status = null; - $criteria->localeEnabled = null; - - $oldParent = $criteria->first(); - $oldParentId = ($oldParent ? $oldParent->id : ''); - - if ($entry->parentId != $oldParentId) - { - return true; - } - - // Must be set to the same one then - return false; - } } diff --git a/feedme/services/FeedMe_FeedJSONService.php b/feedme/services/FeedMe_FeedJSONService.php index 54bab9c7..c2b4ed21 100644 --- a/feedme/services/FeedMe_FeedJSONService.php +++ b/feedme/services/FeedMe_FeedJSONService.php @@ -3,6 +3,9 @@ class FeedMe_FeedJSONService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function getFeed($url, $primaryElement) { if (false === ($raw_content = craft()->feedMe_feed->getRawData($url))) { craft()->userSession->setError(Craft::t('Unable to parse Feed URL.')); diff --git a/feedme/services/FeedMe_FeedService.php b/feedme/services/FeedMe_FeedService.php index 9b299056..8678330b 100644 --- a/feedme/services/FeedMe_FeedService.php +++ b/feedme/services/FeedMe_FeedService.php @@ -3,7 +3,13 @@ class FeedMe_FeedService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function getFeed($type, $url, $element, $returnAttr = false) { + // Check for and environment variables in url + $url = craft()->config->parseEnvironmentString($url); + if ($type == FeedMe_FeedType::JSON) { return craft()->feedMe_feedJSON->getFeed($url, $element); } else { @@ -98,7 +104,7 @@ public function getValueForNode($element, $data) $indexes = explode('/', $element); - while(count($indexes) > 0) { + while (count($indexes) > 0) { $elementNode = array_shift($indexes); if ($elementNode === '...') { @@ -122,7 +128,7 @@ public function getValueForNode($element, $data) } } - $data = (empty($next_data)) ? false : $next_data; + return (empty($next_data)) ? false : $next_data; } else { return null; } diff --git a/feedme/services/FeedMe_FeedXMLService.php b/feedme/services/FeedMe_FeedXMLService.php index 98be212b..29e2404c 100644 --- a/feedme/services/FeedMe_FeedXMLService.php +++ b/feedme/services/FeedMe_FeedXMLService.php @@ -3,6 +3,9 @@ class FeedMe_FeedXMLService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function getFeed($url, $primaryElement, $returnAttr = false) { if (false === ($raw_content = craft()->feedMe_feed->getRawData($url))) { @@ -27,7 +30,7 @@ public function getFeed($url, $primaryElement, $returnAttr = false) return $xml_array; } - function elementArray($xml, $first = true, $returnAttr = false) + public function elementArray($xml, $first = true, $returnAttr = false) { if (!$xml) { return null; @@ -69,7 +72,7 @@ function elementArray($xml, $first = true, $returnAttr = false) return $return; } - function parseXML($xml) + public function parseXML($xml) { $xmlArray = null; diff --git a/feedme/services/FeedMe_FeedsService.php b/feedme/services/FeedMe_FeedsService.php index ab9bf025..b19a4b45 100644 --- a/feedme/services/FeedMe_FeedsService.php +++ b/feedme/services/FeedMe_FeedsService.php @@ -3,6 +3,9 @@ class FeedMe_FeedsService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= + public function getFeeds() { $feedRecords = FeedMe_FeedRecord::model()->findAll(); diff --git a/feedme/services/FeedMe_FieldsService.php b/feedme/services/FeedMe_FieldsService.php index 24ac1ad4..25b3c739 100644 --- a/feedme/services/FeedMe_FieldsService.php +++ b/feedme/services/FeedMe_FieldsService.php @@ -3,7 +3,15 @@ class FeedMe_FieldsService extends BaseApplicationComponent { - public function prepForFieldType(&$data, &$handle, $field = null) + // Properties + // ========================================================================= + + private $_entryFields = array(); + + // Public Methods + // ========================================================================= + + public function prepForFieldType(&$data, $handle, $field = null) { if (!is_array($data)) { $data = StringHelper::convertToUTF8($data); @@ -11,83 +19,62 @@ public function prepForFieldType(&$data, &$handle, $field = null) } if (!$field) { - $field = craft()->fields->getFieldByHandle($handle); - } - - // Special case for Matrix fields - if (substr($handle, 0, 10) == '__matrix__') { - $handle = str_replace('__matrix__', '', $handle); - - // [0]matrix - [1]blocktype - [2]field - $matrixInfo = explode('__', $handle); - - $field = craft()->fields->getFieldByHandle($matrixInfo[0]); - } + // Check for sub-fields, we only want to grab the top-level handle (for now) + preg_match('/(\w+)/', $handle, $matches); + $fieldHandle = $matches[0]; - // Special case for SuperTable fields - if (substr($handle, 0, 14) == '__supertable__') { - $handle = str_replace('__supertable__', '', $handle); + if (isset($this->_entryFields[$fieldHandle])) { + $field = $this->_entryFields[$fieldHandle]; + } else { + $field = craft()->fields->getFieldByHandle($fieldHandle); - // [0]matrix - [1]blocktype - [2]field - $matrixInfo = explode('__', $handle); - - $field = craft()->fields->getFieldByHandle($matrixInfo[0]); - } - - // Special case for Table fields - if (substr($handle, 0, 9) == '__table__') { - $handle = str_replace('__table__', '', $handle); - - // [0]table - [1]column - $tableInfo = explode('__', $handle); - - $field = craft()->fields->getFieldByHandle($tableInfo[0]); + $this->_entryFields[$fieldHandle] = $field; + } + } else { + $fieldHandle = $handle; } if (!is_null($field)) { switch ($field->type) { case FeedMe_FieldType::Assets: - $data = $this->prepAssets($data, $field); break; + $data = array( $fieldHandle => $this->prepAssets($data, $field) ); break; case FeedMe_FieldType::Categories: - $data = $this->prepCategories($data, $field); break; + $data = array( $fieldHandle => $this->prepCategories($data, $field) ); break; case FeedMe_FieldType::Checkboxes: - $data = $this->prepCheckboxes($data, $field); break; + $data = array( $fieldHandle => $this->prepCheckboxes($data, $field) ); break; case FeedMe_FieldType::Date: - $data = $this->prepDate($data, $field); break; + $data = array( $fieldHandle => $this->prepDate($data, $field) ); break; case FeedMe_FieldType::Dropdown: - $data = $this->prepDropdown($data, $field); break; + $data = array( $fieldHandle => $this->prepDropdown($data, $field) ); break; case FeedMe_FieldType::Entries: - $data = $this->prepEntries($data, $field); break; + $data = array( $fieldHandle => $this->prepEntries($data, $field) ); break; case FeedMe_FieldType::Matrix: - $data = $this->prepMatrix($data, $matrixInfo, $field, $handle); break; + $data = array( $fieldHandle => $this->prepMatrix($data, $handle, $field) ); break; case FeedMe_FieldType::MultiSelect: - $data = $this->prepMultiSelect($data, $field); break; + $data = array( $fieldHandle => $this->prepMultiSelect($data, $field) ); break; case FeedMe_FieldType::Number: - $data = $this->prepNumber($data, $field); break; + $data = array( $fieldHandle => $this->prepNumber($data, $field) ); break; case FeedMe_FieldType::RadioButtons: - $data = $this->prepRadioButtons($data, $field); break; + $data = array( $fieldHandle => $this->prepRadioButtons($data, $field) ); break; case FeedMe_FieldType::RichText: - $data = $this->prepRichText($data, $field); break; + $data = array( $fieldHandle => $this->prepRichText($data, $field) ); break; case FeedMe_FieldType::Table: - $data = $this->prepTable($data, $tableInfo, $field, $handle); break; + $data = array( $fieldHandle => $this->prepTable($data, $handle, $field) ); break; case FeedMe_FieldType::Tags: - $data = $this->prepTags($data, $field); break; + $data = array( $fieldHandle => $this->prepTags($data, $field) ); break; case FeedMe_FieldType::Users: - $data = $this->prepUsers($data, $field); break; + $data = array( $fieldHandle => $this->prepUsers($data, $field) ); break; // Color, Lightswitch, PlainText, PositionSelect all take care of themselves - - // Third-Party - case FeedMe_FieldType::SuperTable: - $data = $this->prepSuperTable($data, $matrixInfo, $field, $handle); break; + default: + $data = array( $fieldHandle => $data ); } // Third-party fieldtype support - $thirdPartyFields = craft()->plugins->call('registerFeedMeField'); - - if (in_array($field->type, $thirdPartyFields)) { - craft()->plugins->call('prepForFeedMeFieldType', array(&$data, $handle)); - } + craft()->plugins->call('prepForFeedMeFieldType', array($field, &$data, $handle)); + } else { + // For core entry fields - still need to return with handle + $data = array( $fieldHandle => $data ); } return $data; @@ -261,43 +248,51 @@ public function prepEntries($data, $field) { return $fieldData; } - public function prepMatrix($data, $matrixInfo, $field, &$handle) { + public function prepMatrix($data, $handle, $field) { $fieldData = array(); - $matrixHandle = $matrixInfo[0]; - $blocktypeHandle = $matrixInfo[1]; - $fieldHandle = $matrixInfo[2]; + preg_match_all('/\w+/', $handle, $matches); - // Set the original handle (index key) property to the matrix field handle - $handle = $matrixHandle; + if (isset($matches[0])) { + $fieldHandle = $matches[0][0]; + $blocktypeHandle = $matches[0][1]; + $subFieldHandle = $matches[0][2]; - if (!empty($data)) { - $blockFieldData = $this->prepForFieldType($data, $fieldHandle); + // Store the fields for this Matrix - can't use the fields service due to context + $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id, 'handle'); + $blockType = $blockTypes[$blocktypeHandle]; - if (!is_array($blockFieldData)) { - $blockFieldData = array($blockFieldData); + foreach ($blockType->getFields() as $f) { + if ($f->handle == $subFieldHandle) { + $subField = $f; + } } - foreach ($blockFieldData as $i => $singleFieldData) { + $rows = array(); + + if (!empty($data)) { + if (!is_array($data)) { + $data = array($data); + } - // For each field in each Matrix block, be sure to run these through the same - // process as we would for standalone fields. - $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id, 'handle'); - $blockType = $blockTypes[$blocktypeHandle]; + foreach ($data as $i => $singleFieldData) { - foreach ($blockType->getFields() as $f) { - if ($f->handle == $fieldHandle) { - $parsedFieldData = $this->prepForFieldType($singleFieldData, $fieldHandle, $f); + // Check to see if this is an array of items, or just a single item + if (count($singleFieldData) != count($singleFieldData, 1)) { + $elementFieldData = array_values($singleFieldData)[0]; + + $subFieldData = $this->prepForFieldType($elementFieldData, $subFieldHandle, $subField); + } else { + $subFieldData = $this->prepForFieldType($singleFieldData, $subFieldHandle, $subField); } - } - $fieldData['new'.$blocktypeHandle.($i+1)] = array( - 'type' => $blocktypeHandle, - 'enabled' => true, - 'fields' => array( - $fieldHandle => $parsedFieldData, - ) - ); + $fieldData['new'.$blocktypeHandle.($i+1)] = array( + 'type' => $blocktypeHandle, + 'order' => $i, + 'enabled' => true, + 'fields' => $subFieldData, + ); + } } } @@ -337,38 +332,26 @@ public function prepRadioButtons($data, $field) { return $fieldData; } - public function prepSuperTable($data, $matrixInfo, $field, &$handle) { + public function prepTable($data, $handle, $field) { $fieldData = array(); - $matrixHandle = $matrixInfo[0]; - $blocktypeId = $matrixInfo[1]; - $fieldHandle = $matrixInfo[2]; - - // Set the original handle (index key) property to the matrix field handle - $handle = $matrixHandle; + // Get the table columns - sent through as fieldname[col] + preg_match_all('/\w+/', $handle, $matches); - if (!empty($data)) { - $blockFieldData = $this->prepForFieldType($data, $fieldHandle); - - foreach ($blockFieldData as $i => $singleFieldData) { + if (isset($matches[0])) { + $fieldHandle = $matches[0][0]; + $columnHandle = $matches[0][1]; - // For each field in each Matrix block, be sure to run these through the same - // process as we would for standalone fields. - $blockTypes = craft()->superTable->getBlockTypesByFieldId($field->id, 'id'); - $blockType = $blockTypes[$blocktypeId]; + $rows = ArrayHelper::stringToArray($data); - foreach ($blockType->getFields() as $f) { - if ($f->handle == $fieldHandle) { - $parsedFieldData = $this->prepForFieldType($singleFieldData, $fieldHandle, $f); - } + foreach ($rows as $i => $row) { + // Check for false for checkbox + if ($row === 'false') { + $row = null; } - $fieldData['new'.$blocktypeId.($i+1)] = array( - 'type' => $blocktypeId, - 'enabled' => true, - 'fields' => array( - $fieldHandle => $parsedFieldData, - ) + $fieldData[$i+1] = array( + 'col'.$columnHandle => $row, ); } } @@ -376,28 +359,6 @@ public function prepSuperTable($data, $matrixInfo, $field, &$handle) { return $fieldData; } - public function prepTable($data, $tableInfo, $field, &$handle) { - $fieldData = array(); - - // Set the original handle (index key) property to the table field handle - $handle = $tableInfo[0]; - - $rows = ArrayHelper::stringToArray($data); - - foreach ($rows as $i => $row) { - // Check for false for checkbox - if ($row === 'false') { - $row = null; - } - - $fieldData[$i+1] = array( - $tableInfo[1] => $row, - ); - } - - return $fieldData; - } - public function prepTags($data, $field) { $fieldData = array(); @@ -466,7 +427,7 @@ public function prepUsers($data, $field) { $criteria = craft()->elements->getCriteria(ElementType::User); $criteria->groupId = $groupIds; $criteria->limit = $settings->limit; - $criteria->search = 'username:'.$user.' OR email:'.$user; + $criteria->search = $user; $fieldData = array_merge($fieldData, $criteria->ids()); } @@ -484,90 +445,50 @@ public function prepUsers($data, $field) { } - - - // Function that (almost) mimics Craft's inner slugify process. - // But... we allow forward slashes to stay, so we can create full uri's. - public function slugify($slug) + // Function for third-party plugins to provide custom mapping options for fieldtypes + public function getCustomOption($fieldHandle) { + $options = craft()->plugins->call('registerFeedMeMappingOptions'); - // Remove HTML tags - $slug = preg_replace('/<(.*?)>/u', '', $slug); - - // Remove inner-word punctuation. - $slug = preg_replace('/[\'"‘’“”\[\]\(\)\{\}:]/u', '', $slug); - - if (craft()->config->get('allowUppercaseInSlug') === false) { - // Make it lowercase - $slug = StringHelper::toLowerCase($slug, 'UTF-8'); + foreach ($options as $pluginHandle => $option) { + if (isset($option[$fieldHandle])) { + return $option[$fieldHandle]; + } } - // Get the "words". Split on anything that is not a unicode letter or number. Periods, underscores, hyphens and forward slashes get a pass. - preg_match_all('/[\p{L}\p{N}\.\/_-]+/u', $slug, $words); - $words = ArrayHelper::filterEmptyStringsFromArray($words[0]); - $slug = implode(craft()->config->get('slugWordSeparator'), $words); - - return $slug; + return false; } - - // Extra functions when dealing with certain field types - mostly revolves around combining fields for Table and Matrix - public function handleMatrixData($newFields, $handle, $content) - { - $return = $content; - - if (isset($newFields[$handle])) { - foreach ($newFields[$handle] as $matrixBlockKey => $matrixBlock) { - if (isset($content[$matrixBlockKey])) { - // Merge just the fields property - $merged = array_merge($content[$matrixBlockKey]['fields'], $matrixBlock['fields']); - $return[$matrixBlockKey]['fields'] = $merged; - } else { - $return = array_merge($newFields[$handle], $content); - } - } - } - - return $return; - } - - public function handleTableData($newFields, $handle, $content) + // Some post-processing needs to be done, specifically for a Matrix field. Unfortuntely, multiple + // blocks are added out of order, which is messy - fix this here. Fortuntely, we have a 'order' attribute + // on each block. Also call any third-party post processing (looking at you Super Table). + public function postForFieldType(&$fieldData) { - $return = $content; - - if (isset($newFields[$handle])) { - foreach ($newFields[$handle] as $rowId => $row) { - if (isset($content[$rowId])) { - // Merge just the fields property - $merged = array_merge($content[$rowId], $row); - $return[$rowId] = array_merge($content[$rowId], $row); - } else { - $return = array_merge($newFields[$handle], $content); - } - } - } + // This is less intensive than craft()->fields->getFieldByHandle($fieldHandle); + foreach ($fieldData as $fieldHandle => $data) { + if (is_array($data)) { + + // Check for the order attr, otherwise not what we're after + if (isset(array_values($data)[0]['order'])) { + $orderedMatrixData = array(); + $tempMatrixData = array(); + + foreach ($data as $key => $subField) { + $tempMatrixData[$subField['order']][$key] = $subField; + } - return $return; - } + $fieldData[$fieldHandle] = array(); - public function handleSuperTableData($newFields, $handle, $content) - { - $return = $content; - - if (isset($newFields[$handle])) { - foreach ($newFields[$handle] as $matrixBlockKey => $matrixBlock) { - if (isset($content[$matrixBlockKey])) { - // Merge just the fields property - $merged = array_merge($content[$matrixBlockKey]['fields'], $matrixBlock['fields']); - $return[$matrixBlockKey]['fields'] = $merged; - } else { - $return = array_merge($newFields[$handle], $content); + foreach ($tempMatrixData as $key => $subField) { + $fieldData[$fieldHandle] = array_merge($fieldData[$fieldHandle], $subField); + } } } } - - return $return; + + // Third-party fieldtype support + craft()->plugins->call('postForFeedMeFieldType', array(&$fieldData)); } } diff --git a/feedme/services/FeedMe_LogsService.php b/feedme/services/FeedMe_LogsService.php index ed0c18aa..045dfab2 100644 --- a/feedme/services/FeedMe_LogsService.php +++ b/feedme/services/FeedMe_LogsService.php @@ -3,6 +3,8 @@ class FeedMe_LogsService extends BaseApplicationComponent { + // Public Methods + // ========================================================================= public function show() { diff --git a/feedme/tasks/FeedMeTask.php b/feedme/tasks/FeedMeTask.php index 305af921..53c36473 100644 --- a/feedme/tasks/FeedMeTask.php +++ b/feedme/tasks/FeedMeTask.php @@ -3,6 +3,9 @@ class FeedMeTask extends BaseTask { + // Properties + // ========================================================================= + private $_feed; private $_logsId; private $_feedData; @@ -10,12 +13,8 @@ class FeedMeTask extends BaseTask private $_backup; private $_chunkedFeedData; - protected function defineSettings() - { - return array( - 'feed' => AttributeType::Mixed, - ); - } + // Public Methods + // ========================================================================= public function getDescription() { @@ -53,8 +52,22 @@ public function getTotalSteps() public function runStep($step) { - craft()->feedMe->importNode($this->_chunkedFeedData[$step], $this->_feed, $this->_feedSettings); + $result = craft()->feedMe->importNode($this->_chunkedFeedData[$step], $this->_feed, $this->_feedSettings); + + if (!$result) { + return 'Feed Me Failure: Check Feed Me logs.'; + } else { + return true; + } + } - return true; + // Protected Methods + // ========================================================================= + + protected function defineSettings() + { + return array( + 'feed' => AttributeType::Mixed, + ); } } \ No newline at end of file diff --git a/feedme/templates/feeds/_edit.html b/feedme/templates/feeds/_edit.html index 49b5093f..a57b2138 100644 --- a/feedme/templates/feeds/_edit.html +++ b/feedme/templates/feeds/_edit.html @@ -1,7 +1,7 @@ {% extends "_layouts/cp" %} -{% includeCssResource 'feedme/css/feedme.css' %} -{% includeJsResource 'feedme/js/feedme.js' %} +{% includeCssResource 'feedme/css/FeedMe.css' %} +{% includeJsResource 'feedme/js/FeedMe.js' %} {% set crumbs = [ { label: craft.feedme.getPluginName | t, url: url('feedme') }, diff --git a/feedme/templates/feeds/_map.html b/feedme/templates/feeds/_map.html index 0bf7767a..4eea5075 100644 --- a/feedme/templates/feeds/_map.html +++ b/feedme/templates/feeds/_map.html @@ -1,7 +1,7 @@ {% extends "_layouts/cp" %} -{% includeCssResource 'feedme/css/feedme.css' %} -{% includeJsResource 'feedme/js/feedme.js' %} +{% includeCssResource 'feedme/css/FeedMe.css' %} +{% includeJsResource 'feedme/js/FeedMe.js' %} {% set crumbs = [ { label: craft.feedme.getPluginName | t, url: url('feedme') }, @@ -86,13 +86,15 @@ {% set f = field.getField() %} {% set label = (f.required) ? f.name ~ '*' : f.name %} + {% set customOption = craft.feedMe.customOption(f.type) %} + {# Special case for Matrix and Table fields #} {% if f.type == 'Matrix' %} {{ _self.generateMatrixOption(f, label, f.handle, key, feed) }} {% elseif f.type == 'Table' %} {{ _self.generateTableOption(f, label, f.handle, key, feed) }} - {% elseif f.type == 'SuperTable' %} - {{ _self.generateSuperTableOption(f, label, f.handle, key, feed) }} + {% elseif customOption %} + {% include customOption with { field: f, label: label, value: f.handle, key: key, feed: feed } %} {% else %} {{ _self.generateOption(label, f.handle, key, feed) }} {% endif %} @@ -181,10 +183,9 @@ {% endfor %} {% endmacro %} - -{% macro generateSuperTableOption(field, label, value, key, feed) %} - {% for blocktype in craft.feedme.getSuperTableBlocks(field.id) %} - - {% endfor %} - {% endfor %} -{% endmacro %} diff --git a/feedme/templates/feeds/index.html b/feedme/templates/feeds/index.html index 312c2f0c..b2aa175d 100644 --- a/feedme/templates/feeds/index.html +++ b/feedme/templates/feeds/index.html @@ -1,7 +1,7 @@ {% extends "_layouts/cp" %} {% includeCssResource 'feedme/css/font-awesome.min.css' %} -{% includeCssResource 'feedme/css/feedme.css' %} +{% includeCssResource 'feedme/css/FeedMe.css' %} {% set crumbs = [ { label: craft.feedme.getPluginName | t, url: url('feedme') }, diff --git a/feedme/templates/help/index.html b/feedme/templates/help/index.html index 8ec0cf9b..89a13a4d 100644 --- a/feedme/templates/help/index.html +++ b/feedme/templates/help/index.html @@ -1,7 +1,7 @@ {% extends "_layouts/cp" %} {% includeCssResource 'feedme/css/font-awesome.min.css' %} -{% includeCssResource 'feedme/css/feedme.css' %} +{% includeCssResource 'feedme/css/FeedMe.css' %} {% includeJsResource 'feedme/js/FeedMeHelp.js' %} diff --git a/feedme/templates/logs/index.html b/feedme/templates/logs/index.html index 59318c5f..8cd34592 100644 --- a/feedme/templates/logs/index.html +++ b/feedme/templates/logs/index.html @@ -1,7 +1,7 @@ {% extends "_layouts/cp" %} {% includeCssResource 'feedme/css/font-awesome.min.css' %} -{% includeCssResource 'feedme/css/feedme.css' %} +{% includeCssResource 'feedme/css/FeedMe.css' %} {% set crumbs = [ { label: craft.feedme.getPluginName | t, url: url('feedme') }, diff --git a/feedme/variables/FeedMeVariable.php b/feedme/variables/FeedMeVariable.php index 570aad9d..354d95e8 100644 --- a/feedme/variables/FeedMeVariable.php +++ b/feedme/variables/FeedMeVariable.php @@ -103,6 +103,11 @@ public function getFeeds() return $result; } + public function customOption($fieldHandle) + { + return craft()->feedMe_fields->getCustomOption($fieldHandle); + } + // Helper function for handling Matrix fields public function getMatrixBlocks($fieldId) @@ -110,11 +115,6 @@ public function getMatrixBlocks($fieldId) return craft()->matrix->getBlockTypesByFieldId($fieldId); } - public function getSuperTableBlocks($fieldId) - { - return craft()->superTable->getBlockTypesByFieldId($fieldId); - } - }