Last active
August 7, 2016 04:21
-
-
Save danielpowney/25b86304f70e2ed898983822933c6b25 to your computer and use it in GitHub Desktop.
Amazon rating form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Amazon rating form | |
*/ | |
?> | |
<div class="rating-form <?php echo $class; ?> amazon-rating-form"> | |
<?php | |
if ( ! empty( $title ) ) { | |
$before_title = apply_filters( 'mrp_rating_form_before_title', $before_title, $post_id, $rating_form_id ); | |
$after_title = apply_filters( 'mrp_rating_form_after_title', $after_title, $post_id, $rating_form_id ); | |
echo "$before_title" . esc_html( $title ) . "$after_title"; | |
} | |
?> | |
<hr /> | |
<?php | |
if ( $user_id == 0 && ! $allow_anonymous_ratings ) { | |
?> | |
<p> | |
<?php | |
printf( __( 'You must be <a href="%s">logged in</a> to write a review.'), wp_login_url( get_the_permalink( $post_id ) ) ); | |
?> | |
<p> | |
<?php | |
} else { | |
if ( has_post_thumbnail( $post_id ) ) { | |
?> | |
<table> | |
<tr> | |
<td class=" mrp-featured-img" style="vertical-align: top"> | |
<?php echo get_the_post_thumbnail( $post_id, 'thumbnail' ); ?> | |
</td> | |
<td> | |
<p style="margin-top: 0px;"> | |
<a href="<?php echo esc_attr( get_permalink( $post_id ) ); ?>"><?php echo esc_html( get_the_title( $post_id ) ); ?></a> | |
<br /> | |
<?php printf( __( 'By %s', 'my-text-domain' ), get_the_author() ); ?> | |
</p> | |
<?php | |
} | |
$user_can_update_delete = apply_filters( 'mrp_user_can_update_delete', $user_can_update_delete, $user_id, $rating_entry_id, $post_id, $rating_form_id ); | |
// if already submitted a rating and user cannot update or delete, do not show rating form | |
if ( ! ($rating_entry_id != null && ! $user_can_update_delete ) ) { | |
// if an entry exists, show message | |
if ( $rating_entry_id != null && $show_status_message == true ) { | |
if ( $entry_status != 'approved' ) { | |
?> | |
<p class="message mrp"><?php echo esc_html( $rating_awaiting_moderation_message ); ?></p> | |
<?php | |
} else { | |
?> | |
<p class="message mrp"><?php echo esc_html( $existing_rating_message ); ?></p> | |
<?php | |
} | |
} | |
?> | |
<form id="rating-form-<?php echo $rating_form_id; ?>-<?php echo $post_id; ?>-<?php echo $sequence; ?>" action="#"> | |
<?php | |
// rating items at the top - show_rating_item_label set to false for star ratings | |
foreach ( (array) $rating_items as $rating_item ) { | |
$rating_item_id = $rating_item['rating_item_id']; | |
$element_id = 'rating-item-' . $rating_item_id . '-' . $sequence ; | |
$description = $rating_item['description']; | |
$rating_item_type = $rating_item['type']; | |
$max_option_value = $rating_item['max_option_value']; | |
$default_option_value = $rating_item['default_option_value']; | |
$required = $rating_item['required']; | |
$option_value_text = $rating_item['option_value_text']; | |
$rating_item_type = $rating_item['type']; | |
$only_show_text_options = $rating_item['only_show_text_options']; | |
$option_value_text_lookup = MRP_Utils::get_option_value_text_lookup( $option_value_text ); | |
if ( isset( $rating_item_values[$rating_item_id] ) ) { | |
$default_option_value = $rating_item_values[$rating_item_id]; | |
} | |
mrp_get_template_part( 'rating-form', 'rating-item', true, array( | |
'rating_item_id' => $rating_item_id, | |
'element_id' => $element_id, | |
'description' => $description, | |
'max_option_value' => $max_option_value, | |
'default_option_value' => $default_option_value, | |
'required' => $required, | |
'option_value_text' => $option_value_text, | |
'class' => null, | |
'style' => null, | |
'rating_item_type' => $rating_item_type, | |
'option_value_text_lookup' => $option_value_text_lookup, | |
'rating_entry_id' => $rating_entry_id, | |
'only_show_text_options' => $only_show_text_options, | |
'show_rating_item_label' => ( $rating_item_type != 'star_rating' ) // added | |
) ); | |
?> | |
<!-- hidden field to get rating item id --> | |
<input type="hidden" value="<?php echo $rating_item_id; ?>" class="rating-item-<?php echo $rating_form_id; ?>-<?php echo $post_id; ?>-<?php echo $sequence; ?>" id="hidden-rating-item-id-<?php echo $rating_item_id; ?>" /> | |
<?php | |
} | |
// Show title input - no label and input placeholder changed to "Headline for your review" | |
if ( $show_title_input == true ) { | |
?> | |
<p class="mrp review-field"> | |
<input type="text" name="title-<?php echo $sequence; ?>" size="30" placeholder="<?php _e( 'Headline for your review', 'multi-rating-pro' ); ?>" id="mrp-title-<?php echo $sequence ?>" class="title" value="<?php echo esc_attr( $title2 ); ?>" maxlength="100"></input> | |
<span id="title-<?php echo $sequence; ?>-error" class="mrp-error"></span> | |
</p> | |
<?php | |
} | |
// Show comment textarea | |
if ( $show_comment_textarea == true && $comment_id == null ) { | |
$comment_placeholder = __( 'Write you review here (required) ' | |
. 'Consider ' | |
. 'Why did you choose this rating? ' | |
. 'What did you like dislike? ' | |
. 'Who would you recommend this to?', 'multi-rating-pro' ); | |
?> | |
<p class="mrp review-field"> | |
<textarea rows="8" cols="80" name="comment-<?php echo $sequence ?>" placeholder="<?php echo $comment_placeholder; ?>" id="mrp-comment-<?php echo $sequence ?>" class="comments" value="" maxlength="1020"><?php echo esc_textarea( $comment ); ?></textarea> | |
<span id="comment-<?php echo $sequence; ?>-error" class="mrp-error"></span> | |
</p> | |
<?php | |
} | |
// Show name input. Do not show name input if logged in, the user's display name is used | |
if ( $show_name_input == true && $user_id == 0 && $comment_id == null ) { | |
?> | |
<p class="mrp review-field"> | |
<label for="name-<?php echo $sequence; ?>" class="input-label"><?php _e( 'Name', 'multi-rating-pro' ); ?></label><br /> | |
<input type="text" name="name-<?php echo $sequence; ?>" size="30" placeholder="<?php _e( 'Enter your name...', 'multi-rating-pro' ); ?>" id="mrp-name-<?php echo $sequence ?>" class="name" value="<?php echo esc_attr( $name ); ?>" maxlength="100"></input> | |
<span id="name-<?php echo $sequence; ?>-error" class="mrp-error"></span> | |
</p> | |
<?php | |
} | |
// Show email input. Do not show email input if logged in, the user's email is used | |
if ( $show_email_input == true && $user_id == 0 && $comment_id == null ) { | |
?> | |
<p class="mrp review-field"> | |
<label for="email echo $sequence ?>" class="input-label"><?php _e( 'Email', 'multi-rating-pro' ); ?></label><br /> | |
<input type="text" name="email-<?php echo $sequence ?>" size="30" placeholder="<?php _e( 'Enter your email address...', 'multi-rating-pro' ); ?>" id="mrp-email-<?php echo $sequence ?>" class="name" value="<?php echo esc_attr( $email ); ?>" maxlength="100"></input> | |
<span id="email-<?php echo $sequence; ?>-error" class="mrp-error"></span> | |
</p> | |
<?php | |
} | |
foreach ( (array) $custom_fields as $custom_field ) { | |
$custom_field_id = $custom_field['custom_field_id']; | |
$label = $custom_field['label']; | |
$required = $custom_field['required']; | |
$max_length = $custom_field['max_length']; | |
$type = $custom_field['type']; | |
$placeholder = $custom_field['placeholder']; | |
$element_id = 'custom-field-' . $custom_field_id . '-' . $sequence; | |
$value = ''; | |
if ( isset( $custom_field_values[$custom_field_id] ) ) { | |
$value = $custom_field_values[$custom_field_id]; | |
} | |
mrp_get_template_part( 'rating-form', 'custom-fields', true, array( | |
'custom_field_id' => $custom_field_id, | |
'label' => $label, | |
'required' => $required, | |
'max_length' => $max_length, | |
'type' => $type, | |
'placeholder' => $placeholder, | |
'value' => $value, | |
'element_id' => $element_id | |
) ); | |
?> | |
<!-- hidden field to get custom field id --> | |
<input type="hidden" value="<?php echo $custom_field_id; ?>" class="custom-field-<?php echo $rating_form_id; ?>-<?php echo $post_id; ?>-<?php echo $sequence; ?>" id="hidden-custom-field-id-<?php echo $custom_field_id; ?>" /> | |
<?php | |
} | |
$button_text = $submit_button_text; | |
if ( $rating_entry_id != null ) { | |
$button_text = $update_button_text; | |
?> | |
<input type="hidden" value="<?php echo $rating_entry_id; ?>" id="ratingEntryId-<?php echo $rating_form_id; ?>-<?php echo $post_id; ?>-<?php echo $sequence; ?>" /> | |
<a href="#" onclick="return false" class="btn call-to-action btn-default delete-rating" id="deleteBtn-<?php echo $rating_form_id; ?>-<?php echo $post_id; ?>-<?php echo $sequence; ?>"><?php echo $delete_button_text; ?></a> | |
<?php | |
} | |
?> | |
<a href="#" onclick="return false" class="btn call-to-action btn-default save-rating" id="saveBtn-<?php echo $rating_form_id; ?>-<?php echo $post_id; ?>-<?php echo $sequence; ?>"><?php echo $button_text; ?></a> | |
<input type="hidden" name="sequence" value="<?php echo $sequence; ?>" /> | |
</form> | |
<?php | |
} | |
if ( has_post_thumbnail( $post_id ) ) { | |
?> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
} | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment