public function redirect($p)
 {
     $path = FabriqModules::new_model('pathmap', 'Paths');
     $path->get_by_path($p);
     if (count($path)) {
         switch ($path->modpage) {
             case 'module':
                 if (FabriqModules::enabled($path->controller)) {
                     $extra = explode('/', $path->extra);
                     if (count($extra) == 1) {
                         if ($extra[0] == '') {
                             unset($extra[0]);
                         }
                     }
                     PathMap::arg(0, $path->controller);
                     PathMap::arg(1, $path->action);
                     for ($i = 0; $i < count($extra); $i++) {
                         PathMap::arg($i + 2, $extra[$i]);
                     }
                     FabriqStack::enqueue($path->controller, $path->action, 'module', $extra);
                     return true;
                 } else {
                     FabriqStack::error(404);
                 }
                 break;
             case 'page':
             default:
                 PathMap::arg(0, $path->controller);
                 PathMap::arg(1, $path->action);
                 FabriqStack::enqueue($path->controller, $path->action);
                 if ($path->extra != '') {
                     $extra = explode('/', $path->extra);
                     if ($path->wildcard) {
                         $p = explode('/', $_GET['q']);
                         array_unshift($extra, $p[$path->wildcard]);
                     }
                     for ($i = 0; $i < count($extra); $i++) {
                         PathMap::arg($i + 2, $extra[$i]);
                     }
                 } else {
                     if ($path->wildcard) {
                         $p = explode('/', $_GET['q']);
                         PathMap::arg(2, $p[$path->wildcard]);
                     }
                 }
                 return true;
                 break;
         }
     }
     return false;
 }
 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);
         }
     }
 }
示例#4
0
 /**
  * Determines the path and enques what to render. This function
  * can be extended in the /app/PathMap.class.php file to add custom
  * functionality.
  */
 public static function map_path()
 {
     global $q;
     global $_FAPP;
     global $installed;
     $mapped = false;
     if ($installed && FabriqModules::enabled('pathmap')) {
         if (isset($_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_forcepwdreset']) && $_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_forcepwdreset'] == 1) {
             if (!in_array('users', $q) && !in_array('changePassword', $q)) {
                 header('Location:' . call_user_func_array('BaseMapping::build_path', array_merge(array('users', 'changePassword'), $q)));
             }
         }
     }
     if (count($q) > 0) {
         if (trim($q[0]) != '' && (file_exists("app/controllers/{$q[0]}.controller.php") || file_exists('sites/' . FabriqStack::site() . "/app/controllers/{$q[0]}.controller.php"))) {
             $controller = $q[0];
             $mapped = true;
         }
         if (count($q) > 1) {
             if (!is_numeric($q[1])) {
                 $action = $q[1];
             } else {
                 $action = $_FAPP['adefault'];
             }
         } else {
             $action = $_FAPP['adefault'];
         }
         if ($mapped) {
             FabriqStack::enqueue($controller, $action);
         }
     }
     // try to map path with pathmap module if enabled and necessary
     if ($installed && FabriqModules::enabled('pathmap') && !$mapped) {
         $pathmap =& FabriqModules::module('pathmap');
         $mapped = $pathmap->redirect($_GET['q']);
     }
     // not installed, map to the install function
     if (!$installed) {
         PathMap::arg(0, 'fabriqinstall');
         PathMap::arg(1, 'install');
         FabriqStack::enqueue('fabriqinstall', 'install', 'module');
         $mapped = true;
     }
     // resolve controller and action if not already declared
     if (!$mapped) {
         if (count($q) == 0) {
             PathMap::arg(0, $_FAPP['cdefault']);
             PathMap::arg(1, $_FAPP['adefault']);
             FabriqStack::enqueue($_FAPP['cdefault'], $_FAPP['adefault']);
         } else {
             if ($q[0] != '' && !file_exists("app/controllers/{$q[0]}.controller.php") && !file_exists('sites/' . FabriqStack::site() . "/app/controllers/{$q[0]}.controller.php")) {
                 FabriqStack::error(404);
             }
         }
     }
 }
    ?>
>Start</li>
			<li<?php 
    if (PathMap::arg(2) == 2) {
        echo ' class="current"';
    }
    ?>
>Framework updates</li>
			<li<?php 
    if (PathMap::arg(2) == 3) {
        echo ' class="current"';
    }
    ?>
>Module updates</li>
			<li<?php 
    if (PathMap::arg(2) == 4) {
        echo ' class="current"';
    }
    ?>
>Finish</li>
		</ul>
		<div class="clearbox">&nbsp;</div>
	</section>
</nav>
<?php 
}
?>

<section id="body">
	<section id="content">
	</div>
	<div style="padding: 2px;">
		<button type="button" name="submit">Save configuration</button> 
		<button type="button" name="cancel">Cancel</button>
	</div>
