1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Wicked
14: {
15:
16: const MODE_DISPLAY = 0;
17:
18:
19: const MODE_EDIT = 1;
20:
21:
22: const MODE_REMOVE = 2;
23:
24:
25: const MODE_HISTORY = 3;
26:
27:
28: const MODE_DIFF = 4;
29:
30:
31: const MODE_LOCKING = 7;
32:
33:
34: const MODE_UNLOCKING = 8;
35:
36:
37: const MODE_CREATE = 9;
38:
39:
40: const MODE_CONTENT = 10;
41:
42:
43: const MODE_BLOCK = 11;
44:
45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61:
62: const REGEXP_WIKIWORD = "(!?[A-Z\xc0-\xde][A-Za-z0-9\xc0-\xfe]*[a-z0-9\xdf-\xfe]+\/?[A-Z\xc0-\xde][A-Za-z0-9\xc0-\xfe\/]*)((\#[A-Za-z0-9\xc0-\xfe]([-_A-Za-z0-9\xc0-\xfe:.]*[-_A-Za-z0-9\xc0-\xfe])?)?)";
63:
64:
65: const VFS_ATTACH_PATH = '.horde/wicked/attachments';
66:
67: 68: 69: 70: 71: 72: 73: 74: 75: 76:
77: public static function url($page, $full = false, $append_session = 0)
78: {
79: if ($GLOBALS['conf']['urls']['pretty'] == 'rewrite') {
80: $script = str_replace('%2F', '/', urlencode($page));
81: } else {
82: $script = Horde_Util::addParameter('display.php', 'page', $page);
83: }
84:
85: $url = Horde::url($script, $full, array('append_session' => $append_session));
86: if (!$full) {
87: $url->url = preg_replace('|^([a-zA-Z][a-zA-Z0-9+.-]{0,19})://[^/]*|', '', $url->url);
88: }
89:
90: return $url;
91: }
92:
93: 94: 95:
96: public static function ($returnType = 'object')
97: {
98: global $conf, $page;
99:
100: $menu = new Horde_Menu(Horde_Menu::MASK_ALL);
101:
102: if (@count($conf['menu']['pages'])) {
103: $pages = array('Wiki/Home' => _("_Home"),
104: 'Wiki/Usage' => _("_Usage"),
105: 'RecentChanges' => _("_Recent Changes"),
106: 'AllPages' => _("_All Pages"));
107: foreach ($conf['menu']['pages'] as $pagename) {
108:
109: $curpage = isset($page) ? $page->pageName() : null;
110: $referrer = Horde_Util::getFormData('referrer', $curpage);
111:
112: 113: 114:
115: if (!strstr($_SERVER['PHP_SELF'], 'prefs.php') &&
116: $curpage === $pagename) {
117: $cellclass = 'current';
118: } else {
119: $cellclass = '__noselection';
120: }
121:
122: $url = Horde_Util::addParameter(self::url($pagename), 'referrer', $referrer);
123: $menu->add($url, $pages[$pagename], str_replace('/', '', $pagename) . '.png', null, null, null, $cellclass);
124: }
125: }
126:
127: if ($returnType == 'object') {
128: return $menu;
129: } else {
130: return $menu->render();
131: }
132: }
133:
134: 135: 136: 137: 138: 139: 140:
141: public static function mail($message, $headers = array())
142: {
143: global $conf, $registry;
144:
145:
146: if (empty($conf['wicked']['notify_address'])) {
147: return;
148: }
149:
150: if ($GLOBALS['registry']->getAuth()) {
151: $prefix = $GLOBALS['registry']->getAuth();
152: } else {
153: $prefix = 'guest [' . $_SERVER['REMOTE_ADDR'] . ']';
154: }
155: $message = $prefix . ' ' . date('r') . "\n\n" . $message;
156:
157: 158: 159:
160: $default_from_addr = !empty($conf['wicked']['guest_address']) ?
161: $conf['wicked']['guest_address'] :
162: $conf['wicked']['notify_address'];
163: if ($GLOBALS['registry']->getAuth()) {
164: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
165: $from = $identity->getValue('fullname');
166: if (empty($from)) {
167: $from = $registry->get('name');
168: }
169: $from_addr = $identity->getValue('from_addr');
170: if (empty($from_addr)) {
171: $from_addr = $default_from_addr;
172: }
173: } else {
174: $from = $registry->get('name') . ' Guest';
175: $from_addr = $default_from_addr;
176: }
177:
178: $mail = new Horde_Mime_Mail(array(
179: 'body' => $message,
180: 'To' => $conf['wicked']['notify_address'],
181: 'From' => $from . '<' . $from_addr . '>',
182: 'User-Agent' => 'Wicked ' . $GLOBALS['registry']->getVersion(),
183: 'Precedence' => 'bulk',
184: 'Auto-Submitted' => 'auto-replied'));
185: foreach (array_keys($headers) as $hkey) {
186: $mail->addHeader($hkey, $headers[$hkey]);
187: }
188: try {
189: $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
190: } catch (Horde_Mime_Exception $e) {
191: $GLOBALS['notification']->push($e);
192: }
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202:
203: public static function getCAPTCHA($new = false)
204: {
205: global $session;
206:
207: if ($new || !$session->get('wicked', 'captcha')) {
208: $captcha = '';
209: for ($i = 0; $i < 5; ++$i) {
210: $captcha .= chr(rand(65, 90));
211: }
212: $session->set('wicked', 'captcha', $captcha);
213: }
214:
215: return $session->get('wicked', 'captcha');
216: }
217:
218: 219: 220: 221: 222: 223:
224: public static function lockUser()
225: {
226: return $GLOBALS['registry']->getAuth() ? $GLOBALS['registry']->getAuth() : $GLOBALS['browser']->getIPAddress();
227: }
228:
229: }
230: