diff options
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/app.php | 17 | ||||
-rw-r--r-- | lib/public/appframework/db/mapper.php | 73 | ||||
-rw-r--r-- | lib/public/files/mount/imountpoint.php | 7 | ||||
-rw-r--r-- | lib/public/files/storage/istoragefactory.php | 5 | ||||
-rw-r--r-- | lib/public/idbconnection.php | 1 | ||||
-rw-r--r-- | lib/public/inavigationmanager.php | 7 | ||||
-rw-r--r-- | lib/public/iservercontainer.php | 8 | ||||
-rw-r--r-- | lib/public/mail/imailer.php | 57 | ||||
-rw-r--r-- | lib/public/util.php | 39 |
9 files changed, 178 insertions, 36 deletions
diff --git a/lib/public/app.php b/lib/public/app.php index bef4e96ae02..736c2b64c7d 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -49,8 +49,6 @@ class App { /** * Adds an entry to the navigation - * @param array $data containing the data - * @return boolean * * This function adds a new entry to the navigation visible to users. $data * is an associative array. @@ -62,10 +60,17 @@ class App { * The following keys are optional: * - icon: path to the icon of the app * - order: integer, that influences the position of your application in - * the navigation. Lower values come first. + * the navigation. Lower values come first. + * + * @param array $data containing the data + * @return boolean + * + * @deprecated Use \OC::$server->getNavigationManager()->add() instead to + * register a closure, this helps to speed up all requests against ownCloud */ - public static function addNavigationEntry( $data ) { - return \OC_App::addNavigationEntry( $data ); + public static function addNavigationEntry($data) { + \OC::$server->getNavigationManager()->add($data); + return true; } /** @@ -76,6 +81,8 @@ class App { * This function sets a navigation entry as active and removes the 'active' * property from all other entries. The templates can use this for * highlighting the current position of the user. + * + * @deprecated Use \OC::$server->getNavigationManager()->setActiveEntry() instead */ public static function setActiveNavigationEntry( $id ) { return \OC_App::setActiveNavigationEntry( $id ); diff --git a/lib/public/appframework/db/mapper.php b/lib/public/appframework/db/mapper.php index 5143547c8e8..9a5d6e819b9 100644 --- a/lib/public/appframework/db/mapper.php +++ b/lib/public/appframework/db/mapper.php @@ -26,7 +26,8 @@ namespace OCP\AppFramework\Db; -use \OCP\IDBConnection; +use OCP\IDBConnection; +use OCP\IDb; /** @@ -183,6 +184,31 @@ abstract class Mapper { return $entity; } + /** + * Checks if an array is associative + * @param array $array + * @return bool true if associative + */ + private function isAssocArray(array $array) { + return array_values($array) !== $array; + } + + /** + * Returns the correct PDO constant based on the value type + * @param $value + * @return PDO constant + */ + private function getPDOType($value) { + switch (gettype($value)) { + case 'integer': + return \PDO::PARAM_INT; + case 'boolean': + return \PDO::PARAM_BOOL; + default: + return \PDO::PARAM_STR; + } + } + /** * Runs an sql query @@ -193,32 +219,37 @@ abstract class Mapper { * @return \PDOStatement the database query result */ protected function execute($sql, array $params=[], $limit=null, $offset=null){ - $query = $this->db->prepare($sql, $limit, $offset); - - $index = 1; // bindParam is 1 indexed - foreach($params as $param) { - - switch (gettype($param)) { - case 'integer': - $pdoConstant = \PDO::PARAM_INT; - break; - - case 'boolean': - $pdoConstant = \PDO::PARAM_BOOL; - break; + if ($this->db instanceof IDb) { + $query = $this->db->prepareQuery($sql, $limit, $offset); + } else { + $query = $this->db->prepare($sql, $limit, $offset); + } - default: - $pdoConstant = \PDO::PARAM_STR; - break; + if ($this->isAssocArray($params)) { + foreach ($params as $key => $param) { + $pdoConstant = $this->getPDOType($param); + $query->bindValue($key, $param, $pdoConstant); } + } else { + $index = 1; // bindParam is 1 indexed + foreach ($params as $param) { + $pdoConstant = $this->getPDOType($param); + $query->bindValue($index, $param, $pdoConstant); + $index++; + } + } - $query->bindValue($index, $param, $pdoConstant); + $result = $query->execute(); - $index++; + // this is only for backwards compatibility reasons and can be removed + // in owncloud 10. IDb returns a StatementWrapper from execute, PDO, + // Doctrine and IDbConnection don't so this needs to be done in order + // to stay backwards compatible for the things that rely on the + // StatementWrapper being returned + if ($result instanceof \OC_DB_StatementWrapper) { + return $result; } - $query->execute(); - return $query; } diff --git a/lib/public/files/mount/imountpoint.php b/lib/public/files/mount/imountpoint.php index af7819ae160..2ec0cca1dce 100644 --- a/lib/public/files/mount/imountpoint.php +++ b/lib/public/files/mount/imountpoint.php @@ -64,4 +64,11 @@ interface IMountPoint { * @return mixed */ public function getOption($name, $default); + + /** + * Get all options for the mount + * + * @return array + */ + public function getOptions(); } diff --git a/lib/public/files/storage/istoragefactory.php b/lib/public/files/storage/istoragefactory.php index 50c844af2e6..7d4fa55e418 100644 --- a/lib/public/files/storage/istoragefactory.php +++ b/lib/public/files/storage/istoragefactory.php @@ -7,6 +7,7 @@ */ namespace OCP\Files\Storage; +use OCP\Files\Mount\IMountPoint; /** * Creates storage instances and manages and applies storage wrappers @@ -25,10 +26,10 @@ interface IStorageFactory { public function addStorageWrapper($wrapperName, $callback); /** - * @param string|boolean $mountPoint + * @param \OCP\Files\Mount\IMountPoint $mountPoint * @param string $class * @param array $arguments * @return \OCP\Files\Storage */ - public function getInstance($mountPoint, $class, $arguments); + public function getInstance(IMountPoint $mountPoint, $class, $arguments); } diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php index 1117c2da9b2..38f5c7e2e59 100644 --- a/lib/public/idbconnection.php +++ b/lib/public/idbconnection.php @@ -83,6 +83,7 @@ interface IDBConnection { * @param array $input data that should be inserted into the table (column name => value) * @param array|null $compare List of values that should be checked for "if not exists" * If this is null or an empty array, all keys of $input will be compared + * Please note: text fields (clob) must not be used in the compare array * @return int number of inserted rows * @throws \Doctrine\DBAL\DBALException */ diff --git a/lib/public/inavigationmanager.php b/lib/public/inavigationmanager.php index 9497d3fd08e..9e0e6826454 100644 --- a/lib/public/inavigationmanager.php +++ b/lib/public/inavigationmanager.php @@ -36,10 +36,13 @@ namespace OCP; interface INavigationManager { /** * Creates a new navigation entry - * @param array $entry containing: id, name, order, icon and href key + * + * @param array|\Closure $entry Array containing: id, name, order, icon and href key + * The use of a closure is preferred, because it will avoid + * loading the routing of your app, unless required. * @return void */ - public function add(array $entry); + public function add($entry); /** * Sets the current navigation entry of the currently running app diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index ec23cc52345..20345e61212 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -318,9 +318,15 @@ interface IServerContainer { * @return \bantu\IniGetWrapper\IniGetWrapper */ function getIniWrapper(); - /** * @return \OCP\Command\IBus */ function getCommandBus(); + + /** + * Creates a new mailer + * + * @return \OCP\Mail\IMailer + */ + function getMailer(); } diff --git a/lib/public/mail/imailer.php b/lib/public/mail/imailer.php new file mode 100644 index 00000000000..dc6fe5ba869 --- /dev/null +++ b/lib/public/mail/imailer.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\Mail; +use OC\Mail\Message; + +/** + * Class IMailer provides some basic functions to create a mail message that can be used in combination with + * \OC\Mail\Message. + * + * Example usage: + * + * $mailer = \OC::$server->getMailer(); + * $message = $mailer->createMessage(); + * $message->setSubject('Your Subject'); + * $message->setFrom(array('cloud@domain.org' => 'ownCloud Notifier'); + * $message->setTo(array('recipient@domain.org' => 'Recipient'); + * $message->setBody('The message text'); + * $mailer->send($message); + * + * This message can then be passed to send() of \OC\Mail\Mailer + * + * @package OCP\Mail + */ +interface IMailer { + /** + * Creates a new message object that can be passed to send() + * + * @return Message + */ + public function createMessage(); + + /** + * Send the specified message. Also sets the from address to the value defined in config.php + * if no-one has been passed. + * + * @param Message $message Message to send + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and + * therefore should be considered + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address + * has been supplied.) + */ + public function send(Message $message); + + /** + * Checks if an e-mail address is valid + * + * @param string $email Email address to be validated + * @return bool True if the mail address is valid, false otherwise + */ + public function validateMailAddress($email); +} diff --git a/lib/public/util.php b/lib/public/util.php index aa6cd5ba012..5efdcc55de4 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -63,12 +63,40 @@ class Util { * @param string $ccaddress * @param string $ccname * @param string $bcc + * @deprecated Use \OCP\Mail\IMailer instead */ - public static function sendMail( $toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, + public static function sendMail($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') { - // call the internal mail class - \OC_MAIL::send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, - $html, $altbody, $ccaddress, $ccname, $bcc); + $mailer = \OC::$server->getMailer(); + $message = $mailer->createMessage(); + $message->setTo([$toaddress => $toname]); + $message->setSubject($subject); + $message->setPlainBody($mailtext); + $message->setFrom([$fromaddress => $fromname]); + if($html === 1) { + $message->setHTMLBody($altbody); + } + + if($altbody === '') { + $message->setHTMLBody($mailtext); + $message->setPlainBody(''); + } else { + $message->setHtmlBody($mailtext); + $message->setPlainBody($altbody); + } + + if(!empty($ccaddress)) { + if(!empty($ccname)) { + $message->setCc([$ccaddress => $ccname]); + } else { + $message->setCc([$ccaddress]); + } + } + if(!empty($bcc)) { + $message->setBcc([$bcc]); + } + + $mailer->send($message); } /** @@ -275,7 +303,8 @@ class Util { $host_name = \OC_Config::getValue('mail_domain', $host_name); $defaultEmailAddress = $user_part.'@'.$host_name; - if (\OC_Mail::validateAddress($defaultEmailAddress)) { + $mailer = \OC::$server->getMailer(); + if ($mailer->validateMailAddress($defaultEmailAddress)) { return $defaultEmailAddress; } |