public function downloadAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $config = Knowledgeroot_Registry::get('config'); // action body // normal download // with x-sendfile // @see: http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/ // @see: http://redmine.lighttpd.net/projects/1/wiki/X-LIGHTTPD-send-file // @see: http://wiki.nginx.org/XSendfile $file = new Knowledgeroot_File($this->_getParam('id')); // check acl if (!Knowledgeroot_Acl::iAmAllowed('content_' . $file->getParent(), 'show')) { $this->_redirect(''); } // check for sendfile option if ($config->files->xsendfile->enable) { header("Content-Disposition: attachment; filename=\"" . $file->getName() . "\";"); header($config->files->xsendfile->name . ": " . $file->getDatastorePath()); } else { header("Content-Type: " . $file->getType() . "; name=\"" . $file->getName() . "\""); header("Content-Disposition: attachment; filename=\"" . $file->getName() . "\";"); header("Pragma: private"); header("Expires: 0"); header("Cache-Control: private, must-revalidate, post-check=0, pre-check=0"); header("Content-Transfer-Encoding: binary"); // put file content to screen echo $file->getContent(); } }
public function languageAction() { // get translate object $translate = Knowledgeroot_Registry::get('translate'); // set locale $translate->setLocale($this->getRequest()->getParam('language'), true); // redirect $this->_redirect('./'); }
public function saveAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $acl = Knowledgeroot_Registry::get('acl'); $params = $this->getAllParams(); // save acl $acl->saveAclForResource($params['panelName'], $params['panelStore']); }
public function isValid() { $config = Knowledgeroot_Registry::get('config'); if ($this->apikey != null && $config->rest->apikey == $this->apikey) { return true; } else { return false; } }
public function preDispatch(Zend_Controller_Request_Abstract $request) { $config = Knowledgeroot_Registry::get('config'); if ($config->misc->defaultpage != '') { $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); if ($module == 'default' && $controller == 'index' && $action == 'index') { $this->_response->setRedirect($config->misc->defaultpage); } } }
public function indexAction() { // get user session $session = new Zend_Session_Namespace('user'); // check for non guest users if (!$session->valid) { $this->_redirect(''); } // get user $user = new Knowledgeroot_User($session->id); // check for post if ($this->getRequest()->getMethod() == 'POST') { $user->setFirstName($this->_getParam('first_name')); $user->setLastName($this->_getParam('last_name')); $user->setEmail($this->_getParam('email')); $user->setLanguage($this->_getParam('language')); $user->setTimezone($this->_getParam('timezone')); // check for password change if ($this->_getParam('password') != '') { if ($this->_getParam('password') == $this->_getParam('password1')) { // save password $user->setPassword($this->_getParam('password')); // display success message Knowledgeroot_Message::success("Password changed", "Your password was changed!"); } else { Knowledgeroot_Message::error("Password", "Your password could not changed!"); } } // save user $user->save(); // save settings also to session $session->language = $this->_getParam('language'); $session->timezone = $this->_getParam('timezone'); // display message // TODO: translate text to new language here! Knowledgeroot_Message::success("Settings", "Your settings were saved"); // redirect to this page again $this->_redirect('settings'); } // prepare view vars $this->view->id = $user->getId(); $this->view->login = $user->getLogin(); $this->view->first_name = $user->getFirstName(); $this->view->last_name = $user->getLastName(); $this->view->email = $user->getEmail(); $this->view->language = $user->getLanguage(); $this->view->timezone = $user->getTimezone(); // get translations $translation = Knowledgeroot_Registry::get('translate'); $this->view->translations = $translation->getTranslations(); // get timezones $this->view->timezones = Knowledgeroot_Timezone::getTimezones(); }
public static function false() { $db = Knowledgeroot_Registry::get('db'); switch ($db) { case $db instanceof Zend_Db_Adapter_Pdo_Sqlite: case $db instanceof Zend_Db_Adapter_Sqlsrv: case $db instanceof Zend_Db_Adapter_Pdo_Mysql: case $db instanceof Zend_Db_Adapter_Mysqli: return 0; default: return 'false'; } }
/** * load module by keyname * * @param type $keyname */ protected function loadModule($keyname) { try { // define modulePath $modulePath = PROJECT_PATH . '/module/' . $keyname; // define moduleFile name $moduleFile = $modulePath . '/Module.php'; // define moduleFile class $moduleFileClass = ucfirst($keyname) . 'Module'; // include module file include_once $moduleFile; // init module file $module = new $moduleFileClass(); // get modul config $moduleConfig = new Zend_Config_Ini($module->getConfigPath()); // save config Knowledgeroot_Registry::set($keyname . '_config', $moduleConfig); // check if autoloader should include module lib path if ($moduleConfig->module->lib->path) { // add module lib to include path set_include_path(implode(PATH_SEPARATOR, array(realpath($modulePath . '/' . $moduleConfig->module->lib->path), get_include_path()))); // check namespace if ($moduleConfig->module->namespace) { $namespace = $moduleConfig->module->namespace; } else { $namespace = $moduleFileClass . '_'; } // add module prefix to autoloader $autoloader = Knowledgeroot_Registry::get('loader'); $autoloader->registerNamespace($namespace); } // check for bootstrap if ($moduleConfig->module->bootstrap->path && $moduleConfig->module->bootstrap->class) { // get bootstrap $bootstrapPath = $modulePath . '/' . $moduleConfig->module->bootstrap->path; $boostrapClass = $moduleConfig->module->bootstrap->class; // include bootstrap class include_once $bootstrapPath; // init bootstrap $bootstrap = new $boostrapClass(); $bootstrap->run(); } } catch (Exception $e) { throw new Knowledgeroot_ModuleManager_Exception('Could not load Module: ' . $keyname, 0, $e); } }
public function saveSession() { // if auth is not valid return if (!$this->isValid) { return; } // get db class $db = Knowledgeroot_Registry::get('db'); // get user from db $user = $db->fetchRow("SELECT id, login, language, timezone FROM " . $db->quoteIdentifier('user') . " WHERE login=?", array($this->username)); // get new session namespace and save data $session = new Zend_Session_Namespace('user'); $session->valid = true; $session->id = $user['id']; $session->login = $user['login']; $session->language = $user['language']; $session->timezone = $user['timezone']; }
/** * show permission panel * * @param string $name * @param array $actions * @param array $config * @return string * * config options: * bool show_save_button - show save button so that stuff will be saved per ajax - default: false * bool add_acl_on_form_submit - should acl be submitted on form submit as value - default: false * bool add_user_permissions - add full permissions for the user itself if permissions are empty - default: false */ public function permissionPanel($name, $actions, $config = null) { $view = new Zend_View(); $view->name = $name; $view->actions = $actions; // get actual userid $session = new Zend_Session_Namespace('user'); $view->userId = $session->id; if (isset($config['show_save_button']) && $config['show_save_button']) { $view->showSaveButton = true; } else { $view->showSaveButton = false; } if (isset($config['add_acl_on_form_submit']) && $config['add_acl_on_form_submit']) { $view->addAclOnFormSubmit = true; } else { $view->addAclOnFormSubmit = false; } if (isset($config['add_user_permissions']) && $config['add_user_permissions']) { $view->addUserPermissions = true; } else { $view->addUserPermissions = false; } // available roles $roles = array(); $users = Knowledgeroot_User::getUsers(); foreach ($users as $value) { $roles['U_' . $value->getId()] = $value->getLogin() . ' (U)'; } $groups = Knowledgeroot_Group::getGroups(); foreach ($groups as $value) { $roles['G_' . $value->getId()] = $value->getName() . ' (G)'; } $view->roles = $roles; $acl = Knowledgeroot_Registry::get('acl'); // active roles with permissions $view->permissions = $acl->getAclForResource($name); $view->setScriptPath(APPLICATION_PATH . '/view/scripts/'); return $view->render('helpers/permissionpanel.phtml'); }
/** * get all pages on this page as Knowledgeroot_Page object * * return $array */ public static function getPages(Knowledgeroot_Page $parentPage = null) { $ret = array(); // get acl $acl = Knowledgeroot_Registry::get('acl'); $page = new Knowledgeroot_Db_Page(); $select = $page->select(); //$select->where('parent = ?', $parentPage->getId()); $select->where('deleted = ' . Knowledgeroot_Db::false()); $rows = $page->fetchAll($select); foreach ($rows as $value) { if ($acl->iAmAllowed('page_' . $value->id, 'show')) { $ret[] = new Knowledgeroot_Page($value->id); } } return $ret; }
/** * return date in system timezone */ public function getSystemDate() { // get config $config = Knowledgeroot_Registry::get('config'); return $this->getDate($config->base->timezone); }
/** * init modules */ protected function _initModules() { try { // load config $this->bootstrap('config'); // init module manager $manager = new Knowledgeroot_ModuleManager(); // load modules $manager->loadModules(); // save filemanager Knowledgeroot_Registry::set('modulemanager', $manager); } catch (Exception $e) { echo $e->getMessage(); die('could not load modules'); } }
/** * get all contents on this page as Knowledgeroot_Content object * * @param object $page Knowledgeroot_Page object * @param string $sorting column to sort by also with ASC|DESC * return $array */ public static function getContents(Knowledgeroot_Page $page, $sorting = 'sorting') { $ret = array(); // get acl $acl = Knowledgeroot_Registry::get('acl'); $content = new Knowledgeroot_Db_Content(); $select = $content->select(); $select->where('parent = ?', $page->getId()); $select->where('deleted = ' . Knowledgeroot_Db::false()); $select->order($sorting); $rows = $content->fetchAll($select); foreach ($rows as $value) { if ($acl->iAmAllowed('content_' . $value->id, 'show')) { $ret[] = new Knowledgeroot_Content($value->id); } } return $ret; }
public function editAction() { // check acl if (!Knowledgeroot_Acl::iAmAllowed('content_' . $this->_getParam('id'), 'edit')) { $this->_redirect('page/' . $this->_getParam('content_page')); } if ($this->getRequest()->getMethod() == 'POST') { if ($this->_getParam('button') == 'close') { $this->_redirect('page/' . $this->_getParam('content_page')); } $content = new Knowledgeroot_Content($this->_getParam('id')); $content->setName($this->_getParam('content_title')); $content->setContent($this->_getParam('content')); $content->setParent($this->_getParam('content_page')); $content->setAcl(json_decode($this->_getParam('acl'))); $content->save(); // delete existing tags $content->deleteTags(); // save tags if ($this->_getParam('content_tags') != '') { $tags = explode(",", $this->_getParam('content_tags')); foreach ($tags as $tag) { if (trim($tag) != '') { $newTag = new Knowledgeroot_Tag(); $newTag->setName(trim($tag)); $newTag->save(); $content->addTag($newTag); } } } if ($this->_getParam('button') == 'save') { $this->_redirect('content/edit/' . $content->getId()); } else { $this->_redirect('page/' . $this->_getParam('content_page') . '#content' . $content->getId()); } } else { $this->view->action = 'edit'; $this->view->id = $this->_getParam('id'); $content = new Knowledgeroot_Content($this->_getParam('id')); $rte = Knowledgeroot_Registry::get('rte'); $rte->setName('content'); $rte->setContent($content->getContent(true)); $this->view->editor = $rte; $this->view->title = $content->getName(); $this->view->tags = $content->getTags(); $this->view->page = $content->getParent(); $parent = new Knowledgeroot_Page($content->getParent()); $this->view->pagename = $parent->getName(); $this->view->created_by = $content->getCreatedBy()->getLogin(); $this->view->create_date = $content->getCreateDate()->getUserDate(); $this->view->versions = $content->getVersions(); $this->renderScript("content/content.phtml"); } }
/** * * @param type $resource * @param type $action * @return type */ public static function iAmAllowed($resource, $action) { $acl = Knowledgeroot_Registry::get('acl'); // create resource if resource not exists to avoid exception if (!$acl->has($resource)) { $res = new Zend_Acl_Resource($resource); $acl->addResource($res); } $session = new Zend_Session_Namespace('user'); $userId = 'U_' . $session->id; return $acl->isAllowed($userId, $resource, $action); }
public function showAction() { // check acl if (!Knowledgeroot_Acl::iAmAllowed('page_' . $this->_getParam('id'), 'show')) { $this->_redirect(''); } $translate = Knowledgeroot_Registry::get('Zend_Translate'); // using blank layout $this->_helper->layout->setLayout('blank'); if ($this->_getParam('version') !== null) { $page = new Knowledgeroot_Page($this->_getParam('id'), $this->_getParam('version')); } else { $page = new Knowledgeroot_Page($this->_getParam('id')); } $this->view->name = $page->getName(); $this->view->subtitle = $page->getSubtitle(); $this->view->alias = $page->getAlias(); $this->view->tooltip = $page->getTooltip(); $this->view->description = $page->getDescription(); $this->view->title = $translate->translate('Show version of page'); }
/** * create absolut filename from hash * * @param string $hash * @return string filename */ public function getFilename($hash) { // config $config = Knowledgeroot_Registry::get('config'); // get filename $filename = $config->files->datastore . "/" . $hash[0] . "/" . $hash[1] . "/" . $hash; // return filename return $filename; }