1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Contact Form |
---|
4 | Version: auto |
---|
5 | Description: Add a "Contact" item in the Menu block to offer a contact form to users |
---|
6 | Plugin URI: auto |
---|
7 | Author: Piwigo Team |
---|
8 | Author URI: http://piwigo.org |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | global $prefixeTable; |
---|
14 | |
---|
15 | defined('CONTACT_FORM_ID') or define('CONTACT_FORM_ID', basename(dirname(__FILE__))); |
---|
16 | define('CONTACT_FORM_PATH', PHPWG_PLUGINS_PATH . CONTACT_FORM_ID . '/'); |
---|
17 | define('CONTACT_FORM_ADMIN', get_root_url() . 'admin.php?page=plugin-' . CONTACT_FORM_ID); |
---|
18 | define('CONTACT_FORM_PUBLIC', get_absolute_root_url() . make_index_url(array('section' => 'contact')) . '/'); |
---|
19 | define('CONTACT_FORM_TABLE', $prefixeTable .'contact_form'); |
---|
20 | define('CONTACT_FORM_VERSION', 'auto'); |
---|
21 | |
---|
22 | |
---|
23 | add_event_handler('init', 'contact_form_init'); |
---|
24 | |
---|
25 | if (defined('IN_ADMIN')) |
---|
26 | { |
---|
27 | add_event_handler('get_admin_plugin_menu_links', 'contact_form_admin_menu'); |
---|
28 | } |
---|
29 | else |
---|
30 | { |
---|
31 | add_event_handler('loc_end_section_init', 'contact_form_section_init'); |
---|
32 | add_event_handler('loc_end_index', 'contact_form_page'); |
---|
33 | } |
---|
34 | |
---|
35 | add_event_handler('blockmanager_apply', 'contact_form_applymenu', EVENT_HANDLER_PRIORITY_NEUTRAL+10); |
---|
36 | add_event_handler('before_parse_mail_template', 'contact_form_mail_template', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
37 | |
---|
38 | include(CONTACT_FORM_PATH . 'include/functions.inc.php'); |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * update & unserialize conf & load language & init emails |
---|
43 | */ |
---|
44 | function contact_form_init() |
---|
45 | { |
---|
46 | global $conf, $template, $pwg_loaded_plugins; |
---|
47 | |
---|
48 | include_once(CONTACT_FORM_PATH . 'maintain.inc.php'); |
---|
49 | $maintain = new ContactForm_maintain(CONTACT_FORM_ID); |
---|
50 | $maintain->autoUpdate(CONTACT_FORM_VERSION, 'install'); |
---|
51 | |
---|
52 | $conf['ContactForm'] = unserialize($conf['ContactForm']); |
---|
53 | load_language('plugin.lang', CONTACT_FORM_PATH); |
---|
54 | load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true)); |
---|
55 | |
---|
56 | if ($conf['ContactForm']['cf_must_initialize']) |
---|
57 | { |
---|
58 | contact_form_initialize_emails(); |
---|
59 | } |
---|
60 | |
---|
61 | $conf['ContactForm_ready'] = count(get_contact_emails()); |
---|
62 | |
---|
63 | if ($conf['ContactForm_ready'] && (!is_a_guest() || $conf['ContactForm']['cf_allow_guest'])) |
---|
64 | { |
---|
65 | $template->assign(array( |
---|
66 | 'CONTACT_MAIL' => true, |
---|
67 | 'CONTACT_FORM_PUBLIC' => CONTACT_FORM_PUBLIC, |
---|
68 | )); |
---|
69 | $template->set_prefilter('tail', 'contact_form_footer_link'); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * admin plugins menu link |
---|
75 | */ |
---|
76 | function contact_form_admin_menu($menu) |
---|
77 | { |
---|
78 | $menu[] = array( |
---|
79 | 'URL' => CONTACT_FORM_ADMIN, |
---|
80 | 'NAME' => 'Contact Form', |
---|
81 | ); |
---|
82 | return $menu; |
---|
83 | } |
---|