コード例 #1
0
ファイル: User.php プロジェクト: ballistiq/revive-adserver
 function loadAccountData($accountId)
 {
     if (!empty($accountId)) {
         $this->_clearAccountData();
         $doAccount = OA_Dal::factoryDO('accounts');
         $doAccount->account_id = $accountId;
         $doAccount->find();
         if ($doAccount->fetch()) {
             $this->aAccount = $doAccount->toArray() + $this->aAccount;
             if ($this->aAccount['account_type'] != OA_ACCOUNT_ADMIN) {
                 $this->aAccount['entity_id'] = $this->_getEntityId();
                 if (empty($this->aAccount['entity_id'])) {
                     Max::raiseError("No entity associated with the account");
                 }
                 if ($this->aAccount['account_type'] == OA_ACCOUNT_MANAGER) {
                     $this->aAccount['agency_id'] = $this->aAccount['entity_id'];
                 } else {
                     $this->aAccount['agency_id'] = $this->_getAgencyId();
                 }
                 if (empty($this->aAccount['agency_id'])) {
                     Max::raiseError("No manager associated with the account");
                 }
             }
         } else {
             Max::raiseError("Could not find the specified account");
         }
     }
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function transformMarkdown($text)
 {
     $types = array();
     $markdown = preg_replace_callback("@```[ ]*([^\n]*)(.+?)```@smi", function ($m) use(&$types) {
         $types[] = trim($m[1]);
         return '    ' . str_replace("\n", "\n    ", trim($m[2], "\r\n"));
     }, parent::transformMarkdown($text));
     return $markdown;
 }
コード例 #3
0
ファイル: MaxTest.php プロジェクト: shinichi81/eep-php
 /** 
  * @test 
  *
  * So this test is skipped, because compensate doesn't work. Need to 
  * think up a way of doing this without effective keeping the whole
  * window in memory. 
  */
 public function compensateRemovesNumber()
 {
     $this->markTestIncomplete();
     return;
     $max = new Max();
     $max->init();
     $max->accumulate(1);
     $max->accumulate(5);
     $max->compensate(5);
     $this->assertEquals(1, $max->emit());
 }
コード例 #4
0
ファイル: DB.php プロジェクト: Spark-Eleven/revive-adserver
 /**
  * A method to return a singleton database connection resource.
  *
  * Example usage:
  * $oDbh = OA_DB::singleton();
  *
  * Warning: In order to work correctly, the singleton method must
  * be instantiated statically and by reference, as in the above
  * example.
  *
  * @static
  * @param string $dsn Optional database DSN details - connects to the
  *                    database defined by the configuration file otherwise.
  *                    See {@link OA_DB::getDsn()} for format.
  *
  * @param array $aDriverOptions An optional array of driver options. Currently
  *                              supported options are:
  *                  - For MySQL:
  *                      ['ssl']      = false|true Perform connection over SSL?
  *                      ['ca']       = Name of CA file, if "ssl" true
  *                      ['capath']   = Path to CA file above, is "ssl" true
  *                      ['compress'] = false|true Use client compression?
  *
  * @return MDB2_Driver_Common An MDB2 connection resource, or PEAR_Error
  *                            on failure to connect.
  */
 static function singleton($dsn = null, $aDriverOptions = array())
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Get the driver options, if not set
     if (!is_array($aDriverOptions) || is_null($dsn) && empty($aDriverOptions)) {
         $aDriverOptions = OA_DB::getDsnOptions();
     }
     // Get the DSN, if not set
     $dsn = is_null($dsn) ? OA_DB::getDsn() : $dsn;
     // Check that the parameter is a string, not an array
     if (is_array($dsn)) {
         return Max::raiseError('Bad argument: DSN should be a string', MAX_ERROR_INVALIDARGS);
     }
     // A hack to allow for installation on pgsql
     // If the configuration hasn't been defined prevent
     // loading mysql MDB2 driver.
     if (strpos($dsn, '//:@') !== false) {
         // Return a silent error
         return new PEAR_Error('Bad argument: Empty DSN');
     }
     // Get the database type in use from the DNS, not from the
     // configuration file
     $aDSN = MDB2::parseDSN($dsn);
     $databaseType = $aDSN['phptype'];
     // Is this a MySQL database connection that should happen via SSL?
     if (strcasecmp($databaseType, 'mysql') === 0 && @$aDriverOptions['ssl']) {
         // Modify the DSN string to include the required CA and CAPATH options
         if (!empty($aDriverOptions['ca']) && !empty($aDriverOptions['capath'])) {
             $dsn .= "?ca={$aDriverOptions['ca']}&capth={$aDriverOptions['capath']}";
         }
     }
     // Create an MD5 checksum of the DSN
     $dsnMd5 = md5($dsn);
     // Does this database connection already exist?
     if (isset($GLOBALS['_OA']['CONNECTIONS'])) {
         $aConnections = array_keys($GLOBALS['_OA']['CONNECTIONS']);
     } else {
         $aConnections = array();
     }
     if (!(count($aConnections) > 0) || !in_array($dsnMd5, $aConnections)) {
         // Prepare options for a new database connection
         $aOptions = array();
         // Sequence column name
         $aOptions['seqcol_name'] = 'id';
         // Set the index name format
         $aOptions['idxname_format'] = '%s';
         // Use 4 decimal places in DECIMAL nativetypes
         $aOptions['decimal_places'] = 4;
         // Set the portability options
         $aOptions['portability'] = OA_DB_MDB2_DEFAULT_OPTIONS;
         // Set the default table type for MySQL, if appropriate
         if (strcasecmp($databaseType, 'mysql') === 0) {
             if (!empty($aConf['table']['type'])) {
                 $aOptions['default_table_type'] = $aConf['table']['type'];
                 // Enable transaction support when using InnoDB tables
                 if (strcasecmp($aOptions['default_table_type'], 'innodb') === 0) {
                     // Enable transaction support
                     $aOptions['use_transactions'] = true;
                 }
             }
         } elseif (strcasecmp($databaseType, 'pgsql') === 0) {
             $aOptions['quote_identifier'] = true;
         }
         // Add default charset - custom OpenX
         if (defined('OA_DB_MDB2_DEFAULT_CHARSET')) {
             $aOptions['default_charset'] = OA_DB_MDB2_DEFAULT_CHARSET;
         } else {
             $aOptions['default_charset'] = 'utf8';
         }
         // this will log select queries to a var/sql.log
         // currently used for analysis purposes
         if (isset($aConf['debug']['logSQL']) && $aConf['debug']['logSQL']) {
             $aOptions['log_statements'] = explode('|', $aConf['debug']['logSQL']);
             $aOptions['debug'] = true;
             $aOptions['debug_handler'] = 'logSQL';
         }
         $aOptions += OA_DB::getDatatypeMapOptions();
         // Is this a MySQL database connection?
         if (strcasecmp($databaseType, 'mysql') === 0) {
             // Should this connection happen over SSL?
             if (@$aDriverOptions['ssl']) {
                 $aOptions['ssl'] = true;
             }
         }
         // Create the new database connection
         OA::disableErrorHandling();
         $oDbh = MDB2::singleton($dsn, $aOptions);
         OA::enableErrorHandling();
         if (PEAR::isError($oDbh)) {
             return $oDbh;
         }
         // Is this a MySQL database connection?
         if (strcasecmp($databaseType, 'mysql') === 0) {
             $client_flags = 0;
             // Should this connection happen over SSL?
             if (@$aDriverOptions['ssl']) {
                 $client_flags = $client_flags | MYSQL_CLIENT_SSL;
             }
             // Should this connection use compression?
             if (@$aDriverOptions['compress']) {
                 $client_flags = $client_flags | MYSQL_CLIENT_COMPRESS;
             }
             // Are there any MySQL connection flags to set?
             if ($client_flags != 0) {
                 $oDbh->dsn['client_flags'] = $client_flags;
             }
         }
         OA::disableErrorHandling();
         $success = $oDbh->connect();
         OA::enableErrorHandling();
         if (PEAR::isError($success)) {
             return $success;
         }
         // Set charset if needed
         $success = OA_DB::setCharset($oDbh);
         if (PEAR::isError($success)) {
             return $success;
         }
         // Set schema if needed
         $success = OA_DB::setSchema($oDbh);
         if (PEAR::isError($success)) {
             return $success;
         }
         // Set the fetchmode to be use used
         $oDbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
         // Load modules that are likely to be needed
         $oDbh->loadModule('Extended');
         $oDbh->loadModule('Datatype');
         $oDbh->loadModule('Manager');
         // Store the database connection
         $GLOBALS['_OA']['CONNECTIONS'][$dsnMd5] = $oDbh;
         // Set MySQL 4 compatibility if needed
         if (strcasecmp($databaseType, 'mysql') === 0 && !empty($aConf['database']['mysql4_compatibility'])) {
             $oDbh->exec("SET SESSION sql_mode='MYSQL40'");
         }
     }
     return $GLOBALS['_OA']['CONNECTIONS'][$dsnMd5];
 }
コード例 #5
0
ファイル: MaxTest.php プロジェクト: vituhugo/webservice
 /**
  * @dataProvider providerForInvalidMax
  * @expectedException Respect\Validation\Exceptions\MaxException
  */
 public function test_invalid_max_value_should_throw_MaxException($maxValue, $inclusive, $input)
 {
     $max = new Max($maxValue, $inclusive);
     $this->assertFalse($max->validate($input));
     $this->assertFalse($max->assert($input));
 }
コード例 #6
0
 /**
  * Send the password recovery email
  *
  * @todo Set email language according to the account preferences
  *
  * @param string email address
  * @return int Number of emails sent
  */
 function sendRecoveryEmail($email)
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aPref = $GLOBALS['_MAX']['PREF'];
     $aUsers = $this->_dal->searchMatchingUsers($email);
     $aEmails = array();
     foreach ($aUsers as $u) {
         $aEmails[$u['email_address']][] = $u;
     }
     $sent = 0;
     foreach ($aEmails as $email => $aUsers) {
         $text = '';
         foreach ($aUsers as $u) {
             $recoveryId = $this->_dal->generateRecoveryId($u['user_id']);
             $header = $GLOBALS['strUser'] . " {$u['contact_name']}";
             $text .= $header . "\n" . str_repeat('-', strlen($header)) . "\n";
             $text .= $GLOBALS['strUsername'] . ": {$u['username']}\n";
             $text .= $GLOBALS['strPwdRecResetLink'] . ": ";
             $text .= Max::constructURL(MAX_URL_ADMIN, "password-recovery.php?id={$recoveryId}") . "\n\n";
         }
         // Hack
         $aConf['email']['admin_name'] = $aPref['admin_fullname'];
         $aConf['email']['admin'] = $aPref['admin_email'];
         $oEmail = new OA_Email();
         $oEmail->sendMail(sprintf($GLOBALS['strPwdRecEmailPwdRecovery'], $aPref['name']), $text, $email, $u['username']);
         $sent++;
     }
     return $sent;
 }
コード例 #7
0
ファイル: M2M.php プロジェクト: villos/tree_admin
 /**
  * Class constructor
  *
  * @param string $accountId If null, the current account ID is used
  * @param string $accountType If null, the current account type is used
  * @return OA_Central_M2M
  */
 function OA_Central_M2M($accountId = null)
 {
     parent::OA_Central_Common();
     $currentId = OA_Permission::getAccountId();
     if (is_null($accountId)) {
         $this->accountId = $currentId;
     } else {
         $this->accountId = $accountId;
     }
     if ($this->accountId == $currentId) {
         $this->accountType = OA_Permission::getAccountType();
     } else {
         $doAccounts = OA_Dal::factoryDO('accounts');
         $doAccounts->account_id = $this->accountId;
         $doAccounts->find();
         if ($doAccounts->fetch()) {
             $this->accountType = $doAccounts->account_type;
         } else {
             Max::raiseError('Unexisting account ID', null, PEAR_ERROR_DIE);
         }
     }
     if ($this->accountType == OA_ACCOUNT_ADMIN) {
         $this->accountId = 0;
     }
 }
コード例 #8
0
 /**
  * Get scalar values from parameters
  *
  * @access public
  *
  * @param array $aReferencesOnVariables array of references to variables
  * @param array $aRequired array of boolean values to indicate which field is required
  * @param XML_RPC_Message  $oParams
  * @param XML_RPC_Response &$oResponseWithError
  * @param integer $idxStart Index of parameter from which values start
  *
  * @return boolean  shows true if method was executed successfully
  */
 function getScalarValues($aReferencesOnVariables, $aRequired, &$oParams, &$oResponseWithError, $idxStart = 0)
 {
     if (count($aReferencesOnVariables) != count($aRequired)) {
         Max::raiseError('$aReferencesOnVariables & $aRequired arrays should have the same length');
         exit;
     }
     $cVariables = count($aReferencesOnVariables);
     for ($i = 0; $i < $cVariables; $i++) {
         if ($aRequired[$i]) {
             if (!XmlRpcUtils::getRequiredScalarValue($aReferencesOnVariables[$i], $oParams, $i + $idxStart, $oResponseWithError)) {
                 return false;
             }
         } else {
             if (!XmlRpcUtils::_getNotRequiredScalarValue($aReferencesOnVariables[$i], $oParams, $i + $idxStart, $oResponseWithError)) {
                 return false;
             }
         }
     }
     return true;
 }
