Skip to content

Commit

Permalink
Merge branch 'release/2013-08.01'
Browse files Browse the repository at this point in the history
Conflicts:
	app/Config/version.php
	app/Model/Entry.php
  • Loading branch information
Schlaefer committed Aug 15, 2013
2 parents 5376dd3 + eb714b8 commit 906dac1
Show file tree
Hide file tree
Showing 170 changed files with 4,451 additions and 2,973 deletions.
2 changes: 1 addition & 1 deletion app/Config/version.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
Configure::write('Saito.v', '2013-07.01b');
Configure::write('Saito.v', '2013-08.01');
3 changes: 2 additions & 1 deletion app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AppController extends Controller {
*/
'Cookie',
'CurrentUser',
'CacheSupport',
'JsData',
'SaitoEmail',
'EmailNotification',
Expand Down Expand Up @@ -100,7 +101,7 @@ public function beforeFilter() {
[
'hashBaseUrl' => 'entries/view/',
'atBaseUrl' => 'users/name/',
'server' => Router::baseURL(),
'server' => Router::fullBaseUrl(),
'webroot' => $this->webroot
]
);
Expand Down
63 changes: 17 additions & 46 deletions app/Controller/Component/CacheSupportComponent.php
Original file line number Diff line number Diff line change
@@ -1,66 +1,37 @@
<?php

App::uses('Component', 'Controller');
App::import('Lib', 'CacheSupport');
App::uses('CacheTree', 'Lib/CacheTree');

class CacheSupportComponent extends Component {

public $components = [
'CacheTree'
];
protected $_CacheSupport;

public $CacheTree;

public function initialize(Controller $Controller) {
$this->_CacheSupport = new CacheSupport();
$this->CacheTree = CacheTree::getInstance();
$this->CacheTree->initialize($Controller);
}

public function beforeRedirect(Controller $Controller, $url, $status = null, $exit = true) {
$this->CacheTree->beforeRedirect($Controller, $url, $status, $exit);
}

public function shutdown(Controller $Controller) {
$this->CacheTree->shutdown($Controller);
}

public function clearAll() {
$this->clearSaito();
$this->clearApc();
$this->clearCake();
}

public function clearSaito() {
Cache::clear(false, 'default');
Cache::clear(false, 'short');
$this->clearTrees();
}

public function clearCake() {
Cache::clearGroup('persistent');
Cache::clearGroup('models');
Cache::clearGroup('views');
}

public function clearTree($id) {
$this->_clearEntries();
$this->CacheTree->delete($id);
public function beforeRender(Controller $Controller) {
$Controller->set('CacheTree', $this->CacheTree);
}

public function clearTrees() {
$this->_clearEntries();
$this->CacheTree->reset();
public function beforeRedirect(Controller $Controller, $url, $status = null, $exit = true) {
$this->CacheTree->saveCache();
}

protected function _clearEntries() {
Cache::clear(false, 'entries');
public function shutdown(Controller $Controller) {
$this->CacheTree->saveCache();
}

/**
* Clears out the APC if available
*/
public function clearApc() {
if (function_exists('apc_store')) {
apc_clear_cache();
apc_clear_cache('user');
apc_clear_cache('opcode');
public function __call($method, $params) {
$proxy = [$this->_CacheSupport, $method];
if (is_callable($proxy)) {
return call_user_func_array($proxy, $params);
}
}

}
24 changes: 15 additions & 9 deletions app/Controller/Component/CurrentUserComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function _markOnline() {
Stopwatch::start('CurrentUser->_markOnline()');

$id = $this->getId();
if ($this->isLoggedIn() == false):
if ($this->isLoggedIn() === false):
// don't count search bots as guests
if ($this->_isBot()) {
return;
Expand All @@ -166,8 +166,8 @@ protected function _isBot() {

protected function _cookieRelogin() {
$cookie = $this->PersistentCookie->get();
// is_array -> if cookie could no be correctly deciphered it's just an random string
if ($cookie) {
// is_array -> if cookie could no be correctly deciphered it's just an random string
if (!is_null($cookie) && is_array($cookie)):
if ($this->_Controller->Auth->login($cookie)):
return;
Expand Down Expand Up @@ -203,7 +203,7 @@ public function login() {

public function refresh($user = null) {
parent::set($this->_Controller->Auth->user());
// all session should must use current user data (locked, user_type, …)
// all session have to use current user data (locked, user_type, …)
if ($this->isLoggedIn()) {
$this->_User->id = $this->getId();
parent::set($this->_User->getProfile($this->getId()));
Expand Down Expand Up @@ -368,12 +368,18 @@ public function __construct(SaitoUser $currentUser, User $user) {
$this->user = $user;
}

public function forceSet() {
$this->_set(date("Y-m-d H:i:s"));
}

public function set() {
$this->_set($this->currentUser['last_refresh_tmp']);
/**
* @param mixed $timestamp
*
* null|'now'|<`Y-m-d H:i:s` timestamp>
*/
public function set($timestamp = null) {
if ($timestamp === 'now') {
$timestamp = date('Y-m-d H:i:s');
} elseif ($timestamp === null) {
$timestamp = $this->currentUser['last_refresh_tmp'];
}
$this->_set($timestamp);
}

public function setMarker() {
Expand Down
164 changes: 95 additions & 69 deletions app/Controller/Component/EmailNotificationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,65 +39,66 @@ public function dispatchEvent($event) {
}

protected function _modelEntryReplyToThread($event, array $recipients) {
// get parent entry
foreach ( $recipients as $recipient ):
// don't send answer if new entry belongs to the user itself
if ( Configure::read('debug') === 0 && (int)$recipient['id'] === (int)$event->data['data']['Entry']['user_id'] ) {
continue;
}
$event->subject()->contain();
$rootEntry = $event->subject()->findById($event->data['data']['Entry']['tid']);
try {
$this->_Controller->SaitoEmail->email(array(
'recipient' => array('User' => $recipient),
'subject' => __('New reply to "%s"', $rootEntry['Entry']['subject']),
'sender' => array(
'User' => array(
'user_email' => Configure::read('Saito.Settings.forum_email'),
'username' => Configure::read('Saito.Settings.forum_name')),
),
'template' => Configure::read('Config.language') . DS . 'notification-model-entry-afterReply',
'viewVars' => array(
'recipient' => $recipient,
'parentEntry' => $rootEntry,
'newEntry' => $event->data['data'],
'notification' => $recipient['Esnotification'],
),
));
} catch ( Exception $exc ) {
$event->subject()->contain();
$rootEntry = $event->subject()->findById($event->data['data']['Entry']['tid']);

$config = [
'subject' => __(
'New reply to "%s"',
$rootEntry['Entry']['subject']
),
'sender' => array(
'User' => array(
'user_email' => Configure::read('Saito.Settings.forum_email'),
'username' => Configure::read('Saito.Settings.forum_name')
),
),
'template' => Configure::read(
'Config.language'
) . DS . 'notification-model-entry-afterReply',
'viewVars' => array(
'parentEntry' => $rootEntry,
'newEntry' => $event->data['data'],
),
];
foreach ( $recipients as $recipient ):
if ($this->_shouldRecipientReceiveReplyMessage($recipient, $event->data['data']['Entry'])) {
$config['recipient'] = ['User' => $recipient];
$config['viewVars']['recipient'] = $recipient;
$config['viewVars']['notification'] = $recipient['Esnotification'];
$this->_email($config);
}
endforeach;
}

protected function _modelEntryReplyToEntry($event, array $recipients) {
// get parent entry
$event->subject()->contain();
$parentEntry = $event->subject()->findById($event->data['data']['Entry']['pid']);
$config = [
'subject' => __(
'New reply to "%s"',
$parentEntry['Entry']['subject']
),
'sender' => array(
'User' => array(
'user_email' => Configure::read('Saito.Settings.forum_email'),
'username' => Configure::read('Saito.Settings.forum_name')
),
),
'template' => Configure::read(
'Config.language'
) . DS . 'notification-model-entry-afterReply',
'viewVars' => array(
'parentEntry' => $parentEntry,
'newEntry' => $event->data['data']
)
];
foreach ( $recipients as $recipient ):
// don't send answer if new entry belongs to the user itself
if ( Configure::read('debug') === 0 && (int)$recipient['id'] === (int)$event->data['data']['Entry']['user_id'] ) {
continue;
}
$event->subject()->contain();
$parentEntry = $event->subject()->findById($event->data['data']['Entry']['pid']);
try {
$this->_Controller->SaitoEmail->email(array(
'recipient' => array('User' => $recipient),
'subject' => __('New reply to "%s"', $parentEntry['Entry']['subject']),
'sender' => array(
'User' => array(
'user_email' => Configure::read('Saito.Settings.forum_email'),
'username' => Configure::read('Saito.Settings.forum_name')),
),
'template' => Configure::read('Config.language') . DS . 'notification-model-entry-afterReply',
'viewVars' => array(
'recipient' => $recipient,
'parentEntry' => $parentEntry,
'newEntry' => $event->data['data'],
'notification' => $recipient['Esnotification'],
),
));
} catch ( Exception $exc ) {

if ($this->_shouldRecipientReceiveReplyMessage($recipient, $event->data['data']['Entry'])) {
$config['recipient'] = ['User' => $recipient];
$config['viewVars']['recipient'] = $recipient;
$config['viewVars']['notification'] = $recipient['Esnotification'];
$this->_email($config);
}
endforeach;
}
Expand All @@ -107,25 +108,52 @@ public function userActivatedAdminNotice($event) {
if ( !is_array($recipients) )
return;
$new_user = $event->data['User'];
$config = [
'subject' => __('Successfull registration'),
'sender' => array(
'User' => array(
'user_email' => Configure::read('Saito.Settings.forum_email'),
'username' => Configure::read('Saito.Settings.forum_name')
),
),
'template' => Configure::read(
'Config.language'
) . DS . 'notification-admin-user_activated',
'viewVars' => array('user' => $new_user, 'ip' => env('REMOTE_ADDR')),

];
foreach ( $recipients as $recipient ) :
try {
$this->_Controller->SaitoEmail->email(array(
'recipient' => $recipient,
'subject' => __('Successfull registration'),
'sender' => array(
'User' => array(
'user_email' => Configure::read('Saito.Settings.forum_email'),
'username' => Configure::read('Saito.Settings.forum_name')),
),
'template' => Configure::read('Config.language') . DS . 'notification-admin-user_activated',
'viewVars' => array('user' => $new_user, 'ip' => env('REMOTE_ADDR')),
));
} catch ( Exception $exc ) {

}
$config['recipient'] = $recipient;
$this->_email($config);
endforeach;
}

protected function _shouldRecipientReceiveReplyMessage($entry, $recipient) {
if (Configure::read('debug') === 0 &&
// don't send answer if new entry belongs to the user itself
(int)$recipient['id'] === (int)$entry['user_id']
) {
return false;
} else {
return true;
}

}

protected function _email($config) {
try {
$this->_Controller->SaitoEmail->email($config);
} catch (Exception $exc) {
$this->log(
sprintf(
"Error %s in EmailNotificationComponent::_email() with %s",
$exc,
print_r($config, true)
)
);
}
}

protected function _debug($event, array $receivers) {
debug($event);
foreach ( $receivers as $receiver ) {
Expand All @@ -134,5 +162,3 @@ protected function _debug($event, array $receivers) {
}

}

?>
2 changes: 1 addition & 1 deletion app/Controller/Component/SaitoEmailComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function _resetConfig() {
protected function _config($options = array()) {
$defaults = array(
'viewVars'=> array(
'webroot' => Router::baseURL() . $this->_webroot,
'webroot' => Router::fullBaseUrl() . $this->_webroot,
),
);
extract(array_merge_recursive($defaults, $options));
Expand Down
Loading

0 comments on commit 906dac1

Please sign in to comment.