/**
         * My History Content
         * @since 0.1
         * @version 1.2
         */
        public function my_history_screen()
        {
            global $bp;
            $mycred_types = mycred_get_types();
            $type = 'mycred_default';
            if (isset($_REQUEST['show-ctype']) && array_key_exists($_REQUEST['show-ctype'], $mycred_types)) {
                $type = $_REQUEST['show-ctype'];
            }
            $args = array('user_id' => bp_displayed_user_id(), 'number' => apply_filters('mycred_bp_history_num_to_show', $this->buddypress['history_num']), 'ctype' => $type);
            if (isset($_GET['paged']) && $_GET['paged'] != '') {
                $args['paged'] = $_GET['paged'];
            }
            if (isset($bp->canonical_stack['action']) && $bp->canonical_stack['action'] != $this->buddypress['history_url']) {
                $args['time'] = $bp->canonical_stack['action'];
            }
            $log = new myCRED_Query_Log($args);
            unset($log->headers['column-username']);
            ob_start();
            if (count($mycred_types) > 1) {
                ?>
<form action="" id="mycred-sort-cred-history-form" method="get" style="display: block; height: 48px; float: right;"><label>Show:</label> <?php 
                mycred_types_select_from_dropdown('show-ctype', 'mycred-select-type', $type);
                ?>
 <input type="submit" class="btn btn-large btn-primary button button-large button-primary" value="<?php 
                _e('Go', 'mycred');
                ?>
" /></form>
<?php 
            }
            ?>
<style type="text/css">
.pagination-links { float: right; }
.tablenav { vertical-align: middle; }
</style>
<div class="wrap" id="myCRED-wrap">

	<?php 
            $log->mobile_support();
            ?>

	<form method="get" action="">
		<div class="tablenav top clear clearfix">

			<?php 
            if ($log->have_entries() && $log->max_num_pages > 1) {
                $log->navigation('top');
            }
            ?>

		</div>

		<?php 
            $log->display();
            ?>

		<div class="tablenav bottom clear clearfix">

			<?php 
            if ($log->have_entries() && $log->max_num_pages > 1) {
                $log->navigation('bottom');
            }
            ?>

		</div>

	</form>
</div>
<?php 
            $log->reset_query();
            $output = ob_get_contents();
            ob_end_clean();
            echo apply_filters('mycred_bp_history_page', $output, $this);
        }
Example #2
0
        /**
         * My History Page
         * @since 0.1
         * @version 1.2.1
         */
        public function my_history_page()
        {
            // Security
            if (!is_user_logged_in()) {
                wp_die(__('Access Denied', 'mycred'));
            }
            $settings_key = 'mycred_epp_' . $_GET['page'];
            if (!$this->is_main_type) {
                $settings_key .= '_' . $this->mycred_type;
            }
            $per_page = mycred_get_user_meta($this->current_user_id, $settings_key, '', true);
            if ($per_page == '') {
                $per_page = 10;
            }
            $args = array('user_id' => $this->current_user_id, 'number' => $per_page);
            if (isset($_GET['type']) && !empty($_GET['type'])) {
                $args['ctype'] = $_GET['type'];
            } else {
                $args['ctype'] = $this->mycred_type;
            }
            if (isset($_GET['s']) && !empty($_GET['s'])) {
                $args['s'] = sanitize_text_field($_GET['s']);
            }
            if (isset($_GET['ref']) && !empty($_GET['ref'])) {
                $args['ref'] = sanitize_text_field($_GET['ref']);
            }
            if (isset($_GET['show']) && !empty($_GET['show'])) {
                $args['time'] = absint($_GET['show']);
            }
            if (isset($_GET['order']) && !empty($_GET['order'])) {
                $args['order'] = sanitize_text_field($_GET['order']);
            }
            if (isset($_GET['start']) && isset($_GET['end'])) {
                $args['amount'] = array('start' => sanitize_text_field($_GET['start']), 'end' => sanitize_text_field($_GET['end']));
            } elseif (isset($_GET['num']) && isset($_GET['compare'])) {
                $args['amount'] = array('num' => sanitize_text_field($_GET['num']), 'compare' => $_GET['compare']);
            } elseif (isset($_GET['amount'])) {
                $args['amount'] = sanitize_text_field($_GET['amount']);
            }
            if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                $args['paged'] = absint($_GET['paged']);
            }
            $log = new myCRED_Query_Log($args);
            unset($log->headers['column-username']);
            ?>
