Пример #1
0
 public function userOverviewSimple($statement, $userHandle, $galleries = false)
 {
     $words = new MOD_words();
     $Gallery = new GalleryController();
     $callbackId = $Gallery->updateGalleryProcess();
     $vars =& PPostHandler::getVars($callbackId);
     if (!isset($vars['errors'])) {
         $vars['errors'] = array();
     }
     $type = 'images';
     $galleries = $this->_model->getUserGalleries();
     echo '
     <form method="post" action="gallery/show/user/' . $userHandle . '/pictures" name="mod-images" class="def-form">
     <input type="hidden" name="' . $callbackId . '" value="1"/>
     ';
     if (in_array('gallery', $vars['errors'])) {
         echo '<span class="error">' . $words->get('GalleryErrorsPhotosets') . '</span>';
     }
     if (in_array('images', $vars['errors'])) {
         echo '<span class="error">' . $words->get('GalleryErrorsImages') . '</span>';
     }
     require 'templates/overview.php';
     require 'templates/user_controls.php';
     echo '</form>';
 }
Пример #2
0
 public static function display()
 {
     $data = AFormatter::objectiveSettings(Applum::find(1));
     View::make('site/head/head');
     View::make("site/body/header/header");
     IntroController::intro($data);
     FeatureController::feature($data);
     AppController::app($data);
     SubscribeController::subscribe($data);
     GalleryController::gallery($data);
     TestimonialController::testimonial($data);
     PricingController::pricing($data);
     ContactController::contact($data);
     FooterController::footer($data);
 }
Пример #3
0
 /**
  *	Handles input, by calling according controller,
  *	an sets view depending on url.
  *	@return void
  */
 public function handleInput()
 {
     //Create database, get content catalog
     $db = new Database();
     $contentDAL = new contentDAL($db);
     $Catalog = new contentCatalog();
     $contentController = new ContentController($contentDAL, $Catalog);
     $contentCatalog = $contentController->getContent();
     //Handle login
     if ($this->navigationView->wantsToLogin()) {
         $login = new LoginController($this->users, $this->navigationView);
         $this->IsLoggedIn = $login->doLogin();
         if ($this->IsLoggedIn) {
             $this->navigationView->redirToAdmin();
         } else {
             $this->view = $login->getOutPut();
         }
     } else {
         if ($this->navigationView->wantsToUpload() && isset($_SESSION['user'])) {
             $this->view = new AdminView();
             $uploadController = new uploadController($this->view, $contentDAL, $this->users);
             $uploadController->doUpload();
         } else {
             if ($this->navigationView->wantsToReg()) {
                 $model = new RegFacade($this->userDAL);
                 $this->view = new RegView($this->navigationView);
                 $regControl = new RegisterController($model, $this->view);
                 $regControl->addUser();
                 $this->view = new RegView($this->navigationView);
             } else {
                 if ($this->navigationView->wantsToViewImage()) {
                     $this->view = new ImageView();
                     $imgController = new ImageController($this->view, $contentCatalog);
                     $imgController->getImage();
                 } else {
                     if ($this->navigationView->wantsToViewContent()) {
                         $commentView = new commentView();
                         $this->view = new ContentView($commentView);
                         $id = $this->view->getID();
                         $commentDAL = new commentDAL($db);
                         $commentController = new CommentController($commentView, $commentDAL);
                         $comments = $commentController->doComment($id);
                         $content = $contentController->getContentByID($id);
                         $this->view->createHTML($content, $comments);
                     } else {
                         $this->view = new galleryView();
                         $galController = new GalleryController($this->view);
                         $galController->doGallery($contentCatalog);
                     }
                 }
             }
         }
     }
 }
Пример #4
0
/**
 * Process our request
 * @return array object GalleryStatus a status code
 *               array[]
 */
