diff --git a/account.php b/account.php index e8bcaf07a0270ef61c18cd300e42ada49391449f..97c8b5efdf6ee5812f5bf66979ba10b0915a4dcd 100644 --- a/account.php +++ b/account.php @@ -37,7 +37,7 @@ elseif ($thisclient) { // Existing client (with an account) updating profile else { $user = User::lookup($thisclient->getId()); - $content = Page::lookup(Page::getIdByType('registration-thanks')); + $content = Page::lookupByType('registration-thanks'); $inc = isset($_GET['confirmed']) ? 'register.confirmed.inc.php' : 'profile.inc.php'; } @@ -94,7 +94,7 @@ elseif ($_POST) { if (!$errors) { switch ($_POST['do']) { case 'create': - $content = Page::lookup(Page::getIdByType('registration-confirm')); + $content = Page::lookupByType('registration-confirm'); $inc = 'register.confirm.inc.php'; $acct->sendConfirmEmail(); break; diff --git a/include/ajax.content.php b/include/ajax.content.php index 68297e991fc891140c69c49ee714d9cd5cde943e..39eda3e6d2921d36386ed42049f125d19db3321a 100644 --- a/include/ajax.content.php +++ b/include/ajax.content.php @@ -157,7 +157,7 @@ class ContentAjaxAPI extends AjaxController { $langs = $cfg->getSecondaryLanguages(); - $content = Page::lookup(Page::getIdByType($type, $lang)); + $content = Page::lookupByType($type, $lang); include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; } diff --git a/include/class.client.php b/include/class.client.php index 84b69f2570a15f436caca77cbf407a340596809c..e29f570b77e2c94b5ec8b6fb270165d9eef206a7 100644 --- a/include/class.client.php +++ b/include/class.client.php @@ -55,7 +55,7 @@ abstract class TicketUser { if (!($ticket = $this->getTicket()) || !($email = $ost->getConfig()->getDefaultEmail()) - || !($content = Page::lookup(Page::getIdByType('access-link')))) + || !($content = Page::lookupByType('access-link'))) return; $vars = array( diff --git a/include/class.page.php b/include/class.page.php index 641832b66d63a7881213aa017848507e5a9a5da3..e843a15aad7a6cfeb311c6bd43bfc13afcfce90a 100644 --- a/include/class.page.php +++ b/include/class.page.php @@ -196,6 +196,18 @@ class Page extends VerySimpleModel { return self::getActivePages(array('type' => 'thank-you')); } + static function lookup($id, $lang=false) { + try { + $qs = self::objects()->filter(array('id'=>$id)); + if ($lang) + $qs = $qs->filter(array('lang'=>$lang)); + return $qs->one(); + } + catch (DoesNotExist $ex) { + return null; + } + } + static function getIdByName($name, $lang=false) { try { $qs = self::objects()->filter(array('name'=>$name)) @@ -210,14 +222,12 @@ class Page extends VerySimpleModel { } } - static function getIdByType($type, $lang=false) { + static function lookupByType($type, $lang=false) { try { - $qs = self::objects()->filter(array('type'=>$type)) - ->values_flat('id'); + $qs = self::objects()->filter(array('type'=>$type)); if ($lang) $qs = $qs->filter(array('lang'=>$lang)); - list($id) = $qs->one(); - return $id; + return $qs->one(); } catch (DoesNotExist $ex) { return null; diff --git a/include/class.staff.php b/include/class.staff.php index e20e3c03cd805be8dcf5d8c91578d4168274d938..dd3444bea22dba5f4019101e92eaa7d90f44c7a2 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -687,7 +687,7 @@ class Staff extends AuthenticatedUser { function sendResetEmail($template='pwreset-staff') { global $ost, $cfg; - $content = Page::lookup(Page::getIdByType($template)); + $content = Page::lookupByType($template); $token = Misc::randCode(48); // 290-bits if (!$content) diff --git a/include/class.user.php b/include/class.user.php index 08b54cce6303ad6d62ffc6e33199d051d39efa7c..382c66f8024e855ae67ab43f9f1a7ea337b9637d 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -941,7 +941,7 @@ class UserAccount extends UserAccountModel { $token = Misc::randCode(48); // 290-bits $email = $cfg->getDefaultEmail(); - $content = Page::lookup(Page::getIdByType($template)); + $content = Page::lookupByType($template); if (!$email || !$content) return new Error(sprintf(_S('%s: Unable to retrieve template'), diff --git a/include/client/login.inc.php b/include/client/login.inc.php index 2eb28a227d004e2cd9e9f9e357b0b8c064811c78..2b688ee2de4b9f69b545d4ed89dbc57ab26170ba 100644 --- a/include/client/login.inc.php +++ b/include/client/login.inc.php @@ -4,7 +4,7 @@ if(!defined('OSTCLIENTINC')) die('Access Denied'); $email=Format::input($_POST['luser']?:$_GET['e']); $passwd=Format::input($_POST['lpasswd']?:$_GET['t']); -$content = Page::lookup(Page::getIdByType('banner-client')); +$content = Page::lookupByType('banner-client'); if ($content) { list($title, $body) = $ost->replaceTemplateVariables( diff --git a/scp/login.php b/scp/login.php index c4947918b693b236188d69279e4a95e9afd71f3f..609a0c5eca29df70b768233f29c9eb38e4e5fe1c 100644 --- a/scp/login.php +++ b/scp/login.php @@ -23,7 +23,7 @@ TextDomain::configureForUser(); require_once(INCLUDE_DIR.'class.staff.php'); require_once(INCLUDE_DIR.'class.csrf.php'); -$content = Page::lookup(Page::getIdByType('banner-staff')); +$content = Page::lookupByType('banner-staff'); $dest = $_SESSION['_staff']['auth']['dest']; $msg = $_SESSION['_staff']['auth']['msg'];