PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/scribe/lib/scribe-display-helpers.php

https://gitlab.com/iamgraeme/royalmile
PHP | 327 lines | 239 code | 86 blank | 2 comment | 51 complexity | 14afbf5ab081c53e6c0181faa26b72ea MD5 | raw file
  1. <?php
  2. function scribe_score_class( $score, $type = 'doc' ) {
  3. if ( $type == 'site' && 70 <= $score )
  4. return 'scribe-great';
  5. elseif ( $type == 'doc' && 70 <= $score )
  6. return 'scribe-great';
  7. elseif ( $type == 'dificulty' && 5 < $score )
  8. return 'scribe-great';
  9. return 'scribe-average';
  10. }
  11. function scribe_bar_graph_class( $score, $type = '' ) {
  12. if ( 'difficulty' == $type || 'keyword-difficulty' == $type )
  13. return 50 > $score ? 'scribe-graph-green' : 'scribe-graph-red';
  14. if ( 'popularity' == $type ) {
  15. if ( 70 <= $score )
  16. return 'scribe-graph-green';
  17. if ( 40 <= $score )
  18. return 'scribe-graph-yellow';
  19. return 'scribe-graph-red';
  20. }
  21. if ( 'competition' == $type ) {
  22. if ( 50 > $score )
  23. return 'scribe-graph-green';
  24. if ( 71 > $score )
  25. return 'scribe-graph-yellow';
  26. return 'scribe-graph-red';
  27. }
  28. if (80 <= $score) {
  29. $class = 'scribe-graph-green';
  30. } elseif (20 <= $score) {
  31. $class = 'scribe-graph-yellow';
  32. } else {
  33. $class = 'scribe-graph-red';
  34. }
  35. return $class;
  36. }
  37. function scribe_get_content_for_letter_score($score, $a, $b, $c, $d) {
  38. $score = strtolower($score);
  39. if (in_array($score, array('a', 'b', 'c', 'd'))) {
  40. return $$score;
  41. } else {
  42. return '';
  43. }
  44. }
  45. function scribe_get_keyword_analysis_score_text($score) {
  46. return apply_filters( 'scribe_get_keyword_analysis_score_text',
  47. scribe_get_content_for_letter_score(
  48. $score,
  49. __( 'Congratulations, this term strikes a good balance between search optimization and copywriting best practices.', 'scribeseo' ),
  50. __( 'You\'re close! This keyword requires a bit more work to reach the correct balance between search optimization and copywriting best practices.', 'scribeseo' ),
  51. __( 'You need to integrate this keyword more closely into your copy to achieve a better score and make it more relevant.', 'scribeseo' ),
  52. __( 'Please reevaluate your use of this keyword to improve its ranking.', 'scribeseo' )
  53. )
  54. );
  55. }
  56. function scribe_get_content_for_score( $score, $a, $b, $c, $type = '' ) {
  57. if ( 'overall' == $type )
  58. return 6 > $score ? $a : $b;
  59. if ( 100 == $score )
  60. return $a;
  61. elseif ( 100 > $score )
  62. return $b;
  63. return $c;
  64. }
  65. function scribe_get_keyword_analysis_data_y( $kws ) {
  66. $kws = (float) $kws;
  67. if ( $kws <= 0.15 )
  68. return 0.15;
  69. if ( $kws <= 5.0 )
  70. return $kws;
  71. return ( ( min( $kws, 11 ) - 5 ) * 5 / 6.15 ) + 5;
  72. }
  73. function scribe_get_content_analyis_site_score_text( $score, $keywords ) {
  74. if ( $score < 50 ) {
  75. $text = __( 'While terms like <strong>%1$s</strong> and <strong>%2$s</strong> appear in your page, your site does not use these terms frequently. Consider adding more content to your site for these terms. %3$s', 'scribeseo' );
  76. $improve_text = '';
  77. } else {
  78. $text = __( 'This page is a good match for your site for terms like <strong>%1$s</strong> and <strong>%2$s</strong>. %3$s', 'scribeseo' );
  79. $improve_text = __( 'To improve your Site Score, consider adding more content related to these terms.', 'scribeseo' );
  80. }
  81. // find the top kws & primary keywords
  82. $kws = array();
  83. $primary_keywords = array();
  84. foreach( $keywords as $index => $keyword ) {
  85. if ( ! isset( $kws[$keyword->kws] ) )
  86. $kws[$keyword->kws] = array();
  87. $kws[$keyword->kws][] = $index;
  88. if ( $keyword->kwl == 1 )
  89. $primary_keywords[] = esc_html( $keyword->text );
  90. }
  91. krsort( $kws, SORT_NUMERIC );
  92. $terms = array();
  93. $k = 1;
  94. $primary = false;
  95. while( $k < 3 && ! empty( $kws ) ) {
  96. $top_kws = array_shift( $kws );
  97. while( $k < 3 && ! empty( $top_kws ) ) {
  98. $index = array_shift( $top_kws );
  99. $terms[$k] = $keywords[$index]->text;
  100. $primary |= ( $keywords[$index]->kwl == 1 );
  101. $k++;
  102. }
  103. }
  104. reset( $kws );
  105. $keyword_list = implode( __( '</strong> and <strong>', 'scribeseo' ), $primary_keywords );
  106. if ( ! empty( $primary_keywords ) ) {
  107. if ( $score < 70 && key( $kws ) < 5 )
  108. $text = sprintf( __( 'While the terms <strong>%s</strong> are used in your page, they are not used frequently enough on your site. Consider adding more content to your site for these terms.', 'scribeseo' ), $keyword_list );
  109. elseif ( ! $primary )
  110. $improve_text = sprintf( __( ' To improve your Site Score, consider adding more content related to <strong>%s</strong>, so that this page better aligns with your site.', 'scribeseo' ), $keyword_list );
  111. }
  112. return sprintf( $text, esc_html( $terms[1] ), esc_html( $terms[2] ), $improve_text );
  113. }
  114. function scribe_get_content_analysis_doc_score_text( $score, $keywords ) {
  115. if ( $score < 100 )
  116. return __( 'Your page needs some improvement. Review the suggestions under Improve Page Structure to raise your score.', 'scribeseo' );
  117. if ( $score == 100 ) {
  118. $primary = array();
  119. $primary_keywords = array();
  120. foreach( $keywords as $index => $keyword ) {
  121. if ( $keyword->kwl == 1 ) {
  122. // make the array key a string instead of a number
  123. $primary['x' . $index] = $keyword->kwc;
  124. $primary_keywords[$index] = esc_html( $keyword->text );
  125. }
  126. }
  127. if ( count( $primary_keywords > 2 ) ) {
  128. arsort( $primary, SORT_NUMERIC );
  129. $primary = array_slice( $primary, 0, 2 );
  130. $primary_keys = array_keys( $primary );
  131. foreach( $primary_keywords as $index => $keyword ) {
  132. if ( ! in_array( 'x'.$index, $primary_keys ) )
  133. unset( $primary_keywords[$index] );
  134. }
  135. }
  136. return sprintf( __( 'Your page does a good job of meeting the best practices of SEO Copywriting for the term <strong>%s</strong>.', 'scribeseo' ), implode( __( '</strong> and <strong>', 'scribeseo' ), $primary_keywords ) );
  137. }
  138. return __( 'Your page does a good job of meeting the best practices of SEO Copywriting.', 'scribeseo' );
  139. }
  140. function scribe_get_link_building_tab_load( $link_building_info, $tab ) {
  141. $load = false;
  142. foreach( array( 'ext' => 'externalLinks', 'int' => 'internalLinks', 'soc' => 'googlePlusActivities' ) as $type => $data ) {
  143. if ( $tab != $type )
  144. continue;
  145. if ( ! isset( $link_building_info->$data ) )
  146. $load = true;
  147. break;
  148. }
  149. return $load ? 'data-load="' . esc_attr( $tab ) . '"' : '';
  150. }
  151. function scribe_get_link_building_score_description($score) {
  152. if ( $score > 50 )
  153. return apply_filters('scribe_get_link_building_score_description', __( 'Getting connections to your site for the term <strong>%s</strong> will be difficult. <a href="http://www.copyblogger.com/content-marketing" target="_blank">Click here</a> to study a few useful tutorials that will help you write the kind of content your audience is looking for. ', 'scribeseo' ) );
  154. return apply_filters('scribe_get_link_building_score_description',
  155. scribe_get_content_for_score(
  156. $score,
  157. __( 'You have plenty of connections for the phrase you\'ve chosen.', 'scribeseo' ),
  158. __( 'You have a lot of connections, but need more for this phrase.', 'scribeseo' ),
  159. __( 'You need to generate a lot more connections for this phrase.', 'scribeseo' ),
  160. 'link'
  161. )
  162. );
  163. }
  164. function scribe_get_overall_score_description($score) {
  165. return apply_filters( 'scribe_get_overall_score_description',
  166. scribe_get_content_for_score(
  167. $score,
  168. __( 'It will not be difficult for you to rank on a search engine for this keyword.', 'scribeseo' ),
  169. __( 'This term will be somewhat difficult for you to rank for on a search engine.', 'scribeseo' ),
  170. '',
  171. 'overall'
  172. )
  173. );
  174. }
  175. function scribe_the_overall_score_description($score) {
  176. echo apply_filters('scribe_the_overall_score_description', scribe_get_overall_score_description($score), $score);
  177. }
  178. function scribe_get_content_score_description($score) {
  179. return apply_filters( 'scribe_get_content_score_description',
  180. scribe_get_content_for_score(
  181. $score,
  182. __( 'Great! You have an awesome score!', 'scribeseo'),
  183. __( 'Consider adding more content to your site for this term.', 'scribeseo' ),
  184. __( 'Your site exceeds the amount of content for this term for sites that are ranking.', 'scribeseo' )
  185. )
  186. );
  187. }
  188. function scribe_the_content_score_description($score) {
  189. echo apply_filters('scribe_the_content_score_description', scribe_get_content_score_description($score), $score);
  190. }
  191. function scribe_get_content_score_more_link($score) {
  192. return '#';
  193. }
  194. function scribe_get_link_score_description($score) {
  195. return apply_filters( 'scribe_get_link_score_description',
  196. scribe_get_content_for_score(
  197. $score,
  198. __( 'Great! You have an awesome score!', 'scribeseo' ),
  199. __( 'You will need to obtain more links to your site for this term.', 'scribeseo' ),
  200. __( 'Your site exceeds the number of links for sites that currently rank for this term.', 'scribeseo' )
  201. )
  202. );
  203. }
  204. function scribe_the_link_score_description($score) {
  205. echo apply_filters('scribe_the_link_score_description', scribe_get_link_score_description($score), $score);
  206. }
  207. function scribe_get_link_score_more_link($score) {
  208. return '#';
  209. }
  210. function scribe_get_domain_authority_score_description($score) {
  211. return apply_filters( 'scribe_get_domain_authority_score_description',
  212. scribe_get_content_for_score(
  213. $score,
  214. __( 'Great! You have an awesome score!', 'scribeseo' ),
  215. __( 'You should obtain more links for this term from sites that have strong authority.', 'scribeseo' ),
  216. __( 'Your site’s authority exceeds the authority of most sites that rank for this term.', 'scribeseo' )
  217. )
  218. );
  219. }
  220. function scribe_the_domain_authority_score_description($score) {
  221. echo apply_filters('scribe_the_domain_authority_score_description', scribe_get_domain_authority_score_description($score), $score);
  222. }
  223. function scribe_get_domain_authority_score_more_link($score) {
  224. return '#';
  225. }
  226. function scribe_get_facebook_likes_score_description($score) {
  227. return apply_filters('scribe_get_facebook_likes_score_description',
  228. scribe_get_content_for_score(
  229. $score,
  230. __( 'Great! You have an awesome score!', 'scribeseo' ),
  231. __( 'You should have more people sharing your content online in order to rank well for this term.', 'scribeseo' ),
  232. __( 'Your site’s content for this term is highly socialized.', 'scribeseo' )
  233. )
  234. );
  235. }
  236. function scribe_the_facebook_likes_score_description($score) {
  237. echo apply_filters('scribe_the_facebook_likes_score_description', scribe_get_facebook_likes_score_description($score), $score);
  238. }
  239. function scribe_get_facebook_likes_score_more_link($score) {
  240. return '#';
  241. }