From bbb8881d03746f07996acf05c6cdac7b87230c79 Mon Sep 17 00:00:00 2001 From: Ruben Reyes Date: Sun, 22 May 2016 12:42:02 -0400 Subject: [PATCH] Initial commit --- README.md | 7 +- flexicontent.php | 154 ++++++++++++++++++++++++++ flexicontent.xml | 15 +++ index.html | 1 + language/en-GB/en-GB.flexicontent.ini | 13 +++ 5 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 flexicontent.php create mode 100644 flexicontent.xml create mode 100644 index.html create mode 100644 language/en-GB/en-GB.flexicontent.ini diff --git a/README.md b/README.md index 57293e6..1692117 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ -# plg_jmap_flexicontent \ No newline at end of file +# plg_jmap_flexicontent + +Very basic JSitemap plugin for FLEXIcontent. + +Allows to include/excludes items by category. + diff --git a/flexicontent.php b/flexicontent.php new file mode 100644 index 0000000..3b112e1 --- /dev/null +++ b/flexicontent.php @@ -0,0 +1,154 @@ + It's the mandatory objects array of elements, it must contain at least title and routed link fields + * $returndata['items_tree'] -> Needed to render elements grouped by cats with a nested tree, not mandatory + * $returndata['categories_tree'] -> Needed to render elements grouped by cats with a nested tree, not mandatory + * + * $returndata['items'] must contain records objects with following properties (* = required) + * ->title * A string for the title + * ->link * A string for the link + * ->lastmod (used for XML sitemap) A date string in MySql format yyyy-mm-dd hh:ii:ss + * ->metakey (used for Google news sitemap) A string for metakeys of each record + * ->publish_up (used for Google news sitemap) A date string in MySql format yyyy-mm-dd hh:ii:ss + * ->access (used for Google news sitemap, >1 = registration access) An integer for Joomla! access level of each record + * + * $returndata['items_tree'] must be a numerical array that groups items by the containing category id, the index of the array is the category id + * + * $returndata['categories_tree'] must be a numerical array that groups categories by parent category, the index of the array is the category parent id, + * the elements of the array must be records objects representing categories with following properties (* = required) + * ->category_id * An integer for the category ID + * ->category_title * A string for the category title + * ->category_link * A string for the category link + * ->lastmod (used for XML sitemap) A date string in MySql format yyyy-mm-dd hh:ii:ss + */ + public function getSourceData(JRegistry $pluginParams, JDatabase $db, JMapModel $sitemapModel) { + + // Check if the extension is installed + if(!file_exists(JPATH_SITE . '/components/com_flexicontent')) { + throw new JMapException(JText::sprintf('COM_JMAP_ERROR_EXTENSION_NOTINSTALLED', 'FLEXIcontent'), 'warning'); + } + + // The associative array holding the returned data + $returndata = array(); + + // Get user + $user = JFactory::getUser(); + if(!is_object($user)) { + throw new JMapException(JText::_('COM_JMAP_PLGFLEXICONTENT_NOUSER_OBJECT'), 'warning'); + } + + // Get access level and language + $accessLevel = $user->getAuthorisedViewLevels(); + $langTag = JFactory::getLanguage()->getTag(); + $hashClassName = version_compare(JVERSION, '3.0', 'ge') ? 'JApplication' : 'JUtility'; + + // Category scope + $catScope = $pluginParams->get('cats_scope', 1); + $catScopeQuery = null; + if($catScope) { + // Exclude categories + $cats = $pluginParams->get('cats'); + if(is_array($cats)) $catScopeQuery = "\n AND #__categories.id NOT IN ( " . implode(',', $cats) . " )"; + } + else { + // Include categories + $cats = $pluginParams->get('cats'); + if(is_array($cats)) $catScopeQuery = "\n AND #__categories.id IN ( " . implode(',', $cats) . " )"; + } + + // ACL + $aclQueryItems = "\n AND #__content.access IN ( " . implode(',', $accessLevel) . " )"; + $aclQueryCategories = "\n AND #__categories.access IN ( " . implode(',', $accessLevel) . " )"; + + // Retrieve records + $itemsQuery = "SELECT" . + "\n #__content.id," . + "\n #__content.alias," . + "\n #__content.title," . + "\n #__content.catid," . + "\n #__content.modified AS " . $db->quoteName('lastmod') . "," . + "\n #__content.publish_up," . + "\n #__content.metakey" . + "\n FROM " . $db->quoteName('#__content') . + "\n JOIN " . $db->quoteName('#__categories') . " ON #__content.catid = #__categories.id" . + "\n WHERE" . + "\n #__categories.published = 1" . + "\n AND #__content.state = 1" . + $aclQueryItems . + $aclQueryCategories . + $catScopeQuery . + "\n AND (#__content.language = '*' OR #__content.language = '' OR #__content.language = " . $db->quote($langTag) . ")" . + //"\n AND #__content.trash = 0" . + "\n AND (#__content.publish_down > NOW() OR #__content.publish_down = '0000-00-00 00:00:00')" . + "\n ORDER BY" . + "\n #__categories.title ASC," . + "\n #__content.title ASC"; + + // Check if a limit for query rows has been set, this means we are in precaching process by JS App client + if(!$sitemapModel->limitRows) { + $items = $db->setQuery($itemsQuery)->loadObjectList(); + } else { + $items = $db->setQuery($itemsQuery, $sitemapModel->limitStart, $sitemapModel->limitRows)->loadObjectList(); + } + + if ($db->getErrorNum ()) { + throw new JMapException(JText::sprintf('COM_JMAP_ERROR_RETRIEVING_DATA_FROM_PLUGIN_DATASOURCE', $db->getErrorMsg()), 'warning'); + } + + // Detected a precaching call, we have to store in the model state the number of affected rows for the JS application + if($sitemapModel->limitRows) { + $sitemapModel->setState('affected_rows', $db->getAffectedRows()); + } + + // Include the extension route helper + if(file_exists(JPATH_SITE . '/components/com_flexicontent/helpers/route.php')) { + include_once (JPATH_SITE . '/components/com_flexicontent/helpers/route.php'); + } + + + // Route links for each record + if(count($items)) { + $itemsByCats = array(); + foreach ($items as $item) { + $item->link = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid)); + } + // Sort by URL + usort($items, function($a, $b) { + return strcmp($a->link, $b->link); + }); + $returndata['items'] = $items; // Assign items + } + + return $returndata; + } +} \ No newline at end of file diff --git a/flexicontent.xml b/flexicontent.xml new file mode 100644 index 0000000..9ef815c --- /dev/null +++ b/flexicontent.xml @@ -0,0 +1,15 @@ + + + FLEXIcontent + FLEXIcontent plugin for JSitemap + + +
+ + + + + +
+
+
diff --git a/index.html b/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/language/en-GB/en-GB.flexicontent.ini b/language/en-GB/en-GB.flexicontent.ini new file mode 100644 index 0000000..4e1d4c6 --- /dev/null +++ b/language/en-GB/en-GB.flexicontent.ini @@ -0,0 +1,13 @@ +;Language translations file +;Save always UTF-8 No Bom + +;Plugin translations backend +COM_JMAP_PLGFLEXICONTENT_INCLUDE="Include" +COM_JMAP_PLGFLEXICONTENT_EXCLUDE="Exclude" +COM_JMAP_PLGFLEXICONTENT_CAT_SCOPE="Category Scope" +COM_JMAP_PLGFLEXICONTENT_CAT_SCOPE_DESC="Select method for handling categories. Use include to pick the categories you want to include. Use exclude to pick the categories you want to exclude." +COM_JMAP_PLGFLEXICONTENT_CATEGORIES="Categories" +COM_JMAP_PLGFLEXICONTENT_CATEGORIES_DESC="Select categories to include or exclude" + +;Plugin translations frontend +COM_JMAP_PLGFLEXICONTENT_NOUSER_OBJECT="User object not valid"