PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php

https://gitlab.com/javicodigonexo/inblan
PHP | 1322 lines | 920 code | 223 blank | 179 comment | 347 complexity | e98af356f20f28dd3be3632f2186490f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Plugin Name: SI CAPTCHA Anti-Spam
  4. Plugin URI: http://www.642weather.com/weather/scripts-wordpress-captcha.php
  5. Description: Adds CAPTCHA anti-spam methods to WordPress forms for comments, registration, lost password, login, or all. This prevents spam from automated bots. WP, WPMU, and BuddyPress compatible. <a href="plugins.php?page=si-captcha-for-wordpress/si-captcha.php">Settings</a> | <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KXJWLPPWZG83S">Donate</a>
  6. Version: 2.7.7.5
  7. Author: Mike Challis
  8. Author URI: http://www.642weather.com/weather/scripts.php
  9. */
  10. $si_captcha_version = '2.7.7.5';
  11. /* Copyright (C) 2008-2014 Mike Challis (http://www.642weather.com/weather/contact_us.php)
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. // settings get deleted when plugin is deleted from admin plugins page
  25. // this must be outside the class or it does not work
  26. function si_captcha_unset_options() {
  27. if (basename(dirname(__FILE__)) != "mu-plugins")
  28. delete_option('si_captcha');
  29. }
  30. if (!class_exists('siCaptcha')) {
  31. class siCaptcha {
  32. var $si_captcha_add_script;
  33. var $si_captcha_version;
  34. function si_captcha_add_tabs() {
  35. global $wpmu, $wp_version;
  36. // for WP 3.0+ ONLY!
  37. if( $wpmu == 1 && version_compare($wp_version,'3','>=') && is_multisite() && is_super_admin() ) { // wp 3.0 +
  38. add_submenu_page('ms-admin.php', __('SI Captcha Options', 'si-captcha'), __('SI Captcha Options', 'si-captcha'), 'manage_options', __FILE__,array(&$this,'si_captcha_options_page'));
  39. add_options_page( __('SI Captcha Options', 'si-captcha'), __('SI Captcha Options', 'si-captcha'), 'manage_options', __FILE__,array(&$this,'si_captcha_options_page'));
  40. }
  41. else if ($wpmu == 1 && function_exists('is_site_admin') && is_site_admin()) {
  42. add_submenu_page('wpmu-admin.php', __('SI Captcha Options', 'si-captcha'), __('SI Captcha Options', 'si-captcha'), 'manage_options', __FILE__,array(&$this,'si_captcha_options_page'));
  43. add_options_page( __('SI Captcha Options', 'si-captcha'), __('SI Captcha Options', 'si-captcha'), 'manage_options', __FILE__,array(&$this,'si_captcha_options_page'));
  44. }
  45. else if ($wpmu != 1) {
  46. add_submenu_page('plugins.php', __('SI Captcha Options', 'si-captcha'), __('SI Captcha Options', 'si-captcha'), 'manage_options', __FILE__,array(&$this,'si_captcha_options_page'));
  47. }
  48. }
  49. function si_captcha_get_options() {
  50. global $wpmu, $si_captcha_opt, $si_captcha_option_defaults;
  51. $default_position = ( function_exists('bp_loaded') ) ? 'label-required-input' : 'input-label-required';
  52. $si_captcha_option_defaults = array(
  53. 'si_captcha_donated' => 'false',
  54. 'si_captcha_perm' => 'true',
  55. 'si_captcha_perm_level' => 'read',
  56. 'si_captcha_comment' => 'true',
  57. 'si_captcha_comment_label_position' => $default_position,
  58. 'si_captcha_login' => 'false',
  59. 'si_captcha_register' => 'true',
  60. 'si_captcha_lostpwd' => 'true',
  61. 'si_captcha_rearrange' => 'true',
  62. 'si_captcha_enable_session' => 'false',
  63. 'si_captcha_captcha_small' => 'false',
  64. 'si_captcha_honeypot_enable' => 'false',
  65. 'si_captcha_aria_required' => 'false',
  66. 'si_captcha_external_style' => 'false',
  67. 'si_captcha_captcha_div_style' => 'display:block;',
  68. 'si_captcha_captcha_div_style_sm' => 'width:175px; height:45px; padding-top:10px;',
  69. 'si_captcha_captcha_div_style_m' => 'width:250px; height:60px; padding-top:10px;',
  70. 'si_captcha_captcha_image_style' => 'border-style:none; margin:0; padding-right:5px; float:left;',
  71. 'si_captcha_refresh_image_style' => 'border-style:none; margin:0; vertical-align:bottom;',
  72. 'si_captcha_captcha_input_div_style' => 'display:block; padding-top:15px; padding-bottom:5px;',
  73. 'si_captcha_comment_label_style' => 'margin:0;',
  74. 'si_captcha_comment_field_style' => 'width:65px;',
  75. 'si_captcha_label_captcha' => '',
  76. 'si_captcha_error_spambot' => '',
  77. 'si_captcha_error_incorrect' => '',
  78. 'si_captcha_error_empty' => '',
  79. 'si_captcha_error_token' => '',
  80. 'si_captcha_error_unreadable' => '',
  81. 'si_captcha_error_cookie' => '',
  82. 'si_captcha_error_error' => '',
  83. 'si_captcha_required_indicator' => ' *',
  84. 'si_captcha_tooltip_captcha' => '',
  85. 'si_captcha_tooltip_refresh' => '',
  86. );
  87. // upgrade path from old version
  88. if ($wpmu != 1 && !get_option('si_captcha') && get_option('si_captcha_comment')) {
  89. // just now updating, migrate settings
  90. $si_captcha_option_defaults = $this->si_captcha_migrate($si_captcha_option_defaults);
  91. }
  92. // install the option defaults
  93. if ($wpmu == 1) {
  94. if( !get_site_option('si_captcha') ) {
  95. add_site_option('si_captcha', $si_captcha_option_defaults, '', 'yes');
  96. }
  97. }else{
  98. add_option('si_captcha', $si_captcha_option_defaults, '', 'yes');
  99. }
  100. // get the options from the database
  101. if ($wpmu == 1)
  102. $si_captcha_opt = get_site_option('si_captcha'); // get the options from the database
  103. else
  104. $si_captcha_opt = get_option('si_captcha');
  105. // array merge incase this version has added new options
  106. $si_captcha_opt = array_merge($si_captcha_option_defaults, $si_captcha_opt);
  107. // strip slashes on get options array
  108. foreach($si_captcha_opt as $key => $val) {
  109. $si_captcha_opt[$key] = $this->si_stripslashes($val);
  110. }
  111. if ($si_captcha_opt['si_captcha_captcha_image_style'] == '') {
  112. // if default styles are missing, reset styles
  113. $style_resets_arr = array('si_captcha_comment_label_style','si_captcha_comment_field_style','si_captcha_captcha_div_style','si_captcha_captcha_div_style_sm','si_captcha_captcha_div_style_m','si_captcha_captcha_input_div_style','si_captcha_captcha_image_style','si_captcha_refresh_image_style');
  114. foreach($style_resets_arr as $style_reset) {
  115. $si_captcha_opt[$style_reset] = $si_captcha_option_defaults[$style_reset];
  116. }
  117. }
  118. if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST )
  119. $si_captcha_opt['si_captcha_login'] = 'false'; // disable captcha on xmlrpc connections
  120. } // end function si_captcha_get_options
  121. function si_captcha_migrate($si_captcha_option_defaults) {
  122. // read the options from the prior version
  123. $new_options = array ();
  124. foreach($si_captcha_option_defaults as $key => $val) {
  125. $new_options[$key] = get_option( "$key" );
  126. // now delete the options from the prior version
  127. delete_option("$key");
  128. }
  129. // now the old settings will carry over to the new version
  130. return $new_options;
  131. } // end function si_captcha_migrate
  132. function si_captcha_options_page() {
  133. global $wpmu, $si_captcha_dir, $si_captcha_url, $si_captcha_url_ns, $si_captcha_dir_ns, $si_captcha_opt, $si_captcha_option_defaults, $si_captcha_version;
  134. $si_captcha_admin_path = str_replace('/captcha','',$si_captcha_dir);
  135. if ($wpmu == 1)
  136. $si_captcha_admin_path = 'si-captcha-for-wordpress';
  137. require_once($si_captcha_admin_path . '/si-captcha-admin.php');
  138. }// end function si_captcha_options_page
  139. function si_captcha_perm_dropdown($select_name, $checked_value='') {
  140. // choices: Display text => permission_level
  141. $choices = array (
  142. __('All registered users', 'si-captcha') => 'read',
  143. __('Edit posts', 'si-captcha') => 'edit_posts',
  144. __('Publish Posts', 'si-captcha') => 'publish_posts',
  145. __('Moderate Comments', 'si-captcha') => 'moderate_comments',
  146. __('Administer site', 'si-captcha') => 'level_10'
  147. );
  148. // print the <select> and loop through <options>
  149. echo '<select name="' . esc_attr($select_name) . '" id="' . esc_attr($select_name) . '">' . "\n";
  150. foreach ($choices as $text => $capability) :
  151. if ($capability == $checked_value) $checked = ' selected="selected" ';
  152. echo "\t". '<option value="' . esc_attr($capability) . '"' . $checked . '>'.esc_html($text)."</option>\n";
  153. $checked = '';
  154. endforeach;
  155. echo "\t</select>\n";
  156. } // end function si_captcha_perm_dropdown
  157. function si_captcha_check_requires() {
  158. global $si_captcha_dir, $si_captcha_add_script;
  159. $ok = 'ok';
  160. // Test for some required things, print error message if not OK.
  161. if ( !extension_loaded('gd') || !function_exists('gd_info') ) {
  162. echo '<p style="color:maroon">'.__('ERROR: si-captcha.php plugin says GD image support not detected in PHP!', 'si-captcha').'</p>';
  163. echo '<p>'.__('Contact your web host and ask them why GD image support is not enabled for PHP.', 'si-captcha').'</p>';
  164. $ok = 'no';
  165. }
  166. if ( !function_exists('imagepng') ) {
  167. echo '<p style="color:maroon">'.__('ERROR: si-captcha.php plugin says imagepng function not detected in PHP!', 'si-captcha').'</p>';
  168. echo '<p>'.__('Contact your web host and ask them why imagepng function is not enabled for PHP.', 'si-captcha').'</p>';
  169. $ok = 'no';
  170. }
  171. if ( !@strtolower(ini_get('safe_mode')) == 'on' && !file_exists("$si_captcha_dir/securimage.php") ) {
  172. echo '<p style="color:maroon">'.__('ERROR: si-captcha.php plugin says captcha_library not found.', 'si-captcha').'</p>';
  173. $ok = 'no';
  174. }
  175. if ($ok == 'no') return false;
  176. $si_captcha_add_script = true;
  177. return true;
  178. } // end function si_captcha_check_requires
  179. // this function adds the captcha to the comment form
  180. function si_captcha_comment_form() {
  181. global $si_captcha_url, $si_captcha_opt;
  182. // skip the captcha if user is logged in and the settings allow
  183. if (is_user_logged_in() && $si_captcha_opt['si_captcha_perm'] == 'true') {
  184. // skip the CAPTCHA display if the minimum capability is met
  185. if ( current_user_can( $si_captcha_opt['si_captcha_perm_level'] ) ) {
  186. // skip capthca
  187. return true;
  188. }
  189. }
  190. // the captcha html
  191. echo '
  192. <div id="captchaImgDiv">
  193. ';
  194. // Test for some required things, print error message right here if not OK.
  195. if ($this->si_captcha_check_requires()) {
  196. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  197. // the captcha html - comment form 2.0
  198. echo '
  199. <div ';
  200. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  201. echo '>';
  202. $this->si_captcha_captcha_html('si_image_com','com');
  203. echo '</div>
  204. <div id="captchaInputDiv">';
  205. $label_string = ' <label id="captcha_code_label" for="captcha_code">';
  206. $label_string .= ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  207. $label_string .= '</label>';
  208. $required_string = '<span class="required">'.$si_captcha_opt['si_captcha_required_indicator']."</span>\n";
  209. $input_string = '<input id="captcha_code" name="captcha_code" type="text" value="" tabindex="4" '.$si_aria_required.' />
  210. ';
  211. if ($si_captcha_opt['si_captcha_comment_label_position'] == 'label-required-input' || $si_captcha_opt['si_captcha_comment_label_position'] == 'left' ) { // buddypress (label-required-input)(label left)
  212. echo $label_string . $required_string . $input_string; // BP
  213. } else if ($si_captcha_opt['si_captcha_comment_label_position'] == 'label-required-linebreak-input' || $si_captcha_opt['si_captcha_comment_label_position'] == 'top' ) {
  214. echo $label_string . $required_string .'<br />'. $input_string; // regular WP - twenty ten
  215. } else if ($si_captcha_opt['si_captcha_comment_label_position'] == 'label-input-required' || $si_captcha_opt['si_captcha_comment_label_position'] == 'right' ) {
  216. echo $label_string . $input_string . $required_string; // suffusion
  217. } else if ($si_captcha_opt['si_captcha_comment_label_position'] == 'input-label-required' ) {
  218. echo $input_string . $label_string . $required_string; // regular WP
  219. } else {
  220. echo $input_string . $label_string . $required_string; // regular WP
  221. }
  222. echo ' </div>
  223. </div>
  224. ';
  225. // rearrange submit button display order
  226. if ($si_captcha_opt['si_captcha_rearrange'] == 'true') {
  227. print <<<EOT
  228. <script type='text/javascript'>
  229. var sUrlInput = document.getElementById("comment");
  230. var oParent = sUrlInput.parentNode;
  231. var sSubstitue = document.getElementById("captchaImgDiv");
  232. oParent.appendChild(sSubstitue, sUrlInput);
  233. </script>
  234. <noscript>
  235. <style type='text/css'>#submit {display:none;}</style><br />
  236. EOT;
  237. echo ' <input name="submit" type="submit" id="submit-alt" tabindex="6" value="'.__('Submit Comment', 'si-captcha').'" />
  238. </noscript>
  239. ';
  240. }
  241. }else{
  242. echo '</div>';
  243. }
  244. return true;
  245. } // end function si_captcha_comment_form 2.0
  246. // this function adds the captcha to the comment form WP3
  247. function si_captcha_comment_form_wp3() {
  248. global $si_captcha_url, $si_captcha_opt;
  249. // skip the captcha if user is logged in and the settings allow
  250. if (is_user_logged_in() && $si_captcha_opt['si_captcha_perm'] == 'true') {
  251. // skip the CAPTCHA display if the minimum capability is met
  252. if ( current_user_can( $si_captcha_opt['si_captcha_perm_level'] ) ) {
  253. // skip capthca
  254. return true;
  255. }
  256. }
  257. // the captch html
  258. // Test for some required things, print error message right here if not OK.
  259. if ($this->si_captcha_check_requires()) {
  260. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  261. // the captcha html - comment form 3.0+
  262. if (is_user_logged_in()) {
  263. echo '<br />';
  264. }
  265. echo '
  266. <div ';
  267. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  268. echo '>';
  269. $this->si_captcha_captcha_html('si_image_com','com');
  270. echo '</div>
  271. <br />
  272. ';
  273. echo '<p>';
  274. $label_string = '<label id="captcha_code_label" for="captcha_code" >';
  275. $label_string .= ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  276. $label_string .= '</label>';
  277. $required_string = '<span class="required">'.$si_captcha_opt['si_captcha_required_indicator']."</span>\n";
  278. $input_string = '<input id="captcha_code" name="captcha_code" type="text" size="6" ' . $si_aria_required . ' />
  279. ';
  280. if ($si_captcha_opt['si_captcha_comment_label_position'] == 'label-required-input' || $si_captcha_opt['si_captcha_comment_label_position'] == 'left' ) { // buddypress (label-required-input)(label left)
  281. echo $label_string . $required_string . $input_string; // BP
  282. } else if ($si_captcha_opt['si_captcha_comment_label_position'] == 'label-required-linebreak-input' || $si_captcha_opt['si_captcha_comment_label_position'] == 'top' ) {
  283. echo $label_string . $required_string .'<br />'. $input_string; // regular WP - twenty ten
  284. } else if ($si_captcha_opt['si_captcha_comment_label_position'] == 'label-input-required' || $si_captcha_opt['si_captcha_comment_label_position'] == 'right' ) {
  285. echo $label_string . $input_string . $required_string; // suffusion
  286. } else if ($si_captcha_opt['si_captcha_comment_label_position'] == 'input-label-required' ) {
  287. echo $input_string . $label_string . $required_string; // regular WP
  288. } else {
  289. echo $input_string . $label_string . $required_string; // regular WP
  290. }
  291. echo '</p>';
  292. }
  293. // prevent double captcha fields
  294. remove_action('comment_form', array(&$this, 'si_captcha_comment_form'), 1);
  295. return true;
  296. } // end function si_captcha_comment_form_wp3
  297. // this function adds the captcha to the login form
  298. function si_captcha_login_form() {
  299. global $si_captcha_url, $si_captcha_opt;
  300. if ($si_captcha_opt['si_captcha_login'] != 'true') {
  301. return true; // captcha setting is disabled for login
  302. }
  303. // Test for some required things, print error message right here if not OK.
  304. if ($this->si_captcha_check_requires()) {
  305. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  306. // the captcha html - login form
  307. echo '
  308. <br />
  309. <div ';
  310. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  311. echo '>';
  312. $this->si_captcha_captcha_html('si_image_log','log');
  313. echo '</div>
  314. <p>
  315. <label>';
  316. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  317. echo '<br />
  318. <input id="captcha_code" name="captcha_code" class="input" type="text" value="" size="12" tabindex="30" '.$si_aria_required.' style="font-size: 24px; width: 97%; padding: 3px; margin-top: 2px; margin-right: 6px; margin-bottom: 16px; border: 1px solid #e5e5e5; background: #fbfbfb;" /></label>
  319. </p>
  320. <br />
  321. ';
  322. }
  323. return true;
  324. } // end function si_captcha_login_form
  325. // this function adds the captcha to the login bar form of all buddypress versions
  326. function si_captcha_bp_login_form() {
  327. global $si_captcha_url, $si_captcha_opt;
  328. if ($si_captcha_opt['si_captcha_login'] != 'true') {
  329. return true; // captcha setting is disabled for login
  330. }
  331. // Test for some required things, print error message right here if not OK.
  332. if ($this->si_captcha_check_requires()) {
  333. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  334. // the captcha html - buddypress login form
  335. echo '
  336. <div style="width:440px; height:45px">';
  337. $this->si_captcha_captcha_html('si_image_log','log');
  338. echo '<input id="captcha_code" name="captcha_code" class="input" type="text" value="" '.$si_aria_required.' />
  339. <label for="captcha_code">';
  340. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  341. echo '</label>
  342. </div>
  343. </div>
  344. ';
  345. }
  346. return true;
  347. } // end function si_captcha_bp_login_form
  348. // this function adds the captcha to the login sidebar form of all buddypress versions
  349. function si_captcha_bp_login_sidebar_form() {
  350. global $si_captcha_url, $si_captcha_opt;
  351. if ($si_captcha_opt['si_captcha_login'] != 'true') {
  352. return true; // captcha setting is disabled for login
  353. }
  354. // Test for some required things, print error message right here if not OK.
  355. if ($this->si_captcha_check_requires()) {
  356. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  357. // the captcha html - buddypress sidebar login form
  358. echo '
  359. <div class="captchaSizeDivSmall">
  360. ';
  361. $this->si_captcha_captcha_html('si_image_side_login','log');
  362. echo '
  363. </div>
  364. <label for="captcha_code_side_login">';
  365. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  366. echo '</label>
  367. <input style="width=145px;" id="captcha_code_side_login" name="captcha_code" class="input" type="text" value="" '.$si_aria_required.' />
  368. <br />
  369. <br />
  370. ';
  371. }
  372. return true;
  373. } // end function si_captcha_bp_login_sidebar_form
  374. // this function adds the captcha to the login form any time wp_login_form is called
  375. function si_captcha_inline_login_form() {
  376. global $si_captcha_url, $si_captcha_opt;
  377. if ($si_captcha_opt['si_captcha_login'] != 'true') {
  378. return true; // captcha setting is disabled for login
  379. }
  380. // Test for some required things, print error message right here if not OK.
  381. if ($this->si_captcha_check_requires()) {
  382. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  383. // the captcha html - buddypress sidebar login form
  384. $si_html = '
  385. <div class="captchaSizeDivSmall">
  386. ';
  387. $si_html .= $this->si_captcha_captcha_html('si_image_side_login','log', true);
  388. $si_html .= '
  389. </div>
  390. <label for="captcha_code_side_login">';
  391. $si_html .= ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  392. $si_html .= '</label>
  393. <input style="width=145px;" id="captcha_code_side_login" name="captcha_code" class="input" type="text" value="" '.$si_aria_required.' />
  394. <br />
  395. <br />
  396. ';
  397. }
  398. return $si_html;
  399. } // end function si_captcha_inline_login_form
  400. // this function adds the captcha to the register form
  401. function si_captcha_register_form() {
  402. global $si_captcha_url, $si_captcha_opt;
  403. if ($si_captcha_opt['si_captcha_register'] != 'true') {
  404. return true; // captcha setting is disabled for registration
  405. }
  406. // Test for some required things, print error message right here if not OK.
  407. if ($this->si_captcha_check_requires()) {
  408. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  409. // the captcha html - register form
  410. echo '
  411. <br />
  412. <div ';
  413. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  414. echo '>';
  415. $this->si_captcha_captcha_html('si_image_reg','reg');
  416. echo '</div>
  417. <p>
  418. <label>';
  419. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  420. echo '<br />
  421. <input id="captcha_code" name="captcha_code" class="input" type="text" value="" tabindex="30" '.$si_aria_required.' style="font-size: 24px; width: 97%; padding: 3px; margin-top: 2px; margin-right: 6px; margin-bottom: 16px; border: 1px solid #e5e5e5; background: #fbfbfb;" /></label>
  422. </p>
  423. ';
  424. }
  425. return true;
  426. } // end function si_captcha_register_form
  427. // this function adds the captcha to the lostpassword form
  428. function si_captcha_lostpassword_form() {
  429. global $si_captcha_url, $si_captcha_opt;
  430. // Test for some required things, print error message right here if not OK.
  431. if ($this->si_captcha_check_requires()) {
  432. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  433. // the captcha html - lostpassword form
  434. echo '
  435. <br />
  436. <div ';
  437. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  438. echo '>';
  439. $this->si_captcha_captcha_html('si_image_reg','reg');
  440. echo '</div>
  441. <p>
  442. <label>';
  443. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  444. echo '<br />
  445. <input id="captcha_code" name="captcha_code" class="input" type="text" value="" tabindex="30" '.$si_aria_required.' style="font-size: 24px; width: 97%; padding: 3px; margin-top: 2px; margin-right: 6px; margin-bottom: 16px; border: 1px solid #e5e5e5; background: #fbfbfb;" /></label>
  446. </p>
  447. ';
  448. }
  449. return true;
  450. } // end function si_captcha_lostpassword_form
  451. // for wpmu and buddypress before 1.1
  452. function si_captcha_wpmu_signup_form( $errors ) {
  453. global $si_captcha_url, $si_captcha_opt;
  454. if ($si_captcha_opt['si_captcha_register'] != 'true') {
  455. return true; // captcha setting is disabled for registration
  456. }
  457. $error = $errors->get_error_message('captcha');
  458. if( isset($error) && $error != '') {
  459. echo '<p class="error">' . $error . '</p>';
  460. }
  461. // Test for some required things, print error message right here if not OK.
  462. if ($this->si_captcha_check_requires()) {
  463. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  464. // the captcha html - wpmu register form
  465. echo '
  466. <div ';
  467. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  468. echo '>';
  469. $this->si_captcha_captcha_html('si_image_reg','reg');
  470. echo '</div>
  471. <label for="captcha_code">';
  472. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  473. echo '</label>
  474. <input id="captcha_code" name="captcha_code" type="text" value="" '.$si_aria_required.' />
  475. ';
  476. }
  477. } // end function si_captcha_wpmu_signup_form
  478. // for buddypress 1.1+ only
  479. // hooks into register.php do_action( 'bp_before_registration_submit_buttons' )
  480. // and bp-core-signup.php add_action( 'bp_' . $fieldname . '_errors', ...
  481. function si_captcha_bp_signup_form() {
  482. global $si_captcha_url, $si_captcha_opt;
  483. if ($si_captcha_opt['si_captcha_register'] != 'true') {
  484. return true; // captcha setting is disabled for registration
  485. }
  486. // Test for some required things, print error message right here if not OK.
  487. if ($this->si_captcha_check_requires()) {
  488. $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
  489. // the captcha html - buddypress 1.1 register form
  490. echo '
  491. <div class="register-section" style="clear:left; margin-top:-10px;">
  492. <div ';
  493. echo ($si_captcha_opt['si_captcha_captcha_small'] == 'true') ? 'class="captchaSizeDivSmall"' : 'class="captchaSizeDivLarge"';
  494. echo '>';
  495. $this->si_captcha_captcha_html('si_image_reg','reg');
  496. echo '</div>
  497. <label for="captcha_code">';
  498. do_action( 'bp_captcha_code_errors' );
  499. echo ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
  500. echo '</label>
  501. <input style="width:145px;" id="captcha_code" name="captcha_code" type="text" value="" '.$si_aria_required.' />
  502. </div>
  503. ';
  504. }
  505. } // end function si_captcha_wpmu_signup_form
  506. // this function checks the captcha posted with registration on BuddyPress 1.1+
  507. // hooks into bp-core-signup.php do_action( 'bp_signup_validate' );
  508. function si_captcha_bp_signup_validate() {
  509. global $bp, $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt;
  510. $validate_result = $this->si_captcha_validate_code('reg', 'unlink');
  511. if($validate_result != 'valid') {
  512. $bp->signup->errors['captcha_code'] = $validate_result;
  513. return;
  514. }
  515. return;
  516. } // end function si_captcha_bp_signup_validate
  517. // this function checks the captcha posted with registration on wpmu and buddypress before 1.1
  518. function si_captcha_wpmu_signup_post($errors) {
  519. global $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt;
  520. if ($_POST['stage'] == 'validate-user-signup') {
  521. $validate_result = $this->si_captcha_validate_code('reg', 'unlink');
  522. if($validate_result != 'valid') {
  523. $error = ($si_captcha_opt['si_captcha_error_error'] != '') ? $si_captcha_opt['si_captcha_error_error'] : __('ERROR', 'si-captcha');
  524. $errors['errors']->add('captcha', "<strong>$error</strong>: $validate_result");
  525. return $errors;
  526. }
  527. }
  528. return($errors);
  529. } // end function si_captcha_wpmu_signup_post
  530. // this function checks the captcha posted with registration
  531. function si_captcha_register_post($errors) {
  532. global $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt;
  533. $validate_result = $this->si_captcha_validate_code('reg', 'unlink');
  534. if($validate_result != 'valid') {
  535. $error = ($si_captcha_opt['si_captcha_error_error'] != '') ? $si_captcha_opt['si_captcha_error_error'] : __('ERROR', 'si-captcha');
  536. $errors->add('captcha_error', "<strong>$error</strong>: $validate_result");
  537. return $errors;
  538. }
  539. return($errors);
  540. } // end function si_captcha_register_post
  541. function si_captcha_lostpassword_post() {
  542. global $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt;
  543. $validate_result = $this->si_captcha_validate_code('reg', 'unlink');
  544. if($validate_result != 'valid') {
  545. $error = ($si_captcha_opt['si_captcha_error_error'] != '') ? $si_captcha_opt['si_captcha_error_error'] : __('ERROR', 'si-captcha');
  546. wp_die( "<strong>$error</strong>: $validate_result" );
  547. }
  548. return;
  549. } // function si_captcha_lostpassword_post
  550. // this function checks the captcha posted with the comment
  551. function si_captcha_comment_post($comment) {
  552. global $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt;
  553. // added for compatibility with WP Wall plugin
  554. // this does NOT add CAPTCHA to WP Wall plugin,
  555. // it just prevents the "Empty CAPTCHA" when submitting a WP Wall comment
  556. if ( function_exists('WPWall_Widget') && isset($_POST['wpwall_comment']) ) {
  557. // skip capthca
  558. return $comment;
  559. }
  560. // skip the captcha if user is logged in and the settings allow
  561. if (is_user_logged_in() && $si_captcha_opt['si_captcha_perm'] == 'true') {
  562. // skip the CAPTCHA display if the minimum capability is met
  563. if ( current_user_can( $si_captcha_opt['si_captcha_perm_level'] ) ) {
  564. // skip capthca
  565. return $comment;
  566. }
  567. }
  568. // skip captcha for comment replies from admin menu
  569. if ( isset($_POST['action']) && $_POST['action'] == 'replyto-comment' &&
  570. ( check_ajax_referer( 'replyto-comment', '_ajax_nonce', false ) || check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment', false )) ) {
  571. // skip capthca
  572. return $comment;
  573. }
  574. // Skip captcha for trackback or pingback
  575. if ( $comment['comment_type'] != '' && $comment['comment_type'] != 'comment' ) {
  576. // skip capthca
  577. return $comment;
  578. }
  579. $validate_result = $this->si_captcha_validate_code('com', 'unlink');
  580. if($validate_result != 'valid') {
  581. $error = ($si_captcha_opt['si_captcha_error_error'] != '') ? $si_captcha_opt['si_captcha_error_error'] : __('ERROR', 'si-captcha');
  582. wp_die( "<strong>$error</strong>: $validate_result" );
  583. }
  584. return($comment);
  585. } // end function si_captcha_comment_post
  586. function si_wp_authenticate_username_password($user, $username, $password) {
  587. global $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt, $wp_version;
  588. if ( is_a($user, 'WP_User') ) { return $user; }
  589. if ( empty($username) || empty($password) || isset($_POST['captcha_code']) && empty($_POST['captcha_code'])) {
  590. $error = new WP_Error();
  591. if ( empty($username) )
  592. $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
  593. if ( empty($password) )
  594. $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
  595. if (isset($_POST['captcha_code']) && empty($_POST['captcha_code'])) {
  596. remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
  597. $print_error = ($si_captcha_opt['si_captcha_error_error'] != '') ? $si_captcha_opt['si_captcha_error_error'] : __('ERROR', 'si-captcha');
  598. $empty_captcha = ($si_captcha_opt['si_captcha_error_empty'] != '') ? $si_captcha_opt['si_captcha_error_empty'] : __('Empty CAPTCHA', 'si-captcha');
  599. $error->add('empty_captcha', "<strong>$print_error</strong>: $empty_captcha");
  600. }
  601. return $error;
  602. }
  603. // begin si captcha check
  604. $validate_result = $this->si_captcha_validate_code('log', 'unlink');
  605. if($validate_result != 'valid') {
  606. remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
  607. $print_error = ($si_captcha_opt['si_captcha_error_error'] != '') ? $si_captcha_opt['si_captcha_error_error'] : __('ERROR', 'si-captcha');
  608. return new WP_Error('captcha_error', "<strong>$print_error</strong>: $validate_result");
  609. }
  610. // end si captcha check
  611. $userdata = get_user_by('login', $username);
  612. if ( !$userdata ) {
  613. return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));
  614. }
  615. // for WP 3.0+ ONLY!
  616. if( version_compare($wp_version,'3','>=') ) { // wp 3.0 +
  617. if ( is_multisite() ) {
  618. // Is user marked as spam?
  619. if ( 1 == $userdata->spam)
  620. return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Your account has been marked as a spammer.'));
  621. // Is a user's blog marked as spam?
  622. if ( !is_super_admin( $userdata->ID ) && isset($userdata->primary_blog) ) {
  623. $details = get_blog_details( $userdata->primary_blog );
  624. if ( is_object( $details ) && $details->spam == 1 )
  625. return new WP_Error('blog_suspended', __('Site Suspended.'));
  626. }
  627. }
  628. }
  629. $userdata = apply_filters('wp_authenticate_user', $userdata, $password);
  630. if ( is_wp_error($userdata) ) {
  631. return $userdata;
  632. }
  633. if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) ) {
  634. return new WP_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: Incorrect password. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));
  635. }
  636. $user = new WP_User($userdata->ID);
  637. return $user;
  638. } // end function si_wp_authenticate_username_password
  639. // check the honeypot trap for spam bots
  640. // hidden empty field honyepot trap for spam bots
  641. function si_captcha_check_honeypot($form_id = 'com') {
  642. global $si_captcha_opt;
  643. if ($si_captcha_opt['si_captcha_honeypot_enable'] == 'false')
  644. return 'ok';
  645. // validate hidden honeypot field
  646. if( isset($_POST["email_$form_id"]) && trim($_POST["email_$form_id"]) != '')
  647. return 'failed honeypot';
  648. return 'ok';
  649. } // end function si_captcha_check_honeypot
  650. // check if the posted capcha code was valid
  651. function si_captcha_validate_code($form_id = 'com', $unlink = 'unlink') {
  652. global $si_captcha_dir, $si_captcha_dir_ns, $si_captcha_opt;
  653. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'lostpassword' && $form_id == 'log')
  654. return 'valid'; // fixes lostpassword page because add_filter('login_errors' is also being called before
  655. if (isset($_POST['captcha_code']) && empty($_POST['captcha_code']))
  656. return ($si_captcha_opt['si_captcha_error_empty'] != '') ? $si_captcha_opt['si_captcha_error_empty'] : __('Empty CAPTCHA', 'si-captcha');
  657. if($si_captcha_opt['si_captcha_enable_session'] != 'true') {
  658. //captcha without sessions
  659. if (empty($_POST['captcha_code']) || $_POST['captcha_code'] == '') {
  660. return ($si_captcha_opt['si_captcha_error_empty'] != '') ? $si_captcha_opt['si_captcha_error_empty'] : __('Empty CAPTCHA', 'si-captcha');
  661. }else if (!isset($_POST["si_code_$form_id"]) || empty($_POST["si_code_$form_id"])) {
  662. return ($si_captcha_opt['si_captcha_error_token'] != '') ? $si_captcha_opt['si_captcha_error_token'] : __('Missing CAPTCHA token', 'si-captcha');
  663. }else{
  664. $prefix = 'xxxxxx';
  665. if ( isset($_POST["si_code_$form_id"]) && is_string($_POST["si_code_$form_id"]) && preg_match('/^[a-zA-Z0-9]{15,17}$/',$_POST["si_code_$form_id"]) ){
  666. $prefix = $_POST["si_code_$form_id"];
  667. }
  668. if ( is_readable( $si_captcha_dir_ns . $prefix . '.php' ) ) {
  669. include( $si_captcha_dir_ns . $prefix . '.php' );
  670. if ( 0 == strcasecmp( trim(strip_tags($_POST['captcha_code'])), $captcha_word ) ) {
  671. // captcha was matched
  672. if($unlink == 'unlink')
  673. @unlink ($si_captcha_dir_ns . $prefix . '.php');
  674. // empty field honyepot trap for spam bots
  675. $hp_check = $this->si_captcha_check_honeypot("$form_id");
  676. if($hp_check != 'ok')
  677. return ($si_captcha_opt['si_captcha_error_spambot'] != '') ? $si_captcha_opt['si_captcha_error_spambot'] : __('Possible spam bot', 'si-captcha');
  678. return 'valid';
  679. } else {
  680. return ($si_captcha_opt['si_captcha_error_incorrect'] != '') ? $si_captcha_opt['si_captcha_error_incorrect'] : __('Wrong CAPTCHA', 'si-captcha');
  681. }
  682. } else {
  683. return ($si_captcha_opt['si_captcha_error_unreadable'] != '') ? $si_captcha_opt['si_captcha_error_unreadable'] : __('Unreadable CAPTCHA token file', 'si-captcha');
  684. //$this->si_captcha_token_error();
  685. }
  686. }
  687. }else{
  688. //captcha with PHP sessions
  689. if (!isset($_SESSION["securimage_code_si_$form_id"]) || empty($_SESSION["securimage_code_si_$form_id"])) {
  690. return ($si_captcha_opt['si_captcha_error_cookie'] != '') ? $si_captcha_opt['si_captcha_error_cookie'] : __('Unreadable CAPTCHA cookie', 'si-captcha');
  691. }else{
  692. $captcha_code = trim(strip_tags($_POST['captcha_code']));
  693. require_once "$si_captcha_dir/securimage.php";
  694. $img = new Securimage_si();
  695. $img->form_id = $form_id; // makes compatible with multi-forms on same page
  696. $valid = $img->check("$captcha_code");
  697. // Check, that the right CAPTCHA password has been entered, display an error message otherwise.
  698. if($valid == true) {
  699. // empty field honyepot trap for spam bots
  700. $hp_check= $this->si_captcha_check_honeypot("$form_id");
  701. if($hp_check != 'ok')
  702. return ($si_captcha_opt['si_captcha_error_spambot'] != '') ? $si_captcha_opt['si_captcha_error_spambot'] : __('Possible spam bot', 'si-captcha');
  703. // ok can continue
  704. return 'valid';
  705. } else {
  706. return ($si_captcha_opt['si_captcha_error_incorrect'] != '') ? $si_captcha_opt['si_captcha_error_incorrect'] : __('Wrong CAPTCHA', 'si-captcha');
  707. }
  708. }
  709. }
  710. } // end function si_captcha_validate_code
  711. // displays the CAPTCHA in the forms
  712. function si_captcha_captcha_html($label = 'si_image', $form_id = 'com', $no_echo = false) {
  713. global $si_captcha_url, $si_captcha_dir, $si_captcha_url_ns, $si_captcha_dir_ns, $si_captcha_opt;
  714. $capt_disable_sess = 0;
  715. if ($si_captcha_opt['si_captcha_enable_session'] != 'true')
  716. $capt_disable_sess = 1;
  717. // url for no session captcha image
  718. $securimage_show_url = $si_captcha_url .'/securimage_show.php?';
  719. $securimage_size = 'width="175" height="60"';
  720. if($si_captcha_opt['si_captcha_captcha_small'] == 'true' || $label == 'si_image_side_login' ) {
  721. $securimage_show_url .= 'si_sm_captcha=1&amp;';
  722. $securimage_size = 'width="132" height="45"';
  723. }
  724. $parseUrl = parse_url($si_captcha_url);
  725. $securimage_url = $parseUrl['path'];
  726. $securimage_show_url .= 'si_form_id=' .$form_id;
  727. if($capt_disable_sess) {
  728. // clean out old captcha no session temp files
  729. $this->si_captcha_clean_temp_dir($si_captcha_dir_ns, 30);
  730. // pick new prefix token
  731. $prefix_length = 16;
  732. $prefix_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  733. $prefix = '';
  734. $prefix_count = strlen($prefix_characters);
  735. while ($prefix_length--) {
  736. $prefix .= $prefix_characters[mt_rand(0, $prefix_count-1)];
  737. }
  738. $securimage_show_rf_url = $securimage_show_url . '&amp;prefix=';
  739. $securimage_show_url .= '&amp;prefix='.$prefix;
  740. }
  741. $si_html = '';
  742. if($si_captcha_opt['si_captcha_honeypot_enable'] == 'true' ) {
  743. // hidden empty honeypot field
  744. $si_html .= '
  745. <div style="display:none;">
  746. <label for="email_'.$form_id.'"><small>'.__('Leave this field empty', 'si-captcha').'</small></label>
  747. <input type="text" name="email_'.$form_id.'" id="email_'.$form_id.'" value="" />
  748. </div>
  749. ';
  750. }
  751. $si_html .= '<img id="'.$label.'" class="si-captcha" src="'.$securimage_show_url.'" '.$securimage_size.' alt="';
  752. $si_html .= ($si_captcha_opt['si_captcha_tooltip_captcha'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_captcha'] ) : esc_attr(__('CAPTCHA Image', 'si-captcha'));
  753. $si_html .= '" title="';
  754. $si_html .= ($si_captcha_opt['si_captcha_tooltip_captcha'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_captcha'] ) : esc_attr(__('CAPTCHA Image', 'si-captcha'));
  755. $si_html .= '" />'."\n";
  756. if($capt_disable_sess) {
  757. $si_html .= ' <input id="si_code_'.$form_id.'" name="si_code_'.$form_id.'" type="hidden" value="'.$prefix.'" />'."\n";
  758. }
  759. $si_html .= ' <div id="si_refresh_'.$form_id.'">'."\n";
  760. $si_html .= '<a href="#" rel="nofollow" title="';
  761. $si_html .= ($si_captcha_opt['si_captcha_tooltip_refresh'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_refresh'] ) : esc_attr(__('Refresh Image', 'si-captcha'));
  762. if($capt_disable_sess) {
  763. $si_html .= '" onclick="si_captcha_refresh(\''.$label.'\',\''.$form_id.'\',\''.$securimage_url.'\',\''.$securimage_show_rf_url.'\'); return false;">'."\n";
  764. }else{
  765. $si_html .= '" onclick="document.getElementById(\''.$label.'\').src = \''.$securimage_show_url.'&amp;sid=\''.' + Math.random(); return false;">'."\n";
  766. }
  767. $si_html .= ' <img class="captchaImgRefresh" src="'.$si_captcha_url.'/images/refresh.png" width="22" height="20" alt="';
  768. $si_html .= ($si_captcha_opt['si_captcha_tooltip_refresh'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_refresh'] ) : esc_attr(__('Refresh Image', 'si-captcha'));
  769. $si_html .= '" onclick="this.blur();" /></a>
  770. </div>
  771. ';
  772. if ( $no_echo ) return $si_html;
  773. echo $si_html;
  774. } // end function si_captcha_captcha_html
  775. function si_captcha_plugin_action_links( $links, $file ) {
  776. //Static so we don't call plugin_basename on every plugin row.
  777. static $this_plugin;
  778. if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
  779. if ( $file == $this_plugin ){
  780. $settings_link = '<a href="plugins.php?page=si-captcha-for-wordpress/si-captcha.php">' . __('Settings', 'si-captcha') . '</a>';
  781. array_unshift( $links, $settings_link );
  782. }
  783. return $links;
  784. } // end function si_captcha_plugin_action_links
  785. function si_captcha_init() {
  786. global $wpmu;
  787. if (function_exists('load_plugin_textdomain')) {
  788. if ($wpmu == 1) {
  789. load_plugin_textdomain('si-captcha', false, dirname(plugin_basename(__FILE__)).'/si-captcha-for-wordpress/languages' );
  790. } else {
  791. load_plugin_textdomain('si-captcha', false, dirname(plugin_basename(__FILE__)).'/languages' );
  792. }
  793. }
  794. } // end function si_captcha_init
  795. function si_captcha_start_session() {
  796. // a PHP session cookie is set so that the captcha can be remembered and function
  797. // this has to be set before any header output
  798. //echo "before starting session si captcha";
  799. if( !isset( $_SESSION ) ) { // play nice with other plugins
  800. if ( !defined('XMLRPC_REQUEST') ) { // buddypress fix
  801. //set the $_SESSION cookie into HTTPOnly mode for better security
  802. if (version_compare(PHP_VERSION, '5.2.0') >= 0) // supported on PHP version 5.2.0 and higher
  803. @ini_set("session.cookie_httponly", 1);
  804. session_cache_limiter ('private, must-revalidate');
  805. session_start();
  806. //echo "session started si captcha";
  807. }
  808. }
  809. } // function si_captcha_start_session
  810. // needed for making temp directories for attachments and captcha session files
  811. function si_captcha_init_temp_dir($dir) {
  812. $dir = trailingslashit( $dir );
  813. // make the temp directory
  814. wp_mkdir_p( $dir );
  815. //@chmod( $dir, 0733 );
  816. $htaccess_file = $dir . '.htaccess';
  817. if ( !file_exists( $htaccess_file ) ) {
  818. if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
  819. fwrite( $handle, "Deny from all\n" );
  820. fclose( $handle );
  821. }
  822. }
  823. $php_file = $dir . 'index.php';
  824. if ( !file_exists( $php_file ) ) {
  825. if ( $handle = @fopen( $php_file, 'w' ) ) {
  826. fwrite( $handle, '<?php //do not delete ?>' );
  827. fclose( $handle );
  828. }
  829. }
  830. } // end function si_captcha_init_temp_dir
  831. // needed for emptying temp directories for attachments and captcha session files
  832. function si_captcha_clean_temp_dir($dir, $minutes = 60) {
  833. // deletes all files over xx minutes old in a temp directory
  834. if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! is_writable( $dir ) )
  835. return false;
  836. $count = 0;
  837. if ( $handle = @opendir( $dir ) ) {
  838. while ( false !== ( $file = readdir( $handle ) ) ) {
  839. if ( $file == '.' || $file == '..' || $file == '.htaccess' || $file == 'index.php')
  840. continue;
  841. $stat = @stat( $dir . $file );
  842. if ( ( $stat['mtime'] + $minutes * 60 ) < time() ) {
  843. @unlink( $dir . $file );
  844. $count += 1;
  845. }
  846. }
  847. closedir( $handle );
  848. }
  849. return $count;
  850. }
  851. // functions for form vars
  852. function si_stripslashes($string) {
  853. //if (get_magic_quotes_gpc()) {
  854. // wordpress always needs stripslashes
  855. return stripslashes($string);
  856. //} else {
  857. //return $string;
  858. // }
  859. } // end function si_stripslashes
  860. function si_captcha_convert_css($string,$css) {
  861. global $si_captcha_option_defaults;
  862. if( preg_match("/^style=\"(.*)\"$/i", $string, $matches) ){
  863. return $matches[1];
  864. }
  865. if( preg_match("/^class=\"(.*)\"$/i", $string) ){
  866. return (isset($si_captcha_option_defaults[$css])) ? $si_captcha_option_defaults[$css] : $string;
  867. }
  868. return $string;
  869. } // end function si_captcha_convert_css
  870. function si_captcha_admin_head() {
  871. // only load this header stuff on the admin settings page
  872. if(isset($_GET['page']) && is_string($_GET['page']) && preg_match('/si-captcha.php$/',$_GET['page']) ) {
  873. ?>
  874. <!-- begin SI CAPTCHA Anti-Spam - admin settings page header code -->
  875. <style type="text/css">
  876. div.si-star-holder { position: relative; height:19px; width:100px; font-size:19px;}
  877. div.si-star {height: 100%; position:absolute; top:0px; left:0px; background-color: transparent; letter-spacing:1ex; border:none;}
  878. .si-star1 {width:20%;} .si-star2 {width:40%;} .si-star3 {width:60%;} .si-star4 {width:80%;} .si-star5 {width:100%;}
  879. .si-star.si-star-rating {background-color: #fc0;}
  880. .si-star img{display:block; position:absolute; right:0px; border:none; text-decoration:none;}
  881. div.si-star img {width:19px; height:19px; border-left:1px solid #fff; border-right:1px solid #fff;}
  882. .si-notice{background-color:#ffffe0;border-color:#e6db55;border-width:1px;border-style:solid;padding:5px;margin:5px 5px 20px;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}
  883. .fscf_left {clear:left; float:left;}
  884. .fscf_img {margin:0 10px 10px 0;}
  885. .fscf_tip {text-align:left; display:none;color:#006B00;padding:5px;}
  886. </style>
  887. <!-- end SI CAPTCHA Anti-Spam - admin settings page header code -->
  888. <?php
  889. } // end if(isset($_GET['page'])
  890. }
  891. function si_captcha_login_head(){
  892. global $si_captcha_opt;
  893. echo '<script type="text/javascript" src="'.plugins_url('si-captcha-for-wordpress/captcha/si_captcha.js?ver='.time()).'"></script>'."\n";
  894. // only load this css on the blog pages where login/register could be
  895. if( $si_captcha_opt['si_captcha_external_style'] == 'true' )
  896. return;
  897. ?>
  898. <!-- begin SI CAPTCHA Anti-Spam - login/register form style -->
  899. <style type="text/css">
  900. div#captchaImgDiv { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_captcha_div_style'],'si_captcha_captcha_div_style'); ?> }
  901. .captchaSizeDivSmall { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_captcha_div_style_sm'],'si_captcha_captcha_div_style_sm'); ?> }
  902. .captchaSizeDivLarge { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_captcha_div_style_m'],'si_captcha_captcha_div_style_m'); ?> }
  903. img#si_image_com,#si_image_reg,#si_image_log,#si_image_side_login { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_captcha_image_style'],'si_captcha_captcha_image_style'); ?> }
  904. .captchaImgRefresh { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_refresh_image_style'],'si_captcha_refresh_image_style'); ?> }
  905. div#captchaInputDiv { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_captcha_input_div_style'],'si_captcha_captcha_input_div_style'); ?> }
  906. label#captcha_code_label { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_comment_label_style'],'si_captcha_comment_label_style'); ?> }
  907. input#captcha_code { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_comment_field_style'],'si_captcha_comment_field_style'); ?> }
  908. </style>
  909. <!-- end SI CAPTCHA Anti-Spam - login/register form style -->
  910. <?php
  911. }
  912. function si_captcha_add_css(){
  913. global $si_captcha_opt, $si_captcha_add_script;
  914. if (!$si_captcha_add_script)
  915. return;
  916. // only load this css on the blog pages where the captcha could be
  917. wp_enqueue_script('jquery');
  918. if( $si_captcha_opt['si_captcha_external_style'] != 'true' ) {
  919. ?>
  920. <script type="text/javascript">
  921. //<![CDATA[
  922. var si_captcha_styles = "\
  923. <!-- begin SI CAPTCHA Anti-Spam - comment form style -->\
  924. <style type='text/css'>\
  925. div#captchaImgDiv { <?php echo $this->si_captcha_convert_css($si_captcha_opt['si_captcha_captcha_div_style'],'si_captcha_captcha_div_style'); ?> }\
  926. .captchaSizeDivSmall { <?php echo $this->si_captcha_conv

Large files files are truncated, but you can click here to view the full file