<div class="wrap" id="myCRED-wrap">
	<h2><?php 
            $this->page_title(sprintf(__('My %s History', 'mycred'), $this->core->plural()));
            ?>
</h2>

	<?php 
            $log->filter_dates(admin_url('users.php?page=' . $_GET['page']));
            ?>

	<?php 
            do_action('mycred_top_my_log_page', $this);
            ?>

	<?php 
            $log->exporter(__('Export', 'mycred'), true);
            ?>

	<form method="get" action="" name="mycred-mylog-form" novalidate>
<?php 
            if (isset($_GET['s']) && !empty($_GET['s'])) {
                echo '<input type="hidden" name="s" value="' . $_GET['s'] . '" />';
            }
            if (isset($_GET['ref']) && !empty($_GET['ref'])) {
                echo '<input type="hidden" name="ref" value="' . $_GET['ref'] . '" />';
            }
            if (isset($_GET['show']) && !empty($_GET['show'])) {
                echo '<input type="hidden" name="show" value="' . $_GET['show'] . '" />';
            }
            if (isset($_GET['order']) && !empty($_GET['order'])) {
                echo '<input type="hidden" name="order" value="' . $_GET['order'] . '" />';
            }
            if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                echo '<input type="hidden" name="paged" value="' . $_GET['paged'] . '" />';
            }
            $log->search();
            ?>
		<input type="hidden" name="page" value="<?php 
            echo $_GET['page'];
            ?>
" />

		<?php 
            do_action('mycred_above_my_log_table', $this);
            ?>

		<div class="tablenav top">

			<?php 
            $log->table_nav('top', true);
            ?>

		</div>

		<?php 
            $log->display();
            ?>

		<div class="tablenav bottom">

			<?php 
            $log->table_nav('bottom', true);
            ?>

		</div>

		<?php 
            do_action('mycred_bellow_my_log_table', $this);
            ?>

	</form>

	<?php 
            do_action('mycred_bottom_my_log_page', $this);
            ?>

</div>
<?php 
            $log->reset_query();
        }
    function mycred_render_shortcode_history($atts, $content = '')
    {
        extract(shortcode_atts(array('user_id' => '', 'number' => '', 'time' => '', 'ref' => '', 'order' => '', 'show_user' => 0, 'show_nav' => 1, 'login' => '', 'type' => 'mycred_default'), $atts));
        // If we are not logged in
        if (!is_user_logged_in() && $login != '') {
            return $login . $content;
        }
        if ($user_id == 'current') {
            $user_id = get_current_user_id();
        }
        $args = array('ctype' => $type);
        if ($user_id != '') {
            $args['user_id'] = $user_id;
        }
        if ($number != '') {
            $args['number'] = $number;
        }
        if ($time != '') {
            $args['time'] = $time;
        }
        if ($ref != '') {
            $args['ref'] = $ref;
        }
        if ($order != '') {
            $args['order'] = $order;
        }
        if (isset($_GET['paged']) && $_GET['paged'] != '') {
            $args['paged'] = absint($_GET['paged']);
        }
        $log = new myCRED_Query_Log($args);
        if ($show_user != 1) {
            unset($log->headers['column-username']);
        }
        ob_start();
        ?>

<form class="form" role="form" method="get" action="">
	<div class="tablenav top">

		<?php 
        if ($log->have_entries() && $show_nav == 1 && $log->max_num_pages > 1) {
            $log->navigation('top');
        }
        ?>

	</div>

	<?php 
        $log->display();
        ?>

	<div class="tablenav bottom">

		<?php 
        if ($log->have_entries() && $show_nav == 1 && $log->max_num_pages > 1) {
            $log->navigation('bottom');
        }
        ?>

	</div>
</form>
<?php 
        $content = ob_get_contents();
        ob_end_clean();
        $log->reset_query();
        return $content;
    }
Example #4
0
 /**
  * Widget Output
  */
 function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     // If we are logged in
     if (is_user_logged_in()) {
         // Current user id
         $user_id = get_current_user_id();
         // Load myCRED Now
         if (!isset($instance['type']) || empty($instance['type'])) {
             $instance['type'] = 'mycred_default';
         }
         $mycred = mycred($instance['type']);
         // If this is an excluded user we bail
         if ($mycred->exclude_user($user_id)) {
             return;
         }
         // Start
         echo $before_widget;
         // Title
         if (!empty($instance['title'])) {
             echo $before_title;
             echo $mycred->template_tags_general($instance['title']);
             echo $after_title;
         }
         // Balance
         $balance = $mycred->get_users_cred($user_id, $instance['type']);
         if (empty($balance)) {
             $balance = 0;
         }
         $layout = $mycred->template_tags_amount($instance['cred_format'], $balance);
         $layout = $mycred->template_tags_user($layout, false, wp_get_current_user());
         // Include Ranking
         if ($instance['show_rank']) {
             if (function_exists('mycred_get_users_rank')) {
                 $rank_name = mycred_get_users_rank($user_id);
                 $ranking = str_replace('%rank%', $rank_name, $instance['rank_format']);
                 $ranking = str_replace('%rank_logo%', mycred_get_rank_logo($rank_name), $ranking);
                 $ranking = str_replace('%ranking%', '', $ranking);
             } else {
                 $ranking = str_replace(array('%rank%', '%ranking%'), '', $instance['rank_format']);
             }
             $ranking = '<div class="myCRED-rank">' . $ranking . '</div>';
             $layout .= $ranking;
         }
         echo '<div class="myCRED-balance">' . $layout . '</div>';
         // If we want to include history
         if ($instance['show_history']) {
             echo '<div class="myCRED-widget-history">';
             // Query Log
             $log = new myCRED_Query_Log(array('user_id' => $user_id, 'number' => $instance['number'], 'ctype' => $instance['type']));
             // Have results
             if ($log->have_entries()) {
                 // Title
                 if (!empty($instance['history_title'])) {
                     $history_title = $instance['history_title'];
                     echo $before_title . $mycred->template_tags_general($history_title) . $after_title;
                 }
                 // Organized List
                 echo '<ol class="myCRED-history">';
                 $alt = 0;
                 $date_format = get_option('date_format');
                 foreach ($log->results as $entry) {
                     // Row Layout
                     $layout = $instance['history_format'];
                     $layout = str_replace('%date%', '<span class="date">' . date_i18n($date_format, $entry->time) . '</span>', $layout);
                     $layout = str_replace('%entry%', $mycred->parse_template_tags($entry->entry, $entry), $layout);
                     $layout = $mycred->allowed_tags($layout);
                     $layout = $mycred->template_tags_general($layout);
                     $layout = $mycred->template_tags_amount($layout, $entry->creds);
                     // Alternating rows
                     $alt = $alt + 1;
                     if ($alt % 2 == 0) {
                         $class = 'row alternate';
                     } else {
                         $class = 'row';
                     }
                     // Output list item
                     echo '<li class="' . $class . '">' . $layout . '</li>';
                 }
                 echo '</ol>';
             }
             $log->reset_query();
             echo '</div>';
         }
         // End
         echo $after_widget;
     } else {
         // If we want to show a message, then do so
         if ($instance['show_visitors']) {
             echo $before_widget;
             $mycred = mycred($instance['type']);
             // Title
             if (!empty($instance['title'])) {
                 echo $before_title;
                 echo $mycred->template_tags_general($instance['title']);
                 echo $after_title;
             }
             $message = $instance['message'];
             $message = $mycred->template_tags_general($message);
             $message = $mycred->allowed_tags($message);
             echo '<div class="myCRED-my-balance-message"><p>' . nl2br($message) . '</p></div>';
             echo $after_widget;
         }
     }
 }
Example #5
0
 function mycred_render_shortcode_history($atts)
 {
     extract(shortcode_atts(array('user_id' => NULL, 'number' => NULL, 'time' => NULL, 'ref' => NULL, 'order' => NULL, 'show_user' => false, 'login' => '', 'type' => 'mycred_default'), $atts));
     // If we are not logged in
     if (!is_user_logged_in() && !empty($login)) {
         return '<p class="mycred-history login">' . $login . '</p>';
     }
     if ($user_id === NULL) {
         $user_id = get_current_user_id();
     }
     $args = array('user_id' => $user_id, 'ctype' => $type);
     if ($number !== NULL) {
         $args['number'] = $number;
     }
     if ($time !== NULL) {
         $args['time'] = $time;
     }
     if ($ref !== NULL) {
         $args['ref'] = $ref;
     }
     if ($order !== NULL) {
         $args['order'] = $order;
     }
     $log = new myCRED_Query_Log($args);
     if ($show_user !== true) {
         unset($log->headers['column-username']);
     }
     $result = $log->get_display();
     $log->reset_query();
     return $result;
 }