function _GalleryMain($embedded = false)
{
    global $gallery;
    $main = array();
    $urlGenerator =& $gallery->getUrlGenerator();
    /* Figure out the target view/controller */
    list($viewName, $controllerName) = GalleryUtilities::getRequestVariables('view', 'controller');
    $gallery->debug("controller {$controllerName}, view {$viewName}");
    /* Check if core module needs upgrading */
    list($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core', true);
    if ($ret) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
    $installedVersions = $core->getInstalledVersions();
    if ($installedVersions['core'] != $core->getVersion()) {
        if ($redirectUrl = @$gallery->getConfig('mode.maintenance')) {
            /* Maintenance mode -- redirect if given url, else simple message */
            if ($redirectUrl === true) {
                print $core->translate('Site is temporarily down for maintenance.');
                exit;
            }
        } else {
            $gallery->debug('Redirect to the upgrade wizard, core module version is out of date');
            $redirectUrl = $urlGenerator->getCurrentUrlDir(true) . 'upgrade/index.php';
        }
        return array(null, _GalleryMain_doRedirect($redirectUrl));
    }
    $ret = GalleryInitSecondPass();
    if ($ret) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
    /* Load and run the appropriate controller */
    $results = array();
    if (!empty($controllerName)) {
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryController.class');
        list($ret, $controller) = GalleryController::loadController($controllerName);
        if ($ret) {
            return array($ret->wrap(__FILE__, __LINE__), null);
        }
        if (!$embedded && $gallery->getConfig('mode.embed.only') && !$controller->isAllowedInEmbedOnly()) {
            /* Lock out direct access when embed-only is set */
            return array(GalleryCoreApi::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__), null);
        }
        if ($gallery->getConfig('mode.maintenance') && !$controller->isAllowedInMaintenance()) {
            /* Maintenance mode - allow admins, else redirect to given or standard url */
            list($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
            if ($ret) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
            if (!$isAdmin) {
                if (($redirectUrl = $gallery->getConfig('mode.maintenance')) === true) {
                    $redirectUrl = $urlGenerator->generateUrl(array('view' => 'core.MaintenanceMode'), array('forceFullUrl' => true));
                }
                return array(null, _GalleryMain_doRedirect($redirectUrl));
            }
        }
        /* Get our form and return variables */
        $form = GalleryUtilities::getFormVariables('form');
        /* Let the controller handle the input */
        list($ret, $results) = $controller->handleRequest($form);
        if ($ret) {
            return array($ret->wrap(__FILE__, __LINE__), null);
        }
        /* Check to make sure we got back everything we want */
        if (!isset($results['status']) || !isset($results['error']) || !isset($results['redirect']) && !isset($results['delegate']) && !isset($results['return'])) {
            return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__, 'Controller results are missing status, ' . 'error, (redirect, delegate, return)'), null);
        }
        /* Try to return if the controller instructs it */
        if (!empty($results['return'])) {
            list($ret, $navigationLinks) = $urlGenerator->getNavigationLinks(1);
            if ($ret) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
            if (count($navigationLinks) > 0) {
                /* Go back to the previous navigation point in our history */
                $redirectUrl = $navigationLinks[0]['url'];
            } else {
                $redirectUrl = GalleryUtilities::getRequestVariables('return');
                if (empty($redirectUrl)) {
                    $redirectUrl = GalleryUtilities::getRequestVariables('formUrl');
                }
            }
        }
        /* Failing that, redirect if so instructed */
        if (empty($redirectUrl) && !empty($results['redirect'])) {
            /*
             * If we have a status, store its data in the session and attach it
             * to the URL.
             */
            if (!empty($results['status'])) {
                $session =& $gallery->getSession();
                $results['redirect']['statusId'] = $session->putStatus($results['status']);
            }
            $urlToGenerate = $results['redirect'];
            /* Keep our navId in the URL */
            $navId = $urlGenerator->getNavigationId();
            if (!empty($navId)) {
                $urlToGenerate['navId'] = $navId;
            }
            $redirectUrl = $urlGenerator->generateUrl($urlToGenerate, array('forceFullUrl' => true));
        }
        /* If we have a redirect url.. use it */
        if (!empty($redirectUrl)) {
            return array(null, _GalleryMain_doRedirect($redirectUrl, null, $controllerName));
        }
        /* Let the controller specify the next view */
        if (!empty($results['delegate'])) {
            /* Load any errors into the request */
            if (!empty($results['error'])) {
                foreach ($results['error'] as $error) {
                    GalleryUtilities::putRequestVariable($error, 1);
                }
            }
            /* Save the view name, put the rest into the request so the view can get it */
            foreach ($results['delegate'] as $key => $value) {
                switch ($key) {
                    case 'view':
                        $viewName = $value;
                        break;
                    default:
                        GalleryUtilities::putRequestVariable($key, $value);
                        break;
                }
            }
        }
    }
    /* Load and run the appropriate view */
    if (empty($viewName)) {
        $viewName = GALLERY_DEFAULT_VIEW;
        GalleryUtilities::putRequestVariable('view', $viewName);
    }
    list($ret, $view) = GalleryView::loadView($viewName);
    if ($ret) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
    if ($gallery->getConfig('mode.maintenance') && !$view->isAllowedInMaintenance()) {
        /* Maintenance mode - allow admins, else redirect to given url or show standard view */
        list($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
        if ($ret) {
            return array($ret->wrap(__FILE__, __LINE__), null);
        }
        if (!$isAdmin) {
            if (($redirectUrl = $gallery->getConfig('mode.maintenance')) !== true) {
                return array(null, _GalleryMain_doRedirect($redirectUrl));
            }
            $viewName = 'core.MaintenanceMode';
            list($ret, $view) = GalleryView::loadView($viewName);
            if ($ret) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
        }
    }
    if (!$embedded && $gallery->getConfig('mode.embed.only') && !$view->isAllowedInEmbedOnly()) {
        /* Lock out direct access when embed-only is set */
        return array(GalleryCoreApi::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__), null);
    }
    /* Check if the page is cached and return the cached version, else generate the page */
    list($ret, $shouldCache) = GalleryDataCache::shouldCache('read', 'full');
    if ($ret) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
    $html = '';
    if ($shouldCache) {
        $session =& $gallery->getSession();
        list($ret, $html) = GalleryDataCache::getPageData('page', $urlGenerator->getCacheableUrl());
        if ($ret) {
            return array($ret->wrap(__FILE__, __LINE__), null);
        }
    }
    if (!empty($html)) {
        /*
         * TODO: If we cache all the headers and replay them here, we could send a 304 not
         * modified back
         */
        $session =& $gallery->getSession();
        $html = $session->replaceTempSessionIdIfNecessary($html);
        /* Set the appropriate charset in our HTTP header */
        if (!headers_sent()) {
            header('Content-Type: text/html; charset=UTF-8');
        }
        print $html;
        $data['isDone'] = true;
    } else {
        /* Initialize our container for template data */
        $gallery->setCurrentView($viewName);
        /*
         * If we render directly to the browser, we need get a session before,
         * or no session at all
         */
        if ($view->isImmediate() || $viewName == 'core.ProgressBar') {
            /*
             * Session: Find out whether we need to send a cookie & get a new sessionId and save it
             * (make sure there's a sessionId before starting to render, but only if we need a
             * session)
             */
            $session =& $gallery->getSession();
            $ret = $session->start();
            if ($ret) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
            /* From now on, don't add navid / sessionId to URLs if there's no persistent session */
            $session->doNotUseTempId();
        }
        /*
         * If this is an immediate view, it will send its own output directly.  This is
         * used in the situation where we want to send back data that's not controlled by the
         * layout.  That's usually something that's not user-visible like a binary file.
         */
        $data = array();
        if ($view->isImmediate()) {
            $status = isset($results['status']) ? $results['status'] : array();
            $error = isset($results['error']) ? $results['error'] : array();
            $ret = $view->renderImmediate($status, $error);
            if ($ret) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
            $data['isDone'] = true;
        } else {
            GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class');
            $template = new GalleryTemplate(dirname(__FILE__));
            list($ret, $results, $theme) = $view->doLoadTemplate($template);
            if ($ret) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
            if (isset($results['redirect']) || isset($results['redirectUrl'])) {
                if (isset($results['redirectUrl'])) {
                    $redirectUrl = $results['redirectUrl'];
                } else {
                    $redirectUrl = $urlGenerator->generateUrl($results['redirect'], array('forceFullUrl' => true));
                }
                return array(null, _GalleryMain_doRedirect($redirectUrl, $template));
            }
            if (empty($results['body'])) {
                return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__, 'View results are missing body file'), null);
            }
            $templatePath = 'gallery:' . $results['body'];
            $template->setVariable('l10Domain', $theme->getL10Domain());
            $template->setVariable('isEmbedded', $embedded);
            if ($viewName == 'core.ProgressBar') {
                /* Render progress bar pages immediately so that the user sees the bar moving */
                $ret = $template->display($templatePath);
                if ($ret) {
                    return array($ret->wrap(__FILE__, __LINE__), null);
                }
                $data['isDone'] = true;
            } else {
                list($ret, $html) = $template->fetch($templatePath);
                if ($ret) {
                    return array($ret->wrap(__FILE__, __LINE__), null);
                }
                $html = preg_replace('/^\\s+/m', '', $html);
                list($ret, $shouldCache) = GalleryDataCache::shouldCache('write', 'full');
                if ($ret) {
                    return array($ret->wrap(__FILE__, __LINE__), null);
                }
                if ($shouldCache && $results['cacheable']) {
                    $htmlForCache = $html;
                }
                /*
                 * Session: Find out whether we need to send a cookie & need a new session
                 * (only if we don't have one yet)
                 */
                $session =& $gallery->getSession();
                $ret = $session->start();
                if ($ret) {
                    return array($ret->wrap(__FILE__, __LINE__), null);
                }
                $html = $session->replaceTempSessionIdIfNecessary($html);
                if ($embedded) {
                    $data = $theme->splitHtml($html, $results);
                    $data['themeData'] =& $template->getVariableByReference('theme');
                    $data['isDone'] = false;
                } else {
                    /* Set the appropriate charset in our HTTP header */
                    if (!headers_sent()) {
                        header('Content-Type: text/html; charset=UTF-8');
                    }
                    print $html;
                    if ($shouldCache && $results['cacheable']) {
                        $session =& $gallery->getSession();
                        if ($session->getId() != SESSION_TEMP_ID) {
                            $htmlForCache = str_replace($session->getId(), SESSION_TEMP_ID, $htmlForCache);
                        }
                        $ret = GalleryDataCache::putPageData('page', $results['cacheable'], $urlGenerator->getCacheableUrl(), $htmlForCache);
                        if ($ret) {
                            return array($ret->wrap(__FILE__, __LINE__), null);
                        }
                    }
                    $data['isDone'] = true;
                }
            }
        }
    }
    return array(null, $data);
}
Пример #5
0
<?php

global $_zp_themeroot;
Utils::import('GalleryController');
Utils::import('Overrides');
//required this soon because slideshow plugin outputs unprotected script
Utils::printScripts("slideshow");
$controller = new GalleryController();
?>

<div id="gallery-desc">
	<?php 
printGalleryDesc();
?>
</div>	

<?php 
$controller->printGalleryNav();
?>

<div id="album-wrapper" class="slideshow">
	<div id="album-title">
		<div id="breadcrumb">
		<?php 
$controller->printBreadCrumb(' : Slideshow');
?>
		</div>
	</div>

	<div id="album-description">
		<?php 
<?php

$words = new MOD_words();
$request = PRequest::get()->request;
$gallery_ctrl = new GalleryController();
$image = $this->image;
if ($member = $this->model->getLoggedInMember()) {
    $callbackId = $gallery_ctrl->editProcess($image);
    $vars =& PPostHandler::getVars($callbackId);
}
$GalleryRight = MOD_right::get()->hasRight('Gallery');
$d = $image;
$d->user_handle = MOD_member::getUserHandle($d->user_id_foreign);
$canEdit = $member && $member->Username == $d->user_handle ? true : false;
if (!isset($vars['errors'])) {
    $vars['errors'] = array();
}
Пример #7
0
<?php 
global $_zp_page, $_zp_gallery_page, $_zp_current_album, $_zp_themeroot, $_zp_gallery;
Utils::import('GalleryController');
$controller = new GalleryController();
?>

