Example #1
1
 /**
  * Constructor for MBC_Mailchimp
  *
  * @param array $apiKey
  *   The MailChimp API key to use for this instance of MailChip API activities.
  */
 public function __construct($apiKey)
 {
     $this->mailChimp = new MailChimp($apiKey);
     $this->mbConfig = MB_Configuration::getInstance();
     $this->statHat = $this->mbConfig->getProperty('statHat');
 }
 /**
  * Constructor for MB_Toolbox_BaseConsumer - all consumer applications should extend this base class.
  */
 public function __construct($targetMBconfig = 'messageBroker')
 {
     $this->mbConfig = MB_Configuration::getInstance();
     $this->messageBroker = $this->mbConfig->getProperty($targetMBconfig);
     $this->statHat = $this->mbConfig->getProperty('statHat');
     $this->startTime = date('c');
 }
 /**
  * __construct: When a new instance of the class is created it must include an email address. An
  * email address is the minimum value needed to work with Digest User related functionality.
  *
  * @parm string $email (required)
  * 
  * @return boolean
  */
 public function __construct($email)
 {
     // Validate structure and existing TLD (top level domain) for address
     if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $this->email = $email;
     } else {
         return FALSE;
     }
     $this->mbConfig = MB_Configuration::getInstance();
     $this->statHat = $this->mbConfig->getProperty('statHat');
     $this->mbToolbox = $this->mbConfig->getProperty('mbToolbox');
 }
 public function __construct()
 {
     // Application configuration
     $this->mbConfig = MB_Configuration::getInstance();
     $this->messageBroker = $this->mbConfig->getProperty('messageBroker');
     $this->statHat = $this->mbConfig->getProperty('statHat');
     $this->mbToolbox = $this->mbConfig->getProperty('mbToolbox');
     $this->mandrill = $this->mbConfig->getProperty('mandrill');
     // Resources for building digest batch
     $this->userIndex = 0;
     $this->campaignTempate = parent::getTemplate('campaign-markup.inc');
     $this->campaignTempateDivider = parent::getTemplate('campaign-divider-markup.inc');
     $this->setGlobalMergeVars();
 }
 /**
  * Constructor for MB_RabbitMQManagementAPI
  *
  * @param array $config
  *   Configuration settings from mb-config.inc
  */
 public function __construct($conig)
 {
     $domain = 'http://' . $conig['domain'];
     $port = $conig['port'];
     $vhost = $conig['vhost'];
     $this->vhost = $vhost;
     $username = $conig['username'];
     $password = $conig['password'];
     if ($port > 0 && is_numeric($port)) {
         $domain .= ':' . (int) $port;
     }
     $this->rabbitManagement = new RabbitMqManagementApi(null, $domain, $username, $password);
     $this->mbConfig = MB_Configuration::getInstance();
     $this->statHat = $this->mbConfig->getProperty('statHat');
 }
Example #6
0
 /**
  * Test the display() function
  *
  * @return  void
  */
 public function testDisplay()
 {
     // Setup
     $content = 'anything';
     // Test display() with all null params
     $this->handler = new RDFa();
     $this->assertEquals($this->handler->display(), '');
     // Test if the params are reseted after the display() function
     $this->handler->setType('Article')->content($content)->property('name')->fallback('Thing', 'url')->display();
     $this->assertNull($this->handler->getFallbackProperty());
     $this->assertNull($this->handler->getFallbackType());
     $this->assertNull($this->handler->getProperty());
     $this->assertNull($this->handler->getContent());
     // Test for a simple display
     $response = $this->handler->property('url')->display();
     $this->assertEquals($response, "property='url'");
     // Test for a simple display with $content
     $response = $this->handler->property('url')->content($content)->display();
     $this->assertEquals($response, "<span property='url'>{$content}</span>");
     // Test for a simple display if the $content is empty ''
     $response = $this->handler->enable(true)->content('')->property('name')->display();
     $this->assertEquals($response, "<span property='name'></span>");
     // Test for a simple 'nested' display
     $response = $this->handler->property('author')->display();
     $this->assertEquals($response, "property='author' vocab='https://schema.org' typeof='Organization'");
     // Test for a 'nested' display with $content
     $response = $this->handler->property('author')->content($content)->display();
     $this->assertEquals($response, "<span property='author' vocab='https://schema.org' typeof='Organization'>{$content}</span>");
     // Test for a 'nested' display with $content and $Fallback
     $response = $this->handler->fallback('Person', 'name')->property('author')->content($content)->display();
     $this->assertEquals($response, "<span property='author' vocab='https://schema.org' typeof='Person'><span property='name'>{$content}</span></span>");
     // Test for a 'nested' display with $Fallback and without $content
     $response = $this->handler->fallback('Person', 'name')->property('author')->display();
     $this->assertEquals($response, "property='author' vocab='https://schema.org' typeof='Person' property='name'");
     // Test for a 'meta' display without $content
     $response = $this->handler->property('datePublished')->display();
     $this->assertEquals($response, "property='datePublished'");
     // Test for a 'meta' display with $content
     $content = '01 January 2011';
     $response = $this->handler->property('datePublished')->content($content)->display();
     $this->assertEquals($response, "<meta property='datePublished' content='{$content}'/>{$content}");
     // Test for a 'meta' display with human $content and $machineContent
     $machineContent = "2011-01-01T00:00:00+00:00";
     $response = $this->handler->property('datePublished')->content($content, $machineContent)->display();
     $this->assertEquals($response, "<meta property='datePublished' content='{$machineContent}'/>{$content}");
     // Test when if fallbacks that the library returns an empty string as specified
     $response = $this->handler->content('en-GB')->property('doesNotExist')->display('meta', true);
     $this->assertEquals($response, '');
     // Test if the library is disabled
     $response = $this->handler->enable(false)->content($content)->fallback('Article', 'about')->property('datePublished')->display();
     $this->assertEquals($response, $content);
     // Test if the library is disabled and if it have a $content it must return an empty string
     $response = $this->handler->enable(false)->content('en-GB')->property('inLanguage')->fallback('Language', 'name')->display('meta', true);
     $this->assertEquals($response, '');
     // Test if the params are reseted after display(), if the library is disabled
     $this->assertNull($this->handler->getFallbackProperty());
     $this->assertNull($this->handler->getFallbackType());
     $this->assertNull($this->handler->getProperty());
     $this->assertNull($this->handler->getContent());
 }
Example #7
0
 /**
  * Cria uma instrução SQL de deleção no banco
  * @param	Model	$model		model a ser deletado
  * @throws	DatabaseException	disparada caso o model seja uma nova instância, ou não tenha a anotação Entity
  * @return	void
  */
 public function delete(Model $model)
 {
     $conditions = array();
     if (get_class($model) != $this->clazz) {
         throw new DatabaseException("O objeto deve ser do tipo '" . $this->clazz . "'");
     }
     $class = $this->annotation->getClass();
     if (!$class->Entity) {
         throw new DatabaseException('A classe ' . get_class($model) . ' não é uma entidade');
     }
     if ($model->_isNew()) {
         throw new DatabaseException('O método delete não pode ser utilizado com uma nova instância de ' . $this->clazz);
     }
     foreach ($model as $field => $value) {
         $property = $this->annotation->getProperty($field);
         if ($this->isField($property) && $this->isKey($property)) {
             $conditions['fields'][] = '`' . $field . '` = ?';
             $conditions['values'][] = $value;
         }
     }
     $entity = $class->Entity ? $class->Entity : get_class($model);
     $sql = 'DELETE FROM `' . $entity . '` WHERE ' . implode(' AND ', $conditions['fields']) . ';';
     Debug::addSql($sql, $conditions['values']);
     $this->operations[] = array('sql' => $sql, 'values' => $conditions['values']);
 }
Example #8
0
 /**
  * Test the display() function
  *
  * @return  void
  *
  * @since   3.2
  */
 public function testDisplay()
 {
     // Setup
     $content = 'anything';
     // Test display() with all null params
     $this->handler = new JMicrodata();
     $this->assertEquals($this->handler->display(), '');
     // Test if the params are reseted after display()
     $this->handler->setType('Article')->content($content)->property('name')->fallback('Thing', 'url')->display();
     $this->assertNull($this->handler->getFallbackProperty());
     $this->assertNull($this->handler->getFallbackType());
     $this->assertNull($this->handler->getProperty());
     $this->assertEmpty($this->handler->getContent());
     // Test for a simple display
     $responce = $this->handler->property('url')->display();
     $this->assertEquals($responce, "itemprop='url'");
     // Test for a simple display with content
     $responce = $this->handler->property('url')->content($content)->display();
     $this->assertEquals($responce, "<span itemprop='url'>{$content}</span>");
     // Test for a simple display if the content is empty ''
     $responce = $this->handler->enable(true)->content('')->property('name')->display();
     $this->assertEquals($responce, "<span itemprop='name'></span>");
     // Test for a simple nested display
     $responce = $this->handler->property('author')->display();
     $this->assertEquals($responce, "itemprop='author' itemscope itemtype='https://schema.org/Organization'");
     // Test for a nested display with content
     $responce = $this->handler->property('author')->content($content)->display();
     $this->assertEquals($responce, "<span itemprop='author' itemscope itemtype='https://schema.org/Organization'>{$content}</span>");
     // Test for a nested display with content and Fallback
     $responce = $this->handler->fallback('Person', 'name')->property('author')->content($content)->display();
     $this->assertEquals($responce, "<span itemprop='author' itemscope itemtype='https://schema.org/Person'><span itemprop='name'>{$content}</span></span>");
     // Test for a nested display with Fallback and without content
     $responce = $this->handler->fallback('Person', 'name')->property('author')->display();
     $this->assertEquals($responce, "itemprop='author' itemscope itemtype='https://schema.org/Person' itemprop='name'");
     // Test for a meta display without content
     $responce = $this->handler->property('datePublished')->display();
     $this->assertEquals($responce, "itemprop='datePublished'");
     // Test for a meta display with content
     $content = '01 January 2011';
     $responce = $this->handler->property('datePublished')->content($content)->display();
     $this->assertEquals($responce, "<meta itemprop='datePublished' content='{$content}'/>{$content}");
     // Test if the JMicrodata is disabled
     $responce = $this->handler->enable(false)->content($content)->fallback('Article', 'about')->property('datePublished')->display();
     $this->assertEquals($responce, $content);
     // Test if JMicrodata is disabled and have a $content it must return an empty string
     $responce = $this->handler->enable(false)->content('en-GB')->property('inLanguage')->fallback('Language', 'name')->display('meta', true);
     $this->assertEquals($responce, '');
     // Test if the params are reseted after display(), if the library is disabled
     $this->assertNull($this->handler->getFallbackProperty());
     $this->assertNull($this->handler->getFallbackType());
     $this->assertNull($this->handler->getProperty());
     $this->assertNull($this->handler->getContent());
 }
Example #9
0
 public function parserProperties()
 {
     if (!$this->reflector) {
         return $this;
     }
     foreach ($this->reflector->getProperties() as $obj) {
         $p = $this->reflector->getProperty($obj->name);
         $p->setAccessible(true);
         $this->properties[$this->prefixProperty . $obj->name] = $p->getValue();
     }
     return $this;
 }
Example #10
0
 /**
  * Load defaults needed by service
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string
  * @return void
  */
 public function load()
 {
     $this->name = "KTLuceneTest";
     $this->javaSystem = new Java('java.lang.System');
     $this->setJavaBin($this->javaSystem->getProperty('java.home') . DS . "bin");
     $this->setLuceneDIR(SYSTEM_DIR . "bin" . DS . "luceneserver");
     $this->setLuceneExe("KTLuceneService.exe");
     $this->setJavaJVM();
     $this->setLuceneSource("ktlucene.jar");
     $this->setLuceneServer("com.knowledgetree.lucene.KTLuceneServer");
     $this->setLuceneOut("lucene-out.txt");
     $this->setLuceneError("lucene-err.txt");
 }
Example #11
0
	/**
	 * Creates a table in the image of the property definitions supplied to it.
	 *
	 * @param string $tableName What the table will be called.
	 * @param array $propertyDefinitions The structure of the table.
	 * 
	 * @todo Need to make this use the query class.
	 */
	private static function createTable ($tableName, $propertyDefinitions)
	{
		$query .= " CREATE TABLE `" . metaclass::$db->getProperty('database') . "`.`$tableName` (\n";
		$query .= " `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n";
		foreach ($propertyDefinitions as $k => $v)
		{
			$vars = metaclass::getClassVars($v['type'], 'datatypes');
			$querylines[] .= "`$k` " . (janitor::notNull($vars['fieldtype']) ? $vars['fieldtype'] : 'VARCHAR( 255 )') .
					 " NOT NULL ";
		}
		$query .= implode(",\n", $querylines);
		$query .= ")";
		metaclass::$db->query($query);
		metaclass::$tablesLoaded[] = $tableName;
	}
 /**
  * Constructor for MBC_BaseConsumer - all consumer applications should extend this base class.
  *
  * @param string $targetMBconfig The Message Broker object used to interface the RabbitMQ server
  *                               exchanges and related queues.
  */
 public function __construct($targetMBconfig = 'messageBroker')
 {
     $this->mbConfig = MB_Configuration::getInstance();
     $this->settings = $this->mbConfig->getProperty('generalSettings');
     $this->messageBroker = $this->mbConfig->getProperty($targetMBconfig);
     $this->messageBroker_deadLetter = $this->mbConfig->getProperty('messageBroker_deadLetter');
     $this->statHat = $this->mbConfig->getProperty('statHat');
     $this->mbRabbitMQManagementAPI = $this->mbConfig->getProperty('mbRabbitMQManagementAPI');
     $connection = $this->messageBroker->connection;
     $this->channel = $connection->channel();
 }
Example #13
0
 /**
  * Generate user specific link URL to user subscription setting
  * (http://subscriptions.dosomething.org) web page. The page is an interface
  * to allow users to subscribe/unsubscribe to different types of email
  * messaging.
  *
  * @param string $targetEmail
  *   The email address to generate the subscription URL for.
  * @param integer $drupalNID
  *   Supplying the related Drupal NID incomplination with the $targetEmail will
  *   result in an unsubscription link generation that will not require a call
  *   to the Drupal app to lookup the NID by email. This is important because the
  *   valume for this call that the Drupal app will process is very limited (maxes
  *   at 200 calls per session key).
  *
  * @return string $subscription_link
  *   The URL to the user subscription settings web page. The link includes a
  *   key md5 hash value to limit page access to authorized users who have
  *   received an email from the lists the subscription page administers.
  */
 public function subscriptionsLinkGenerator($targetEmail, $drupalUID = null)
 {
     $subscriptionLink = '';
     $dsDrupalAPIConfig = $this->mbConfig->getProperty('ds_drupal_api_config');
     $curlUrl = $dsDrupalAPIConfig['host'];
     $port = $dsDrupalAPIConfig['port'];
     if ($port != 0 && is_numeric($port)) {
         $curlUrl .= ':' . (int) $port;
     }
     // Gather Drupal NID
     if ($drupalUID == null) {
         $curlUrl .= self::DRUPAL_API . '/users.json?parameters[email]=' . urlencode($targetEmail);
         $result = $this->mbToolboxcURL->curlGETauth($curlUrl);
         if (isset($result[0][0]->uid)) {
             $drupalUID = (int) $result[0][0]->uid;
         } elseif ($result[1] == 200) {
             echo '- ERROR - Drupal user not found by email: ' . $targetEmail, PHP_EOL;
             $subscriptionLink = 'ERROR - Drupal user not found by email.';
             $this->statHat->ezCount('MB_Toolbox: subscriptionsLinkGenerator - ERROR - Drupal user not found by email');
         } else {
             echo 'Error making curlGETauth request to ' . $curlUrl, PHP_EOL;
             echo 'Returned results: ' . print_r($result, true), PHP_EOL;
             $subscriptionLink = false;
             $this->statHat->ezCount('MB_Toolbox: subscriptionsLinkGenerator - ERROR - curlGETauth call failed');
         }
     }
     // Generate link
     if ($drupalUID > 0) {
         // Build Subscription link path
         $subscriptions = $this->mbConfig->getProperty('subscriptions_config');
         if (strlen($subscriptions['host']) > 0) {
             $subscriptionsUrl = $subscriptions['host'];
         } else {
             $subscriptionsUrl = $subscriptions['ip'];
         }
         $port = $subscriptions['port'];
         if ($port > 0 && is_numeric($port)) {
             $subscriptionsUrl .= ':' . (int) $port;
         }
         $keyData = urlencode($targetEmail) . ', ' . $drupalUID . ', ' . date('Y-m-d');
         $subscriptionLink = $subscriptionsUrl . '?targetEmail=' . urlencode($targetEmail) . '&key=' . md5($keyData);
         $this->statHat->ezCount('MB_Toolbox: subscriptionsLinkGenerator - Success');
     }
     return $subscriptionLink;
 }
