Yoast_Social_Facebook_Form

This will display the HTML for the facebook insights part.

Defined (1)

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

/admin/class-social-facebook.php  
  1. class Yoast_Social_Facebook_Form { 
  2.  
  3. /** 
  4. * @var array - The options for social 
  5. */ 
  6. private $options; 
  7.  
  8. /** 
  9. * @var array - The repository for the buttons that will be shown 
  10. */ 
  11. private $buttons = array(); 
  12.  
  13. /** 
  14. * @var string - The URL to link to 
  15. */ 
  16. private $admin_url = 'admin.php?page=wpseo_social'; 
  17.  
  18. /** 
  19. * Setting the options and call the methods to display everything 
  20. */ 
  21. public function __construct() { 
  22. $this->options = get_option( 'wpseo_social' ); 
  23.  
  24. /** 
  25. * Returns the output-property 
  26. */ 
  27. public function show_form() { 
  28. $this 
  29. ->form_head() 
  30. ->manage_user_admin() 
  31. ->form_thickbox() 
  32. ->show_buttons() 
  33. ->manage_app_as_admin(); 
  34.  
  35. /** 
  36. * Parses the admin_link 
  37. * @param string $admin_id Facebook admin ID string. 
  38. * @param array $admin Admin data array. 
  39. * @param string|bool $nonce Optional nonce string. 
  40. * @return string 
  41. */ 
  42. public function get_admin_link( $admin_id, $admin, $nonce = false ) { 
  43. if ( $nonce === false ) { 
  44. $nonce = $this->get_delete_nonce(); 
  45.  
  46. $return = '<li><a target="_blank" href="' . esc_url( $admin['link'] ) . '">' . esc_html( $admin['name'] ) . '</a>'; 
  47. $return .= ' - <strong><a href="' . $this->admin_delete_link( $admin_id, $nonce ) . '">X</a></strong></li>'; 
  48.  
  49. return $return; 
  50.  
  51. /** 
  52. * SHow the top of the social insights part of the page 
  53. * @return $this 
  54. */ 
  55. private function form_head() { 
  56. echo '<h2>' . esc_html__( 'Facebook Insights and Admins', 'wordpress-seo' ) . '</h2>'; 
  57. echo '<p>', sprintf( 
  58. /** translators: %1$s and %2$s expand to a link to Facebook Insights */ 
  59. esc_html__( 'To be able to access %1$sFacebook Insights%2$s for your site, you need to specify a Facebook Admin. This can be a user. If you have an app for your site, you could use that as well.', 'wordpress-seo' ),  
  60. '<a target="_blank" href="https://www.facebook.com/insights">',  
  61. '</a>' 
  62. ); 
  63. echo ' '; 
  64. /** translators: %1$s and %2$s expand to a link to the Yoast Knowledge Base */ 
  65. printf( __( 'More info can be found %1$son our knowledge base%2$s.', 'wordpress-seo' ), '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/facebook-insights' ) . '">', '</a>' ); 
  66. echo '</p>'; 
  67.  
  68. return $this; 
  69.  
  70. /** 
  71. * Show the form inside the thickbox 
  72. */ 
  73. private function form_thickbox() { 
  74. // Adding the thickbox. 
  75. add_thickbox(); 
  76.  
  77. echo '<div id="add_facebook_admin" class="hidden">'; 
  78. echo "<div class='form-wrap wpseo_content_wrapper wpseo-add-fb-admin-form-wrap'>"; 
  79. echo '<p>'; 
  80. /** translators: %1$s and %2$s expand to a link to Facebook Insights */ 
  81. printf( __( 'To be able to access %1$sFacebook Insights%2$s, you need to add a user here. The name is used for reference only, the ID is used for verification.', 'wordpress-seo' ), '<a target="_blank" href="https://www.facebook.com/insights">', '</a>' ); 
  82. echo '</p>'; 
  83. echo '<p>'; 
  84. /** translators: %1$s and %2$s expand to a link to the Yoast Knowledge Base */ 
  85. printf( __( 'If you don\'t know where to find the needed ID, see %1$sthis knowledge base article%2$s.', 'wordpress-seo' ), '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/facebook-insights' ) . '">', '</a>' ); 
  86. echo '</p>'; 
  87. echo '<div class="form-field form-required">'; 
  88. echo '<label for="fb_admin_name">' . __( 'Admin\'s name:', 'wordpress-seo' ) . '</label>'; 
  89. echo '<input type="text" id="fb_admin_name" name="fb_admin_name" value="" maxlength="255" />'; 
  90. echo '</div>'; 
  91. echo '<div class="form-field form-required">'; 
  92. echo '<label for="fb_admin_id">' . __( 'Admin\'s Facebook user ID:', 'wordpress-seo' ) . '</label>'; 
  93. echo '<input type="text" id="fb_admin_id" name="fb_admin_id" value="" maxlength="255" />'; 
  94. echo '</div>'; 
  95. echo "<p class='submit'>"; 
  96. echo '<input type="hidden" name="fb_admin_nonce" value="' . wp_create_nonce( 'wpseo_fb_admin_nonce' ) . '" />'; 
  97. echo '<input type="submit" value="' . __( 'Add Facebook admin', 'wordpress-seo' ) . '" class="button button-primary" onclick="javascript:wpseo_add_fb_admin();" />'; 
  98. echo '</p>'; 
  99. echo '</div>'; 
  100. echo '</div>'; 
  101.  
  102. return $this; 
  103.  
  104. /** 
  105. * Display the buttons to add an admin or add another admin from Facebook and display the admin that has been added already. 
  106. * @return $this 
  107. */ 
  108. private function manage_user_admin() { 
  109. $button_text = __( 'Add Facebook admin', 'wordpress-seo' ); 
  110. $nonce = false; 
  111. $class_attr = ' class="hidden"'; 
  112.  
  113. if ( is_array( $this->options['fb_admins'] ) && $this->options['fb_admins'] !== array() ) { 
  114. $nonce = $this->get_delete_nonce(); 
  115. $button_text = __( 'Add Another Facebook Admin', 'wordpress-seo' ); 
  116. $class_attr = ''; 
  117.  
  118. echo "<div id='connected_fb_admins'{$class_attr}>"; 
  119. echo '<p>' . __( 'Currently connected Facebook admins:', 'wordpress-seo' ) . '</p>'; 
  120. echo '<ul id="user_admin">'; 
  121. $this->show_user_admins( $nonce ); 
  122. echo '</ul>'; 
  123. echo '</div>'; 
  124.  
  125. unset( $nonce ); 
  126.  
  127. $this->add_button( 
  128. array( 
  129. 'url' => '#TB_inline?width=600&height=350&inlineId=add_facebook_admin',  
  130. 'value' => $button_text,  
  131. 'class' => 'thickbox',  
  132. 'title' => $button_text,  
  133. ); 
  134.  
  135. return $this; 
  136.  
  137. /** 
  138. * Show input field to set a facebook apps as an admin 
  139. * @return $this 
  140. */ 
  141. private function manage_app_as_admin() { 
  142. echo '<div class="clear"></div><br />'; 
  143. Yoast_Form::get_instance()->textinput( 'fbadminapp', __( 'Facebook App ID', 'wordpress-seo' ) ); 
  144.  
  145. return $this; 
  146.  
  147. /** 
  148. * Loop through the fb-admins to parse the output for them 
  149. * @param string $nonce Nonce string. 
  150. */ 
  151. private function show_user_admins( $nonce ) { 
  152. foreach ( $this->options['fb_admins'] as $admin_id => $admin ) { 
  153. echo $this->get_admin_link( $admin_id, $admin, $nonce ); 
  154.  
  155. /** 
  156. * Parsing the link that directs to the admin removal 
  157. * @param string $admin_id Facebook admin ID. 
  158. * @param string $nonce Nonce string. 
  159. * @return string 
  160. */ 
  161. private function admin_delete_link( $admin_id, $nonce ) { 
  162. return esc_url( 
  163. add_query_arg( 
  164. array( 
  165. 'delfbadmin' => esc_attr( $admin_id ),  
  166. 'nonce' => $nonce,  
  167. ),  
  168. admin_url( $this->admin_url . '#top#facebook' ) 
  169. ); 
  170.  
  171. /** 
  172. * Adding a button to the button property 
  173. * @param array $args Arguments data array. 
  174. */ 
  175. private function add_button( $args ) { 
  176. $args = wp_parse_args( 
  177. $args,  
  178. array( 
  179. 'url' => '',  
  180. 'value' => '',  
  181. 'class' => '',  
  182. 'id' => '',  
  183. 'title' => '',  
  184.  
  185. ); 
  186.  
  187. $this->buttons[] = '<a title="' . esc_attr( $args['title'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="button ' . esc_attr( $args['class'] ) . '" href="' . esc_url( $args['url'] ) . '">' . esc_html( $args['value'] ) . '</a>'; 
  188.  
  189. /** 
  190. * Showing the buttons 
  191. */ 
  192. private function show_buttons() { 
  193. if ( $this->get_clearall() ) { 
  194. $this->add_button( 
  195. array( 
  196. 'url' => add_query_arg( array( 
  197. 'nonce' => wp_create_nonce( 'fbclearall' ),  
  198. 'fbclearall' => 'true',  
  199. ), admin_url( $this->admin_url . '#top#facebook' ) ),  
  200. 'value' => __( 'Clear all Facebook Data', 'wordpress-seo' ),  
  201. ); 
  202.  
  203. if ( is_array( $this->buttons ) && $this->buttons !== array() ) { 
  204. echo '<p class="fb-buttons">' . implode( '', $this->buttons ) . '</p>'; 
  205.  
  206. return $this; 
  207.  
  208. /** 
  209. * Check if the clear button should be displayed. This is based on the set options. 
  210. * @return bool 
  211. */ 
  212. private function get_clearall() { 
  213. return is_array( $this->options['fb_admins'] ) && $this->options['fb_admins'] !== array(); 
  214.  
  215. /** 
  216. * Creates nonce for removal link 
  217. * @return mixed 
  218. */ 
  219. private function get_delete_nonce() { 
  220. return wp_create_nonce( 'delfbadmin' );