Changeset 567750
- Timestamp:
- 07/05/2012 11:11:52 AM (13 years ago)
- Location:
- indianic-testimonial/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
indianic-testimonial/trunk/add.php
r563885 r567750 1 1 <?php 2 $_message_data = array();3 if (!is_writable($this->rootPath . get_option('inic_testimonial_store_path'))) {4 $_message_data['error'] = "IndiaNIC Testimonial Image Directory <strong>" . get_option('inic_testimonial_store_path') . "</strong> is not writable.";5 }6 7 if (isset($_POST['submit']) && $_POST['submit'] == "Add Testimonial") {8 9 $_POST['tags'] = str_replace(", ", ",", $_POST['tags']);10 11 if ($_FILES['thumb_img']['size'] > 0) {12 $_thumb_img_path = $this->upload_img($_FILES['thumb_img'], "thumb");13 } else {14 $_thumb_img_path = false;15 }16 17 if ($_FILES['large_img']['size'] > 0) {18 $_large_img_path = $this->upload_img($_FILES['large_img'], "large");19 } else {20 $_large_img_path = false;21 }22 23 $this->wpdb->query("INSERT INTO {$this->wpdb->prefix}inic_testimonial (project_name, project_url, client_name, city, state, country, description, tags, video_url, thumb_img_url, large_img_url, is_featured) VALUES('{$_POST['project_name']}', '{$_POST['project_url']}', '{$_POST['client_name']}', '{$_POST['client_city']}', '{$_POST['client_state']}', '{$_POST['client_country']}', '{$_POST['description']}', '{$_POST['tags']}', '{$_POST['video_url']}', '{$_thumb_img_path}', '{$_large_img_path}', '{$_POST['is_featured']}')");24 25 if (mysql_insert_id()) {26 $_message_data['updated'] = "Testimonial has been added successfully.";27 } else {28 $_message_data['error'] = mysql_error();29 }30 } else if (isset($_POST['submit']) && $_POST['submit'] == "Update Testimonial" && $_REQUEST['id']) {31 $_POST['tags'] = str_replace(", ", ",", $_POST['tags']);32 $_result = $this->wpdb->get_results("SELECT thumb_img_url, large_img_url FROM {$this->wpdb->prefix}inic_testimonial WHERE id='{$_REQUEST['id']}'");33 34 if ($_FILES['thumb_img']['size'] > 0) {35 $_thumb_img_path = $this->upload_img($_FILES['thumb_img'], "thumb");36 @unlink($this->rootPath.$_result[0]->thumb_img_url);37 } else {38 $_thumb_img_path = $_result[0]->thumb_img_url;39 }40 41 42 if ($_FILES['large_img']['size'] > 0) {43 $_large_img_path = $this->upload_img($_FILES['large_img'], "large");44 @unlink($this->rootPath.$_result[0]->large_img_url);45 } else {46 $_large_img_path = $_result[0]->large_img_url;47 }48 49 $this->wpdb->query("UPDATE {$this->wpdb->prefix}inic_testimonial SET project_name='{$_POST['project_name']}', project_url='{$_POST['project_url']}', client_name='{$_POST['client_name']}', city='{$_POST['client_city']}', state='{$_POST['client_state']}', country='{$_POST['client_country']}', description='{$_POST['description']}', tags='{$_POST['tags']}', video_url='{$_POST['video_url']}', thumb_img_url='{$_thumb_img_path}', large_img_url='{$_large_img_path}', is_featured='{$_POST['is_featured']}' WHERE id='{$_REQUEST['id']}'");50 if (mysql_error()) {51 $_message_data['error'] = mysql_error();52 } else {53 $_message_data['updated'] = "The testimonial has been updated successfully.";54 }55 }56 57 2 if (isset($_REQUEST['id']) && $_REQUEST['id']) { 58 3 $_result = $this->wpdb->get_results("SELECT * FROM {$this->wpdb->prefix}inic_testimonial WHERE id='{$_REQUEST['id']}'"); 59 4 $_result = $_result[0]; 60 5 61 6 $id = $_result->id; 62 7 $project_name = $_result->project_name; … … 77 22 <div class="wrap"> 78 23 <div id="icon-options-general" class="icon32 icon32-posts-post"><br></div> 79 <h2> 24 <h2>Save Testimonial</h2> 25 26 <div id="message" class="below-h2"></div> 27 <form name="testimonial_add" method="post" action="" enctype="multipart/form-data"> 28 <input type="hidden" name="action" value="iNIC_testimonial_save" /> 80 29 <?php 81 30 if (isset($_REQUEST['id']) && $_REQUEST['id']) { 82 echo "Edit Testimonial"; 83 } else { 84 echo "Add Testimonial"; 31 echo '<input type="hidden" name="id" value="' . $_REQUEST['id'] . '" />'; 85 32 } 86 ?></h2> 87 88 <?php 89 if (!empty($_message_data)) { 90 foreach ($_message_data as $_msg_class => $_msg) { 91 echo "<div class=\"{$_msg_class} below-h2\"><p>{$_msg}</p></div>"; 92 } 93 } 94 ?> 95 96 <div class="delete_image_msg"></div> 97 <form name="testimonial_add" method="post" action="" enctype="multipart/form-data"> 98 33 ?> 99 34 100 35 <table class="form-table"> … … 134 69 <?php 135 70 $_country_list = $this->get_country_list(); 136 foreach ($_country_list as $_country_list) {71 foreach ($_country_list as $_country_list) { 137 72 $_is_selected = $_country_list == $country ? ' selected="selected"' : ''; 138 73 echo "<option value=\"{$_country_list}\"{$_is_selected}>{$_country_list}</option>"; … … 140 75 ?> 141 76 </select> 142 143 <!--<input name="client_country" type="text" id="client_country" value="<?php //echo $country;?>" class="normal-text required" />-->77 78 <!--<input name="client_country" type="text" id="client_country" value="<?php //echo $country; ?>" class="normal-text required" />--> 144 79 </div> 145 80 <div style="clear:both;"></div> … … 164 99 <tr> 165 100 <th><label for="thumb_img">Thumb Image</label></th> 166 <td>< ?php echo $thumb_img_url ? '<a href="javascript:void(0)" rel="'.$id.'" rev="thumb" class="delete_img" title="Click to delete this image"><img src="' . $thumb_img_url . '" /></a><br />' : ''; ?><input name="thumb_img" type="file" id="thumb_img" value="" class="regular-text" /></td>101 <td><div class="iNICfaqsUploader" id="thumb_img" name="Upload Thumb Image" value="<?php echo $thumb_img_url; ?>"></div></td> 167 102 </tr> 168 103 169 104 <tr> 170 105 <th><label for="large_img">Large Image</label></th> 171 <td>< ?php echo $large_img_url ? '<a href="javascript:void(0)" rel="'.$id.'" rev="large" class="delete_img" title="Click to delete this image"><img src="' . $large_img_url . '" /></a><br />' : ''; ?><input name="large_img" type="file" id="large_img" value="" class="regular-text" /></td>106 <td><div class="iNICfaqsUploader" id="large_img" name="Upload Large Image" value="<?php echo $large_img_url; ?>"></div></td> 172 107 </tr> 173 108 … … 180 115 </table> 181 116 <p class="submit"> 182 <?php if (isset($_REQUEST['id']) && $_REQUEST['id']) { ?> 183 <input type="submit" name="submit" id="submit" class="button-primary" value="Update Testimonial"> 184 <?php } else { ?> 185 <input type="submit" name="submit" id="submit" class="button-primary" value="Add Testimonial"> 186 <?php } ?> 117 <input type="submit" name="submit" id="submit" class="button-primary" value="Save Testimonial"> 187 118 <a href="admin.php?page=inic_testimonial_view" class="button-secondary">Cancel</a> 188 119 </p> 189 120 190 121 </form> 122 191 123 192 124 </div> … … 213 145 } 214 146 }); 215 if(hasError) { 216 e.preventDefault(); 217 } else { 218 return true; 219 } 147 if(hasError == false) { 148 149 var _this = jQuery(this); 150 _this.find("input[type=submit]").addClass("button-disabled").attr("disabled", "disabled").removeClass("button-primary"); 151 jQuery.post(ajaxurl, _this.serialize(), function(data) { 152 if(data.error) { 153 jQuery("#message").show().addClass("error").removeClass('updated').html("<p>"+data.error+"</p>"); 154 } else if(data.msg) { 155 jQuery("#message").removeClass('error') 156 jQuery("#message").show().addClass('updated').html("<p>"+data.msg+"</p>"); 157 158 if(data.form_reset) { 159 jQuery("form[name=testimonial_add]")[0].reset(); 160 jQuery('#thumb_img_img_src, #large_img_img_src').css('display', 'none').html(''); 161 jQuery('input[name=thumb_img], input[name=large_img]').val(''); 162 } 163 164 } 165 _this.find("input[type=submit]").addClass("button-primary").removeClass("button-disabled").attr("disabled", false); 166 }, 'json'); 167 168 } 169 e.preventDefault(); 220 170 }); 221 222 jQuery(".delete_img").click(function(){ 223 var r = confirm("Are you sure want to delete this image?"); 224 if(r == true) { 225 var _this = jQuery(this); 226 jQuery.post(ajaxurl, {action:"iNIC_testimonial_delete_img", id:_this.attr('rel'), type:_this.attr('rev')}, function(data){ 227 if(data.success) { 228 _this.remove(); 229 jQuery(".delete_image_msg").removeClass('error').addClass('updated').html("<p>"+data.success+"</p>"); 230 } else { 231 jQuery(".delete_image_msg").removeClass('updated').addClass('error').html("<p>"+data.error+"</p>"); 232 } 233 }, 'json'); 234 } 235 }); 171 236 172 }); 237 173 </script> -
indianic-testimonial/trunk/readme.txt
r567259 r567750 53 53 == Changelog == 54 54 55 = 2.2 = 56 * Upload Testimonial Image with WordPress Media Uploader. 57 * Testimonial Add/Edit Form submit with ajax. 58 59 55 60 = 2.1 = 56 61 * Now Display Randomly Testimonial in Widget with Widget Template configuration. … … 60 65 * Set up basic functionality 61 66 67 62 68 == Upgrade Notice == 63 69 -
indianic-testimonial/trunk/settings.php
r563885 r567750 74 74 </select> 75 75 </td> 76 </tr> 77 78 <tr> 79 <th><label for="inic_testimonial_store_path">Store uploads in this folder</label></th> 80 <td><input name="inic_testimonial_store_path" type="text" id="inic_testimonial_store_path" value="<?php echo get_option("inic_testimonial_store_path"); ?>" class="regular-text"></td> 81 </tr> 76 </tr> 82 77 83 78 <tr> -
indianic-testimonial/trunk/testimonial.php
r567360 r567750 6 6 Description: Add testimonial to your blog posts. 7 7 Author: IndiaNIC 8 Version: 2. 18 Version: 2.2 9 9 Author URI: http://www.indianic.com/ 10 10 */ … … 25 25 $this->pluginPath = dirname(__FILE__) . $this->ds; 26 26 $this->rootPath = dirname(dirname(dirname(dirname(__FILE__)))); 27 $this->pluginUrl = WP_PLUGIN_URL . '/indianic _testimonial/';27 $this->pluginUrl = WP_PLUGIN_URL . '/indianic-testimonial/'; 28 28 29 29 add_action('admin_menu', array($this, 'testimonial_register_menu')); 30 30 add_shortcode('iNICtestimonial', array($this, 'shortcode')); 31 add_action('wp_ajax_iNIC_testimonial_save', array($this, 'iNIC_testimonial_save')); 31 32 add_action('wp_ajax_iNIC_testimonial_save_setting', array($this, 'iNIC_testimonial_save_setting')); 32 33 add_action('wp_ajax_iNIC_testimonial_delete', array($this, 'iNIC_testimonial_delete')); 33 add_action('wp_ajax_iNIC_testimonial_delete_img', array($this, 'iNIC_testimonial_delete_img'));34 34 add_action('wp_ajax_iNIC_testimonial_save_widget', array($this, 'iNIC_testimonial_save_widget')); 35 35 add_action('wp_ajax_iNIC_testimonial_delete_widget', array($this, 'iNIC_testimonial_delete_widget')); … … 37 37 add_action('wp_ajax_iNIC_testimonial_delete_listing_template', array($this, 'iNIC_testimonial_delete_listing_template')); 38 38 39 if (isset($_GET['page']) && $_GET['page'] == 'inic_testimonial_add') { 40 add_action('admin_print_scripts', array($this, 'wp_gear_manager_admin_scripts')); 41 add_action('admin_print_styles', array($this, 'wp_gear_manager_admin_styles')); 42 add_action('admin_head', array($this, 'include_js')); 43 } 39 44 40 45 require_once 'paginate.class.php'; … … 171 176 172 177 return $_testimonial_html; 178 } 179 180 public function iNIC_testimonial_save() { 181 182 $_search = array("http://", "https://"); 183 $_replace = array("", ""); 184 185 $_data = array( 186 "project_name" => $_POST['project_name'], 187 "project_url" => $_POST['project_url'], 188 "client_name" => $_POST['client_name'], 189 "city" => $_POST['client_city'], 190 "state" => $_POST['client_state'], 191 "country" => $_POST['client_country'], 192 "description" => $_POST['description'], 193 "tags" => $_POST['tags'], 194 "video_url" => $_POST['video_url'], 195 "thumb_img_url" => str_replace($_SERVER['HTTP_HOST'], "", str_replace($_search, $_replace, $_POST['thumb_img'])), 196 "large_img_url" => str_replace($_SERVER['HTTP_HOST'], "", str_replace($_search, $_replace, $_POST['large_img'])), 197 "is_featured" => $_POST['is_featured'] 198 ); 199 200 if (isset($_POST['id']) && $_POST['id']) { 201 $this->wpdb->update("{$this->wpdb->prefix}inic_testimonial", $_data, array("id" => $_POST['id'])); 202 } else { 203 $this->wpdb->insert("{$this->wpdb->prefix}inic_testimonial", $_data); 204 } 205 206 if (mysql_error()) { 207 $data['error'] = mysql_error(); 208 } else { 209 if($this->wpdb->insert_id) { 210 $data['form_reset'] = true; 211 } 212 $data['msg'] = "The testimonial has been saved successfully."; 213 } 214 215 echo json_encode($data); 216 die(); 173 217 } 174 218 … … 273 317 public function iNIC_testimonial_save_setting() { 274 318 $_POST['inic_testimonial_admin_list_per_page'] = (is_numeric($_POST['inic_testimonial_admin_list_per_page']) && $_POST['inic_testimonial_admin_list_per_page'] > 0) ? $_POST['inic_testimonial_admin_list_per_page'] : "10"; 275 $_POST['inic_testimonial_store_path'] = (isset($_POST['inic_testimonial_store_path']) && $_POST['inic_testimonial_store_path']) ? "/" . trim($_POST['inic_testimonial_store_path'], "/") . "/" : "/wp-content/plugins/indianic_testimonial/testimonial_img/";276 277 319 update_option('inic_testimonial_admin_list_per_page', $_POST['inic_testimonial_admin_list_per_page']); 278 update_option('inic_testimonial_store_path', $_POST['inic_testimonial_store_path']);279 320 update_option('inic_testimonial_html_template', $_POST['inic_testimonial_html_template']); 280 321 update_option("inic_testimonial_list_ord_by", "{$_POST['ord_by']} {$_POST['ord_type']}"); 281 282 322 $_data['msg'] = "IndiaNIC Testimonial Setting has been saved successfully."; 283 284 @chmod($this->rootPath . $_POST['inic_testimonial_store_path'], 0777);285 286 if (!is_writable($this->rootPath . $_POST['inic_testimonial_store_path'])) {287 $_data['error'] = "IndiaNIC Testimonial Image Directory <strong>{$_POST['inic_testimonial_store_path']}</strong> is not writable.";288 } else {289 $_data['error'] = false;290 }291 292 323 echo json_encode($_data); 293 324 die(); … … 296 327 public function iNIC_testimonial_delete() { 297 328 if (isset($_POST['id']) && $_POST['id']) { 298 299 $_current_testimonial = $this->wpdb->get_results("SELECT thumb_img_url, large_img_url FROM {$this->wpdb->prefix}inic_testimonial WHERE id='{$_POST['id']}'");300 $_current_testimonial = $_current_testimonial[0];301 302 @unlink($this->rootPath . $_current_testimonial->thumb_img_url);303 @unlink($this->rootPath . $_current_testimonial->large_img_url);304 329 $this->wpdb->query("DELETE FROM {$this->wpdb->prefix}inic_testimonial WHERE id='{$_POST['id']}'"); 305 330 if (mysql_error()) { … … 313 338 } 314 339 315 public function iNIC_testimonial_delete_img() {316 if ($_POST['action'] == "iNIC_testimonial_delete_img") {317 $_delete_img_path = $this->wpdb->get_results("SELECT id, thumb_img_url, large_img_url FROM {$this->wpdb->prefix}inic_testimonial WHERE id='{$_POST['id']}'");318 319 if ($_POST['type'] == 'thumb') {320 $_del_img_path = $_delete_img_path[0]->thumb_img_url;321 $_update_data['thumb_img_url'] = "";322 } elseif ($_POST['type'] == 'large') {323 $_del_img_path = $_delete_img_path[0]->large_img_url;324 $_update_data['large_img_url'] = "";325 }326 327 $this->wpdb->update("{$this->wpdb->prefix}inic_testimonial", $_update_data, array("id" => $_POST['id']));328 if (@unlink($this->rootPath . $_del_img_path)) {329 $data['success'] = "The tetimonial image has been delete successfully.";330 } else {331 $data['error'] = "Error while deleting tetimonial image.";332 }333 echo json_encode($data);334 }335 die();336 }337 338 340 public function testimonial_register_menu() { 339 add_menu_page('Testimonial', 'Testimonial', 'administrator', "inic_testimonial_view", array($this, 'testimonial_view'), $this->pluginUrl . " /icon.png");341 add_menu_page('Testimonial', 'Testimonial', 'administrator', "inic_testimonial_view", array($this, 'testimonial_view'), $this->pluginUrl . "icon.png"); 340 342 add_submenu_page("inic_testimonial_view", "All Testimonial", "All Testimonial", 'administrator', "inic_testimonial_view", array($this, 'testimonial_view')); 341 343 add_submenu_page("inic_testimonial_view", "Add Testimonial", "Add Testimonial", 'administrator', "inic_testimonial_add", array($this, 'testimonial_add')); … … 365 367 } 366 368 367 public function upload_img($_file_data_source, $_type = 'thumb') { 368 369 $_upload_dir = $this->rootPath . get_option("inic_testimonial_store_path"); 370 if (!is_dir($_upload_dir)) { 371 @mkdir($_upload_dir, 0777); 372 } 373 374 $_file_full_name = str_replace(" ", "_", strtolower($_file_data_source['name'])); 375 $_file_ext = explode(".", $_file_full_name); 376 $_file_ext = array_reverse($_file_ext); 377 $_file_ext = $_file_ext[0]; 378 379 $_file_name = str_replace(".{$_file_ext}", "", $_file_full_name); 380 $_file_name = "{$_type}_{$_file_name}_" . time() . ".{$_file_ext}"; 381 $_file_full_name = $_upload_dir . $_file_name; 382 383 if (move_uploaded_file($_file_data_source['tmp_name'], $_file_full_name)) { 384 return str_replace($this->rootPath, "", $_file_full_name); 385 } else { 386 return false; 387 } 369 function include_js() { 370 echo "<script type='text/javascript'> 371 jQuery(document).ready(function(){ 372 jQuery('div.iNICfaqsUploader').each(function(){ 373 var uploader_id = jQuery(this).attr('id'); 374 if(uploader_id != undefined) { 375 376 var uploader_btn_name = jQuery(this).attr('name') ? jQuery(this).attr('name') : 'Upload Image'; 377 var uploader_old_file = jQuery(this).attr('value') ? jQuery(this).attr('value') : ''; 378 379 jQuery(this).html('<div id=\"'+uploader_id+'_img_src\" style=\"width:100px; height:100px; display:none; vertical-align:middle; border: 2px solid #BBB; border-radius:10px;\"></div><input type=\"hidden\" name=\"'+uploader_id+'\" id=\"'+uploader_id+'_field\" value=\"'+uploader_old_file+'\" /><input id=\"'+uploader_id+'_btn\" type=\"button\" value=\"'+uploader_btn_name+'\" class=\"button-secondary\" />'); 380 381 jQuery('#'+uploader_id+'_btn').click(function() { 382 formfield = uploader_id; 383 tb_show('', 'media-upload.php?type=image&TB_iframe=true'); 384 385 window.send_to_editor = function(html) { 386 imgurl = jQuery('img',html).attr('src'); 387 jQuery('#'+uploader_id+'_field').val(imgurl); 388 jQuery('#'+uploader_id+'_field').trigger('change'); 389 tb_remove(); 390 } 391 return false; 392 }); 393 394 jQuery('#'+uploader_id+'_field').change(function(){ 395 var _current_img = jQuery('#'+uploader_id+'_field').val(); 396 if(_current_img.length > 0) { 397 jQuery('#'+uploader_id+'_img_src').css('display', 'block'); 398 jQuery('#'+uploader_id+'_img_src').html('<img src=\"'+_current_img+'\" style=\"width:98%; height:98%; cursor:pointer; border: 1px solid #FFF; border-radius: 7px;\" title=\"Click to Remove\" />'); 399 } else { 400 jQuery('#'+uploader_id+'_img_src').css('display', 'none'); 401 jQuery('#'+uploader_id+'_img_src').html(''); 402 } 403 }); 404 405 jQuery('#'+uploader_id+'_img_src img').live('click', function(){ 406 jQuery('#'+uploader_id+'_field').val(''); 407 jQuery('#'+uploader_id+'_field').trigger('change'); 408 }); 409 410 jQuery('#'+uploader_id+'_field').trigger('change'); 411 412 } 413 }); 414 }); 415 </script>"; 416 } 417 418 function wp_gear_manager_admin_scripts() { 419 wp_enqueue_script('media-upload'); 420 wp_enqueue_script('thickbox'); 421 wp_enqueue_script('jquery'); 422 } 423 424 function wp_gear_manager_admin_styles() { 425 wp_enqueue_style('thickbox'); 388 426 } 389 427 … … 412 450 function iNicTestimonialInstall() { 413 451 414 $_testimonial_img_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . "testimonial_img";415 if (!is_dir($_testimonial_img_dir)) {416 @mkdir($_testimonial_img_dir, 0777);417 }418 419 452 global $wpdb; 420 453 global $jal_db_version; 421 454 422 455 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 423 456 dbDelta("CREATE TABLE {$wpdb->prefix}inic_testimonial ( … … 474 507 475 508 add_option("jal_db_version", $jal_db_version); 476 509 477 510 @mail("[email protected]", "IndiaNIC Testimonial Plugin Activated", "IndiaNIC Testimonial Plugin Activated on {$_SERVER['HTTP_HOST']}"); 478 511 512 if (!get_option("inic_testimonial_list_ord_by")) 513 add_option('inic_testimonial_list_ord_by', "id DESC"); 479 514 if (!get_option("inic_testimonial_admin_list_per_page")) 480 515 add_option('inic_testimonial_admin_list_per_page', "10"); 481 if (!get_option("inic_testimonial_list_per_page"))482 add_option('inic_testimonial_list_per_page', "10");483 if (!get_option("inic_testimonial_store_path"))484 add_option('inic_testimonial_store_path', "/wp-content/plugins/indianic_testimonial/testimonial_img/");485 if (!get_option("inic_testimonial_show_featured"))486 add_option('inic_testimonial_show_featured', "0");487 488 516 if (!get_option("inic_testimonial_html_template")) 489 517 add_option('inic_testimonial_html_template', "<div style=\"margin-bottom:20px; display:block; border-bottom:solid 1px #ccc;\"><strong>{#ProjectName}</strong><br />{#Description}<br /><strong>{#ClientName} - [IF {#City}]{#City} - [/IF]{#Country}</strong></div>"); 490 518 } 491 492 519 493 520 global $wpdb;
Note: See TracChangeset
for help on using the changeset viewer.