コード例 #9
0
 /**
  * A method to check if the user has specific permissions to perform
  * an action on an account
  *
  * TODOPERM - consider caching permissions in user session so they could
  *            be reused across many user requests
  *
  * @static
  * @param integer $permissionId
  * @param int $accountId
  * @return boolean
  */
 public static function hasPermission($permissionId, $accountId = null, $userId = null)
 {
     if (empty($userId)) {
         $userId = self::getUserId();
     }
     if (self::isUserLinkedToAdmin($userId)) {
         return true;
     }
     static $aCache = array();
     if (empty($accountId)) {
         $accountId = self::getAccountId();
         $accountType = self::getAccountType();
     } else {
         $oAccounts = OA_Dal::staticGetDO('accounts', $accountId);
         if ($oAccounts) {
             $accountType = $oAccounts->accountType;
         } else {
             // Account does not exist
             Max::raiseError('No such account ID: ' . $accountId);
             return false;
         }
     }
     if (self::isPermissionRelatedToAccountType($accountType, $permissionId)) {
         $aCache[$userId][$accountId] = self::getAccountUsersPermissions($userId, $accountId);
     } else {
         $aCache[$userId][$accountId][$permissionId] = true;
     }
     return isset($aCache[$userId][$accountId][$permissionId]) ? $aCache[$userId][$accountId][$permissionId] : false;
 }
コード例 #10
0
 /**
  * Performs a batch insert
  *
  * @see OA_Dal::batchInsert()
  *
  * @param string $tableNameUnquoted The unquoted table name (including prefix, see _getTablenameUnquoted)
  * @param array  $data              The array of data to be inserted
  * @param array  $fields            The array of unquoted field names
  */
 function batchInsert($tableNameUnquoted, $data, $fields)
 {
     $result = OA_Dal::batchInsert($tableNameUnquoted, $fields, $data);
     if (PEAR::isError($result)) {
         Max::raiseError($result->getMessage(), PEAR_ERROR_DIE);
     }
     OA::debug('Inserted ' . $result . ' rows in the table ' . $tableNameUnquoted, PEAR_LOG_INFO);
 }
コード例 #11
0
ファイル: MaxTest.php プロジェクト: gawonmi/Validation
 /**
  * @dataProvider providerForInvalidMax
  * @expectedException Respect\Validation\Exceptions\MaxException
  */
 public function testInvalidMaxValueShouldThrowMaxException($maxValue, $inclusive, $input)
 {
     $max = new Max($maxValue, $inclusive);
     $this->assertFalse($max->validate($input));
     $this->assertFalse($max->assert($input));
 }