Ejemplo n.º 1
0
    /**
     * Show avg rating for multiple posts for same form id,
     * calls from shortcode or direct function call or from widget
     *
     * @param     $option
     * @param int $show_title
     * @param int $show_form_id
     * @param int $show_text
     * @param int $show_star
     * @param int $show_single
     * @param int $text_label
     *
     * @return string
     */
    public static function standalone_singlePost_rating_summary($option, $show_title = 0, $show_form_id = 0, $show_text = 0, $show_star = 1, $show_single = 0, $text_label = '')
    {
        CBRatingSystem::load_scripts_and_styles();
        if ($option == NULL) {
            return '';
        }
        $text_label = $text_label == '' ? __('Rating: ', 'cbratingsystem') : $text_label;
        $post_ids = !isset($option['post_id']) || !is_array($option['post_id']) || sizeof($option['post_id']) == 0 ? array(get_the_ID()) : $option['post_id'];
        $form_ids = !isset($option['form_id']) || !is_array($option['form_id']) || sizeof($option['form_id']) == 0 ? array(self::get_default_ratingFormId()) : $option['form_id'];
        //$post_ids        = is_array($post_ids)
        $rating_smmary = array('post' => array());
        $show = '';
        /*echo '<pre>';
        		print_r($option);
        		echo '</pre>';*/
        //var_dump($form_ids);
        //var_dump($show_single);
        if ($show_single == 1 || sizeof($post_ids) == 1) {
            //if ( $show_single == 1 ) {
            //show only for first item
            $option['post_id'] = array($post_ids[0]);
            $option['form_id'] = array($form_ids[0]);
            $average_rating = CBRatingSystemData::get_ratings_summary($option);
            if (!sizeof($average_rating)) {
                $average_rating['form_id'] = $form_ids[0];
                $average_rating['post_id'] = $post_ids[0];
                $average_rating['post_title'] = get_the_title($post_ids[0]);
                $average_rating['per_post_rating_summary'] = 0;
                $average_rating['found'] = 0;
            } else {
                $average_rating = $average_rating[0];
                //no rating found for this post and form id
                $average_rating['found'] = 1;
            }
            $show .= '<div class="cbratingavgratelist">';
            if ($show_title == 1) {
                $show .= '<p>' . __('Post: ', 'cbratingsystem') . $average_rating['post_title'] . '</p>';
            }
            if ($show_form_id == 1) {
                $show .= '<p>' . __('Form: ', 'cbratingsystem') . $average_rating['form_id'] . '</p>';
            }
            if ($show_text == 1) {
                $show .= '<p>' . $text_label . number_format($average_rating['per_post_rating_summary'] / 100 * 5, 2) . '/5</p>';
            }
            $clip_back = 120;
            $star_clip_amount = number_format($average_rating['per_post_rating_summary'] / 100 * 120, 2);
            if ($show_star == 1) {
                ?>
				<script>
					jQuery(document).ready(function ($) {
						$('.cbrp-alone-rated<?php 
                echo $average_rating['post_id'];
                ?>
').raty({
							half    : true,
							path    : '<?php 
                echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                ?>
',
							score   : <?php 
                echo $average_rating['per_post_rating_summary'] / 100 * 5;
                ?>
,
							readOnly: true,
							hintList: ['', '', '', '', '']
						});
					});
				</script>
				<?php 
                $show .= '  <div class="cbrp-alone-rated cbrp-alone-rated' . $average_rating['post_id'] . '" id="cbrp-alone-rated' . $average_rating['post_id'] . '" style="margin: 0;"></div>';
            }
            $show .= '</div>';
            // echo   $show;
        } else {
            //var_dump('I am here');
            //$show = '';
            if (!empty($post_ids) && !empty($form_ids)) {
                //$position = 30;
                foreach ($post_ids as $post_id) {
                    //$average_ratings = CBRatingSystemData::get_ratings($form_id,$post_id);
                    //$option=array('post_id'=>$post_id,'form_id'=>$form_id);
                    //unset( $whrOpt );
                    $option = array();
                    $option['form_id'] = $form_ids;
                    $option['post_id'] = array($post_id);
                    $average_rating = CBRatingSystemData::get_ratings_summary($option);
                    if (!sizeof($average_rating)) {
                        $average_rating['form_id'] = $form_ids[0];
                        $average_rating['post_id'] = $post_ids[0];
                        $average_rating['post_title'] = get_the_title($post_ids[0]);
                        $average_rating['per_post_rating_summary'] = 0;
                        $average_rating['found'] = 0;
                    } else {
                        $average_rating = $average_rating[0];
                        $average_rating['found'] = 1;
                    }
                    $show .= '<div class="cbratingavgratelist" style="position:relative;">';
                    if ($show_title == 1) {
                        $show .= '<p>' . __('Post: ', 'cbratingsystem') . $average_rating['post_title'] . '</p>';
                    }
                    if ($show_form_id == 1) {
                        $show .= '<p>' . __('Form: ', 'cbratingsystem') . $average_rating['form_id'] . '<p>';
                    }
                    if ($show_text == 1) {
                        $show .= '<p>' . $text_label . '' . number_format($average_rating['per_post_rating_summary'] / 100 * 5, 2) . '/5<p>';
                    }
                    $clip_back = 120;
                    $star_clip_amount = number_format($average_rating['per_post_rating_summary'] / 100 * 120, 2);
                    if ($show_star == 1) {
                        ?>
						<script>
							jQuery(document).ready(function ($) {
								$('.cbrp-alone-rated<?php 
                        echo $post_id;
                        ?>
').raty({
									half    : true,
									path    : '<?php 
                        echo CB_RATINGSYSTEM_PLUGIN_DIR_IMG;
                        ?>
',
									score   : <?php 
                        echo $average_rating['per_post_rating_summary'] / 100 * 5;
                        ?>
,
									readOnly: true,
									hintList: ['', '', '', '', '']
								});
							});
						</script>
						<?php 
                        $show .= '  <div class="cbrp-alone-rated cbrp-alone-rated' . $average_rating['post_id'] . '" id="cbrp-alone-rated' . $post_id . '" style="margin: 0;"></div>';
                    }
                    $show .= '</div>';
                    //$position += 30;
                }
                //echo $show;
            }
        }
        return $show;
    }
