Advertisement
Guest User

Untitled

a guest
Sep 24th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Demon Image Annotations
  4. Plugin URI: http://www.superwhite.cc/demon/image-annotation-plugin
  5. Description: 'Allows you to add textual annotations to images by select a region of the image and then attach a textual description, the concept of annotating images with user comments.'
  6. Author: Demon
  7. Version: 2.4.5
  8. Author URI: http://www.superwhite.cc
  9. */
  10.  
  11. //*************** Header function ***************
  12. function load_image_annotation_js() {
  13. $plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
  14. echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'></script>\n";
  15. echo "<script type='text/javascript' src='". $plugindir ."/js/jquery.annotate.js'></script>\n";
  16. echo "<script type='text/javascript' src='". $plugindir ."/js/jquery-ui-1.7.1.js'></script>\n";
  17. echo "<script type='text/javascript' src='". $plugindir ."/js/jquery.md5.js'></script>\n";
  18.  
  19. function ae_detect_ie()
  20. {
  21. if (isset($_SERVER['HTTP_USER_AGENT']) &&
  22. (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
  23. return true;
  24. else
  25. return false;
  26. }
  27.  
  28. if (is_single()) {
  29. $plugin = 1;
  30. } else if(is_archive()){
  31. if( (get_option('demon_image_annotation_archive') == '1') ) {
  32. $plugin = 2;
  33. } else {
  34. $plugin = 0;
  35. }
  36. } else if(is_home()){
  37. if( (get_option('demon_image_annotation_homepage') == '1') ) {
  38. $plugin = 2;
  39. } else {
  40. $plugin = 0;
  41. }
  42. }
  43.  
  44. ?>
  45. <script language="javascript">
  46. <?php if( (get_option('demon_image_annotation_display') == '0' && $plugin != 0) ) { ?>
  47. $(document).ready(function(){
  48. //image annotaion
  49. $("<?php echo get_option('demon_image_annotation_postcontainer'); ?> img").each(function() {
  50. var idname = $(this).attr("id")
  51. var source = $(this).attr('src');
  52.  
  53. if(idname.substring(4,idname.length) != 'exclude') {
  54. //check if image annotation addable attribute exist
  55. var addablecon = $(this).attr("addable")
  56.  
  57. //disable if image annotation addable for admin only
  58. <?php if (get_option('demon_image_annotation_admin') == '0') { ?>
  59. addablecon = false;
  60. <?php } else { ?>
  61. addablecon = addablecon == undefined ? "true" : addablecon;
  62. <?php } ?>
  63.  
  64. //enable addable and editable only in single page
  65. //disable addable button if not in single page
  66. <?php if ($plugin != 1) { ?>
  67. var addablepage = false;
  68. var editable = false
  69. addablecon = false;
  70. <?php } else { ?>
  71. var addablepage = true;
  72. var editable = true;
  73. <?php } ?>
  74.  
  75. //find image link if exist
  76. var imagelink = $(this).parent("a").attr('href');
  77. var imgid = ""
  78.  
  79. //auto insert image id attribute
  80. <?php if( (get_option('demon_image_annotation_autoimageid') == '0') ) { ?>
  81. imgid = $.md5(source);
  82. <?php if( (get_option('demon_image_annotation_autoimageid') == '0') ) { ?>
  83. var postid = <?php global $wp_query; $thePostID = $wp_query->post->ID; echo $thePostID; ?>;
  84. imgid = "img-" + postid + "-" + imgid.substring(0,10);
  85. <?php } else { ?>
  86. imgid = "img-" + imgid.substring(0,10);
  87. <?php }; ?>
  88. <?php }; ?>
  89.  
  90. //replace if image id attribute exist
  91. if(idname.substring(0,4) == "img-") {
  92. imgid = idname;
  93. }
  94.  
  95. if(imgid.substring(0,4) == "img-") {
  96. //deactive the lnik if exist
  97. $(this).parent("a").removeAttr("href");
  98.  
  99. <?php if( (get_option('demon_image_annotation_dia_imgtag') == '0') ) { ?>
  100. $(this).parent("a").removeAttr("title");
  101. <?php } ?>
  102.  
  103. $(this).attr("id", imgid);
  104. $(this).wrap($('<div id=' + imgid.substring(4,imgid.length) + ' ></div>'));
  105. var imagenotedesc = "<?php echo get_option('demon_image_annotation_mouseoverdesc'); ?>";
  106. var imagelinkdesc = "<?php echo get_option('demon_image_annotation_linkdesc'); ?>";
  107.  
  108. var imagenotetag = imagenotedesc != '' ? imagenotedesc : imagenotedesc;
  109. var imagelinktag = imagelink != undefined ? '<a href="' + imagelink + '" target="blank">' + imagelinkdesc + '</a>' : '';
  110. var divider;
  111.  
  112. if(imagenotedesc != '') {
  113. divider = imagelink != undefined ? ' | ' : '';
  114. } else if (imagelink != undefined) {
  115. divider = imagenotetag == '' ? '' : ' | ';
  116. } else {
  117. divider = '';
  118. }
  119.  
  120. $(this).before('<div class="image-note-desc">'+ imagenotetag + divider + imagelinktag + '</div>');
  121.  
  122. $(this).mouseover(function() {
  123. $(this).annotateImage({
  124. getPostID: <?php global $wp_query; $thePostID = $wp_query->post->ID; echo $thePostID; ?>,
  125. getImgID: imgid,
  126. pluginUrl: "<?php echo $plugindir; ?>/imageannotation-run.php",
  127. editable: <?php get_currentuserinfo(); global $user_level; if ($user_level > 0) { ?>editable<?php } else { ?> false <?php } ?>,
  128. addable: <?php get_currentuserinfo(); global $user_level; if ($user_level > 0) { ?>addablepage<?php } else { ?> addablecon == "true" ? true : false <?php } ?>
  129. });
  130. });
  131. }
  132. }
  133.  
  134. });
  135.  
  136. //comment thumbnails
  137. $('div').each(function() {
  138. var divid = $(this).attr("id");
  139. if(divid.substring(0,8) == "comment-") {
  140. var getimgsrc = imageSource(divid.substring(8,divid.length));
  141. if(getimgsrc != "") {
  142. $(this).remove("noted");
  143. $(this).html('<div class="image-note-thumbnail"><a href="#' + divid.substring(8,divid.length) + '"><img src="' + getimgsrc + '" /></a></div>');
  144. }
  145. }
  146. });
  147. });
  148.  
  149. //get image source from post for thumbnail
  150. function imageSource(id) {
  151. var idreturn = "";
  152. $('<?php echo get_option('demon_image_annotation_postcontainer'); ?> img').each(function() {
  153. var imgid = $(this).attr("id");
  154. if(imgid == "img-" + id) {
  155. idreturn = $(this).attr("src");
  156. }
  157. });
  158.  
  159. return idreturn;
  160. }
  161. <?php } ?>
  162.  
  163. </script>
  164. <?php
  165. }
  166.  
  167. //*************** Comment function ***************
  168. function getImgID() {
  169. global $comment;
  170. $commentID = $comment->comment_ID;
  171.  
  172. global $wpdb;
  173. $table_name = $wpdb->prefix . "demon_imagenote";
  174. $imgIDNow = $wpdb->get_var("SELECT note_img_ID FROM ".$table_name." WHERE note_comment_id = ".(int)$commentID);
  175.  
  176. if($imgIDNow != "") {
  177. $str = substr($imgIDNow, 4, strlen($imgIDNow));
  178. echo "<div id=\"comment-".$str."\"><a href='#".$str."'>noted on #".$imgIDNow."</a></div>";
  179. } else {
  180. echo "&nbsp;";
  181. }
  182. }
  183.  
  184. function getImgID_inserter($comment_ID = 0){
  185. getImgID();
  186. $comment_content = get_comment_text();
  187. return $comment_content;
  188. }
  189.  
  190. if( (get_option('demon_image_annotation_display') == '0') ) {
  191. if( (get_option('demon_image_annotation_thumbnail') == '0') ) {
  192. add_filter('comment_text', 'getImgID_inserter', 10, 4);
  193. }
  194. }
  195.  
  196. add_action('wp_head', 'load_image_annotation_js');
  197.  
  198. //*************** Admin function ***************
  199. function demonimageannotation_admin() {
  200. include('imageannotation-admin.php');
  201. }
  202.  
  203. function demonimageannotation_admin_actions() {
  204. add_menu_page('demon-Image-Annotation', 'demon-Image-Annotation', 'manage_options', 'demon-Image-Annotation', 'demonimageannotation_admin', plugins_url('icon.png',__FILE__));
  205. changeTableName();
  206. }
  207.  
  208. function changeTableName() {
  209. global $wpdb;
  210. $table_name = $wpdb->prefix . "demon_imagenote";
  211.  
  212. //wp_demon_imagenote
  213. if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
  214. $sql = "Rename table `demon_imagenote` to `".$table_name."`;";
  215. $wpdb->query($sql);
  216.  
  217. $sql = "Rename table `wp_imagenote` to `".$table_name."`;";
  218. $wpdb->query($sql);
  219. }
  220.  
  221. if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
  222. $sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
  223. `note_ID` int(11) NOT NULL AUTO_INCREMENT,
  224. `note_img_ID` varchar(30) NOT NULL,
  225. `note_comment_ID` int(11) NOT NULL,
  226. `note_author` varchar(100) NOT NULL,
  227. `note_email` varchar(100) NOT NULL,
  228. `note_top` int(11) NOT NULL,
  229. `note_left` int(11) NOT NULL,
  230. `note_width` int(11) NOT NULL,
  231. `note_height` int(11) NOT NULL,
  232. `note_text` text NOT NULL,
  233. `note_text_ID` varchar(100) NOT NULL,
  234. `note_editable` tinyint(1) NOT NULL,
  235. `note_date` datetime NOT NULL,
  236. PRIMARY KEY (`note_ID`)
  237. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;";
  238.  
  239. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  240. dbDelta($sql);
  241. } else {
  242. $sql = "ALTER TABLE `".$table_name."` modify `note_img_ID` VARCHAR(30);";
  243. $wpdb->query($sql);
  244.  
  245. $sql = "ALTER TABLE `".$table_name."` ADD `note_approved` VARCHAR(20) DEFAULT '1' AFTER `note_editable`;";
  246. $wpdb->query($sql);
  247. }
  248. }
  249.  
  250.  
  251. if (is_admin())
  252. {
  253. add_action('admin_menu', 'demonimageannotation_admin_actions');
  254. }
  255. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement