Overview

Packages

  • None
  • Wicked

Classes

  • Text_Wiki_Parse_Heading2
  • Text_Wiki_Parse_Toc2
  • Text_Wiki_Render_Latex_Heading2
  • Text_Wiki_Render_Latex_Toc2
  • Text_Wiki_Render_Plain_Heading2
  • Text_Wiki_Render_Plain_Toc2
  • Text_Wiki_Render_Rst
  • Text_Wiki_Render_Rst_Blockquote
  • Text_Wiki_Render_Rst_Bold
  • Text_Wiki_Render_Rst_Code
  • Text_Wiki_Render_Rst_Deflist
  • Text_Wiki_Render_Rst_Emphasis
  • Text_Wiki_Render_Rst_Freelink
  • Text_Wiki_Render_Rst_Heading2
  • Text_Wiki_Render_Rst_Links
  • Text_Wiki_Render_Rst_List
  • Text_Wiki_Render_Rst_Newline
  • Text_Wiki_Render_Rst_Paragraph
  • Text_Wiki_Render_Rst_Raw
  • Text_Wiki_Render_Rst_Toc2
  • Text_Wiki_Render_Rst_Tt
  • Text_Wiki_Render_Rst_Url
  • Text_Wiki_Render_Xhtml_Attribute
  • Text_Wiki_Render_Xhtml_Code2
  • Text_Wiki_Render_Xhtml_Freelink2
  • Text_Wiki_Render_Xhtml_Heading2
  • Text_Wiki_Render_Xhtml_Image2
  • Text_Wiki_Render_Xhtml_Interwiki
  • Text_Wiki_Render_Xhtml_Registrylink
  • Text_Wiki_Render_Xhtml_Toc2
  • Text_Wiki_Render_Xhtml_Url
  • Text_Wiki_Render_Xhtml_Wickedblock
  • Text_Wiki_Render_Xhtml_Wikilink2
  • Wicked
  • Wicked_Api
  • Wicked_Driver
  • Wicked_Driver_Sql
  • Wicked_Exception
  • Wicked_Factory_Driver
  • Wicked_Page
  • Wicked_Page_AddPage
  • Wicked_Page_AllPages
  • Wicked_Page_AttachedFiles
  • Wicked_Page_BackLinks
  • Wicked_Page_DeletePage
  • Wicked_Page_EditPage
  • Wicked_Page_LeastPopular
  • Wicked_Page_LikePages
  • Wicked_Page_MergeOrRename
  • Wicked_Page_MostPopular
  • Wicked_Page_NewPage
  • Wicked_Page_RecentChanges
  • Wicked_Page_RevertPage
  • Wicked_Page_Search
  • Wicked_Page_StandardHistoryPage
  • Wicked_Page_StandardPage
  • Wicked_Page_SyncDiff
  • Wicked_Page_SyncPages
  • Wicked_Sync
  • Wicked_Sync_Wicked
  • Wicked_Test
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Wicked Base Class.
  4:  *
  5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Tyler Colbert <tyler@colberts.us>
 11:  * @package Wicked
 12:  */
 13: class Wicked
 14: {
 15:     /** Display mode. */
 16:     const MODE_DISPLAY = 0;
 17: 
 18:     /** The edit screen. */
 19:     const MODE_EDIT = 1;
 20: 
 21:     /** Page can be removed. */
 22:     const MODE_REMOVE = 2;
 23: 
 24:     /** Display the page history. */
 25:     const MODE_HISTORY = 3;
 26: 
 27:     /** Diff two versions of the page. */
 28:     const MODE_DIFF = 4;
 29: 
 30:     /** Page can be locked. */
 31:     const MODE_LOCKING = 7;
 32: 
 33:     /** Page can be unlocked. */
 34:     const MODE_UNLOCKING = 8;
 35: 
 36:     /** The ability to add a page. */
 37:     const MODE_CREATE = 9;
 38: 
 39:     /** Raw content mode. */
 40:     const MODE_CONTENT = 10;
 41: 
 42:     /** Like display, but for a block. */
 43:     const MODE_BLOCK = 11;
 44: 
 45:     /** Our wiki word regexp (needed many places).
 46:        "(!?" .                       // START WikiPage pattern (1)
 47:        "[A-Z\xc0-\xde]" .            // 1 upper
 48:        "[A-Za-z0-9\xc0-\xfe]*" .     // 0+ alpha or digit
 49:        "[a-z0-9\xdf-\xfe]+" .        // 1+ lower or digit
 50:        "\/?" .                       // 0/1 slash
 51:        "[A-Z\xc0-\xde]" .            // 1 upper
 52:        "[A-Za-z0-9\xc0-\xfe\/]*" .   // 0+ or more alpha or digit or slash
 53:        ")" .                         // END WikiPage pattern (/1)
 54:        "((\#" .                      // START Anchor pattern (2)(3)
 55:        "[A-Za-z0-9\xc0-\xfe]" .      // 1 alpha
 56:        "(" .                         // start sub pattern (4)
 57:        "[-_A-Za-z0-9\xc0-\xfe:.]*" . // 0+ dash, alpha, digit, underscore,
 58:                                      // colon, dot
 59:        "[-_A-Za-z0-9\xc0-\xfe]" .    // 1 dash, alpha, digit, or underscore
 60:        ")?)?)");                     // end subpatterns (/4)(/3)(/2)
 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:     /** Where we store our attachments in VFS. */
 65:     const VFS_ATTACH_PATH = '.horde/wicked/attachments';
 66: 
 67:     /**
 68:      * Puts together the URL to a Wicked page. Uses mod_rewrite or GET
 69:      * style URLs depending on configuration.
 70:      *
 71:      * @param string $page             The name of the page to target.
 72:      * @param boolean $full            @see Horde::url()
 73:      * @param integer $append_session  @see Horde::url()
 74:      *
 75:      * @return Horde_Url  The URL of $page.
 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:      * Build Wicked's list of menu items.
 95:      */
 96:     public static function getMenu($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:                 /* Determine who we should say referred us. */
109:                 $curpage = isset($page) ? $page->pageName() : null;
110:                 $referrer = Horde_Util::getFormData('referrer', $curpage);
111: 
112:                 /* Determine if we should depress the button. We have to do
113:                  * this on our own because all the buttons go to the same .php
114:                  * file, just with different args. */
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:      * Mails a notification message after encoding the headers and adding the
136:      * standard username/time line.
137:      *
138:      * @param string $message  The message text to send out.
139:      * @param array $headers   Additional headers to add to the email.
140:      */
141:     public static function mail($message, $headers = array())
142:     {
143:         global $conf, $registry;
144: 
145:         /* Make sure there's a place configured to send the email. */
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:         /* In case we don't get a user's email address to send the
158:          * notification from, what should we fall back to for the From:
159:          * header? */
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:      * Generate a CAPTCHA string.
197:      *
198:      * @param boolean $new  If true, a new CAPTCHA is created and returned.
199:      *                      The current, to-be-confirmed string otherwise.
200:      *
201:      * @return string  A CAPTCHA string.
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:      * Returns the user name that is used for locking, either the current user
220:      * or the current IP address.
221:      *
222:      * @return string  The user name used for locking.
223:      */
224:     public static function lockUser()
225:     {
226:         return $GLOBALS['registry']->getAuth() ? $GLOBALS['registry']->getAuth() : $GLOBALS['browser']->getIPAddress();
227:     }
228: 
229: }
230: 
API documentation generated by ApiGen