Ejemplo n.º 2
0
    public static function post_meta_box_form($object, $box)
    {
        //echo '<pre>'; print_r($object); echo '</pre>';
        $postId = $object->ID;
        //var_dump($postId);
        $ratingFormEnabled = get_post_meta($postId, '_cbrating_enable_ratingForm', true);
        $defaultRatingFormEnabled = get_post_meta($postId, '_cbrating_is_default_ratingForm', true);
        $ratingFormToShow = get_post_meta($postId, '_cbrating_listing_ratingForm', true);
        $default = get_option('cbratingsystem_defaultratingForm');
        $default = CBRatingSystem::get_default_ratingFormId();
        $ratingFormToShow = (!empty($ratingFormToShow) and is_numeric($ratingFormToShow)) ? $ratingFormToShow : ((is_numeric($default) and !empty($default)) ? $default : '#NONE#');
        $action = array('is_active' => true, 'post_type' => $object->post_type);
        $ratingForms = CBRatingSystemData::get_ratingForms(true, $action);
        $adminUrl = admin_url('?page=rating');
        $option = '<select id="listing_ratingForm" name="listing_ratingForm" class="listing_ratingForm_select" style="width:50%">';
        if ($ratingFormToShow == '#NONE#') {
            $option .= '<option selected value="#NONE#">' . __('--Select rating form--', 'cbratingsystem') . '</option>';
        } else {
            $option .= '<option value="#NONE#">' . __('--Select rating form--', 'cbratingsystem') . '</option>';
        }
        if (!empty($ratingForms)) {
            foreach ($ratingForms as $ratingForm) {
                if ($default == $ratingForm->id) {
                    $txt = ' (' . __('Default Form', 'cbratingsystem') . ')';
                } else {
                    $txt = '';
                }
                if ($ratingFormToShow == $ratingForm->id) {
                    $option .= '<option selected value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>';
                } else {
                    $option .= '<option value="' . $ratingForm->id . '">' . $ratingForm->name . $txt . '</option>';
                }
            }
        }
        $option .= '</select>';
        ?>
		<?php 
        wp_nonce_field(basename(__FILE__), 'rating_form_meta_box_nonce');
        ?>


		<p>
			<label for="enable_ratingForm"><?php 
        _e(sprintf("Display Form"), 'cbratingsystem');
        ?>
</label>
			<input type="checkbox" id="enable_ratingForm" name="enable_ratingForm" value="1" <?php 
        echo $ratingFormEnabled != '' ? $ratingFormEnabled == 1 ? 'checked' : '' : 'checked';
        ?>
/>
		</p>
		<p>
			<label for="is_default_ratingForm"><?php 
        _e(sprintf("Use Default"), 'cbratingsystem');
        ?>
</label>
			<input type="checkbox" id="is_default_ratingForm" name="is_default_ratingForm" value="1" <?php 
        echo $defaultRatingFormEnabled != '' ? $defaultRatingFormEnabled == 1 ? 'checked' : '' : 'checked';
        ?>
/>
		</p>
		<p class="cb_listing_ratingForm">
			<label for="listing_ratingForm"><?php 
        _e(sprintf("Select which form should work for this %s:", $object->post_type), 'cbratingsystem');
        ?>
</label>
			<br />
			<?php 
        echo $option;
        ?>
			<span class="description"><?php 
        _e(sprintf("Select which form should work for this %s. You can checkout rating forms at %s page.", $object->post_type, '<a target="_blank" href="' . $adminUrl . '">this</a>'), 'cbratingsystem');
        ?>
</span>
		</p>

		<script type="text/javascript">
			jQuery(document).ready(function ($) {
				$('input#is_default_ratingForm').change(function () {
					if ($(this).is(':checked')) {
						$('.cb_listing_ratingForm').hide();
					} else {
						$('.cb_listing_ratingForm').show();
					}
				});
				if ($('input#is_default_ratingForm').is(':checked')) {
					$('.cb_listing_ratingForm').hide();
				} else {
					$('.cb_listing_ratingForm').show();
				}
			});
		</script>
	<?php 
    }