<div id="gallery-desc">
	<?php 
printGalleryDesc();
?>
</div>	

<?php 
$controller->printGalleryNav();
?>

<div id="album-wrapper">
	<div id="album-title">
		<div id="breadcrumb">
			<?php 
$controller->printBreadCrumb();
?>
			<?php 
echo $controller->getRss();
?>
		</div>
	</div>

	<div id="album-description">
		<?php 
<?php

$words = new MOD_words();
$request = PRequest::get()->request;
$layoutbits = new MOD_layoutbits();
$d = $image = $this->image;
$Gallery = new GalleryModel();
$gallery_ctrl = new GalleryController();
if ($this->model->getLoggedInMember()) {
    $callbackId = $gallery_ctrl->editProcess($image);
    $vars =& PPostHandler::getVars($callbackId);
    $callbackIdCom = $gallery_ctrl->commentProcess($image);
    $varsCom =& PPostHandler::getVars($callbackIdCom);
    $R = MOD_right::get();
    $GalleryRight = $R->hasRight('Gallery');
}
if (!isset($vars['errors'])) {
    $vars['errors'] = array();
}
$Previous = $this->previous;
$Next = $this->next;
$userpic = MOD_layoutbits::PIC_30_30($d->user_handle, '', $style = 'float_left');
echo <<<HTML
    <div class="floatbox" style="padding-top: 30px;">
        {$userpic}
        {$words->flushBuffer()}
        <h3><a href="gallery/show/user/{$image->user_handle}">{$words->getFormatted('galleryUserOthers', $image->user_handle)}</a></h3>
    </div>
