diff --git a/lib/classes/collection.class.php b/lib/classes/collection.class.php index 1e16a88b45..14c1c53a75 100644 --- a/lib/classes/collection.class.php +++ b/lib/classes/collection.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @license http://opensource.org/licenses/gpl-3.0 GPLv3 @@ -31,14 +33,16 @@ class collection implements cache_cacheableInterface protected $databox; protected $is_active; protected $binary_logo; + protected $app; const PIC_LOGO = 'minilogos'; const PIC_WM = 'wm'; const PIC_STAMP = 'stamp'; const PIC_PRESENTATION = 'presentation'; - protected function __construct($coll_id, databox &$databox) + protected function __construct(Application $app, $coll_id, databox &$databox) { + $this->app = $app; $this->databox = $databox; $this->sbas_id = (int) $databox->get_sbas_id(); $this->coll_id = (int) $coll_id; @@ -78,7 +82,7 @@ class collection implements cache_cacheableInterface $this->name = $row['asciiname']; $this->prefs = $row['prefs']; - $conn = connection::getPDOConnection(); + $conn = connection::getPDOConnection($this->app); $sql = 'SELECT server_coll_id, sbas_id, base_id, active FROM bas WHERE server_coll_id = :coll_id AND sbas_id = :sbas_id'; @@ -120,10 +124,9 @@ class collection implements cache_cacheableInterface $this->is_active = true; $this->delete_data_from_cache(); - $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); - cache_databox::update($this->databox->get_sbas_id(), 'structure'); + cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure'); return $this; } @@ -136,10 +139,9 @@ class collection implements cache_cacheableInterface $stmt->closeCursor(); $this->is_active = false; $this->delete_data_from_cache(); - $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); - cache_databox::update($this->databox->get_sbas_id(), 'structure'); + cache_databox::update($this->app, $this->databox->get_sbas_id(), 'structure'); return $this; } @@ -158,7 +160,7 @@ class collection implements cache_cacheableInterface $stmt->closeCursor(); foreach ($rs as $row) { - $record = new record_adapter($this->databox->get_sbas_id(), $row['record_id']); + $record = $this->databox->get_record($row['record_id']); $record->delete(); unset($record); } @@ -218,7 +220,7 @@ class collection implements cache_cacheableInterface $this->delete_data_from_cache(); - phrasea::reset_baseDatas(); + phrasea::reset_baseDatas($this->databox->get_appbox()); return $this; } @@ -331,7 +333,7 @@ class collection implements cache_cacheableInterface $stmt->execute(array(':coll_id' => $this->get_coll_id())); $stmt->closeCursor(); - $appbox = appbox::get_instance(\bootstrap::getCore()); + $appbox = $this->databox->get_appbox(); $sql = "DELETE FROM bas WHERE base_id = :base_id"; $stmt = $appbox->get_connection()->prepare($sql); @@ -363,17 +365,16 @@ class collection implements cache_cacheableInterface * @param int $base_id * @return collection */ - public static function get_from_base_id($base_id) + public static function get_from_base_id(Application $app, $base_id) { - $coll_id = phrasea::collFromBas($base_id); - $sbas_id = phrasea::sbasFromBas($base_id); + $coll_id = phrasea::collFromBas($app, $base_id); + $sbas_id = phrasea::sbasFromBas($app, $base_id); if ( ! $sbas_id || ! $coll_id) { throw new Exception_Databox_CollectionNotFound(sprintf("Collection could not be found")); } - $appbox = \appbox::get_instance(\bootstrap::getCore()); - $databox = $appbox->get_databox($sbas_id); + $databox = $app['phraseanet.appbox']->get_databox($sbas_id); - return self::get_from_coll_id($databox, $coll_id); + return self::get_from_coll_id($app, $databox, $coll_id); } /** @@ -382,13 +383,13 @@ class collection implements cache_cacheableInterface * @param int $coll_id * @return collection */ - public static function get_from_coll_id(databox $databox, $coll_id) + public static function get_from_coll_id(Application $app, databox $databox, $coll_id) { assert(is_int($coll_id)); $key = sprintf('%d_%d', $databox->get_sbas_id(), $coll_id); if ( ! isset(self::$_collections[$key])) { - self::$_collections[$key] = new self($coll_id, $databox); + self::$_collections[$key] = new self($app, $coll_id, $databox); } return self::$_collections[$key]; @@ -443,11 +444,12 @@ class collection implements cache_cacheableInterface return $this->available; } - public function unmount_collection(appbox &$appbox) + public function unmount_collection(Application $app) { + $appbox = $app['phraseanet.appbox']; $params = array(':base_id' => $this->get_base_id()); - $query = new User_Query($appbox); + $query = new User_Query($app); $total = $query->on_base_ids(array($this->get_base_id())) ->include_phantoms(false) ->include_special_users(true) @@ -483,21 +485,18 @@ class collection implements cache_cacheableInterface $stmt->execute($params); $stmt->closeCursor(); - phrasea::reset_baseDatas(); + phrasea::reset_baseDatas($appbox); return $this; } - public static function create(databox $databox, appbox $appbox, $name, User_Adapter $user = null) + public static function create(Application $app, databox $databox, appbox $appbox, $name, User_Adapter $user = null) { $sbas_id = $databox->get_sbas_id(); $connbas = $databox->get_connection(); $conn = $appbox->get_connection(); $new_bas = false; - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); - $prefs = ' 0 @@ -531,16 +530,15 @@ class collection implements cache_cacheableInterface $databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); - cache_databox::update($sbas_id, 'structure'); + cache_databox::update($app, $sbas_id, 'structure'); - phrasea::reset_baseDatas(); + phrasea::reset_baseDatas($appbox); if (null !== $user) { self::set_admin($new_bas, $user); - $appbox->get_session()->renew_phrasea_session(); } - return self::get_from_coll_id($databox, $new_id); + return self::get_from_coll_id($app, $databox, $new_id); } public function set_admin($base_id, user_adapter $user) @@ -571,47 +569,44 @@ class collection implements cache_cacheableInterface return true; } - public static function mount_collection($sbas_id, $coll_id, User_Adapter $user) + public static function mount_collection(Application $app, databox $databox, $coll_id, User_Adapter $user) { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); $sql = "INSERT INTO bas (base_id, active, server_coll_id, sbas_id, aliases) VALUES (null, 1, :server_coll_id, :sbas_id, '')"; - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $databox->get_appbox()->get_connection()->prepare($sql); $stmt->execute(array(':server_coll_id' => $coll_id, ':sbas_id' => $sbas_id)); $stmt->closeCursor(); - $new_bas = $appbox->get_connection()->lastInsertId(); - $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); + $new_bas = $databox->get_appbox()->get_connection()->lastInsertId(); + $databox->get_appbox()->delete_data_from_cache(appbox::CACHE_LIST_BASES); - $databox = $appbox->get_databox((int) $sbas_id); $databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); - cache_databox::update($sbas_id, 'structure'); + cache_databox::update($app, $sbas_id, 'structure'); - phrasea::reset_baseDatas(); + phrasea::reset_baseDatas($databox->get_appbox()); self::set_admin($new_bas, $user); return $new_bas; } - public static function getLogo($base_id, $printname = false) + public static function getLogo($base_id, Application $app, $printname = false) { $base_id_key = $base_id . '_' . ($printname ? '1' : '0'); if ( ! isset(self::$_logos[$base_id_key])) { - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; if (is_file($registry->get('GV_RootPath') . 'config/minilogos/' . $base_id)) { - $name = phrasea::bas_names($base_id); + $name = phrasea::bas_names($base_id, $app); self::$_logos[$base_id_key] = ''; } elseif ($printname) { - self::$_logos[$base_id_key] = phrasea::bas_names($base_id); + self::$_logos[$base_id_key] = phrasea::bas_names($base_id, $app); } } @@ -622,8 +617,7 @@ class collection implements cache_cacheableInterface { if ( ! isset(self::$_watermarks['base_id'])) { - $registry = registry::get_instance(); - if (is_file($registry->get('GV_RootPath') . 'config/wm/' . $base_id)) + if (is_file(__DIR__ . '/../../config/wm/' . $base_id)) self::$_watermarks['base_id'] = ''; } @@ -634,8 +628,7 @@ class collection implements cache_cacheableInterface { if ( ! isset(self::$_presentations['base_id'])) { - $registry = registry::get_instance(); - if (is_file($registry->get('GV_RootPath') . 'config/presentation/' . $base_id)) + if (is_file(__DIR__ . '/../../config/presentation/' . $base_id)) self::$_presentations['base_id'] = ''; } @@ -646,8 +639,7 @@ class collection implements cache_cacheableInterface { if ( ! isset(self::$_stamps['base_id'])) { - $registry = registry::get_instance(); - if (is_file($registry->get('GV_RootPath') . 'config/stamp/' . $base_id)) + if (is_file(__DIR__ . '/../../config/stamp/' . $base_id)) self::$_stamps['base_id'] = ''; } diff --git a/lib/classes/connection.class.php b/lib/classes/connection.class.php index 1a86e5cbfe..f5efad5890 100755 --- a/lib/classes/connection.class.php +++ b/lib/classes/connection.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @license http://opensource.org/licenses/gpl-3.0 GPLv3 @@ -33,13 +35,19 @@ class connection * @var Array */ public static $log = array(); + protected $app; + + public function __construct(Application $app) + { + $this->app = $app; + } /** * */ public function __destruct() { - self::printLog(); + self::printLog($this->app); return; } @@ -48,10 +56,9 @@ class connection * * @return Void */ - public static function printLog() + public static function printLog(Application $app) { - $registry = registry::get_instance(); - if ( ! $registry->get('GV_debug')) { + if (!$app['phraseanet.registry']->get('GV_debug')) { return; } @@ -65,7 +72,7 @@ class connection $totalTime += $entry['time']; $string = $entry['time'] . "\t" . ' - ' . $query . ' - ' . "\n"; - file_put_contents($registry->get('GV_RootPath') . 'logs/mysql_log.log', $string, FILE_APPEND); + file_put_contents($app['phraseanet.registry']->get('GV_RootPath') . 'logs/mysql_log.log', $string, FILE_APPEND); } $string = count(self::$log) . ' queries - ' . $totalTime . "\nEND OF QUERY " . $_SERVER['PHP_SELF'] @@ -79,7 +86,7 @@ class connection } $string .= "\n\n\n\n"; - file_put_contents($registry->get('GV_RootPath') . 'logs/mysql_log.log', $string, FILE_APPEND); + file_put_contents($app['phraseanet.registry']->get('GV_RootPath') . 'logs/mysql_log.log', $string, FILE_APPEND); return; } @@ -88,10 +95,10 @@ class connection * * @return type */ - protected static function instantiate() + protected static function instantiate(Application $app) { - if ( ! self::$_selfinstance) - self::$_selfinstance = new self(); + if (!self::$_selfinstance) + self::$_selfinstance = new self($app); return; } @@ -101,9 +108,9 @@ class connection * @param string $name * @return connection_pdo */ - public static function getPDOConnection($name = null, registryInterface $registry = null) + public static function getPDOConnection(Application $app, $name = null, registryInterface $registry = null) { - self::instantiate(); + self::instantiate($app); if (trim($name) == '') { $name = 'appbox'; } elseif (is_int((int) $name)) { @@ -112,19 +119,17 @@ class connection return false; } - if ( ! isset(self::$_PDO_instance[$name])) { + if (!isset(self::$_PDO_instance[$name])) { $hostname = $port = $user = $password = $dbname = false; $connection_params = array(); if (trim($name) !== 'appbox') { - $connection_params = phrasea::sbas_params(); + $connection_params = phrasea::sbas_params($app); } else { - $configuration = \Alchemy\Phrasea\Core\Configuration::build(); + $choosenConnexion = $app['phraseanet.configuration']->getPhraseanet()->get('database'); - $choosenConnexion = $configuration->getPhraseanet()->get('database'); - - $connexion = $configuration->getConnexion($choosenConnexion); + $connexion = $app['phraseanet.configuration']->getConnexion($choosenConnexion); $hostname = $connexion->get('host'); $port = $connexion->get('port'); @@ -142,6 +147,7 @@ class connection } try { + $registry = $registry ? : $app['phraseanet.registry']; self::$_PDO_instance[$name] = new connection_pdo($name, $hostname, $port, $user, $password, $dbname, array(), $registry); self::$_PDO_instance[$name]->query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); } catch (Exception $e) { diff --git a/lib/classes/liste.class.php b/lib/classes/liste.class.php index 568568b7e2..37d34ce0c8 100644 --- a/lib/classes/liste.class.php +++ b/lib/classes/liste.class.php @@ -1,19 +1,19 @@ get_session(); - if ( ! is_array($lst)) explode(';', $lst); $okbrec = array(); - $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); + $user = $app['phraseanet.user']; foreach ($lst as $basrec) { $basrec = explode("_", $basrec); @@ -21,7 +21,7 @@ class liste continue; } try { - $record = new record_adapter($basrec[0], $basrec[1]); + $record = new record_adapter($app, $basrec[0], $basrec[1]); } catch (Exception $e) { continue; } @@ -41,7 +41,7 @@ class liste continue; try { - $connsbas = connection::getPDOConnection($basrec[0]); + $connsbas = connection::getPDOConnection($app, $basrec[0]); $sql = 'SELECT record_id FROM record WHERE ((status ^ ' . $user->ACL()->get_mask_xor($record->get_base_id()) . ') & ' . $user->ACL()->get_mask_and($record->get_base_id()) . ')=0' . diff --git a/lib/classes/login.class.php b/lib/classes/login.class.php index 5fb7805bbc..023410e113 100644 --- a/lib/classes/login.class.php +++ b/lib/classes/login.class.php @@ -1,19 +1,20 @@ get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php'; + require_once __DIR__ . '/deprecated/inscript.api.php'; - $bases = giveMeBases(); + $bases = giveMeBases($app); if ($bases) { foreach ($bases as $base) { @@ -26,22 +27,22 @@ class login return false; } - public function get_register_link() + public function get_register_link(Application $app) { $demandLinkBox = ''; - if (self::register_enabled()) { + if (self::register_enabled($app)) { $demandLinkBox = '' . _('login:: register') . ''; } return $demandLinkBox; } - public function get_guest_link() + public function get_guest_link(Application $app) { $inviteBox = ''; - if (phrasea::guest_allowed()) { + if (phrasea::guest_allowed($app)) { $inviteBox = '' . _('login:: guest Access') . ''; } diff --git a/lib/classes/mail.class.php b/lib/classes/mail.class.php index 26cf48077a..bf7840767e 100644 --- a/lib/classes/mail.class.php +++ b/lib/classes/mail.class.php @@ -1,11 +1,13 @@ $registry->get('GV_defaulmailsenderaddr'), 'name' => $registry->get('GV_defaulmailsenderaddr')); $subject = _('mail:: test d\'envoi d\'email'); @@ -14,33 +16,26 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $message, $to, $from); + return self::send_mail($app, $subject, $message, $to, $from); } - public static function send_validation_results($email, $subject, $from, $message) + public static function ftp_sent(Application $app, $email, $subject, $body) { $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $message, $to, $from); + return self::send_mail($app, $subject, $body, $to); } - public static function ftp_sent($email, $subject, $body) - { - $to = array('email' => $email, 'name' => $email); - - return self::send_mail($subject, $body, $to); - } - - public static function ftp_receive($email, $body) + public static function ftp_receive(Application $app, $email, $body) { $subject = _("task::ftp:Someone has sent some files onto FTP server"); $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function send_documents($email, $url, $from, $endate_obj, $message = '', $accuse) + public static function send_documents(Application $app, $email, $url, $from, $endate_obj, $message = '', $accuse) { $subject = _('export::vous avez recu des documents'); @@ -49,7 +44,7 @@ class mail $body .= '
' . sprintf( - _('Attention, ce lien lien est valable jusqu\'au %s'), phraseadate::getDate($endate_obj) . ' ' . phraseadate::getTime($endate_obj) + _('Attention, ce lien lien est valable jusqu\'au %s'), $app['date-formatter']->getDate($endate_obj) . ' ' . $app['date-formatter']->getTime($endate_obj) ) . '
'; @@ -59,10 +54,10 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to, $from, array(), $accuse); + return self::send_mail($app, $subject, $body, $to, $from, array(), $accuse); } - public static function forgot_passord($email, $login, $url) + public static function forgot_passord(Application $app, $email, $login, $url) { $subject = _('login:: Forgot your password'); // Registration order on . @@ -72,12 +67,12 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function register_confirm($email, $accept, $deny) + public static function register_confirm(Application $app, $email, $accept, $deny) { - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; $subject = sprintf(_('login::register:email: Votre compte %s'), $registry->get('GV_homeTitle')); $body = '
' . _('login::register:email: Voici un compte rendu du traitement de vos demandes d\'acces :') . "
\n"; @@ -91,35 +86,14 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function register_user($email, $auto, $others) + public static function reset_email(Application $app, $email, $usr_id) { - $registry = registry::get_instance(); - $subject = sprintf(_('login::register:email: Votre compte %s'), $registry->get('GV_homeTitle')); - - $body = "
" . _('login::register:Votre inscription a ete prise en compte') . "
\n"; - - if ($auto != '') { - $body .= "
\n
" . _('login::register: vous avez des a present acces aux collections suivantes : ') . "
\n\n"; - } - - if ($others != '') { - $body .= "
\n
" . _('login::register: vos demandes concernat les collections suivantes sont sujettes a approbation d\'un administrateur') . "
\n\n"; - $body .= "
\n
" . _('login::register : vous serez avertis par email lorsque vos demandes seront traitees') . "
\n"; - } - - $to = array('email' => $email, 'name' => $email); - - return self::send_mail($subject, $body, $to); - } - - public static function reset_email($email, $usr_id) - { - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; $date = new DateTime('1 day'); - $token = random::getUrlToken(\random::TYPE_EMAIL, $usr_id, $date, $email); + $token = random::getUrlToken($app, \random::TYPE_EMAIL, $usr_id, $date, $email); $url = $registry->get('GV_ServerName') . 'account/reset-email/?token=' . $token; @@ -130,12 +104,12 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function change_mail_information($display_name, $old_email, $new_email) + public static function change_mail_information(Application $app, $display_name, $old_email, $new_email) { - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; $subject = sprintf(_('Update of your email address on %s'), $registry->get('GV_homeTitle')); $body = "
" . sprintf(_('Dear %s,'), $display_name) . "
\n
\n"; @@ -152,30 +126,15 @@ class mail $to_old = array('email' => $old_email, 'name' => $display_name); $to_new = array('email' => $new_email, 'name' => $display_name); - $res_old = $old_email ? self::send_mail($subject, $body, $to_old) : true; - $res_new = $new_email ? self::send_mail($subject, $body, $to_new) : true; + $res_old = $old_email ? self::send_mail($app, $subject, $body, $to_old) : true; + $res_new = $new_email ? self::send_mail($app, $subject, $body, $to_new) : true; return $res_old && $res_new; } - public static function change_password(User_Adapter $user, $ip, \DateTime $date) + public static function send_credentials(Application $app, $url, $login, $email) { - $registry = registry::get_instance(); - - $subject = sprintf(_('Your account update on %s'), $registry->get('GV_homeTitle')); - - $body = "
" . sprintf(_('Dear %s,'), $user->get_display_name()) . "

\n\n"; - $body .= "
" . sprintf(_('The password of your account %s has been successfully updated'), $user->get_login()) . "

\n\n"; - $body .= "
" . sprintf(_('For your interest, the request has been done from %s at %s'), $ip, $date->format(DATE_ATOM)) . "
\n"; - - $to = array('email' => $user->get_email(), 'name' => $user->get_email()); - - return self::send_mail($subject, $body, $to); - } - - public static function send_credentials($url, $login, $email) - { - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; $subject = sprintf(_('Your account on %s'), $registry->get('GV_homeTitle')); @@ -185,12 +144,12 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function mail_confirm_registered($email) + public static function mail_confirm_registered(Application $app, $email) { - $registry = \registry::get_instance(); + $registry = $app['phraseanet.registry']; $subject = _('login::register: sujet email : confirmation de votre adresse email'); @@ -200,10 +159,10 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function mail_confirm_unregistered($email, array $others) + public static function mail_confirm_unregistered(Application $app, $email, array $others) { $subject = _('login::register: sujet email : confirmation de votre adresse email'); @@ -219,14 +178,14 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } - public static function mail_confirmation($email, $usr_id) + public static function mail_confirmation(Application $app, $email, $usr_id) { - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; $expire = new DateTime('+3 days'); - $token = random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, $expire, $email); + $token = random::getUrlToken($app, \random::TYPE_PASSWORD, $usr_id, $expire, $email); $subject = _('login::register: sujet email : confirmation de votre adresse email'); @@ -235,7 +194,7 @@ class mail $to = array('email' => $email, 'name' => $email); - return self::send_mail($subject, $body, $to); + return self::send_mail($app, $subject, $body, $to); } public static function validateEmail($email) @@ -243,11 +202,9 @@ class mail return PHPMailer::ValidateAddress($email); } - public static function send_mail($subject, $body, $to, $from = false, $files = array(), $reading_confirm_to = false) + public static function send_mail(Application $app, $subject, $body, $to, $from = false, $files = array(), $reading_confirm_to = false) { - $Core = \bootstrap::getCore(); - - $registry = $Core->getRegistry(); + $registry = $app['phraseanet.registry']; if ( ! isset($to['email']) || ! PHPMailer::ValidateAddress($to['email'])) { return false; @@ -255,8 +212,6 @@ class mail $mail = new PHPMailer(); - $body = eregi_replace("[\]", '', $body); - $body .= "



\n\n\n\n"; $body .= '
' . _('si cet email contient des liens non cliquables copiez/collez ces liens dans votre navigateur.') . '
'; $body .= "
\n"; @@ -270,13 +225,13 @@ class mail $mail->CharSet = 'utf-8'; $mail->Encoding = 'base64'; //'quoted-printable'; - $registry = registry::get_instance(); + $registry = $app['phraseanet.registry']; if ($registry->get('GV_smtp')) { $mail->IsSMTP(); if ($registry->get('GV_smtp_host') != '') $mail->Host = $registry->get('GV_smtp_host'); -// $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) + if ($registry->get('GV_smtp_auth')) { $mail->SMTPAuth = true; @@ -311,7 +266,7 @@ class mail $mail->AddAttachment($f); // attachment } - if ($Core->getConfiguration()->getEnvironnement() !== 'test') { + if ($app->getEnvironment() !== 'test') { $mail->Send(); } diff --git a/lib/classes/p4file.class.php b/lib/classes/p4file.class.php index 072e5a9953..de030cb507 100644 --- a/lib/classes/p4file.class.php +++ b/lib/classes/p4file.class.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Core\Configuration; + class p4file { - public static function apache_tokenize($file) + public static function apache_tokenize(\registry $registry, $file) { $ret = false; - $registry = registry::get_instance(); if ($registry->get('GV_h264_streaming') && is_file($file)) { if (($pos = mb_strpos($file, $registry->get('GV_mod_auth_token_directory_path'))) === false) { @@ -56,143 +57,4 @@ class p4file return $ret; } - public static function archiveFile(system_file &$system_file, $base_id, $delete = true, $name = false) - { - throw new Exception('This method is deprecated'); - - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); - $registry = $appbox->get_registry(); - - $system_file->set_phrasea_tech_field(system_file::TECH_FIELD_ORIGINALNAME, $name ? $name : $system_file->getFilename()); - $system_file->set_phrasea_tech_field(system_file::TECH_FIELD_PARENTDIRECTORY, null); - $system_file->set_phrasea_tech_field(system_file::TECH_FIELD_SUBPATH, null); - - $go = User_Adapter::getInstance($session->get_usr_id(), $appbox) - ->ACL() - ->has_right_on_base($base_id, 'canaddrecord'); - - if ( ! $go) { - echo "\ndroits insuffisants"; - - return false; - } - - $sbas_id = phrasea::sbasFromBas($base_id); - $databox = $appbox->get_databox($sbas_id); - $collection = collection::get_from_base_id($base_id); - - $collprefs = simplexml_load_string($collection->get_prefs()); - - $server_coll_id = phrasea::collFromBas($base_id); - - if ($collprefs === false) { - if (GV_debug) - echo 'Error loading collprefs'; - - return false; - } - - $metadatas = $system_file->extract_metadatas($databox->get_meta_structure()); - - $status = "0"; - - if ($collprefs->status) - $status = (string) ($collprefs->status); - - $record_id = $record = false; - - try { - $record = record_adapter::create($collection, $system_file, $name); - $record_id = $record->get_record_id(); - $record->set_metadatas($metadatas['metadatas'], true); - } catch (Exception $e) { - echo $e->getMessage(); - if ($record instanceof record_adapter) - $record->delete(); - - return false; - } - - $record->set_binary_status(databox_status::dec2bin($status)); - $record->rebuild_subdefs(); - $record->reindex(); - - if ($delete) { - @unlink($system_file->getPathname()); - unset($system_file); - } - - return $record_id; - } - - public static function check_file_error($filename, $sbas_id, $originalname) - { - throw new Exception('This method is deprecated'); - - $core = \bootstrap::getCore(); - $appbox = \appbox::get_instance($core); - $checks = array(); - - $system_file = new system_file($filename); - - $doctype = $system_file->get_phrasea_type(); - - $databox = $appbox->get_databox($sbas_id); - - if ($baseprefs = $databox->get_sxml_structure()) { - - $file_checks = $baseprefs->filechecks; - $checks = $file_checks->$doctype; - $checks = $checks[0]; - } else { - throw new Exception(_('prod::erreur : impossible de lire les preferences de base')); - } - - $errors = array(); - - $media = $core['mediavorus']->guess($filename); - - $width = $height = 0; - $colorSpace = null; - - if ($media instanceof \MediaVorus\Media\Image) { - $width = $media->getWidth(); - $height = $media->getHeight(); - $colorSpace = strtolower($media->getColorSpace()); - } - - foreach ($checks as $name => $value) { - switch ($name) { - case 'name': - $records = record_adapter::get_records_by_originalname($databox, $original_name, false, 0, 1); - if (count($records) > 0) - $errors[] = sprintf(_('Le fichier \'%s\' existe deja'), $originalname); - break; - case 'size': - if (min($width, $height) < (int) $value) { - $errors[] = sprintf(_('Taille trop petite : %dpx'), $min); - } - break; - case 'color_space': - $required = strtolower(in_array($value, array('sRGB', 'RGB')) ? 'RGB' : $value); - - $go = false; - - if ( ! $colorSpace || $required == $colorSpace) { - $go = true; - } elseif ($required == 'rgb' && in_array($colorSpace, array('srgb', 'rgb')) > 0) { - $go = true; - } - - if ( ! $go) { - $errors[] = sprintf(_('Mauvais mode colorimetrique : %s'), $colorSpace); - } - - break; - } - } - - return $errors; - } } diff --git a/lib/classes/phrasea.class.php b/lib/classes/phrasea.class.php index 6c5832dd5e..9950c3cfcd 100644 --- a/lib/classes/phrasea.class.php +++ b/lib/classes/phrasea.class.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Core\Configuration; +use Alchemy\Phrasea\Exception\RuntimeException; + class phrasea { private static $_bas2sbas = false; @@ -26,10 +30,10 @@ class phrasea const CACHE_SBAS_FROM_BAS = 'sbas_from_bas'; const CACHE_SBAS_PARAMS = 'sbas_params'; - public static function is_scheduler_started() + public static function is_scheduler_started(Application $app) { $retval = false; - $conn = connection::getPDOConnection(); + $conn = connection::getPDOConnection($app); $sql = 'SELECT schedstatus FROM sitepreff'; $stmt = $conn->prepare($sql); @@ -44,10 +48,8 @@ class phrasea return $retval; } - public static function start(\Alchemy\Phrasea\Core $Core) + public static function start(Configuration $configuration) { - $configuration = $Core->getConfiguration(); - $choosenConnexion = $configuration->getPhraseanet()->get('database'); $connexion = $configuration->getConnexion($choosenConnexion); @@ -58,23 +60,27 @@ class phrasea $password = $connexion->get('password'); $dbname = $connexion->get('dbname'); - if ( ! extension_loaded('phrasea2')) - printf("Missing Extension php-phrasea"); + if (!extension_loaded('phrasea2')) { + throw new RuntimeException('Phrasea extension is required'); + } - if (function_exists('phrasea_conn')) - if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true) - self::headers(500); + if (!function_exists('phrasea_conn')) { + throw new RuntimeException('Phrasea extension requires upgrade'); + } + + if (phrasea_conn($hostname, $port, $user, $password, $dbname) !== true) { + throw new RuntimeException('Unable to initialize Phrasea connection'); + } } - public function getHome($type = 'PUBLI', $context = 'prod') + public function getHome(Application $app, $type = 'PUBLI', $context = 'prod') { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); + $appbox = $app['phraseanet.appbox']; $registry = $appbox->get_registry(); - $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); + $user = $app['phraseanet.user']; if ($type == 'HELP') { - if (file_exists($registry->get('GV_RootPath') . "config/help_" . $session->get_I18n() . ".php")) { - require($registry->get('GV_RootPath') . "config/help_" . $session->get_I18n() . ".php"); + if (file_exists($registry->get('GV_RootPath') . "config/help_" . $app['locale.I18n'] . ".php")) { + require($registry->get('GV_RootPath') . "config/help_" . $app['locale.I18n'] . ".php"); } elseif (file_exists($registry->get('GV_RootPath') . 'config/help.php')) {// on verifie si il y a une home personnalisee sans langage require($registry->get('GV_RootPath') . 'config/help.php'); } else { @@ -101,7 +107,7 @@ class phrasea foreach ($searchSet->bases as $bases) $bas = array_merge($bas, $bases); } else { - $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); + $user = $app['phraseanet.user']; $bas = array_keys($user->ACL()->get_granted_base()); } @@ -150,22 +156,21 @@ class phrasea return; } - public static function clear_sbas_params() + public static function clear_sbas_params(Application $app) { self::$_sbas_params = null; - $appbox = appbox::get_instance(\bootstrap::getCore()); - $appbox->delete_data_from_cache(self::CACHE_SBAS_PARAMS); + $app['phraseanet.appbox']->delete_data_from_cache(self::CACHE_SBAS_PARAMS); return true; } - public static function sbas_params() + public static function sbas_params(Application $app) { if (self::$_sbas_params) { return self::$_sbas_params; } - $appbox = appbox::get_instance(\bootstrap::getCore()); + $appbox = $app['phraseanet.appbox']; try { self::$_sbas_params = $appbox->get_data_from_cache(self::CACHE_SBAS_PARAMS); @@ -191,14 +196,13 @@ class phrasea return self::$_sbas_params; } - public static function guest_allowed() + public static function guest_allowed(Application $app) { - $usr_id = User_Adapter::get_usr_id_from_login('invite'); - if ( ! $usr_id) { + $usr_id = User_Adapter::get_usr_id_from_login($app, 'invite'); + if (!$usr_id) { return false; } - $appbox = appbox::get_instance(\bootstrap::getCore()); - $user = User_Adapter::getInstance($usr_id, $appbox); + $user = User_Adapter::getInstance($usr_id, $app); return count($user->ACL()->get_granted_base()) > 0; } @@ -243,10 +247,10 @@ class phrasea return $array; } - public static function sbasFromBas($base_id) + public static function sbasFromBas(Application $app, $base_id) { - if ( ! self::$_bas2sbas) { - $appbox = appbox::get_instance(\bootstrap::getCore()); + if (!self::$_bas2sbas) { + $appbox = $app['phraseanet.appbox']; try { self::$_bas2sbas = $appbox->get_data_from_cache(self::CACHE_SBAS_FROM_BAS); } catch (Exception $e) { @@ -267,10 +271,10 @@ class phrasea return isset(self::$_bas2sbas[$base_id]) ? self::$_bas2sbas[$base_id] : false; } - public static function baseFromColl($sbas_id, $coll_id) + public static function baseFromColl($sbas_id, $coll_id, Application $app) { - if ( ! self::$_coll2bas) { - $conn = connection::getPDOConnection(); + if (!self::$_coll2bas) { + $conn = connection::getPDOConnection($app); $sql = 'SELECT base_id, server_coll_id, sbas_id FROM bas'; $stmt = $conn->prepare($sql); $stmt->execute(); @@ -278,7 +282,7 @@ class phrasea $stmt->closeCursor(); foreach ($rs as $row) { - if ( ! isset(self::$_coll2bas[$row['sbas_id']])) + if (!isset(self::$_coll2bas[$row['sbas_id']])) self::$_coll2bas[$row['sbas_id']] = array(); self::$_coll2bas[$row['sbas_id']][$row['server_coll_id']] = (int) $row['base_id']; } @@ -287,10 +291,9 @@ class phrasea return isset(self::$_coll2bas[$sbas_id][$coll_id]) ? self::$_coll2bas[$sbas_id][$coll_id] : false; } - public static function reset_baseDatas() + public static function reset_baseDatas(appbox $appbox) { self::$_coll2bas = self::$_bas2coll = self::$_bas_names = self::$_bas2sbas = null; - $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache( array( self::CACHE_BAS_2_COLL @@ -303,10 +306,9 @@ class phrasea return; } - public static function reset_sbasDatas() + public static function reset_sbasDatas(appbox $appbox) { self::$_sbas_names = self::$_sbas_params = self::$_bas2sbas = null; - $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache( array( self::CACHE_SBAS_NAMES @@ -318,10 +320,10 @@ class phrasea return; } - public static function collFromBas($base_id) + public static function collFromBas(Application $app, $base_id) { - if ( ! self::$_bas2coll) { - $conn = connection::getPDOConnection(); + if (!self::$_bas2coll) { + $conn = connection::getPDOConnection($app); $sql = 'SELECT base_id, server_coll_id FROM bas'; $stmt = $conn->prepare($sql); $stmt->execute(); @@ -336,10 +338,10 @@ class phrasea return isset(self::$_bas2coll[$base_id]) ? self::$_bas2coll[$base_id] : false; } - public static function sbas_names($sbas_id) + public static function sbas_names($sbas_id, Application $app) { - if ( ! self::$_sbas_names) { - $appbox = appbox::get_instance(\bootstrap::getCore()); + if (!self::$_sbas_names) { + $appbox = $app['phraseanet.appbox']; try { self::$_sbas_names = $appbox->get_data_from_cache(self::CACHE_SBAS_NAMES); } catch (Exception $e) { @@ -360,10 +362,10 @@ class phrasea return isset(self::$_sbas_names[$sbas_id]) ? self::$_sbas_names[$sbas_id] : 'Unknown base'; } - public static function bas_names($base_id) + public static function bas_names($base_id, Application $app) { - if ( ! self::$_bas_names) { - $appbox = appbox::get_instance(\bootstrap::getCore()); + if (!self::$_bas_names) { + $appbox = $app['phraseanet.appbox']; try { self::$_bas_names = $appbox->get_data_from_cache(self::CACHE_BAS_NAMES); } catch (Exception $e) { @@ -423,9 +425,9 @@ class phrasea return; } - public static function scheduler_key($renew = false) + public static function scheduler_key(Application $app, $renew = false) { - $conn = connection::getPDOConnection(); + $conn = connection::getPDOConnection($app); $schedulerkey = false; diff --git a/lib/classes/phraseadate.class.php b/lib/classes/phraseadate.class.php index b0263dd1de..dda74af39f 100644 --- a/lib/classes/phraseadate.class.php +++ b/lib/classes/phraseadate.class.php @@ -1,5 +1,7 @@ app = $app; + } + /** * * @param DateTime $date * @return string */ - public static function getTime(DateTime $date) + public function getTime(DateTime $date) { - $locale = Session_Handler::get_locale(); - - switch ($locale) { + switch ($this->app['locale']) { default: case 'fr_FR': case 'de_DE': @@ -44,7 +51,7 @@ class phraseadate * @param DateTime $date * @return string */ - public static function getDate(DateTime $date) + public function getDate(DateTime $date) { $compareTo = new DateTime('now'); $diff = $compareTo->format('U') - $date->format('U'); @@ -55,9 +62,9 @@ class phraseadate } if ($dayDiff < 365) { - return self::formatDate($date, Session_Handler::get_locale(), 'DAY_MONTH'); + return $this->formatDate($date, $this->app['locale'], 'DAY_MONTH'); } else { - return self::formatDate($date, Session_Handler::get_locale(), 'DAY_MONTH_YEAR'); + return $this->formatDate($date, $this->app['locale'], 'DAY_MONTH_YEAR'); } } @@ -66,7 +73,7 @@ class phraseadate * @param DateTime $date * @return string */ - public static function getPrettyString(DateTime $date = null) + public function getPrettyString(DateTime $date = null) { if (is_null($date)) { return null; @@ -80,7 +87,7 @@ class phraseadate return ''; } - $date_string = self::formatDate($date, Session_Handler::get_locale(), 'DAY_MONTH'); + $date_string = $this->formatDate($date, $this->app['locale'], 'DAY_MONTH'); if ($dayDiff == 0) { if ($diff < 60) { @@ -101,7 +108,7 @@ class phraseadate } elseif ($dayDiff < 365 && $dayDiff > 0) { return $date_string; } else { - return self::formatDate($date, Session_Handler::get_locale(), 'DAY_MONTH_YEAR'); + return $this->formatDate($date, $this->app['locale'], 'DAY_MONTH_YEAR'); } } @@ -110,7 +117,7 @@ class phraseadate * @param DateTime $date * @return string */ - public static function format_mysql(DateTime $date) + public function format_mysql(DateTime $date) { return $date->format(DATE_ISO8601); } @@ -171,7 +178,7 @@ class phraseadate * @param string $format * @return string */ - public static function isodateToDate($isodelimdate, $format) + public function isodateToDate($isodelimdate, $format) { $tc = array(); $bal = array(); @@ -234,7 +241,7 @@ class phraseadate * @param string $format * @return string */ - public static function dateToIsodate($strdate, $format) + public function dateToIsodate($strdate, $format) { $v_y = $v_m = $v_d = $v_h = $v_n = $v_s = 0; $v = str_replace( diff --git a/lib/classes/queries.class.php b/lib/classes/queries.class.php index 6a549a6c11..2b75f7f523 100644 --- a/lib/classes/queries.class.php +++ b/lib/classes/queries.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Core\Configuration; + /** * * @@ -18,23 +20,19 @@ class queries { - public static function tree_topics() + public static function tree_topics($I18N) { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); - $registry = $appbox->get_registry(); - $out = ''; $xmlTopics = null; $sxTopics = null; - if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml')) - $xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml'; + if (file_exists(__DIR__ . '/../../config/topics/topics_' . $I18N . '.xml')) + $xmlTopics = __DIR__ . '/../../config/topics/topics_' . $I18N . '.xml'; if ( ! $xmlTopics) { - if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics.xml')) { - $xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics.xml'; + if (file_exists(__DIR__ . '/../../config/topics/topics.xml')) { + $xmlTopics = __DIR__ . '/../../config/topics/topics.xml'; } } @@ -65,40 +63,32 @@ class queries return $out; } - public static function topics_exists() + public static function topics_exists($I18n) { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); - $registry = $appbox->get_registry(); - - if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml')) { + if (file_exists(__DIR__ . '/../../config/topics/topics_' . $I18n . '.xml')) { return true; } - if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics.xml')) { + if (file_exists(__DIR__ . '/../../config/topics/topics.xml')) { return true; } return false; } - public static function dropdown_topics() + public static function dropdown_topics($I18n) { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); - $registry = $appbox->get_registry(); - $out = ''; $xmlTopics = ''; $sxTopics = null; - if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml')) - $xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics_' . $session->get_I18n() . '.xml'; + if (file_exists(__DIR__ . '/../../config/topics/topics_' . $I18n . '.xml')) + $xmlTopics = __DIR__ . '/../../config/topics/topics_' . $I18n . '.xml'; if ($xmlTopics == '') { - if (file_exists($registry->get('GV_RootPath') . 'config/topics/topics.xml')) { - $xmlTopics = $registry->get('GV_RootPath') . 'config/topics/topics.xml'; + if (file_exists(__DIR__ . '/../../config/topics/topics.xml')) { + $xmlTopics = __DIR__ . '/../../config/topics/topics.xml'; } } @@ -200,14 +190,10 @@ class queries return $out; } - public static function history() + public static function history(appbox $appbox, $usr_id) { - $appbox = appbox::get_instance(\bootstrap::getCore()); - $session = $appbox->get_session(); $conn = $appbox->get_connection(); - $usr_id = $session->get_usr_id(); - $sql = "SELECT query from dsel where usr_id = :usr_id ORDER BY id DESC LIMIT 0,25"; @@ -219,8 +205,6 @@ class queries $history = '