public function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings)
 {
     $this->_daoFactory = $daoFactory;
     $this->_settings = $settings;
     $this->_cacheDao = $daoFactory->getCacheDao();
     $this->_httpProvider = new Services_Providers_Http($this->_cacheDao);
 }
 public function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings)
 {
     $this->_daoFactory = $daoFactory;
     $this->_settings = $settings;
     $this->_userDao = $daoFactory->getUserDao();
     $this->_sessionDao = $daoFactory->getSessionDao();
 }
 /**
  * Create collections from a list of spot(headers)
  *
  * @param array $spotDbList
  * @return array
  */
 public function createCollectionsFromList(array $spotDbList)
 {
     /*
      * Loop through all Spots, and try to get the most appropriate
      * parsed title out of it, so we can later reuse that as an unique
      * identifier for the collection info.
      */
     foreach ($spotDbList as &$spot) {
         $spot['collectionInfo'] = Services_ParseCollections_Factory::factory($spot)->parseSpot();
     }
     // foreach
     unset($spot);
     /*
      * Now try to find collection id's in the database for those, and set that collection
      * id to the database
      */
     $spotDbList = $this->_daoFactory->getCollectionsDao()->getCollectionIdList($spotDbList);
     foreach ($spotDbList as &$spot) {
         if ($spot['collectionInfo'] != null) {
             $spot['collectionid'] = $spot['collectionInfo']->getId();
         } else {
             $spot['collectionid'] = null;
         }
         // else
     }
     // foreach
     unset($spot);
     return $spotDbList;
 }
Пример #4
0
 function connect()
 {
     SpotTiming::start(__FUNCTION__);
     /* 
      * Erase username/password so it won't show up in any stacktrace
      */
     # SQlite heeft geen username gedefinieerd
     if (isset($this->_dbsettings['user'])) {
         $tmpUser = $this->_dbsettings['user'];
         $this->_dbsettings['user'] = '******';
     }
     # if
     # en ook geen pass
     if (isset($this->_dbsettings['pass'])) {
         $tmpPass = $this->_dbsettings['pass'];
         $this->_dbsettings['pass'] = '******';
     }
     # if
     switch ($this->_dbsettings['engine']) {
         case 'mysql':
             $this->_conn = new dbeng_mysql($this->_dbsettings['host'], $tmpUser, $tmpPass, $this->_dbsettings['dbname']);
             $daoFactory = Dao_Factory::getDAOFactory("mysql");
             break;
         case 'pdo_mysql':
             $this->_conn = new dbeng_pdo_mysql($this->_dbsettings['host'], $tmpUser, $tmpPass, $this->_dbsettings['dbname']);
             $daoFactory = Dao_Factory::getDAOFactory("mysql");
             break;
         case 'pdo_pgsql':
             $this->_conn = new dbeng_pdo_pgsql($this->_dbsettings['host'], $tmpUser, $tmpPass, $this->_dbsettings['dbname']);
             $daoFactory = Dao_Factory::getDAOFactory("postgresql");
             break;
         case 'pdo_sqlite':
             $this->_conn = new dbeng_pdo_sqlite($this->_dbsettings['path']);
             $daoFactory = Dao_Factory::getDAOFactory("sqlite");
             break;
         default:
             throw new Exception('Unknown DB engine specified (' . $this->_dbsettings['engine'] . ', please choose pdo_pgsql, mysql or pdo_mysql');
     }
     # switch
     $daoFactory->setConnection($this->_conn);
     $this->_auditDao = $daoFactory->getAuditDao();
     $this->_blackWhiteListDao = $daoFactory->getBlackWhiteListDao();
     $this->_cacheDao = $daoFactory->getCacheDao();
     $this->_commentDao = $daoFactory->getCommentDao();
     $this->_notificationDao = $daoFactory->getNotificationDao();
     $this->_sessionDao = $daoFactory->getSessionDao();
     $this->_settingDao = $daoFactory->getSettingDao();
     $this->_spotReportDao = $daoFactory->getSpotReportDao();
     $this->_userFilterCountDao = $daoFactory->getUserFilterCountDao();
     $this->_userFilterDao = $daoFactory->getUserFilterDao();
     $this->_userDao = $daoFactory->getUserDao();
     $this->_spotDao = $daoFactory->getSpotdao();
     $this->_spotStateListDao = $daoFactory->getSpotStateListDao();
     $this->_nntpDao = $daoFactory->getNntpDao();
     $this->_conn->connect();
     SpotTiming::stop(__FUNCTION__);
 }
Пример #5
0
 function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings, $force, $retro)
 {
     $this->_daoFactory = $daoFactory;
     $this->_settings = $settings;
     $this->_retro = $retro;
     $this->_force = $force;
     $this->_textServer = $settings->get('nntp_hdr');
     $this->_binServer = $settings->get('nntp_nzb');
     /*
      * Create the specific DAO objects
      */
     $this->_usenetStateDao = $daoFactory->getUsenetStateDao();
     $this->_usenetStateDao->initialize();
     /*
      * Create the service objects for both the NNTP binary group and the
      * textnews group. We only create a basic NNTP_Engine object, but we 
      * don't create any higher level objects
      */
     $this->_svcNntpText = Services_Nntp_EnginePool::pool($this->_settings, 'hdr');
     $this->_svcNntpBin = Services_Nntp_EnginePool::pool($this->_settings, 'bin');
 }
Пример #6
0
 /**
  * Bootup the settings system
  */
 public function getSettings(Dao_Factory $daoFactory, $requireDb)
 {
     $settingsContainer = Services_Settings_Container::singleton();
     /**
      * Add a database source
      */
     try {
         $dbSource = new Services_Settings_DbContainer();
         $dbSource->initialize(array('dao' => $daoFactory->getSettingDao()));
         $settingsContainer->addSource($dbSource);
     } catch (Exception $x) {
         if ($requireDb) {
             throw $x;
         }
         # if
     }
     # catch
     /**
      * Add the file (ownsettings.php etc) source to override settings
      */
     require "settings.php";
     $fileSource = new Services_Settings_FileContainer();
     $fileSource->initialize($settings);
     $settingsContainer->addSource($fileSource);
     return $settingsContainer;
 }