Example #14
0
 /**
  * Set Java Directory path
  *
  * @author KnowledgeTree Team
  * @access private
  * @param string
  * @return void
  */
 private function setJavaBin()
 {
     if ($this->util->zendBridge()) {
         if ($this->util->javaBridge()) {
             $this->javaSystem = new Java('java.lang.System');
             $this->javaBin = $this->javaSystem->getProperty('java.home') . DS . "bin";
             return true;
         }
     }
     // TODO: Will not detect, but a java pre-check is done in services, before this
     if (file_exists($this->varDir . 'outJVHome')) {
         $this->javaBin = file_get_contents($this->varDir . 'outJVHome');
         if ($this->javaBin != '') {
             return true;
         }
     }
     return false;
 }
 /**
  * Gather campaign properties based on the campaign lookup on the Drupal site.
  *
  * @param integer $nid
  *   The Drupal nid (node ID) of the target campaign.
  *
  * @return object
  *   The returned results from the call to the campaign endpoint on the Drupal site.
  *   Return boolean FALSE if request is unsuccessful.
  */
 private function gatherSettings($nid)
 {
     $dsDrupalAPIConfig = $this->mbConfig->getProperty('ds_drupal_api_config');
     $curlUrl = $dsDrupalAPIConfig['host'];
     $port = isset($dsDrupalAPIConfig['port']) ? $dsDrupalAPIConfig['port'] : NULL;
     if ($port != 0 && is_numeric($port)) {
         $curlUrl .= ':' . (int) $port;
     }
     $campaignAPIUrl = $curlUrl . '/api/v1/content/' . $nid;
     $result = $this->mbToolboxcURL->curlGET($campaignAPIUrl);
     // Exclude campaigns that don't have details in Drupal API or "Access
     // denied" due to campaign no longer published
     if ($result[1] == 200 && is_object($result[0])) {
         return $result[0];
     } elseif ($result[1] == 200 && is_array($result[0])) {
         throw new Exception('Call to ' . $campaignAPIUrl . ' returned  200 with rejected response. nid: ' . $nid);
     } elseif ($result[1] == 403) {
         throw new Exception('Call to ' . $campaignAPIUrl . ' returned 403 and rejected response: ' . $result[0][0] . ' . nid: ' . $nid);
     } else {
         throw new Exception('Unable to call ' . $campaignAPIUrl . ' to get Campaign object: ' . $nid);
     }
 }
 /**
  * Authenticate for Drupal API access
  */
 private function authenticate()
 {
     $dsDrupalAPIConfig = $this->mbConfig->getProperty('ds_drupal_api_config');
     if (!empty($dsDrupalAPIConfig['username']) && !empty($dsDrupalAPIConfig['password'])) {
         $post = ['username' => $dsDrupalAPIConfig['username'], 'password' => $dsDrupalAPIConfig['password']];
     } else {
         trigger_error("MB_Toolbox->authenticate() : username and/or password not defined.", E_USER_ERROR);
         exit(0);
     }
     // https://www.dosomething.org/api/v1/auth/login
     $curlUrl = $this->buildcURL($dsDrupalAPIConfig);
     $curlUrl .= self::DRUPAL_API . '/auth/login';
     $auth = $this->curlPOST($curlUrl, $post);
     if ($auth[1] == 200) {
         $auth = $auth[0];
     } else {
         echo 'ERROR - Failed to get auth creds: ' . $curlUrl . ' with POST: ' . print_r($post, true), PHP_EOL;
         $auth = false;
     }
     $this->auth = $auth;
     $this->statHat->ezCount('MB_Toolbox: MB_Toolbox_cURL: authenticate', 1);
 }
Example #17
0
 protected function generateMessage($attribute, $type, array $options = [])
 {
     if ($attribute == self::BASE_ERRORS_INDEX) {
         $properAttr = 'base';
     } else {
         $properAttr = $attribute;
     }
     if (method_exists($this->model, 'i18nScope')) {
         $i18nKey = $this->getI18nKey();
         $defaults = [$this->model->i18nScope() . '.errors.models.' . $i18nKey . '.attributes.' . $properAttr . '.' . $type, $this->model->i18nScope() . '.errors.models.' . $i18nKey . '.' . $type];
     } else {
         $defaults = [];
     }
     $defaults = array_merge($defaults, ['errors.attributes.' . $properAttr . '.' . $type, 'errors.messages.' . $type]);
     $key = array_shift($defaults);
     $value = $attribute != self::BASE_ERRORS_INDEX ? $this->model->getProperty($attribute) : null;
     $infl = self::services()->get('inflector');
     $model = $this->model;
     $options = array_merge(['default' => $defaults, 'model' => $infl->humanize($infl->underscore(get_class($this->model))), 'attribute' => $model::humanAttributeName($properAttr), 'value' => $value], $options);
     $message = self::services()->get('i18n')->translate($key, $options);
     return $message;
 }
Example #18
0
 /**
  * Updates the properties of the containers from the original source.
  *
  * @param bool if the auth container should be updated
  * @param bool if the perm container should be updated
  * @return bool true on success and false on failure
  *
  * @access public
  */
 function updateProperty($auth, $perm = null, $accountId = 0)
 {
     if (!is_a($this->_auth, 'LiveUser_Auth_Common')) {
         $this->stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no auth container instance is available');
         return false;
     }
     if ($auth && !$this->_auth->readUserData(null, null, $this->_auth->getProperty('auth_user_id'), $accountId)) {
         return false;
     }
     if (is_null($perm)) {
         $perm = is_a($this->_perm, 'LiveUser_Perm_Simple');
     }
     if ($perm) {
         if (!is_a($this->_perm, 'LiveUser_Perm_Simple')) {
             $this->stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no perm container instance is available');
             return false;
         }
         if (!$this->_perm->mapUser($this->_auth->getProperty('auth_user_id'), $this->_auth->containerName)) {
             return false;
         }
     }
     $this->_freeze();
     return true;
 }
Example #19
0
/**
 * Returns an array containing time zone data from vtimezone standard/daylight instances
 *
 * @param object $vtzc   an iCalcreator calendar standard/daylight instance
 * @return array         time zone data; array before(offsetHis, offsetSec), array after(offsetHis, offsetSec, tzname)
 *
 */
function expandTimezoneDates($vtzc)
{
    $tzdates = array();
    // prepare time zone "description" to attach to each change
    $tzbefore = array();
    $tzbefore['offsetHis'] = $vtzc->getProperty('tzoffsetfrom');
    $tzbefore['offsetSec'] = iCalUtilityFunctions::_tz2offset($tzbefore['offsetHis']);
    if ('-' != substr((string) $tzbefore['offsetSec'], 0, 1) && '+' != substr((string) $tzbefore['offsetSec'], 0, 1)) {
        $tzbefore['offsetSec'] = '+' . $tzbefore['offsetSec'];
    }
    $tzafter = array();
    $tzafter['offsetHis'] = $vtzc->getProperty('tzoffsetto');
    $tzafter['offsetSec'] = iCalUtilityFunctions::_tz2offset($tzafter['offsetHis']);
    if ('-' != substr((string) $tzafter['offsetSec'], 0, 1) && '+' != substr((string) $tzafter['offsetSec'], 0, 1)) {
        $tzafter['offsetSec'] = '+' . $tzafter['offsetSec'];
    }
    if (FALSE === ($tzafter['tzname'] = $vtzc->getProperty('tzname'))) {
        $tzafter['tzname'] = $tzafter['offsetHis'];
    }
    // find out where to start from
    $dtstart = $vtzc->getProperty('dtstart');
    $dtstarttimestamp = mktime($dtstart['hour'], $dtstart['min'], $dtstart['sec'], $dtstart['month'], $dtstart['day'], $dtstart['year']);
    if (!isset($dtstart['unparsedtext'])) {
        // ??
        $dtstart['unparsedtext'] = sprintf('%04d%02d%02dT%02d%02d%02d', $dtstart['year'], $dtstart['month'], $dtstart['day'], $dtstart['hour'], $dtstart['min'], $dtstart['sec']);
    }
    if ($dtstarttimestamp == 0) {
        // it seems that the dtstart string may not have parsed correctly
        // let's set a timestamp starting from 1902, using the time part of the original string
        // so that the time will change at the right time of day
        // at worst we'll get midnight again
        $origdtstartsplit = explode('T', $dtstart['unparsedtext']);
        $dtstarttimestamp = strtotime("19020101", 0);
        $dtstarttimestamp = strtotime($origdtstartsplit[1], $dtstarttimestamp);
    }
    // the date (in dtstart and opt RDATE/RRULE) is ALWAYS LOCAL (not utc!!), adjust from 'utc' to 'local' timestamp
    $diff = -1 * $tzbefore['offsetSec'];
    $dtstarttimestamp += $diff;
    // add this (start) change to the array of changes
    $tzdates[] = array('timestamp' => $dtstarttimestamp, 'tzbefore' => $tzbefore, 'tzafter' => $tzafter);
    $datearray = getdate($dtstarttimestamp);
    // save original array to use time parts, because strtotime (used below) apparently loses the time
    $changetime = $datearray;
    // generate dates according to an RRULE line
    $rrule = $vtzc->getProperty('rrule');
    if (is_array($rrule)) {
        if ($rrule['FREQ'] == 'YEARLY') {
            // calculate transition dates starting from DTSTART
            $offsetchangetimestamp = $dtstarttimestamp;
            // calculate transition dates until 10 years in the future
            $stoptimestamp = strtotime("+10 year", time());
            // if UNTIL is set, calculate until then (however far ahead)
            if (isset($rrule['UNTIL']) && $rrule['UNTIL'] != '') {
                $stoptimestamp = mktime($rrule['UNTIL']['hour'], $rrule['UNTIL']['min'], $rrule['UNTIL']['sec'], $rrule['UNTIL']['month'], $rrule['UNTIL']['day'], $rrule['UNTIL']['year']);
            }
            $count = 0;
            $stopcount = isset($rrule['COUNT']) ? $rrule['COUNT'] : 0;
            $daynames = array('SU' => 'Sunday', 'MO' => 'Monday', 'TU' => 'Tuesday', 'WE' => 'Wednesday', 'TH' => 'Thursday', 'FR' => 'Friday', 'SA' => 'Saturday');
            // repeat so long as we're between DTSTART and UNTIL, or we haven't prepared COUNT dates
            while ($offsetchangetimestamp < $stoptimestamp && ($stopcount == 0 || $count < $stopcount)) {
                // break up the timestamp into its parts
                $datearray = getdate($offsetchangetimestamp);
                if (isset($rrule['BYMONTH']) && $rrule['BYMONTH'] != 0) {
                    // set the month
                    $datearray['mon'] = $rrule['BYMONTH'];
                }
                if (isset($rrule['BYMONTHDAY']) && $rrule['BYMONTHDAY'] != 0) {
                    // set specific day of month
                    $datearray['mday'] = $rrule['BYMONTHDAY'];
                } elseif (is_array($rrule['BYDAY'])) {
                    // find the Xth WKDAY in the month
                    // the starting point for this process is the first of the month set above
                    $datearray['mday'] = 1;
                    // turn $datearray as it is now back into a timestamp
                    $offsetchangetimestamp = mktime($datearray['hours'], $datearray['minutes'], $datearray['seconds'], $datearray['mon'], $datearray['mday'], $datearray['year']);
                    if ($rrule['BYDAY'][0] > 0) {
                        // to find Xth WKDAY in month, we find last WKDAY in month before
                        // we do that by finding first WKDAY in this month and going back one week
                        // then we add X weeks (below)
                        $offsetchangetimestamp = strtotime($daynames[$rrule['BYDAY']['DAY']], $offsetchangetimestamp);
                        $offsetchangetimestamp = strtotime("-1 week", $offsetchangetimestamp);
                    } else {
                        // to find Xth WKDAY before the end of the month, we find the first WKDAY in the following month
                        // we do that by going forward one month and going to WKDAY there
                        // then we subtract X weeks (below)
                        $offsetchangetimestamp = strtotime("+1 month", $offsetchangetimestamp);
                        $offsetchangetimestamp = strtotime($daynames[$rrule['BYDAY']['DAY']], $offsetchangetimestamp);
                    }
                    // now move forward or back the appropriate number of weeks, into the month we want
                    $offsetchangetimestamp = strtotime($rrule['BYDAY'][0] . " week", $offsetchangetimestamp);
                    $datearray = getdate($offsetchangetimestamp);
                }
                // convert the date parts back into a timestamp, setting the time parts according to the
                // original time data which we stored
                $offsetchangetimestamp = mktime($changetime['hours'], $changetime['minutes'], $changetime['seconds'] + $diff, $datearray['mon'], $datearray['mday'], $datearray['year']);
                // add this change to the array of changes
                $tzdates[] = array('timestamp' => $offsetchangetimestamp, 'tzbefore' => $tzbefore, 'tzafter' => $tzafter);
                // update counters (timestamp and count)
                $offsetchangetimestamp = strtotime("+" . (isset($rrule['INTERVAL']) && $rrule['INTERVAL'] != 0 ? $rrule['INTERVAL'] : 1) . " year", $offsetchangetimestamp);
                $count += 1;
            }
        }
    }
    // generate dates according to RDATE lines
    while ($rdates = $vtzc->getProperty('rdate')) {
        if (is_array($rdates)) {
            foreach ($rdates as $rdate) {
                // convert the explicit change date to a timestamp
                $offsetchangetimestamp = mktime($rdate['hour'], $rdate['min'], $rdate['sec'] + $diff, $rdate['month'], $rdate['day'], $rdate['year']);
                // add this change to the array of changes
                $tzdates[] = array('timestamp' => $offsetchangetimestamp, 'tzbefore' => $tzbefore, 'tzafter' => $tzafter);
            }
        }
    }
    return $tzdates;
}
Example #20
0
 /**
  * add calendar component as subcomponent to container for subcomponents
  *
  * @author Kjell-Inge Gustafsson <*****@*****.**>
  * @since 2.4.13 - 2008-09-24
  * @param object $component calendar component
  * @param mixed $arg1 optional, ordno/component type/ component uid
  * @param mixed $arg2 optional, ordno if arg1 = component type
  * @return bool
  */
 function setComponent($component, $arg1 = FALSE, $arg2 = FALSE)
 {
     if (!isset($this->components)) {
         return FALSE;
     }
     if ('' >= $component->getConfig('language')) {
         $component->setConfig('language', $this->getConfig('language'));
     }
     $component->setConfig('allowEmpty', $this->getConfig('allowEmpty'));
     $component->setConfig('nl', $this->getConfig('nl'));
     $component->setConfig('unique_id', $this->getConfig('unique_id'));
     $component->setConfig('format', $this->getConfig('format'));
     if (!in_array($component->objName, array('valarm', 'vtimezone', 'standard', 'daylight'))) {
         unset($component->propix);
         /* make sure dtstamp and uid is set */
         $dummy = $component->getProperty('dtstamp');
         $dummy = $component->getProperty('uid');
     }
     if (!$arg1) {
         $this->components[] = $component->copy();
         return TRUE;
     }
     $argType = $index = null;
     if (ctype_digit((string) $arg1)) {
         $argType = 'INDEX';
         $index = (int) $arg1 - 1;
     } elseif (strlen($arg1) <= strlen('vfreebusy') && FALSE === strpos($arg1, '@')) {
         $argType = strtolower($arg1);
         $index = ctype_digit((string) $arg2) ? (int) $arg2 - 1 : 0;
     }
     $cix2sC = 0;
     foreach ($this->components as $cix => $component2) {
         if (empty($component2)) {
             continue;
         }
         unset($component2->propix);
         if ('INDEX' == $argType && $index == $cix) {
             $this->components[$cix] = $component->copy();
             return TRUE;
         } elseif ($argType == $component2->objName) {
             if ($index == $cix2sC) {
                 $this->components[$cix] = $component->copy();
                 return TRUE;
             }
             $cix2sC++;
         } elseif (!$argType && $arg1 == $component2->getProperty('uid')) {
             $this->components[$cix] = $component->copy();
             return TRUE;
         }
     }
     /* not found.. . insert anyway.. .*/
     $this->components[] = $component->copy();
     return TRUE;
 }
Example #21
0
 /**
  * Wrapper method to access properties from the auth and
  * permission containers.
  *
  * @access public
  * @param  string   Name of the property to be returned.
  * @param  string   'auth' or 'perm'
  * @return mixed    , a value or an array.
  */
 function getProperty($what, $container = 'auth')
 {
     if ($this->_error) {
         return false;
     }
     $that = null;
     if ($container == 'auth' && $this->_auth && $this->_auth->getProperty($what) !== null) {
         $that = $this->_auth ? $this->_auth->getProperty($what) : null;
     } elseif ($this->_perm && $this->_perm->getProperty($what) !== null) {
         $that = $this->_perm ? $this->_perm->getProperty($what) : null;
     }
     return $that;
 }
Example #22
0
 /**
  * 构造函数
  *
  * @author      mrmsl <*****@*****.**>
  * @date        2013-06-05 17:42:41
  *
  * @param object $model            数据库实例
  * @param object $view_template     默认null,自动获取
  * @param bool   $exceptions        true可捕获发送异常。默认false
  *
  * @return void 无返回值
  */
 public function __construct($model, $view_template = null, $exceptions = false)
 {
     parent::__construct($exceptions);
     $this->SetLanguage('zh_cn', PHPMAILER_PATH . 'language/');
     $this->setConfig();
     $this->_model = $model;
     $this->_view_template = null === $view_template ? $model->getProperty('_module')->getViewTemplate(array('_caching' => false)) : $view_template;
 }
