public function uninstall()
 {
     $mod = new Modules();
     $mod->getModuleByName('blog');
     // remove perms
     FabriqModules::remove_perms($mod->id);
     // remove paths
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->remove_path('blog');
     $pathmap->remove_path('blog/create');
     $pathmap->remove_path('blog/update/!#');
     $pathmap->remove_path('blog/destroy/!#');
     $pathmap->remove_path('blog/show/!#');
     // delete database table
     global $db;
     $sql = "DROP TABLE `fabmod_blog_blogs`;";
     $db->query($sql);
     // uninstall any terms
     if (FabriqModules::enabled('taxonomy')) {
         FabriqModules::module('taxonomy')->uninstallMaps('fabmod_blog_blogs');
     }
     // set module as not installed
     $mod->installed = 0;
     $mod->update();
 }
示例#2
0
 public function install()
 {
     $mod = new Modules();
     $mod->getModuleByName('roles');
     $perms = array('create roles', 'update roles', 'delete roles', 'manage roles');
     $perm_ids = FabriqModules::register_perms($mod->id, $perms);
     global $db;
     $sql = "CREATE TABLE IF NOT EXISTS `fabmod_roles_roles` (\n\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`role` VARCHAR(100) NOT NULL,\n\t\t\t`enabled` TINYINT(1) NOT NULL DEFAULT 1,\n\t\t\t`created` DATETIME NOT NULL,\n\t\t\t`updated` DATETIME NOT NULL,\n\t\t\tPRIMARY KEY (`id`)\n\t\t) ENGINE=INNODB;";
     $db->query($sql);
     $sql = "CREATE TABLE IF NOT EXISTS `fabmod_roles_moduleperms` (\n\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`permission` INT(11) NOT NULL,\n\t\t\t`role` INT(11) NOT NULL,\n\t\t\t`created` DATETIME NOT NULL,\n\t\t\t`updated` DATETIME NOT NULL,\n\t\t\tPRIMARY KEY (`id`),\n\t\t\tCONSTRAINT `fk_moduleperms_permission` FOREIGN KEY (`permission`) REFERENCES fabmods_perms(id) ON DELETE CASCADE,\n\t\t\tCONSTRAINT `fk_moduleperms_role` FOREIGN KEY (`role`) REFERENCES fabmod_roles_roles(id) ON DELETE CASCADE\n\t\t) ENGINE=INNODB;";
     $db->query($sql);
     // create base roles
     $role = FabriqModules::new_model('roles', 'Roles');
     $role->role = "unauthenticated";
     $role->enabled = 1;
     $role->id = $role->create();
     $role = FabriqModules::new_model('roles', 'Roles');
     $role->role = "authenticated";
     $role->enabled = 1;
     $role->id = $role->create();
     $role = FabriqModules::new_model('roles', 'Roles');
     $role->role = "administrator";
     $role->enabled = 1;
     $role->id = $role->create();
     // map paths
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->register_path('fabriqadmin/roles/manage', 'roles', 'index', 'module');
     $pathmap->register_path('fabriqadmin/roles/create', 'roles', 'create', 'module');
     $pathmap->register_path('fabriqadmin/roles/perms', 'roles', 'perms', 'module');
     // set module as installed
     $mod->installed = 1;
     $mod->update();
 }
 public function getAll($page = 0, $limit = 10)
 {
     global $db;
     $go = $page * $limit;
     if (FabriqModules::module('roles')->userHasPermission('update blog posts', 'roles')) {
         $query = "SELECT * FROM {$this->db_table} ORDER BY created DESC LIMIT ?, ?";
         $this->fill($db->prepare_select($query, $this->fields(), array($go, $limit)));
     } else {
         $query = "SELECT * FROM {$this->db_table} WHERE locked = ? ORDER BY created DESC LIMIT ?, ?";
         $this->fill($db->prepare_select($query, $this->fields(), array(0, $go, $limit)));
     }
     $found = array();
     for ($i = 0; $i < $this->count(); $i++) {
         // get user details
         if (!array_key_exists($this[$i]->user, $found)) {
             $user = FabriqModules::new_model('users', 'Users');
             $user->find($this[$i]->user);
             $found[$this[$i]->user] = $user;
             $this[$i]->user = $user;
         }
         // look for a custom url
         $this[$i]->customPath = FabriqModules::new_model('pathmap', 'Paths');
         $this[$i]->customPath->get_by_details('blog', 'show', $this[$i]->id);
     }
     // get terms if the module is enabled
     if (FabriqModules::enabled('taxonomy')) {
         for ($i = 0; $i < $this->count(); $i++) {
             $this[$i]->terms = FabriqModules::new_model('taxonomy', 'Terms');
             $this[$i]->terms->getMappedTerms($this->db_table, $this[$i]->id);
         }
     }
 }
 public function install()
 {
     $mod = new Modules();
     $mod->getModuleByName('fabriqmodules');
     $perms = array('manage modules');
     $perm_ids = FabriqModules::register_perms($mod->id, $perms);
     // map paths
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->register_path('fabriqmodules', 'fabriqmodules', 'manage', 'module');
     $pathmap->register_path('fabriqmodules/manage', 'fabriqmodules', 'manage', 'module');
     $pathmap->register_path('fabriqmodules/configure/!#', 'fabriqmodules', 'configure', 'module', null, 2);
     $pathmap->register_path('fabriqmodules/disable/!#', 'fabriqmodules', 'disable', 'module', null, 2);
     $pathmap->register_path('fabriqmodules/enable/!#', 'fabriqmodules', 'enable', 'module', null, 2);
     $pathmap->register_path('fabriqmodules/install/!#', 'fabriqmodules', 'install', 'module', null, 2);
     $pathmap->register_path('fabriqmodules/uninstall/!#', 'fabriqmodules', 'uninstall', 'module', null, 2);
     // give administrators the ability to manage modules
     $adminPerm = FabriqModules::new_model('roles', 'ModulePerms');
     $adminPerm->permission = $perm_ids[0];
     $adminRole = FabriqModules::new_model('roles', 'Roles');
     $adminRole->getRole('administrator');
     $adminPerm->role = $adminRole->id;
     $adminPerm->id = $adminPerm->create();
     // set module as installed
     $mod->installed = 1;
     $mod->update();
 }
示例#5
0
 public function install()
 {
     $mod = new Modules();
     $mod->getModuleByName('users');
     $perms = array('administer users', 'ban users', 'enable users');
     $perm_ids = FabriqModules::register_perms($mod->id, $perms);
     global $db;
     $sql = "CREATE TABLE IF NOT EXISTS `fabmod_users_users` (\n\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`display` VARCHAR(24) NOT NULL,\n\t\t\t`email` VARCHAR(100) NOT NULL,\n\t\t\t`encpwd` VARCHAR(100) NOT NULL,\n\t\t\t`status` INT(4) NOT NULL DEFAULT 0,\n\t\t\t`banned` TINYINT(1) NOT NULL DEFAULT 0,\n\t\t\t`forcepwdreset` TINYINT(1) NOT NULL DEFAULT 0,\n\t\t\t`created` DATETIME NOT NULL,\n\t\t\t`updated` DATETIME NOT NULL,\n\t\t\tPRIMARY KEY (`id`)\n\t\t) ENGINE=INNODB;";
     $db->query($sql);
     $sql = "CREATE TABLE IF NOT EXISTS `fabmod_users_roles` (\n\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`user` INT(11) NOT NULL,\n\t\t\t`role` INT(11) NOT NULL,\n\t\t\t`created` DATETIME NOT NULL,\n\t\t\t`updated` DATETIME NOT NULL,\n\t\t\tPRIMARY KEY (`id`),\n\t\t\tCONSTRAINT `fk_users_user` FOREIGN KEY (`user`) REFERENCES `fabmod_users_users`(`id`) ON DELETE CASCADE,\n\t\t\tCONSTRAINT `fk_users_role` FOREIGN KEY (`role`) REFERENCES `fabmod_roles_roles`(`id`) ON DELETE CASCADE\n\t\t) ENGINE=INNODB;";
     $db->query($sql);
     // map paths
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->register_path('users/index', 'users', 'index', 'module');
     $pathmap->register_path('users/index/!#', 'users', 'index', 'module', null, 2);
     $pathmap->register_path('users/login', 'users', 'login', 'module');
     $pathmap->register_path('users/login/!#', 'users', 'login', 'module', null, 2);
     $pathmap->register_path('users/logout', 'users', 'logout', 'module');
     $pathmap->register_path('users/forgotpassword', 'users', 'forgotpassword', 'module');
     $pathmap->register_path('users/create', 'users', 'create', 'module');
     $pathmap->register_path('users/update/!#', 'users', 'update', 'module', null, 2);
     $pathmap->register_path('users/enable', 'users', 'enable', 'module');
     $pathmap->register_path('users/ban', 'users', 'ban', 'module');
     $pathmap->register_path('users/register', 'users', 'register', 'module');
     $pathmap->register_path('users/checkDisplay', 'users', 'checkDisplay', 'module');
     $pathmap->register_path('users/checkEmail', 'users', 'checkEmail', 'module');
     $pathmap->register_path('users/changePassword/!#', 'users', 'changePassword', 'module', null, 2);
     $pathmap->register_path('users/myAccount', 'users', 'myAccount', 'module');
     $pathmap->register_path('users/updateAccount', 'users', 'updateAccount', 'module');
     $pathmap->register_path('users/getRoles', 'users', 'getRoles', 'module');
     // set module as installed
     $mod->installed = 1;
     $mod->update();
 }
 public function uninstall()
 {
     $mod = new Modules();
     $mod->getModuleByName('sitemenus');
     // remove perms
     FabriqModules::remove_perms($mod->id);
     // remove paths
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->remove_path('sitemenus');
     $pathmap->remove_path('sitemenus/index');
     $pathmap->remove_path('sitemenus/create');
     $pathmap->remove_path('sitemenus/update/!#');
     $pathmap->remove_path('sitemenus/destroy/!#');
     $pathmap->remove_path('sitemenus/items/index/!#');
     $pathmap->remove_path('sitemenus/items/create/!#');
     $pathmap->remove_path('sitemenus/items/update/!#');
     $pathmap->remove_path('sitemenus/items/destroy/!#');
     // delete database table
     global $db;
     $sql = "DROP TABLE `fabmod_sitemenus_menus`;";
     $db->query($sql);
     $sql = "DROP TABLE `fabmod_sitemenus_menuitems`;";
     $db->query($sql);
     // set module as not installed
     $mod->installed = 0;
     $mod->update();
 }
 public function update_2_3_1()
 {
     // update the path(s) for the fabriqupdate module to point to the proper actions
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->remove_path('fabriqupdates');
     $pathmap->register_path('fabriqupdates', 'fabriqinstall', 'fetchUpdates', 'module');
     // update the module version number
     $mod = new Modules();
     $mod->getModuleByName('fabriqinstall');
     $mod->versioninstalled = '2.3.1';
     $mod->update();
 }
 public function update_2_1_1()
 {
     // update the module version number
     $mod = new Modules();
     $mod->getModuleByName('pathmap');
     $mod->versioninstalled = '2.1.1';
     $mod->update();
     // map paths
     $pathmap =& FabriqModules::module('pathmap');
     $pathmap->register_path('403', 'pathmap', '_403', 'module');
     $pathmap->register_path('404', 'pathmap', '_404', 'module');
     $pathmap->register_path('500', 'pathmap', '_500', 'module');
 }
 public function show($entry)
 {
     if (FabriqModules::module('roles')->requiresPermission('view blog posts', 'blog')) {
         $blog = FabriqModules::new_model('blog', 'Blogs');
         if (!$entry || !is_numeric($entry)) {
             $blog->find(PathMap::arg(2));
         } else {
             $blog->find($entry);
         }
         if ($blog->title != '' && ($blog->locked == 0 || FabriqModules::module('roles')->requiresPermission('update blog posts', 'blog'))) {
             Fabriq::title('Blog - ' . $blog->title);
             $user = FabriqModules::new_model('users', 'Users');
             $user->find($blog->user);
             $blog->user = $user;
             $taxonomyEnabled = FabriqModules::enabled('taxonomy');
             FabriqModules::set_var('blog', 'taxonomyEnabled', $taxonomyEnabled);
             FabriqModules::set_var('blog', 'blog', $blog);
             $isAdmin = FabriqModules::module('roles')->userHasPermission('update blog posts', 'blog');
             FabriqModules::set_var('blog', 'isAdmin', $isAdmin);
         } else {
             FabriqModules::set_var('blog', 'notFound', true);
             Fabriq::title('Blog entry not found');
         }
     }
 }
 public function itemsDestroy()
 {
     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->destroy();
                     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);
         }
     }
 }
示例#11
0
 /**
  * Process everything the queue
  */
 public static function processQueue()
 {
     if (!count(self::$queue)) {
         return false;
     }
     $next = FabriqStack::dequeue();
     while ($next->controller == '') {
         if (!count(self::$queue)) {
             return false;
         }
         FabriqStack::processQueue();
     }
     self::$processing = $next;
     switch ($next->type) {
         case 'module':
             $module =& FabriqModules::module($next->controller);
             call_user_func_array(array($module, $next->action), $next->extra);
             if (Fabriq::render() != 'none' && FabriqModules::has_permission() && !FabriqModules::stopMappedRender()) {
                 FabriqTemplates::renderToBody($next);
             }
             break;
         case 'controller':
         default:
             PathMap::controller($next->controller);
             PathMap::action($next->action);
             $file = "app/controllers/{$next->controller}.controller.php";
             if (file_exists('sites/' . FabriqStack::site() . "/{$file}")) {
                 require_once 'sites/' . FabriqStack::site() . "/{$file}";
             } else {
                 require_once $file;
             }
             $c = "{$next->controller}_controller";
             $controller = new $c();
             $a = str_replace('.', '_', $next->action);
             if (!$controller->hasMethod($a)) {
                 FabriqStack::error(404);
             }
             call_user_func(array($controller, $a));
             FabriqTemplates::renderToBody($next);
             break;
     }
     if (count(self::$queue)) {
         FabriqStack::processQueue();
     }
 }
示例#12
0
			<td style="width: 85px; padding: 5px; text-align: center;" class="fabriqmodules-config-col">
			<?php 
        if ($module->hasconfigs == 1 && $module->installed == 1) {
            ?>
				<button type="button" id="config-button-<?php 
            echo $module->id;
            ?>
" onclick="FabriqModules.configurationForm(<?php 
            echo $module->id;
            ?>
);">configure</button>
			<?php 
        } else {
            ?>
				&nbsp;
			<?php 
        }
        ?>
			</td>
		</tr>
<?php 
    }
    ?>
	</tbody>
</table>
<?php 
} else {
    FabriqModules::module('roles')->noPermission();
    FabriqModules::render('roles', 'noPermission');
    FabriqModules::has_permission(false);
}
示例#13
0
 public function requiresPermission($permission, $module)
 {
     if (isset($_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_roles'])) {
         $roles = unserialize($_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_roles']);
         if (count($roles) > 0) {
             global $db;
             $query = "SELECT COUNT( * ) AS num\nFROM fabmod_roles_moduleperms\nWHERE permission = (\n\tSELECT id\n\tFROM fabmods_perms\n\tWHERE permission = ?\n\tAND module = (\n\t\tSELECT id\n\t\tFROM fabmods_modules\n\t\tWHERE module = ?\n\t\tLIMIT 1\n\t)\n\tLIMIT 1\n)\nAND role\nIN (" . $db->qmarks(count($roles)) . ")";
             $data = $db->prepare_select($query, array('num'), array_merge(array($permission, $module), $roles));
             if ($data[0]['num'] > 0) {
                 return TRUE;
             }
             $this->noPermission();
             FabriqModules::render('roles', 'noPermission');
             FabriqModules::has_permission(false);
             return FALSE;
         }
         $this->noPermission();
         FabriqModules::render('roles', 'noPermission');
         FabriqModules::has_permission(false);
         return FALSE;
     }
     // user isn't logged in
     if (Fabriq::render() != 'none') {
         FabriqModules::module('users')->login();
         FabriqModules::render('users', 'login');
         FabriqModules::has_permission(false);
     }
     return FALSE;
 }
 /**
  * Fetch the list of updates
  */
 public function fetchUpdates()
 {
     if (FabriqModules::module('roles')->hasRole('administrator')) {
         global $db;
         Fabriq::title('Fabriq Updates');
         // get the currently installed version
         $query = "SELECT version FROM fabriq_config ORDER BY installed DESC, version DESC LIMIT 1";
         $db->query($query);
         $data = mysqli_fetch_array($db->result);
         $installedVersion = $data['version'];
         FabriqModules::set_var('fabriqinstall', 'installedVersion', $installedVersion);
         // get the list of updates from the site
         try {
             $versions = json_decode(file_get_contents('http://fabriqframework.com/changelog/json'), TRUE);
             $available = array();
             $upToDate = false;
             if (is_array($versions) && count($versions) > 0) {
                 foreach ($versions as $version => $info) {
                     if ($version > $installedVersion) {
                         $available[$version] = $info;
                     }
                 }
                 if (count($available) == 0) {
                     $upToDate = true;
                 }
                 FabriqModules::set_var('fabriqinstall', 'available', $available);
                 FabriqModules::set_var('fabriqinstall', 'connected', true);
             } else {
                 FabriqModules::set_var('fabriqinstall', 'connected', false);
             }
             FabriqModules::set_var('fabriqinstall', 'upToDate', $upToDate);
         } catch (Exception $e) {
             FabriqModules::set_var('fabriqinstall', 'connected', false);
         }
     }
 }
 /**
  * Triggers an event so that handlers can take action if necessary
  * @param string $module
  * @param string $action
  * @param string $name
  * @param mixed $data
  */
 public static function trigger_event($module, $action, $name, $data = null)
 {
     if (array_key_exists("{$module}_{$action}", self::$eventHandlers)) {
         if (array_key_exists($name, self::$eventHandlers["{$module}_{$action}"])) {
             for ($i = 0; $i < count(self::$eventHandlers["{$module}_{$action}"][$name]); $i++) {
                 FabriqModules::module(self::$eventHandlers["{$module}_{$action}"][$name][$i]['module'])->{self::$eventHandlers["{$module}_{$action}"][$name][$i]['action']}($data);
             }
         }
     }
 }
示例#16
0
 public function getRoles()
 {
     Fabriq::render('none');
     header('Content-type:application/json');
     if (FabriqModules::module('roles')->requiresPermission('administer users', $this->name)) {
         $r = FabriqModules::new_model('roles', 'Roles');
         $r->getAll();
         $roles = array();
         for ($i = 0; $i < $r->count(); $i++) {
             if ($r[$i]->role != 'unauthenticated' && $r[$i]->role != 'authenticated') {
                 $roles[] = $r[$i];
             }
         }
         echo json_encode(array('roles' => $roles));
     } else {
         echo json_encode(array('notLoggedIn' => true));
     }
 }
 public function uninstall()
 {
     Fabriq::render('none');
     header('Content-type:application/json');
     if (FabriqModules::module('roles')->hasRole('administrator')) {
         $module = new Modules(PathMap::arg(2));
         if ($module->module != '') {
             $module->installed = 0;
             $module->update();
             FabriqModules::uninstall($module->module);
             echo json_encode(array('success' => true));
         } else {
             echo json_encode(array('success' => false));
         }
     } else {
         echo json_encode(array('success' => false, 'notLoggedIn' => true));
     }
 }