Пример #7
0
function createSystem()
{
    global $settings;
    global $_testInstall_Ok;
    try {
        /*
         * The settings system is used to create a lot of output,
         * we swallow it all
         */
        ob_start();
        /*
         * Get the schema version and other constants
         */
        require_once "lib/Bootstrap.php";
        $bootstrap = new Bootstrap();
        /*
         * Now create the database
         */
        $dbsettings = $_SESSION['spotsettings']['db'];
        $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
        $dbCon->connect($dbsettings['host'], $dbsettings['user'], $dbsettings['pass'], $dbsettings['dbname']);
        $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
        $daoFactory->setConnection($dbCon);
        /*
         * The database must exist before we can get the Service_Settings_Base instance
         */
        $dbStruct = SpotStruct_abs::factory($dbsettings['engine'], $daoFactory->getConnection());
        $dbStruct->updateSchema();
        $spotSettings = $bootstrap->getSettings($daoFactory, false);
        $svcUpgradeBase = new Services_Upgrade_Base($daoFactory, $spotSettings, $dbsettings['engine']);
        /*
         * Create all the different settings (only the default) ones
         */
        $svcUpgradeBase->settings();
        /*
         * Create the users
         */
        $svcUpgradeBase->users();
        /*
         * print all the output as HTML comment for debugging
         */
        $dbCreateOutput = ob_get_contents();
        ob_end_clean();
        /*
         * Now it is time to do something with
         * the information the user has given to us
         */
        /*
         * Update the NNTP settings in the databas
         */
        $spotSettings->set('nntp_nzb', $_SESSION['spotsettings']['nntp']['nzb']);
        $spotSettings->set('nntp_hdr', $_SESSION['spotsettings']['nntp']['hdr']);
        $spotSettings->set('nntp_post', $_SESSION['spotsettings']['nntp']['post']);
        /*
         * Create the given user
         */
        $svcUserRecord = new Services_User_Record($daoFactory, $spotSettings);
        $spotUser = $_SESSION['spotsettings']['adminuser'];
        /*
         * and actually add the user
         */
        $spotUser['userid'] = $svcUserRecord->createUserRecord($spotUser)->getData('userid');
        /*
         * When the new user was created a random password was assigned, 
         * so now have to set the supplied password
         */
        $svcUserRecord->setUserPassword($spotUser);
        # Change the administrators' account password to that of this created user
        $adminUser = $svcUserRecord->getUser(SPOTWEB_ADMIN_USERID);
        $adminUser['newpassword1'] = $spotUser['newpassword1'];
        $svcUserRecord->setUserPassword($adminUser);
        # update the settings with our system type and our admin id
        $spotSettings->set('custom_admin_userid', $spotUser['userid']);
        $spotSettings->set('systemtype', $spotUser['systemtype']);
        # Set the system type
        $svcUpgradeBase->resetSystemType($spotUser['systemtype']);
        /* 
         * Create the necessary database connection information
         */
        $dbConnectionString = '';
        switch ($_SESSION['spotsettings']['db']['engine']) {
            case 'pdo_mysql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_mysql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # mysql
            # mysql
            case 'pdo_pgsql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_pgsql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # pdo_pgsql
        }
        # switch
        # Try to create the dbsettings.inc.php file for the user
        @file_put_contents("dbsettings.inc.php", "<?php" . PHP_EOL . $dbConnectionString);
        $createdDbSettings = file_exists("dbsettings.inc.php");
        showTemplate("step-final.inc.php", array('createdDbSettings' => $createdDbSettings, 'dbCreateOutput' => $dbCreateOutput, 'dbConnectionString' => $dbConnectionString));
    } catch (Exception $x) {
        showTemplate("fatalerror.inc.php", array('x' => $x));
    }
    # exception
}
Пример #8
0
 function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings)
 {
     $this->_dbCon = $daoFactory->getConnection();
     $this->_userDao = $daoFactory->getUserDao();
     $this->_settings = $settings;
 }
