FacebookFanpageImportAdminSettings

The Facebook Fanpage Import FacebookFanpageImportAdminSettings class.

Defined (1)

The class is defined in the following location(s).

/components/admin/settings.php  
  1. class FacebookFanpageImportAdminSettings{ 
  2. var $name; 
  3. var $errors = array(); 
  4.  
  5. /** 
  6. * Initializes the Component. 
  7. * @since 1.0.0 
  8. */ 
  9. function __construct() { 
  10. $this->name = get_class( $this ); 
  11.  
  12. // Functions in Admin 
  13. if( is_admin() ): 
  14. add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 
  15. endif; 
  16.  
  17. if( '' != skip\value( 'fbfpi_settings', 'app_id' ) && '' != skip\value( 'fbfpi_settings', 'app_secret' ) && '' != skip\value( 'fbfpi_settings', 'page_id' ) ): 
  18. $this->test_con(); 
  19. add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
  20. endif; 
  21.  
  22. } // end constructor 
  23.  
  24. /** 
  25. * Adds the Admin menu. 
  26. * @since 1.0.0 
  27. */  
  28. public function admin_menu() { 
  29. add_submenu_page( 'options-general.php', __( 'Facebook Fanpage Import Settings', 'fbfpi' ), __( 'Fanpage Import', 'fbfpi' ), 'activate_plugins', 'Component' . $this->name, array( $this, 'admin_page' ) ); 
  30.  
  31. public function test_con() { 
  32. // init app with app id (APPID) and secret (SECRET) 
  33.  
  34. /** 
  35. echo '<br /><br />Trying:'; 
  36.  
  37. try { 
  38. $session = $helper->getSessionFromRedirect(); 
  39. } catch( FacebookRequestException $ex ) { 
  40. print_r( $ex ); 
  41. } catch( Exception $ex ) { 
  42. // When validation fails or other local issues 
  43. print_r( $ex ); 
  44.  
  45. // see if we have a session 
  46. if ( isset( $session ) ) { 
  47. // graph api request for user data 
  48. $request = new FacebookRequest( $session, 'GET', '/me' ); 
  49. $response = $request->execute(); 
  50. // get response 
  51. $graphObject = $response->getGraphObject(); 
  52.  
  53. // print data 
  54. echo print_r( $graphObject, 1 ); 
  55. } else { 
  56. // show login url 
  57. echo '<a href="' . $helper->getLoginUrl() . '">Login</a>'; 
  58.  
  59.  
  60. /** 
  61. $app_id = skip_value( 'fbfpi_settings', 'app_id' ); 
  62. $app_secret = skip_value( 'fbfpi_settings', 'app_secret' ); 
  63. $page_id = skip_value( 'fbfpi_settings', 'page_id' ); 
  64.  
  65. $fb_args = array( 
  66. 'appId' => $app_id,  
  67. 'secret' => $app_secret 
  68. ); 
  69.  
  70. $fb = new Facebook( $fb_args ); 
  71.  
  72. try{ 
  73. $fb->api( '/' . $page_id . '?fields=name, link' ); 
  74. }catch( Exception $e ) { 
  75. $this->errors[] = sprintf( __( '<a href="%s">Data incorrect. Please check your Facebook App ID, App Secret and your Fanpage ID.</a>', 'fbfpi' ), get_bloginfo( 'wpurl' ) . '/wp-admin/options-general.php?page=ComponentFacebookFanpageImportAdminSettings' ); 
  76. */ 
  77.  
  78. /** 
  79. * Content of the admin page. 
  80. * @since 1.0.0 
  81. */ 
  82. public function admin_page() { 
  83. echo '<div class="wrap">'; 
  84.  
  85. echo '<div id="icon-options-general" class="icon32 icon32-posts-post"></div>'; 
  86. echo '<h2>' . __( 'Facebook Fanpage Import', 'fbfpi' ) . '</h2>'; 
  87. echo '<p>' . __( 'Just put in your Fanpage ID and start importing.', 'fbfpi' ) . '</p>'; 
  88.  
  89. skip\form_start( 'fbfpi_settings' ); 
  90.  
  91. /** 
  92. * Fanpage ID 
  93. */ 
  94. skip\textfield( 'page_id', __( 'Page ID', 'fbfpi' ) ); 
  95.  
  96. /** 
  97. * Select stream languages 
  98. */ 
  99. $available_languages = get_available_languages(); 
  100.  
  101. if( !in_array( 'en_US', $available_languages) ) 
  102. $available_languages[] = 'en_US'; 
  103.  
  104. foreach( $available_languages AS $language ) 
  105. $select_languages[] = array( 'value' => $language ); 
  106. skip\select( 'stream_language', $select_languages, __( 'Facebook Language', 'fbfpi' ) );  
  107.  
  108. /** 
  109. * Import WP Cron settings 
  110. */ 
  111. $schedules = wp_get_schedules(); // Getting WordPress schedules 
  112. foreach( $schedules AS $key => $schedule ) 
  113. $select_schedules[] = array( 'label' => $schedule[ 'display' ], 'value' => $key ); 
  114.  
  115. skip\select( 'update_interval', $select_schedules, __( 'Import Interval', 'fbfpi' ) ); 
  116.  
  117. /** 
  118. * Num of entries to import 
  119. */ 
  120. skip\select( 'update_num', '5, 10, 25, 50, 100, 200', __( 'Entries to import', 'fbfpi' ) ); 
  121.  
  122. /** 
  123. * Select where to import, as posts or as own post type 
  124. */ 
  125. $args = array( 
  126. array( 
  127. 'value' => 'posts',  
  128. 'label' => __( 'Posts' ) 
  129. ),  
  130. array( 
  131. 'value' => 'status',  
  132. 'label' => __( 'Status message (own post type)', 'fbfpi' ) 
  133. ); 
  134. skip\select( 'insert_post_type', $args, __( 'Insert Messages as', 'fbfpi' ) ); 
  135.  
  136. /** 
  137. * Select importing User 
  138. */ 
  139. $users = get_users( array( 'fields' => array( 'ID', 'display_name' ) ) ); 
  140. $user_list = array(); 
  141. foreach( $users AS $user ): 
  142. $user_list[] = array( 
  143. 'value' => $user->ID,  
  144. 'label' => $user->display_name 
  145. ); 
  146. endforeach; 
  147.  
  148. skip\select( 'insert_user_id', $user_list, __( 'Inserting User', 'fbfpi' ) ); 
  149.  
  150. /** 
  151. * Post status 
  152. */ 
  153. $post_status_values = array( 
  154. array( 
  155. 'value' => 'publish',  
  156. 'label' => __( 'Published' ) 
  157. ),  
  158. array( 
  159. 'value' => 'draft',  
  160. 'label' => __( 'Draft' ) 
  161. ),  
  162. ); 
  163.  
  164. skip\select( 'insert_post_status', $post_status_values, __( 'Post status', 'fbfpi' ) ); 
  165.  
  166. /** 
  167. * Link target for imported links 
  168. */ 
  169. $link_select_values = array( 
  170. array( 
  171. 'value' => '_self',  
  172. 'label' => __( 'same window', 'fbfpi' ) 
  173. ),  
  174. array( 
  175. 'value' => '_blank',  
  176. 'label' => __( 'new window', 'fbfpi' ) 
  177. ),  
  178. ); 
  179.  
  180. skip\select( 'link_target', $link_select_values, __( 'Open Links in', 'fbfpi' ) ); 
  181.  
  182. /** 
  183. * Selecting post formats if existing 
  184. */ 
  185. if ( current_theme_supports( 'post-formats' ) ): 
  186. $post_formats = get_theme_support( 'post-formats' ); 
  187.  
  188. if( FALSE != $post_formats ): 
  189. $post_formats = $post_formats[ 0 ]; 
  190. $post_format_list = array(); 
  191.  
  192. $post_format_list[] = array( 
  193. 'value' => 'none',  
  194. 'label' => __( '-- None --', 'fbfpi' ) 
  195. ); 
  196.  
  197. foreach( $post_formats as $post_format ): 
  198. $post_format_list[] = array( 
  199. 'value' => $post_format,  
  200. 'label' => $post_format 
  201. ); 
  202. endforeach; 
  203. skip\select( 'insert_post_format', $post_format_list, __( 'Post format', 'fbfpi' ) ); 
  204. endif; 
  205. endif; 
  206.  
  207. skip\checkbox( 'own_css', 'yes', __( 'Deactivate Plugin CSS', 'fbfpi' ) ); 
  208.  
  209. do_action( 'fbfpi_settings_form' ); 
  210.  
  211. /** 
  212. * Save Button 
  213. */ 
  214. skip\button( __( 'Save', 'fbfpi' ) ); 
  215.  
  216. /** 
  217. * Import button 
  218. */ 
  219. if( '' != skip\value( 'fbfpi_settings', 'page_id' ) ) 
  220. echo ' <input type="submit" name="bfpi-now" value="' . __( 'Import Now', 'fbfpi' ) . '" class="button" style="margin-left:10px;" /> ';  
  221.  
  222. skip\form_end(); 
  223.  
  224. echo '</div>'; 
  225.  
  226. public function admin_notices() { 
  227. if( count( $this->errors ) > 0 ): 
  228. foreach( $this->errors AS $error ) 
  229. echo '<div class="updated"><p>' . __( 'Facebook Fanpage Import', 'fbfpi' ) . ': ' . $error . '</p></div>'; 
  230. endif; 
  231.  
  232. if( count( $this->notices ) > 0 ): 
  233. foreach( $this->notices AS $notice ) 
  234. echo '<div class="updated"><p>' . __( 'Facebook Fanpage Import', 'fbfpi' ) . ': ' . $notice . '</p></div>'; 
  235. endif;  
  236. }