public function module($module = null, $task = null) { Loader::model('dashboard/homepage'); $dh = new DashboardHomepageView(); $mod = $dh->getByHandle($module); if ($mod->pkgID > 0) { $pkg = Package::getByID($mod->pkgID); $class = Loader::dashboardModuleController($mod->dbhModule, $pkg); } else { $class = Loader::dashboardModuleController($mod->dbhModule); } $args = func_get_args(); array_shift($args); array_shift($args); // no that's not a misprint if (method_exists($class, $task)) { try { $resp = call_user_func_array(array($class, $task), $args); if ($resp) { $this->set('message', $resp); } } catch(Exception $e) { $this->set('error', $e); } } print $this->view(); }
public function inspect_package($pkgID = 0) { if ($pkgID > 0) { $pkg = Package::getByID($pkgID); } if (isset($pkg) && ($pkg instanceof Package)) { $this->set('pkg', $pkg); } else { $this->redirect('/dashboard/extend/install'); } }
public function output($dbh) { ob_start(); if ($dbh->pkgID > 0) { $pkg = Package::getByID($dbh->pkgID); Loader::dashboardModule($dbh->dbhModule, $pkg); } else { Loader::dashboardModule($dbh->dbhModule); } $content = ob_get_contents(); ob_end_clean(); return $content; }
public function remove($ptID, $token = '') { $v = Loader::helper('validation/error'); try { $valt = Loader::helper('validation/token'); if (!$valt->validate('remove', $token)) { throw new Exception($valt->getErrorMessage()); } $pl = PageTheme::getByID($ptID); if (!is_object($pl)) { throw new Exception(t('Invalid theme.')); } /* if ($pl->getPackageID() > 0) { throw new Exception('You may not uninstall a packaged theme.'); } */ $localUninstall = true; if ($pl->getPackageID() > 0) { // then we check to see if this is the only theme in that package. If so, we uninstall the package too $pkg = Package::getByID($pl->getPackageID()); $items = $pkg->getPackageItems(); if (count($items) == 1) { $_pl = $items[0]; if ($_pl instanceof PageTheme && $_pl->getThemeID() == $ptID) { $pkg->uninstall(); $localUninstall = false; } } } if ($localUninstall) { $pl->uninstall(); } $this->set('message', t('Theme uninstalled.')); } catch (Exception $e) { $v->add($e); $this->set('error', $v); } $this->view(); }
/** * @return Package */ public function install() { PackageList::refreshCache(); $db = Loader::db(); $dh = Loader::helper('date'); $v = array($this->getPackageName(), $this->getPackageDescription(), $this->getPackageVersion(), $this->getPackageHandle(), 1, $dh->getSystemDateTime()); $db->query("insert into Packages (pkgName, pkgDescription, pkgVersion, pkgHandle, pkgIsInstalled, pkgDateInstalled) values (?, ?, ?, ?, ?, ?)", $v); $pkg = Package::getByID($db->Insert_ID()); Package::installDB($pkg->getPackagePath() . '/' . FILENAME_PACKAGE_DB); $env = Environment::get(); $env->clearOverrideCache(); return $pkg; }
<tr> <td colspan="4"> <?php echo t('No pages found.'); ?> </td> </tr> <?php } else { ?> <?php foreach ($generated as $p) { $cp = new Permissions($p); if ($p->getPackageID() > 0) { $package = Package::getByID($p->getPackageID()); if (is_object($package)) { $packageHandle = $package->getPackageHandle(); $packageName = $package->getPackageName(); } } else { $packageName = t('None'); } ?> <tr> <td style="width: 30%"><a href="<?php echo DIR_REL; ?> /<?php echo DISPATCHER_FILENAME; ?>
public function getPackageObject() { return Package::getByID($this->getPackageID()); }
public function refresh() { // takes a generated collection and refreshes it - updates its path, it's cDateModified // it's name, it's permissions if (!$this->isGeneratedCollection()) { return false; } $pkg = Package::getByID($this->getPackageID()); $currentPath = $this->getCollectionPath(); $pathToFile = SinglePage::getPathToNode($currentPath, $pkg); $pxml = SinglePage::obtainPermissionsXML($currentPath, $pkg); $txt = Loader::helper('text'); $data = array(); $data['cName'] = $txt->unhandle($this->getCollectionHandle()); $data['cFilename'] = $pathToFile; $this->update($data); if ($pxml) { $this->assignPermissionSet($pxml); // pass it an array } }
/** * render takes one argument - the item being rendered - and it can either be a path or a page object * @access public * @param string $view * @param array $args * @return void */ public function render($view, $args = null) { if (is_array($args)) { extract($args); } // strip off a slash if there is one at the end if (is_string($view)) { if (substr($view, strlen($view) - 1) == '/') { $view = substr($view, 0, strlen($view) - 1); } } $dsh = Loader::helper('concrete/dashboard'); $wrapTemplateInTheme = false; $this->checkMobileView(); if (defined('DB_DATABASE') && $view !== '/upgrade') { Events::fire('on_start', $this); } // Extract controller information from the view, and put it in the current context if (!isset($this->controller)) { $this->controller = Loader::controller($view); $this->controller->setupAndRun(); } if ($this->controller->getRenderOverride() != '') { $view = $this->controller->getRenderOverride(); } // Determine which inner item to load, load it, and stick it in $innerContent $content = false; ob_start(); if ($view instanceof Page) { $_pageBlocks = $view->getBlocks(); if (!$dsh->inDashboard()) { $_pageBlocksGlobal = $view->getGlobalBlocks(); $_pageBlocks = array_merge($_pageBlocks, $_pageBlocksGlobal); } // do we have any custom menu plugins? $cp = new Permissions($view); if ($cp->canViewToolbar()) { $ih = Loader::helper('concrete/interface/menu'); $_interfaceItems = $ih->getPageHeaderMenuItems(); foreach ($_interfaceItems as $_im) { $_controller = $_im->getController(); $_controller->outputAutoHeaderItems(); } unset($_interfaceItems); unset($_im); unset($_controller); } unset($_interfaceItems); unset($_im); unset($_controller); // now, we output all the custom style records for the design tab in blocks/areas on the page $c = $this->getCollectionObject(); $view->outputCustomStyleHeaderItems(); $viewPath = $view->getCollectionPath(); $this->viewPath = $viewPath; $cFilename = $view->getCollectionFilename(); $ctHandle = $view->getCollectionTypeHandle(); $editMode = $view->isEditMode(); $c = $view; $this->c = $c; $env = Environment::get(); // $view is a page. It can either be a SinglePage or just a Page, but we're not sure at this point, unfortunately if ($view->getCollectionTypeID() == 0 && $cFilename) { $wrapTemplateInTheme = true; $cFilename = trim($cFilename, '/'); $content = $env->getPath(DIRNAME_PAGES . '/' . $cFilename, $view->getPackageHandle()); $themeFilename = $c->getCollectionHandle() . '.php'; } else { $rec = $env->getRecord(DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php', $view->getPackageHandle()); if ($rec->exists()) { $wrapTemplateInTheme = true; $content = $rec->file; } $themeFilename = $ctHandle . '.php'; } } else { if (is_string($view)) { // if we're passing a view but our render override is not null, that means that we're passing // a new view from within a controller. If that's the case, then we DON'T override the viewPath, we want to keep it // In order to enable editable 404 pages, other editable pages that we render without actually visiting if (defined('DB_DATABASE') && $view == '/page_not_found') { $pp = Page::getByPath($view); if (!$pp->isError()) { $this->c = $pp; } } $viewPath = $view; if ($this->controller->getRenderOverride() != '' && $this->getCollectionObject() != null) { // we are INSIDE a collection renderring a view. Which means we want to keep the viewPath that of the collection $this->viewPath = $this->getCollectionObject()->getCollectionPath(); } // we're just passing something like "/login" or whatever. This will typically just be // internal Concrete stuff, but we also prepare for potentially having something in DIR_FILES_CONTENT (ie: the webroot) if (file_exists(DIR_FILES_CONTENT . "/{$view}/" . FILENAME_COLLECTION_VIEW)) { $content = DIR_FILES_CONTENT . "/{$view}/" . FILENAME_COLLECTION_VIEW; } else { if (file_exists(DIR_FILES_CONTENT . "/{$view}.php")) { $content = DIR_FILES_CONTENT . "/{$view}.php"; } else { if (file_exists(DIR_FILES_CONTENT_REQUIRED . "/{$view}/" . FILENAME_COLLECTION_VIEW)) { $content = DIR_FILES_CONTENT_REQUIRED . "/{$view}/" . FILENAME_COLLECTION_VIEW; } else { if (file_exists(DIR_FILES_CONTENT_REQUIRED . "/{$view}.php")) { $content = DIR_FILES_CONTENT_REQUIRED . "/{$view}.php"; } else { if ($this->getCollectionObject() != null && $this->getCollectionObject()->isGeneratedCollection() && $this->getCollectionObject()->getPackageID() > 0) { //This is a single_page associated with a package, so check the package views as well $pagePkgPath = Package::getByID($this->getCollectionObject()->getPackageID())->getPackagePath(); if (file_exists($pagePkgPath . "/single_pages/{$view}/" . FILENAME_COLLECTION_VIEW)) { $content = $pagePkgPath . "/single_pages/{$view}/" . FILENAME_COLLECTION_VIEW; } else { if (file_exists($pagePkgPath . "/single_pages/{$view}.php")) { $content = $pagePkgPath . "/single_pages/{$view}.php"; } } } } } } } $wrapTemplateInTheme = true; $themeFilename = $view . '.php'; } } if (is_object($this->c)) { $c = $this->c; if (defined('DB_DATABASE') && ($view == '/page_not_found' || $view == '/login')) { $view = $c; $req = Request::get(); $req->setCurrentPage($c); $_pageBlocks = $view->getBlocks(); $_pageBlocksGlobal = $view->getGlobalBlocks(); $_pageBlocks = array_merge($_pageBlocks, $_pageBlocksGlobal); } } if (is_array($_pageBlocks)) { foreach ($_pageBlocks as $b1) { $b1p = new Permissions($b1); if ($b1p->canRead()) { $btc = $b1->getInstance(); // now we inject any custom template CSS and JavaScript into the header if ('Controller' != get_class($btc)) { $btc->outputAutoHeaderItems(); } $btc->runTask('on_page_view', array($view)); } } } // Determine which outer item/theme to load // obtain theme information for this collection if (isset($this->themeOverride)) { $theme = $this->themeOverride; } else { if ($this->controller->theme != false) { $theme = $this->controller->theme; } else { if (($tmpTheme = $this->getThemeFromPath($viewPath)) != false) { $theme = $tmpTheme; } else { if (is_object($this->c) && ($tmpTheme = $this->c->getCollectionThemeObject()) != false) { $theme = $tmpTheme; } else { $theme = FILENAME_COLLECTION_DEFAULT_THEME; } } } } $this->setThemeForView($theme, $themeFilename, $wrapTemplateInTheme); // finally, we include the theme (which was set by setTheme and will automatically include innerContent) // disconnect from our db and exit $this->controller->on_before_render(); extract($this->controller->getSets()); extract($this->controller->getHelperObjects()); if ($content != false && !$this->disableContentInclude) { include $content; } $innerContent = ob_get_contents(); if (ob_get_level() > OB_INITIAL_LEVEL) { ob_end_clean(); } if (defined('DB_DATABASE') && $view !== '/upgrade') { Events::fire('on_before_render', $this); } if (defined('APP_CHARSET')) { header("Content-Type: text/html; charset=" . APP_CHARSET); } if (file_exists($this->theme)) { $cache = PageCache::getLibrary(); $shouldAddToCache = $cache->shouldAddToCache($this); if ($shouldAddToCache) { $cache->outputCacheHeaders($c); } ob_start(); include $this->theme; $pageContent = ob_get_contents(); ob_end_clean(); $ret = Events::fire('on_page_output', $pageContent); if ($ret != '') { print $ret; $pageContent = $ret; } else { print $pageContent; } $cache = PageCache::getLibrary(); if ($shouldAddToCache) { $cache->set($c, $pageContent); } } else { throw new Exception(t('File %s not found. All themes need default.php and view.php files in them. Consult concrete5 documentation on how to create these files.', $this->theme)); } if (defined('DB_DATABASE') && $view !== '/upgrade') { Events::fire('on_render_complete', $this); } if (ob_get_level() == OB_INITIAL_LEVEL) { require DIR_BASE_CORE . '/startup/jobs.php'; require DIR_BASE_CORE . '/startup/shutdown.php'; exit; } }
/** * render takes one argument - the item being rendered - and it can either be a path or a page object * @access public * @param string $view * @param array $args * @return void */ public function render($view, $args = null) { try { if (is_array($args)) { extract($args); } // strip off a slash if there is one at the end if (is_string($view)) { if (substr($view, strlen($view) - 1) == '/') { $view = substr($view, 0, strlen($view) - 1); } } $wrapTemplateInTheme = false; Events::fire('on_start', $this); // Extract controller information from the view, and put it in the current context if (!isset($this->controller)) { $this->controller = Loader::controller($view); $this->controller->setupAndRun(); } if ($this->controller->getRenderOverride() != '') { $view = $this->controller->getRenderOverride(); } // Determine which inner item to load, load it, and stick it in $innerContent $content = false; ob_start(); if ($view instanceof Page) { $viewPath = $view->getCollectionPath(); $this->viewPath = $viewPath; $cFilename = $view->getCollectionFilename(); $ctHandle = $view->getCollectionTypeHandle(); $editMode = $view->isEditMode(); $c = $view; $this->c = $c; // $view is a page. It can either be a SinglePage or just a Page, but we're not sure at this point, unfortunately if ($view->getCollectionTypeID() == 0 && $cFilename) { $wrapTemplateInTheme = true; if (file_exists(DIR_FILES_CONTENT. "{$cFilename}")) { $content = DIR_FILES_CONTENT. "{$cFilename}"; } else if ($view->getPackageID() > 0) { $file1 = DIR_PACKAGES . '/' . $view->getPackageHandle() . '/'. DIRNAME_PAGES . $cFilename; $file2 = DIR_PACKAGES_CORE . '/' . $view->getPackageHandle() . '/'. DIRNAME_PAGES . $cFilename; if (file_exists($file1)) { $content = $file1; } else if (file_exists($file2)) { $content = $file2; } } else if (file_exists(DIR_FILES_CONTENT_REQUIRED . "{$cFilename}")) { $content = DIR_FILES_CONTENT_REQUIRED. "{$cFilename}"; } $themeFilename = $c->getCollectionHandle() . '.php'; } else { if (file_exists(DIR_BASE . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php')) { $content = DIR_BASE . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php'; $wrapTemplateInTheme = true; } else if (file_exists(DIR_BASE_CORE. '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php')) { $content = DIR_BASE_CORE . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php'; $wrapTemplateInTheme = true; } else if ($view->getPackageID() > 0) { $file1 = DIR_PACKAGES . '/' . $view->getPackageHandle() . '/'. DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php'; $file2 = DIR_PACKAGES_CORE . '/' . $view->getPackageHandle() . '/'. DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php'; if (file_exists($file1)) { $content = $file1; $wrapTemplateInTheme = true; } else if (file_exists($file2)) { $content = $file2; $wrapTemplateInTheme = true; } } $themeFilename = $ctHandle . '.php'; } } else if (is_string($view)) { // if we're passing a view but our render override is not null, that means that we're passing // a new view from within a controller. If that's the case, then we DON'T override the viewPath, we want to keep it // In order to enable editable 404 pages, other editable pages that we render without actually visiting if (defined('DB_DATABASE') && $view == '/page_not_found') { $pp = Page::getByPath($view); if (!$pp->isError()) { $this->c = $pp; } } $viewPath = $view; if ($this->controller->getRenderOverride() != '' && $this->getCollectionObject() != null) { // we are INSIDE a collection renderring a view. Which means we want to keep the viewPath that of the collection $this->viewPath = $this->getCollectionObject()->getCollectionPath(); } // we're just passing something like "/login" or whatever. This will typically just be // internal Concrete stuff, but we also prepare for potentially having something in DIR_FILES_CONTENT (ie: the webroot) if (file_exists(DIR_FILES_CONTENT . "/{$view}/" . FILENAME_COLLECTION_VIEW)) { $content = DIR_FILES_CONTENT . "/{$view}/" . FILENAME_COLLECTION_VIEW; } else if (file_exists(DIR_FILES_CONTENT . "/{$view}.php")) { $content = DIR_FILES_CONTENT . "/{$view}.php"; } else if (file_exists(DIR_FILES_CONTENT_REQUIRED . "/{$view}/" . FILENAME_COLLECTION_VIEW)) { $content = DIR_FILES_CONTENT_REQUIRED . "/{$view}/" . FILENAME_COLLECTION_VIEW; } else if (file_exists(DIR_FILES_CONTENT_REQUIRED . "/{$view}.php")) { $content = DIR_FILES_CONTENT_REQUIRED . "/{$view}.php"; } else if ($this->getCollectionObject() != null && $this->getCollectionObject()->isGeneratedCollection() && $this->getCollectionObject()->getPackageID() > 0) { //This is a single_page associated with a package, so check the package views as well $pagePkgPath = Package::getByID($this->getCollectionObject()->getPackageID())->getPackagePath(); if (file_exists($pagePkgPath . "/single_pages/{$view}/" . FILENAME_COLLECTION_VIEW)) { $content = $pagePkgPath . "/single_pages/{$view}/" . FILENAME_COLLECTION_VIEW; } else if (file_exists($pagePkgPath . "/single_pages/{$view}.php")) { $content = $pagePkgPath . "/single_pages/{$view}.php"; } } $wrapTemplateInTheme = true; $themeFilename = $view . '.php'; } if (is_object($this->c)) { $c = $this->c; if (defined('DB_DATABASE') && $view == '/page_not_found') { $view = $c; $req = Request::get(); $req->setCurrentPage($c); } } // Determine which outer item/theme to load // obtain theme information for this collection if (isset($this->themeOverride)) { $theme = $this->themeOverride; } else if ($this->controller->theme != false) { $theme = $this->controller->theme; } else if (($tmpTheme = $this->getThemeFromPath($viewPath)) != false) { $theme = $tmpTheme; } else if (is_object($this->c) && ($tmpTheme = $this->c->getCollectionThemeObject()) != false) { $theme = $tmpTheme; } else { $theme = FILENAME_COLLECTION_DEFAULT_THEME; } $this->setThemeForView($theme, $themeFilename, $wrapTemplateInTheme); // Now, if we're on an actual page, we retrieve all the blocks on the page // and store their view states in the local cache (for the page). That way // we can add header items and have them show up in the header BEFORE // the block itself is actually loaded if ($view instanceof Page) { $_pageBlocks = $view->getBlocks(); $_pageBlocksGlobal = $view->getGlobalBlocks(); $_pageBlocks = array_merge($_pageBlocks, $_pageBlocksGlobal); if ($view->supportsPageCache($_pageBlocks, $this->controller)) { $pageContent = $view->getFromPageCache(); if ($pageContent != false) { Events::fire('on_before_render', $this); if (defined('APP_CHARSET')) { header("Content-Type: text/html; charset=" . APP_CHARSET); } print($pageContent); Events::fire('on_render_complete', $this); if (ob_get_level() == OB_INITIAL_LEVEL) { require(DIR_BASE_CORE . '/startup/shutdown.php'); exit; } return; } } foreach($_pageBlocks as $b1) { $btc = $b1->getInstance(); // now we inject any custom template CSS and JavaScript into the header if('Controller' != get_class($btc)){ $btc->outputAutoHeaderItems(); } $btc->runTask('on_page_view', array($view)); } // do we have any custom menu plugins? $cp = new Permissions($view); if ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage() || $cp->canApproveCollection()) { $ih = Loader::helper('concrete/interface/menu'); $_interfaceItems = $ih->getPageHeaderMenuItems(); foreach($_interfaceItems as $_im) { $_controller = $_im->getController(); $_controller->outputAutoHeaderItems(); } unset($_interfaceItems); unset($_im); unset($_controller); } unset($_interfaceItems); unset($_im); unset($_controller); // now, we output all the custom style records for the design tab in blocks/areas on the page $c = $this->getCollectionObject(); $view->outputCustomStyleHeaderItems(); } // finally, we include the theme (which was set by setTheme and will automatically include innerContent) // disconnect from our db and exit $this->controller->on_before_render(); extract($this->controller->getSets()); extract($this->controller->getHelperObjects()); if ($content != false) { include($content); } $innerContent = ob_get_contents(); if (ob_get_level() > OB_INITIAL_LEVEL) { ob_end_clean(); } Events::fire('on_before_render', $this); if (defined('APP_CHARSET')) { header("Content-Type: text/html; charset=" . APP_CHARSET); } if (file_exists($this->theme)) { ob_start(); include($this->theme); $pageContent = ob_get_contents(); ob_end_clean(); $ret = Events::fire('on_page_output', $pageContent); if($ret != '') { print $ret; } else { print $pageContent; } if ($view instanceof Page) { if ($view->supportsPageCache($_pageBlocks, $this->controller)) { $view->addToPageCache($pageContent); } } } else { throw new Exception(t('File %s not found. All themes need default.php and view.php files in them. Consult concrete5 documentation on how to create these files.', $this->theme)); } Events::fire('on_render_complete', $this); if (ob_get_level() == OB_INITIAL_LEVEL) { require(DIR_BASE_CORE . '/startup/shutdown.php'); exit; } } catch(ADODB_Exception $e) { // if it's a database exception we go here. if (Config::get('SITE_DEBUG_LEVEL') == DEBUG_DISPLAY_ERRORS) { $this->renderError(t('An unexpected error occurred.'), $e->getMessage(), $e); } else { $this->renderError(t('An unexpected error occurred.'), t('A database error occurred while processing this request.'), $e); } // log if setup to do so if (ENABLE_LOG_ERRORS) { $l = new Log(LOG_TYPE_EXCEPTIONS, true, true); $l->write(t('Exception Occurred: ') . $e->getMessage()); $l->write($e->getTraceAsString()); $l->close(); } } catch (Exception $e) { $this->renderError(t('An unexpected error occurred.'), $e->getMessage(), $e); // log if setup to do so if (ENABLE_LOG_ERRORS) { $l = new Log(LOG_TYPE_EXCEPTIONS, true, true); $l->write(t('Exception Occurred: ') . $e->getMessage()); $l->write($e->getTraceAsString()); $l->close(); } } }
/** * refreshes the BlockType's database schema throws an Exception if error * @return void */ public function refresh() { if ($this->getPackageID() > 0) { $pkg = Package::getByID($this->getPackageID()); $resp = BlockType::installBlockTypeFromPackage($this->getBlockTypeHandle(), $pkg, $this->getBlockTypeID()); if ($resp != '') { throw new Exception($resp); } } else { $resp = BlockType::installBlockType($this->getBlockTypeHandle(), $this->getBlockTypeID()); if ($resp != '') { throw new Exception($resp); } } }
public static function exportList($x) { $nconfig = $x->addChild('config'); $db = Loader::db(); $r = $db->Execute("select cfKey, cfValue, pkgID from Config where uID = 0 and cfKey not in ('SITE','SITE_APP_VERSION','SEEN_INTRODUCTION')"); while ($row = $r->FetchRow()) { $option = $nconfig->addChild($row['cfKey'], $row['cfValue']); if ($row['pkgID'] > 0) { $pkg = Package::getByID($row['pkgID']); if (is_object($pkg)) { $option->addAttribute('package', $pkg->getPackageHandle()); } } } }
public function package_installed($pkgID = 0) { $this->set('message', t('The package has been installed.')); $this->set('installedPKG', Package::getByID($pkgID)); }