Advertisement
rm2773

Sliders

Jan 8th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 40.88 KB | None | 0 0
  1. <?php
  2. // avoid direct calls to this file where wp core files not present
  3. if (!function_exists ('add_action')) {
  4.     header('Status: 403 Forbidden');
  5.     header('HTTP/1.1 403 Forbidden');
  6.     exit();
  7. }
  8. // class that reperesent the complete plugin
  9. class TestimonialOptions {
  10.     function TestimonialOptions() {
  11.         // register the callback been used if options of page been submitted and needs to be processed
  12.         add_action('admin_post_save_option', array(&$this, 'on_save_changes'));
  13.         // add filter for WordPress 2.8 changed backend box system !
  14.         add_filter('screen_layout_columns', array(&$this, 'on_screen_layout_columns'), 10, 2);
  15.         // register callback for admin menu setup
  16.         add_action('admin_menu', array(&$this, 'on_admin_menu'));
  17.     }
  18.     // extend the admin menu
  19.     function on_admin_menu() {
  20.         // add our own option page, you can also add it to different sections or use your own one
  21.         add_menu_page('Testimonial Manager', "Testimonials", administrator, "testimonials", array(&$this, 'on_show_page'));
  22.         $this->_manage_page_ref = add_submenu_page('testimonials', 'Manage', 'Manage', 'administrator', 'testimonials_manage', array(&$this, 'on_manage_page'));
  23.         $this->_add_new_page_ref = add_submenu_page('testimonials', 'Add New', 'Add New', 'administrator', 'testimonials_add', array(&$this, 'on_show_page'));
  24.         $this->_settings_page_ref = add_submenu_page('testimonials', 'Settings', 'Settings', 'administrator', 'testimonials_settings', array(&$this, 'on_setting_page'));
  25.  
  26.         add_action( "admin_print_scripts-{$this->_manage_page_ref}", array( $this, 'add_admin_scripts' ) );
  27.         add_action( "admin_print_scripts-{$this->_add_new_page_ref}", array( $this, 'add_admin_scripts' ) );
  28.         add_action( "admin_print_scripts-{$this->_settings_page_ref}", array( $this, 'add_admin_scripts' ) );
  29.  
  30.         add_action( "admin_print_scripts-{$this->_add_new_page_ref}", array( $this, 'add_tinymce_scripts' ) );
  31.  
  32.         // register callback gets call prior your own page gets rendered
  33.         // $this->on_load_page();
  34.         // add_action('load-'.$this->pagehook, array(&$this, 'on_load_page'));
  35.     }
  36.     function add_admin_scripts() {
  37.         // ensure, that the needed javascripts been loaded to allow drag/drop, expand/collapse and hide/show of boxes
  38.         wp_enqueue_script('postbox');
  39.         // add_meta_box('id', 'title', 'callback', 'page', 'context', 'priority');
  40.     }
  41.     function add_tinymce_scripts() {
  42.         wp_enqueue_script('editor');
  43.         wp_enqueue_script('quicktags');
  44.  
  45.         add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
  46.     }
  47.     // for WordPress 2.8 we have to tell, that we support 2 columns !
  48.     function on_screen_layout_columns($columns, $screen) {
  49.         if ($screen == $this->pagehook) {
  50.             $columns[$this->pagehook] = 2;
  51.         }
  52.         return $columns;
  53.     }
  54.     function on_show_page() {
  55.         // add_meta_box('testimonialOption1', 'Manage Testimonials', array(&$this, 'managetestimonial'), $this->pagehook, 'normal', 'core');
  56.         add_meta_box('testimonialOption2', 'Testimonial Details', array(&$this, 'createtestimonial'), $this->pagehook, 'normal', 'core');
  57.         add_meta_box('testimonialOption3', 'Plugin Info', array(&$this, 'plugininfo'), $this->pagehook, 'side', 'core');
  58.         // add_meta_box('testimonialOption4', 'Testimonial custom css', array(&$this, 'testimonialcss'), $this->pagehook, 'normal', 'core');
  59.         add_meta_box('testimonialOption5', 'How to Use This Plugin', array(&$this, 'recommend'), $this->pagehook, 'normal', 'core');
  60.         // we need the global screen column value to beable to have a sidebar in WordPress 2.8
  61.         // global $screen_layout_columns;
  62.         $screen_layout_columns = 1;
  63.         if ($_GET['action'] == 'edit' && $_GET['msg'] != "Testimonial Edited") {
  64.             $title = 'Edit Testimonial';
  65.         } else {
  66.             $title = 'Add New Testimonial';
  67.         }
  68.  
  69.         ?>
  70. <div class="wrap">
  71. <h2><?php echo __($title); ?></h2>
  72. <div class="bordertitle"></div>
  73. <br/>
  74. <?php
  75.             if (isset($_GET['msg'])) { ?>
  76. <div class='updated'><p><strong><?php echo $_GET['msg']; ?></strong></p></div>
  77. <?php
  78.             } ?>
  79. <form action="admin-post.php" method="post" enctype="multipart/form-data">
  80. <?php wp_nonce_field('themeOptionPage'); ?>
  81. <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
  82. <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
  83. <input type="hidden" name="action" value="save_option" />
  84. <div id="poststuff" class="metabox-holder<?php echo 2 == $screen_layout_columns ? ' has-right-sidebar' : ''; ?>">
  85. <div id="side-info-column" class="inner-sidebar">
  86. <?php do_meta_boxes($this->pagehook, 'side', $data); ?>
  87. </div>
  88. <div id="post-body" class="has-sidebar">
  89. <div id="post-body-content" class="has-sidebar-content">
  90. <?php do_meta_boxes($this->pagehook, 'normal', $data); ?>
  91. <?php do_meta_boxes($this->pagehook, 'additional', $data); ?>
  92. <br/>
  93. </div>
  94. </div>
  95. <br class="clear"/>
  96. </div>
  97. </form>
  98. </div>
  99. <script type="text/javascript">
  100. //<![CDATA[
  101. jQuery(document).ready( function($) {
  102. // close postboxes that should be closed
  103. $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
  104. // postboxes setup
  105. postboxes.add_postbox_toggles('<?php echo $this->pagehook; ?>');
  106. });
  107. //]]>
  108. </script>
  109. <?php
  110.     }
  111.  
  112.     function on_manage_page() {
  113.         add_meta_box('testimonialOption5', 'How to Use This Plugin', array(&$this, 'recommend'), $this->pagehook, 'normal', 'core');
  114.         // we need the global screen column value to beable to have a sidebar in WordPress 2.8
  115.         // global $screen_layout_columns;
  116.         $screen_layout_columns = 1;
  117.         ?>
  118. <div class="wrap">
  119. <h2><?php echo __('Manage Your Testimonials'); ?></h2>
  120. <div class="bordertitle"></div>
  121. <br/>
  122. <?php
  123.             if (isset($_GET['msg'])) { ?>
  124. <div class='updated'><p><strong><?php echo $_GET['msg']; ?></strong></p></div>
  125. <?php
  126.             } ?>
  127. <form action="admin-post.php" method="post" enctype="multipart/form-data">
  128. <?php wp_nonce_field('themeOptionPage'); ?>
  129. <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
  130. <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
  131. <input type="hidden" name="action" value="save_option" />
  132. <div id="poststuff" class="metabox-holder<?php echo 2 == $screen_layout_columns ? ' has-right-sidebar' : ''; ?>">
  133. <div id="side-info-column" class="inner-sidebar"></div>
  134. <div id="post-body" class="has-sidebar">
  135. <div id="post-body-content" class="has-sidebar-content">
  136. <?php echo $this->managetestimonial(); ?>
  137. <?php do_meta_boxes($this->pagehook, 'normal', $data); ?>
  138. <br/>
  139. </div>
  140. </div>
  141. <br class="clear"/>
  142. </div>
  143. </form>
  144. </div>
  145. <script type="text/javascript">
  146. //<![CDATA[
  147. jQuery(document).ready( function($) {
  148. // close postboxes that should be closed
  149. $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
  150. // postboxes setup
  151. postboxes.add_postbox_toggles('<?php echo $this->pagehook; ?>');
  152. $(".checkall").click(function() {
  153.  
  154. var checked_status = this.checked;
  155. $(".tobedeleted").each(function() {
  156. this.checked = checked_status;
  157. });
  158. });
  159. });
  160. //]]>
  161. </script>
  162. <?php
  163.     }
  164.    
  165.     function on_setting_page() {
  166.         add_meta_box('testimonialOption3', 'Plugin Info', array(&$this, 'plugininfo'), $this->pagehook, 'side', 'core');
  167.         add_meta_box('testimonialOption4', 'CSS &amp; Settings', array(&$this, 'testimonialcss'), $this->pagehook, 'normal', 'core');
  168.         add_meta_box('testimonialOption5', 'How to Use This Plugin', array(&$this, 'recommend'), $this->pagehook, 'normal', 'core');
  169.         // we need the global screen column value to beable to have a sidebar in WordPress 2.8
  170.         // global $screen_layout_columns;
  171.         $screen_layout_columns = 1;
  172.         ?>
  173. <div class="wrap">
  174. <h2><?php echo __('Testimonial Manager Settings'); ?></h2>
  175. <div class="bordertitle"></div>
  176. <br/>
  177. <?php
  178.             if (isset($_GET['msg'])) { ?>
  179. <div class='updated'><p><strong><?php echo $_GET['msg']; ?></strong></p></div>
  180. <?php
  181.             } ?>
  182. <form action="admin-post.php" method="post" enctype="multipart/form-data">
  183. <?php wp_nonce_field('themeOptionPage'); ?>
  184. <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
  185. <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
  186. <input type="hidden" name="action" value="save_option" />
  187. <div id="poststuff" class="metabox-holder<?php echo 2 == $screen_layout_columns ? ' has-right-sidebar' : ''; ?>">
  188. <div id="side-info-column" class="inner-sidebar">
  189. <?php do_meta_boxes($this->pagehook, 'side', $data); ?>
  190. </div>
  191. <div id="post-body" class="has-sidebar">
  192. <div id="post-body-content" class="has-sidebar-content">
  193. <?php do_meta_boxes($this->pagehook, 'normal', $data); ?>
  194. <?php do_meta_boxes($this->pagehook, 'additional', $data); ?>
  195. <br/>
  196. </div>
  197. </div>
  198. <br class="clear"/>
  199. </div>
  200. </form>
  201. </div>
  202. <script type="text/javascript">
  203. //<![CDATA[
  204. jQuery(document).ready( function($) {
  205. // close postboxes that should be closed
  206. $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
  207. // postboxes setup
  208. postboxes.add_postbox_toggles('<?php echo $this->pagehook; ?>');
  209.  
  210. });
  211. //]]>
  212. </script>
  213. <?php
  214.     }
  215.  
  216.     function on_save_changes() {
  217.         if ($_POST['doaction'] == 'Apply') {
  218.             $data = get_option('testimonials_manager');
  219.             if (!empty($_POST['delete_comments'])) {
  220.                 foreach ($_POST['delete_comments'] as $arr) {
  221.                     unset($data['data'][$arr]);
  222.                 }
  223.  
  224.                 $data['data'] = array_values($data['data']);
  225.                 update_option('testimonials_manager', $data);
  226.             }
  227.         }
  228.        
  229.         // die();
  230.         if (isset($_POST['CreateTestimonial'])) {
  231.             $data = get_option('testimonials_manager');
  232.  
  233.             $inputdata['name'] = stripslashes($_POST['name']);
  234.             $inputdata['title'] = stripslashes($_POST['title']);
  235.             $inputdata['company_name'] = stripslashes($_POST['company_name']);
  236.             $inputdata['company'] = stripslashes($_POST['company']);
  237.             $inputdata['url'] = stripslashes($_POST['url']);
  238.             $inputdata['text'] = stripslashes($_POST['text']);
  239.             $inputdata['avatar'] = stripslashes($_POST['avatar']);
  240.             $inputdata['email'] = stripslashes($_POST['email']);
  241.             if ($_FILES['own_avatar']['name'] != "") {
  242.                 $overrides = array('test_form' => false);
  243.                 $file = wp_handle_upload($_FILES['own_avatar'], $overrides);
  244.  
  245.                 if (isset($file['error']))
  246.                     die($file['error']);
  247.  
  248.                 $url = $file['url'];
  249.                 $type = $file['type'];
  250.                 $file = $file['file'];
  251.                 $filename = basename($file);
  252.  
  253.                 // Construct the object array
  254.                 $object = array(
  255.                         'post_title' => $filename,
  256.                         'post_content' => $url,
  257.                         'post_mime_type' => $type,
  258.                         'guid' => $url);
  259.  
  260.                 $inputdata['own_avatar'] = $url.$filename;
  261.  
  262.                 // Save the data
  263.                 $id = wp_insert_attachment($object, $file);
  264.  
  265.                 list($width, $height, $type, $attr) = getimagesize($file);
  266.  
  267.                 if ($width == $data['imagex'] && $height == $data['imagey']) {
  268.                     $inputdata['own_avatar'] = $url;
  269.                 } elseif ($width > $data['imagex']) {
  270.                     $image = image_resize($file, $data['imagex'], $data['imagey'], true, 't', null, 100);
  271.                     $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
  272.                     $url = str_replace(basename($url), basename($image), $url);
  273.                     $inputdata['own_avatar'] = $url;
  274.                 } else {
  275.                     $oitar = 1;
  276.                 }
  277.  
  278.                
  279.             }
  280.  
  281.             if ($inputdata['own_avatar'] == "") {
  282.                 $inputdata['own_avatar'] = $data['data'][$previous_test_id]['own_avatar'];
  283.             }
  284.  
  285.  
  286.             $data['data'][] = $inputdata;
  287.             if ($_POST['avatar']=='own_pic' AND (empty($_FILES['own_avatar']['name']))) {
  288.                 $alert = urlencode('Picture not specified. Press back to try again');
  289.             } elseif ($_POST['avatar']=='gravatar' AND (empty($_POST['email']))) {
  290.                 $alert = urlencode('No personal Gravatar specified. Press back to try again');
  291.             } elseif (empty($inputdata['name'])) {
  292.                 $alert = urlencode('Name not specified. Press back to try again');
  293.             } elseif (empty($inputdata['text'])) {
  294.                 $alert = urlencode('No testimonial entered. Press back to try again');
  295.             } else {
  296.                 update_option('testimonials_manager', $data);
  297.                 $alert = urlencode("New Testimonial Created.");
  298.             }
  299.         }
  300.  
  301.         if (isset($_POST['EditTestimonial'])) {
  302.             $_POST['_wp_http_referer'] = str_replace('testimonials_add','testimonials_manage',$_POST['_wp_http_referer']);
  303.             $data = get_option('testimonials_manager');
  304.             $previous_test_id = $_POST['previous_test_id'];
  305.  
  306.             $inputdata['name'] = stripslashes($_POST['name']);
  307.             $inputdata['title'] = stripslashes($_POST['title']);
  308.             $inputdata['company_name'] = stripslashes($_POST['company_name']);
  309.             $inputdata['company'] = stripslashes($_POST['company']);
  310.             $inputdata['url'] = stripslashes($_POST['url']);
  311.             $inputdata['text'] = stripslashes($_POST['text']);
  312.             $inputdata['avatar'] = stripslashes($_POST['avatar']);
  313.             $inputdata['email'] = stripslashes($_POST['email']);
  314.  
  315.  
  316.             if ($_FILES['own_avatar']['name'] != "") {
  317.                 $overrides = array('test_form' => false);
  318.                 $file = wp_handle_upload($_FILES['own_avatar'], $overrides);
  319.  
  320.                 if (isset($file['error']))
  321.                     die($file['error']);
  322.  
  323.                 $url = $file['url'];
  324.                 $type = $file['type'];
  325.                 $file = $file['file'];
  326.                 $filename = basename($file);
  327.                 // Construct the object array
  328.                 $object = array(
  329.                         'post_title' => $filename,
  330.                         'post_content' => $url,
  331.                         'post_mime_type' => $type,
  332.                         'guid' => $url);
  333.  
  334.                 $inputdata['own_avatar'] = $url.$filename;
  335.                 // Save the data
  336.                 $id = wp_insert_attachment($object, $file);
  337.  
  338.                 list($width, $height, $type, $attr) = getimagesize($file);
  339.  
  340.                 if ($width == $data['imagex'] && $height == $data['imagey']) {
  341.                     $inputdata['own_avatar'] = $url;
  342.                 } elseif ($width > $data['imagex']) {
  343.                     $image = image_resize($file, $data['imagex'], $data['imagey'], true, 't', null, 100);
  344.                     $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
  345.                     $url = str_replace(basename($url), basename($image), $url);
  346.                     $inputdata['own_avatar'] = $url;
  347.                 } else {
  348.                     $oitar = 1;
  349.                 }
  350.  
  351.              
  352.             }
  353.  
  354.  
  355.             if ($inputdata['own_avatar'] == "") {
  356.                 $inputdata['own_avatar'] = $data['data'][$previous_test_id]['own_avatar'];
  357.             }
  358.  
  359.  
  360.             $data['data'][$previous_test_id] = $inputdata;
  361.             if ($_POST['avatar']=='own_pic' AND (empty($_FILES['own_avatar']['name'])) AND ($inputdata['own_avatar']=='')) {
  362.                 $alert = urlencode('Picture not specified. Press back to try again');
  363.             } elseif ($_POST['avatar']=='gravatar' AND (empty($_POST['email']))) {
  364.                 $alert = urlencode('No personal Gravatar specified. Press back to try again');
  365.             } elseif (empty($inputdata['name'])) {
  366.                 $alert = urlencode('Name not specified. Press back to try again');
  367.  
  368.             } elseif (empty($inputdata['text'])) {
  369.                 $alert = urlencode('No testimonial entered. Press back to try again');
  370.             } else {
  371.                 update_option('testimonials_manager', $data);
  372.                 $alert = urlencode("Testimonial Edited");
  373.             }
  374.         }
  375.  
  376.         if (isset($_POST['btnDeleteTestimonial'])) {
  377.             $id = array_keys($_POST['btnDeleteTestimonial']);
  378.             $data = get_option('testimonials_manager');
  379.  
  380.             unset($data['data'][$id[0]]);
  381.             $data['data'] = array_values($data['data']);
  382.  
  383.             update_option('testimonials_manager', $data);
  384.             $alert = urlencode("Testimonial Deleted");
  385.         }
  386.  
  387.         if (isset($_POST['CreateCustomCSS'])) {
  388.             $data = get_option('testimonials_manager');
  389.             $data['customcss'] = stripslashes($_POST['css']);
  390.             $data['imagex'] = stripslashes($_POST['imagex']);
  391.             $data['imagey'] = stripslashes($_POST['imagey']);
  392.             $data['dorder'] = stripslashes($_POST['dorder']);
  393.             $data['items'] = stripslashes($_POST['items']);
  394.             update_option('testimonials_manager', $data);
  395.             $alert = urlencode("Custom CSS Saved");
  396.         }
  397.  
  398.         if (isset($_POST['recommendButton'])) {
  399.             $data = get_option('testimonials_manager');
  400.             $data['recommend'] = stripslashes($_POST['recommend']);
  401.             update_option('testimonials_manager', $data);
  402.             $alert = urlencode("Plugin Updated");
  403.         }
  404.  
  405.         $params = array('msg' => $alert);
  406.         wp_redirect(add_query_arg($params, $_POST['_wp_http_referer']));
  407.     }
  408.    
  409.     function managetestimonial() {
  410.         $x = 0;
  411.         $data = get_option('testimonials_manager');
  412.         if (($_GET['action'] == 'delete')) {
  413.             $id = ($_GET['testimonial_id']);
  414.             $data = get_option('testimonials_manager');
  415.             unset($data['data'][$id]);
  416.             $data['data'] = array_values($data['data']);
  417.  
  418.             update_option('testimonials_manager', $data);
  419.             echo "Testimonial Deleted<br/>";
  420.         }
  421.  
  422.         $testimonialboxcount = count($data['data']);
  423.  
  424.         $p = new testimonial_pagination;
  425.  
  426.         $p->items($testimonialboxcount);
  427.  
  428.         $p->limit(25);
  429.         if (empty($_GET['pg'])) {
  430.             $page = 1;
  431.         } else {
  432.             $page = $_GET['pg'];
  433.         }
  434.         $p->currentPage($page);
  435.         $p->target('admin.php?page=testimonials_manage');
  436.  
  437.         ?>
  438. <div class="tablenav">
  439. <div class='tablenav-pages'>
  440. <?php
  441.                  echo $p->show();
  442.                  // Echo out the list of paging. ?>
  443.             </div>
  444.             <div class = "alignleft actions" > <select name = "act" > <option value = "-1" selected = "selected" > Bulk Actions</option > <option value = "trash" > Delete</option >
  445. </select > <input type = "submit" name = "doaction" id = "doaction" value = "Apply" class = "button-secondary apply" / >
  446. </div><br class = "clear" / >
  447. </div >
  448. <?php
  449. // print_r($data);
  450. if ($testimonialboxcount > 25) {
  451. $testimonialboxcount = 25;
  452. // now to make the array smaller
  453. $newarray = array_slice($data['data'], ($page - 1) * 25, 25);
  454. $data['data'] = $newarray;
  455. $testimonialboxcount = count($newarray);
  456. }
  457. ?>
  458. <table class="widefat" cellspacing="0">
  459. <thead>
  460. <tr>
  461. <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" class="checkall"/></th>
  462. <th scope="col" width="250px">Name</th>
  463. <th scope="col">Testimonial</th>
  464. </tr>
  465. </thead>
  466. <tfoot>
  467. <tr>
  468. <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" class="checkall" /></th>
  469. <th scope="col">Name</th>
  470. <th scope="col">Testimonial</th>
  471. </tr>
  472. </tfoot>
  473. <tbody>
  474. <?php
  475. if ($testimonialboxcount == 0) {
  476. ?>
  477. <tr style="background:#eeeeee;">
  478.                         <td colspan="3" align="center"><strong>No testimonial yet, add one below.</strong></td>
  479.                     </tr>
  480.                 <?php
  481.                 } else {
  482.                     while ($x <$testimonialboxcount) {
  483.                         $num = $x;
  484.                         $num = $num + 1 + ($page - 1) * 25;
  485.                         $url = $data['data'][$x]['url'];
  486.                         if (substr($url, 0, 7) != 'http://') {
  487.                             $url = 'http://' . $url;
  488.                         }
  489.                         if ($data['data'][$x]['avatar']) {
  490.                             if ($data['data'][$x]['avatar'] == "gravatar") {
  491.                                 $av = get_avatar($data['data'][$x]['email'], 48);
  492.                             } else {
  493.                                 $av = '<img src="' . $data['data'][$x]['own_avatar'] . '" class="avatar" alt="avatar" width="48" height="48" />';
  494.                             }
  495.                         }
  496.                         ?>
  497. <tr>
  498. <td align="center" valign="top"><input type='checkbox' name='delete_comments[]' class="tobedeleted" value='<?php echo($num - 1); ?>' /></td>
  499. <td class="author column-author">
  500. <strong><?php echo $av ?> <?php echo $data['data'][$x]['name'] ?></strong><br>
  501. <?php echo $data['data'][$x]['company']; ?><br/>
  502. <a href="<?php echo $url; ?>"><?php echo $data['data'][$x]['url']; ?></a>
  503. </td>
  504. <td align="" valign="top"><?php echo $data['data'][$x]['text']; ?>
  505. <div class="row-actions"><span class='edit'><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=testimonials_add&action=edit&testimonial_id=<?php echo ($num - 1);?>" title="Edit this post">Edit</a> | </span><!-- <span class='inline hide-if-no-js'><a href="#" class="editinline" title="Edit this post inline">Quick&nbsp;Edit</a> | </span> --><span class='trash'><a class='submitdelete' title='Move this post to the Trash' href='<?php echo $_SERVER['PHP_SELF']; ?>?page=testimonials_manage&action=delete&testimonial_id=<?php echo ($num - 1);?>'>Delete</a> </span></div>
  506. </td>
  507. </tr>
  508. <?php
  509.                         $x++;
  510.                     }
  511.                 }?>
  512. </tbody>
  513. </table>
  514. <div class="tablenav">
  515. <div class='tablenav-pages'>
  516. <?php echo $p->show(); // Echo out the list of paging. ?>
  517.             </div>
  518.             <div class = "alignleft actions" > <select name = "act" > <option value = "-1" selected = "selected" > Bulk Actions</option > <option value = "trash" > Delete</option >
  519. </select ><input type = "submit" name = "doaction" id = "doaction" value = "Apply" class = "button-secondary apply" / >
  520. </div><br class = "clear" / >
  521. </div>
  522. <br />
  523. <br />
  524. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=testimonials_add" class="button-primary">Add New Testimonial</a>
  525. <br />
  526. <br />
  527. <?php
  528.     }
  529.     function createTestimonial($title) {
  530.         $data = get_option('testimonials_manager');
  531.     ?>
  532. <a name="addnewTestimonial"></a>
  533. <table border="0" width="100%" cellspacing="20">
  534. <tr>
  535. <td width="16%" align="right" valign="top" >
  536. <label for="avatar"><strong>Image:</strong></label>
  537. </td>
  538. <td width="84%">
  539. <?php
  540.                     if ($_GET['action'] == 'edit' && $_GET['msg'] != "Testimonial Edited") {
  541.                         $data = get_option('testimonials_manager');
  542.                         $testcount = count($data);
  543.                         $test = $data['data'][$_GET['testimonial_id']];
  544.                     }
  545.                     ?>
  546. <input type="radio" name="avatar" onclick="document.getElementById('email').style.display = 'block'; document.getElementById('picture_upload').style.display = 'none';" value="gravatar" <?php if ($test['avatar'] == "gravatar") { echo "checked"; } ?> />Use Gravatar
  547. <input type="radio" name="avatar" onclick="document.getElementById('picture_upload').style.display = 'block'; document.getElementById('email').style.display = 'none';" value="own_pic" <?php if ($test['avatar'] == "own_pic") { echo "checked";} ?> /> Upload picture
  548. <input type="radio" name="avatar" onclick="document.getElementById('email').style.display = 'none'; document.getElementById('picture_upload').style.display = 'none';" value="" <?php if ($test['avatar'] == "") { echo "checked"; }?> /> No Image
  549. <br />
  550. <div id="email" style="display:<?php if ($test['avatar'] == "gravatar") { echo "block"; } else { echo "none";} ?>; padding:10px 30px; background:#f4f4f4;">
  551. <strong>E-Mail:</strong><br /><br />
  552. <input name="email" type="text" style="width:100%" value="<?php if ($_GET['action'] == 'edit' && $test['avatar'] != "own_pic") { echo $test['email']; }?>" /><br />
  553. <small>Please enter the gravatar e-mail</small>
  554. </div>
  555. <div id="picture_upload" style="display:<?php if ($test['avatar'] == "own_pic") { echo "block"; } else { echo "none"; }?>; padding:10px 30px; background:#f4f4f4;">
  556. <strong>Upload picture:</strong><br /><br />
  557. <input name="own_avatar" type="file" style="width:100%" /><br />
  558. <small>Picture will be resized to <?php echo $data['imagex'];?>x<?php echo $data['imagey'];?> pixels</small>
  559. <?php
  560.                         if ($_GET['action'] == 'edit') {
  561.                             if ($test['own_avatar'] != "") { ?>
  562. <br /><br />
  563. <?php
  564.                                 if ($test['avatar'] != "gravatar") { ?>
  565. <strong>Current Image:</strong><br /><br /><img src="<?php echo $test['own_avatar']; ?>" alt="avatar" width="48" height="48"/>
  566. <?php
  567.                                 }
  568.                             }
  569.                         }
  570.                         ?>
  571. </div>
  572. </td>
  573. </tr>
  574. <tr>
  575. <td width="16%" align="right" valign="top" >
  576. <label for="name"><strong>Name:</strong></label>
  577. </td>
  578. <td width="84%">
  579. <input type="text" name="name" value="<?php if ($_GET['action'] == 'edit') { echo $test['name']; } ?>" style="width:100%;" />
  580. </td>
  581. </tr>
  582. <tr>
  583. <td width="16%" align="right" valign="top" >
  584. <label for="title"><strong>Title:</strong></label>
  585. </td>
  586. <td width="84%">
  587. <input type="text" name="title" value="<?php if ($_GET['action'] == 'edit') { echo $test['title']; } ?>" style="width:100%;" />
  588. </td>
  589. </tr>
  590. <tr>
  591. <td width="16%" align="right" valign="top" >
  592. <label for="company_name"><strong>Company Name:</strong></label>
  593. </td>
  594. <td width="84%">
  595. <input type="text" name="company_name" value="<?php if ($_GET['action'] == 'edit') { echo $test['company_name']; } ?>" style="width:100%;" />
  596. </td>
  597. </tr>
  598. <tr>
  599. <td width="16%" align="right" valign="top" >
  600. <label for="company"><strong>Website Name:</strong></label>
  601. </td>
  602. <td width="84%">
  603. <input type="text" name="company" value="<?php if ($_GET['action'] == 'edit') { echo $test['company'];} ?>" style="width:100%;" />
  604. </td>
  605. </tr>
  606. <tr>
  607. <td width="16%" align="right" valign="top" >
  608. <label for="url"><strong>Website URL:</strong></label>
  609. </td>
  610. <td width="84%">
  611. <input type="text" name="url" value="<?php if ($_GET['action'] == 'edit') { echo $test['url'];}?>" style="width:100%;" />
  612. </td>
  613. </tr>
  614. <tr>
  615. <td width="16%" align="right" valign="top"><label for="text"><strong>Testimonial:</strong></label><br></td>
  616. <td width="84%">
  617. <?php the_editor($test['text'], 'text', '', false, 4); ?>
  618. </td>
  619. </tr>
  620. </table>
  621. <p style="text-align:right;">
  622. <?php
  623.             if ($_GET['action'] == 'edit') { ?>
  624. <input type="hidden" name="previous_test_id" value="<?php echo $_GET['testimonial_id'] ?>" />
  625. <input type="submit" value="Update Testimonial" class="button-primary" name="EditTestimonial"/>
  626. <?php
  627.             } else { ?>
  628. <input type="submit" value="Create Testimonial" class="button-primary" name="CreateTestimonial"/>
  629. <?php
  630.             } ?>
  631. <br/>
  632. </p>
  633. <style>#text {width:100%} </style>
  634. <?php
  635.     }
  636.  
  637.     function plugininfo() {?>
  638. <table width="100%" border="0" cellspacing="4">
  639. <tr>
  640. <td width="80px" valign="top">Plugin Name:</td>
  641. <td valign="top">Testimonials Manager</td>
  642. </tr>
  643. <tr>
  644. <td valign="top">Version:</td>
  645. <td valign="top"> 2.0</td>
  646. </tr>
  647. <tr>
  648. <td valign="top">Author:</td>
  649. <td valign="top"> Gobala Krishnan</td>
  650. </tr>
  651. <tr>
  652. <td valign="top">Description:</td>
  653. <td valign="top">Manage and display testimonials for your blog, product or service.</td>
  654. </tr>
  655. <tr>
  656. <td align="center" colspan="2">
  657. <br/>
  658. <input type="submit" value="Update" class="button-primary" name="recommendButton"/>
  659. <br/><br/>
  660. </td>
  661. </tr>
  662. </table>
  663. <?php
  664.     }
  665.  
  666.     function testimonialcss() {
  667.         $data = get_option('testimonials_manager');
  668.         // print_r($data);
  669.         if (empty($data['imagex'])) {
  670.             $data['imagex'] = 48;
  671.         }
  672.         if (empty($data['imagey'])) {
  673.             $data['imagey'] = 48;
  674.         }
  675.         if (empty($data['dorder'])) {
  676.             $data['dorder'] = 'asc';
  677.         }
  678.         if (empty($data['items'])) {
  679.             $data['items'] = 10;
  680.         }
  681.         ?>
  682.  
  683. <table border="0" width="100%" cellspacing="20">
  684. <tr>
  685. <td width="16%" align="right" valign="top"><label for="css"><strong>Custom CSS:</strong></label><br></td>
  686. <td width="84%">
  687. <textarea name="css" style="width:100%; height:200px;">
  688. <?php
  689.                         if (!isset($data['customcss']) || $data['customcss'] == "") {
  690.                             echo <<<EOF
  691. .testimonial{
  692. margin: 10px 0;
  693. padding:10px;
  694. border: 1px dotted #f4f4f4;
  695. background: #dddddd;
  696. }
  697.  
  698. .testimonial .avatar {
  699. background:#FFFFFF none repeat scroll 0 0;
  700. border:1px solid #DDDDDD;
  701. float:right;
  702. margin-right:-5px;
  703. margin-top:-5px;
  704. padding:2px;
  705. position:relative;
  706. }
  707.  
  708. div.pagination {
  709. padding: 3px;
  710. margin: 3px;
  711. text-align:center;
  712. }
  713.  
  714. div.pagination a {
  715. border: 1px solid #dedfde;
  716. margin-right:3px;
  717. padding:2px 6px;
  718.  
  719. background-position:bottom;
  720. text-decoration: none;
  721.  
  722. color: #0061de;
  723. }
  724. div.pagination a:hover, div.meneame a:active {
  725. border: 1px solid #000;
  726. background-image:none;
  727. background-color:#0061de;
  728. color: #fff;
  729. }
  730. div.pagination span.current {
  731. margin-right:3px;
  732. padding:2px 6px;
  733.  
  734. font-weight: bold;
  735. color: #ff0084;
  736. }
  737. div.pagination span.disabled {
  738. margin-right:3px;
  739. padding:2px 6px;
  740.  
  741. color: #adaaad;
  742. }
  743. EOF;
  744.                         } else {
  745.                             echo $data['customcss'];
  746.                         } ?>
  747. </textarea>
  748. <small>Enter your custom CSS here.</small>
  749. </td>
  750. </tr>
  751. <tr>
  752. <td width="16%" align="right" valign="top"><label for="imagesize"><strong>Image Size</strong></label><br></td>
  753. <td width="84%">
  754. <input name="imagex" value="<?php echo $data['imagex'] ?>" size="2"/> x <input name="imagey" value="<?php echo $data['imagey'] ?>" size="2"/> pixels
  755. </td>
  756. </tr>
  757. <tr>
  758. <td width="16%" align="right" valign="top"><label for="dorder"><strong>Display Order</strong></label><br></td>
  759. <td width="84%">
  760. <select name="dorder">
  761. <option value="asc">Ascending</option>
  762. <option value="desc">Descending</option>
  763. </select>
  764. </td>
  765. </tr>
  766. <tr>
  767. <td width="16%" align="right" valign="top"><label for="items"><strong>Items Per Page</strong></label><br></td>
  768. <td width="84%">
  769. <input name="items" value="<?php echo $data['items'] ?>" />
  770. </td>
  771. </tr>
  772. </table>
  773. <p style="text-align:right;">
  774. <input type="submit" value="Save Settings" class="button-primary" name="CreateCustomCSS"/>
  775. <br/>
  776. </p>
  777. <?php
  778.     }
  779.  
  780.     function recommend() {
  781.         $data = get_option('testimonials_manager');
  782.         ?>
  783. <table border="0" width="100%" cellspacing="20">
  784. <tr>
  785. <td>
  786. <p style="font-size:13px;">Just enter new testimonials on this page. You can either display user images from <a href="http://www.gravatar.com">Gravatar.com</a> or upload your own images.</p>
  787. <p style="font-size:13px;">A new testimonials page has been created for you for the first time user, or you can also create your own page and paste the following code to display your testimonials:<br /><br />[show_testimonials]<br /><br /></p>
  788. <p style="font-size:13px;">To rotate testimonials in your sidebar, use the testimonials widget.</p>
  789. <p style="font-size:13px;">You can customize the appearance of the testimonials on your testimonials page as well as the sidebar using the Custom CSS box.</p>
  790. </td>
  791. </tr>
  792. </table>
  793. <?php
  794.     }
  795. }
  796.  
  797. $TestimonialOptions = new TestimonialOptions();
  798.  
  799. class testimonial_pagination {
  800.     /*
  801. Script Name: *Digg Style Paginator Class
  802. Script URI: http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/
  803. Description: Class in PHP that allows to use a pagination like a digg or sabrosus style.
  804. Script Version: 0.4
  805. Author: Victor De la Rocha
  806. Author URI: http://www.mis-algoritmos.com
  807. */
  808.     /*Default values*/
  809.     var $total_pages = - 1; //items
  810.     var $limit = null;
  811.     var $target = "";
  812.     var $page = 1;
  813.     var $adjacents = 2;
  814.     var $showCounter = false;
  815.     var $className = "testimonial_pagination";
  816.     var $parameterName = "pg";
  817.     var $urlF = false; //urlFriendly
  818.     /*Buttons next and previous*/
  819.     var $nextT = "Next";
  820.     var $nextI = "&#187;"; //&#9658;
  821.     var $prevT = "Previous";
  822.     var $prevI = "&#171;"; //&#9668;
  823.  
  824.     var $calculate = false;
  825.     // Total items
  826.     function items($value) {
  827.         $this->total_pages = (int) $value;
  828.     }
  829.     // how many items to show per page
  830.     function limit($value) {
  831.         $this->limit = (int) $value;
  832.     }
  833.     // Page to sent the page value
  834.     function target($value) {
  835.         $this->target = $value;
  836.     }
  837.     // Current page
  838.     function currentPage($value) {
  839.         $this->page = (int) $value;
  840.     }
  841.     // How many adjacent pages should be shown on each side of the current page?
  842.     function adjacents($value) {
  843.         $this->adjacents = (int) $value;
  844.     }
  845.     // show counter?
  846.     function showCounter($value = "") {
  847.         $this->showCounter = ($value === true)?true:false;
  848.     }
  849.     // to change the class name of the pagination div
  850.     function changeClass($value = "") {
  851.         $this->className = $value;
  852.     }
  853.  
  854.     function nextLabel($value) {
  855.         $this->nextT = $value;
  856.     }
  857.     function nextIcon($value) {
  858.         $this->nextI = $value;
  859.     }
  860.     function prevLabel($value) {
  861.         $this->prevT = $value;
  862.     }
  863.     function prevIcon($value) {
  864.         $this->prevI = $value;
  865.     }
  866.     // to change the class name of the pagination div
  867.     function parameterName($value = "") {
  868.         $this->parameterName = $value;
  869.     }
  870.     // to change urlFriendly
  871.     function urlFriendly($value = "%") {
  872.         if (eregi('^ *$', $value)) {
  873.             $this->urlF = false;
  874.             return false;
  875.         }
  876.         $this->urlF = $value;
  877.     }
  878.  
  879.     var $pagination;
  880.     function pagination() {
  881.     }
  882.     function show() {
  883.         if (!$this->calculate) {
  884.             if ($this->calculate()) {
  885.                 echo "<div class=\"$this->className\">$this->pagination</div>\n";
  886.             }
  887.         }
  888.     }
  889.     function getOutput() {
  890.         if (!$this->calculate) {
  891.             if ($this->calculate()) {
  892.                 return "<div class=\"$this->className\">$this->pagination</div>\n";
  893.             }
  894.         }
  895.     }
  896.     function get_pagenum_link($id) {
  897.         if (strpos($this->target, '?') === false)
  898.             if ($this->urlF)
  899.                 return str_replace($this->urlF, $id, $this->target);
  900.             else
  901.                 return "$this->target?$this->parameterName=$id";
  902.         else
  903.             return "$this->target&$this->parameterName=$id";
  904.     }
  905.  
  906.     function calculate() {
  907.         $this->pagination = "";
  908.         $this->calculate == true;
  909.         $error = false;
  910.         if ($this->urlF and $this->urlF != '%' and strpos($this->target, $this->urlF) === false) {
  911.             // Es necesario especificar el comodin para sustituir
  912.             echo "Especificaste un wildcard para sustituir, pero no existe en el target<br />";
  913.             $error = true;
  914.         } elseif ($this->urlF and $this->urlF == '%' and strpos($this->target, $this->urlF) === false) {
  915.             echo "Es necesario especificar en el target el comodin % para sustituir el n?mero de p?gina<br />";
  916.             $error = true;
  917.         }
  918.  
  919.         if ($this->total_pages <0) {
  920.             echo "It is necessary to specify the <strong>number of pages</strong> (\$class->items(1000))<br />";
  921.             $error = true;
  922.         }
  923.         if ($this->limit == null) {
  924.             echo "It is necessary to specify the <strong>limit of items</strong> to show per page (\$class->limit(10))<br />";
  925.             $error = true;
  926.         }
  927.         if ($error)return false;
  928.  
  929.         $n = trim($this->nextT . ' ' . $this->nextI);
  930.         $p = trim($this->prevI . ' ' . $this->prevT);
  931.  
  932.         /* Setup vars for query. */
  933.         if ($this->page)
  934.             $start = ($this->page - 1) * $this->limit; //first item to display on this page
  935.         else
  936.             $start = 0; //if no page var is given, set start to 0
  937.         /* Setup page vars for display. */
  938.         $prev = $this->page - 1; //previous page is page - 1
  939.         $next = $this->page + 1; //next page is page + 1
  940.         $lastpage = ceil($this->total_pages / $this->limit); //lastpage is = total pages / items per page, rounded up.
  941.         $lpm1 = $lastpage - 1; //last page minus 1
  942.         /*
  943. Now we apply our rules and draw the pagination object.
  944. We're actually saving the code to a variable in case we want to draw it more than once.
  945. */
  946.  
  947.         if ($lastpage > 1) {
  948.             if ($this->page) {
  949.                 // anterior button
  950.                 if ($this->page > 1)
  951.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link($prev) . "\" class=\"prev\">$p</a>";
  952.                 else
  953.                     $this->pagination .= "<span class=\"disabled\">$p</span>";
  954.             }
  955.             // pages
  956.             if ($lastpage <7 + ($this->adjacents * 2)) { // not enough pages to bother breaking it up
  957.                 for ($counter = 1; $counter <= $lastpage; $counter++) {
  958.                     if ($counter == $this->page)
  959.                         $this->pagination .= "<span class=\"current\">$counter</span>";
  960.                     else
  961.                         $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
  962.                 }
  963.             } elseif ($lastpage > 5 + ($this->adjacents * 2)) { // enough pages to hide some
  964.                 // close to beginning; only hide later pages
  965.                 if ($this->page <1 + ($this->adjacents * 2)) {
  966.                     for ($counter = 1; $counter <4 + ($this->adjacents * 2); $counter++) {
  967.                         if ($counter == $this->page)
  968.                             $this->pagination .= "<span class=\"current\">$counter</span>";
  969.                         else
  970.                             $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
  971.                     }
  972.                     $this->pagination .= "...";
  973.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lpm1) . "\">$lpm1</a>";
  974.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lastpage) . "\">$lastpage</a>";
  975.                 }
  976.                 // in middle; hide some front and some back
  977.                 elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) {
  978.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link(1) . "\">1</a>";
  979.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link(2) . "\">2</a>";
  980.                     $this->pagination .= "...";
  981.                     for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++)
  982.                         if ($counter == $this->page)
  983.                             $this->pagination .= "<span class=\"current\">$counter</span>";
  984.                         else
  985.                             $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
  986.                     $this->pagination .= "...";
  987.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lpm1) . "\">$lpm1</a>";
  988.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link($lastpage) . "\">$lastpage</a>";
  989.                 }
  990.                 // close to end; only hide early pages
  991.                 else {
  992.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link(1) . "\">1</a>";
  993.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link(2) . "\">2</a>";
  994.                     $this->pagination .= "...";
  995.                     for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++)
  996.                         if ($counter == $this->page)
  997.                             $this->pagination .= "<span class=\"current\">$counter</span>";
  998.                         else
  999.                             $this->pagination .= "<a href=\"" . $this->get_pagenum_link($counter) . "\">$counter</a>";
  1000.                 }
  1001.             }
  1002.             if ($this->page) {
  1003.                 // siguiente button
  1004.                 if ($this->page <$counter - 1)
  1005.                     $this->pagination .= "<a href=\"" . $this->get_pagenum_link($next) . "\" class=\"next\">$n</a>";
  1006.                 else
  1007.                     $this->pagination .= "<span class=\"disabled\">$n</span>";
  1008.                 if ($this->showCounter)$this->pagination .= "<div class=\"pagination_data\">($this->total_pages Pages)</div>";
  1009.             }
  1010.         }
  1011.  
  1012.         return true;
  1013.     }
  1014. }
  1015.  
  1016. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement