Exemplo n.º 1
0
function wp_ajax_yasr_create_shortcode_callback()
{
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
    } else {
        exit;
    }
    global $wpdb;
    $multi_set = yasr_get_multi_set();
    $n_multi_set = $wpdb->num_rows;
    ?>

            <div id="yasr-tinypopup-form">

                <h2 class="nav-tab-wrapper yasr-underline">
                    <a href="#" id="yasr-link-tab-main" class="nav-tab nav-tab-active"><?php 
    _e("Main", 'yet-another-stars-rating');
    ?>
</a>
                    <a href="#" id="yasr-link-tab-charts" class="nav-tab"><?php 
    _e("Charts", 'yet-another-stars-rating');
    ?>
</a>
                    <?php 
    do_action('yasr_add_tabs_on_tinypopupform');
    ?>

                    <a href="https://yetanotherstarsrating.com/f-a-q/" target="_blank" id="yasr-tinypopup-link-doc"><?php 
    _e("Read the doc", 'yet-another-stars-rating');
    ?>
</a>

                </h2>

                <div id="yasr-content-tab-main">

                    <table id="yasr-table-tiny-popup-main" class="form-table">

                        <tr>
                            <th><label for="yasr-overall"><?php 
    _e("Overall Rating / Review", 'yet-another-stars-rating');
    ?>
</label></th>
                            <td>
                                <input type="button" class="button-primary" id="yasr-overall" name="yasr-overall" value="<?php 
    _e("Insert Overall Rating", 'yet-another-stars-rating');
    ?>
" /><br />
                                <small><?php 
    _e("Insert Overall Rating / Review for this post", 'yet-another-stars-rating');
    ?>
</small>

                                <div id="yasr-overall-choose-size">
                                    <small><?php 
    _e("Choose Size", 'yet-another-stars-rating');
    ?>
<small>
                                    <div class="yasr-tinymce-button-size">
                                        <input type="button" class="button-secondary" id="yasr-overall-insert-small" name="yasr-overall-insert-small" value="<?php 
    _e("Small", 'yet-another-stars-rating');
    ?>
" />
                                        <input type="button" class="button-secondary" id="yasr-overall-insert-medium" name="yasr-overall-insert-medium" value="<?php 
    _e("Medium", 'yet-another-stars-rating');
    ?>
" />
                                        <input type="button" class="button-secondary" id="yasr-overall-insert-large" name="yasr-overall-insert-large" value="<?php 
    _e("Large", 'yet-another-stars-rating');
    ?>
" />
                                    </div>
                                </div>

                            </td>
                        </tr>

                        <tr>
                            <th><label for="yasr-id"><?php 
    _e("Visitor Votes", 'yet-another-stars-rating');
    ?>
</label></th>
                            <td>
                                <input type="button" class="button-primary" name="yasr-visitor-votes" id="yasr-visitor-votes" value="<?php 
    _e("Insert Visitor Votes", 'yet-another-stars-rating');
    ?>
" /><br />
                                <small><?php 
    _e("Insert the ability for your visitor to vote", 'yet-another-stars-rating');
    ?>
</small>

                                <div id="yasr-visitor-choose-size">
                                    <small><?php 
    _e("Choose Size", 'yet-another-stars-rating');
    ?>
<small>
                                    <div class="yasr-tinymce-button-size">
                                        <input type="button" class="button-secondary" id="yasr-visitor-insert-small" name="yasr-visitor-insert-small" value="<?php 
    _e("Small", 'yet-another-stars-rating');
    ?>
" />
                                        <input type="button" class="button-secondary" id="yasr-visitor-insert-medium" name="yasr-visitor-insert-medium" value="<?php 
    _e("Medium", 'yet-another-stars-rating');
    ?>
" />
                                        <input type="button" class="button-secondary" id="yasr-visitor-insert-large" name="yasr-visitor-insert-large" value="<?php 
    _e("Large", 'yet-another-stars-rating');
    ?>
" />
                                    </div>
                                </div>

                            </td>
                        </tr>

                        <?php 
    if ($n_multi_set > 1) {
        //If multiple Set are found
        ?>

                            <tr>
                                <th><label for="yasr-size"><?php 
        _e("If you want to insert a Multi Set, pick one:", 'yet-another-stars-rating');
        ?>
</label></th>
                                <td>
                                    <?php 
        foreach ($multi_set as $name) {
            ?>
                                        <input type="radio" value="<?php 
            echo $name->set_id;
            ?>
" name="yasr_tinymce_pick_set" class="yasr_tinymce_select_set"><?php 
            echo $name->set_name;
            ?>
                                        <br />
                                    <?php 
        }
        //End foreach
        ?>
                                    <small><?php 
        _e("Choose wich set you want to insert.", 'yet-another-stars-rating');
        ?>
</small>
                                    <p>
                                        <input type="checkbox" id="yasr-allow-vote-multiset"><?php 
        _e("Readonly?", 'yet-another-stars-rating');
        ?>
<br />
                                    </p>
                                    <small><?php 
        _e("If Readonly is checked, only you can insert the votes (in the box above the editor)", 'yet-another-stars-rating');
        ?>
</small>
                                    <input type="button" class="button-primary" name="yasr-insert-multiset" id="yasr-insert-multiset-select" value="<?php 
        _e("Insert Multi Set", 'yet-another-stars-rating');
        ?>
" /><br />

                                </td>
                            </tr>

                        <?php 
    } elseif ($n_multi_set == 1) {
        ?>
                            <tr>
                                <th><label for="yasr-size"><?php 
        _e("Insert Multiset:", 'yet-another-stars-rating');
        ?>
</label></th>
                                <td>
                                    <?php 
        foreach ($multi_set as $name) {
            ?>
                                        <button type="button" class="button-primary" id="yasr-single-set" name="yasr-single-set" value="<?php 
            echo $name->set_id;
            ?>
" ><?php 
            _e("Insert Multiple Set", 'yet-another-stars-rating');
            ?>
</button>
                                        &nbsp;&nbsp;&nbsp;
                                        <input type="checkbox" id="yasr-allow-vote-multiset"><?php 
            _e("Readonly?", 'yet-another-stars-rating');
            ?>
<br />
                                        <small><?php 
            _e("If Readonly is checked, only you can insert the votes (in the box above the editor)", 'yet-another-stars-rating');
            ?>
</small>
                                    <?php 
        }
        //End foreach
        ?>
                                </td>
                            </tr>
                        <?php 
    }
    //End elseif
    ?>
                    </table>

                </div>

                <div id="yasr-content-tab-charts" style="display:none">

                    <table id="yasr-table-tiny-popup-charts" class="form-table">
                        <tr>
                            <th><label for="yasr-10-overall"><?php 
    _e("Ranking reviews", 'yet-another-stars-rating');
    ?>
</label></th>
                            <td><input type="button" class="button-primary" name="yasr-top-10-overall-rating" id="yasr-top-10-overall-rating" value="<?php 
    _e("Insert Ranking reviews", 'yet-another-stars-rating');
    ?>
" /><br />
                            <small><?php 
    _e("Insert Top 10 ranking for [yasr_overall_rating] shortcode", 'yet-another-stars-rating');
    ?>
</small></td>
                        </tr>

                        <tr>
                            <th><label for="yasr-10-highest-most-rated"><?php 
    _e("Users' ranking", 'yet-another-stars-rating');
    ?>
</label></th>
                            <td><input type="button" class="button-primary" name="yasr-10-highest-most-rated" id="yasr-10-highest-most-rated" value="<?php 
    _e("Insert Users ranking", 'yet-another-stars-rating');
    ?>
" /><br />
                            <small><?php 
    _e("Insert Top 10 ranking for [yasr_visitor_votes] shortcode", 'yet-another-stars-rating');
    ?>
</small></td>
                        </tr>

                        <tr>
                            <th><label for="yasr-5-active-reviewers"><?php 
    _e("Most active reviewers", 'yet-another-stars-rating');
    ?>
</label></th>
                            <td><input type="button" class="button-primary" name="yasr-5-active-reviewers" id="yasr-5-active-reviewers" value="<?php 
    _e("Insert Most Active Reviewers", 'yet-another-stars-rating');
    ?>
 " /><br />
                            <small><?php 
    _e("Insert Top 5 active reviewers", 'yet-another-stars-rating');
    ?>
</small></td>
                        </tr>

                        <tr>
                            <th><label for="yasr-10-active-users"><?php 
    _e("Most Active Users", 'yet-another-stars-rating');
    ?>
</label></th>
                            <td><input type="button" class="button-primary" name="yasr-top-10-active-users" id="yasr-top-10-active-users" value="<?php 
    _e("Insert Most Active Users", 'yet-another-stars-rating');
    ?>
" /><br />
                            <small><?php 
    _e("Insert Top 10 voters [yasr_visitor_votes] shortcode", 'yet-another-stars-rating');
    ?>
</small></td>
                        </tr>

                    </table>

                </div>

                <?php 
    do_action('yasr_add_content_on_tinypopupform');
    ?>

            </div>

            <script type="text/javascript">

                jQuery( document ).ready(function() {

                    var nMultiSet = <?php 
    echo json_encode("{$n_multi_set}");
    ?>
                    
                    yasrShortcodeCreator(nMultiSet);

                });

            </script>

        <?php 
    die;
}
function yasr_add_metaboxes()
{
    //Default post type where display metabox
    $post_type_where_display_metabox = array('post', 'page');
    //get the custom post type
    $custom_post_types = yasr_get_custom_post_type();
    if ($custom_post_types) {
        //First merge array then changes keys to int
        $post_type_where_display_metabox = array_values(array_merge($post_type_where_display_metabox, $custom_post_types));
    }
    //Always add this metabox
    foreach ($post_type_where_display_metabox as $post_type) {
        add_meta_box('yasr_metabox_overall_rating', 'YASR', 'yasr_metabox_overall_rating_content', $post_type, 'side', 'high');
    }
    $multi_set = yasr_get_multi_set();
    //If multiset are used then add the second metabox
    if ($multi_set) {
        foreach ($post_type_where_display_metabox as $post_type) {
            add_meta_box('yasr_metabox_multiple_rating', __('Yet Another Stars Rating: Multiple set', 'yasr'), 'yasr_metabox_multiple_rating_content', $post_type, 'normal', 'high');
        }
    }
}
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
*/
if (!defined('ABSPATH')) {
    exit('You\'re not allowed to see this page');
}
// Exit if accessed directly
$multi_set = yasr_get_multi_set();
$ajax_nonce_multi = wp_create_nonce("yasr_nonce_insert_multi_rating");
$set_id = NULL;
global $wpdb;
$n_multi_set = $wpdb->num_rows;
//wpdb->num_rows always store the the count number of rows of the last query
if ($n_multi_set > 1) {
    _e("Choose wich set you want to use", 'yet-another-stars-rating');
    ?>

    <br />
    <select id ="select_set">
        <?php 
    foreach ($multi_set as $name) {
        ?>
    		    <option value="<?php 
function yasr_edit_multi_form()
{
    $multi_set = yasr_get_multi_set();
    global $wpdb;
    $n_multi_set = $wpdb->num_rows;
    //wpdb->num_rows always store the last of the last query
    if ($n_multi_set > 1) {
        ?>

			<div class="yasr-manage-multiset">

				<h4 class="yasr-multi-set-form-headers"><?php 
        _e("Manage Multiple Set", "yasr");
        ?>
</h4>

				<?php 
        _e('Wich set do you want to edit or remove?', 'yasr');
        ?>

				<select id ="yasr_select_edit_set">
    				<?php 
        foreach ($multi_set as $name) {
            ?>
		    		<option value="<?php 
            echo $name->set_id;
            ?>
"><?php 
            echo $name->set_name;
            ?>
</option>
	  				<?php 
        }
        //End foreach
        ?>
  				</select>

  				<button href="#" class="button-delete" id="yasr-button-select-set-edit-form"><?php 
        _e("Select");
        ?>
</button>

					
			</div>

				<?php 
    } elseif ($n_multi_set == 1) {
        $set_name = $wpdb->get_results("SELECT field_name AS name, field_id AS id, parent_set_id AS set_id\n\t\t\t                            FROM " . YASR_MULTI_SET_FIELDS_TABLE . "  \n\t\t\t                            ORDER BY field_id ASC");
        foreach ($multi_set as $find_set_id) {
            $set_type = $find_set_id->set_id;
        }
        ?>
			
				<div class="yasr-manage-multiset-single">

					<h4 class="yasr-multi-set-form-headers"><?php 
        _e("Manage Multiple Set", "yasr");
        ?>
</h4>

					<form action=" <?php 
        echo admin_url('options-general.php?page=yasr_settings_page&tab=manage_multi');
        ?>
" id="form_edit_multi_set" method="post">

		        		<input type="hidden" name="yasr_edit_multi_set_form" value="<?php 
        echo $set_type;
        ?>
" />

						<table id="yasr-table-form-edit-multi-set">
		                <tr>

		                    <td id="yasr-table-form-edit-multi-set-header"> 
		                         <?php 
        _e('Field name', 'yasr');
        ?>
		                    </td>

		                     <td id="yasr-table-form-edit-multi-set-remove"> 
		                        <?php 
        _e('Remove', 'yasr');
        ?>
 
		                     </td>

		                </tr>

						<?php 
        $i = 1;
        foreach ($set_name as $name) {
            echo "\n\t\t\t                <tr>\n\t\t                    \n\t\t\t                    <td width=\"80%\">\n\t\t\t                        Element #{$i} <input type=\"text\" value=\"{$name->name}\" name=\"edit-multi-set-element-{$i}\"> \n\t\t\t                        <input type=\"hidden\" value=\"{$name->id}\" name=\"db-id-for-element-{$i}\"> \n\t\t\t                    </td>\n\n\t\t\t                    <td width=\"20%\" style=\"text-align:center\">\n\t\t\t                        <input type=\"checkbox\" value=\"{$name->id}\" name=\"remove-element-{$i}\">\n\t\t\t                    </td>\n\n\t\t                \t</tr>\n\t\t                \t";
            $i++;
        }
        $i = $i - 1;
        //This is the number of the fields
        echo "\n\n\t\t\t            <input type=\"hidden\" name=\"yasr-edit-form-number-elements\" id=\"yasr-edit-form-number-elements\" value=\"{$i}\">\n\n\t\t\t            </table>\n\n\t\t\t            <table width=\"100%\" class=\"yasr-edit-form-remove-entire-set\">\n\t\t\t            <tr>\n\n\t\t\t                <td width=\"80%\">" . __("Remove whole set?", "yasr") . "</td>\n\n\t\t\t                <td width=\"20%\" style=\"text-align:center\">\n\t\t\t                    <input type=\"checkbox\" name=\"yasr-remove-multi-set\" value=\"{$set_type}\">\n\t\t\t                </td>\n\n\t\t\t            </tr>\n\n\t\t\t            </table>\n\n\t\t\t            ";
        echo "<p>";
        _e("If you remove something you will remove all the votes for that set or field. This operation CAN'T BE undone.", "yasr");
        echo "</p>";
        wp_nonce_field('edit-multi-set', 'add-nonce-edit-multi-set');
        ?>

			            <div id="yasr-element-limit" style="display:none; color:red"><?php 
        _e("You can use up to 9 elements", "yasr");
        ?>
</div>

			            <input type="button" class="button-delete" id="yasr-add-field-edit-multiset" value="<?php 
        _e('Add element', 'yasr');
        ?>
"> 

			            <input type="submit" value="<?php 
        _e('Save changes', 'yasr');
        ?>
" class="button-primary" >	

					</form>

				</div>

			<?php 
    } else {
        _e("No Multiple Set were found", "yasr");
    }
}