Example #1
0
 public function render(\Curry\Backend\AbstractLegacyBackend $backend, array $params)
 {
     $view = $this->view ? $this->view : $this->parentView;
     if (!$view instanceof \Curry_ModelView_List) {
         throw new \Exception('Expected view to be of type Curry_ModelView_List, got ' . get_class($view));
     }
     $view = clone $view;
     // Send response headers to the browser
     $filename = $this->filename ? $this->filename : $view->getOption('title') . ".csv";
     header('Content-Type: text/csv');
     header('Content-Disposition: attachment; filename=' . StringHelper::escapeQuotedString($filename));
     $fp = fopen('php://output', 'w');
     // Print column headers
     $headers = array();
     foreach ($view->getOption('columns') as $name => $opts) {
         // TODO: should we really ignore display/escape option?
         $view->addColumn($name, array('display' => null, 'escape' => false));
         $headers[] = $opts['label'];
     }
     if ($this->includeHeaders) {
         self::fputcsv($fp, $headers);
     }
     // Print rows
     $page = 0;
     $maxPerPage = 100;
     $view->setOptions(array('maxPerPage' => $maxPerPage));
     do {
         $results = $view->getJson(array('p' => ++$page));
         foreach ($results['rows'] as $row) {
             self::fputcsv($fp, $row);
         }
     } while (count($results['rows']) == $maxPerPage);
     fclose($fp);
     exit;
 }
Example #2
0
 /**
  * Create an archive of the project.
  */
 public function showBundle()
 {
     $this->addMainMenu();
     $this->addMessage('You can install this bundle using <a href="' . url('', array('module', 'view' => 'InstallScript')) . '">this installation script</a>.', self::MSG_NOTICE, false);
     $form = new \Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('project' => array('checkbox', array('label' => 'Project', 'value' => true)), 'www' => array('checkbox', array('label' => 'WWW folder', 'value' => true)), 'vendor' => array('checkbox', array('label' => 'Vendor', 'value' => true)), 'database' => array('checkbox', array('label' => 'Database', 'value' => true)), 'compression' => array('select', array('label' => 'Compression', 'multiOptions' => array(Archive::COMPRESSION_NONE => 'None', Archive::COMPRESSION_GZ => 'Gzip'))), 'save' => array('submit', array('label' => 'Create bundle')))));
     if (isPost() && $form->isValid($_POST)) {
         // create archive
         @set_time_limit(0);
         $compression = $form->compression->getValue();
         $tar = new Archive('', $compression);
         // set up file list
         $options = array(array('pattern' => '*.svn*', 'pattern_subject' => 'path', 'skip' => true), array('pattern' => '*.git*', 'pattern_subject' => 'path', 'skip' => true), array('pattern' => '.DS_Store', 'skip' => true), array('pattern' => 'Thumbs.db', 'skip' => true), array('pattern' => '._*', 'skip' => true));
         if ($form->project->isChecked()) {
             $tar->add($this->app['projectPath'], 'cms/', array_merge($options, array(array('path' => 'data/', 'pattern' => 'data/*/*', 'pattern_subject' => 'path', 'skip' => true))));
         }
         if ($form->www->isChecked()) {
             $tar->add($this->app['wwwPath'], 'www/', $options);
         }
         if ($form->vendor->isChecked()) {
             $tar->add($this->app['projectPath'] . '/../vendor', 'vendor/', $options);
         }
         if ($form->database->isChecked()) {
             $fiveMBs = 5 * 1024 * 1024;
             $fp = fopen("php://temp/maxmemory:{$fiveMBs}", 'r+');
             if (!\Curry_Backend_DatabaseHelper::dumpDatabase($fp)) {
                 throw new \Exception('Aborting: There was an error when dumping the database.');
             }
             fseek($fp, 0);
             $tar->addString('db.txt', stream_get_contents($fp));
             fclose($fp);
         }
         $filename = str_replace(" ", "_", $this->app['name']) . "-bundle-" . date("Ymd") . ".tar" . ($compression ? ".{$compression}" : '');
         header("Content-type: " . Archive::getCompressionMimeType($compression));
         header("Content-disposition: attachment; filename=" . StringHelper::escapeQuotedString($filename));
         // do not use output buffering
         while (ob_end_clean()) {
         }
         $tar->stream();
         exit;
     }
     $this->addMainContent($form);
     return parent::render();
 }
