/home/coolpkct/www/websites/cake3.cool.rocks/admin/commands/plupload.php
<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2012, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>');
$sep = DIRECTORY_SEPARATOR;
require_once "commands{$sep}command.php" ;
require_once "classes{$sep}pluploadscreen.php";
require_once "classes{$sep}pagefactory.php";
require_once "classes{$sep}pageset.php";
require_once "classes{$sep}helpers.php";
require_once "classes{$sep}themeset.php";
 
/**
 * Command - Upload
 *
 * @package Showkase
 */
class Plupload extends Command
{
    function doExecute( Request $request )
    {
        $context   = array();
        $pageSet   = new PageSet();
        $pageIndex = $pageSet->getCurrentPageIndex($request);
        $_SESSION['pageIndex'] = $pageIndex;
        $pagePrefs = $pageSet->getPagesPrefs();
        $runtime   = $pagePrefs['uploaderRuntime'];
        $context['resize']              = $pagePrefs['galleryImageResize'];
        $context['maxImageWidth']       = $pagePrefs['galleryMaxImageWidth'];
        $context['maxImageHeight']      = $pagePrefs['galleryMaxImageHeight'];
        $context['compressionQuality']  = $pagePrefs['galleryResizeQuality'];
        $pageRef     = $pageSet->getPageRef($pageIndex);
        $pageType    = $pageSet->getPageType($pageIndex);
        $pagePath    = $pageSet->getPagePath($pageIndex);
        $themeSet    = new ThemeSet();
        $pageFactory = new PageFactory($themeSet);
        $page        = $pageFactory->make($pageType, $pageRef, $pagePath);
        if (!$page->isSupportedPageType()) {
            Board::addMessage('Current theme does not support <i>'.$pageType.'</i> page type.', 'warning');
        }
        if ($request->propertyIsSet('submitResize')) {
            try {
                $pageSet->setPagesPref('galleryImageResize',    $request->propertyIsSet('resizeOn'));
                $pageSet->setPagesPref('galleryMaxImageWidth',  intval($request->getProperty('maxImageWidth')));
                $pageSet->setPagesPref('galleryMaxImageHeight', intval($request->getProperty('maxImageHeight')));
                $pageSet->setPagesPref(
                    'galleryResizeQuality',
                    max(1,
                        min(100,
                            intval(
                                $request->getProperty('compressionQuality')
                            )
                        )
                    )
                );
                $pageSet->savePagesPrefs();
                Board::addMessage('Resize settings saved');
            } catch (Exception $e) {Board::addExceptionMessage($e);}
            // AJAX call no need to print out page
            die(Board::getMessages());
        }
        if ($request->propertyIsSet('runtime')) {
            try {
                $runtime = $request->getProperty('runtime');
                $pageSet->setPagesPref('uploaderRuntime', $runtime);
                $pageSet->savePagesPrefs();
            } catch (Exception $e) {
                Board::addExceptionMessage($e);
            }
        }
        switch ($runtime) {
            case ('flash') :
                $context['runtimes'] = 'flash,html4';
                break;
            case ('html4') :
                $context['runtimes'] = 'html4';
                break;
            default :
                $context['runtimes'] = 'html5,flash,html4';
        }
        $absImagePath = realpath(
            getcwd().DIRECTORY_SEPARATOR.
            $page->gallery->getImageDirPathRelSvm()
        );
        $pageTypes = $themeSet->getPageTypes();
        $context['pageIndex']          = $pageIndex;
        $context['pageRef']            = $pageRef;
        $context['maxUploadMBytes']    = Helpers::getMaxUploadMBytes();
        // Escape backslashes for javascript in windows server paths
        $context['absImagePath']       = str_replace('\\', '\\\\', $absImagePath);
        $context['pagePath']           = str_replace('\\', '\\\\', $pagePath);
        $context['supportedPageType']  = $page->isSupportedPageType();
        $context['pageType']           = $pageType;
        $context['cmd']                = 'plupload';
        $context['h2']  = htmlspecialchars($page->getNavName(), ENT_QUOTES, 'UTF-8');
        $context['h3']  =  '<h3>'.$pageTypes[$pageType]['name'].'</h3>';
        $bbClass        = ucfirst($page->getPluginType().'Buttonbar');
        $screen = new PluploadScreen($bbClass, 'Showkase &ndash; upload images', 'plupload', 'pages plupload '.$pageType);
        print $screen->getHtml($context);
    }
}