[17483] | 1 | <?php |
---|
| 2 | if (!defined('CONTACT_FORM_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * define page section from url |
---|
| 6 | */ |
---|
| 7 | function contact_form_section_init() |
---|
| 8 | { |
---|
| 9 | global $tokens, $page, $conf; |
---|
[25872] | 10 | |
---|
[17483] | 11 | if ($tokens[0] == 'contact') |
---|
| 12 | { |
---|
| 13 | $page['section'] = 'contact'; |
---|
[25872] | 14 | $page['title'] = l10n('Contact'); |
---|
| 15 | $page['body_id'] = 'theContactPage'; |
---|
| 16 | $page['is_external'] = true; |
---|
[20795] | 17 | $page['is_homepage'] = false; |
---|
[25872] | 18 | |
---|
| 19 | $page['section_title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.CONTACT_FORM_PUBLIC.'">'.l10n('Contact').'</a>'; |
---|
[17483] | 20 | } |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | /** |
---|
[25872] | 24 | * contact page |
---|
[17483] | 25 | */ |
---|
| 26 | function contact_form_page() |
---|
| 27 | { |
---|
| 28 | global $page; |
---|
| 29 | |
---|
| 30 | if (isset($page['section']) and $page['section'] == 'contact') |
---|
| 31 | { |
---|
[25872] | 32 | include(CONTACT_FORM_PATH . 'include/contact_form.inc.php'); |
---|
[17483] | 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
[25872] | 36 | /** |
---|
| 37 | * public menu link |
---|
[17483] | 38 | */ |
---|
| 39 | function contact_form_applymenu($menu_ref_arr) |
---|
| 40 | { |
---|
| 41 | global $conf; |
---|
| 42 | |
---|
[25872] | 43 | if (!$conf['ContactForm']['cf_menu_link']) return; |
---|
| 44 | if (!is_classic_user() and !$conf['ContactForm']['cf_allow_guest']) return; |
---|
| 45 | if (!$conf['ContactForm_ready']) return; |
---|
| 46 | |
---|
[17483] | 47 | $menu = &$menu_ref_arr[0]; |
---|
| 48 | if (($block = $menu->get_block('mbMenu')) != null) |
---|
| 49 | { |
---|
[25872] | 50 | $block->data[] = array( |
---|
[17483] | 51 | 'URL' => CONTACT_FORM_PUBLIC, |
---|
| 52 | 'NAME' => l10n('Contact'), |
---|
[25872] | 53 | ); |
---|
[17483] | 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
[25872] | 58 | * change contact link in footer |
---|
[17491] | 59 | */ |
---|
| 60 | function contact_form_footer_link($content, &$smarty) |
---|
| 61 | { |
---|
| 62 | $search = '<a href="mailto:{$CONTACT_MAIL}?subject={\'A comment on your site\'|@translate|@escape:url}">'; |
---|
[25872] | 63 | $replace = '<a href="{$CONTACT_FORM_PUBLIC}">'; |
---|
[17491] | 64 | return str_replace($search, $replace, $content); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
[25872] | 68 | * change contact link in mail footer |
---|
| 69 | */ |
---|
| 70 | function contact_form_mail_template($cache_key, $content_type) |
---|
| 71 | { |
---|
| 72 | global $conf_mail; |
---|
| 73 | |
---|
| 74 | $template = &$conf_mail[$cache_key]['theme']; |
---|
| 75 | $template->assign('CONTACT_FORM_PUBLIC', CONTACT_FORM_PUBLIC); |
---|
| 76 | |
---|
| 77 | if ($content_type == 'text/html') |
---|
| 78 | { |
---|
| 79 | $template->set_prefilter('mail_footer', 'contact_form_mail_template_html'); |
---|
| 80 | } |
---|
| 81 | else |
---|
| 82 | { |
---|
| 83 | $template->set_prefilter('mail_footer', 'contact_form_mail_template_plain'); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | function contact_form_mail_template_html($content) |
---|
| 87 | { |
---|
| 88 | return str_replace( |
---|
| 89 | 'mailto:{$CONTACT_MAIL}?subject={\'A comment on your site\'|translate|escape:url}', |
---|
| 90 | '{$CONTACT_FORM_PUBLIC}', |
---|
| 91 | $content |
---|
| 92 | ); |
---|
| 93 | } |
---|
| 94 | function contact_form_mail_template_plain($content) |
---|
| 95 | { |
---|
| 96 | return str_replace( |
---|
| 97 | '{$CONTACT_MAIL}', |
---|
| 98 | '{$CONTACT_FORM_PUBLIC}', |
---|
| 99 | $content |
---|
| 100 | ); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
[17483] | 104 | * init emails list |
---|
| 105 | */ |
---|
| 106 | function contact_form_initialize_emails() |
---|
| 107 | { |
---|
| 108 | global $conf; |
---|
[25872] | 109 | |
---|
[17483] | 110 | $query = ' |
---|
| 111 | SELECT |
---|
| 112 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 113 | u.'.$conf['user_fields']['email'].' AS email |
---|
| 114 | FROM '.USERS_TABLE.' AS u |
---|
| 115 | JOIN '.USER_INFOS_TABLE.' AS i |
---|
| 116 | ON i.user_id = u.'.$conf['user_fields']['id'].' |
---|
[24347] | 117 | WHERE i.status IN (\'webmaster\', \'admin\') |
---|
[17483] | 118 | AND '.$conf['user_fields']['email'].' IS NOT NULL |
---|
| 119 | ORDER BY username |
---|
| 120 | ;'; |
---|
| 121 | $result = pwg_query($query); |
---|
[25872] | 122 | |
---|
[17483] | 123 | $emails = array(); |
---|
| 124 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 125 | { |
---|
[25872] | 126 | $emails[] = array( |
---|
[17483] | 127 | 'name' => $row['username'], |
---|
| 128 | 'email' => $row['email'], |
---|
[17945] | 129 | 'active' => 'true', |
---|
[25872] | 130 | ); |
---|
[17483] | 131 | } |
---|
[25872] | 132 | |
---|
[17945] | 133 | mass_inserts( |
---|
| 134 | CONTACT_FORM_TABLE, |
---|
| 135 | array('name','email','active'), |
---|
[18331] | 136 | $emails |
---|
[17945] | 137 | ); |
---|
[25872] | 138 | |
---|
[17483] | 139 | $conf['ContactForm']['cf_must_initialize'] = false; |
---|
| 140 | conf_update_param('ContactForm', serialize($conf['ContactForm'])); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * Send comment to subscribers |
---|
| 146 | */ |
---|
| 147 | function send_contact_form(&$comm, $key) |
---|
| 148 | { |
---|
[25872] | 149 | global $conf, $page, $template; |
---|
| 150 | |
---|
[17945] | 151 | $query = ' |
---|
| 152 | SELECT DISTINCT group_name |
---|
| 153 | FROM '. CONTACT_FORM_TABLE .' |
---|
| 154 | ORDER BY group_name |
---|
| 155 | ;'; |
---|
| 156 | $groups = array_from_query($query, 'group_name'); |
---|
[25872] | 157 | |
---|
[17483] | 158 | $comm = array_merge($comm, |
---|
| 159 | array( |
---|
| 160 | 'ip' => $_SERVER['REMOTE_ADDR'], |
---|
| 161 | 'agent' => $_SERVER['HTTP_USER_AGENT'] |
---|
| 162 | ) |
---|
| 163 | ); |
---|
| 164 | |
---|
| 165 | $comment_action='validate'; |
---|
[25872] | 166 | |
---|
[17483] | 167 | // check key |
---|
| 168 | if (!verify_ephemeral_key(@$key)) |
---|
| 169 | { |
---|
| 170 | $comment_action='reject'; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | // check author |
---|
[25872] | 174 | if ($conf['ContactForm']['cf_mandatory_name'] and empty($comm['author'])) |
---|
[17483] | 175 | { |
---|
[25872] | 176 | $page['errors'][] = l10n('Please enter a name'); |
---|
[17483] | 177 | $comment_action='reject'; |
---|
| 178 | } |
---|
[25872] | 179 | |
---|
[17483] | 180 | // check email |
---|
[25872] | 181 | if ($conf['ContactForm']['cf_mandatory_mail'] and empty($comm['email'])) |
---|
[17483] | 182 | { |
---|
[25872] | 183 | $page['errors'][] = l10n('Please enter an e-mail'); |
---|
[17483] | 184 | $comment_action='reject'; |
---|
| 185 | } |
---|
[25872] | 186 | else if (!empty($comm['email']) and !email_check_format($comm['email'])) |
---|
[17483] | 187 | { |
---|
[25872] | 188 | $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'); |
---|
[17483] | 189 | $comment_action='reject'; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | // check subject |
---|
| 193 | if (empty($comm['subject'])) |
---|
| 194 | { |
---|
[25872] | 195 | $page['errors'][] = l10n('Please enter a subject'); |
---|
[17483] | 196 | $comment_action='reject'; |
---|
| 197 | } |
---|
| 198 | else if (strlen($comm['subject']) > 100) |
---|
| 199 | { |
---|
[25872] | 200 | $page['errors'][] = sprintf(l10n('%s must not be more than %d characters long'), l10n('Subject'), 100); |
---|
[17483] | 201 | $comment_action='reject'; |
---|
| 202 | } |
---|
[25872] | 203 | |
---|
[17945] | 204 | // check group |
---|
[25872] | 205 | if (count($groups) > 1 and $comm['group'] == -1) |
---|
[17945] | 206 | { |
---|
| 207 | $comm['group'] = true; |
---|
[25872] | 208 | $page['errors'][] = l10n('Please choose a category'); |
---|
[17945] | 209 | $comment_action='reject'; |
---|
| 210 | } |
---|
[25872] | 211 | |
---|
[17483] | 212 | // check content |
---|
| 213 | if (empty($comm['content'])) |
---|
| 214 | { |
---|
[25872] | 215 | $page['errors'][] = l10n('Please enter a message'); |
---|
[17483] | 216 | $comment_action='reject'; |
---|
| 217 | } |
---|
| 218 | else if (strlen($comm['subject']) > 2000) |
---|
| 219 | { |
---|
[25872] | 220 | $page['errors'][] = sprintf(l10n('%s must not be more than %d characters long'), l10n('Message'), 2000); |
---|
[17483] | 221 | $comment_action='reject'; |
---|
| 222 | } |
---|
[25872] | 223 | |
---|
[17483] | 224 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
| 225 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[25872] | 226 | |
---|
[17483] | 227 | add_event_handler('contact_form_check', 'user_comment_check', |
---|
| 228 | EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[25872] | 229 | |
---|
[17483] | 230 | // perform more spam check |
---|
| 231 | $comment_action = trigger_event('contact_form_check', $comment_action, $comm); |
---|
[25872] | 232 | |
---|
[17483] | 233 | // get admin emails |
---|
[17945] | 234 | $emails = get_contact_emails($comm['group']); |
---|
[17483] | 235 | if (!count($emails)) |
---|
| 236 | { |
---|
[25872] | 237 | $page['errors'][] = l10n('Error while sending e-mail'); |
---|
[17483] | 238 | $comment_action='reject'; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | if ($comment_action == 'validate') |
---|
| 242 | { |
---|
[26074] | 243 | $comm['content'] = trigger_change('render_contact_content', $comm['content']); |
---|
| 244 | |
---|
[17483] | 245 | $prefix = str_replace('%gallery_title%', $conf['gallery_title'], $conf['ContactForm']['cf_subject_prefix']); |
---|
[25872] | 246 | |
---|
| 247 | $from = $Cc = null; |
---|
| 248 | if (!empty($comm['email'])) |
---|
[17483] | 249 | { |
---|
[25872] | 250 | $from = array( |
---|
| 251 | 'name' => $comm['author'], |
---|
| 252 | 'email' => $comm['email'], |
---|
| 253 | ); |
---|
| 254 | if ($comm['send_copy']) |
---|
| 255 | { |
---|
| 256 | $Cc = $from; |
---|
| 257 | } |
---|
[17483] | 258 | } |
---|
[25872] | 259 | |
---|
[17483] | 260 | switch_lang_to(get_default_language()); |
---|
| 261 | load_language('plugin.lang', CONTACT_FORM_PATH); |
---|
[25872] | 262 | |
---|
| 263 | $result = pwg_mail( |
---|
| 264 | $emails, |
---|
| 265 | array( |
---|
| 266 | 'subject' => '['.$prefix.'] '.$comm['subject'], |
---|
| 267 | 'mail_title' => $prefix, |
---|
| 268 | 'mail_subtitle' => $comm['subject'], |
---|
| 269 | 'content_format' => 'text/html', |
---|
| 270 | 'from' => $from, |
---|
| 271 | 'Cc' => $Cc, |
---|
| 272 | ), |
---|
| 273 | array( |
---|
| 274 | 'filename' => 'mail', |
---|
| 275 | 'dirname' => realpath(CONTACT_FORM_PATH . 'template'), |
---|
| 276 | 'assign' => array( |
---|
| 277 | 'CONTACT' => $comm, |
---|
| 278 | ), |
---|
| 279 | ) |
---|
[17483] | 280 | ); |
---|
[25872] | 281 | |
---|
[17483] | 282 | switch_lang_back(); |
---|
| 283 | load_language('plugin.lang', CONTACT_FORM_PATH); |
---|
[25872] | 284 | |
---|
[17483] | 285 | if ($result == false) |
---|
| 286 | { |
---|
[25872] | 287 | $page['errors'][] = l10n('Error while sending e-mail'); |
---|
[17483] | 288 | $comment_action='reject'; |
---|
| 289 | } |
---|
| 290 | } |
---|
[25872] | 291 | |
---|
[17483] | 292 | return $comment_action; |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | /** |
---|
| 296 | * get contact emails |
---|
[17945] | 297 | * @param mixed group: |
---|
| 298 | * - bool true: all emails |
---|
| 299 | * - empty string: emails without group |
---|
| 300 | * - string: emails with the specified group |
---|
[17483] | 301 | */ |
---|
[17945] | 302 | function get_contact_emails($group=true) |
---|
[17483] | 303 | { |
---|
| 304 | global $conf; |
---|
[25872] | 305 | |
---|
[17483] | 306 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[25872] | 307 | |
---|
[17945] | 308 | $where = '1=1'; |
---|
| 309 | if ($group!==true) |
---|
[17483] | 310 | { |
---|
[17945] | 311 | if (empty($group)) |
---|
[17483] | 312 | { |
---|
[17945] | 313 | $where = 'group_name IS NULL'; |
---|
[17483] | 314 | } |
---|
[17945] | 315 | else |
---|
| 316 | { |
---|
| 317 | $where = 'group_name="'.$group.'"'; |
---|
| 318 | } |
---|
[17483] | 319 | } |
---|
[25872] | 320 | |
---|
[17945] | 321 | $query = ' |
---|
[25872] | 322 | SELECT name, email |
---|
[17945] | 323 | FROM '. CONTACT_FORM_TABLE .' |
---|
[25872] | 324 | WHERE |
---|
[17945] | 325 | '.$where.' |
---|
| 326 | AND active = "true" |
---|
| 327 | ORDER BY name ASC |
---|
| 328 | '; |
---|
[25872] | 329 | $emails = array_from_query($query); |
---|
| 330 | |
---|
[17483] | 331 | return $emails; |
---|
| 332 | } |
---|