HTML;
$UserId = 1;
$SetId = false;
Пример #9
0
<?php

$request = PRequest::get()->request;
$Gallery = new GalleryController();
$callbackId = $Gallery->updateGalleryProcess();
$vars = PPostHandler::getVars($callbackId);
$words = $this->getWords();
$layoutbits = new MOD_layoutbits();
$thumbsize = $this->thumbsize;
echo $words->flushBuffer();
if ($statement) {
    $requestStr = implode('/', $request);
    $matches = array();
    if (preg_match('%/=page(\\d+)%', $requestStr, $matches)) {
        $page = $matches[1];
        $requestStr = preg_replace('%/=page(\\d+)%', '', $requestStr);
    } else {
        $page = 1;
    }
    if (!isset($itemsPerPage)) {
        $itemsPerPage = 12;
    }
    $p = PFunctions::paginate($statement, $page, $itemsPerPage);
    $statement = $p[0];
    foreach ($statement as $d) {
        $title_short = strlen($d->title) >= 26 ? substr($d->title, 0, 25) . '...' : $d->title;
        $d->HTML = '
        <div class="img thumb" style="width: 244px;">
            <a href="gallery/show/image/' . $d->id . '" id="image_link_' . $d->id . '"><img class="framed" src="gallery/thumbimg?id=' . $d->id . ($thumbsize ? '&t=' . $thumbsize : '') . '" alt="image" style="margin: 5px 0; float:none;" /></a>';
        $d->HTML .= '<h4 class="floatbox">';
        if ($this->loggedInMember && $this->loggedInMember->Username == $d->user_handle) {
Пример #10
0
<?php

if ($this->model->getLoggedInMember()) {
    $Gallery = new GalleryController();
    $callbackId = $Gallery->editProcess();
    $vars =& PPostHandler::getVars($callbackId);
}
$words = new MOD_words();
$d = $image;
if ($deleted) {
    echo <<<HTML
    <p class="note"><img src="images/misc/check.gif">&nbsp; &nbsp; {$words->getFormatted('GalleryImageDeleted')}: <i>{$d->title}</i></p>
HTML;
} else {
    echo <<<HTML
    <p class="warning"><img src="images/misc/checkfalse.gif">&nbsp; &nbsp; {$words->getFormatted('GalleryImageNotDeleted')}: <i>{$d->title}</i></p>
HTML;
}
Пример #11
0
/**
 * Process our request.
 * @return array GalleryStatus a status code
 *               array
 */
function _GalleryMain($embedded = false, $template = null)
{
    global $gallery;
    $urlGenerator =& $gallery->getUrlGenerator();
    /* Figure out the target view/controller */
    list($controllerName, $viewName) = GalleryUtilities::getRequestVariables('controller', 'view');
    $controllerName = is_string($controllerName) ? $controllerName : null;
    $viewName = is_string($viewName) ? $viewName : null;
    $gallery->debug("controller {$controllerName}, view {$viewName}");
    /* Check if core module needs upgrading */
    list($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core', true);
    if ($ret) {
        return array($ret, null);
    }
    $installedVersions = $core->getInstalledVersions();
    if ($installedVersions['core'] != $core->getVersion()) {
        if ($redirectUrl = @$gallery->getConfig('mode.maintenance')) {
            /* Maintenance mode - redirect if given URL, else simple message */
            if ($redirectUrl === true) {
                header('Content-Type: text/html; charset=UTF-8');
                print $core->translate('Site is temporarily down for maintenance.');
                exit;
            }
        } else {
            $gallery->debug('Redirect to the upgrade wizard, core module version is out of date');
            $redirectUrl = $urlGenerator->getCurrentUrlDir(true) . 'upgrade/index.php';
        }
        list($ignored, $results) = _GalleryMain_doRedirect($redirectUrl, null, null, true);
        return array(null, $results);
    }
    $ret = GalleryInitSecondPass();
    if ($ret) {
        return array($ret, null);
    }
    /* Load and run the appropriate controller */
    $results = array();
    if (!empty($controllerName)) {
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryController.class');
        list($ret, $controller) = GalleryController::loadController($controllerName);
        if ($ret) {
            return array($ret, null);
        }
        if (!$embedded && $gallery->getConfig('mode.embed.only') && !$controller->isAllowedInEmbedOnly()) {
            /* Lock out direct access when embed-only is set */
            if (($redirectUrl = $gallery->getConfig('mode.embed.only')) === true) {
                return array(GalleryCoreApi::error(ERROR_PERMISSION_DENIED), null);
            }
            list($ignored, $results) = _GalleryMain_doRedirect($redirectUrl, null, null, true);
            return array(null, $results);
        }
        if ($gallery->getConfig('mode.maintenance') && !$controller->isAllowedInMaintenance()) {
            /* Maintenance mode - allow admins, else redirect to given or standard URL */
            list($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
            if ($ret) {
                return array($ret, null);
            }
            if (!$isAdmin) {
                if (($redirectUrl = $gallery->getConfig('mode.maintenance')) === true) {
                    $redirectUrl = $urlGenerator->generateUrl(array('view' => 'core.MaintenanceMode'), array('forceFullUrl' => true));
                }
                list($ignored, $results) = _GalleryMain_doRedirect($redirectUrl, null, null, true);
                return array(null, $results);
            }
        }
        /* Get our form and return variables */
        $form = GalleryUtilities::getFormVariables('form');
        /* Verify the genuineness of the request */
        if (!$controller->omitAuthTokenCheck()) {
            $ret = GalleryController::assertIsGenuineRequest();
            if ($ret) {
                return array($ret, null);
            }
        }
        /* Let the controller handle the input */
        list($ret, $results) = $controller->handleRequest($form);
        if ($ret) {
            list($ret, $results) = $controller->permissionCheck($ret);
            if ($ret) {
                return array($ret, null);
            }
        }
        /* Check to make sure we got back everything we want */
        if (!isset($results['status']) || !isset($results['error']) || !isset($results['redirect']) && !isset($results['delegate']) && !isset($results['return'])) {
            return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__, 'Controller results are missing status, error, (redirect, delegate, return)'), null);
        }
        /* Try to return if the controller instructs it */
        if (!empty($results['return'])) {
            $redirectUrl = GalleryUtilities::getRequestVariables('return');
            if (empty($redirectUrl)) {
                $redirectUrl = GalleryUtilities::getRequestVariables('formUrl');
            }
        }
        /* Failing that, redirect if so instructed */
        if (empty($redirectUrl) && !empty($results['redirect'])) {
            /* If we have a status, store its data in the session */
            if (!empty($results['status'])) {
                $session =& $gallery->getSession();
                $session->putStatus($results['status']);
            }
            $urlToGenerate = $results['redirect'];
            $redirectUrl = $urlGenerator->generateUrl($urlToGenerate, array('forceFullUrl' => true));
        }
        /* If we have a redirect URL use it */
        if (!empty($redirectUrl)) {
            return _GalleryMain_doRedirect($redirectUrl, null, $controllerName);
        }
        /* Let the controller specify the next view */
        if (!empty($results['delegate'])) {
            /* Load any errors into the request */
            if (!empty($results['error'])) {
                foreach ($results['error'] as $error) {
                    GalleryUtilities::putRequestVariable($error, 1);
                }
            }
            /* Save the view name, put the rest into the request so the view can get it */
            foreach ($results['delegate'] as $key => $value) {
                switch ($key) {
                    case 'view':
                        $viewName = $value;
                        break;
                    default:
                        GalleryUtilities::putRequestVariable($key, $value);
                        break;
                }
            }
        }
    }
    /* Load and run the appropriate view */
    if (empty($viewName)) {
        $viewName = GALLERY_DEFAULT_VIEW;
        GalleryUtilities::putRequestVariable('view', $viewName);
    }
    list($ret, $view) = GalleryView::loadView($viewName);
    if ($ret) {
        return array($ret, null);
    }
    if ($gallery->getConfig('mode.maintenance') && !$view->isAllowedInMaintenance()) {
        /* Maintenance mode - allow admins, else redirect to given url or show standard view */
        list($ret, $isAdmin) = GalleryCoreApi::isUserInSiteAdminGroup();
        if ($ret) {
            return array($ret, null);
        }
        if (!$isAdmin) {
            if (($redirectUrl = $gallery->getConfig('mode.maintenance')) !== true) {
                list($ignored, $results) = _GalleryMain_doRedirect($redirectUrl, null, null, true);
                return array(null, $results);
            }
            $viewName = 'core.MaintenanceMode';
            list($ret, $view) = GalleryView::loadView($viewName);
            if ($ret) {
                return array($ret, null);
            }
        }
    }
    if (!$embedded && $gallery->getConfig('mode.embed.only') && !$view->isAllowedInEmbedOnly()) {
        /* Lock out direct access when embed-only is set */
        if (($redirectUrl = $gallery->getConfig('mode.embed.only')) === true) {
            return array(GalleryCoreApi::error(ERROR_PERMISSION_DENIED), null);
        }
        return _GalleryMain_doRedirect($redirectUrl);
    }
    /* Check if the page is cached and return the cached version, else generate the page */
    list($ret, $shouldCache) = GalleryDataCache::shouldCache('read', 'full');
    if ($ret) {
        return array($ret, null);
    }
    $html = '';
    if ($shouldCache) {
        $session =& $gallery->getSession();
        list($ret, $html) = GalleryDataCache::getPageData('page', $urlGenerator->getCacheableUrl());
        if ($ret) {
            return array($ret, null);
        }
        if (!empty($html) && $embedded) {
            /* Also get the theme data */
            list($ret, $themeData) = GalleryDataCache::getPageData('theme', $urlGenerator->getCacheableUrl());
            if ($ret) {
                return array($ret, null);
            }
        }
    }
    if (!empty($html) && (!$embedded || !empty($themeData))) {
        /* TODO: If we cache all the headers and replay them here, we could send a 304 back */
        $session =& $gallery->getSession();
        if (!$embedded) {
            /* Set the appropriate charset in our HTTP header */
            if (!headers_sent()) {
                header('Content-Type: text/html; charset=UTF-8');
            }
            print $session->replaceTempSessionIdIfNecessary($html);
            $data['isDone'] = true;
        } else {
            $html = unserialize($html);
            $themeData = unserialize($themeData);
            $data = $session->replaceSessionIdInData($html);
            $data['themeData'] = $session->replaceSessionIdInData($themeData);
            $data['isDone'] = false;
        }
    } else {
        /* Initialize our container for template data */
        $gallery->setCurrentView($viewName);
        if ($view->isControllerLike()) {
            /* Verify the genuineness of the request */
            $ret = GalleryController::assertIsGenuineRequest();
            if ($ret) {
                return array($ret, null);
            }
        }
        /* If we render directly to the browser, we need a session before, or no session at all */
        if ($view->isImmediate() || $viewName == 'core.ProgressBar') {
            /*
             * Session: Find out whether we need to send a cookie & get a new sessionId and save it
             * (make sure there's a sessionId before starting to render, but only if we need a
             * session)
             */
            $session =& $gallery->getSession();
            $ret = $session->start();
            if ($ret) {
                return array($ret, null);
            }
            /* From now on, don't add sessionId to URLs if there's no persistent session */
            $session->doNotUseTempId();
        }
        /*
         * If this is an immediate view, it will send its own output directly.  This is used in the
         * situation where we want to send back data that's not controlled by the layout.  That's
         * usually something that's not user-visible like a binary file.
         */
        $data = array();
        if ($view->isImmediate()) {
            if ($view->autoCacheControl()) {
                /* r17660 removed the default on the $template parameter */
                $null = null;
                $ret = $view->setCacheControl($null);
                if ($ret) {
                    return array($ret, null);
                }
            }
            $status = isset($results['status']) ? $results['status'] : array();
            $error = isset($results['error']) ? $results['error'] : array();
            $ret = $view->renderImmediate($status, $error);
            if ($ret) {
                list($ret2, $inGroup) = GalleryCoreApi::isUserInSiteAdminGroup();
                if ($ret->getErrorCode() & ERROR_MISSING_OBJECT && ($ret2 || !$inGroup)) {
                    /* Normalize error to GalleryView::_permissionCheck() */
                    $ret->addErrorCode(ERROR_PERMISSION_DENIED);
                }
                return array($ret, null);
            }
            $data['isDone'] = true;
        } else {
            if (!isset($template)) {
                GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class');
                $template = new GalleryTemplate(dirname(__FILE__));
            }
            list($ret, $results, $theme) = $view->doLoadTemplate($template);
            if ($ret) {
                list($ret, $results) = $view->_permissionCheck($ret);
                if ($ret) {
                    return array($ret, null);
                }
            }
            if (isset($results['redirect']) || isset($results['redirectUrl'])) {
                if (isset($results['redirectUrl'])) {
                    $redirectUrl = $results['redirectUrl'];
                } else {
                    $redirectUrl = $urlGenerator->generateUrl($results['redirect'], array('forceFullUrl' => true));
                }
                return _GalleryMain_doRedirect($redirectUrl, $template);
            }
            if (empty($results['body'])) {
                return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__, 'View results are missing body file'), null);
            }
            $templatePath = 'gallery:' . $results['body'];
            $template->setVariable('l10Domain', $theme->getL10Domain());
            $template->setVariable('isEmbedded', $embedded);
            if ($viewName == 'core.ProgressBar') {
                @ini_set('output_buffering', '0');
                /**
                 * Try to prevent Apache's mod_deflate from gzipping the output since that
                 * can interfere with streamed output.
                 */
                if (function_exists('apache_setenv') && !@$gallery->getConfig('apacheSetenvBroken')) {
                    @apache_setenv('no-gzip', '1');
                }
                /* Render progress bar pages immediately so that the user sees the bar moving */
                $ret = $template->display($templatePath);
                if ($ret) {
                    return array($ret, null);
                }
                $data['isDone'] = true;
            } else {
                $event = GalleryCoreApi::newEvent('Gallery::BeforeDisplay');
                $event->setEntity($template);
                $event->setData(array('templatePath' => $templatePath, 'view' => $view));
                list($ret, $ignored) = GalleryCoreApi::postEvent($event);
                if ($ret) {
                    return array($ret, null);
                }
                list($ret, $html) = $template->fetch($templatePath);
                if ($ret) {
                    return array($ret, null);
                }
                /*
                 * Session: Find out whether we need to send a cookie & need a new session (only if
                 * we don't have one yet)
                 */
                $session =& $gallery->getSession();
                $ret = $session->start();
                if ($ret) {
                    return array($ret, null);
                }
                list($ret, $shouldCache) = GalleryDataCache::shouldCache('write', 'full');
                if ($ret) {
                    return array($ret, null);
                }
                if ($embedded) {
                    $html = $theme->splitHtml($html, $results);
                }
                if ($shouldCache && $results['cacheable']) {
                    $htmlForCache = $html;
                    if ($embedded) {
                        $themeDataForCache = $template->getVariable('theme');
                    }
                }
                if ($embedded) {
                    $data = $session->replaceSessionIdInData($html);
                    $data['themeData'] =& $template->getVariableByReference('theme');
                    $data['themeData'] = $session->replaceSessionIdInData($data['themeData']);
                    $data['isDone'] = false;
                } else {
                    /* Set the appropriate charset in our HTTP header */
                    if (!headers_sent()) {
                        header('Content-Type: text/html; charset=UTF-8');
                    }
                    print $session->replaceTempSessionIdIfNecessary($html);
                    $data['isDone'] = true;
                }
                if ($shouldCache && $results['cacheable']) {
                    $session =& $gallery->getSession();
                    $cacheKey = $urlGenerator->getCacheableUrl();
                    $sessionId = $session->getId();
                    if (!empty($sessionId) && $sessionId != SESSION_TEMP_ID) {
                        $htmlForCache = $session->replaceSessionIdInData($htmlForCache, $sessionId, SESSION_TEMP_ID);
                        if ($embedded) {
                            $data['themeData'] = $session->replaceSessionIdInData($data['themeData'], $sessionId, SESSION_TEMP_ID);
                        }
                    }
                    if ($embedded) {
                        $htmlForCache = serialize($htmlForCache);
                        $ret = GalleryDataCache::putPageData('theme', $results['cacheable'], $cacheKey, serialize($data['themeData']));
                        if ($ret) {
                            return array($ret, null);
                        }
                    }
                    $ret = GalleryDataCache::putPageData('page', $results['cacheable'], $cacheKey, $htmlForCache);
                    if ($ret) {
                        return array($ret, null);
                    }
                }
            }
        }
    }
    return array(null, $data);
}
Пример #12
0
 protected function getAlbumImages($start)
 {
     $a = parent::getAlbumImages(0);
     return array_slice($a, ($start - 1) * getOption('images_per_page'), getOption('images_per_page'));
 }