public function __construct(Database $database, Collection $collection, Container $container, User $user) { parent::__construct($database, $container); $this->collection = $collection; $this->input = $container->input; $this->user = $user->getCurrentUser(); //"label"=>"","datatype"=>"","charsize"=>"" , "default"=>"", "index"=>TRUE, "allowempty"=>FALSE $this->definePropertyModel(array("media_published" => array("Published", "datetime", 50), "media_content" => array("Content", "varchar", 1000), "media_title" => array("Title", "mediumtext", 50, NULL), "media_summary" => array("Summary", "mediumtext", 50, NULL), "media_comment_status" => array("Allow Comments", "tinyint", 1, 0), "media_parent" => array("Parent", "smallint", 10, 0), "media_generator" => array("Generator", "mediumtext", 100), "media_template" => array("Template", "mediumtext", 100), "media_provider" => array("Provider", "mediumtext", 100, "budkit"), "media_mentions" => array("Mentions", "varchar", 1000), "media_owner" => array("Owner", "varchar", 1000), "media_verb" => array("Verb", "mediumtext", 20, "post"), "media_geotags" => array("Geotags", "varchar", 1000), "media_object" => array("Object", "varchar", 1000), "media_target" => array("Target", "varchar", 1000), "media_permissions" => array("Permissions", "mediumtext", 50)), "media"); $this->defineValueGroup("media"); $this->setListOrderBy(array("o.object_updated_on"), "DESC"); }
/** * Registers a superadministrator at installation * @return boolean */ public function superadmin(User $account, Container $application, Database $database) { //@TODO create master user account //1. Load the model $config = $this->config; //$database = \Library\Database::getInstance(); //2. Prevalidate passwords and other stuff; $username = $application->input->getString("user_first_name", "", "post", FALSE, array()); $usernameid = $application->input->getString("user_name_id", "", "post", FALSE, array()); $userpass = $application->input->getString("user_password", "", "post", FALSE, array()); $userpass2 = $application->input->getString("user_password_2", "", "post", FALSE, array()); $useremail = $application->input->getString("user_email", "", "post", FALSE, array()); //3. Encrypt validated password if new users! //4. If not new user, check user has update permission on this user //5. MailOut if (empty($userpass) || empty($username) || empty($usernameid) || empty($useremail)) { //Display a message telling them what can't be empty throw new Exception(t('Please provide at least a Name, Username, E-mail and Password')); return false; } //Validate the passwords if ($userpass != $userpass2) { throw new Exception(t('The user passwords do not match')); return false; } //6. Store the user if (!$account->store($application->input->data("post"), true)) { //Display a message telling them what can't be empty throw new Exception(t('Could not store the admin user account')); return false; } //Add this user to the superadministrators group! //$adminObject = $account->getObjectByURI( $usernameid ); $adminAuthority = $this->config->get("setup.site.superadmin-authority", NULL); //Default Permission Group? if (!empty($adminAuthority)) { $query = "INSERT INTO ?objects_authority( authority_id, object_id ) SELECT {$database->quote((int) $adminAuthority)}, object_id FROM ?objects WHERE object_uri={$database->quote($usernameid)}"; $database->exec($query); } //@TODO Empty the setup/sessions folder // \Library\Folder::deleteContents( APPPATH."setup".DS."sessions" ); //No need to through an error //Completes installation //set session handler to database if database is connectable $config->set("setup.session.store", "database"); $config->set("setup.database.installed", TRUE); if (!$config->saveParams()) { throw new Exception("could not save config"); return false; } return true; }
public function update($uri, $format = 'html') { //1. check this uer has permission to execute /page/create $this->checkPermission("execute"); //2. are we patching or updating an existing? $input = $this->application->input; $user = new User($this->application, $this->application->database, $this->application->session); if ($input->methodIs("PATCH")) { //because we are updating; //3. load the page; $page = $this->application->createInstance(Model\Page::class); // $page = $page->defineValueGroup("page"); $page = $page->loadObjectByURI($uri); //4. Is this a valid page? if ($page->getObjectId()) { //if we have a page; //Checks if the current user is the owner of this page or has special permissions to edit pages if ($page->getPropertyValue("media_owner") == $user->getCurrentUser()->getPropertyValue("user_name_id") || $this->checkPermission("special", "/page/edit")) { //we will save the content as HTML $page = $this->bindData($page); //binds input data; $page->setPropertyValue("media_published", Time::stamp()); $page->defineValueGroup("page"); if ($page->saveObject($page->getObjectURI(), $page->getObjectType())) { $this->response->addAlert(t("Your page content has been updated successfully"), "success"); //Redirect to dashboard or to last url? return $this->application->dispatcher->redirect("/page/{$page->getObjectURI()}/edit", HTTP_FOUND, null, $this->response->getAlerts()); } } } } $this->response->addAlert(t("The page content was not updated"), "warning"); //Redirect to dashboard or to last url? return $this->application->dispatcher->redirect("/page/{$page->getObjectURI()}/edit", HTTP_FOUND, null, $this->response->getAlerts()); }