addBehavior( 'adminDashboardItems', ['topWriterAdmin', 'adminDashboardItems'] ); $core->addBehavior( 'adminDashboardOptionsForm', ['topWriterAdmin', 'adminDashboardOptionsForm'] ); $core->addBehavior( 'adminAfterDashboardOptionsUpdate', ['topWriterAdmin', 'adminAfterDashboardOptionsUpdate'] ); /** * @ingroup DC_PLUGIN_TOPWRITER * @brief Display most active users - admin methods. * @since 2.6 */ class topWriterAdmin { public static function adminDashboardItems(dcCore $core, $__dashboard_items) { $pref = self::setDefaultPref($core); # top posts if ($pref['topWriterPostsItems']) { $lines = topWriter::posts($core, $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($core, $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(dcCore $core) { $pref = self::setDefaultPref($core); 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) { global $core; $core->auth->user_prefs->dashboard->put( 'topWriterPostsItems', !empty($_POST['topWriterPostsItems']), 'boolean' ); $core->auth->user_prefs->dashboard->put( 'topWriterPostsPeriod', (string) $_POST['topWriterPostsPeriod'], 'string' ); $core->auth->user_prefs->dashboard->put( 'topWriterPostsLimit', (int) $_POST['topWriterPostsLimit'], 'integer' ); $core->auth->user_prefs->dashboard->put( 'topWriterCommentsItems', !empty($_POST['topWriterCommentsItems']), 'boolean' ); $core->auth->user_prefs->dashboard->put( 'topWriterCommentsPeriod', (string) $_POST['topWriterCommentsPeriod'], 'string' ); $core->auth->user_prefs->dashboard->put( 'topWriterCommentsLimit', (int) $_POST['topWriterCommentsLimit'], 'integer' ); } private static function setDefaultPref($core) { if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) { $core->auth->user_prefs->dashboard->put( 'topWriterPostsItems', false, 'boolean' ); } if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) { $core->auth->user_prefs->dashboard->put( 'topWriterPostsPeriod', 'month', 'string' ); } if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) { $core->auth->user_prefs->dashboard->put( 'topWriterPostsLimit', 10, 'integer' ); } if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) { $core->auth->user_prefs->dashboard->put( 'topWriterCommentsItems', false, 'boolean' ); } if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) { $core->auth->user_prefs->dashboard->put( 'topWriterCommentsPeriod', 'month', 'string' ); } if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) { $core->auth->user_prefs->dashboard->put( 'topWriterCommentsLimit', 10, 'integer' ); } return [ 'topWriterPostsItems' => $core->auth->user_prefs->dashboard->get('topWriterPostsItems'), 'topWriterPostsPeriod' => $core->auth->user_prefs->dashboard->get('topWriterPostsPeriod'), 'topWriterPostsLimit' => $core->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10, 'topWriterCommentsItems' => $core->auth->user_prefs->dashboard->get('topWriterCommentsItems'), 'topWriterCommentsPeriod' => $core->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'), 'topWriterCommentsLimit' => $core->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10 ]; } }