Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

methods to get voting markup

  • Loading branch information...
commit baa0e78056483c4c3525a139f5801528af04d49a 1 parent f4f9493
@matzko authored
Showing with 55 additions and 5 deletions.
  1. +55 −5 includes/core.php
View
60 includes/core.php
@@ -1,6 +1,6 @@
<?php
-if ( ! class_exists( '' ) ) {
+if ( ! class_exists( 'WP_Post_Object_Voter' ) ) {
class WP_Post_Object_Voter
{
@@ -69,6 +69,56 @@ public function does_voter_table_exist()
}
}
+class WP_Post_Object_Voter_View
+{
+ public $link_template = '<a href="%1$s" class="%2$s" id="%3$s">%4$s</a>';
+
+ public function __construct()
+ {
+ }
+
+ public function get_thumbs_down_link( $object_id = 0 )
+ {
+ $object_id = (int) $object_id;
+
+ $url = add_query_arg( array(
+ 'thumbs-down' => $object_id,
+ 'thumbs-nonce' => wp_create_nonce( 'thumbs-vote-nonce' ),
+ ) );
+
+ return sprintf(
+ $this->link_template,
+ $url,
+ 'post-object-vote thumbs-down',
+ 'thumbs-down-' . $object_id,
+ __( 'Thumbs Down', 'post-voter' )
+ );
+ }
+
+ public function get_thumbs_up_link( $object_id = 0 )
+ {
+ $object_id = (int) $object_id;
+
+ $url = add_query_arg( array(
+ 'thumbs-up' => $object_id,
+ 'thumbs-nonce' => wp_create_nonce( 'thumbs-vote-nonce' ),
+ ) );
+
+ return sprintf(
+ $this->link_template,
+ $url,
+ 'post-object-vote thumbs-up',
+ 'thumbs-up-' . $object_id,
+ __( 'Thumbs Up', 'post-voter' )
+ );
+ }
+
+ public function print_voting_section( $object_id = 0 )
+ {
+
+ }
+}
+
class WP_Post_Object_Vote
{
public $blog_id = 0;
@@ -163,9 +213,9 @@ public function vote_thumbs_down( $object_id = 0 )
$object_id = (int) $object_id;
if ( false === $this->_get_existing_vote( $this->blog_id, $object_id, $this->user_id ) ) {
- $this->_add_vote( $this->user_id, $object_id, $this->user_id, -1 )
+ $this->_add_vote( $this->user_id, $object_id, $this->user_id, -1 );
} else {
- $this->_update_vote( $this->user_id, $object_id, $this->user_id, -1 )
+ $this->_update_vote( $this->user_id, $object_id, $this->user_id, -1 );
}
}
@@ -175,9 +225,9 @@ public function vote_thumbs_up( $object_id = 0 )
$object_id = (int) $object_id;
if ( false === $this->_get_existing_vote( $this->blog_id, $object_id, $this->user_id ) ) {
- $this->_add_vote( $this->user_id, $object_id, $this->user_id, 1 )
+ $this->_add_vote( $this->user_id, $object_id, $this->user_id, 1 );
} else {
- $this->_update_vote( $this->user_id, $object_id, $this->user_id, 1 )
+ $this->_update_vote( $this->user_id, $object_id, $this->user_id, 1 );
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.