From 27c3b95f1efb9a5f726e9f06991c4db7bd63265e Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 25 Jun 2012 17:22:15 +0200 Subject: [PATCH] Improved sitemap implementation --- com.woltlab.wcf/template/headInclude.tpl | 1 + com.woltlab.wcf/template/header.tpl | 1 + com.woltlab.wcf/template/sitemap.tpl | 31 +++++ wcfsetup/install/files/js/WCF.js | 120 ++++++++++++++++++ .../files/lib/data/DatabaseObject.class.php | 14 ++ .../lib/data/DatabaseObjectList.class.php | 2 +- .../lib/data/sitemap/SitemapAction.class.php | 9 +- .../builder/SitemapCacheBuilder.class.php | 2 +- .../system/sitemap/SitemapHandler.class.php | 33 +++-- 9 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 com.woltlab.wcf/template/sitemap.tpl diff --git a/com.woltlab.wcf/template/headInclude.tpl b/com.woltlab.wcf/template/headInclude.tpl index aceab103b3..cdc52025a1 100644 --- a/com.woltlab.wcf/template/headInclude.tpl +++ b/com.woltlab.wcf/template/headInclude.tpl @@ -84,6 +84,7 @@ new WCF.Date.Time(); new WCF.Effect.SmoothScroll(); new WCF.Effect.BalloonTooltip(); + new WCF.Sitemap(); WCF.Dropdown.init(); {event name='javascriptInit'} diff --git a/com.woltlab.wcf/template/header.tpl b/com.woltlab.wcf/template/header.tpl index 34743942a1..4aec40b794 100644 --- a/com.woltlab.wcf/template/header.tpl +++ b/com.woltlab.wcf/template/header.tpl @@ -40,6 +40,7 @@ diff --git a/com.woltlab.wcf/template/sitemap.tpl b/com.woltlab.wcf/template/sitemap.tpl new file mode 100644 index 0000000000..44e20e60cd --- /dev/null +++ b/com.woltlab.wcf/template/sitemap.tpl @@ -0,0 +1,31 @@ +
+ {hascontent} +
+ + + {foreach from=$tree item=sitemapName} + + {/foreach} +
+ + + {hascontentelse} + {@$sitemap} + {/hascontent} +
\ No newline at end of file diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 4704270b0f..2eb8f75ae5 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -5836,6 +5836,126 @@ $.widget('ui.wcfSidebar', { } }); +/** + * Provides a generic sitemap. + */ +WCF.Sitemap = Class.extend({ + /** + * sitemap name cache + */ + _cache: [ ], + + /** + * dialog overlay + * @var jQuery + */ + _dialog: null, + + /** + * initialization state + * @var boolean + */ + _didInit: false, + + /** + * action proxy + * @var WCF.Action.Proxy + */ + _proxy: null, + + /** + * Initializes the generic sitemap. + */ + init: function() { + $('#sitemap').click($.proxy(this._click, this)); + + this._cache = [ ]; + this._dialog = null; + this._didInit = false; + this._proxy = new WCF.Action.Proxy({ + success: $.proxy(this._success, this) + }); + }, + + /** + * Handles clicks on the sitemap icon. + */ + _click: function() { + if (this._dialog === null) { + this._dialog = $('
').appendTo(document.body); + + this._proxy.setOption('data', { + actionName: 'getSitemap', + className: 'wcf\\data\\sitemap\\SitemapAction' + }); + this._proxy.sendRequest(); + } + else { + this._dialog.wcfDialog('open'); + } + }, + + /** + * Handles successful AJAX responses. + * + * @param object data + * @param string textStatus + * @param jQuery jqXHR + */ + _success: function(data, textStatus, jqXHR) { + if (this._didInit) { + this._cache.push(data.returnValues.sitemapName); + + this._dialog.find('#sitemap-' + data.returnValues.sitemapName).html(data.returnValues.template); + + // redraw dialog + this._dialog.wcfDialog('render'); + } + else { + // mark sitemap name as loaded + this._cache.push(data.returnValues.sitemapName); + + // insert sitemap template + this._dialog.html(data.returnValues.template); + + // bind event listener + this._dialog.find('.sitemapNavigation').click($.proxy(this._navigate, this)); + + // show dialog + this._dialog.wcfDialog({ + title: WCF.Language.get('wcf.sitemap.title') + }); + + this._didInit = true; + } + }, + + /** + * Navigates between different sitemaps. + * + * @param object event + */ + _navigate: function(event) { + var $sitemapName = $(event.currentTarget).data('sitemapName'); + if (WCF.inArray($sitemapName, this._cache)) { + this._dialog.find('.tabMenuContainer').wcfTabs('select', 'sitemap-' + $sitemapName); + + // redraw dialog + this._dialog.wcfDialog('render'); + } + else { + this._proxy.setOption('data', { + actionName: 'getSitemap', + className: 'wcf\\data\\sitemap\\SitemapAction', + parameters: { + sitemapName: $sitemapName + } + }); + this._proxy.sendRequest(); + } + } +}); + /** * Provides a toggleable sidebar with persistent visibility. */ diff --git a/wcfsetup/install/files/lib/data/DatabaseObject.class.php b/wcfsetup/install/files/lib/data/DatabaseObject.class.php index 16ade9df48..1adc322b26 100644 --- a/wcfsetup/install/files/lib/data/DatabaseObject.class.php +++ b/wcfsetup/install/files/lib/data/DatabaseObject.class.php @@ -133,6 +133,20 @@ abstract class DatabaseObject implements IStorableObject { * @see wcf\data\IStorableObject::getDatabaseTableAlias() */ public static function getDatabaseTableAlias() { + if (empty(static::$databaseTableName)) { + $className = get_called_class(); + $className = substr($className, (strrpos($className, '\\') + 1)); + + preg_match_all('~((?:^|[A-Z])[a-z]+)~', $className, $matches); + foreach ($matches[1] as $part) { + if (!empty(static::$databaseTableName)) { + static::$databaseTableName .= '_'; + } + + static::$databaseTableName .= strtolower($part); + } + } + return static::$databaseTableName; } diff --git a/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php b/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php index ca0e83a021..ea22f1a863 100644 --- a/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php +++ b/wcfsetup/install/files/lib/data/DatabaseObjectList.class.php @@ -157,7 +157,6 @@ abstract class DatabaseObjectList implements \Countable, ITraversableObject { if (!count($this->objectIDs)) { return; } - $sql = "SELECT ".(!empty($this->sqlSelects) ? $this->sqlSelects.($this->useQualifiedShorthand ? ',' : '') : '')." ".($this->useQualifiedShorthand ? $this->getDatabaseTableAlias().'.*' : '')." FROM ".$this->getDatabaseTableName()." ".$this->getDatabaseTableAlias()." @@ -169,6 +168,7 @@ abstract class DatabaseObjectList implements \Countable, ITraversableObject { $this->objects = $statement->fetchObjects(($this->objectClassName ?: $this->className)); } else { + //if (!empty($this->sqlSelects)) die("x".$this->sqlSelects); $sql = "SELECT ".(!empty($this->sqlSelects) ? $this->sqlSelects.($this->useQualifiedShorthand ? ',' : '') : '')." ".($this->useQualifiedShorthand ? $this->getDatabaseTableAlias().'.*' : '')." FROM ".$this->getDatabaseTableName()." ".$this->getDatabaseTableAlias()." diff --git a/wcfsetup/install/files/lib/data/sitemap/SitemapAction.class.php b/wcfsetup/install/files/lib/data/sitemap/SitemapAction.class.php index aceebf6461..929675faea 100644 --- a/wcfsetup/install/files/lib/data/sitemap/SitemapAction.class.php +++ b/wcfsetup/install/files/lib/data/sitemap/SitemapAction.class.php @@ -38,16 +38,21 @@ class SitemapAction extends AbstractDatabaseObjectAction { public function getSitemap() { if (isset($this->parameters['sitemapName'])) { return array( + 'sitemapName' => $this->parameters['sitemapName'], 'template' => SitemapHandler::getInstance()->getSitemap($this->parameters['sitemapName']) ); } else { + $sitemapName = SitemapHandler::getInstance()->getDefaultSitemapName(); + WCF::getTPL()->assign(array( - 'tree' => SitemapHandler::getInstance()->getTree(), - 'sitemap' => SitemapHandler::getInstance()->getSitemap() + 'defaultSitemapName' => $sitemapName, + 'sitemap' => SitemapHandler::getInstance()->getSitemap($sitemapName), + 'tree' => SitemapHandler::getInstance()->getTree() )); return array( + 'sitemapName' => $sitemapName, 'template' => WCF::getTPL()->fetch('sitemap') ); } diff --git a/wcfsetup/install/files/lib/system/cache/builder/SitemapCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/SitemapCacheBuilder.class.php index 1c04f3df59..8350344b6d 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/SitemapCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/SitemapCacheBuilder.class.php @@ -19,7 +19,7 @@ class SitemapCacheBuilder implements ICacheBuilder { */ public function getData(array $cacheResource) { $sitemapList = new SitemapList(); - $sitemapList->getConditionBuilder()->add("sitemap.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getPackageIDs())); + $sitemapList->getConditionBuilder()->add("sitemap.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $sitemapList->sqlLimit = 0; $sitemapList->readObjects(); diff --git a/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php b/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php index 5802fe4c03..4b4f9bca66 100644 --- a/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php +++ b/wcfsetup/install/files/lib/system/sitemap/SitemapHandler.class.php @@ -55,25 +55,32 @@ class SitemapHandler extends SingletonFactory { } /** - * Returns sitemap for given sitemap name or falls back to active package id. + * Returns default sitemap name. * - * @param string $sitemapName - * @return wcf\data\sitemap\Sitemap + * @return string */ - public function getSitemap($sitemapName = '') { - if (empty($sitemapName)) { - foreach ($this->cache as $sitemap) { - if ($sitemap->packageID == PACKAGE_ID) { - $sitemapName = $sitemap->sitemapName; - } - } - - if (empty($sitemapName)) { - $sitemap = reset($this->cache); + public function getDefaultSitemapName() { + foreach ($this->cache as $sitemap) { + if ($sitemap->packageID == PACKAGE_ID) { $sitemapName = $sitemap->sitemapName; } } + if (empty($sitemapName)) { + $sitemap = reset($this->cache); + $sitemapName = $sitemap->sitemapName; + } + + return $sitemapName; + } + + /** + * Returns sitemap for given sitemap name. + * + * @param string $sitemapName + * @return wcf\data\sitemap\Sitemap + */ + public function getSitemap($sitemapName) { foreach ($this->cache as $sitemap) { if ($sitemap->sitemapName == $sitemapName) { return $sitemap->getTemplate(); -- 2.20.1