/** * Show package grid json. */ public function showJson() { $entries = array(); foreach (Curry_PackageManager::getPackages() as $packageInfo) { $packageInfo = array_shift($packageInfo); $installedPackage = PackageQuery::create()->findPk($packageInfo['name']); $hasUpgrade = $installedPackage ? version_compare($installedPackage->getVersion(), $packageInfo['version']) < 0 : false; $icon = '<img src="shared/images/icons/' . ($hasUpgrade ? 'package_go' : 'package') . '.png" alt="" title="' . ($hasUpgrade ? 'You can upgrade this package' : 'This package is up to date') . '" /> '; $entries[] = array('id' => $packageInfo['name'], 'cell' => array($icon, $packageInfo['name'], $installedPackage ? $installedPackage->getVersion() : 'Not installed', $packageInfo['version'], isset($packageInfo['filesize']) ? Curry_Util::humanReadableBytes($packageInfo['filesize']) : 'n/a', $packageInfo['summary'])); } $this->returnJson(array('page' => 1, 'total' => count($entries), 'rows' => $entries)); }
/** * Insert module and return generated content. * * @param Curry_PageModuleWrapper $pageModuleWrapper * @return string */ protected function insertModule(Curry_PageModuleWrapper $pageModuleWrapper) { Curry_Core::log(($pageModuleWrapper->getEnabled() ? 'Inserting' : 'Skipping') . ' module "' . $pageModuleWrapper->getName() . '" of type "' . $pageModuleWrapper->getClassName() . '" with target "' . $pageModuleWrapper->getTarget() . '"'); if (!$pageModuleWrapper->getEnabled()) { return ""; } $cached = false; $devMode = Curry_Core::$config->curry->developmentMode; if ($devMode) { $time = microtime(true); $sqlQueries = Curry_Propel::getQueryCount(); $userTime = Curry_Util::getCpuTime('u'); $systemTime = Curry_Util::getCpuTime('s'); $memoryUsage = memory_get_usage(true); } $this->moduleCache = array(); $module = $pageModuleWrapper->createObject(); $module->setPageGenerator($this); $cp = $module->getCacheProperties(); $cacheName = $this->getModuleCacheName($pageModuleWrapper, $module); // try to use cached content if ($cp !== null && ($cache = Curry_Core::$cache->load($cacheName)) !== false) { $cached = true; $this->insertCachedModule($cache); $content = $cache['content']; } else { $template = null; if ($pageModuleWrapper->getTemplate()) { $template = Curry_Twig_Template::loadTemplate($pageModuleWrapper->getTemplate()); } else { if ($module->getDefaultTemplate()) { $template = Curry_Twig_Template::loadTemplateString($module->getDefaultTemplate()); } } if ($template && $template->getEnvironment()) { $twig = $template->getEnvironment(); $twig->addGlobal('module', array('Id' => $pageModuleWrapper->getPageModuleId(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Name' => $pageModuleWrapper->getName(), 'ModuleDataId' => $pageModuleWrapper->getModuleDataId(), 'Target' => $pageModuleWrapper->getTarget())); } $content = (string) $module->showFront($template); if ($cp !== null) { $this->moduleCache['content'] = $content; $this->saveModuleCache($cacheName, $cp->getLifetime()); } } if ($devMode) { $time = microtime(true) - $time; $userTime = Curry_Util::getCpuTime('u') - $userTime; $systemTime = Curry_Util::getCpuTime('s') - $systemTime; $memoryUsage = memory_get_usage(true) - $memoryUsage; $sqlQueries = $sqlQueries !== null ? Curry_Propel::getQueryCount() - $sqlQueries : null; $cpuLimit = Curry_Core::$config->curry->debug->moduleCpuLimit; $timeLimit = Curry_Core::$config->curry->debug->moduleTimeLimit; $memoryLimit = Curry_Core::$config->curry->debug->moduleMemoryLimit; $sqlLimit = Curry_Core::$config->curry->debug->moduleSqlLimit; if ($userTime + $systemTime > $cpuLimit || $time > $timeLimit) { trace_warning('Module generation time exceeded limit'); } if ($memoryUsage > $memoryLimit) { trace_warning('Module memory usage exceeded limit'); } if ($sqlQueries > $sqlLimit) { trace_warning('Module sql query count exceeded limit'); } // add module debug info $this->moduleDebugInfo[] = array($pageModuleWrapper->getName(), $pageModuleWrapper->getClassName(), $pageModuleWrapper->getTemplate(), $pageModuleWrapper->getTarget(), $cached, round($time * 1000.0), round(($userTime + $systemTime) * 1000.0), Curry_Util::humanReadableBytes($memoryUsage), Curry_Util::humanReadableBytes(memory_get_peak_usage(true)), $sqlQueries !== null ? $sqlQueries : 'n/a'); } return $content; }
/** * Shutdown function to execute at the end of the request. This function * is called automatically so there is no need to call it explicitly. */ public static function shutdown() { $error = error_get_last(); if ($error !== null && $error['type'] == E_ERROR) { $e = new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']); self::showException($e); } if (self::$logger) { self::$throwExceptionsOnError = false; $queryCount = Curry_Propel::getQueryCount(); $generationTime = self::getExecutionTime(); self::log("Generation time: " . round($generationTime, 3) . "s", Zend_Log::NOTICE); self::log("Peak memory usage: " . Curry_Util::humanReadableBytes(memory_get_peak_usage()), Zend_Log::NOTICE); self::log("SQL query count: " . ($queryCount !== null ? $queryCount : 'n/a'), Zend_Log::NOTICE); if (self::$writer instanceof Zend_Log_Writer_Firebug && !headers_sent()) { // Flush log data to browser $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance(); $response = $channel->getResponse(); $channel->flush(); //$response->sendHeaders(); // send headers manually so http status (3xx) doesn't get overridden foreach ($response->getRawHeaders() as $header) { header($header); } foreach ($response->getHeaders() as $header) { header($header['name'] . ': ' . $header['value'], $header['replace']); } } } }
/** * Get file details. * * @param array $selected * @return array */ public function getFileInfo($selected) { if (count($selected) == 1) { try { $path = $selected[0]; $physical = self::virtualToPhysical($path); $public = self::physicalToPublic($physical); if (!is_file($physical)) { return null; } $owner = fileowner($physical); if (function_exists('posix_getpwuid')) { $owner = posix_getpwuid($owner); $owner = '<span title="' . $owner['uid'] . '">' . htmlspecialchars($owner['name']) . '</span>'; } $group = filegroup($physical); if (function_exists('posix_getgrgid')) { $group = posix_getgrgid($group); $group = '<span title="' . $group['gid'] . '">' . htmlspecialchars($group['name']) . '</span>'; } $fi = array('Name' => '<h2>' . basename($physical) . '</h2>', 'Preview' => '', 'Size' => '<strong>Size: </strong>' . Curry_Util::humanReadableBytes(filesize($physical)), 'Writable' => '<strong>Writable: </strong>' . (self::isWritable($physical) ? 'Yes' : 'No'), 'Permissions' => '<strong>Permissions: </strong>' . Curry_Util::getFilePermissions($physical), 'Owner' => '<strong>Owner: </strong>' . $owner . ' / ' . $group); switch (strtolower(pathinfo($physical, PATHINFO_EXTENSION))) { case 'jpg': case 'gif': case 'png': case 'bmp': $image = getimagesize($physical); $fi['Preview'] = '<img src="' . $public . '?' . filemtime($physical) . '" alt="" class="preview" />'; if ($image[0] > 240 || $image[1] > 240) { $fi['Preview'] = '<a href="' . $public . '?' . filemtime($physical) . '" target="_blank" class="fullscreen-preview" title="Click to toggle fullscreen">' . $fi['Preview'] . '</a>'; } $fi['Dimensions'] = '<strong>Dimension: </strong>' . $image[0] . 'x' . $image[1]; if (self::isPhysicalWritable($physical)) { $fi['Actions'] = '<a href="' . url('', array('module', 'view' => 'PixlrEdit', 'image' => $public)) . '" class="dialog" onclick="$(this).data(\'dialog\').width = $(window).width() - 20; $(this).data(\'dialog\').height = $(window).height() - 20;" data-dialog=\'{"width":"90%","height":600,"resizable":false,"draggable":false}\'>Edit with Pixlr</a>'; } break; case 'ogg': case 'ogv': case 'mp4': case 'webm': $fi['Preview'] = '<video src="' . $public . '" class="preview" controls />'; break; case 'mp3': case 'oga': case 'wav': $fi['Preview'] = '<audio src="' . $public . '" class="preview" controls />'; break; case 'swf': $size = getimagesize($physical); $flash = Curry_Flash::embed(Curry_Flash::SWFOBJECT_STATIC, $public, $size[0], $size[1], '9.0.0', array()); $fi['Preview'] = $flash['html']; break; } return $fi; } catch (Exception $e) { trace_error($e->getMessage()); } } else { $totalSize = 0; foreach ($selected as $s) { $physical = self::virtualToPhysical($s); $totalSize += filesize($physical); } return array('Name' => '<h2>' . count($selected) . ' files</h2>', 'Size' => '<strong>Size: </strong>' . Curry_Util::humanReadableBytes($totalSize)); } return null; }
/** * Restore database. */ public function showRestore() { $this->showMainMenu(); $tables = array(); $selectedTables = array(); $disabledTables = array(); foreach (Curry_Propel::getModels() as $package => $classes) { $tables[$package] = array(); foreach ($classes as $table) { $tables[$package][$table] = $table; if (method_exists($table, 'save')) { $selectedTables[] = $table; } else { $disabledTables[] = $table; } } } $files = array('' => '-- Select file --', 'upload' => '[ Upload from computer ]', 'remote' => '[ From remote server ]'); $path = Curry_Backend_DatabaseHelper::createBackupName('*.txt'); foreach (array_reverse(glob($path)) as $file) { $files[$file] = basename($file) . ' (' . Curry_Util::humanReadableBytes(filesize($file)) . ')'; } $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'enctype' => 'multipart/form-data', 'elements' => array('tables' => array('multiselect', array('label' => 'Tables', 'multiOptions' => $tables, 'value' => $selectedTables, 'disable' => $disabledTables, 'size' => 15)), 'file' => array('select', array('label' => 'From file', 'multiOptions' => $files, 'class' => 'trigger-change', 'onchange' => "\$('#uploadfile-label').next().andSelf()[this.value == 'upload'?'show':'hide']();" . "\$('#remote-label').next().andSelf()[this.value == 'remote'?'show':'hide']();")), 'uploadfile' => array('file', array('label' => 'Upload file', 'valueDisabled' => true)), 'remote' => array('text', array('label' => 'Remote')), 'max_execution_time' => array('text', array('label' => 'Max execution time', 'value' => '', 'description' => 'Input time in seconds to allow interruption if the time taken to restore would exceed the maximum execution time.'))))); $form->addElement('submit', 'Go'); if (isPost() && $form->isValid($_POST)) { if ($form->file->getValue() == 'upload') { if (!$form->uploadfile->isUploaded()) { throw new Exception('No file was uploaded.'); } $fileinfo = $form->uploadfile->getFileInfo(); Curry_Backend_DatabaseHelper::restoreFromFile($fileinfo['uploadfile']['tmp_name'], $form->tables->getValue(), 0, 0, $this); } else { if ($form->file->getValue() == 'remote') { if (!$form->remote->getValue()) { throw new Exception('No remote URL set'); } $url = url($form->remote->getValue()); $post = array('login_username' => $url->getUser(), 'login_password' => $url->getPassword(), 'tables' => '*', 'name' => 'db.txt', 'type' => 'local'); $url->setUser(null)->setPassword(null)->setPath('/admin.php')->add(array('module' => 'Curry_Backend_Database', 'view' => 'Backup')); $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query($post)))); $fp = fopen($url, 'r', false, $context); Curry_Backend_DatabaseHelper::restoreFromFile($fp, $form->tables->getValue(), 0, 0, $this); fclose($fp); } else { if ($form->file->getValue()) { Curry_Backend_DatabaseHelper::restoreFromFile($form->file->getValue(), $form->tables->getValue(), (int) $form->max_execution_time->getValue(), 0, $this); } } } } $this->addMainContent($form); }