mail() 공개 정적인 메소드

Mails a notification message after encoding the headers and adding the standard username/time line.
public static mail ( string $message, array $headers = [] )
$message string The message text to send out.
$headers array Additional headers to add to the email.
예제 #1
0
파일: DeletePage.php 프로젝트: horde/horde
 public function handleAction()
 {
     $pagename = $this->referrer();
     $page = Wicked_Page::getPage($pagename);
     if ($page->allows(Wicked::MODE_REMOVE)) {
         $version = Horde_Util::getFormData('version');
         if (empty($version)) {
             $GLOBALS['wicked']->removeAllVersions($pagename);
             $GLOBALS['notification']->push(sprintf(_("Successfully deleted \"%s\"."), $pagename), 'horde.success');
             Wicked::mail("Deleted page: {$pagename}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename));
             Wicked::url('Wiki/Home', true)->redirect();
         }
         $GLOBALS['wicked']->removeVersion($pagename, $version);
         $GLOBALS['notification']->push(sprintf(_("Deleted version %s of \"%s\"."), $version, $pagename), 'horde.success');
         Wicked::mail("Deleted version: {$version} of {$pagename}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename . ' [' . $version . ']'));
         Wicked::url($pagename, true)->redirect();
     }
     $GLOBALS['notification']->push(sprintf(_("You don't have permission to delete \"%s\"."), $pagename), 'horde.warning');
     Wicked::url($this->referrer(), true)->redirect();
 }
예제 #2
0
 /**
  * Retrieve the form fields and process the merge or rename.
  */
 public function handleAction()
 {
     global $wicked, $notification, $registry;
     if (Horde_Util::getFormData('submit') == _("Cancel")) {
         Wicked::url($this->referrer(), true)->redirect();
     }
     $referrer = $this->referrer();
     $new_name = Horde_Util::getFormData('new_name');
     if (empty($new_name)) {
         $this->_errors['new_name'] = _("This is a required field.");
     } elseif ($new_name == $referrer) {
         $this->_errors['new_name'] = _("New name is the same as old name.");
     }
     $collision = Horde_Util::getFormData('collision');
     if (empty($collision)) {
         $this->_errors['collision'] = _("This is a required field.");
     }
     if (count($this->_errors)) {
         return;
     }
     $sourcePage = Wicked_Page::getPage($referrer);
     if (!$this->allows(Wicked::MODE_EDIT)) {
         throw new Wicked_Exception(sprintf(_("You do not have permission to edit \"%s\""), $referrer));
     }
     $destPage = Wicked_Page::getPage($new_name);
     if (!$destPage instanceof Wicked_Page_AddPage) {
         // Destination page exists.
         if ($collision != 'merge') {
             // We don't want to overwrite.
             throw new Wicked_Exception(sprintf(_("Page \"%s\" already exists."), $new_name));
         }
         if (!$destPage->allows(Wicked::MODE_EDIT)) {
             throw new Wicked_Exception(sprintf(_("You do not have permission to edit \"%s\""), $new_name));
         }
         // Merge the two pages.
         $newText = $destPage->getText() . "\n----\n" . $sourcePage->getText();
         $changelog = sprintf(_("Merged from %s"), $referrer);
         $wicked->updateText($new_name, $newText, $changelog);
         $wicked->removeAllVersions($referrer);
         $notification->push(sprintf(_("Merged \"%s\" into \"%s\"."), $referrer, $new_name), 'horde.success');
         $url = Wicked::url($new_name, true, -1);
         $message = sprintf(_("Merged \"%s\" into \"%s\". New page: %s\n"), $referrer, $new_name, $url);
         Wicked::mail($message, array('Subject' => '[' . $registry->get('name') . '] merged: ' . $referrer . ', ' . $new_name));
     } else {
         // Rename the page.
         $wicked->renamePage($referrer, $new_name);
         $notification->push(sprintf(_("Renamed \"%s\" to \"%s\"."), $referrer, $new_name), 'horde.success');
         $url = Wicked::url($new_name, true, -1);
         $message = sprintf(_("Renamed \"%s\" to \"%s\". New page: %s\n"), $referrer, $new_name, $url);
         Wicked::mail($message, array('Subject' => '[' . $registry->get('name') . '] renamed: ' . $referrer . ', ' . $new_name));
     }
     $wikiWord = '/^' . Wicked::REGEXP_WIKIWORD . '$/';
     // We don't check permissions on these pages since we want references
     // to be fixed even if the user doing the editing couldn't fix that
     // page, and fixing references is likely to never be a destructive
     // action, and the user can't supply their own data for it.
     $references = Horde_Util::getFormData('ref', array());
     foreach ($references as $name => $value) {
         $page_name = quoted_printable_decode($name);
         // Fix up for self-references.
         if ($page_name == $referrer) {
             $page_name = $new_name;
         }
         try {
             $refPage = $wicked->retrieveByName($page_name);
         } catch (Wicked_Exception $e) {
             $notification->push(sprintf(_("Error retrieving %s: %s"), $page_name, $e->getMessage()), 'horde.error');
             continue;
         }
         $changelog = sprintf(_("Changed references from %s to %s"), $referrer, $new_name);
         if (preg_match($wikiWord, $new_name)) {
             $replaceWith = $new_name;
         } else {
             $replaceWith = '((' . $new_name . '))';
         }
         $from = array('/\\(\\(' . preg_quote($referrer, '/') . '\\)\\)/');
         $to = array($replaceWith);
         // If this works as a bare wiki word, replace that, too.
         if (preg_match($wikiWord, $referrer)) {
             $from[] = '/\\b' . preg_quote($referrer, '/') . '\\b/';
             $to[] = $replaceWith;
         }
         $newText = preg_replace($from, $to, $refPage['page_text']);
         $wicked->updateText($page_name, $newText, $changelog);
     }
     Wicked::url($new_name, true)->redirect();
 }
예제 #3
0
 /**
  * @throws Wicked_Exception
  */
 public function updateText($newtext, $changelog)
 {
     $version = $this->version();
     $result = $GLOBALS['wicked']->updateText($this->pageName(), $newtext, $changelog);
     $url = Wicked::url($this->pageName(), true, -1);
     $new_page = $this->getPage($this->pageName());
     $message = "Modified page: {$url}\n" . 'New Revision:  ' . $new_page->version() . "\n" . ($changelog ? 'Change log:  ' . $changelog . "\n" : '') . "\n" . $new_page->getDiff($version);
     Wicked::mail($message, array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] changed: ' . $this->pageName()));
     $this->_page['page_text'] = $newtext;
 }
예제 #4
0
 /**
  * Retrieves the form fields and processes the attachment.
  */
 public function handleAction()
 {
     global $notification, $wicked, $registry, $conf;
     // Only allow POST commands.
     $cmd = Horde_Util::getPost('cmd');
     $version = Horde_Util::getFormData('version');
     $is_update = (bool) Horde_Util::getFormData('is_update');
     $filename = Horde_Util::getFormData('filename');
     $change_log = Horde_Util::getFormData('change_log');
     // See if we're supposed to delete an attachment.
     if ($cmd == 'delete' && $filename && $version) {
         if (!$this->allows(Wicked::MODE_REMOVE)) {
             $notification->push(_("You do not have permission to delete attachments from this page."), 'horde.error');
             return;
         }
         try {
             $wicked->removeAttachment($wicked->getPageId($this->referrer()), $filename, $version);
             $notification->push(sprintf(_("Successfully deleted version %s of \"%s\" from \"%s\""), $version, $filename, $this->referrer()), 'horde.success');
         } catch (Wicked_Exception $e) {
             $notification->push($result->getMessage(), 'horde.error');
         }
         return;
     }
     if (empty($filename)) {
         $filename = Horde_Util::dispelMagicQuotes($_FILES['attachment_file']['name']);
     }
     try {
         $GLOBALS['browser']->wasFileUploaded('attachment_file', _("attachment"));
     } catch (Horde_Browser_Exception $e) {
         $notification->push($e, 'horde.error');
         return;
     }
     if (strpos($filename, ' ') !== false) {
         $notification->push(_("Attachments with spaces can't be embedded into a page."), 'horde.warning');
     }
     $data = file_get_contents($_FILES['attachment_file']['tmp_name']);
     if ($data === false) {
         $notification->push(_("Can't read uploaded file."), 'horde.error');
         return;
     }
     if (!$this->allows(Wicked::MODE_EDIT)) {
         $notification->push(sprintf(_("You do not have permission to edit \"%s\""), $this->referrer()), 'horde.error');
         return;
     }
     if ($conf['wicked']['require_change_log'] && empty($change_log)) {
         $notification->push(_("You must enter a change description to attach this file."), 'horde.error');
         return;
     }
     $referrer_id = $wicked->getPageId($this->referrer());
     try {
         $attachments = $wicked->getAttachedFiles($referrer_id);
     } catch (Wicked_Exception $e) {
         $notification->push(sprintf(_("Error retrieving attachments: %s"), $e->getMessage()), 'horde.error');
         return;
     }
     $found = false;
     foreach ($attachments as $attach) {
         if ($filename == $attach['attachment_name']) {
             $found = true;
             break;
         }
     }
     if ($is_update) {
         if (!$found) {
             $notification->push(sprintf(_("Can't update \"%s\": no such attachment."), $filename), 'horde.error');
             return;
         }
     } else {
         if ($found) {
             $notification->push(sprintf(_("There is already an attachment named \"%s\"."), $filename), 'horde.error');
             return;
         }
     }
     $file = array('page_id' => $referrer_id, 'attachment_name' => $filename, 'change_log' => $change_log);
     try {
         $wicked->attachFile($file, $data);
     } catch (Wicked_Exception $e) {
         $notification->push($e);
         Horde::log($e);
         throw $e;
     }
     if ($is_update) {
         $message = sprintf(_("Updated attachment \"%s\" on page \"%s\"."), $filename, $this->referrer());
     } else {
         $message = sprintf(_("New attachment \"%s\" to page \"%s\"."), $filename, $this->referrer());
     }
     $notification->push($message, 'horde.success');
     $url = Wicked::url($this->referrer(), true, -1);
     Wicked::mail($message . ' ' . _("View page: ") . $url . "\n", array('Subject' => '[' . $registry->get('name') . '] attachment: ' . $this->referrer() . ', ' . $filename));
 }
예제 #5
0
파일: Sql.php 프로젝트: jubinpatel/horde
 /**
  * Creates a new page.
  *
  * @param string $pagename  The new page's name.
  * @param string $text      The new page's text.
  *
  * @throws Wicked_Exception
  */
 public function newPage($pagename, $text)
 {
     if (!strlen($pagename)) {
         throw new Wicked_Exception(_("Page name must not be empty"));
     }
     if ($GLOBALS['browser']->isRobot()) {
         throw new Wicked_Exception(_("Robots are not allowed to create pages"));
     }
     $author = $GLOBALS['registry']->getAuth();
     if ($author === false) {
         $author = null;
     }
     /* Attempt the insertion/update query. */
     try {
         $page_id = $this->_db->insert('INSERT INTO ' . $this->_params['table'] . ' (page_name, page_text, version_created, page_version,' . ' page_hits, change_author) VALUES (?, ?, ?, 1, 0, ?)', array($this->_convertToDriver($pagename), $this->_convertToDriver($text), time(), $author));
     } catch (Horde_Db_Exception $e) {
         throw new Wicked_Exception($e);
     }
     /* Send notification. */
     $url = Wicked::url($pagename, true, -1);
     Wicked::mail("Created page: {$url}\n\n{$text}\n", array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] created: ' . $pagename));
     /* Call getPages with no caching so that the new list of pages is
      * read in. */
     $this->getPages(true, true);
     return $page_id;
 }