/core.php

  1. <?php 
  2. /** 
  3. * Facebook Fanpage Import Core Class 
  4. * 
  5. * This class initializes the Plugin. 
  6. * 
  7. * @author mahype, awesome.ug <very@awesome.ug> 
  8. * @package Facebook Fanpage Import 
  9. * @version 1.0.0 
  10. * @since 1.0.0 
  11. * @license GPL 2 
  12.   
  13. Copyright 2015 Awesome UG (very@awesome.ug) 
  14.   
  15. This program is free software; you can redistribute it and/or modify 
  16. it under the terms of the GNU General Public License, version 2, as  
  17. published by the Free Software Foundation. 
  18.   
  19. This program is distributed in the hope that it will be useful,  
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  22. GNU General Public License for more details. 
  23.   
  24. You should have received a copy of the GNU General Public License 
  25. along with this program; if not, write to the Free Software 
  26. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
  27.   
  28. */ 
  29.  
  30. if ( !defined( 'ABSPATH' ) ) exit; 
  31.  
  32. use skip\v1_0_0 as skip; 
  33.  
  34. class FacebookFanpageImport { 
  35.  
  36. /** 
  37. * Initializes the plugin. 
  38. * @since 1.0.0 
  39. */ 
  40. function __construct() { 
  41. $this->constants(); 
  42. $this->includes(); 
  43. $this->framework(); 
  44.  
  45. add_action( 'init', array( $this, 'load_components' ) ); 
  46. add_action( 'init', array( $this, 'load_textdomain' ) ); 
  47.  
  48. // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively. 
  49. register_activation_hook( __FILE__, array( $this, 'activate' ) ); 
  50. register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); 
  51. // register_uninstall_hook( __FILE__, array( $this, 'uninstall' ) ); 
  52.  
  53. // Functions on Frontend 
  54. if( is_admin() ): 
  55. // Register admin styles and scripts 
  56. add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) ); 
  57. add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) ); 
  58. else: 
  59. // Register plugin styles and scripts 
  60. add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); 
  61. add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) ); 
  62. endif; 
  63. } // end constructor 
  64.  
  65. /** 
  66. * Fired when the plugin is activated. 
  67. * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog 
  68. * @since 1.0.0  
  69. */ 
  70. public function activate( $network_wide ) { 
  71. // TODO: Define activation functionality here 
  72. } // end activate 
  73.  
  74. /** 
  75. * Fired when the plugin is deactivated. 
  76. * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog  
  77. */ 
  78. public function deactivate( $network_wide ) { 
  79. // TODO: Define deactivation functionality here  
  80. } // end deactivate 
  81.  
  82. /** 
  83. * Fired when the plugin is uninstalled. 
  84. * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog 
  85. * @since 1.0.0  
  86. */ 
  87. public function uninstall( $network_wide ) { 
  88. // TODO: Define uninstall functionality here  
  89. } // end uninstall 
  90.  
  91. /** 
  92. * Loads the plugin text domain for translation. 
  93. * @since 1.0.0 
  94. */ 
  95. public function load_textdomain() { 
  96. // TODO: replace "plugin-name-locale" with a unique value for your plugin 
  97. load_plugin_textdomain( 'fbfpi', false, FBFPI_RELATIVE_FOLDER . '/languages' ); 
  98. } // end plugin_textdomain 
  99.  
  100. /** 
  101. * Registers and enqueues admin-specific styles. 
  102. * @since 1.0.0 
  103. */ 
  104. public function register_admin_styles() { 
  105. // TODO: Change 'plugin-name' to the name of your plugin 
  106. wp_enqueue_style( 'fbfpi-admin-styles', FBFPI_URLPATH . '/includes/css/admin.css' ); 
  107.  
  108. } // end register_admin_styles 
  109.  
  110. /** 
  111. * Registers and enqueues admin-specific JavaScript. 
  112. * @since 1.0.0 
  113. */  
  114. public function register_admin_scripts() { 
  115. wp_enqueue_script( 'fbfpi-admin-script', FBFPI_URLPATH . '/includes/js/admin.js' ); 
  116.  
  117. } // end register_admin_scripts 
  118.  
  119. /** 
  120. * Registers and enqueues plugin-specific styles. 
  121. * @since 1.0.0 
  122. */ 
  123. public function register_plugin_styles() { 
  124. if( '' == skip\value( 'fbfpi_settings', 'own_css' ) ) 
  125. wp_enqueue_style( 'fbfpi-plugin-styles', FBFPI_URLPATH . '/includes/css/display.css' ); 
  126.  
  127. } // end register_plugin_styles 
  128.  
  129. /** 
  130. * Registers and enqueues plugin-specific scripts. 
  131. * @since 1.0.0 
  132. */ 
  133. public function register_plugin_scripts() { 
  134. wp_enqueue_script( 'fbfpi-plugin-script', FBFPI_URLPATH . '/includes/js/display.js' ); 
  135.  
  136. } // end register_plugin_scripts 
  137.  
  138. /** 
  139. * Defining Constants for Use in Plugin 
  140. * @since 1.0.0 
  141. */ 
  142. public function constants() { 
  143. define( 'FBFPI_FOLDER', $this->get_folder() );  
  144. define( 'FBFPI_RELATIVE_FOLDER', substr( FBFPI_FOLDER, strlen( WP_PLUGIN_DIR ), strlen( FBFPI_FOLDER ) ) );  
  145. define( 'FBFPI_URLPATH', $this->get_url_path() ); 
  146. define( 'FBFPI_COMPONENTFOLDER', FBFPI_FOLDER . '/components' ); 
  147.  
  148. /** 
  149. * Defining Constants for Use in Plugin 
  150. * @since 1.0.0 
  151. */ 
  152. public function framework() { 
  153. // Loading Skip 
  154. include( FBFPI_FOLDER . '/includes/skip/loader.php' );  
  155. skip\start(); 
  156. }  
  157.  
  158. /** 
  159. * Getting include files 
  160. * @since 1.0.0 
  161. */ 
  162. public function includes() { 
  163. // Loading functions 
  164. include( FBFPI_FOLDER . '/functions.php' ); 
  165.  
  166. /** 
  167. * Loading components dynamical 
  168. * @since 1.0.0 
  169. */ 
  170. function load_components() { 
  171. // Loading Components 
  172. $handle = opendir( FBFPI_COMPONENTFOLDER ); // TODO: Rename Constant 
  173.  
  174. while ( FALSE !== ( $file = readdir( $handle) ) ): 
  175. $entry = FBFPI_COMPONENTFOLDER . '/' . $file; 
  176. if( is_dir( $entry ) && '.' != $file && '..' != $file ) 
  177. if( file_exists( $entry . '/component.php' ) ) 
  178. include( $entry . '/component.php' ); 
  179. endwhile; 
  180.  
  181. closedir($handle); 
  182.  
  183. /** 
  184. * Getting URL 
  185. * @since 1.0.0 
  186. */ 
  187. private function get_url_path() { 
  188. $sub_path = substr( FBFPI_FOLDER, strlen( ABSPATH ), ( strlen( FBFPI_FOLDER ) - 11 ) ); 
  189. $script_url = get_bloginfo( 'wpurl' ) . '/' . $sub_path; 
  190. return $script_url; 
  191.  
  192. /** 
  193. * Getting Folder 
  194. * @since 1.0.0 
  195. */ 
  196. private function get_folder() { 
  197. $sub_folder = substr( dirname(__FILE__), strlen( ABSPATH ), ( strlen( dirname(__FILE__) ) - strlen( ABSPATH ) ) ); 
  198. $script_folder = ABSPATH . $sub_folder; 
  199. return $script_folder; 
  200.  
  201. } // end class 
  202.  
  203. $FacebookFanpageImport = new FacebookFanpageImport(); 
.