/**
  * Constructor method to instantiate the form object
  *
  * @param  string $action
  * @param  string $method
  * @param  string $type
  * @param  string $name
  * @param  string $format
  * @param  string $version
  * @return self
  */
 public function __construct($action = null, $method = 'post', $type = null, $name = null, $format = null, $version = null)
 {
     parent::__construct($action, $method, null, '        ');
     $site = Table\Sites::getSite();
     if (strpos($site->domain, 'www.') !== false) {
         $domain = 'ftp.' . str_replace('www.', '', $site->domain);
     } else {
         $domain = $site->domain;
     }
     $rootValue = $_POST && isset($_POST['change_ftp_root']) ? $_POST['change_ftp_root'] : null;
     $fields1 = array('ftp_address' => array('type' => 'text', 'label' => $this->i18n->__('FTP Address'), 'required' => true, 'attributes' => array('size' => 40), 'value' => $domain), 'username' => array('type' => 'text', 'label' => $this->i18n->__('Username'), 'required' => true, 'attributes' => array('size' => 40)), 'password' => array('type' => 'text', 'label' => $this->i18n->__('Password'), 'required' => true, 'attributes' => array('size' => 40)), 'ftp_root' => array('type' => 'radio', 'label' => $this->i18n->__('FTP Root'), 'value' => array('0' => $this->i18n->__('Log directly into the document root.') . '<br /><br />', '1' => $this->i18n->__('No, change the directory to') . ' <input style="margin-left: 5px; width: 150px; height: 15px; font-size: 0.9em;" type="text" size="18" name="change_ftp_root" value="' . $rootValue . '" />'), 'marked' => '0'));
     $fields2 = array('submit' => array('type' => 'submit', 'value' => $this->i18n->__('UPDATE'), 'attributes' => array('class' => 'save-btn')), 'use_pasv' => array('type' => 'radio', 'label' => $this->i18n->__('Use PASV'), 'value' => array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), 'marked' => '1'), 'protocol' => array('type' => 'radio', 'label' => $this->i18n->__('Protocol'), 'value' => array('0' => $this->i18n->__('FTP'), '1' => $this->i18n->__('FTPS')), 'marked' => '0'), 'type' => array('type' => 'hidden', 'value' => $type), 'name' => array('type' => 'hidden', 'value' => $name), 'version' => array('type' => 'hidden', 'value' => $version), 'format' => array('type' => 'hidden', 'value' => $format), 'base_path' => array('type' => 'hidden', 'value' => BASE_PATH), 'content_path' => array('type' => 'hidden', 'value' => CONTENT_PATH), 'app_path' => array('type' => 'hidden', 'value' => APP_PATH));
     $this->initFieldsValues = array($fields2, $fields1);
     $this->setAttributes('id', 'update-form');
 }
 /**
  * Constructor method to instantiate the user controller object
  *
  * @param  Request  $request
  * @param  Response $response
  * @param  Project  $project
  * @param  string   $viewPath
  * @return self
  */
 public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null)
 {
     // Create the session object and get the user type
     $this->sess = Session::getInstance();
     $this->type = $project->getService('acl')->getType();
     if (null === $viewPath) {
         $cfg = $project->module('Phire')->asArray();
         $viewPath = __DIR__ . '/../../../../view/phire';
         if (isset($cfg['view'])) {
             $class = get_class($this);
             if (is_array($cfg['view']) && isset($cfg['view'][$class])) {
                 $viewPath = $cfg['view'][$class];
             } else {
                 if (is_array($cfg['view']) && isset($cfg['view']['*'])) {
                     $viewPath = $cfg['view']['*'];
                 } else {
                     if (is_string($cfg['view'])) {
                         $viewPath = $cfg['view'];
                     }
                 }
             }
         }
         // If it is not a user, or a user globally logged into another area
         if (strtolower($this->type->type) != 'user' && !$this->type->global_access || substr($_SERVER['REQUEST_URI'], 0, strlen(BASE_PATH . APP_URI)) != BASE_PATH . APP_URI) {
             $site = Table\Sites::getSite();
             $theme = Table\Extensions::findBy(array('type' => 0, 'active' => 1), null, 1);
             $themePath = $site->document_root . $site->base_path . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $this->type->type;
             $activeThemePath = null;
             if (isset($theme->rows[0])) {
                 $activeThemePath = $site->document_root . $site->base_path . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme->rows[0]->name . DIRECTORY_SEPARATOR . $this->type->type;
             }
             if (null !== $activeThemePath && file_exists($activeThemePath)) {
                 $viewPath = $activeThemePath;
             } else {
                 if (file_exists($themePath)) {
                     $viewPath = $themePath;
                 }
             }
         }
     }
     // Set the correct base path and user URI based on user type
     if (get_called_class() == 'Phire\\Controller\\Phire\\IndexController') {
         $basePath = strtolower($this->type->type) != 'user' ? BASE_PATH . '/' . strtolower($this->type->type) : BASE_PATH . APP_URI;
         $request = new Request(null, $basePath);
     }
     parent::__construct($request, $response, $project, $viewPath);
 }
 /**
  * Prepare view method
  *
  * @param  string $template
  * @param  array  $data
  * @return void
  */
 public function prepareView($template = null, array $data = array())
 {
     $site = \Phire\Table\Sites::getSite();
     if (null !== $template) {
         $template = $this->getCustomView($template, $site);
     }
     $sess = \Pop\Web\Session::getInstance();
     $config = \Phire\Table\Config::getSystemConfig();
     $i18n = \Phire\Table\Config::getI18n();
     $this->live = (bool) $config->live;
     $jsVars = null;
     $this->view = View::factory($template, $data);
     $this->view->set('base_path', $site->base_path)->set('content_path', CONTENT_PATH);
     // Check for an override Phire theme for the header/footer
     if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/header.phtml') && file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/footer.phtml')) {
         $this->view->set('phireHeader', $site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/header.phtml')->set('phireFooter', $site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/footer.phtml');
         // Else, just use the default header/footer
     } else {
         $this->view->set('phireHeader', $site->document_root . $site->base_path . APP_PATH . '/vendor/Phire/view/phire/header.phtml')->set('phireFooter', $site->document_root . $site->base_path . APP_PATH . '/vendor/Phire/view/phire/footer.phtml');
     }
     if (isset($this->view->assets)) {
         $jsVars = '?lang=' . $config->default_language;
     }
     if (isset($sess->user)) {
         if (isset($this->sess->user->last_action)) {
             $this->sess->user->last_action = date('Y-m-d H:i:s');
         }
         // Set the timeout warning, giving a 30 second buffer to act
         if (isset($this->view->assets)) {
             if (isset($this->view->acl) && $this->view->acl->getType()->session_expiration > 0 && $this->view->acl->getType()->timeout_warning) {
                 $exp = $this->view->acl->getType()->session_expiration * 60 - 30;
                 $uri = $site->base_path . (strtolower($this->view->acl->getType()->type) != 'user' ? '/' . strtolower($this->view->acl->getType()->type) : APP_URI);
                 $jsVars .= '&_exp=' . $exp . '&_base=' . urlencode($uri);
             }
         }
         $this->view->set('user', $sess->user)->set('role', \Phire\Table\UserRoles::getRole($sess->user->role_id))->set('globalAccess', $sess->user->global_access);
         if (isset($this->view->phireNav) && isset($this->view->acl) && $this->view->acl->hasRole($this->view->role->getName())) {
             $this->view->phireNav->setConfig(array('top' => array('node' => 'ul', 'id' => 'phire-nav')));
             $this->view->phireNav->setAcl($this->view->acl);
             $this->view->phireNav->setRole($this->view->role);
             $tree = $this->view->phireNav->getTree();
             // If the sub-children haven't been added yet
             if (isset($tree[0])) {
                 // And any user types to the main phire nav
                 $userTypes = \Phire\Table\UserTypes::findAll('id ASC');
                 if (isset($userTypes->rows)) {
                     foreach ($userTypes->rows as $type) {
                         $perm = 'index_' . $type->id;
                         if ($this->view->acl->isAuth('Phire\\Controller\\Phire\\User\\IndexController', 'index') && $this->view->acl->isAuth('Phire\\Controller\\Phire\\User\\IndexController', 'index_' . $type->id)) {
                             $perm = 'index';
                         }
                         $this->view->phireNav->addLeaf('Users', array('name' => ucwords(str_replace('-', ' ', $type->type)), 'href' => 'index/' . $type->id, 'acl' => array('resource' => 'Phire\\Controller\\Phire\\User\\IndexController', 'permission' => $perm)), 1);
                     }
                 }
                 // Set the language
                 $tree = $this->view->phireNav->getTree();
                 foreach ($tree as $key => $value) {
                     if (isset($value['name'])) {
                         $tree[$key]['name'] = $i18n->__($value['name']);
                         if (isset($value['children']) && count($value['children']) > 0) {
                             foreach ($value['children'] as $k => $v) {
                                 if ($v['name'] == 'Fields' && isset($tree[$key]['children'][$k]['children'][0]['name'])) {
                                     $tree[$key]['children'][$k]['children'][0]['name'] = $i18n->__($tree[$key]['children'][$k]['children'][0]['name']);
                                 }
                                 $tree[$key]['children'][$k]['name'] = $i18n->__($v['name']);
                             }
                         }
                     }
                 }
                 $this->view->phireNav->setTree($tree);
             }
             $this->view->phireNav->rebuild();
             $this->view->phireNav->nav()->setIndent('    ');
         }
     }
     if (isset($this->view->assets)) {
         $this->view->assets = str_replace('jax.3.2.0.min.js', 'jax.3.2.0.min.js' . $jsVars, $this->view->assets);
     }
     if (isset($sess->errors)) {
         $this->view->set('errors', $sess->errors);
     }
     // Set config object and system/site default data
     $this->view->set('i18n', $i18n)->set('system_title', $config->system_title)->set('system_email', $config->system_email)->set('site_title', $config->site_title)->set('base_path', $config->base_path)->set('separator', $config->separator)->set('default_language', $config->default_language)->set('datetime_format', $config->datetime_format);
 }