Пример #9
0
 function sendMessages($userId)
 {
     $userDao = $this->_daoFactory->getUserDao();
     $notificationDao = $this->_daoFactory->getNotificationDao();
     if ($userId == 0) {
         $userList = $userDao->getUserList();
     } else {
         $thisUser = $userDao->getUser($userId);
         $userList = array($thisUser);
     }
     # else
     foreach ($userList as $user) {
         # Omdat we vanuit getUserList() niet alle velden meekrijgen
         # vragen we opnieuw het user record op
         $user = $userDao->getUser($user['userid']);
         $security = new SpotSecurity($this->_daoFactory->getUserDao(), $this->_daoFactory->getAuditDao(), $this->_settings, $user, '');
         # Om e-mail te kunnen versturen hebben we iets meer data nodig
         $user['prefs']['notifications']['email']['sender'] = $this->_settings->get('systemfrommail');
         $user['prefs']['notifications']['email']['receiver'] = $user['mail'];
         # Twitter heeft ook extra settings nodig
         $user['prefs']['notifications']['twitter']['consumer_key'] = $this->_settings->get('twitter_consumer_key');
         $user['prefs']['notifications']['twitter']['consumer_secret'] = $this->_settings->get('twitter_consumer_secret');
         # Evenals Boxcar
         $user['prefs']['notifications']['boxcar']['api_key'] = $this->_settings->get('boxcar_api_key');
         $user['prefs']['notifications']['boxcar']['api_secret'] = $this->_settings->get('boxcar_api_secret');
         $newMessages = $notificationDao->getUnsentNotifications($user['userid']);
         foreach ($newMessages as $newMessage) {
             $objectId = $newMessage['objectid'];
             $spotweburl = $this->_settings->get('spotweburl') == 'http://mijnuniekeservernaam/spotweb/' ? '' : $this->_settings->get('spotweburl');
             $notifProviders = Notifications_Factory::getActiveServices();
             foreach ($notifProviders as $notifProvider) {
                 if ($user['prefs']['notifications'][$notifProvider]['enabled'] && $user['prefs']['notifications'][$notifProvider]['events'][$objectId]) {
                     if ($security->allowed(SpotSecurity::spotsec_send_notifications_services, $notifProvider)) {
                         $this->_notificationServices[$notifProvider] = Notifications_Factory::build('Spotweb', $notifProvider, $user['prefs']['notifications'][$notifProvider]);
                     }
                     # if
                 }
                 # if
             }
             # foreach
             # nu wordt het bericht pas echt verzonden
             foreach ($this->_notificationServices as $notificationService) {
                 $notificationService->sendMessage($newMessage['type'], utf8_decode($newMessage['title']), utf8_decode($newMessage['body']), $spotweburl);
             }
             # foreach
             # Alle services resetten, deze mogen niet hergebruikt worden
             $this->_notificationServices = array();
             # Als dit bericht ging over het aanmaken van een nieuwe user, verwijderen we
             # het plaintext wachtwoord uit de database uit veiligheidsoverwegingen.
             if ($objectId == SpotNotifications::notifytype_user_added) {
                 $body = explode(" ", $newMessage['body']);
                 $body[4] = '[deleted]';
                 $newMessage['body'] = implode(" ", $body);
             }
             # if
             $newMessage['sent'] = true;
             $notificationDao->updateNotification($newMessage);
         }
         # foreach message
     }
     # foreach user
 }
 public function getSpotComments($msgId, $userId, $start, $length, $language)
 {
     # Check users' permissions
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_comments, '');
     $svcNntpSpotReading = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($this->_settings, 'hdr'));
     $svcProvComments = new Services_Providers_Comments($this->_daoFactory->getCommentDao(), $svcNntpSpotReading);
     $tryTranslate = Services_Actions_GetComments::nativeLanguage !== $language;
     /*
      * Basically we are retrieving the comments from the database, for them to be translated
      * if necessary
      */
     $comments = $svcProvComments->fetchSpotComments($msgId, $userId, $start, $length);
     if (!$tryTranslate) {
         return $comments;
     }
     # if
     /*
      * In our cache, we store an key => value pair with the original string and
      * the translation, so we can do very quick lookups.
      */
     $toBeTranslated = array();
     $translated = $this->_cacheDao->getCachedTranslatedComments($msgId, $language);
     if ($translated === false) {
         $translated = array();
     }
     # if
     foreach ($comments as &$comment) {
         $tmpBody = $comment['body'];
         if (isset($translated[$tmpBody])) {
             $comment['body_translated'] = $translated[$tmpBody];
         } else {
             $toBeTranslated[] = $comment;
         }
         # else
     }
     # foreach
     /*
      * Actually translate our list of comments, and merge
      * them with the actual comments
      */
     if (!empty($toBeTranslated)) {
         $svcTranslate = new Services_Translation_Microsoft($this->_settings, $this->_cacheDao);
         if (!$svcTranslate->isAvailable()) {
             return $comments;
         }
         # if
         $translations = $svcTranslate->translateMultiple($language, $toBeTranslated, 'body');
         /*
          * copy the translations into the cache
          */
         if (!empty($translations)) {
             foreach ($translations as $v) {
                 $tmpBody = $v['body'];
                 $translated[$tmpBody] = $v['body_translated'];
             }
             # foreach
             /*
              * Convert the comments once again
              */
             foreach ($comments as &$comment) {
                 $tmpBody = $comment['body'];
                 if (isset($translated[$tmpBody])) {
                     $comment['body_translated'] = $translated[$tmpBody];
                 }
                 # else
             }
             # foreach
         }
         # if
         /*
          * and save the translated bodies into the cache
          */
         $this->_cacheDao->saveTranslatedCommentCache($msgId, $language, $translated);
     }
     # if
     return $comments;
 }
Пример #11
0
 function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings, $dbEngine)
 {
     $this->_daoFactory = $daoFactory;
     $this->_dbStruct = SpotStruct_abs::factory($dbEngine, $daoFactory->getConnection());
     $this->_settings = $settings;
 }