PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/link-adder.php

https://github.com/koggdal/link-adder
PHP | 60 lines | 47 code | 4 blank | 9 comment | 4 complexity | 89227889cfdbd6a002605f58d3448516 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Link Adder
  4. Plugin URI: http://koggdal.com/extras/link-adder/
  5. Description: Creates a bookmarklet that adds the website the user is currently on as a link in your WordPress install
  6. Version: 1.0.1
  7. Author: Johannes Koggdal
  8. Author URI: http://koggdal.com/
  9. License: MIT
  10. */
  11. add_action('admin_menu', 'link_adder_menu');
  12. $option = get_option('link-adder-id');
  13. if(empty($option))
  14. add_option('link-adder-id', substr(hash('sha512','link-adder_'+time()+rand()),0,50));
  15. function link_adder_menu()
  16. {
  17. add_options_page('Link Adder Settings', 'Link Adder', 'manage_options', 'link-adder', 'link_adder_settings');
  18. }
  19. function link_adder_settings()
  20. {
  21. if (!current_user_can('manage_options'))
  22. wp_die( __('You do not have sufficient permissions to access this page.') );
  23. $code = file_get_contents(WP_PLUGIN_URL."/link-adder/link-adder.min.js");
  24. $code = str_replace("%SITENAME%",get_bloginfo('name'),$code);
  25. $code = preg_replace("/\/\*.*?\*\/\n/s","javascript:",$code);
  26. $code = str_replace('"',"'",$code);
  27. $code = str_replace("plugin_folder:''","plugin_folder:'".WP_PLUGIN_URL."/link-adder/'",$code);
  28. $code = str_replace("hash:''","hash:'".get_option('link-adder-id')."'",$code);
  29. $code = htmlentities($code);
  30. $code_full = file_get_contents(WP_PLUGIN_URL."/link-adder/link-adder.js");
  31. $code_full = str_replace("%SITENAME%",get_bloginfo('name'),$code_full);
  32. $code_full = htmlentities($code_full);
  33. $code_full = preg_replace("/plugin_folder: ['\"].*?['\"]/","plugin_folder: '".WP_PLUGIN_URL."/link-adder/'",$code_full);
  34. $code_full = str_replace("hash: ''","hash: '".get_option('link-adder-id')."'",$code_full);
  35. $code_full_rows = split("\n",$code_full);
  36. $code_full_num_rows = count($code_full_rows);
  37. ?>
  38. <div class="wrap">
  39. <div class="icon32" id="icon-options-general"></div>
  40. <h2>Link Adder Settings</h2>
  41. <p>Settings to customize the plugin will come in future versions of Link Adder. You will then also be able to choose which category the link ends up in. Until then, the link will be assigned to the default category.</p>
  42. <p>The code in this bookmarklet has been customized specifically for your WordPress install, so it will not work for any other site.</p>
  43. <h3>Add Bookmarklet</h3>
  44. <p>Drag the link below to your bookmarks, or right click on the link and choose Bookmark This Link.</p>
  45. <p><a href="<?php echo $code; ?>">Link Adder</a></p>
  46. <h3>Code</h3>
  47. <p>If you rather prefer to copy the code and paste to your bookmark organizer or something, you have the code here.</p>
  48. <textarea cols="100" rows="10" style="width: 99%;"><?php echo $code; ?></textarea>
  49. <h3>Unminified Code</h3>
  50. <p>Here is the full bookmarklet code unminified with comments.</p>
  51. <textarea cols="100" rows="<?php echo $code_full_num_rows; ?>" style="width: 99%;"><?php echo $code_full; ?></textarea>
  52. </div>
  53. <?php
  54. }
  55. ?>