Ejemplo n.º 3
0
    /**
     * @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 
    }
Ejemplo n.º 4
0
    /**
     * averageReportPageOutput
     */
    public static function averageReportPageOutput()
    {
        global $wpdb;
        $path = admin_url('admin.php?page=rating_avg_reports');
        $sort = isset($_GET['sort']) && $_GET['sort'] == 'asc' ? 'asc' : 'desc';
        $sortby = (!empty($_GET['sortby']) and $sort) ? $_GET['sortby'] : 'form_id';
        $summaryData = CBRatingSystemData::get_ratings_summary(array(), $sortby, $sort, true);
        ?>
        <div class="wrap columns-2">
            <div class="icon32 icon32_cbrp_admin icon32-cbrp-rating-avg" id="icon32-cbrp-rating-avg"><br></div>
            <h2><?php 
        _e("Codeboxr Rating System Rating Average", 'cbratingsystem');
        ?>
</h2>
            <div class="metabox-holder has-right-sidebar" id="poststuff">
                <div id="message"
                </div>
                <div id="post-body" class="post-body">
                    <div id="stuff-box">
                        <!-- Starting of Average rating Listing -->
                        <div class="cbrp-log-report-average">
                            <form method="post">
                                <div style="clear: both;"></div>

                                <?php 
        if ($summaryData) {
            ?>
                                    <?php 
            foreach ($summaryData as $rowId => $rows) {
                if (!empty($rows->per_post_rating_count) and !empty($rows->per_post_rating_summary)) {
                    ?>

                                            <?php 
                    $log_average = array();
                    $log_post_id = $rows->post_id;
                    $log_post_title = $rows->post_title;
                    $log_form_id = $rows->form_id;
                    $log_average = $rows->per_post_rating_summary > 0 ? "<strong>" . number_format($rows->per_post_rating_summary / 100 * 5, 2) . " out of 5</strong>" : '-';
                    $userRoleLabels = CBRatingSystem::user_role_label();
                    $log_ratingCount = $rows->per_post_rating_count;
                    $log_id = $rows->id;
                    $table = CBRatingSystemData::get_user_ratings_table_name();
                    $sql = $wpdb->prepare("SELECT id FROM {$table} WHERE post_id=%d AND form_id=%d ", $log_post_id, $log_form_id);
                    $results = $wpdb->get_results($sql, ARRAY_A);
                    $results = maybe_unserialize($results[0]['id']);
                    if (!empty($rows->per_criteria_rating_summary)) {
                        $log_criteria_rating = '<ul>';
                        foreach ($rows->per_criteria_rating_summary as $cId => $criteria) {
                            $log_criteria_rating .= "<li>" . $criteria['label'] . ": <strong>" . number_format($criteria['value'] / 100 * count($criteria['stars']), 2) . " out of " . count($criteria['stars']) . "</strong>";
                        }
                        $log_criteria_rating .= '</ul>';
                    } else {
                        $log_criteria_rating = '-';
                    }
                    array_push(CBratinglogreportoutput::$cb_avg_comment_log_data, array('id_user_table' => $results, 'id' => $log_id, 'rating_count' => $log_ratingCount, 'criteria_rating' => $log_criteria_rating, 'post' => $log_post_id, 'posttitle' => $log_post_title, 'formid' => $log_form_id, 'avgrating' => $log_average));
                    ?>
                                        <?php 
                } else {
                    //echo "<td colspan='7' align='center'>No Results Found</td>";
                }
            }
            ?>
                                    <?php 
        } else {
            //echo "<td colspan='7' align='center'>No Results Found</td>";
            ?>
                                    <?php 
        }
        ?>
                            </form>
                        </div>
                        <!-- Ending of Average rating Listing -->
                    </div>
                </div>

            </div>
        </div>
        <?php 
        $list_table = new Cbratingavglog();
        $list_table->prepare_items();
        ?>
        <form id="movies-filter" method="get">
            <input type="hidden" name="page" value="<?php 
        echo $_REQUEST['page'];
        ?>
" />
            <?php 
        $list_table->display();
        ?>
        </form>
        <?php 
    }
Ejemplo n.º 5
0
    public static function admin_ratingForm_tool_settings()
    {
        CBRatingSystem::add_common_styles_scripts();
        ?>

		<!--div class="wrap columns-2">
			<div class="icon32 icon32_cbrp_admin icon32-cbrp-dashboard" id="icon32-cbrp-dashboard"><br></div>
			<h2><?php 
        _e("Codeboxr Rating System Tools", 'cbratingsystem');
        ?>
</h2>

			<div class="metabox-holder has-right-sidebar" id="poststuff">
				<div id="post-body" class="post-body">
                    <?php 
        echo self::rating_system_tools_settings();
        ?>
				</div>

			</div>
		</div-->
		<div class="wrap">

			<div id="icon-options-general" class="icon32"></div>
			<h2><?php 
        _e("Codeboxr Rating System Tools", 'cbratingsystem');
        ?>
</h2>

			<div id="poststuff">

				<div id="post-body" class="metabox-holder columns-2">

					<!-- main content -->
					<div id="post-body-content">

						<div class="meta-box-sortables ui-sortable">

							<div class="postbox">
								<div class="inside">
									<?php 
        echo self::rating_system_tools_settings();
        ?>
								</div> <!-- .inside -->

							</div> <!-- .postbox -->

						</div> <!-- .meta-box-sortables .ui-sortable -->

					</div> <!-- post-body-content -->

					<!-- sidebar -->
					<div id="postbox-container-1" class="postbox-container">

						<div class="meta-box-sortables">

							<div class="postbox">

								<h3><span><?php 
        _e('Plugin Information', 'cbratingsystem');
        ?>
</span></h3>
								<div class="inside">
									<?php 
        define('CB_RATINGSYSTEM_SUPPORT_VIDEO_DISPLAY', true);
        require CB_RATINGSYSTEM_PATH . '/cb-sidebar.php';
        ?>
								</div> <!-- .inside -->

							</div> <!-- .postbox -->

						</div> <!-- .meta-box-sortables -->

					</div> <!-- #postbox-container-1 .postbox-container -->

				</div> <!-- #post-body .metabox-holder .columns-2 -->

				<br class="clear">
			</div> <!-- #poststuff -->

		</div> <!-- .wrap -->

		<?php 
        ?>

	<?php 
    }
