addBehavior( 'adminDashboardItemsV2', ['topWriterAdmin', 'adminDashboardItems'] ); dcCore::app()->addBehavior( 'adminDashboardOptionsFormV2', ['topWriterAdmin', 'adminDashboardOptionsForm'] ); dcCore::app()->addBehavior( 'adminAfterDashboardOptionsUpdate', ['topWriterAdmin', 'adminAfterDashboardOptionsUpdate'] ); /** * @ingroup DC_PLUGIN_TOPWRITER * @brief Display most active users - admin methods. * @since 2.6 */ class topWriterAdmin { public static function adminDashboardItems($__dashboard_items) { $pref = self::setDefaultPref(); # top posts if ($pref['topWriterPostsItems']) { $lines = topWriter::posts($pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']); if (empty($lines)) { return null; } $li = []; foreach ($lines as $k => $line) { $li[] = sprintf('
  • %s %s (%s)
  • ', $k, $line['author'], $line['count']); } # Display $__dashboard_items[0][] = '
    ' . '

    ' . html::escapeHTML(__('Top writer: entries')) . '

    ' . '' . '
    '; } # top comments if ($pref['topWriterCommentsItems']) { $lines = topWriter::comments($pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']); if (empty($lines)) { return null; } $li = []; foreach ($lines as $k => $line) { $li[] = sprintf('
  • %s %s (%s)
  • ', $k, $line['author'], $line['count']); } # Display $__dashboard_items[0][] = '
    ' . '

    ' . html::escapeHTML(__('Top writer: comments')) . '

    ' . '' . '
    '; } } public static function adminDashboardOptionsForm() { $pref = self::setDefaultPref(); echo '
    ' . '

    ' . __('Top writer: entries') . '

    ' . '

    ' . '

    ' . form::combo('topWriterPostsPeriod', topWriter::periods(), $pref['topWriterPostsPeriod']) . '

    ' . '

    ' . form::number('topWriterPostsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterPostsLimit']]) . '

    ' . '
    ' . '
    ' . '

    ' . __('Top writer: comments') . '

    ' . '

    ' . '

    ' . form::combo('topWriterCommentsPeriod', topWriter::periods(), $pref['topWriterCommentsPeriod']) . '

    ' . '

    ' . form::number('topWriterCommentsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterCommentsLimit']]) . '

    ' . '
    '; } public static function adminAfterDashboardOptionsUpdate($user_id) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsItems', !empty($_POST['topWriterPostsItems']), 'boolean' ); dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsPeriod', (string) $_POST['topWriterPostsPeriod'], 'string' ); dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsLimit', (int) $_POST['topWriterPostsLimit'], 'integer' ); dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsItems', !empty($_POST['topWriterCommentsItems']), 'boolean' ); dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsPeriod', (string) $_POST['topWriterCommentsPeriod'], 'string' ); dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsLimit', (int) $_POST['topWriterCommentsLimit'], 'integer' ); } private static function setDefaultPref() { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsItems', false, 'boolean' ); } if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsPeriod', 'month', 'string' ); } if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsLimit', 10, 'integer' ); } if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsItems', false, 'boolean' ); } if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsPeriod', 'month', 'string' ); } if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) { dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsLimit', 10, 'integer' ); } return [ 'topWriterPostsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsItems'), 'topWriterPostsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsPeriod'), 'topWriterPostsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10, 'topWriterCommentsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsItems'), 'topWriterCommentsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'), 'topWriterCommentsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10, ]; } }