PageRenderTime 27ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/umapper/lib/Umapper/Actions.php

https://github.com/digitalstrategyworks/Reese-WordPress
PHP | 280 lines | 117 code | 30 blank | 133 comment | 16 complexity | b239891220fabb4cf839519cad4c31c0 MD5 | raw file
  1. <?php
  2. require_once dirname(__FILE__) . '/Messages.php';
  3. /**
  4. * Action hooks
  5. *
  6. * All necessary actions go into this class
  7. *
  8. * @category Umapper
  9. * @package Umapper_Plugin
  10. * @copyright 2009 CrabDish
  11. * @version Release: 1.0.0
  12. * @author Victor Farazdagi <victor@afcomponents.com>
  13. */
  14. class Umapper_Actions
  15. {
  16. /**
  17. * Singleton instance
  18. * @var Umapper_Actions
  19. */
  20. private static $instance;
  21. /**
  22. * Singleton pattern - constructor is disabled
  23. *
  24. * @return void
  25. */
  26. private function __construct() {}
  27. /**
  28. * Returns singleton instance of current class
  29. *
  30. * @return Umapper_Actions
  31. */
  32. public static function getInstance()
  33. {
  34. if(null == self::$instance) {
  35. self::$instance = new self();
  36. }
  37. return self::$instance;
  38. }
  39. /**
  40. * init action
  41. * Runs after WordPress has finished loading but before any headers are sent.
  42. * Useful for intercepting $_GET or $_POST triggers.
  43. *
  44. * @return void
  45. */
  46. public function init()
  47. {
  48. require_once dirname(__FILE__) . '/Shortcode.php';
  49. // short codes
  50. add_shortcode('umap', array(Umapper_Shortcode::getInstance(), 'shortcodeUmap'));
  51. // setup menu
  52. add_action('admin_menu', array($this, 'adminMenu'));
  53. }
  54. /**
  55. * admin_init action
  56. * Runs at the beginning of every admin page before the page is rendered.
  57. *
  58. * @return void
  59. */
  60. public function adminInit()
  61. {
  62. // bind necessary js/css files
  63. add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts'));
  64. add_action('admin_head', array($this, 'adminHead'));
  65. // media controls
  66. add_action('media_buttons', array($this, 'mediaButtons'));
  67. add_action('media_upload_umapper', array($this, 'mediaUploadUmapper'));
  68. add_action('media_upload_umapper_token', array($this, 'mediaUploadUmapperToken'));
  69. // make sure that user is notified if API-key not found..
  70. if (in_array('umapper/info.php', get_option('active_plugins'))) { // umapper plugin is active
  71. // make sure that user warned about necessity of API-key registration
  72. if ( !(get_option('umapper_api_key')||Umapper_Plugin::$pluginIApiKey) && !isset($_POST['submit']) ) {
  73. add_action('admin_notices', array(Umapper_Messages::getInstance(), 'warningApiKeyMissing'));
  74. } elseif(!(get_option('umapper_providers') && get_option('umapper_templates')) && !isset($_POST['submit'])) {
  75. add_action('admin_notices', array(Umapper_Messages::getInstance(), 'warningRevalidateKey'));
  76. }
  77. }
  78. }
  79. /**
  80. * admin_menu
  81. * Runs after the basic admin panel menu structure is in place
  82. *
  83. * @return void
  84. */
  85. public function adminMenu()
  86. {
  87. // register configuration page
  88. if (function_exists('add_options_page')) {
  89. require_once dirname(__FILE__) . '/Page/Config.php';
  90. add_options_page(__('UMapper Configuration', 'umapper'), __('UMapper', 'umapper'), 8, 'Umapper.php', array(Umapper_Page_Config::getInstance(),'show'));
  91. }
  92. }
  93. /**
  94. * admin_enqueue_scripts
  95. * Runs when admin scripts are enqueued. I use it to make sure that scripts are added only
  96. * on umapper admin pages, w/o cluttering others
  97. *
  98. * @return void
  99. */
  100. public function adminEnqueueScripts($hook_suffix)
  101. {
  102. //var_dump($hook_suffix);
  103. // make sure that admin scripts are only added on umapper pages
  104. $pages = array('umapper', 'settings_page_Umapper');
  105. if(in_array($hook_suffix, $pages)) { // umapper page
  106. add_action('admin_print_scripts', array($this, 'adminPrintScripts'));
  107. add_action('admin_print_styles', array($this, 'adminPrintStyles'));
  108. }
  109. }
  110. /**
  111. * admin_print_scripts
  112. * Runs in the HTML header so a plugin can add JavaScript scripts to all admin pages.
  113. *
  114. * @return void
  115. */
  116. public function adminPrintScripts()
  117. {
  118. wp_enqueue_script('UmapperInit', Umapper_Plugin::getPluginUri() . 'content/js/UmapperInit.js.php', array('jquery'), uniqid());
  119. //wp_enqueue_script('Umapper', Umapper_Plugin::getPluginUri() . 'content/js/Umapper.js', array('UmapperInit', 'jquery'), '1.0');
  120. //wp_enqueue_script('UmapperString', Umapper_Plugin::getPluginUri() . 'content/js/UmapperString.js', array('UmapperInit'), '1.0');
  121. wp_enqueue_script('UmapperRpc', Umapper_Plugin::getPluginUri() . 'content/js/jquery.rpc.js', array('jquery'), '1.0');
  122. wp_enqueue_script('UmapperAjax', Umapper_Plugin::getPluginUri() . 'content/js/UmapperAjax.js', array('UmapperRpc', 'UmapperInit', 'jquery-ui-tabs', 'jquery-ui-core', 'jquery-ui-dialog'), '1.0');
  123. // make sure that JS speaks multilingual
  124. wp_localize_script('UmapperInit', 'umaptxt', array(
  125. 'REQ_BEING_PROCESSED' => __('Request is being processed..', 'umapper'),
  126. 'OBTAIN_SESSION' => __('Obtaining UMapper session..', 'umapper'),
  127. 'VIEWS' => __('views', 'umapper'),
  128. 'DELETE_MAP' => __('Delete Map', 'umapper'),
  129. 'EDIT_MAP_META' => __('Edit Info', 'umapper'),
  130. 'CREATE_NEW_MAP' => __('Create New Map', 'umapper'),
  131. 'MAP_DATA_UPDATED' => __('Map data updated..', 'umapper'),
  132. ));
  133. wp_enqueue_script('jquery-ui-dialog');
  134. /*
  135. wp_localize_script('UmapperString', 'umaptxt', array(
  136. 'test' => __('UMapper requires API key.', 'umapper')
  137. ));
  138. //*/
  139. }
  140. /**
  141. * admin_print_styles
  142. * Runs in the HTML header so a plugin can add CSS/Stylesheets to all admin pages.
  143. *
  144. * @return void
  145. */
  146. public function adminPrintStyles()
  147. {
  148. wp_enqueue_style('UmapperStyleAdmin', Umapper_Plugin::getPluginUri() . 'content/css/admin.compact.css', false, '1.0', 'all');
  149. }
  150. /**
  151. * admin_head
  152. * Runs in the HTML <head> section of the admin panel.
  153. *
  154. * @return void
  155. */
  156. public function adminHead()
  157. {
  158. /*
  159. ?>
  160. <script type="text/javascript">
  161. //<![CDATA[
  162. jQuery(document).ready(function($){
  163. $('#user_info').append('this is a test');
  164. });
  165. //]]>
  166. </script>
  167. <?php
  168. //*/
  169. }
  170. /**
  171. * admin_head - custom head code for U form
  172. * Runs in the HTML <head> section of the admin panel.
  173. *
  174. * @return void
  175. */
  176. public function adminHeadForm()
  177. {
  178. Umapper_Page_Dialogue::getInstance()->show('Head');
  179. }
  180. /**
  181. * admin_head - custom head code for U token obtaining
  182. * Runs in the HTML <head> section of the admin panel.
  183. *
  184. * @return void
  185. */
  186. public function adminHeadToken()
  187. {
  188. Umapper_Page_Token::getInstance()->show('Head');
  189. }
  190. /**
  191. * media_buttons
  192. * Add UMapper media button to the list
  193. *
  194. * @return void
  195. */
  196. public function mediaButtons()
  197. {
  198. global $post_ID, $temp_ID;
  199. $umapFrameSrc = apply_filters('media_umapper_iframe_src', 'post_id=' . ((int) (0 == $post_ID ? $temp_ID : $post_ID)) . '&amp;type=umapper');
  200. $title = __('Add UMapper Map', 'umapper');
  201. // $btn = '<a id="add_umap" class="thickbox" onclick="return false;" '
  202. // . 'title="' . $title . '" '
  203. // . 'href="media-upload.php?' . $umapFrameSrc . '&TB_iframe=true&height=440&width=640">'
  204. // . '<img src="' . Umapper_Plugin::getPluginUri() . 'content/img/umapper.gif" alt="' . $title . '" title="' . $title . '"/></a>';
  205. $btn = '<a id="add_umap" class="thickbox" onclick="return false;" '
  206. . 'title="' . $title . '" '
  207. . 'href="' . Umapper_Plugin::getPluginUri() . 'token.php?' . $umapFrameSrc . '&TB_iframe=true&height=440&width=640">'
  208. . '<img src="' . Umapper_Plugin::getPluginUri() . 'content/img/umapper.gif" alt="' . $title . '" title="' . $title . '"/></a>';
  209. echo $btn;
  210. }
  211. /**
  212. * media_upload_umapper
  213. * Creates iframe content for Meta page
  214. * @param boolean $doIframe Whether to create iframe or its contents
  215. *
  216. * @return void
  217. */
  218. public function mediaUploadUmapper($doIframe = true)
  219. {
  220. require_once dirname(__FILE__) . '/../../patches.php';
  221. require_once dirname(__FILE__) . '/Page/Dialogue.php';
  222. require_once dirname(__FILE__) . '/Shortcode.php';
  223. if($doIframe == 2) {
  224. Umapper_Page_Dialogue::getInstance()->show();
  225. } else {
  226. $this->adminEnqueueScripts('umapper'); // /wp-admin/includes/media.php is quite buggy - it prints scripts but doesn't enqueue
  227. add_action('admin_head', array($this, 'adminHeadForm'));
  228. patch_wp_iframe(array($this, 'mediaUploadUmapper'), 2);
  229. }
  230. }
  231. /**
  232. * media_upload_umapper_token
  233. * Creates iframe content for token getting page
  234. * @param boolean $doIframe Whether to create iframe or its contents
  235. *
  236. * @return void
  237. */
  238. public function mediaUploadUmapperToken($doIframe = true)
  239. {
  240. require_once dirname(__FILE__) . '/../../patches.php';
  241. require_once dirname(__FILE__) . '/Page/Token.php';
  242. if($doIframe == 2) {
  243. Umapper_Page_Token::getInstance()->show();
  244. } else {
  245. $this->adminEnqueueScripts('umapper'); // /wp-admin/includes/media.php is quite buggy - it prints scripts but doesn't enqueue
  246. add_action('admin_head', array($this, 'adminHeadToken'));
  247. patch_wp_iframe(array($this, 'mediaUploadUmapperToken'), 2);
  248. }
  249. }
  250. }