Exemple #4
0
 /**
  * Save user
  *
  * @param  \Pop\Form\Form $form
  * @param  \Pop\Config    $config
  * @return void
  */
 public function save(\Pop\Form\Form $form, $config)
 {
     $encOptions = $config->encryptionOptions->asArray();
     $fields = $form->getFields();
     $type = Table\UserTypes::findById($fields['type_id']);
     $password = isset($fields['password1']) ? self::encryptPassword($fields['password1'], $type->password_encryption, $encOptions) : '';
     // Set the username according to user type
     $username = isset($fields['username']) ? $fields['username'] : $fields['email1'];
     // Set the role according to user type
     if (isset($fields['role_id'])) {
         $fields['role_id'] = $fields['role_id'] == 0 ? null : $fields['role_id'];
     } else {
         $fields['role_id'] = $type->approval ? null : $type->default_role_id;
     }
     // Set verified or not
     if (!isset($fields['verified'])) {
         $fields['verified'] = $type->verification ? 0 : 1;
     }
     if (isset($fields['site_ids'])) {
         $siteIds = $fields['site_ids'];
     } else {
         $site = Table\Sites::getSite();
         $siteIds = array($site->id);
     }
     // Save the new user
     $user = new Table\Users(array('type_id' => $fields['type_id'], 'role_id' => $fields['role_id'], 'username' => $username, 'password' => $password, 'email' => $fields['email1'], 'verified' => $fields['verified'], 'logins' => null, 'failed_attempts' => 0, 'site_ids' => serialize($siteIds), 'created' => date('Y-m-d H:i:s')));
     $user->save();
     $this->data['id'] = $user->id;
     $sess = Session::getInstance();
     $sess->last_user_id = $user->id;
     FieldValue::save($fields, $user->id);
     // Send verification if needed
     if ($type->verification && !$user->verified) {
         $this->sendVerification($user, $type);
     }
     // Send registration notification to system admin
     if ($type->registration_notification) {
         $this->sendNotification($user, $type);
     }
     $form->clear();
 }
 /**
  * Register and load any other modules
  *
  * @param  \Pop\Loader\Autoloader $autoloader
  * @param  boolean                $site
  * @throws Exception
  * @return self
  */
 public function load($autoloader, $site = false)
 {
     if ($site) {
         $s = Table\Sites::getSite();
         $docRoot = $s->document_root;
         $basePath = $s->base_path;
     } else {
         $docRoot = $_SERVER['DOCUMENT_ROOT'];
         $basePath = BASE_PATH;
     }
     $events = array();
     // Load Phire any overriding Phire configuration
     if (!$site) {
         $this->loadAssets(__DIR__ . '/../../../Phire/data', 'Phire', $docRoot);
     }
     // Check if Phire is installed
     self::isInstalled();
     $sess = Session::getInstance();
     $errors = self::checkDirsQuick($docRoot . $basePath . CONTENT_PATH, true, $docRoot);
     if (count($errors) > 0) {
         $sess->errors = '            ' . implode('<br />' . PHP_EOL . '            ', $errors) . PHP_EOL;
     } else {
         unset($sess->errors);
     }
     $modulesAry = array();
     $modulesDirs = array(__DIR__ . '/../../../', __DIR__ . '/../../../../module/', __DIR__ . '/../../../../..' . CONTENT_PATH . '/extensions/modules/');
     // Check for overriding Phire config
     if (file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/extensions/modules/config/phire.php')) {
         $phireCfg = (include $docRoot . BASE_PATH . CONTENT_PATH . '/extensions/modules/config/phire.php');
         if (isset($phireCfg['Phire'])) {
             // If the overriding config is set to allow changes, merge new nav with the original nav
             // else, the entire original nav will be overwritten with the new nav.
             if (isset($phireCfg['Phire']->nav) && $phireCfg['Phire']->changesAllowed()) {
                 $nav = array_merge($phireCfg['Phire']->nav->asArray(), $this->module('Phire')->nav->asArray());
                 $phireCfg['Phire']->nav = new \Pop\Config($nav);
             }
             $this->module('Phire')->merge($phireCfg['Phire']);
             // Get any Phire event
             if (null !== $this->module('Phire')->events) {
                 $events['Phire'] = $this->module('Phire')->events->asArray();
             }
         }
     }
     // Register and load any other modules
     foreach ($modulesDirs as $directory) {
         if (file_exists($directory) && is_dir($directory)) {
             $dir = new Dir($directory);
             $dirs = $dir->getFiles();
             sort($dirs);
             foreach ($dirs as $d) {
                 $moduleCfg = null;
                 if ($d != 'PopPHPFramework' && $d != 'Phire' && $d != 'config' && $d != 'vendor' && is_dir($directory . $d)) {
                     $ext = Table\Extensions::findBy(array('name' => $d));
                     if (!isset($ext->id) || isset($ext->id) && $ext->active) {
                         $modulesAry[] = $d;
                         // Load assets
                         if (!$site) {
                             $this->loadAssets($directory . $d . '/data', $d, $docRoot);
                         }
                         // Get module config
                         if (file_exists($directory . $d . '/config/module.php')) {
                             $moduleCfg = (include $directory . $d . '/config/module.php');
                         }
                         // Check for any module config overrides
                         if (file_exists($directory . '/config/' . strtolower($d) . '.php')) {
                             $override = (include $directory . '/config/' . strtolower($d) . '.php');
                             if (isset($override[$d]) && null !== $moduleCfg) {
                                 $moduleCfg[$d]->merge($override[$d]);
                             }
                         }
                         // Load module configs
                         if (null !== $moduleCfg) {
                             // Register the module source
                             if (file_exists($moduleCfg[$d]->src)) {
                                 $autoloader->register($d, $moduleCfg[$d]->src);
                             }
                             // Get any module events
                             if (null !== $moduleCfg[$d]->events) {
                                 $events[$d] = $moduleCfg[$d]->events->asArray();
                             }
                             $this->loadModule($moduleCfg);
                         }
                     }
                 }
             }
         }
     }
     // Attach any event hooks
     if (count($events) > 0) {
         foreach ($events as $module => $evts) {
             foreach ($evts as $event => $action) {
                 $act = null;
                 $priority = 0;
                 if (is_array($action)) {
                     if (!isset($action['action'])) {
                         throw new Exception("The 'action' parameter is not set for the '" . $event . "' event within the " . $module . " module configuration file.");
                     }
                     $act = $action['action'];
                     $priority = isset($action['priority']) ? $action['priority'] : 0;
                 } else {
                     $act = $action;
                 }
                 if (null !== $act) {
                     $this->attachEvent($event, $act, $priority);
                 }
             }
         }
     }
     // Add Phire CSS override file if it exists
     if (file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/css/phire.css')) {
         $this->assets['css'] .= '    <style type="text/css">@import "' . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/css/phire.css";</style>' . PHP_EOL;
     }
     // If logged in, set Phire path cookie
     if (!$site && isset($sess->user)) {
         $path = BASE_PATH . APP_URI;
         if ($path == '') {
             $path = '/';
         }
         $cookie = Cookie::getInstance(array('path' => $path));
         if (!isset($cookie->phire)) {
             $modsAry = array();
             foreach ($modulesAry as $modName) {
                 $i18n = file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/assets/' . strtolower($modName) . '/i18n');
                 $modsAry[] = array('name' => $modName, 'i18n' => $i18n);
             }
             $cookie->set('phire', array('base_path' => BASE_PATH, 'app_path' => APP_PATH, 'content_path' => CONTENT_PATH, 'app_uri' => APP_URI, 'server_tz_offset' => abs(date('Z')) / 60, 'modules' => $modsAry));
         }
     }
     // Initiate the router object
     $this->loadRouter(new \Pop\Mvc\Router(array(), new \Pop\Http\Request(null, BASE_PATH)));
     return $this;
 }
 /**
  * Event-based auth check
  *
  * @param  \Pop\Mvc\Router $router
  * @return mixed
  */
 public static function auth($router)
 {
     $sess = Session::getInstance();
     $site = Sites::getSite();
     $basePath = $site->base_path;
     $resource = $router->getControllerClass();
     $permission = $router->getAction();
     $isFrontController = substr_count($resource, '\\') == 2;
     // Check for the resource and permission
     if (!$isFrontController && $resource != 'Phire\\Controller\\Phire\\Install\\IndexController') {
         if (null === $router->project()->getService('acl')->getResource($resource)) {
             if ($resource != 'Phire\\Controller\\Phire\\IndexController') {
                 $router->project()->getService('acl')->addResource($resource);
             } else {
                 $resource = null;
                 $permission = null;
             }
         }
         if (null !== $permission && null !== $resource && !method_exists($resource, $permission)) {
             $permission = 'error';
         }
         if ($router->controller()->getRequest()->getPath(0) == 'index' || $router->controller()->getRequest()->getPath(0) == 'add') {
             $permId = $router->controller()->getRequest()->getPath(1);
             if (null !== $permId && is_numeric($permId)) {
                 $permission .= '_' . $permId;
             }
         }
         // Get the user URI
         $uri = APP_URI == '' || strtolower($router->project()->getService('acl')->getType()->type) == 'user' ? APP_URI : '/' . strtolower($router->project()->getService('acl')->getType()->type);
         // If reset password flag is set
         if (isset($sess->reset_pwd) && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/profile' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/login' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/logout') {
             \Pop\Http\Response::redirect($basePath . $uri . '/profile');
             return \Pop\Event\Manager::KILL;
             // If not logged in for unsubscribe and required, redirect to the system login
         } else {
             if ($_SERVER['REQUEST_URI'] == $basePath . $uri . '/unsubscribe' && $router->project()->getService('acl')->getType()->unsubscribe_login && !$router->project()->getService('acl')->isAuth($resource, $permission)) {
                 \Pop\Http\Response::redirect($basePath . $uri . '/login');
                 return \Pop\Event\Manager::KILL;
                 // Else, if not logged in or allowed, redirect to the system login
             } else {
                 if ($_SERVER['REQUEST_URI'] != $basePath . $uri . '/login' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/register' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/forgot' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/unsubscribe' && substr($_SERVER['REQUEST_URI'], 0, strlen($basePath . $uri . '/json')) != $basePath . $uri . '/json' && strpos($_SERVER['REQUEST_URI'], $basePath . $uri . '/verify') === false && !$router->project()->getService('acl')->isAuth($resource, $permission)) {
                     \Pop\Http\Response::redirect($basePath . $uri . '/login');
                     return \Pop\Event\Manager::KILL;
                     // Else, if logged in and allowed, and a system access URI, redirect back to the system
                 } else {
                     if (($_SERVER['REQUEST_URI'] == $basePath . $uri . '/login' || $_SERVER['REQUEST_URI'] == $basePath . $uri . '/register' || $_SERVER['REQUEST_URI'] == $basePath . $uri . '/forgot') && $router->project()->getService('acl')->isAuth($resource, $permission)) {
                         \Pop\Http\Response::redirect($basePath . ($uri == '' ? '/' : $uri));
                         return \Pop\Event\Manager::KILL;
                     }
                 }
             }
         }
     }
 }
 /**
  * Method to filter the content and replace any placeholders
  *
  * @param   array $data
  * @param   int   $siteId
  * @returns array
  */
 protected function filterContent(array $data = null, $siteId = null)
 {
     $dataAry = null === $data ? $this->data : $data;
     if (isset($dataAry['site_id'])) {
         $siteId = (int) $dataAry['site_id'];
     } else {
         $siteId = (int) $siteId;
     }
     $site = Table\Sites::getSite($siteId);
     $keys = array_keys($dataAry);
     foreach ($dataAry as $key => $value) {
         if (is_string($value)) {
             $value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
             $value = str_replace(array('[{base_path}]', '[{content_path}]'), array($site->base_path, CONTENT_PATH), $value);
             foreach ($keys as $k) {
                 if (strpos($value, '[{' . $k . '}]') !== false && $dataAry[$k]) {
                     $value = str_replace('[{' . $k . '}]', $dataAry[$k], $value);
                 }
             }
             $dataAry[$key] = $value;
         } else {
             if (is_array($value)) {
                 $dataAry[$key] = $this->filterContent($value, $siteId);
             }
         }
     }
     if (null === $data) {
         $this->data = $dataAry;
     } else {
         $this->data = array_merge($this->data, $dataAry);
     }
     return $dataAry;
 }
