chipbennett

Untitled

Jul 9th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.42 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Guan Image Notes
  4. Plugin URI: http://pangeran.org/guan-image-notes/
  5. Description: Allows you and your visitors to add comment as textual annotations to images by select a region of the image and then attach a textual description to it. The notes or annotations is intergrated with WordPress comment system.
  6. Author: Pangeran Wiguan
  7. Version: 2.0
  8. Author URI: http://wiguan88.com
  9. */
  10.  
  11. /*
  12.  
  13. Guan Image Notes | Add notes tagging to your images in WordPress powered blogs.
  14. Copyright (C) 2010  Pangeran Wiguan
  15.  
  16. This program is free software; you can redistribute it and/or
  17. modify it under the terms of the GNU General Public License
  18. as published by the Free Software Foundation; either version 2
  19. of the License, or (at your option) any later version.
  20.  
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. GNU General Public License for more details.
  25.  
  26. You should have received a copy of the GNU General Public License
  27. along with this program; if not, write to the Free Software
  28. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  29.  
  30. */
  31.  
  32. //header function
  33. function load_image_annotation_js() {
  34.     $plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
  35.     echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js' type='text/javascript'></script>\n";
  36.     echo "<script type='text/javascript' src='". $plugindir ."/js/jquery.annotate.js'></script>\n";
  37.     echo "<script type='text/javascript' src='". $plugindir ."/js/jquery-ui-1.7.1.js'></script>\n";
  38.     echo "<link rel='stylesheet' href='$plugindir/css/annotation.css' type='text/css' />\n";
  39.    
  40.     function ae_detect_ie()
  41.     {
  42.         if (isset($_SERVER['HTTP_USER_AGENT']) &&
  43.         (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
  44.             return true;
  45.         else
  46.             return false;
  47.     }
  48.    
  49.     /**
  50.      *Since Guan Image Notes Version 1.0
  51.      *Add notification for user to go to single page if other page than single page for example homepage.
  52.       */  
  53.     if (is_single()) : { ?>
  54.        
  55.     <script language="javascript">
  56.     $(document).ready(function(){
  57.             $("img").each(function() {
  58.                 var idname = $(this).attr("id")
  59.                 if(idname.substring(0,4) == "img-") {
  60.                     source = $(this).attr('src');
  61.                     var addablecon = $(this).attr("addable")
  62.                     addablecon = addablecon == undefined ? "true" : addablecon;
  63.                    
  64.                     $(this).wrap($('<div id=' + idname.substring(4,idname.length) + ' ></div>'));
  65.                    
  66.                     $('#' + idname).mouseover(function() {
  67.                         $(this).annotateImage({
  68.                             getPostID: <?php global $wp_query; $thePostID = $wp_query->post->ID; echo $thePostID; ?>,
  69.                             getImgID: idname,
  70.                             getUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  71.                             saveUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  72.                             deleteUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  73.                             editable: <?php get_currentuserinfo(); global $user_level; if ($user_level > 0) { ?>true<?php } else { ?>false<?php } ?>,
  74.                             addable: <?php get_currentuserinfo(); global $user_level; if ($user_level > 0) { ?>true<?php } else { ?> addablecon == "true" ? true : false <?php } ?>
  75.                         });
  76.                     });
  77.                 }
  78.             });
  79.            
  80.             $('div').each(function() {
  81.                 var divid = $(this).attr("id");
  82.                 if(divid.substring(0,8) == "comment-") {
  83.                     var getimgsrc = imageSource(divid.substring(8,divid.length));
  84.                     if(getimgsrc != "") {
  85.                         $(this).remove("noted");
  86.                         $(this).html('<div class="image-note-thumbnail"><a href="#' + divid.substring(8,divid.length) + '"><img src="' + getimgsrc + '" /></a></div>');
  87.                     }
  88.                 }
  89.             });
  90.     });
  91.    
  92.     function imageSource(id) {
  93.         var idreturn = "";
  94.         $('img').each(function() {
  95.             var imgid = $(this).attr("id");
  96.             if(imgid == "img-" + id) {
  97.                 idreturn = $(this).attr("src");
  98.             }
  99.         });
  100.        
  101.         return idreturn;
  102.     }
  103.    
  104.     </script>
  105.    
  106.     <?php }
  107.    
  108.     else : ?>
  109.    
  110.     <script language="javascript">
  111.     $(document).ready(function(){
  112.             $("img").each(function() {
  113.                 var idname = $(this).attr("id")
  114.                 if(idname.substring(0,4) == "img-") {
  115.                     source = $(this).attr('src');
  116.                     var addablecon = $(this).attr("addable")
  117.                     addablecon = addablecon == undefined ? "true" : addablecon;
  118.                    
  119.                     $(this).wrap($('<div id=' + idname.substring(4,idname.length) + ' ></div>'));
  120.                    
  121.                     $('#' + idname).mouseover(function() {
  122.                         $(this).annotateImage({
  123.                             getPostID: <?php global $wp_query; $thePostID = $wp_query->post->ID; echo $thePostID; ?>,
  124.                             getImgID: idname,
  125.                             getUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  126.                             saveUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  127.                             deleteUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  128.                             editable: <?php get_currentuserinfo(); global $user_level; if ($user_level > 0) { ?>false<?php } else { ?>false<?php } ?>,
  129.                             addable2: <?php get_currentuserinfo(); global $user_level; if ($user_level > 0) { ?>true<?php } else { ?> addablecon == "true" ? true : false <?php } ?>
  130.                         });
  131.                     });
  132.                 }
  133.             });
  134.            
  135.             $('div').each(function() {
  136.                 var divid = $(this).attr("id");
  137.                 if(divid.substring(0,8) == "comment-") {
  138.                     var getimgsrc = imageSource(divid.substring(8,divid.length));
  139.                     if(getimgsrc != "") {
  140.                         $(this).remove("noted");
  141.                         $(this).html('<div class="image-note-thumbnail"><a href="#' + divid.substring(8,divid.length) + '"><img src="' + getimgsrc + '" /></a></div>');
  142.                     }
  143.                 }
  144.             });
  145.     });
  146.    
  147.     function imageSource(id) {
  148.         var idreturn = "";
  149.         $('img').each(function() {
  150.             var imgid = $(this).attr("id");
  151.             if(imgid == "img-" + id) {
  152.                 idreturn = $(this).attr("src");
  153.             }
  154.         });
  155.        
  156.         return idreturn;
  157.     }
  158.    
  159.     </script>
  160.    
  161.     <?php endif;
  162.    
  163.    
  164. }
  165.  
  166. //comment function
  167. function getImgID() {
  168.     global $comment;
  169.     $commentID = $comment->comment_ID;
  170.    
  171.     global $wpdb;
  172.     $imgIDNow = $wpdb->get_var("SELECT note_img_ID FROM guan_imagenote WHERE note_comment_id = ".(int)$commentID);
  173.    
  174.     if($imgIDNow != "") {
  175.         $str = substr($imgIDNow, 4, strlen($imgIDNow));
  176.         echo "<div id=\"comment-".$str."\"><a href='#".$str."'>noted on #".$imgIDNow."</a></div>";
  177.     } else {
  178.         echo "&nbsp;"; 
  179.     }
  180. }
  181.  
  182. /**
  183.  *Since Guan Image Notes Version 2.0
  184.  *This function add id="img-012345678" into the image attribute while inserting the image into post using WordPress editor.
  185.  *The number is unique and changed dynamically according to image id attachment.
  186.  *Change the URL attached to the images as [Open Link In New Tab].
  187.  */
  188. function guan_image_note_processor($html, $id , $alt, $title) {
  189.    
  190.     $html = str_replace('<img', '<img id="img-' . $id . '" ', $html);
  191.    
  192.     return $html;
  193.        
  194. }
  195.  
  196. /**
  197.  *Since Guan Image Notes Version 1.0
  198.  *This function add the commented image thumbnail in the comment area.
  199.  */
  200. function guan_getImgID_inserter($comment_ID = 0){
  201.     getImgID();
  202.     $guan_comment_content = get_comment_text();
  203.     return $guan_comment_content;
  204. }
  205.  
  206. /**
  207.  *Since Guan Image Notes 2.0
  208.  *Admin stuffs
  209.  */
  210. function guan_image_notes_menu() {
  211.    
  212.     add_options_page('Guan Image Notes Settings', 'Guan Image Notes Settings', 'manage_options', 'guan-image-notes-page', 'guan_image_notes_options');
  213.  
  214. }
  215.  
  216. function guan_image_notes_options() {
  217.    
  218.     if (!current_user_can('manage_options'))  {
  219.         wp_die( __('You do not have sufficient permissions to access this page.') );
  220.     }
  221.    
  222.     $title = __('Guan Image Notes');
  223.    
  224.     $plugindir = '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
  225.        
  226.     include( ABSPATH . $plugindir . "/guan-image-notes-settings-page.php");
  227.    
  228. }
  229.  
  230. function register_guan_image_notes_settings() { // whitelist options
  231.   register_setting( 'guan-image-notes', 'guan_image_notes_enable_comments_thumbnail' );
  232.   register_setting( 'guan-image-notes', 'guan_image_notes_enable_comment_sync' );
  233. }
  234.  
  235. if ( is_admin() ){ // admin actions
  236.     add_action( 'admin_menu', 'guan_image_notes_menu' );
  237.     add_action( 'admin_init', 'register_guan_image_notes_settings' );
  238. }
  239. else {
  240.   // non-admin enqueues, actions, and filters
  241. }
  242.  
  243. if( (get_option('guan_image_notes_enable_comments_thumbnail') == '1') ) {
  244.     //Do nothing, the user don't want the script to insert the thumbnail into comments.
  245. }
  246. else {
  247.     add_filter('comment_text', 'guan_getImgID_inserter', 10, 4);
  248. }
  249.  
  250. add_filter('get_image_tag','guan_image_note_processor', 10, 4);
  251. add_action('wp_head', 'load_image_annotation_js');
  252. add_filter('Comments', 'getImgID');
  253.  
  254. // ?>
Add Comment
Please, Sign In to add comment