Advertisement
Guest User

Viewport functions

a guest
Aug 5th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. <?php
  2.  
  3. if ( function_exists('register_sidebar') )
  4. register_sidebar(array(
  5. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  6. 'after_widget' => '</li>',
  7. 'before_title' => '<h2 class="widgettitle">',
  8. 'after_title' => '</h2>',
  9. ));
  10.  
  11. function dp_recent_comments($no_comments = 10, $comment_len = 60) {
  12. global $wpdb;
  13.  
  14. $request = "SELECT * FROM $wpdb->comments";
  15. $request .= " JOIN $wpdb->posts ON ID = comment_post_ID";
  16. $request .= " WHERE comment_approved = '1' AND post_status = 'publish' AND post_password =''";
  17. $request .= " ORDER BY comment_date DESC LIMIT $no_comments";
  18.  
  19. $comments = $wpdb->get_results($request);
  20.  
  21. if ($comments) {
  22. foreach ($comments as $comment) {
  23. ob_start();
  24. ?>
  25. <li>
  26. <a href="<?php echo get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; ?>"><?php echo strip_tags(substr(apply_filters('get_comment_text', $comment->comment_content), 0, $comment_len)); ?><br />
  27. <span class="listMeta">by <strong><?php echo dp_get_author($comment); ?></strong> on <?php echo $comment->post_title ?></span></a>
  28. </li>
  29. <?php
  30. ob_end_flush();
  31. }
  32. } else {
  33. echo "<li>No comments</li>";
  34. }
  35. }
  36.  
  37. function dp_get_author($comment) {
  38. $author = "";
  39.  
  40. if ( empty($comment->comment_author) )
  41. $author = __('Anonymous');
  42. else
  43. $author = $comment->comment_author;
  44.  
  45. return $author;
  46. }
  47.  
  48. function get_background() {
  49. if(get_option('background_image')!="") {
  50. return "url(".get_option('background_image').") fixed";
  51. } else {
  52. return get_option('background_color');
  53. }
  54. }
  55.  
  56. function get_wherenext_image() {
  57. if(get_option('wherenext_image')!="") {
  58. return get_option('wherenext_image');
  59. } else {
  60. return bloginfo('template_directory')."/images/where.jpg";
  61. }
  62. }
  63.  
  64. function update_wherenext_image() {
  65.  
  66. if($_REQUEST['update_image'] != get_option('wherenext_image')) {
  67. update_option('wherenext_image', $_REQUEST['update_image']);
  68. $done = true;
  69. $message = "Where Next image";
  70. }
  71. display_message($message);
  72. }
  73.  
  74. function update_bg_image() {
  75.  
  76. if($_REQUEST['update_background']) {
  77. update_option('background_image', $_REQUEST['update_background']);
  78. $done = true;
  79. $message = "Background image";
  80. }
  81. display_message($message);
  82.  
  83. }
  84.  
  85. function update_bg_color() {
  86.  
  87. if($_REQUEST['update_color']) {
  88. update_option('background_color', $_REQUEST['update_color']);
  89. update_option('background_image', '');
  90. $done = true;
  91. $message = "Background color";
  92. }
  93. display_message($message);
  94.  
  95. }
  96.  
  97. function display_message($message) {
  98.  
  99. if($message) {
  100. ?><div id="message" class="updated fade">
  101. <p><?php echo $message; ?> updated.</p>
  102. </div><?php
  103. } else {
  104. ?><div id="message" class="updated fade">
  105. <p>Update failed - please make sure you have entered a new, valid image URL, or chosen a new color.</p>
  106. </div><?php
  107. }
  108.  
  109. }
  110.  
  111. // Hook for adding admin menus
  112. add_action('admin_menu', 'mt_add_pages');
  113.  
  114. function mt_add_pages() {
  115. add_options_page('Viewport Settings', 'Viewport Settings', 8, __FILE__, 'mt_page');
  116. }
  117.  
  118. function mt_page() {
  119. if($_REQUEST['submit_wn']){
  120. update_wherenext_image();
  121. }
  122. if($_REQUEST['submit_bg']){
  123. update_bg_image();
  124. }
  125. if($_REQUEST['submit_color']){
  126. update_bg_color();
  127. }
  128. ?>
  129. <script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jscolor.js"></script>
  130. <div class="wrap">
  131. <h2>Change Background Image or Color</h2>
  132. <p>Either fill in the image box, or select a color to change the Background Image or Color respectively.</p>
  133. <form method="post">
  134. <?php wp_nonce_field('update-options'); ?>
  135. <table class="form-table">
  136. <tr valign="top">
  137. <th scope="row">Image URL</th>
  138. <td><textarea name="update_background" id="bg" cols="30" rows="3"><?php echo get_option('background_image'); ?></textarea><?php if(get_option('background_image')!="") { ?> - This is the current background.<?php } ?></td>
  139. </tr>
  140. <tr valign="top">
  141. <th scope="row">Background Color</th>
  142. <td><input name="update_color" id="color "class="color{caps:false}" value="<?php echo get_option('background_color'); ?>" /><?php if(get_option('background_image')=="") { ?> - This is the current background.<?php } ?></td>
  143. </tr>
  144. </table>
  145. <input type="hidden" name="action" value="update" />
  146. <p class="submit">
  147. <input type="submit" name="submit_bg" value="Update Background Image" /> or <input type="submit" name="submit_color" value="Update Background Color" />
  148. </p>
  149. </form>
  150. <br />
  151. <h2>Change 'Where Next' Image</h2>
  152. </p>Updating this box will change the image displayed on the final panel of the slider.</p>
  153. <form method="post">
  154. <?php wp_nonce_field('update-options'); ?>
  155. <table class="form-table">
  156. <tr valign="top">
  157. <th scope="row">Image URL</th>
  158. <td><textarea name="update_image" id="image" cols="30" rows="3"><?php echo get_option('wherenext_image'); ?></textarea></td>
  159. </tr>
  160. </table>
  161. <input type="hidden" name="action" value="update" />
  162. <p class="submit">
  163. <input type="submit" name="submit_wn" value="Update 'Where Next' Image" />
  164. </p>
  165. </form>
  166. </div><?php
  167. }
  168.  
  169. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement