Skip to content

Commit

Permalink
This is loaded on (almost) every page, so no need to load IMP_Auth ju…
Browse files Browse the repository at this point in the history
…st to access it
  • Loading branch information
slusarz committed Feb 10, 2014
1 parent 0c89f1f commit f30d85f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion imp/index.php
Expand Up @@ -17,4 +17,4 @@
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('imp');

IMP_Auth::getInitialPage()->url->redirect();
IMP::getInitialPage()->url->redirect();
4 changes: 2 additions & 2 deletions imp/lib/Application.php
Expand Up @@ -153,7 +153,7 @@ protected function _init()
if (($registry->initialApp == 'imp') &&
!empty($this->initParams['impmode']) &&
($this->initParams['impmode'] != $registry->getView())) {
IMP_Auth::getInitialPage()->url->redirect();
IMP::getInitialPage()->url->redirect();
}
}

Expand Down Expand Up @@ -181,7 +181,7 @@ public function logout()
*/
public function getInitialPage()
{
return strval(IMP_Auth::getInitialPage()->url);
return strval(IMP::getInitialPage()->url);
}

/* Horde permissions. */
Expand Down
56 changes: 0 additions & 56 deletions imp/lib/Auth.php
Expand Up @@ -227,62 +227,6 @@ static protected function _canAutoLogin($server_key = null, $force = false)
return false;
}

/**
* Returns the initial page.
*
* @return object Object with the following properties:
* - mbox (IMP_Mailbox)
* - url (Horde_Url)
*/
static public function getInitialPage()
{
$init_url = $GLOBALS['prefs']->getValue('initial_page');
if (!$init_url ||
!$GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)) {
$init_url = 'INBOX';
}

if ($init_url == IMP::INITIAL_FOLDERS) {
$mbox = null;
} else {
$mbox = IMP_Mailbox::get($init_url);
$GLOBALS['injector']->getInstance('Horde_Variables')->mailbox = $mbox->exists
? $mbox->form_to
: IMP_Mailbox::get('INBOX')->form_to;
}

$result = new stdClass;
$result->mbox = $mbox;

switch ($GLOBALS['registry']->getView()) {
case Horde_Registry::VIEW_BASIC:
$result->url = is_null($mbox)
? IMP_Basic_Folders::url()
: $mbox->url('mailbox');
break;

case Horde_Registry::VIEW_DYNAMIC:
$result->url = IMP_Dynamic_Mailbox::url(array(
'mailbox' => is_null($mbox) ? 'INBOX' : $mbox
));
break;

case Horde_Registry::VIEW_MINIMAL:
$result->url = is_null($mbox)
? IMP_Minimal_Folders::url()
: IMP_Minimal_Mailbox::url(array('mailbox' => $mbox));
break;

case Horde_Registry::VIEW_SMARTMOBILE:
$result->url = is_null($mbox)
? Horde::url('smartmobile.php', true)
: $mbox->url('mailbox');
break;
}

return $result;
}

/**
* Perform post-login tasks. Session creation requires the full IMP
* environment, which is not available until this callback.
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Block/Summary.php
Expand Up @@ -39,7 +39,7 @@ public function __construct($app, $params = array())
*/
protected function _title()
{
return Horde::link(IMP_Auth::getInitialPage()->url) . $GLOBALS['registry']->get('name') . '</a>';
return Horde::link(IMP::getInitialPage()->url) . $GLOBALS['registry']->get('name') . '</a>';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Dynamic/Mailbox.php
Expand Up @@ -160,7 +160,7 @@ protected function _addMailboxVars()
),
'filter_any' => intval($prefs->getValue('filter_any_mailbox')),
'fsearchid' => IMP_Mailbox::formTo(IMP_Search::MBOX_PREFIX . IMP_Search::DIMP_FILTERSEARCH),
'initial_page' => is_null($initial_page = IMP_Auth::getInitialPage()->mbox) ? null : $initial_page->form_to,
'initial_page' => is_null($initial_page = IMP::getInitialPage()->mbox) ? null : $initial_page->form_to,
'mbox_expand' => intval($prefs->getValue('nav_expanded') == 2),
'name' => $registry->get('name', 'imp'),
'poll_alter' => intval(!$prefs->isLocked('nav_poll') && !$prefs->getValue('nav_poll_all')),
Expand Down
60 changes: 60 additions & 0 deletions imp/lib/IMP.php
Expand Up @@ -134,4 +134,64 @@ static public function parseAddressList($in, array $opts = array())
return $res;
}

/**
* Returns the initial page for IMP.
*
* @return object Object with the following properties:
* <pre>
* - mbox (IMP_Mailbox)
* - url (Horde_Url)
* </pre>
*/
static public function getInitialPage()
{
global $injector, $prefs, $registry;

$init_url = $prefs->getValue('initial_page');
if (!$init_url ||
!$injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)) {
$init_url = 'INBOX';
}

if ($init_url == IMP::INITIAL_FOLDERS) {
$mbox = null;
} else {
$mbox = IMP_Mailbox::get($init_url);
$injector->getInstance('Horde_Variables')->mailbox = $mbox->exists
? $mbox->form_to
: IMP_Mailbox::get('INBOX')->form_to;
}

$result = new stdClass;
$result->mbox = $mbox;

switch ($registry->getView()) {
case Horde_Registry::VIEW_BASIC:
$result->url = is_null($mbox)
? IMP_Basic_Folders::url()
: $mbox->url('mailbox');
break;

case Horde_Registry::VIEW_DYNAMIC:
$result->url = IMP_Dynamic_Mailbox::url(array(
'mailbox' => is_null($mbox) ? 'INBOX' : $mbox
));
break;

case Horde_Registry::VIEW_MINIMAL:
$result->url = is_null($mbox)
? IMP_Minimal_Folders::url()
: IMP_Minimal_Mailbox::url(array('mailbox' => $mbox));
break;

case Horde_Registry::VIEW_SMARTMOBILE:
$result->url = is_null($mbox)
? Horde::url('smartmobile.php', true)
: $mbox->url('mailbox');
break;
}

return $result;
}

}

0 comments on commit f30d85f

Please sign in to comment.