Example #3
0
 /**
  * Check if physical path is writable based on FilebrowserAccess.
  *
  * @param string $physical
  * @return bool
  */
 public static function isPhysicalWritable($physical)
 {
     $roots = self::getRoots();
     foreach ($roots as $root) {
         if ($root['writable'] && StringHelper::startsWith($physical . '/', $root['realpath'] . '/')) {
             return true;
         }
     }
     return false;
 }
Example #4
0
 public function render()
 {
     $app = $this->app;
     if ($app->request->query->get('curry_context') == 'main') {
         return Response::create($this->mainContent);
     }
     $twig = $this->getTwig();
     $templateFile = 'backend.html';
     $htmlHead = $this->getHtmlHead();
     $htmlHead->addScript('shared/libs/build/all.min.js');
     $htmlHead->addStylesheet('shared/libs/build/all.css');
     // Globals
     $twig->addGlobal('BaseUrl', $app->request->getBasePath() . '/');
     $twig->addGlobal('ProjectName', $this->app['name']);
     $twig->addGlobal('Encoding', 'utf-8');
     $twig->addGlobal('Version', App::VERSION);
     if ($app['setup']) {
         $user = 1;
     } else {
         $user = \User::getUser();
     }
     if (!$user) {
         $loginRedirect = '';
         if (isset($_POST['login_redirect'])) {
             $loginRedirect = $_POST['login_redirect'];
         } else {
             if (!isset($_GET['logout']) && count($_GET)) {
                 $loginRedirect = (string) url('', $_GET);
             }
         }
         $twig->addGlobal('LoginRedirect', $loginRedirect);
         $this->addBodyClass('tpl-login');
         $templateFile = 'login.html';
         // Finalize HtmlHead and add global
         $twig->addGlobal('HtmlHead', $htmlHead->getContent());
         $twig->addGlobal('BodyClass', $this->getBodyClass());
         $template = $twig->loadTemplate($templateFile);
         return $template->render(array());
     }
     $backendGroups = array('Content' => array(), 'Appearance' => array(), 'Accounts' => array(), 'System' => array());
     foreach ($app->backend->getViews() as $viewName => $view) {
         //if(!$user->hasAccess(get_class($view)))
         //	continue;
         $active = StringHelper::startsWith($app->request->getPathInfo(), '/' . $view->url());
         $group = $view->getGroup();
         $moduleProperties = array('Module' => $viewName, 'Active' => $active, 'Url' => $view->url(), 'Name' => $view->getName(), 'Title' => $view->getMessage(), 'Notifications' => $view->getNotifications());
         if ($group) {
             if (!isset($backendGroups[$group])) {
                 $backendGroups[$group] = array();
             }
             if (!isset($backendGroups[$group]['modules'])) {
                 $backendGroups[$group]['modules'] = array();
             }
             $backendGroups[$group]['modules'][$viewName] = $moduleProperties;
             $backendGroups[$group]['Name'] = $group;
             $backendGroups[$group]['Active'] = $active;
         }
         if ($active) {
             $twig->addGlobal('module', $moduleProperties);
         }
     }
     $twig->addGlobal('moduleGroups', $backendGroups);
     // Finalize HtmlHead and add global
     $twig->addGlobal('HtmlHead', $htmlHead->getContent());
     $twig->addGlobal('BodyClass', $this->getBodyClass());
     // Render template
     $template = $twig->loadTemplate($templateFile);
     return $template->render(array('breadcrumbs' => $this->breadcrumbs, 'commands' => $this->commands, 'menuItems' => $this->menuItems, 'mainContent' => $this->mainContent, 'menuContent' => $this->menuContent));
 }
 /**
  * Return a file to browser and exit. Will set appropriate headers and return the content.
  *
  * @param string $file			Path to file
  * @param string $contentType	The content-type header to send.
  * @param string $filename		Filename to send to browser, uses the basename of $file if not specified.
  * @param bool $exit			Terminate the script after sending the data.
  * @param bool $disableOutputBuffering	Disable output buffering.
  */
 public static function returnFile($file, $contentType = 'application/octet-stream', $filename = '', $exit = true, $disableOutputBuffering = true)
 {
     if (!$filename) {
         $filename = basename($file);
     }
     header('Content-Description: File Transfer');
     header('Content-Transfer-Encoding: binary');
     header('Content-Disposition: attachment; filename=' . StringHelper::escapeQuotedString($filename));
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-type: ' . $contentType);
     header('Content-Length: ' . filesize($file));
     if ($disableOutputBuffering) {
         while (@ob_end_flush()) {
         }
     }
     readfile($file);
     if ($exit) {
         exit;
     }
 }
Example #6
0
 /**
  * Handler for reverse-routing.
  *
  * @param string $path
  * @param string|array $query
  */
 public function reverseRoute(&$path, &$query)
 {
     // remove matching base path
     $baseUrl = URL::getDefaultBaseUrl();
     $basePath = $baseUrl['path'];
     $basePathRemoved = false;
     if (StringHelper::startsWith($path, $basePath) && $path !== '/') {
         $path = substr($path, strlen($basePath));
         $basePathRemoved = true;
     }
     //\Curry_Route_ModelRoute::reverse($path, $query);
     // re-add base path if it was removed
     if ($basePathRemoved) {
         $path = $basePath . $path;
     }
 }
Example #7
0
 /**
  * Backup database.
  */
 public function showBackup()
 {
     $this->showMainMenu();
     $tables = array();
     $selectedTables = array();
     foreach (Propel::getModels() as $package => $classes) {
         $selectedTables = array_merge($selectedTables, array_values($classes));
         $tables[$package] = array();
         foreach ($classes as $table) {
             $tables[$package][$table] = $table;
         }
     }
     $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'elements' => array('tables' => array('multiselect', array('label' => 'Tables', 'multiOptions' => $tables, 'value' => $selectedTables, 'size' => 15)), 'name' => array('text', array('label' => 'Name', 'required' => true, 'value' => 'backup_%Y-%m-%d_%H-%M-%S.txt', 'description' => 'Name of the file, strftime() is used to format the string.')), 'type' => array('radio', array('label' => 'Where do you want to save?', 'multiOptions' => array('online' => 'Save online', 'local' => 'Save to local file'), 'value' => 'online')))));
     $form->addElement('submit', 'Go');
     if (isPost() && ($_POST['tables'] == '*' || $_POST['tables'] == array('*'))) {
         $_POST['tables'] = $selectedTables;
     }
     if (isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         if ($values['type'] == 'local') {
             // dump to temp, stream to client
             $fp = fopen("php://temp", 'r+');
             Curry_Backend_DatabaseHelper::dumpDatabase($fp, $values['tables'], $this);
             rewind($fp);
             $name = StringHelper::getRewriteString($this->app['name']) . '-db.txt';
             self::returnData($fp, 'application/octet-stream', $name);
         } else {
             if ($values['type'] == 'online') {
                 $filename = Curry_Backend_DatabaseHelper::createBackupName($values['name']);
                 $status = Curry_Backend_DatabaseHelper::dumpDatabase($filename, $values['tables'], $this);
                 $this->addMessage('Backup created ' . $filename, $status ? self::MSG_SUCCESS : self::MSG_ERROR);
             }
         }
     }
     $this->addMainContent($form);
 }