public static function add_post_meta_boxes() { foreach (CBRatingSystem::post_types() as $argType => $postTypes) { foreach ($postTypes['types'] as $type => $typeLabel) { add_meta_box("cbrp-{$type}-meta-box", esc_html__("Rating Form Options", 'cbratingsystem'), array('CBRatingSystemMetaBox', 'post_meta_box_form'), "{$type}", "advanced", "core"); } } }
/** * @return array */ public static function form_default_fields() { $postTypes = CBRatingSystem::post_types(); $userRoles = CBRatingSystem::user_roles(); $editorUserRoles = CBRatingSystem::editor_user_roles(); $form_default = array('id' => array('type' => 'hidden', 'default' => 0), 'name' => array('label' => __('Form Title', 'cbratingsystem'), 'desc' => __('Write form name', 'cardselectbox'), 'type' => 'text', 'default' => __('Example Rating Form', 'cbratingsystem'), 'tooltip' => __('Form Name', 'cbratingsystem'), 'placeholder' => __('Rating Form Name', 'cbratingsystem'), 'required' => true, 'min' => 5, 'max' => 500, 'errormsg' => __('Form title missing or empty, maximum length 500, minimum length 5', 'cbratingsystem')), 'is_active' => array('label' => __('Form Status', 'cbratingsystem'), 'desc' => __('Enable disable the form', 'cbratingsystem'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Enabled', 'cbratingsystem'), '0' => __('Disabled', 'cbratingsystem'))), 'post_types' => array('label' => __('Post Type Selection', 'cbratingsystem'), 'desc' => __('This form will work for the selected post types', 'cbratingsystem'), 'type' => 'multiselect', 'multiple' => true, 'post_types' => true, 'default' => array('post', 'page'), 'tooltip' => __('Post type selection, works with builtin or custom post types', 'cbratingsystem'), 'placeholder' => __('Choose post type(s)...', 'cbratingsystem'), 'required' => true, 'options' => $postTypes, 'errormsg' => __('Post type is missing or at least one post type must be selected', 'cbratingsystem')), 'show_on_single' => array('label' => __('Show on single post/page', 'cbratingsystem'), 'desc' => __('Enable disable for single article', 'cbratingsystem'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem'))), 'show_on_home' => array('label' => __('Show on Home/Frontpage', 'cbratingsystem'), 'desc' => __('Enable disable for home/frontpage', 'cbratingsystem'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem'))), 'show_on_arcv' => array('label' => __('Show on Archives', 'cbratingsystem'), 'desc' => __('Enable disable for archive pages', 'cardselectbox'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem'))), 'position' => array('label' => __('Auto Integration', 'cbratingsystem'), 'desc' => __('Enable disable for shortcode', 'cbratingsystem'), 'type' => 'radio', 'default' => 'bottom', 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('top' => __('Top (Before Content)', 'cbratingsystem'), 'bottom' => __('Bottom (After Content)', 'cbratingsystem'), 'none' => __('Disable Auto Integration', 'cbratingsystem'))), 'enable_shorttag' => array('label' => __('Enable Shortcode', 'cbratingsystem'), 'desc' => __('Enable disable for shortcode', 'cbratingsystem'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem'))), 'logging_method' => array('label' => __('Loggin Method', 'cbratingsystem'), 'desc' => __('Log user rating by ip or cookie or both to protect multiple rating, useful for guest rating', 'cardselectbox'), 'type' => 'multiselect', 'multiple' => 'yes', 'default' => array('ip', 'cookie'), 'tooltip' => __('Log user rating for guest using ip and cookie', 'cbratingsystem'), 'placeholder' => __('Choose logging method...', 'cbratingsystem'), 'required' => true, 'options' => array('ip' => __('IP', 'cbratingsystem'), 'cookie' => __('Cookie', 'cbratingsystem')), 'errormsg' => __('At least one logging method should be enabled', 'cbratingsystem')), 'allowed_users' => array('label' => __('Allowed User Roles Who Can Rate', 'cbratingsystem'), 'desc' => __('Which user group can rate article with this Rating Form', 'cbratingsystem'), 'type' => 'multiselect', 'user_types' => true, 'placeholder' => __('Choose User Group ...', 'cbratingsystem'), 'multiple' => true, 'default' => array('administrator', 'editor'), 'required' => true, 'options' => $userRoles, 'errormsg' => __('You must select one user group for Rating Editor user', 'cbratingsystem')), 'editor_group' => array('label' => __('Rating Editor User Group', 'cbratingsystem'), 'desc' => __('Which group of user will be Rating Editor', 'cbratingsystem'), 'type' => 'multiselect', 'user_types' => true, 'placeholder' => __('Choose Rating Editor User Group ...', 'cbratingsystem'), 'multiple' => false, 'default' => 'administrator', 'required' => true, 'options' => $editorUserRoles, 'errormsg' => __('You must select one user group for Rating Editor user', 'cbratingsystem')), 'enable_comment' => array('label' => __('Enable Comment', 'cbratingsystem'), 'desc' => __('Enable Comment with Rating', 'cbratingsystem'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem'))), 'comment_limit' => array('label' => __('Comment Limit Length', 'cbratingsystem'), 'desc' => __('Comment limit length prevents user from submitting long comment', 'cardselectbox'), 'type' => 'text', 'default' => 200, 'numeric' => true, 'tooltip' => __('Comment text length limit', 'cbratingsystem'), 'placeholder' => __('Comment Length', 'cbratingsystem'), 'required' => true, 'errormsg' => __('Comment limit can not empty or must be numeric', 'cbratingsystem')), 'enable_question' => array('label' => __('Enable Question', 'cbratingsystem'), 'desc' => __('Enable Question with Rating', 'cbratingsystem'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => true, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem')), 'errormsg' => __('Enable question field is missing or value must be 0 or 1', 'cbratingsystem')), 'show_credit_to_codeboxr' => array('label' => __('Show Credit', 'cbratingsystem'), 'desc' => __('This will show a small link under rating form to codeboxr.com', 'cardselectbox'), 'type' => 'radio', 'default' => 1, 'tooltip' => __('Enabled by default', 'cbratingsystem'), 'required' => false, 'options' => array('1' => __('Yes', 'cbratingsystem'), '0' => __('No', 'cbratingsystem')))); $default_extra_fields = CBRatingSystem::form_default_extra_fields(); $form_default = array_merge($form_default, $default_extra_fields); return $form_default; }
/** * @param array $instance * * @return string|void */ function form($instance) { if ($instance) { $title = esc_attr($instance['title']); } else { $title = __('Top Rated Users', 'cbratingsystem'); } if (array_key_exists('timelimit', $instance)) { $timelimit = $instance['timelimit']; } else { $timelimit = '0'; } if (array_key_exists('user_id', $instance)) { $user_id = $instance['user_id']; } else { $user_id = ''; } if (array_key_exists('post_id', $instance)) { $post_id = $instance['post_id']; } else { $post_id = ''; } if (array_key_exists('resultlimit', $instance)) { $limit = $instance['resultlimit']; } else { $limit = '10'; } if (array_key_exists('posttype', $instance)) { $posttype = $instance['posttype']; } else { $posttype = '0'; } if (array_key_exists('post_filter', $instance)) { $post_filter = $instance['post_filter']; } else { $post_filter = 'post_type'; } if (array_key_exists('form_id', $instance)) { $form_id = $instance['form_id']; } else { $form_id = 'form_id'; } if (array_key_exists('order', $instance)) { $order = $instance['order']; } else { $order = 'DESC'; } if (array_key_exists('firstorder', $instance)) { $firstorder = $instance['firstorder']; } else { $firstorder = 'post_count'; } ?> <p> <label for = "<?php echo $this->get_field_id('title'); ?> "><?php _e("Title", 'cbratingsystem'); ?> :</label> <input class = "widefat" id="<?php echo $this->get_field_id('title'); ?> " type="text" name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo $title; ?> " /> </p> <!--user limit --> <p> <label for = "<?php echo $this->get_field_id('user_id'); ?> "><?php _e("User Ids ('Blank or comma separate ids ) ", 'cbratingsystem'); ?> :</label> <input class = "widefat" id="<?php echo $this->get_field_id('user_id'); ?> " type="text" name="<?php echo $this->get_field_name('user_id'); ?> " value="<?php echo $user_id; ?> " /> </p> <!--time limit --> <p> <label for="<?php echo $this->get_field_id('timelimit'); ?> "><?php _e("Display Last", 'cbratingsystem'); ?> :</label> <select id="<?php echo $this->get_field_id('timelimit'); ?> " name="<?php echo $this->get_field_name('timelimit'); ?> " class="widefat" style="width:50%"> <?php //$no_of_days = array( 1 => '24 hours', 7 => 'Week', 15 => '15 Days', 30 => 'Month', 0 => 'All' ); $no_of_days = array(1 => __('Last 24 hours', 'cbratingsystem'), 7 => __('Last 7 Days', 'cbratingsystem'), 15 => __('Last 15 Days', 'cbratingsystem'), 30 => __('Last 30 days', 'cbratingsystem'), 0 => __('All Time', 'cbratingsystem')); foreach ($no_of_days as $day => $day_label) { echo "<option value='{$day}'"; if ($timelimit == $day) { echo "selected='selected'"; } echo ">{$day_label}</option>"; } ?> </select> </p> <p><?php _e('Note: Based on Post creation date', 'cbratingsystem'); ?> </p> <!--result limit --> <p> <label for="<?php echo $this->get_field_id('resultlimit'); ?> ">No. To Display:</label> <input class="widefat" id="<?php echo $this->get_field_id('resultlimit'); ?> " type="text" name="<?php echo $this->get_field_name('resultlimit'); ?> " value="<?php echo $limit; ?> " /> </p> <!--post id --> <p> <label for="<?php echo $this->get_field_id('post_id'); ?> "><?php _e("Post Ids ('Blank or comma separate ids ) ", 'cbratingsystem'); ?> :</label> <input class="widefat" id="<?php echo $this->get_field_id('post_id'); ?> " type="text" name="<?php echo $this->get_field_name('post_id'); ?> " value="<?php echo $post_id; ?> " /> </p> <!--post type id --> <p> <label for="<?php echo $this->get_field_id('posttype'); ?> "><?php _e("Post Type", 'cbratingsystem'); ?> :</label> <select id="<?php echo $this->get_field_id('posttype'); ?> " name="<?php echo $this->get_field_name('posttype'); ?> " class="widefat" style="width: 55%"> <?php echo "<option value='0'"; if ($posttype == 0) { echo "selected='selected'"; } echo ">" . ucfirst('All') . "</option>"; ////////////// foreach (CBRatingSystem::post_types() as $argType => $postTypes) { echo '<optgroup label="' . $postTypes['label'] . '">'; foreach ($postTypes['types'] as $type => $typeLabel) { echo "<option value='{$type}'"; if ($posttype == $type) { echo "selected='selected'"; } echo ">" . ucfirst($typeLabel) . "</option>"; } echo '</optgroup>'; } ?> </select> </p> <!-- post type filter --> <p> <label for="<?php echo $this->get_field_id('post_filter'); ?> "><?php _e("Post Filter", 'cbratingsystem'); ?> :</label> <select id="<?php echo $this->get_field_id('post_filter'); ?> " name="<?php echo $this->get_field_name('post_filter'); ?> " class="widefat" style="width:50%"> <?php $no_of_filter = array('post_type' => 'Post Type', 'post_id' => 'Post ID'); foreach ($no_of_filter as $key => $label) { echo "<option value = '{$key}'"; if ($post_filter == $key) { echo "selected='selected'"; } echo "> {$label} </option>"; } ?> </select> </p> <!-- order by type filter --> <p> <label for="<?php echo $this->get_field_id('order'); ?> "><?php _e("Order", 'cbratingsystem'); ?> :</label> <select id="<?php echo $this->get_field_id('order'); ?> " name="<?php echo $this->get_field_name('order'); ?> " class="widefat" style="width:50%"> <?php $no_of_filter = array('ASC' => 'Ascending', 'DESC' => 'Descending'); foreach ($no_of_filter as $key => $label) { echo "<option value = '{$key}'"; if ($order == $key) { echo "selected='selected'"; } echo "> {$label} </option>"; } ?> </select> </p> <!-- order by type filter --> <p> <label for="<?php echo $this->get_field_id('firstorder'); ?> "><?php _e("First Sort By", 'cbratingsystem'); ?> :</label> <select id="<?php echo $this->get_field_id('firstorder'); ?> " name="<?php echo $this->get_field_name('firstorder'); ?> " class="widefat" style="width:50%"> <?php $no_of_filter = array('rating' => 'Rating', 'post_count' => 'User post Number'); foreach ($no_of_filter as $key => $label) { echo "<option value = '{$key}'"; if ($firstorder == $key) { echo "selected='selected'"; } echo "> {$label} </option>"; } ?> </select> </p> <!--form id --> <p> <label for="<?php echo $this->get_field_id('form_id'); ?> "><?php _e("Form", 'cbratingsystem'); ?> :</label> <select id="<?php echo $this->get_field_id('form_id'); ?> " name="<?php echo $this->get_field_name('form_id'); ?> " class="widefat" style="width: 55%"> <?php $action = array('is_active' => true); $ratingForms = CBRatingSystemData::get_ratingForms(true, $action); $ratingFormToShow = intval($form_id); $default = CBRatingSystem::get_default_ratingFormId(); if (!empty($ratingForms)) { echo "<option value='0'"; if ($ratingFormToShow == 0) { echo "selected='selected'"; } echo ">" . ucfirst('All') . "</option>"; foreach ($ratingForms as $ratingForm) { if ($default == $ratingForm->id) { $txt = ' (' . __('Default Form', 'cbratingsystem') . ')'; } else { $txt = ''; } if ($ratingFormToShow == $ratingForm->id) { echo '<option selected value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>'; } else { echo '<option value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>'; } } } ?> </select> </p> <?php }