Example #23
0
 /**
  * Constructor for MBC_Slack - gather config settings.
  */
 public function __construct()
 {
     $this->mbConfig = MB_Configuration::getInstance();
     $this->slackConfig = $this->mbConfig->getProperty('slack_config');
     $this->statHat = $this->mbConfig->getProperty('statHat');
 }
 /**
  * set sort arguments/parameters in component
  *
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.18.4 - 2013-08-18
  * @param object $c valendar component
  * @param string $sortArg, optional
  * @return void
  */
 public static function _setSortArgs(&$c, $sortArg = FALSE)
 {
     $c->srtk = array('0', '0', '0', '0');
     if ('vtimezone' == $c->objName) {
         if (FALSE === ($c->srtk[0] = $c->getProperty('tzid'))) {
             $c->srtk[0] = 0;
         }
         return;
     } elseif ($sortArg) {
         if ('ATTENDEE' == $sortArg || 'CATEGORIES' == $sortArg || 'CONTACT' == $sortArg || 'RELATED-TO' == $sortArg || 'RESOURCES' == $sortArg) {
             $propValues = array();
             $c->_getProperties($sortArg, $propValues);
             if (!empty($propValues)) {
                 $sk = array_keys($propValues);
                 $c->srtk[0] = $sk[0];
                 if ('RELATED-TO' == $sortArg) {
                     $c->srtk[0] .= $c->getProperty('uid');
                 }
             } elseif ('RELATED-TO' == $sortArg) {
                 $c->srtk[0] = $c->getProperty('uid');
             }
         } elseif (FALSE !== ($d = $c->getProperty($sortArg))) {
             $c->srtk[0] = $d;
             if ('UID' == $sortArg) {
                 if (FALSE !== ($d = $c->getProperty('recurrence-id'))) {
                     $c->srtk[1] = iCalUtilityFunctions::_date2strdate($d);
                     if (FALSE === ($c->srtk[2] = $c->getProperty('sequence'))) {
                         $c->srtk[2] = PHP_INT_MAX;
                     }
                 } else {
                     $c->srtk[1] = $c->srtk[2] = PHP_INT_MAX;
                 }
             }
         }
         return;
     }
     // end elseif( $sortArg )
     if (FALSE !== ($d = $c->getProperty('X-CURRENT-DTSTART'))) {
         $c->srtk[0] = iCalUtilityFunctions::_strdate2date($d[1]);
         unset($c->srtk[0]['unparsedtext']);
     } elseif (FALSE === ($c->srtk[0] = $c->getProperty('dtstart'))) {
         $c->srtk[0] = 0;
     }
     // sortkey 0 : dtstart
     if (FALSE !== ($d = $c->getProperty('X-CURRENT-DTEND'))) {
         $c->srtk[1] = iCalUtilityFunctions::_strdate2date($d[1]);
         // sortkey 1 : dtend/due(/duration)
         unset($c->srtk[1]['unparsedtext']);
     } elseif (FALSE === ($c->srtk[1] = $c->getProperty('dtend'))) {
         if (FALSE !== ($d = $c->getProperty('X-CURRENT-DUE'))) {
             $c->srtk[1] = iCalUtilityFunctions::_strdate2date($d[1]);
             unset($c->srtk[1]['unparsedtext']);
         } elseif (FALSE === ($c->srtk[1] = $c->getProperty('due'))) {
             if (FALSE === ($c->srtk[1] = $c->getProperty('duration', FALSE, FALSE, TRUE))) {
                 $c->srtk[1] = 0;
             }
         }
     }
     if (FALSE === ($c->srtk[2] = $c->getProperty('created'))) {
         // sortkey 2 : created/dtstamp
         if (FALSE === ($c->srtk[2] = $c->getProperty('dtstamp'))) {
             $c->srtk[2] = 0;
         }
     }
     if (FALSE === ($c->srtk[3] = $c->getProperty('uid'))) {
         // sortkey 3 : uid
         $c->srtk[3] = 0;
     }
 }
Example #25
0
 public function getProperty($property, $object = null)
 {
     $property = $this->reflection->getProperty($property);
     $property->setAccessible(true);
     return $property->getValue($object ? $object : $this->throttle);
 }
Example #26
0
/**
 * convert ATTENDEEs, CONTACTs and ORGANIZERs (in email format) to vCards
 *
 * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
 * @since 2.12.2 - 2012-05-07
 * @param object $calendar   iCalcreator vcalendar instance reference
 * @param string $version    vCard version (default 2.1)
 * @param string $directory  where to save vCards (default FALSE)
 * @param string $ext        vCard file extension (default 'vcf')
 * @uses vcalendar::getProperty()
 * @return mixed
 */
function iCal2vCards(&$calendar, $version = '2.1', $directory = FALSE, $ext = 'vcf')
{
    $hits = array();
    $vCardP = array('ATTENDEE', 'CONTACT', 'ORGANIZER');
    foreach ($vCardP as $prop) {
        $hits2 = $calendar->getProperty($prop);
        foreach ($hits2 as $propValue => $occCnt) {
            if (FALSE === ($pos = strpos($propValue, '@'))) {
                continue;
            }
            $propValue = str_replace('MAILTO:', '', $propValue);
            if (isset($hits[$propValue])) {
                $hits[$propValue] += $occCnt;
            } else {
                $hits[$propValue] = $occCnt;
            }
        }
    }
    if (empty($hits)) {
        return FALSE;
    }
    ksort($hits);
    $output = '';
    foreach ($hits as $email => $skip) {
        $res = iCal2vCard($email, $version, $directory, $ext);
        if ($directory && !$res) {
            return FALSE;
        } elseif (!$res) {
            return $res;
        } else {
            $output .= $res;
        }
    }
    if ($directory) {
        return TRUE;
    }
    if (!empty($output)) {
        return $output;
    }
    return FALSE;
}
Example #27
0
 /**
  * add calendar component as subcomponent to container for subcomponents
  *
  * @author Kjell-Inge Gustafsson <*****@*****.**>
  * @since 1.x.x - 2007-04-24
  * @param object $component calendar component
  * @param mixed $arg1 optional, ordno/component type/ component uid
  * @param mixed $arg2 optional, ordno if arg1 = component type
  * @return void
  */
 function setComponent($component, $arg1 = FALSE, $arg2 = FALSE)
 {
     if ('' >= $component->getConfig('language')) {
         $component->setConfig('language', $this->getConfig('language'));
     }
     $component->setConfig('nl', $this->getConfig('nl'));
     $component->setConfig('unique_id', $this->getConfig('unique_id'));
     $component->setConfig('format', $this->getConfig('format'));
     if (!in_array($component->objName, array('valarm', 'vtimezone'))) {
         unset($component->propix);
         /* make sure dtstamp and uid is set */
         $dummy = $component->getProperty('dtstamp');
         $dummy = $component->getProperty('uid');
     }
     if (!$arg1) {
         $this->subcomponents[] = $component;
         return TRUE;
     }
     $argType = $index = null;
     if (is_int($arg1)) {
         $argType = 'INDEX';
         $index = --$arg1;
     } elseif (strlen($arg1) <= strlen('vfreebusy') && FALSE === strpos($arg1, '@')) {
         $argType = strtolower($arg1);
         $index = is_int($arg2) ? --$arg2 : 0;
     }
     $cix2sC = 0;
     foreach ($this->subcomponents as $cix => $subcomponent) {
         unset($subcomponent->propix);
         if ('INDEX' == $argType && $index == $cix) {
             $this->subcomponents[$cix] = $component;
             return TRUE;
         } elseif ($argType == $subcomponent->objName) {
             if ($index == $cix2sC) {
                 $this->subcomponents[$cix] = $component;
                 return TRUE;
             }
             $cix2sC++;
         } elseif (!$argType && $arg1 == $subcomponent2->getProperty('uid')) {
             $this->subcomponents[$cix] = $component;
             return TRUE;
         }
     }
     /* not found.. . insert anyway.. .*/
     $this->subcomponents[] = $component;
 }
Example #28
0
 public function setProperty($property, $value)
 {
     $property = $this->reflection->getProperty($property);
     $property->setAccessible(true);
     return $property->setValue($this->snoothClient, $value);
 }
Example #29
-1
 /**
  * updates the properties of the containers from the original source
  *
  * @param  boolean $auth if the auth container should be updated
  * @param  boolean $perm if the perm container should be updated
  * @return boolean
  *
  * @access public
  */
 function updateProperty($auth, $perm = null)
 {
     if (!is_a($this->_auth, 'LiveUser_Auth_Common')) {
         $this->_stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no auth container instance is available');
         return false;
     }
     if ($auth && !$this->_auth->readUserData('', '', true)) {
         return false;
     }
     if (is_null($perm)) {
         $perm = is_a($this->_perm, 'LiveUser_Perm_Simple');
     }
     if ($perm) {
         if (!is_a($this->_perm, 'LiveUser_Perm_Simple')) {
             $this->_stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no perm container instance is available');
             return false;
         }
         if (!$this->_perm->mapUser($this->_auth->getProperty('auth_user_id'), $this->_auth->backendArrayIndex)) {
             return false;
         }
     }
     return true;
 }
 /**
  * add calendar component as subcomponent to container for subcomponents
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.21.11 - 2015-03-21
  * @param object  $component calendar component
  * @param mixed   $arg1      ordno/component type/ component uid
  * @param mixed   $arg2      ordno if arg1 = component type
  * @uses calendarComponent::$components
  * @uses calendarComponent::setConfig()
  * @uses calendarComponent::getConfig()
  * @uses calendarComponent::$objName
  * @uses iCalUtilityFunctions::$miscComps
  * @uses calendarComponent::getProperty()
  * @uses calendarComponent::copy()
  * @uses iCalUtilityFunctions::$mComps
  * @return bool
  */
 function setComponent($component, $arg1 = FALSE, $arg2 = FALSE)
 {
     if (!isset($this->components)) {
         return FALSE;
     }
     $component->setConfig($this->getConfig(), FALSE, TRUE);
     if (!in_array($component->objName, iCalUtilityFunctions::$miscComps)) {
         /* make sure dtstamp and uid is set */
         $dummy = $component->getProperty('dtstamp');
         $dummy = $component->getProperty('uid');
     }
     if (!$arg1) {
         // plain insert, last in chain
         $this->components[] = $component->copy();
         return TRUE;
     }
     $argType = $index = null;
     if (ctype_digit((string) $arg1)) {
         // index insert/replace
         $argType = 'INDEX';
         $index = (int) $arg1 - 1;
     } elseif (in_array(strtolower($arg1), iCalUtilityFunctions::$mComps)) {
         $argType = strtolower($arg1);
         $index = ctype_digit((string) $arg2) ? (int) $arg2 - 1 : 0;
     }
     // else if arg1 is set, arg1 must be an UID
     $cix2sC = 0;
     foreach ($this->components as $cix => $component2) {
         if (empty($component2)) {
             continue;
         }
         if ('INDEX' == $argType && $index == $cix) {
             // index insert/replace
             $this->components[$cix] = $component->copy();
             return TRUE;
         } elseif ($argType == $component2->objName) {
             // component Type index insert/replace
             if ($index == $cix2sC) {
                 $this->components[$cix] = $component->copy();
                 return TRUE;
             }
             $cix2sC++;
         } elseif (!$argType && $arg1 == $component2->getProperty('uid')) {
             // UID insert/replace
             $this->components[$cix] = $component->copy();
             return TRUE;
         }
     }
     /* arg1=index and not found.. . insert at index .. .*/
     if ('INDEX' == $argType) {
         $this->components[$index] = $component->copy();
         ksort($this->components, SORT_NUMERIC);
     } else {
         /* not found.. . insert last in chain anyway .. .*/
         $this->components[] = $component->copy();
     }
     return TRUE;
 }