Caldera_Forms_Admin_Clippy

Sets up admin helpful messages.

Defined (1)

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

/classes/admin/clippy.php  
  1. class Caldera_Forms_Admin_Clippy { 
  2.  
  3. /** 
  4. * Handle for Javascript 
  5. * @since 1.4.5 
  6. * @var string 
  7. */ 
  8. protected $script_handle; 
  9.  
  10. /** 
  11. * Hashed version of URL to send 
  12. * @since 1.4.5 
  13. * @var string 
  14. */ 
  15. protected $url_hash; 
  16.  
  17. /** 
  18. * Caldera_Forms_Admin_Clippy constructor. 
  19. * @since 1.4.5 
  20. * @param string $plugin_slug Plugin slug 
  21. * @param string $url Current site URL 
  22. */ 
  23. public function __construct( $plugin_slug, $url ) { 
  24. $this->script_handle = $plugin_slug . '-clippy'; 
  25. $this->url_hash = md5( $url ); 
  26.  
  27. /** 
  28. * Setup JavaScript 
  29. * @since 1.4.5 
  30. */ 
  31. public function assets() { 
  32.  
  33. wp_enqueue_script( $this->script_handle, CFCORE_URL . 'assets/js/caldera-clippy.js', array( 'jquery' ), Caldera_Forms::VERSION ); 
  34. wp_localize_script( $this->script_handle, 'CF_CLIPPY', $this->localizer() ); 
  35.  
  36. /** 
  37. * Prepare data to localize 
  38. * @since 1.4.5 
  39. * @return array 
  40. */ 
  41. protected function localizer() { 
  42. $data = array( 
  43. 'api' => 'https://octaviabutler.caldera.space',  
  44. 'p1' => $this->randoms(),  
  45. 'p2' => $this->randoms(),  
  46. 'p3' => $this->randoms(),  
  47. 'url' => $this->url_hash,  
  48. 'l' => get_locale(),  
  49. 'fallback' => $this->fallback_clippy(),  
  50. 'template' => $this->template(),  
  51. 'email_clippy' => $this->email_clippy() 
  52. ); 
  53.  
  54. $forms = Caldera_Forms_Forms::get_forms(); 
  55. if( empty( $forms ) ) { 
  56. $data[ 'no_forms' ] = $this->create_form_clippy(); 
  57. unset( $data[ 'email_clippy' ] ); 
  58.  
  59. return $data; 
  60.  
  61. /** 
  62. * Create random string of digits for p tag 
  63. * @since 1.4.5 
  64. * @param int $length Optional. Length of string. Default is 4. 
  65. * @return string 
  66. */ 
  67. protected function randoms( $length = 4 ) { 
  68. $str = ''; 
  69. for( $i = 0; $i <= $length; $i++ ) { 
  70. $str .= rand( 1, 9 ); 
  71.  
  72. return $str; 
  73.  
  74.  
  75. /** 
  76. * Handlebars template for a clippy 
  77. * @since 1.4.5 
  78. * @return string 
  79. */ 
  80. protected function template() { 
  81. /** Don't unmifiy this!! */ 
  82. return '<div class="caldera-forms-clippy-zone-inner-wrap"><div class="caldera-forms-clippy" ><h2>{{title.content}}</h2><p>{{content.content}}</p><a href="{{link.url}}" data-bt={{link.bt}} target="_blank" class="bt-btn btn btn-{{btn.color}}">{{ btn.content }}</a></div></div>'; 
  83.  
  84.  
  85. /** 
  86. * Email stats clippy 
  87. * @since 1.4.5 
  88. * @return array 
  89. */ 
  90. protected function email_clippy() { 
  91. $clippy = array( 
  92. 'title' => array( 
  93. 'content' => __( 'Email Stats', 'caldera-forms' ),  
  94. ),  
  95. 'content' => array( 
  96. 'content' => '',  
  97. ),  
  98. 'btn' => array( 
  99. 'content' => __( 'Email Resources', 'caldera-forms' ),  
  100. 'grey' => 'orange' 
  101. ),  
  102. 'link' => array( 
  103. 'url' => 'https://calderaforms.com/caldera-forms-emails?utm_source=obs&utm_campaign=admin-page&utm_medium=caldera-forms&utm_term=fallback',  
  104. 'bt' => 'email-stats' 
  105. ); 
  106.  
  107. if( Caldera_Forms_Tracking::tracking_allowed() ) { 
  108. $stats = new Caldera_Forms_Email_TrackData(); 
  109. $stats = $stats->get_stats( ); 
  110. $clippy[ 'content' ][ 'content' ] = __( sprintf( 'Success rate for emails is %d percent of %s total emails', 100 * $stats[ 'success_rate' ], $stats[ 'total' ] ), 'caldera-forms' ); 
  111. }else{ 
  112. $url = Caldera_Forms_Tracking::allow_url(); 
  113. $clippy[ 'content' ][ 'content' ] = __( 'Enable usage tracking to get email stats.', 'caldera-forms' ); 
  114. $clippy[ 'link' ][ 'url' ] = add_query_arg( 'clippy', 1, $url ); 
  115. $clippy[ 'link' ][ 'bt' ] = 'tracking-optin'; 
  116.  
  117.  
  118. return $clippy; 
  119.  
  120. protected function create_form_clippy() 
  121. $clippy = array( 
  122. 'title' => array( 
  123. 'content' => __( 'Need Help Creating A Form?', 'caldera-forms' ),  
  124. ),  
  125. 'content' => array( 
  126. 'content' => 'Click the "New Form" button at the top of the page, or read or getting started guide for creating forms.',  
  127. ),  
  128. 'btn' => array( 
  129. 'content' => __( 'Read The Guide', 'caldera-forms' ),  
  130. 'color' => 'orange' 
  131. ),  
  132. 'link' => array( 
  133. 'url' => 'https://calderaforms.com/doc/creating-new-form?utm_source=obs&utm_campaign=admin-page&utm_medium=caldera-forms&utm_term=no_forms',  
  134. 'bt' => 'email-stats' 
  135. ); 
  136.  
  137. return $clippy; 
  138.  
  139. /** 
  140. * Fallback clippy with link to getting started guide for when the API can't br reached 
  141. * @since 1.4.5 
  142. * @return array 
  143. */ 
  144. protected function fallback_clippy() { 
  145. return array( 
  146. 'title' => array( 
  147. 'content' => __( 'New To Caldera Forms?', 'caldera-forms' ),  
  148. ),  
  149. 'content' => array( 
  150. 'content' => __( 'We have a complete getting started guide for new users.', 'caldera-forms' ),  
  151. ),  
  152. 'btn' => array( 
  153. 'content' => __( 'Read Now', 'caldera-forms' ),  
  154. 'color' => 'orange' 
  155. ),  
  156. 'link' => array( 
  157. 'url' => 'https://calderaforms.com/getting-started?utm_source=obs&utm_campaign=admin-page&utm_medium=caldera-forms&utm_term=fallback' 
  158. ); 
  159.