Ejemplo n.º 6
0
 /**
  * @param $id
  * @param bool $is_object
  * @return array
  */
 public static function get_ratingForm($id, $is_object = false)
 {
     global $wpdb;
     $table_name = self::get_ratingForm_settings_table_name();
     $sql = $wpdb->prepare("SELECT * FROM {$table_name} WHERE id=%d", $id);
     //$postTypes          = CBRatingSystem::post_types();
     //$userRoles          = CBRatingSystem::user_roles();
     //$editorUserRoles    = CBRatingSystem::editor_user_roles();
     $form_default = CBRatingSystem::form_default_fields();
     $form_question = CBRatingSystem::form_default_question();
     $form_criteria = CBRatingSystem::form_default_criteria();
     if (!$is_object) {
         $results = $wpdb->get_results($sql, ARRAY_A);
         if (empty($results)) {
             return array();
         }
         //now we are fixing for array
         $result = $results[0];
         $result["custom_criteria"] = maybe_unserialize($result["custom_criteria"]);
         $result["custom_question"] = maybe_unserialize($result["custom_question"]);
         $extrafields = maybe_unserialize($result['extrafields']);
         $extrafields = (array) $extrafields;
         $result = array_merge($result, $extrafields);
         foreach ($form_default as $key => $field) {
             if ($field['type'] == 'multiselect') {
                 if (!isset($result[$key])) {
                     continue;
                 }
                 $result[$key] = maybe_unserialize($result[$key]);
             }
         }
         /*
         	        echo '<pre>';
         	        print_r($result);
         	        echo '</pre>';
         */
         /*
                     $result["post_types"]                 = maybe_unserialize( $result["post_types"] );
                     $result["position"]                   = maybe_unserialize( $result["position"] );
                     $result["logging_method"]             = maybe_unserialize( $result["logging_method"] );
                     $result["allowed_users"]              = maybe_unserialize( $result["allowed_users"] );
                     $result["view_allowed_users"]         = maybe_unserialize( $result["view_allowed_users"] );
                     $result["comment_view_allowed_users"] = maybe_unserialize( $result["comment_view_allowed_users"] );
                     $result["comment_moderation_users"]   = maybe_unserialize( $result["comment_moderation_users"] );
                     $result["custom_criteria"]            = maybe_unserialize( $result["custom_criteria"] );
                     $result["custom_question"]            = maybe_unserialize( $result["custom_question"] );
                     $result["review"]                     = maybe_unserialize( $result["review"] );
         */
         //echo "<pre>"; print_r($result); echo "</pre>";
     } else {
         $results = $wpdb->get_results($sql, OBJECT);
         if (empty($results)) {
             return new stdclass();
         }
         $result = $results[0];
         $result->custom_criteria = maybe_unserialize($result->custom_criteria);
         $result->custom_question = maybe_unserialize($result->custom_question);
         $extrafields = maybe_unserialize($result->extrafields);
         $extrafields = (array) $extrafields;
         $result = array_merge((array) $result, $extrafields);
         foreach ($form_default as $key => $field) {
             if ($field['type'] == 'multiselect') {
                 $result[$key] = maybe_unserialize($result[$key]);
             }
         }
         $result = (object) $result;
         /*
                     $result->post_types                 = maybe_unserialize( $result->post_types );
                     $result->position                   = maybe_unserialize( $result->position );
                     $result->logging_method             = maybe_unserialize( $result->logging_method );
                     $result->allowed_users              = maybe_unserialize( $result->allowed_users );
                     $result->view_allowed_users         = maybe_unserialize( $result->view_allowed_users );
                     $result->comment_view_allowed_users = maybe_unserialize( $result->comment_view_allowed_users );
                     $result->comment_moderation_users   = maybe_unserialize( $result->comment_moderation_users );
                     $result->custom_criteria            = maybe_unserialize( $result->custom_criteria );
                     $result->custom_question            = maybe_unserialize( $result->custom_question );
                     $result->review                     = maybe_unserialize( $result->review );
         */
     }
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * Ajax function for the review submission
  */
 public static function cbRatingAjaxFunction()
 {
     global $wpdb;
     $user_id = get_current_user_id();
     //returns 0 if guest
     $user_info = '';
     if (isset($_POST['cbRatingData']) && !empty($_POST['cbRatingData'])) {
         $returnedData = $_POST['cbRatingData'];
         //var_dump($returnedData);
         if (wp_verify_nonce($returnedData['cbrp_nonce'], 'cb_ratingForm_front_form_nonce_field')) {
             if (!empty($returnedData['values'])) {
                 list($insertArray['form_id'], $insertArray['post_id']) = explode('-', $returnedData['rp_id']);
                 if ($user_id == 0) {
                     $user_session = $_COOKIE[CB_RATINGSYSTEM_COOKIE_NAME];
                     //this is string
                     $user_ip = CBRatingSystem::get_ipaddress();
                 } elseif ($user_id > 0) {
                     $user_session = 'user-' . $user_id;
                     //this is string
                     $user_ip = CBRatingSystem::get_ipaddress();
                     $user_info = get_userdata($user_id);
                 }
                 $table_name1 = CBRatingSystemData::get_user_ratings_table_name();
                 $table_name2 = CBRatingSystemData::get_ratingForm_settings_table_name();
                 $sql_get_loggin = "SELECT logging_method FROM {$table_name2} where id=" . $insertArray['form_id'];
                 //$sql_get_loggin = maybe_unserialize($sql_get_loggin[0]->logging_method);
                 $query_result = $wpdb->get_results($sql_get_loggin);
                 $query_result2 = maybe_unserialize($query_result[0]->logging_method);
                 //getting the data according to the administrative settings using IP/Cookie for the last comment
                 if (in_array("cookie", $query_result2) && !in_array("ip", $query_result2)) {
                     $sql = $wpdb->prepare("SELECT COUNT(ur.id) AS count FROM {$table_name1} ur WHERE ur.form_id=%d AND ur.post_id=%d AND ur.user_id=%d AND ur.user_session = %s", $insertArray['form_id'], $insertArray['post_id'], $user_id, $user_session);
                     $count = $wpdb->get_var($sql);
                 } else {
                     if (!in_array("cookie", $query_result2) && in_array("ip", $query_result2)) {
                         $sql = $wpdb->prepare("SELECT COUNT(ur.id) AS count FROM {$table_name1} ur WHERE ur.form_id=%d AND ur.post_id=%d AND ur.user_id=%d AND ur.user_ip = %s", $insertArray['form_id'], $insertArray['post_id'], $user_id, $user_ip);
                         $count = $wpdb->get_var($sql);
                     } else {
                         $sql = $wpdb->prepare("SELECT COUNT(ur.id) AS count FROM {$table_name1} ur WHERE ur.form_id=%d AND ur.post_id=%d AND ur.user_id=%d AND ur.user_ip = %s", $insertArray['form_id'], $insertArray['post_id'], $user_id, $user_ip);
                         $count = $wpdb->get_var($sql);
                     }
                 }
                 if ($count < 1) {
                     // first time rating
                     $insertArray['post_type'] = get_post_type($insertArray['post_id']);
                     $insertArray['created'] = time();
                     $question = array();
                     if (!empty($returnedData['question'][$insertArray['form_id']]) && is_array($returnedData['question'][$insertArray['form_id']])) {
                         foreach ($returnedData['question'][$insertArray['form_id']] as $qID => $qValue) {
                             if (is_array($qValue) && !empty($qValue)) {
                                 foreach ($qValue as $key => $val) {
                                     $type = $qValue[$qID . '_type'];
                                     if (isset($qValue[$type . '-' . $qID]) && !empty($qValue[$type . '-' . $qID])) {
                                         $question[$qID] = $qValue[$type . '-' . $qID];
                                     } elseif ($key != $qID . '_type' && $key != $type . '-' . $qID && !empty($val)) {
                                         $key = str_replace($qID . '_', '', $key);
                                         if (is_numeric($key)) {
                                             $question[$qID][$key] = $val;
                                         }
                                     }
                                 }
                             } else {
                                 $question[$qID] = $qValue;
                             }
                         }
                     }
                     $insertArray['question'] = maybe_serialize($question);
                     $comment = esc_html(sanitize_text_field($returnedData['comment']));
                     if (strlen($comment) <= $returnedData['comment_limit']) {
                         $insertArray['comment'] = $comment;
                     } elseif (strlen($comment) > $returnedData['comment_limit']) {
                         $insertArray['comment'] = substr($comment, 0, intval($returnedData['comment_limit']));
                     }
                     if (!is_user_logged_in()) {
                         if (!empty($returnedData['user_name'])) {
                             $insertArray['user_name'] = sanitize_text_field(trim($returnedData['user_name']));
                         } else {
                             $encoded = json_encode(array('validation' => 1, 'errorMessage' => __('Name field can\'t be left blank.', 'cbratingsystem')));
                             echo $encoded;
                             die;
                         }
                         if (!empty($returnedData['user_email']) and is_email(trim($returnedData['user_email']))) {
                             $insertArray['user_email'] = sanitize_text_field(trim($returnedData['user_email']));
                         } else {
                             $encoded = json_encode(array('validation' => 1, 'errorMessage' => __('Please enter a valid email address.', 'cbratingsystem')));
                             echo $encoded;
                             die;
                         }
                     }
                     /*else {
                                                 //guest user
                     							$insertArray['user_name']  = '';
                     							$insertArray['user_email'] = $returnedData['user_email'];
                     							$insertArray['user_ip']      = $user_ip;
                     							$insertArray['user_session'] = $user_session;
                     
                     						}*/
                     $insertArray['user_name'] = $user_id > 0 ? $user_info->user_login : $returnedData['user_name'];
                     $insertArray['user_email'] = $user_id > 0 ? $user_info->user_email : $returnedData['user_email'];
                     $insertArray['user_ip'] = $user_ip;
                     $insertArray['user_session'] = $user_session;
                     /*
                      * @example:
                      * $returnedData['values'] = array(
                      *      0 => 100          // label_id/criteria_id => ( (Score For this label / Star count) * 100)
                      * )
                      */
                     $insertArray['rating'] = maybe_serialize($returnedData['values']);
                     foreach ($returnedData['values'] as $key => $val) {
                         if (is_numeric($key)) {
                             $average[$key] = $val;
                         }
                     }
                     $hash_comment = $insertArray['user_ip'] . $insertArray['user_session'] . $insertArray['user_email'] . time();
                     $hash_comment = md5($hash_comment);
                     $insertArray['average'] = array_sum($average) / count($average);
                     //$insertArray['user_ip']      = CBRatingSystem::get_ipaddress();
                     //$insertArray['user_session'] = ( $user_id != 0 ) ? 'user-' . $user_id : $_COOKIE[CB_RATINGSYSTEM_COOKIE_NAME];
                     $insertArray['user_id'] = $user_id;
                     $insertArray['form_id'] = (int) $insertArray['form_id'];
                     $insertArray['post_id'] = (int) $insertArray['post_id'];
                     $insertArray['comment_status'] = $returnedData['comment_status'];
                     $insertArray['comment_hash'] = $hash_comment;
                     $insertArray['allow_user_to_hide'] = isset($returnedData["hide_this_user_name"]) ? $returnedData["hide_this_user_name"] : 0;
                     $return = CBRatingSystemData::update_rating($insertArray);
                     if ($insertArray['comment_status'] == 'unverified' && $insertArray['comment_hash'] != '' && $insertArray['user_email'] != '') {
                         $cb_subject = __('Verify Your email', 'cbratingsystem');
                         $cb_message = get_site_url() . '?cbratingemailverify=' . $insertArray['comment_hash'];
                         $from = get_option('admin_email');
                         //var_dump($from);
                         wp_mail($insertArray['user_email'], $cb_subject, $cb_message);
                         // mail($insertArray['user_email'],$cb_subject,$cb_message,"From: $from\n");
                     }
                     // buddypress post added 29-10-14 codeboxr
                     if (isset($returnedData["buddypress_post"]) && $returnedData["buddypress_post"] == '1' || is_user_logged_in()) {
                         if (function_exists('bp_is_active')) {
                             // buddy press active
                             $buddy_post = array('id' => false, 'action' => bp_core_get_userlink(bp_loggedin_user_id()) . __(' has rated this post ', 'cbratingsystem') . get_permalink($insertArray['post_id']), 'content' => $insertArray['comment'], 'component' => 'ratingcomponent', 'type' => 'ratingcomponent_activity', 'primary_link' => '', 'user_id' => bp_loggedin_user_id(), 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false, 'is_spam' => false);
                             do_action('cbratingsystem_buddypress_activity_post', $buddy_post);
                         }
                         //end checking if buddypress is installed
                     }
                     $lastcommentrt = $return;
                     // storing the last commend id for safety
                     if ($return) {
                         //getting the criteria rating result
                         $ratingAverage = self::viewPerCriteriaRatingResult($insertArray['form_id'], $insertArray['post_id'], $user_id);
                         $ratingsCount = $ratingAverage['ratingsCount'][$insertArray['form_id'] . '-' . $insertArray['post_id']];
                         if (!empty($ratingsCount)) {
                             $rating = array('form_id' => $insertArray['form_id'], 'post_id' => $insertArray['post_id'], 'post_type' => $insertArray['post_type'], 'per_post_rating_count' => $ratingsCount, 'per_post_rating_summary' => number_format($ratingAverage['perPost'][$insertArray['post_id']], 2), 'custom_user_rating_summary' => maybe_serialize($ratingAverage['customUser']), 'per_criteria_rating_summary' => maybe_serialize($ratingAverage['avgPerCriteria']));
                             foreach ($ratingAverage['avgPerCriteria'] as $cId => $criteria) {
                                 $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($criteria['stars']);
                                 $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                             }
                             if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                                 foreach ($ratingAverage['customUser']['perCriteria']['editor'] as $cId => $criteria) {
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                                 }
                             } else {
                                 foreach ($ratingAverage['avgPerCriteria'] as $cId => $criteria) {
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = 0;
                                 }
                             }
                             $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $rating['per_post_rating_summary'];
                             if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $ratingAverage['customUser']['perPost']['editor'];
                             } else {
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = 0;
                             }
                             $return = CBRatingSystemData::update_rating_summary($rating);
                             $editorCount = isset($ratingAverage['customUser']['perPostRateCount']['editor']) ? (int) $ratingAverage['customUser']['perPostRateCount']['editor'] : 0;
                             //review part here
                             if (empty($ratingFormArray)) {
                                 $defaultFormId = get_option('cbratingsystem_defaultratingForm');
                                 $ratingFormId = apply_filters('rating_form_array', $defaultFormId);
                                 //getting the rating form data from here.
                                 $ratingFormArray = CBRatingSystemData::get_ratingForm($insertArray['form_id']);
                             }
                             //get the theme for doing frontend UI works
                             $theme_key = get_option('cbratingsystem_theme_key');
                             $reviewOptions['theme'] = $theme_key;
                             $reviewOptions['comment_status'] = $insertArray['comment_status'];
                             $reviewOptions["hide_this_user_name"] = isset($returnedData["hide_this_user_name"]) ? $returnedData["hide_this_user_name"] : 0;
                             $lastcomment = is_numeric($lastcommentrt) ? self::build_user_rating_review_single($reviewOptions, $ratingFormArray, $lastcommentrt) : '';
                             //echo $lastcomment;
                             if ($return) {
                                 $encoded = json_encode(array('img_path' => CB_RATINGSYSTEM_PLUGIN_DIR_IMG, 'hints' => json_encode($cCriteria), 'is_rated' => 1, 'ratingsCount' => $ratingsCount, 'editorRatingsCount' => $editorCount, 'lastcomment' => $lastcomment, 'theme_key' => $reviewOptions['theme'], 'firstcomment' => true, 'comment_status' => $insertArray['comment_status']));
                                 echo $encoded;
                             }
                         }
                     }
                 } else {
                     //at least one rating done
                     $summary = CBRatingSystemData::get_ratings_summary(array('form_id' => array($insertArray['form_id']), 'post_id' => array($insertArray['post_id'])));
                     if (!empty($summary[0])) {
                         foreach ($summary[0]['per_criteria_rating_summary'] as $cId => $criteria) {
                             $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($criteria['stars']);
                             $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                         }
                         if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                             foreach ($ratingAverage['customUser']['perCriteria']['editor'] as $cId => $criteria) {
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                 $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = $criteria['value'];
                             }
                         } else {
                             if (!empty($summary[0])) {
                                 foreach ($summary[0]['per_criteria_rating_summary'] as $cId => $criteria) {
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-count'] = count($ratingAverage['avgPerCriteria'][$cId]['stars']);
                                     $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-stars-' . $cId . '-value'] = 0;
                                 }
                             }
                         }
                         $cCriteria['readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $rating['per_post_rating_summary'];
                         if (!empty($ratingAverage['customUser']['perCriteria']['editor'])) {
                             $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = $ratingAverage['customUser']['perPost']['editor'];
                         } else {
                             $cCriteria['editor-readonly-criteria-label-' . $insertArray['form_id'] . '-post-' . $insertArray['post_id'] . '-avgvalue'] = 0;
                         }
                         $encoded = json_encode(array('img_path' => CB_RATINGSYSTEM_PLUGIN_DIR_IMG, 'hints' => json_encode($cCriteria), 'is_rated' => 1, 'ratingsCount' => $summary[0]['per_post_rating_count'], 'errorMessage' => __('You have already rated this.', 'cbratingsystem')));
                         echo $encoded;
                     } else {
                         $encoded = json_encode(array('is_rated' => 1, 'errorMessage' => __('An error occurred while storing data. Please ensure that all data are resonable. If problem persist please contact the administrator.', 'cbratingsystem')));
                         echo $encoded;
                     }
                 }
                 //end you already submitted your rating.
             }
         }
     }
     die;
 }
 /**
  * @param array $comment
  * @param       $session
  * @param       $ip
  *
  * @return bool
  */
 public static function check_permission($comment = array(), $session, $ip)
 {
     $ratingFormArray['comment_view_allowed_users'] = $comment;
     global $current_user, $wpdb;
     $user_id = get_current_user_id();
     $showreview = false;
     //var_dump($user_id);
     if ($user_id > 0) {
         $role = $wpdb->prefix . 'capabilities';
         $current_user->role = array_keys($current_user->{$role});
         $role = $current_user->role[0];
     }
     //var_dump($ratingFormArray['comment_view_allowed_users']);
     //var_dump($role);
     $user_id = get_current_user_id();
     if ($user_id == 0 && in_array('guest', $ratingFormArray['comment_view_allowed_users'])) {
         $showreview = true;
     } else {
         if ($user_id > 0 && in_array($role, $ratingFormArray['comment_view_allowed_users'])) {
             $showreview = true;
         }
     }
     if ($user_id == 0) {
         $user_session = $_COOKIE[CB_RATINGSYSTEM_COOKIE_NAME];
         //this is string
         $user_ip = CBRatingSystem::get_ipaddress();
     } elseif ($user_id > 0) {
         $user_session = 'user-' . $user_id;
         //this is string
         $user_ip = CBRatingSystem::get_ipaddress();
     }
     $show_own_review = false;
     //allowing user to show his own comment
     if ($user_session == $session && $user_ip == $ip) {
         $show_own_review = true;
     }
     if ($show_own_review || $showreview) {
         $show_review_final = true;
     } else {
         $show_review_final = false;
     }
     return $show_review_final;
 }