Advertisement
Guest User

Untitled

a guest
May 11th, 2012
2,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.97 KB | None | 0 0
  1. <?php
  2. //Include the comment-upload handler plugin
  3. require_once('easy-comment-uploads/main.php');
  4.  
  5.  
  6. /**
  7. * This is the only function you need to generate a WP-Viper Guestbook - simply
  8. * "echo vgb_GetGuestbook()" in any of your templates.
  9. *
  10. * Note: Templates that use this guestbook should NOT call comments_template().
  11. * Note: Requires the_post() to've been called already, i.e. we're in The Loop.
  12. * Note: See the $defaults array for available options.
  13. */
  14. function vgb_GetGuestbook( $opts=array() )
  15. {
  16. $defaults = array(
  17. 'entriesPerPg' => 10, //Number if entries to show per page
  18. 'reverseOrder' => false, //Reverse the order of entries (oldest first)
  19. 'allowUploads' => false, //Allow users to upload images
  20. 'maxImgSizKb' => 50, //Max uploadable image size (if allowUploads is set)
  21. 'showBrowsers' => true, //Show browser/OS icons in guestbook entries
  22. 'showFlags' => true, //Show national flags in guestbook entries (REQUIRES OZH IP2NATION)
  23. 'hideCred' => false, //Omit "Powered by WP-ViperGB" (please don't though :))
  24. 'showCredLink' => false //Include a link to the project page in the "Powered by WP-ViperGP" (would be appreciated :))
  25. );
  26. $opts = wp_parse_args( $opts, $defaults );
  27.  
  28. if( vgb_is_listing_pg() ) return vgb_get_listing_pg($opts);
  29. else return vgb_get_sign_pg($opts);
  30. }
  31.  
  32.  
  33. /********************************************************************************/
  34. /******************************IMPLEMENTATION************************************/
  35. /********************************************************************************/
  36.  
  37.  
  38. //PHP Arguments
  39. define('VB_SIGN_PG_ARG', 'sign'); //"Sign" page (vs "Listing" page)
  40. define('VB_PAGED_ARG', 'cpage'); //Paged Comments pagenumber
  41.  
  42.  
  43. /**
  44. * Return true if this is the LISTING page, false if it's the SIGN page
  45. */
  46. function vgb_is_listing_pg()
  47. {
  48. return !isset($_REQUEST[VB_SIGN_PG_ARG]);
  49. }
  50.  
  51.  
  52. /**
  53. * Return the URL to the plugin directory, with trailing slash
  54. */
  55. function vgb_get_data_url()
  56. {
  57. return plugins_url(dirname(plugin_basename(__FILE__))) . '/';
  58. }
  59.  
  60.  
  61. /**
  62. * Return the current page number (in listing view)
  63. */
  64. function vgb_get_current_page_num()
  65. {
  66. return max(get_query_var(VB_PAGED_ARG), 1);
  67. }
  68.  
  69.  
  70. /**
  71. * Get the header: Show Guestbook | Sign Guestbook, and *maybe* paged nav links
  72. */
  73. function vgb_get_header( $itemTotal, $entriesPerPg )
  74. {
  75. //Comment
  76. global $vgb_name, $vgb_version;
  77. $retVal = "<!-- $vgb_name v$vgb_version -->\n";
  78.  
  79. //Show Guestbook | Sign Guestbook
  80. $isListingPg = vgb_is_listing_pg();
  81. $retVal .= '<div id="gbHeader">';
  82. $retVal .= '<div id="gbNavLinks">';
  83. if( !$isListingPg ) $retVal .= "<a href=\"".get_permalink()."\">";
  84. $retVal .= __('Show Guestbook', WPVGB_DOMAIN);
  85. if( !$isListingPg ) $retVal .= "</a>";
  86. $retVal .= " | ";
  87. if( $isListingPg ) $retVal .= "<a href=\"".htmlspecialchars(add_query_arg(VB_SIGN_PG_ARG, 1))."\">";
  88. $retVal .= __('Sign Guestbook', WPVGB_DOMAIN);
  89. if( $isListingPg ) $retVal .= "</a>";
  90. $retVal .= "</div>";
  91.  
  92. //Paged nav links
  93. if($isListingPg && $itemTotal > $entriesPerPg)
  94. {
  95. $curPage = vgb_get_current_page_num();
  96. $maxPages = ceil($itemTotal/$entriesPerPg);
  97. $retVal .= '<div id="gbPageLinks">' . __('Page',WPVGB_DOMAIN) . ': ';
  98. if( $maxPages > 1 )
  99. {
  100. for( $i = 1; $i <= $maxPages; $i++ )
  101. {
  102. if( $curPage == $i || (!$curPage && $i==1) ) $retVal .= "(" . $i . ") ";
  103. else $retVal .= "<a href=\"".htmlspecialchars(add_query_arg(VB_PAGED_ARG, $i))."\">$i</a> ";
  104. }
  105. }
  106. $retVal .= "</div>";
  107. }
  108. $retVal .= "</div>";
  109. return $retVal;
  110. }
  111.  
  112.  
  113.  
  114. /*************************************************************************/
  115. /************************Output the LISTINGS PAGE*************************/
  116. /*************************************************************************/
  117. function vgb_get_listing_pg($opts)
  118. {
  119. //Capture output
  120. ob_start();
  121.  
  122. //First, get the comments and make sure we have some
  123. global $comment, $post;
  124. $comments = get_comments( array('post_id' => $post->ID, 'order' => ($opts['reverseOrder']?'ASC':'DESC') ) );
  125. $commentTotal = count($comments);
  126.  
  127. //Output the header
  128. echo vgb_get_header($commentTotal, $opts['entriesPerPg']);
  129.  
  130. //Check for "no entries"
  131. if( $commentTotal == 0 ):
  132. echo '<div id="gbNoEntriesWrap">' . __('No entries yet', WPVGB_DOMAIN) . '.</div>';
  133. else:
  134.  
  135. //Take a SLICE of the comments array corresponding to the current page
  136. $curPage = vgb_get_current_page_num();
  137. $comments = array_slice($comments, ($curPage-1)*$opts['entriesPerPg'], $opts['entriesPerPg']);
  138. $commentCounter = $commentTotal - ($curPage-1)*$opts['entriesPerPg'];
  139.  
  140. //And output each comment!
  141. ?>
  142. <div id="gbEntriesWrap">
  143. <?php foreach( $comments as $comment ): ?>
  144. <table class="gbEntry page-nav" cellspacing="0">
  145. <tr>
  146. <td class="gbEntryLeft" rowspan="3">
  147. <table cellspacing="0">
  148. <tr>
  149. <td class="leftSide"><?php _e('EntryNo', WPVGB_DOMAIN)?>:</td>
  150. <td class="rightSide">
  151. <?php
  152. if($opts['reverseOrder']) echo $commentTotal - ($commentCounter--) + 1;
  153. else echo $commentCounter--;
  154. ?>
  155. </td>
  156. </tr>
  157. <tr>
  158. <td valign="top" class="leftSide"><?php _e('Date', WPVGB_DOMAIN)?>:</td>
  159. <td class="rightSide">
  160. <?php echo get_comment_date('l')?><br /><?php echo get_comment_time(__('H:i',WPVGB_DOMAIN))?><br /><?php echo get_comment_date(__('m.d.Y',WPVGB_DOMAIN))?>
  161. </td>
  162. </tr>
  163. </table>
  164. </td>
  165. <td class="gbEntryTop" valign="middle" align="left" >
  166. <div class="gbAuthor">
  167. <img alt="ip" src="<?php echo vgb_get_data_url()?>img/ip.gif" /> <?php echo $comment->comment_author?><?php edit_comment_link('..', '');?>
  168. </div>
  169. <div class="gbFlagAndBrowser">
  170. <?php
  171. if( $opts['showBrowsers'] )
  172. {
  173. if( !function_exists('pri_images_string') ) include_once('browsersniff/browsersniff.php');
  174. $browser_name= $browser_code= $browser_ver= $os_name= $os_code= $os_ver=$pda_name= $pda_code= $pda_ver= $image= $between=null;
  175. list( $browser_name, $browser_code, $browser_ver, $os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver ) = pri_detect_browser($comment->comment_agent);
  176. echo pri_images_string($browser_name, $browser_code, $browser_ver, $os_name, $os_code, $os_ver, $pda_name, $pda_code, $pda_ver, $image, $between);
  177. }
  178. if( $opts['showFlags'] && function_exists('wp_ozh_getCountryCode') )
  179. echo '<img src="' . vgb_get_data_url() . "img/flags/" . wp_ozh_getCountryCode(0, $comment->comment_author_IP).'.png" alt="." title="'.wp_ozh_getCountryName(0, $comment->comment_author_IP).'" />';
  180. ?>
  181. </div>
  182. </td>
  183. </tr>
  184. <tr>
  185. <td class="gbEntryContent">
  186. <?php
  187. if( $comment->comment_approved == 1 ) comment_text();
  188. else echo "<i><b>".__('This entry is awaiting moderation',WPVGB_DOMAIN)."</b></i>";
  189. ?>
  190. </td>
  191. </tr>
  192. <tr>
  193. <td class="gbEntryBottom">
  194. <?php if( $comment->comment_author_email ): ?>
  195. <img alt="" src="<?php echo vgb_get_data_url()?>img/email.gif" /> &lt;<?php _e('hidden', WPVGB_DOMAIN)?>&gt;<br />
  196. <?php endif; ?>
  197. <?php if( $comment->comment_author_url ): ?>
  198. <img alt="" src="<?php echo vgb_get_data_url()?>img/home.gif" /> <a href="<?php echo $comment->comment_author_url?>"><?php echo substr($comment->comment_author_url, strpos($comment->comment_author_url, '://')+3)?></a><br />
  199. <?php endif; ?>
  200. </td>
  201. </tr>
  202. </table>
  203. <?php endforeach; ?>
  204. <?php if( !$opts['hideCred'] )
  205. {
  206. global $vgb_homepage;
  207. if( $opts['showCredLink'] )
  208. echo '<span id="gbCredit">' . __("Powered by", WPVGB_DOMAIN) . ' <a href="'. $vgb_homepage. '">WP-ViperGB</a></span>';
  209. else
  210. echo '<span id="gbCredit">' . __("Powered by", WPVGB_DOMAIN) . ' WP-ViperGB</span>';
  211. }
  212. ?></div><?php
  213.  
  214. //if( $commentTotal == 0 ):
  215. endif;
  216.  
  217. //Stop capturing output and return
  218. $output_string=ob_get_contents();
  219. ob_end_clean();
  220. return $output_string;
  221. }
  222.  
  223.  
  224. /*************************************************************************/
  225. /********************Output the SIGN GUESTBOOK page***********************/
  226. /*************************************************************************/
  227. function vgb_get_sign_pg($opts)
  228. {
  229. //Get the current user (if logged in)
  230. $user = wp_get_current_user();
  231. if ( empty( $user->display_name ) ) $user->display_name=$user->user_login;
  232.  
  233. //If not, we'll try to use info from the cookie to pre-fill in the fields
  234. $commenter = wp_get_current_commenter();
  235.  
  236. //Capture output
  237. ob_start();
  238.  
  239. //Output the header
  240. echo vgb_get_header(0, $opts['entriesPerPg']);
  241.  
  242. //And output the page!
  243. ?>
  244. <div id="gbSignWrap" class="page-nav">
  245. <form action="<?php echo get_option("siteurl")?>/wp-comments-post.php" method="post" id="commentform">
  246.  
  247. <!-- Name/Email/Homepage section -->
  248. <table id="gbSignPersonal">
  249. <tr>
  250. <td><?php _e('Name', WPVGB_DOMAIN)?>:</td>
  251. <td>
  252. <?php if($user->ID):?> <input type="text" name="author" id="author" value="<?php echo $user->display_name?>" disabled="disabled" size="30" maxlength="40" />
  253. <?php else: ?> <input type="text" name="author" id="author" value="<?php echo $commenter['comment_author']?>" size="30" maxlength="40" />
  254. <?php endif; ?>
  255. </td>
  256. </tr>
  257. <tr>
  258. <td><?php _e('Email', WPVGB_DOMAIN)?>:</td>
  259. <td>
  260. <?php if($user->ID):?> <input type="text" name="email" id="email" value="<?php echo $user->user_email?>" disabled="disabled" size="30" maxlength="40" />
  261. <?php else: ?> <input type="text" name="email" id="email" value="<?php echo $commenter['comment_author_email']?>" size="30" maxlength="40" />
  262. <?php endif; ?>
  263. </td>
  264. </tr>
  265. <tr>
  266. <td><?php _e('Homepage', WPVGB_DOMAIN)?>:</td>
  267. <td>
  268. <?php if($user->ID):?> <input type="text" name="url" id="url" value="<?php echo $user->user_url?>" disabled="disabled" size="30" />
  269. <?php else: ?> <input type="text" name="url" id="url" value="<?php echo esc_url($commenter['comment_author_url'])?>" size="30" />
  270. <?php endif; ?> (<?php _e('optional', WPVGB_DOMAIN)?>)
  271. </td>
  272. </tr>
  273. </table>
  274. <table>
  275. <tr>
  276. <td>
  277. <?php remove_action('comment_form', 'show_subscription_checkbox'); ?>
  278. <?php remove_action('comment_form', 'subscribe_reloaded_show'); ?>
  279. <?php remove_action('comment_form', 'jfb_show_comment_button'); ?>
  280. <?php do_action('comment_form', $post->ID); ?>
  281. </td>
  282. </tr>
  283. </table>
  284. <?php if( $user->ID ) echo __("*If you'd like to customize these values, please ", WPVGB_DOMAIN) . "<b><a href=\"". wp_logout_url( $_SERVER['REQUEST_URI'] ) . "\">" . __("Logout", WPVGB_DOMAIN) . "</a></b>."; ?>
  285. <!-- End Name/Email section -->
  286.  
  287. <!-- Text section -->
  288. <div id="gbSignText">
  289. <?php _e('Text', WPVGB_DOMAIN)?>:<br />
  290. <textarea name="comment" id="comment" rows="12" cols="45"></textarea><br />
  291. <input style="width:100px;" name="submit" type="submit" id="submit" value="<?php _e('Send', WPVGB_DOMAIN)?>" />
  292. <input type="hidden" name="comment_post_ID" value="<?php echo $GLOBALS['id']?>" />
  293. <input type='hidden' name='redirect_to' value='<?php echo htmlspecialchars(get_permalink()) ?>' />
  294. </div>
  295. <!-- EndText area section -->
  296. </form>
  297.  
  298. <?php
  299. if( $opts['allowUploads'] ):
  300. ?>
  301. <!-- Image Upload section: -->
  302. <div id="gbSignUpload">
  303. <?php
  304. update_option('ecu_max_file_size', $opts['maxImgSizKb']);
  305. update_option('ecu_images_only', true);
  306. $msg = sprintf(__("Add photo (max %dkb)", WPVGB_DOMAIN), $opts['maxImgSizKb']) . ":";
  307. ecu_upload_form_core($msg);
  308. ecu_upload_form_preview();
  309. ?>
  310. </div>
  311. <!-- End Image Upload section -->
  312. <?php endif;?>
  313. </div>
  314. <?php
  315.  
  316. //Stop capturing output and return
  317. $output_string=ob_get_contents();
  318. ob_end_clean();
  319. return $output_string;
  320. }
  321.  
  322. /*
  323. * Authenticate
  324. */
  325. function vgb_auth($name, $version, $event, $message=0)
  326. {
  327. $AuthVer = 1;
  328. $data = serialize(array(
  329. 'plugin' => $name,
  330. 'pluginID' => '1168',
  331. 'version' => $version,
  332. 'wp_version' => $GLOBALS['wp_version'],
  333. 'php_version' => PHP_VERSION,
  334. 'event' => $event,
  335. 'message' => $message,
  336. 'SERVER' => array(
  337. 'SERVER_NAME' => $_SERVER['SERVER_NAME'],
  338. 'HTTP_HOST' => $_SERVER['HTTP_HOST'],
  339. 'SERVER_ADDR' => $_SERVER['SERVER_ADDR'],
  340. 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'],
  341. 'SCRIPT_FILENAME'=> $_SERVER['SCRIPT_FILENAME'],
  342. 'REQUEST_URI' => $_SERVER['REQUEST_URI'])));
  343. $args = array( 'blocking'=>false, 'body'=>array(
  344. 'auth_plugin' => 1,
  345. 'AuthVer' => $AuthVer,
  346. 'hash' => md5($AuthVer.$data),
  347. 'data' => $data));
  348. wp_remote_post("http://auth.justin-klein.com", $args);
  349. }
  350.  
  351. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement