public function update() { if (FabriqModules::module('roles')->requiresPermission('update blog posts', 'blog')) { $blog = FabriqModules::new_model('blog', 'Blogs'); $blog->find(PathMap::arg(2)); if ($blog->title != '' && ($blog->locked == 0 || FabriqModules::module('roles')->requiresPermission('update blog posts', 'blog'))) { Fabriq::title('Update blog entry'); if (file_exists('libs/javascript/tiny_mce/tiny_mce.js')) { FabriqLibs::js_lib('tiny_mce', 'tiny_mce'); FabriqLibs::js_lib('jquery.tinymce', 'tiny_mce'); FabriqModules::add_js('blog', 'blog'); } // determine if extension modules are enabled $pathmapEnabled = FabriqModules::enabled('pathmap'); FabriqModules::set_var('blog', 'pathmapEnabled', $pathmapEnabled); if ($pathmapEnabled) { FabriqModules::module('pathmap')->start_update('blog', 'show', $blog->id); FabriqModules::set_var('pathmap', 'pathmap_controller', 'blog'); FabriqModules::set_var('pathmap', 'pathmap_action', 'show'); FabriqModules::set_var('pathmap', 'pathmap_modpage', 'module'); } $taxonomyEnabled = FabriqModules::enabled('taxonomy'); FabriqModules::set_var('blog', 'taxonomyEnabled', $taxonomyEnabled); if ($taxonomyEnabled) { FabriqModules::module('taxonomy')->termsList('blog', $blog->db_table, $blog->id); } if (isset($_POST['submit'])) { $blog->title = trim($_POST['title']); $blog->body = trim($_POST['body']); $blog->locked = isset($_POST['locked']) && $_POST['locked'] == 1 ? 1 : 0; $blog->user = $_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_userid']; if (strlen($blog->title) == '') { Messaging::message('Blog title is required'); } if (strlen($blog->body) == '') { Messaging::message('Blog body is required'); } if (!Messaging::has_messages()) { $blog->update(); FabriqModules::trigger_event($this->name, 'create', 'blog entry updated', $blog); // create map if needed if ($pathmapEnabled) { $_POST['pathmap_extra'] = $blog->id; $_POST['pathmap_wildcard'] = NULL; FabriqModules::module('pathmap')->update('blog', 'show', $blog->id); } // add taxonomy if available if ($taxonomyEnabled) { FabriqModules::module('taxonomy')->termsList('blog', $blog->db_table, $blog->id); } if (!Messaging::has_messages()) { header('Location: ' . PathMap::build_path('blog')); exit; } } FabriqModules::set_var('blog', 'submitted', true); } FabriqModules::set_var('blog', 'blog', $blog); } else { FabriqModules::set_var('blog', 'notFound', true); Fabriq::title('Blog entry not found'); } } }
/** * Check that the fabriqinstall module is installed */ public static function fabriqinstallReady() { // check that the fabriqinstall module is installed if (!FabriqModules::installed('fabriqinstall')) { FabriqModules::register_module('fabriqinstall'); FabriqModules::install('fabriqinstall'); $module = new Modules(); $module->getModuleByName('fabriqinstall'); $module->enabled = 1; $module->update(); Messaging::message('Installed fabriqinstall module', 'success'); } }
public function itemsUpdate() { if (FabriqModules::module('roles')->requiresPermission('update menus', 'sitemenus')) { $menu = FabriqModules::new_model('sitemenus', 'Menus'); $menu->find(PathMap::arg(3)); if ($menu->menuName != '') { $menuItem = FabriqModules::new_model('sitemenus', 'MenuItems'); $menuItem->find(PathMap::arg(4)); if ($menuItem->itemName != '') { Fabriq::title("Add item to menu \"{$menu->menuName}\""); $menu->buildMenu(); FabriqModules::set_var('sitemenus', 'menu', $menu); FabriqModules::set_var('sitemenus', 'found', true); FabriqModules::set_var('sitemenus', 'moduleName', $this->name); if (isset($_POST['submitted'])) { $menuItem->itemName = trim($_POST[$this->name . '_itemName']); $menuItem->path = trim($_POST[$this->name . '_path']); $menuItem->parentItem = $_POST[$this->name . '_parentItem']; $menuItem->weight = $_POST[$this->name . '_weight']; $menuItem->menu = $menu->id; $menuItem->newWindow = isset($_POST[$this->name . '_newWindow']) && $_POST[$this->name . '_newWindow'] == 1 ? 1 : 0; if (strlen($menuItem->itemName) == 0) { Messaging::message('An item name is required'); } if (strlen($menuItem->path) == 0) { $menuItem->path = NULL; } if ($menuItem->parentItem == '') { $menuItem->parentItem = NULL; } if (!Messaging::has_messages()) { $menuItem->update(); } FabriqModules::set_var('sitemenus', 'submitted', true); } FabriqModules::set_var('sitemenus', 'menuItem', $menuItem); } else { Fabriq::title("Menu item not found"); FabriqModules::set_var('sitemenus', 'found', false); } } else { Fabriq::title("Menu not found"); FabriqModules::set_var('sitemenus', 'found', false); } } }
public function updateAccount() { if (!$this->isLoggedIn()) { header('Location: ' . PathMap::build_path('users', 'login')); exit; } Fabriq::title('Update account'); $user = FabriqModules::new_model('users', 'Users'); $user->find($_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_userid']); if (isset($_POST['submit'])) { $emailPattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i'; $displayPattern = '/([A-z0-9]){6,24}/'; if (!preg_match($displayPattern, $_POST['display'])) { Messaging::message("Display name is invalid"); } if (!preg_match($emailPattern, $_POST['email'])) { Messaging::message("e-mail address is invalid"); } if (!Messaging::has_messages()) { $user->display = $_POST['display']; $user->email = $_POST['email']; $user->update(); $_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_displayname'] = $user->display; $_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_email'] = $user->email; Messaging::message('Account has bee updated', 'success'); } FabriqModules::set_var('users', 'submitted', true); } FabriqModules::set_var('users', 'user', $user); FabriqModules::add_js('users', 'jquery.validate.min'); FabriqModules::add_js('users', 'users-updateAccount'); FabriqModules::add_css('users', 'users-admin'); }
public function perms() { if ($this->requiresPermission('manage roles', $this->name)) { Fabriq::title('Admin | Manage permissions'); FabriqModules::add_css('roles', 'roles'); $perms = new Perms(); $perms->getAll(); $modules = new Modules(); $modules->getEnabled(); $roles = FabriqModules::new_model('roles', 'Roles'); $roles->getRoles(); $modulePerms = FabriqModules::new_model('roles', 'ModulePerms'); $modulePerms->getAll(); $permissions = array(); foreach ($perms as $perm) { $permissions[$perm->id] = array(); foreach ($roles as $role) { if (isset($modulePerms->perms[$perm->id][$role->id])) { $permissions[$perm->id][$role->id] = 1; } else { $permissions[$perm->id][$role->id] = 0; } } } if (isset($_POST['submit'])) { foreach ($perms as $perm) { foreach ($roles as $role) { if (isset($_POST['permission'][$perm->id][$role->id])) { $permissions[$perm->id][$role->id] = 1; // add to database if it's not already set if (!isset($modulePerms->perms[$perm->id][$role->id])) { $p = FabriqModules::new_model('roles', 'ModulePerms'); $p->permission = $perm->id; $p->role = $role->id; $p->id = $p->create(); $modulePerms->perms[$perm->id][$role->id] = $modulePerms->count(); $modulePerms->add($p); } } else { $permissions[$perm->id][$role->id] = 0; // remove from database if it is already set if (isset($modulePerms->perms[$perm->id][$role->id])) { $p = FabriqModules::new_model('roles', 'ModulePerms'); $p->find($modulePerms[$modulePerms->perms[$perm->id][$role->id]]->id); $p->destroy(); $modulePerms->remove($modulePerms->perms[$perm->id][$role->id]); $modulePerms->reindex(); } } } } Messaging::message('Permissions have been updated.', 'success'); } FabriqModules::set_var($this->name, 'perms', $perms); FabriqModules::set_var($this->name, 'modules', $modules); FabriqModules::set_var($this->name, 'roles', $roles); FabriqModules::set_var($this->name, 'permissions', $permissions); } }
/** * Install step 4 * Install the core database tables and modules and create the * default administrator */ protected function install_step4($continue = TRUE) { Fabriq::title('Core module configuration'); FabriqTemplates::template('fabriqinstall'); Messaging::message('Be sure to continue with module set up in order to complete the install process', 'warning'); if (isset($_POST['submit'])) { $emailPattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i'; $displayPattern = '/([A-z0-9]){6,24}/'; $user = FabriqModules::new_model('users', 'Users'); $user->display = $_POST['display']; $user->email = $_POST['email']; $user->encpwd = $_POST['pwd']; if (!preg_match($displayPattern, $user->display)) { Messaging::message("Display name is invalid"); } if (!preg_match($emailPattern, $user->email)) { Messaging::message("e-mail address is invalid"); } if (strlen($user->encpwd) < 8 || $user->encpwd == $user->display || $user->encpwd == $user->email || $user->encpwd != $_POST['confpwd']) { Messaging::message("Password is invalid"); } if (!Messaging::has_messages()) { $user->status = 1; $user->banned = 0; $user->forcepwdreset = 0; $user->id = $user->create(); $user->encpwd = crypt($user->encpwd, $user->id); $user->update(); $role = FabriqModules::new_model('roles', 'Roles'); $role->getRole('administrator'); $userRole = FabriqModules::new_model('users', 'UserRoles'); $userRole->user = $user->id; $userRole->role = $role->id; $userRole->id = $userRole->create(); global $_FAPP; $url = $_FAPP['url'] . PathMap::build_path('users', 'login'); $message = <<<EMAIL Hello {$user->display}, Your account has been created on the {$_FAPP['title']} website. You can log in by navigating to {$url} in your browser. Thanks, The {$_FAPP['title']} team NOTE: Do not reply to this message. It was automatically generated. EMAIL; mail($user->email, "Your account at {$_FAPP['title']}", $message, 'From: noreply@' . str_replace('http://', '', str_replace('https://', '', str_replace('www.', '', $_FAPP['url'])))); if ($continue) { // go to next step header("Location: " . PathMap::build_path('fabriqinstall', 'install', 5)); exit; } } FabriqModules::set_var('fabriqinstall', 'submitted', true); } }
public function update($controller, $action, $extra) { $map = FabriqModules::new_model('pathmap', 'Paths'); $map->get_by_details($controller, $action, $extra); if ($_POST['update_path'] == 1) { if ($_POST['destroy_path'] == 1) { $map->destroy(); } else { $map->path = $_POST[$this->name . '_path']; if (!preg_match('/^([a-zA-Z0-9_\\-\\/]{1}){1,100}$/', $map->path)) { Messaging::message('Paths can only contain letters, numbers, the underscore character, and dashes'); } if (Messaging::has_messages() == 0) { $map->update(); } } } else { if ($_POST['add_path'] == 1) { $map = FabriqModules::new_model('pathmap', 'Paths'); $map->path = $_POST[$this->name . '_path']; $map->controller = $_POST[$this->name . '_controller']; $map->action = $_POST[$this->name . '_action']; $map->modpage = $_POST[$this->name . '_modpage']; $map->extra = $_POST[$this->name . '_extra']; $map->wildcard = $_POST[$this->name . '_wildcard']; if (!preg_match('/^([a-zA-Z0-9_\\-\\/]{1}){1,100}$/', $map->path)) { Messaging::message('Paths can only contain letters, numbers, the underscore character, and dashes'); } if (Messaging::has_messages() == 0) { $map->id = $map->create(); } FabriqModules::set_var($this->name, 'submitted', true); } } FabriqModules::set_var($this->name, 'map', $map); }