* Loads user profile previews.
*
* @see WCF.Popover
+ * @deprecated since 5.3, taken care of by `WoltLabSuite/Core/BootstrapFrontend` via `WoltLabSuite/Core/Controller/Popover`
*/
WCF.User.ProfilePreview = WCF.Popover.extend({
/**
* Initializes user profile popover.
*/
_initUserPopover: function() {
+ ControllerPopover.init({
+ className: 'userLink',
+ dboAction: 'wcf\\data\\user\\UserProfileAction',
+ identifier: 'com.woltlab.wcf.user'
+ });
+
+ // @deprecated since 5.3
ControllerPopover.init({
attributeName: 'data-user-id',
className: 'userLink',
- identifier: 'com.woltlab.wcf.user',
- loadCallback: function(objectId, popover) {
- var callback = function(data) {
- popover.setContent('com.woltlab.wcf.user', objectId, data.returnValues.template);
- };
-
- popover.ajaxApi({
- actionName: 'getUserProfile',
- className: 'wcf\\data\\user\\UserProfileAction',
- objectIDs: [ objectId ]
- }, callback, callback);
- }
+ dboAction: 'wcf\\data\\user\\UserProfileAction',
+ identifier: 'com.woltlab.wcf.user.deprecated'
});
}
};
_handlers.set(options.identifier, {
attributeName: options.attributeName,
+ dboAction: options.dboAction,
elements: options.legacy ? options.className : elByClass(options.className),
legacy: options.legacy,
loadCallback: options.loadCallback
else if (data.state === STATE_NONE) {
data.state = STATE_LOADING;
- _handlers.get(elementData.identifier).loadCallback(elementData.objectId, this);
+ var handler = _handlers.get(elementData.identifier);
+ if (handler.loadCallback) {
+ handler.loadCallback(elementData.objectId, this);
+ }
+ else if (handler.dboAction) {
+ var callback = function(data) {
+ this.setContent(
+ elementData.identifier,
+ elementData.objectId,
+ data.returnValues.template
+ );
+ }.bind(this);
+
+ this.ajaxApi({
+ actionName: 'getPopover',
+ className: handler.dboAction,
+ interfaceName: 'wcf\\data\\IPopoverAction',
+ objectIDs: [ elementData.objectId ]
+ }, callback, callback);
+ }
}
},
--- /dev/null
+<?php
+namespace wcf\data;
+
+/**
+ * Every object action that provides popover previews for database objects has to implement this interface.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data
+ * @since 5.3
+ */
+interface IPopoverAction {
+ /**
+ * Validates the `getPopover` action.
+ */
+ public function validateGetPopover();
+
+ /**
+ * Returns the requested popover for a specific object.
+ *
+ * Return value:
+ * [
+ * 'template' => '...'
+ * ]
+ *
+ * @return string[]
+ */
+ public function getPopover();
+}
--- /dev/null
+<?php
+namespace wcf\data;
+
+/**
+ * Database objects that support links with preview popovers via `WoltLabSuite/Core/Controller/Popover`
+ * can implement this interface so that when the `anchor` template plugin is used and the CSS class name
+ * returned by `getPopoverLinkClass()` is given, the `data-object-id` attribute is automatically added
+ * to support the preview popover.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data
+ * @since 5.3
+ */
+interface IPopoverObject extends IIDObject, ITitledLinkObject {
+ /**
+ * Returns the CSS class that objects of this type use for popover links.
+ *
+ * @return string
+ */
+ public function getPopoverLinkClass();
+}
<?php
namespace wcf\data\user;
+use wcf\data\IPopoverObject;
use wcf\data\language\Language;
use wcf\data\user\group\UserGroup;
use wcf\data\DatabaseObject;
* @property-read integer $articles number of articles written by the user
* @property-read string $blacklistMatches JSON string of an array with all matches in the blacklist, otherwise an empty string
*/
-final class User extends DatabaseObject implements IRouteController, IUserContent {
+final class User extends DatabaseObject implements IPopoverObject, IRouteController, IUserContent {
/**
* list of group ids
* @var integer[]
return WCF::getLanguage()->get('wcf.user.' . $field);
}, $this->getBlacklistMatches());
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getPopoverLinkClass() {
+ return 'userLink';
+ }
}
<?php
namespace wcf\data\user;
+use wcf\data\IPopoverAction;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\group\UserGroup;
use wcf\system\bbcode\BBCodeHandler;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\Data\User
*/
-class UserProfileAction extends UserAction {
+class UserProfileAction extends UserAction implements IPopoverAction {
/**
* @inheritDoc
*/
- protected $allowGuestAccess = ['getUserProfile', 'getDetailedActivityPointList'];
+ protected $allowGuestAccess = ['getUserProfile', 'getDetailedActivityPointList', 'getPopover'];
/**
* @var User
* Validates user profile preview.
*
* @throws UserInputException
+ * @deprecated since 5.3, use `validateGetPopover()`
*/
public function validateGetUserProfile() {
+ $this->validateGetPopover();
+ }
+
+ /**
+ * Returns user profile preview.
+ *
+ * @return array
+ * @deprecated since 5.3, use `getPopover()`
+ */
+ public function getUserProfile() {
+ return array_merge($this->getPopover(), [
+ 'userID' => reset($this->objectIDs),
+ ]);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function validateGetPopover() {
WCF::getSession()->checkPermissions(['user.profile.canViewUserProfile']);
if (count($this->objectIDs) != 1) {
}
/**
- * Returns user profile preview.
- *
- * @return array
+ * @inheritDoc
*/
- public function getUserProfile() {
+ public function getPopover() {
$userID = reset($this->objectIDs);
if ($userID) {
$userProfileList = new UserProfileList();
$userProfileList->getConditionBuilder()->add("user_table.userID = ?", [$userID]);
$userProfileList->readObjects();
- $userProfiles = $userProfileList->getObjects();
- if (empty($userProfiles)) {
- WCF::getTPL()->assign('unknownUser', true);
+ if (count($userProfileList)) {
+ WCF::getTPL()->assign('user', $userProfileList->getSingleObject());
}
else {
- WCF::getTPL()->assign('user', reset($userProfiles));
+ WCF::getTPL()->assign('unknownUser', true);
}
}
else {
return [
'template' => WCF::getTPL()->fetch('userProfilePreview'),
- 'userID' => $userID
];
}
<?php
namespace wcf\system\template\plugin;
use wcf\data\ILinkableObject;
+use wcf\data\IPopoverObject;
use wcf\data\ITitledLinkObject;
use wcf\data\ITitledObject;
use wcf\system\template\TemplateEngine;
* @inheritDoc
*/
public function execute($tagArgs, TemplateEngine $tplObj) {
- $link = $content = null;
+ $link = $content = $object = null;
if (isset($tagArgs['object'])) {
$object = $tagArgs['object'];
unset($tagArgs['object']);
unset($tagArgs['append']);
}
+ $classes = [];
$additionalParameters = '';
foreach ($tagArgs as $name => $value) {
if (!preg_match('~[a-z]+([A-z]+)+~', $name)) {
throw new \InvalidArgumentException("Invalid additional argument name '{$name}'.");
}
+ if ($name === 'class') {
+ $classes = explode(' ', $value);
+ }
+
$additionalParameters .= ' ' . strtolower(preg_replace('~([A-Z])~', '-$1', $name)) . '="' . StringUtil::encodeHTML($value) . '"';
}
+ if ($object !== null && $object instanceof IPopoverObject && in_array($object->getPopoverLinkClass(), $classes)) {
+ $additionalParameters .= ' data-object-id="' . $object->getObjectID() . '"';
+ }
+
return '<a href="' . StringUtil::encodeHTML($link . $append) . '"' . $additionalParameters . '>' . StringUtil::encodeHTML($content) . '</a>';
}
}