Esempio n. 1
0
 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 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();
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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');
         }
     }
 }
Esempio n. 5
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);
             }
         }
     }
 }