GoogleKS_LayoutEngine

Class GoogleKS_LayoutEngine.

Defined (1)

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

/classes/layoutengine.php  
  1. class GoogleKS_LayoutEngine { 
  2.  
  3. // string, public plugin name 
  4. // @since 1.0.0 
  5. private $a_str_PublicPluginName = "Google Keyword Suggest"; 
  6.  
  7. /** 
  8. * @constructor 
  9. * @since 1.0.0 
  10. */ 
  11. public function __construct() { 
  12.  
  13.  
  14. /** 
  15. * executes the layout engine and renders the settings menu 
  16. * @since: 1.0.0 
  17. * @return void 
  18. */ 
  19. public function Run() { 
  20. // add action hook to register my meta boxes for specific pages 
  21. add_action("admin_menu", array($this, "RegisterMetaBoxes")); 
  22.  
  23. /** 
  24. * register all meta boxes 
  25. * @since: 1.0.0 
  26. * @return void 
  27. */ 
  28. public function RegisterMetaBoxes() { 
  29. // add a new meta box to the "edit post" 
  30. add_meta_box( // http://codex.wordpress.org/Function_Reference/add_meta_box 
  31. GOOGLE_KS_INTERNAL_PLUGIN_NAME . "_post", // unique meta box id 
  32. $this->a_str_PublicPluginName, // meta box title 
  33. array($this, "handleMetaBox"), // callback function 
  34. 'post', // screen 
  35. 'side', // content 
  36. 'high' // priority 
  37. ); 
  38.  
  39. // add a new meta box to the "edit page" 
  40. add_meta_box( // http://codex.wordpress.org/Function_Reference/add_meta_box 
  41. GOOGLE_KS_INTERNAL_PLUGIN_NAME . "_page", // unique meta box id 
  42. $this->a_str_PublicPluginName, // meta box title 
  43. array($this, "handleMetaBox"), // callback function 
  44. 'page', // screen 
  45. 'side', // content 
  46. 'high' // priority 
  47. ); 
  48.  
  49. /** 
  50. * callback function for all meta boxes 
  51. * @since 1.0.0 
  52. */ 
  53. public function handleMetaBox() { 
  54. // get language and country code 
  55. $l_arr_Locale = explode("_", strtolower(get_locale())); 
  56. $l_str_Language = $l_arr_Locale[0]; 
  57. $l_str_Country = count($l_arr_Locale) > 1 ? $l_arr_Locale[1] : "us"; 
  58.  
  59. // change country code for specific countries 
  60. switch($l_str_Country) { 
  61. case "gb": // change "Great Britain" to "United Kingdom" 
  62. $l_str_Country = "uk"; 
  63. break; 
  64. ?> 
  65.  
  66. <table> 
  67. <tbody> 
  68. <tr> 
  69. <td><?php echo $this->Label(__("Language:", GOOGLE_KS_INTERNAL_PLUGIN_NAME), "lang"); ?></td> 
  70. <td><?php echo $this->AddSelect("lang", array("en" => "English", "fr" => "French", "de" => "German", "it" => "Italian", "es" => "Spanish", "sv" => "Swedish"), $l_str_Language); ?></td> 
  71. </tr> 
  72. <tr> 
  73. <td><?php echo $this->Label(__("Country:", GOOGLE_KS_INTERNAL_PLUGIN_NAME), "cr"); ?></td> 
  74. <td><?php echo $this->AddSelect("cr", array("au" => "Australia", "at" => "Austria", "fr" => "France", "de" => "Germany", "it" => "Italy", "mx" => "Mexico", "es" => "Spain", "se" => "Sweden", "ch" => "Switzerland", "uk" => "United Kingdom", "us" => "United States"), $l_str_Country); ?></td> 
  75. </tr> 
  76. <tr> 
  77. <td><?php echo $this->Label(__("Keyword:", GOOGLE_KS_INTERNAL_PLUGIN_NAME), "keyword"); ?></td> 
  78. <td><?php echo $this->Text_box("keyword", ""); ?></td> 
  79. </tr> 
  80. <tr> 
  81. <td colspan="100%"> 
  82. <ul id="suggest" style="list-style:square; padding-left:10px;"></ul> 
  83. </td> 
  84. </tr> 
  85. <tr> 
  86. <td colspan="100%"> 
  87. <div style="text-align:right; padding-right:8px;"> 
  88. <input type="button" class="button button-primary" id="google_ks_find" value="<?php echo __('Find suggestions', GOOGLE_KS_INTERNAL_PLUGIN_NAME); ?>" /> 
  89. </div> 
  90. </td> 
  91. </tr> 
  92. <tr> 
  93. <td colspan="100%"> 
  94. <div style="text-align:right; font-size:10px; padding-right:4px;"> 
  95. <span style="font-style:italic;"> 
  96. <?php echo $this->toItalic($this->addText(__("proudly crafted by", GOOGLE_KS_INTERNAL_PLUGIN_NAME))); ?> 
  97. <a href="http://www.herndler.org" target="_blank">herndler.org</a> & 
  98. <a href="http://www.seomotion.org" target="_blank">seomotion.org</a> 
  99. </span> 
  100. </div> 
  101. </td> 
  102. </tr> 
  103. </tbody> 
  104. </table> 
  105. <script type="text/javascript"> 
  106. jQuery("#google_ks_find").on("click", function() { 
  107. var l_obj_Button = jQuery(this); 
  108. l_obj_Button.prop("disabled", true); 
  109. jQuery.ajax({ 
  110. type: 'POST',  
  111. url: '/wp-admin/admin-ajax.php',  
  112. data: { 
  113. action: 'google_ks_suggestion',  
  114. lang: jQuery("#lang").val(),  
  115. cr: jQuery("#cr").val(),  
  116. keyword: jQuery("#keyword").val() 
  117. },  
  118. success: function(data, textStatus, XMLHttpRequest) { 
  119. jQuery("#suggest").html(data); 
  120. l_obj_Button.prop("disabled", false); 
  121. },  
  122. error: function(MLHttpRequest, textStatus, errorThrown) { 
  123. console.log(textStatus); 
  124. l_obj_Button.prop("disabled", false); 
  125. }); 
  126. }); 
  127. </script> 
  128. <?php 
  129.  
  130. /** 
  131. * returns the html code to append a single line break 
  132. * @since: 1.0.0 
  133. * @return string 
  134. */ 
  135. public function LineBreak() { 
  136. return "<br/>"; 
  137.  
  138. /** 
  139. * returns the html code to append a newline 
  140. * @since: 1.0.0 
  141. * @return string 
  142. */ 
  143. public function Newline() { 
  144. return "<br/><br/>"; 
  145.  
  146. /** 
  147. * add a space 
  148. * @since 1.0.0 
  149. * @return string 
  150. */ 
  151. public function addSpace() { 
  152. return "     "; 
  153.  
  154. /** 
  155. * return a html formatted string 
  156. * @since 1.0.0 
  157. * @param string $p_str_Text 
  158. * @return string 
  159. */ 
  160. public function addText($p_str_Text) { 
  161. return '<span>' . $p_str_Text . '</span>'; 
  162.  
  163. /** 
  164. * returns the html code to change the font-style to be bold 
  165. * @since: 1.0.0 
  166. * @param string $p_str_Text 
  167. * @return string 
  168. */ 
  169. public function toBold($p_str_Text) { 
  170. return "<b>" . $p_str_Text . "</b>"; 
  171.  
  172. /** 
  173. * returns the html code to change the font-style to be italic 
  174. * @since: 1.0.0 
  175. * @param string $p_str_Text 
  176. * @return string 
  177. */ 
  178. public function toItalic($p_str_Text) { 
  179. return "<i>" . $p_str_Text . "</i>"; 
  180.  
  181. /** 
  182. * returns the html code to change the font-style to be underlined 
  183. * @since: 1.0.0 
  184. * @param string $p_str_Text 
  185. * @return string 
  186. */ 
  187. public function toUnderline($p_str_Text) { 
  188. return "<u>" . $p_str_Text . "</u>"; 
  189.  
  190. /** 
  191. * returns the html code to change the font-color to a specific HEX value 
  192. * @since: 1.0.0 
  193. * @param string $p_str_Text 
  194. * @param string $p_str_Color [hex value] 
  195. * @return string 
  196. */ 
  197. public function ChangeForeColor($p_str_Text, $p_str_Color) { 
  198. return '<font color="#' . $p_str_Color . '">' . $p_str_Text . '</font>'; 
  199.  
  200. /** 
  201. * returns the html code to be indended 
  202. * @since: 1.0.0 
  203. * @param string $p_str_Text 
  204. * @return string 
  205. */ 
  206. public function Indended($p_str_Text) { 
  207. return "<blockquote>" . $p_str_Text . "</blockquote>"; 
  208.  
  209. /** 
  210. * returns the html code for a formatted description text 
  211. * @since: 1.0.0 
  212. * @param string $p_str_Text 
  213. * @return string 
  214. */ 
  215. public function Description($p_str_Text) { 
  216. return $this->Indended($this->toItalic($p_str_Text)); 
  217.  
  218. /** 
  219. * returns the html code to append a label-tag 
  220. * @since: 1.0.0 
  221. * @param string $p_str_Caption 
  222. * @param string $p_str_For 
  223. * @return string 
  224. */ 
  225. public function Label($p_str_Caption, $p_str_For) { 
  226. return '<label for="' . $p_str_For . '">' . $this->toBold($p_str_Caption) . '</label>'; 
  227.  
  228. /** 
  229. * returns the html code to append a single line text box 
  230. * @since: 1.0.0 
  231. * @param string $p_str_Setting [setting name to be loaded] 
  232. * @param string $p_str_Class [optional css class name] 
  233. * @param int $p_int_Width [optional, css width of input] 
  234. * @param bool $p_bool_Readonly [optional readonly] 
  235. * @param bool $p_bool_hidden [optional hidden input] 
  236. * @param int $p_int_MaxLength [optional max length] 
  237. * @return string 
  238. */ 
  239. public function Text_box($p_str_Setting, $p_str_Class = "", $p_int_Width = -1, $p_bool_Readonly = false, $p_bool_hidden = false, $p_int_MaxLength = -1) { 
  240. // start to build the html tag 
  241. $l_str_OutputStream = '<input type="text"'; 
  242. // append class name to output stream 
  243. if (!empty($p_str_Class)) { 
  244. $l_str_OutputStream .= ' class="' . $p_str_Class . '"'; 
  245. // append width to output stream 
  246. if (!empty($p_int_Width) && is_int($p_int_Width) && $p_int_Width > 0) { 
  247. $l_str_OutputStream .= ' style="width: ' . $p_int_Width . '% !important;"'; 
  248. // append readonly attribute to output stream 
  249. if ($p_bool_Readonly) { 
  250. $l_str_OutputStream .= ' readonly="readonly"'; 
  251. // append hidden attribute to output stream 
  252. if ($p_bool_hidden) { 
  253. $l_str_OutputStream .= ' style="display:none;"'; 
  254. // append max length to output stream 
  255. if (!empty($p_int_MaxLength) && is_int($p_int_MaxLength) && $p_int_MaxLength > 0) { 
  256. $l_str_OutputStream .= ' maxlength="' . $p_int_MaxLength . '"'; 
  257. // append id, name and value 
  258. $l_str_OutputStream .= ' id="' . $p_str_Setting . '"'; 
  259. $l_str_OutputStream .= ' name="' . $p_str_Setting . '"'; 
  260. $l_str_OutputStream .= ' value=""'; 
  261. // close html tag 
  262. $l_str_OutputStream .= '/>'; 
  263. // return html tag 
  264. return $l_str_OutputStream; 
  265.  
  266. /** 
  267. * returns the html code to append a multi line text area 
  268. * @since: 1.0.0 
  269. * @param string $p_str_Setting [setting name to be loaded] 
  270. * @param string $p_str_Class [optional css class name] 
  271. * @param int $p_int_Width [optional, css width of input] 
  272. * @param int $p_int_Rows [optional number of rows] 
  273. * @return string 
  274. */ 
  275. public function Text_area($p_str_Setting, $p_str_Class = "", $p_int_Width = -1, $p_int_Rows = 8) { 
  276. // start to build the html tag 
  277. $l_str_OutputStream = '<textarea'; 
  278. // append class name to output stream 
  279. if (!empty($p_str_Class)) { 
  280. $l_str_OutputStream .= ' class="' . $p_str_Class . '"'; 
  281. // append width to output stream 
  282. if (!empty($p_int_Width) && is_int($p_int_Width) && $p_int_Width > 0) { 
  283. $l_str_OutputStream .= ' style="width: ' . $p_int_Width . '% !important;"'; 
  284. // append max length to output stream 
  285. if (!empty($p_int_Rows) && is_int($p_int_Rows) && $p_int_Rows > 0) { 
  286. $l_str_OutputStream .= ' rows="' . $p_int_Rows . '"'; 
  287. // append id, name and value 
  288. $l_str_OutputStream .= ' id="' . $p_str_Setting . '"'; 
  289. $l_str_OutputStream .= ' name="' . $p_str_Setting . '"'; 
  290. $l_str_OutputStream .= '/>'; 
  291. $l_str_OutputStream .= $p_str_Setting; 
  292. // close html tag 
  293. $l_str_OutputStream .= '</textarea>'; 
  294. // return html tag 
  295. return $l_str_OutputStream; 
  296.  
  297. /** 
  298. * returns a select box 
  299. * @since 1.0.0 
  300. * @param string $p_str_SettingsID 
  301. * @param array $p_arr_Options 
  302. * @param string $p_str_Default 
  303. * @param string $p_str_ClassName 
  304. * @return string 
  305. */ 
  306. public function AddSelect($p_str_SettingsID, $p_arr_Options, $p_str_Default, $p_str_ClassName = "") { 
  307. // if input shall have a css class, add the style tag for it 
  308. if (!empty($p_str_ClassName)) { 
  309. $p_str_ClassName = 'class="' . $p_str_ClassName . '"'; 
  310. // select starting tag 
  311. $l_str_OutputStream = '<select ' . $p_str_ClassName . ' name="' . $p_str_SettingsID . '" id="' . $p_str_SettingsID . '">'; 
  312. // loop through all array keys 
  313. foreach ($p_arr_Options as $l_str_Value => $l_str_Caption) { 
  314. // add key as option value 
  315. $l_str_OutputStream .= '<option value="' . $l_str_Value . '"'; 
  316. if ($p_str_Default == $l_str_Value) { 
  317. $l_str_OutputStream .= ' selected'; 
  318. $l_str_OutputStream .= '>' . $l_str_Caption . '</option>'; 
  319. // close select 
  320. $l_str_OutputStream .= '</select>'; 
  321. // outputs the SELECT field 
  322. return $l_str_OutputStream; 
  323. } // end of class