Exemple #8
0
 /**
  * Get the init field values
  *
  * @param  int     $tid
  * @param  boolean $profile
  * @param  int     $uid
  * @param  string  $action
  * @param  boolean $register
  * @return array
  */
 protected function getInitFields($tid = 0, $profile = false, $uid = 0, $action, $register = false)
 {
     $type = Table\UserTypes::findById($tid);
     $fields1 = array();
     // Continue setting up initial user fields
     $fields1['email1'] = array('type' => 'text', 'label' => $this->i18n->__('Email'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\Email());
     if ($type->email_verification) {
         $fields1['email2'] = array('type' => 'text', 'label' => $this->i18n->__('Re-Type Email'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\Email());
     }
     // If not email as username, create username field
     if (!$type->email_as_username) {
         $fields2 = array('username' => array('type' => 'text', 'label' => $this->i18n->__('Username'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => array(new Validator\AlphaNumeric(), new Validator\LengthGte(4))));
         if ($uid != 0) {
             $fields2['username']['attributes']['onkeyup'] = "phire.updateTitle('#username-title', this);";
         }
     } else {
         $fields2 = array();
         if ($uid != 0) {
             $fields1['email1']['attributes']['onkeyup'] = "phire.updateTitle('#username-title', this);";
         }
     }
     // Continue setting up initial user fields
     if ($type->login) {
         $fields3 = array('password1' => array('type' => 'password', 'label' => $this->i18n->__('Enter Password'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\LengthGte(6)), 'password2' => array('type' => 'password', 'label' => $this->i18n->__('Re-Type Password'), 'required' => true, 'attributes' => array('size' => 30), 'validators' => new Validator\LengthGte(6)));
     } else {
         $fields3 = array();
     }
     $fieldGroups = array();
     $dynamicFields = false;
     $model = str_replace('Form', 'Model', get_class($this));
     $newFields = \Phire\Model\Field::getByModel($model, $tid, $uid);
     if ($newFields['dynamic']) {
         $dynamicFields = true;
     }
     if ($newFields['hasFile']) {
         $this->hasFile = true;
     }
     foreach ($newFields as $key => $value) {
         if (is_numeric($key)) {
             $fieldGroups[] = $value;
         }
     }
     $fields4 = array();
     if ($register) {
         $site = Table\Sites::getSite();
         if ($type->use_csrf) {
             $fields4['csrf'] = array('type' => 'csrf', 'value' => \Pop\Filter\String::random(8));
         }
         if ($type->use_captcha) {
             $fields4['captcha'] = array('type' => 'captcha', 'label' => $this->i18n->__('Enter Code'), 'captcha' => '<br /><img id="captcha-image" src="' . $site->base_path . '/captcha" /><br /><a class="reload-link" href="#" onclick="document.getElementById(\'captcha-image\').src = \'' . $site->base_path . '/captcha?reload=1\';return false;">' . $this->i18n->__('Reload') . '</a>', 'attributes' => array('size' => 5));
         }
     }
     // Finish the initial fields
     $fields4['submit'] = array('type' => 'submit', 'value' => strpos($action, '/register') !== false ? $this->i18n->__('REGISTER') : $this->i18n->__('SAVE'), 'attributes' => array('class' => strpos($action, '/install/user') !== false || $profile ? 'update-btn' : 'save-btn'));
     if ($profile) {
         $fields4['submit']['label'] = '&nbsp;';
         $fields4['submit']['attributes']['style'] = 'width: 250px;';
         $fields4['profile'] = array('type' => 'hidden', 'value' => 1);
         $sess = \Pop\Web\Session::getInstance();
         if (isset($sess->reset_pwd)) {
             $fields4['reset_pwd'] = array('type' => 'hidden', 'value' => 1);
         }
     }
     if (!$profile) {
         $fields4['update'] = array('type' => 'button', 'value' => $this->i18n->__('Update'), 'attributes' => array('onclick' => "return phire.updateForm('#user-form', " . ($this->hasFile || $dynamicFields ? 'true' : 'false') . ");", 'class' => 'update-btn'));
     }
     $fields4['type_id'] = array('type' => 'hidden', 'value' => $tid);
     $fields4['id'] = array('type' => 'hidden', 'value' => 0);
     if (!$profile) {
         $fields4['update_value'] = array('type' => 'hidden', 'value' => 0);
     }
     // If not profile
     if (!$profile) {
         // Get roles for user type
         $rolesAry = array('0' => '(' . $this->i18n->__('Blocked') . ')');
         if ($tid != 0) {
             $roles = Table\UserRoles::findBy(array('type_id' => $tid), 'id ASC');
             foreach ($roles->rows as $role) {
                 $rolesAry[$role->id] = $role->name;
             }
         }
         $siteIds = array('0' => $_SERVER['HTTP_HOST']);
         $sites = Table\Sites::findAll();
         foreach ($sites->rows as $site) {
             $siteIds[(string) $site->id] = $site->domain;
         }
         $fields4['role_id'] = array('type' => 'select', 'required' => true, 'label' => $this->i18n->__('User Role'), 'value' => $rolesAry, 'marked' => $type->default_role_id);
         $fields4['verified'] = array('type' => 'select', 'label' => $this->i18n->__('Verified'), 'value' => array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), 'marked' => '0');
         $fields4['failed_attempts'] = array('type' => 'text', 'label' => $this->i18n->__('Failed Attempts'), 'attributes' => array('size' => 3));
         $fields4['site_ids'] = array('type' => 'checkbox', 'label' => $this->i18n->__('Allowed Sites'), 'value' => $siteIds);
     }
     if (strpos($action, '/install/user') !== false || $profile) {
         $allFields = array($fields1, $fields2, $fields3);
         if (count($fieldGroups) > 0) {
             foreach ($fieldGroups as $fg) {
                 $allFields[] = $fg;
             }
         }
         $allFields[] = $fields4;
     } else {
         $allFields = array($fields4, $fields1, $fields2, $fields3);
         if (count($fieldGroups) > 0) {
             foreach ($fieldGroups as $fg) {
                 $allFields[] = $fg;
             }
         }
     }
     return $allFields;
 }