source: extensions/EasyCaptcha/admin.php @ 24215

Last change on this file since 24215 was 24215, checked in by mistic100, 11 years ago

add extension EasyCaptcha

File size: 3.3 KB
Line 
1<?php
2defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
3
4global $pwg_loaded_plugins;
5$loaded = array(
6  'contactform' => isset($pwg_loaded_plugins['ContactForm']),
7  'category' => isset($pwg_loaded_plugins['Comments_on_Albums']),
8  'guestbook' => isset($pwg_loaded_plugins['GuestBook']),
9  'cryptocaptcha' => isset($pwg_loaded_plugins['CryptograPHP']),
10  );
11
12if ($loaded['cryptocaptcha'])
13{
14  $page['warnings'][] = l10n('easycaptcha_cryptocaptcha');
15}
16
17if (isset($_POST['submit']))
18{
19  $conf['EasyCaptcha'] = array(
20    'activate_on'     => array(
21      'picture'     => in_array('picture', $_POST['activate_on']),
22      'category'    => in_array('category', $_POST['activate_on']) || !$loaded['category'],
23      'register'    => in_array('register', $_POST['activate_on']),
24      'contactform' => in_array('contactform', $_POST['activate_on']) || !$loaded['contactform'],
25      'guestbook'   => in_array('guestbook', $_POST['activate_on']) || !$loaded['guestbook'],
26      ),
27    'comments_action' => $_POST['comments_action'],
28    'challenge' => $_POST['challenge'],
29    'drag' => array(
30      'theme' => $_POST['drag']['theme'],
31      'size'  => (int)$_POST['drag']['size'],
32      'nb'    => (int)$_POST['drag']['nb'],
33      'bg1'   => check_color($_POST['drag']['bg1']),
34      'bg2'   => check_color($_POST['drag']['bg2']),
35      'obj'   => check_color($_POST['drag']['obj']),
36      'sel'   => check_color($_POST['drag']['sel']),
37      'bd1'   => check_color($_POST['drag']['bd1']),
38      'bd2'   => check_color($_POST['drag']['bd2']),
39      'txt'   => check_color($_POST['drag']['txt']),
40      ),
41    'tictac' => array(
42      'size'  => (int)$_POST['tictac']['size'],
43      'bg1'   => check_color($_POST['tictac']['bg1']),
44      'bg2'   => check_color($_POST['tictac']['bg2']),
45      'bd'    => check_color($_POST['tictac']['bd']),
46      'obj'   => check_color($_POST['tictac']['obj']),
47      'sel'   => check_color($_POST['tictac']['sel']),
48      ),
49    );
50
51  conf_update_param('EasyCaptcha', serialize($conf['EasyCaptcha']));
52  array_push($page['infos'], l10n('Information data registered in database'));
53}
54
55function list_themes($dir)
56{
57  $dir = rtrim($dir, '/');
58  $dh = opendir($dir);
59  $themes = array();
60
61  while (($item = readdir($dh)) !== false )
62  {
63    if ($item!=='.' && $item!=='..' && file_exists($dir.'/'.$item.'/conf.inc.php'))
64    {
65      $drag_images = include($dir.'/'.$item.'/conf.inc.php');
66      $themes[$item] = array(
67        'image' => key($drag_images),
68        'count' => count($drag_images),
69        );
70    }
71  }
72
73  closedir($dh);
74  return $themes;
75}
76
77$template->assign(array(
78  'easycaptcha' => $conf['EasyCaptcha'],
79  'loaded' => $loaded,
80  'THEMES' => list_themes(EASYCAPTCHA_PATH.'drag'),
81  'EASYCAPTCHA_PATH' => EASYCAPTCHA_PATH,
82  'EASYCAPTCHA_ABS_PATH' => realpath(EASYCAPTCHA_PATH).'/',
83  ));
84
85$template->set_filename('plugin_admin_content', realpath(EASYCAPTCHA_PATH.'template/admin.tpl'));
86$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
87
88
89function check_color($hex)
90{
91  global $page;
92
93  $hex = ltrim($hex, '#');
94
95  if (strlen($hex) == 3)
96  {
97    $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2];
98  }
99  else if (strlen($hex) != 6)
100  {
101    $page['errors'][] = sprintf(l10n('Invalid color code <i>%s</i>'), '#'.$hex);
102    $hex = '000000';
103  }
104
105  return '#'.$hex;
106}
Note: See TracBrowser for help on using the repository browser.