</form>
<script language="JavaScript" type="text/javascript" id="ajax-callback">
$(function() {
	$('button[name="cancel"]').click(function(event) {
		Fabriq.UI.Overlay.close();
	});
	$('button[name="submit"]').click(function(event) {
		$.ajax({
			type: 'POST',
			url: Fabriq.build_path('fabriqmodules', 'configure', '<?php 
echo PathMap::arg(2);
?>
'),
			data: {
				anyoneCanRegister: ($('input[name="anyoneCanRegister"]:eq(0)').is(':checked')) ? 1 : 0,
				submit: true
			},
			dataType: 'json',
			success: function(data, status) {
				if (data.success) {
					Fabriq.UI.Overlay.close();
					$('#message-box')
						.addClass('successes')
						.html('Users module configuration has been saved')
						.fadeIn();
				}
示例#7
0
<?php

switch (PathMap::arg(2)) {
    case 2:
        require_once 'modules/fabriqinstall/views/install_step2.view.php';
        break;
    case 3:
        require_once 'modules/fabriqinstall/views/install_step3.view.php';
        break;
    case 4:
        require_once 'modules/fabriqinstall/views/install_step4.view.php';
        break;
    case 5:
        require_once 'modules/fabriqinstall/views/install_step5.view.php';
        break;
    case 1:
    default:
        require_once 'modules/fabriqinstall/views/install_step1.view.php';
        break;
}
示例#8
0
 public function update()
 {
     Fabriq::render('none');
     if (FabriqModules::module('roles')->requiresPermission('administer users', $this->name)) {
         $user = FabriqModules::new_model('users', 'Users');
         $user->find(PathMap::arg(2));
         $u = null;
         $errors = array();
         $roles = null;
         if ($user->display != '') {
             $ur = FabriqModules::new_model('users', 'UserRoles');
             $ur->getRoles($user->id);
             $uroles = array();
             for ($i = 0; $i < $ur->count(); $i++) {
                 $uroles[] = $ur[$i]->role;
             }
             $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];
                 }
             }
             if (isset($_POST['submit'])) {
                 $user->display = $_POST['display'];
                 $user->email = $_POST['email'];
                 $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($emailPattern, $_POST['email'])) {
                     $errors[] = "email";
                 }
                 if (!preg_match($displayPattern, $_POST['display'])) {
                     $errors[] = "display";
                 }
                 if (count($errors) == 0) {
                     // update roles
                     $toAdd = array();
                     $toRemove = array();
                     for ($i = 0; $i < count($roles); $i++) {
                         if ($_POST['role' . $roles[$i]->id] == 1) {
                             if (!array_key_exists($roles[$i]->id, $ur->roles)) {
                                 $toAdd[] = $roles[$i]->id;
                             }
                         } else {
                             if (array_key_exists($roles[$i]->id, $ur->roles)) {
                                 $toRemove[] = $roles[$i]->id;
                             }
                         }
                     }
                     // add new role assignments
                     for ($i = 0; $i < count($toAdd); $i++) {
                         $ur = FabriqModules::new_model('users', 'UserRoles');
                         $ur->user = $user->id;
                         $ur->role = $toAdd[$i];
                         $ur->create();
                     }
                     // remove unneeded role assignments
                     for ($i = 0; $i < count($toRemove); $i++) {
                         $ur = FabriqModules::new_model('users', 'UserRoles');
                         $ur->getRole($user->id, $toRemove[$i]);
                         $ur->destroy();
                     }
                     // refresh user roles
                     $uroles = FabriqModules::new_model('users', 'UserRoles');
                     $uroles->getRoles($user->id);
                     $user->update();
                     $msg = "User updated";
                     $success = true;
                 } else {
                     $msg = "User could not be updated because of errors";
                     $success = false;
                 }
                 $u = new stdClass();
                 $u->display = $_POST['display'];
                 $u->email = $_POST['email'];
                 $user->encpwd = null;
                 FabriqModules::trigger_event('users', 'update', 'User updated', $user);
             } else {
                 $msg = "User found";
                 $u = new stdClass();
                 $u->display = $user->display;
                 $u->email = $user->email;
                 $success = true;
             }
             $u->id = $user->id;
             $u->roles = $uroles;
         } else {
             $success = false;
             $msg = "User could not be found";
         }
         $notLoggedIn = false;
     } else {
         $success = false;
         $msg = 'User not logged in';
         $errors = null;
         $u = null;
         $notLoggedIn = true;
     }
     header('Content-type:application/json');
     echo json_encode(array('success' => $success, 'msg' => $msg, 'user' => $u, 'errors' => $error, 'notLoggedIn' => $notLoggedIn, 'roles' => $roles));
 }
 /**
  * Determine which update step to process
  */
 public function update()
 {
     if (FabriqModules::module('roles')->hasRole('administrator')) {
         switch (PathMap::arg(2)) {
             case 2:
                 $this->update_step2();
                 break;
             case 3:
                 $this->update_step3();
                 break;
             case 4:
                 $this->update_step4();
                 break;
             case 1:
             default:
                 $this->update_step1();
                 PathMap::arg(2, 1);
                 break;
         }
     }
 }
 public function configure()
 {
     Fabriq::render('view');
     $module = new Modules(PathMap::arg(2));
     $install_file = "modules/{$module->module}/{$module->module}.install.php";
     if (file_exists('sites/' . FabriqStack::site() . "/{$install_file}")) {
         $install_file = 'sites/' . FabriqStack::site() . "/{$install_file}";
     } else {
         if (!file_exists($install_file)) {
             throw new Exception("Module {$module->module} install file could not be found");
         }
     }
     require_once $install_file;
     eval("\$installer = new {$module->module}_install();");
     $installer->configure();
     FabriqModules::set_var($this->name, 'module', $module);
 }