/lava/_classes/lavaPages.php

https://github.com/volcanicpixels/Privacy-Plugin · PHP · 360 lines · 198 code · 56 blank · 106 comment · 19 complexity · c78f55d20f0890a96f3c63b564baf432 MD5 · raw file

  1. <?php
  2. /**
  3. * The lavaPages class
  4. *
  5. * This class is the controller for the plugin admin pages
  6. *
  7. * @package Lava
  8. * @subpackage lavaPages
  9. *
  10. * @author Daniel Chatfield
  11. * @copyright 2011
  12. * @version 1.0.0
  13. */
  14. /**
  15. * lavaPages
  16. *
  17. * @package Lava
  18. * @subpackage LavaPages
  19. * @author Daniel Chatfield
  20. *
  21. * @since 1.0.0
  22. */
  23. class lavaPages extends lavaBase
  24. {
  25. protected $adminPages = array();
  26. protected $defaultPage;
  27. public $styles = array(), $scripts = array();
  28. /**
  29. * lavaPages::lavaConstruct()
  30. *
  31. * @return void
  32. *
  33. * @since 1.0.0
  34. */
  35. function lavaConstruct()
  36. {
  37. $this->addStyle( $this->_slug( "lavaStyles" ), "lava/_static/styles.css" );
  38. $this->addStyle( $this->_slug( "dropkick" ), "lava/_static/dropkick.css" );
  39. $this->addStyle( $this->_slug( "codemirror" ), "lava/_static/codemirror/codemirror.css" );
  40. $this->addStyle( $this->_slug( "codemirror-theme" ), "lava/_static/codemirror/codemirror.theme.css" );
  41. $this->addStyle( $this->_slug( "lobster" ), "http://fonts.googleapis.com/css?family=Lobster" );
  42. //$this->addStyle( $this->_slug( "colorpicker-theme" ), "lava/_static/colorpicker/colorpicker.css" );
  43. $this->addScript( $this->_slug( "lavaScripts" ), "lava/_static/scripts.js", array( "jquery" ) );
  44. $this->addScript( $this->_slug( "lavaScriptsNew" ), "lava/_static/scripts_new.js", array( "jquery" ) );
  45. $this->addScript( $this->_slug( "dropkick" ), "lava/_static/dropkick.js", array( "jquery" ) );
  46. $this->addScript( $this->_slug( "modernizr" ), "lava/_static/modernizr.js" );
  47. $this->addScript( $this->_slug( "tiptip" ), "lava/_static/tiptip.js", array( "jquery" ) );
  48. $this->addScript( $this->_slug( "jquery-color" ), "lava/_static/jquery.color.js", array( "jquery" ) );
  49. $this->addScript( $this->_slug( "jquery-resize" ), "lava/_static/jquery.resize.js", array( "jquery" ) );
  50. $this->addScript( $this->_slug( "jquery-fileupload") , "lava/_static/jquery.fileupload.js", array( "jquery", "jquery-ui-core", "jquery-ui-widget", $this->_slug( "jquery-iframe-transport" ) ) );
  51. $this->addScript( $this->_slug( "jquery-iframe-transport" ), "lava/_static/jquery.iframe-transport.js", array( "jquery" ) );
  52. $this->addScript( $this->_slug( "codemirror" ), "lava/_static/codemirror/codemirror.js" );
  53. $this->addScript( $this->_slug( "codemirror-css" ), "lava/_static/codemirror/codemirror.css.js" );
  54. $this->addScript( $this->_slug( "colorpicker" ), "lava/_static/autoResize.js", array( "jquery" ) );
  55. //$this->addScript( $this->_slug( "colorpicker" ), "lava/_static/colorpicker/colorpicker.js" );
  56. add_action( "admin_enqueue_scripts", array( $this, "registerIncludes" ) );
  57. add_action( "admin_menu", array( $this, "registerPages") );
  58. if( is_multisite() )
  59. add_action( "network_admin_menu", array( $this, "registerNetworkPages" ) );
  60. }
  61. /**
  62. * addPage function.
  63. *
  64. * This function adds an admin page
  65. *
  66. * @param mixed $slug
  67. * @param string $type (default: "")
  68. * @return void
  69. *
  70. * @since 1.0.0
  71. */
  72. function addPage( $slug, $type = "", $slugify = true )
  73. {
  74. if( true == $slugify )
  75. {
  76. $slug = $this->_slug( $slug );
  77. }
  78. if( !isset( $this->adminPages[ $slug] ) )
  79. {
  80. $arguments = array( $slug );
  81. $this->adminPages[ $slug ] = $this->_new( "lava{$type}Page", $arguments );
  82. }
  83. $this->chain[ "current" ] = $this->adminPages[ $slug ];
  84. if( empty( $this->defaultPage ) )// If a default page (the page that displays when the main page is clicked) hasn't been set then set it (otherwise a blank page will be displayed).
  85. {
  86. $this->defaultPage = $this->adminPages[ $slug ];
  87. }
  88. return $this;
  89. }
  90. /**
  91. * fetchPage function.
  92. *
  93. * @access public
  94. * @param mixed $slug
  95. * @return void
  96. *
  97. * @since 1.0.0
  98. */
  99. function fetchPage( $slug )
  100. {
  101. unset( $this->chain[ "current" ] );
  102. if( isset( $this->adminPages[ $slug ] ) )
  103. {
  104. $this->chain[ "current" ] = $this->adminPages[ $slug ];
  105. }
  106. $slug = $this->_slug( $slug );
  107. if( isset( $this->adminPages[ $slug ] ) )
  108. {
  109. $this->chain[ "current" ] = $this->adminPages[ $slug ];
  110. }
  111. return $this;
  112. }
  113. function pageExists( $slug )
  114. {
  115. if( isset( $this->adminPages[ $slug ] ) )
  116. {
  117. return true;
  118. }
  119. $slug = $this->_slug( $slug );
  120. if( isset( $this->adminPages[ $slug ] ) )
  121. {
  122. return true;
  123. }
  124. return false;
  125. }
  126. function adminPages( $filter = true )
  127. {
  128. $adminPages = $this->adminPages;
  129. if( true == $filter and defined( 'WP_NETWORK_ADMIN') and WP_NETWORK_ADMIN == true )
  130. {
  131. $adminPages = array();
  132. foreach( $this->adminPages as $slug=>$page )
  133. {
  134. if( true == $page->multisiteSupport )
  135. {
  136. $adminPages[$slug] = $page;
  137. }
  138. }
  139. }
  140. return apply_filters( "admin_pages_order-".$this->_slug(), $adminPages );
  141. }
  142. function addPageFromTemplate( $slug, $template )
  143. {
  144. return $this->addPage( $slug );
  145. }
  146. /**
  147. * addAboutPage function.
  148. *
  149. * @access public
  150. * @return void
  151. */
  152. function addAboutPage( $slug = "about" )
  153. {
  154. $this ->addPage( $slug, "About" )
  155. ->setTitle( sprintf( __( "About %s", $this->_framework() ), $this->_name() ) );
  156. return $this;
  157. }
  158. /**
  159. * addSettingsPage function.
  160. *
  161. * @access public
  162. * @return void
  163. */
  164. function addSettingsPage( $slug = "settings" )
  165. {
  166. $this ->addPage( $slug, "Settings" )
  167. /* translators: This is the title of the settings page */
  168. ->setTitle( __( "Plugin Settings", $this->_framework() ) );
  169. return $this;
  170. }
  171. /**
  172. * addSkinsPage function.
  173. *
  174. * @param string $slug (default: "skins") - to be appended to the plugin slug to make the url
  175. * @return void
  176. */
  177. function addSkinsPage( $slug = "skins" )
  178. {
  179. $this->_skins( false );
  180. $this ->addPage( $slug, "Skins" )
  181. /* translators: This is the title of the settings page */
  182. ->setTitle( __( "Skins", $this->_framework() ) )
  183. ;
  184. return $this;
  185. }
  186. /**
  187. * addTablePage function.
  188. *
  189. * @access public
  190. * @param mixed $slug (default: "table") - to be appended to the plugin slug to make the url
  191. * @return void
  192. * @since 1.0.0
  193. */
  194. function addTablePage( $slug = "table" )
  195. {
  196. $this ->addPage( $slug, "Table" )
  197. ->setTitle( __( "Table", $this->_framework() ) )
  198. ;
  199. return $this;
  200. }
  201. /**
  202. * defaultPage function.
  203. * Sets the currently chained page as the one to be displayed when the top-level page is clicked.
  204. *
  205. * @return void
  206. * @since 1.0.0
  207. */
  208. function defaultPage()
  209. {
  210. if( isset( $this->chain[ "current" ] ) )
  211. {
  212. $this->defaultPage = $this->chain[ "current" ];
  213. }
  214. return $this;
  215. }
  216. /**
  217. * registerPages function.
  218. * Registers each of the admin pages
  219. *
  220. * @return void
  221. * @since 1.0.0
  222. */
  223. function registerPages()
  224. {
  225. $defaultPage = $this->defaultPage;
  226. //register the main page
  227. add_menu_page( $defaultPage->get( "title" ), $this->_name(), $defaultPage->get( "capability" ), $defaultPage->get( "slug" ), array( $defaultPage, "doPage" ) );
  228. $parentSlug = $defaultPage->get( "slug" );
  229. //register each subpage
  230. foreach( $this->adminPages as $page )
  231. {
  232. $page->registerPage( $parentSlug );
  233. }
  234. }
  235. /**
  236. * registerNetworkPages function.
  237. * Registers each of the admin pages
  238. *
  239. * @return void
  240. * @since 1.0.0
  241. */
  242. function registerNetworkPages()
  243. {
  244. }
  245. function addStyle( $name, $path = "" )
  246. {
  247. $include = array(
  248. 'path' => $path
  249. );
  250. $this->styles[ $name ] = $include;
  251. return $this;
  252. }
  253. function addScript( $name, $path = "", $dependencies = array() )
  254. {
  255. $include = array(
  256. 'path' => $path,
  257. 'dependencies' => $dependencies
  258. );
  259. $this->scripts[ $name ] = $include;
  260. return $this;
  261. }
  262. /**
  263. * lavaPages::registerIncludes()
  264. *
  265. * @return void
  266. */
  267. function registerIncludes()
  268. {
  269. foreach( $this->scripts as $name => $include )
  270. {
  271. $path = $include['path'];
  272. $dependencies = $include['dependencies'];
  273. if( !empty( $path ) )
  274. {
  275. if( strpos( $path, 'http' ) === false ) {
  276. $path = plugins_url( $path, $this->_file() );
  277. }
  278. wp_register_script( $name, $path, $dependencies );
  279. }
  280. }
  281. foreach( $this->styles as $name => $include )
  282. {
  283. $path = $include['path'];
  284. if( !empty( $path ) )
  285. {
  286. if( strpos( $path, "http" ) === false ) {
  287. $path = plugins_url( $path, $this->_file() );
  288. }
  289. wp_register_style( $name, $path );
  290. }
  291. }
  292. }
  293. function addCustomStyles()
  294. {
  295. $this->addStyle( $this->_slug( "Pluginstyles" ), "_static/styles.css" );
  296. return $this;
  297. }
  298. function addCustomScripts()
  299. {
  300. $this->addScript($this->_slug( "pluginScripts" ), "_static/scripts.js");
  301. return $this;
  302. }
  303. }
  304. ?>