/** * Build a multi-array of parent > children. * * @return array An array representing the page tree. */ public function get_links_tree() { if (\Bundle::exists('pages')) { $all_links = Link::with('page')->order_by('order', 'asc')->get(array('id', 'group_id', 'title', 'class')); } else { $all_links = Link::order_by('order', 'asc')->get(array('id', 'group_id', 'title', 'class')); } // First, re-index the array. foreach ($all_links as $row) { $pages[$row->id] = array('id' => $row->id, 'li_id' => 'link_', 'link_type' => $row->link_type, 'rel' => $row->navigation_group_id, 'parent_id' => $this->id, 'title' => $row->title, 'url' => $row->url, 'target' => $row->target, 'class' => $row->class); } unset($all_links); // Build a multidimensional array of parent > children. foreach ($pages as $row) { if (array_key_exists($row['parent_id'], $pages)) { // Add this page to the children array of the parent page. $pages[$row['parent_id']]['children'][] =& $pages[$row['id']]; } // This is a root page. if ($row['parent_id'] == 0) { $page_array[] =& $pages[$row['id']]; } } return $page_array; }
public function group() { if (\Bundle::exists('groups')) { return $this->belongs_to('Groups\\Model\\Group'); } else { throw new \Exception('Groups module is not installed. To call users with group you must install the groups module.'); } }
public function users() { if (\Bundle::exists('permissions')) { return $this->has_many('Users\\Model\\User'); } else { throw new \Exception('Permissions module is not installed. To call goups with users you must install the permissions module.'); } }
public function get_new() { $this->data['section_bar_active'] = __('email::lang.Send Email')->get(ADM_LANG); $this->data['groups_dropdown'] = null; if (Bundle::exists('groups')) { $this->data['groups_dropdown'] = Groups\Model\Group::all(); } $this->data['email_templates'] = Email\Model\Template::all(); return $this->theme->render('email::email.new', $this->data); }
public function __construct() { parent::__construct(); $this->filter('before', 'auth'); $this->filter('before', 'mwi.admin_controller_start', array($this)); // $this->filter('before', 'check_rule:admin'); $this->filter('before', 'csrf')->on('post'); $this->data['installed_and_active_modules'] = Modules\Model\Module::where('enabled', '=', 1)->get(array('name', 'menu')); if (Bundle::exists('themes')) { $this->theme->set_theme(Config::get('settings::core.backend_theme'), 'backend'); $this->theme->set_layout(Config::get('settings::core.backend_layout'), 'backend'); $this->theme->_theme_data = $this->data; } }
public function __construct() { parent::__construct(); $this->data['site_name'] = Config::get('settings::core.site_name'); $this->data['meta_title'] = ''; $this->data['meta_description'] = ''; $this->data['meta_keywords'] = ''; if (Bundle::exists('themes')) { $this->theme = IoC::resolve('Theme'); } // @TODO add fallback if themes module for // some reason is not installed/enabled $this->filter('before', 'mwi.base_controller_start', array($this)); }
function __construct() { parent::__construct(); if (Bundle::exists('themes')) { $this->theme->set_theme(Config::get('settings::core.frontend_theme')); $this->theme->set_layout(Config::get('settings::core.frontend_layout')); } $maintenance = Config::get('settings::core.site_maintenance'); if ($maintenance == 'yes') { echo View::make('admin::frontend.maintenance'); die; } $this->filter('before', 'mwi.private_controller_start', array($this)); $this->filter('before', 'auth'); $this->filter('before', 'csrf')->on('post'); }
function __construct() { parent::__construct(); if (Bundle::exists('themes')) { $this->theme->set_theme(Config::get('settings::core.frontend_theme', 'frontend')); $this->theme->set_layout(Config::get('settings::core.frontend_layout')); } $maintenance = Config::get('settings::core.site_maintenance'); if ($maintenance == 'yes') { $this->data['site_name'] = Config::get('settings::core.site_name'); echo $this->theme->render('admin::frontend.maintenance', $this->data); die; } $this->filter('before', 'mwi.public_controller_start', array($this)); $this->filter('before', 'csrf')->on('post'); }
public function get_links() { $links_raw = array(); foreach ($this->links as $link) { if ($this->passes(explode(',', $link->restricted_to), new Auth())) { // Check the link type to set the wright url $url = '#'; if ($link->link_type == 'url') { $url = $link->url; } if ($link->link_type == 'uri') { $url = $link->uri; } if ($link->link_type == 'module') { $url = 'what put here'; } if ($link->link_type == 'page') { // If pages module is not installed // the link_type should not be page // lets test it if (\Bundle::exists('pages')) { if (!is_null($link->page)) { $url = $link->page->slug; } else { $url = '404'; } } } $links_raw[$link->id] = array('id' => $link->id, 'li_id' => 'link_', 'link_type' => $link->link_type, 'rel' => $this->id, 'parent_id' => $link->parent, 'title' => $link->title, 'url' => $url, 'target' => $link->target, 'class' => $link->class); } } $links_result = array(); foreach ($links_raw as $link) { if (array_key_exists($link['parent_id'], $links_raw)) { // Add this page to the children array of the parent page. $links_raw[$link['parent_id']]['children'][] =& $links_raw[$link['id']]; } // This is a root page. if ($link['parent_id'] == 0) { $links_result[] =& $links_raw[$link['id']]; } } return $links_result; }
/** * Load the file corresponding to a given class. * * This method is registerd in the bootstrap file as an SPL auto-loader. * * @param string $class * @return void */ public static function load($class) { // First, we will check to see if the class has been aliased. If it has, // we will register the alias, which may cause the auto-loader to be // called again for the "real" class name. if (isset(static::$aliases[$class])) { class_alias(static::$aliases[$class], $class); } elseif (isset(static::$mappings[$class])) { require static::$mappings[$class]; } // If the class namespace is mapped to a directory, we will load the // class using the PSR-0 standards from that directory; however, we // will trim off the beginning of the namespace to account for // the root of the mapped directory. if (!is_null($info = static::namespaced($class))) { $class = substr($class, strlen($info['namespace'])); return static::load_psr($class, $info['directory']); } elseif (($slash = strpos($class, '\\')) !== false) { $namespace = substr($class, 0, $slash); // If the class is namespaced to an existing bundle and the bundle has // not been started, we will start the bundle and attempt to load the // class file again. If that fails, an error will be thrown by PHP. // // This allows bundle classes to be loaded by the auto-loader before // their class mappings have actually been registered; however, it // is up to the bundle developer to namespace their classes to // match the name of their bundle. if (Bundle::exists($namespace) and !Bundle::started($namespace)) { Bundle::start(strtolower($namespace)); static::load($class); } } // If the class is not maped and is not part of a bundle or a mapped // namespace, we'll make a last ditch effort to load the class via // the PSR-0 from one of the registered directories. static::load_psr($class); }
<?php if (!Bundle::exists('vane')) { throw new Error('VaneMart requires Vane bundle installed.'); } else { Bundle::start('vane'); Vane\aliasIn('VaneMart'); } Squall\initEx('VaneMart'); Vane\overrideHTMLki('vanemart::', array('ns' => 'VaneMart', 'stickyFormHiddens' => array('back'))); require_once __DIR__ . DS . 'core.php'; require_once __DIR__ . DS . 'events.php'; Vane\Current::set(VaneMart\VANE_NS); // More flexible autoloader for VaneMart flat class structure. spl_autoload_register(function ($class) { $base = $file = __DIR__ . DS . 'classes' . DS; if (substr($class, 0, 9) === 'VaneMart\\') { @(list($group, $rest) = explode('_', substr($class, 9), 2)); if (isset($rest)) { $file .= strtolower($group) . DS . $rest; } else { $file .= is_file("{$file}{$group}.php") ? $group : 'model' . DS . substr($class, 9); } } else { $file .= 'vendor' . DS . $class; } $file .= '.php'; is_file($file) and (include $file); }); View::composer('vanemart::full', function ($view) { $normAssets = function ($type) use($view) {
<?php Autoloader::namespaces(array('Permissions\\Model' => Bundle::path('permissions') . 'models' . DS, 'Permissions' => Bundle::path('permissions') . 'libraries' . DS)); Route::filter('mwi.admin_controller_start', function ($controller) { $permissions = new \Permissions\Check(\Request::route(), $controller); if (!Bundle::exists('auth')) { return; } // Fix route bundle if // its an administration route $uri = Request::route()->uri; $uri_parts = explode('/', $uri); // check if is set // check if first part is administration uri // check if is not only the dashboard http://site.com/[admin] if (isset($uri_parts['0']) and $uri_parts['0'] = ADM_URI and count($uri_parts) > 1) { unset($uri_parts['0']); $uri = implode('/', $uri_parts); Request::route()->bundle = Bundle::handles($uri); $controller->bundle = Request::route()->bundle; } $result = $permissions::can(Auth::user()); if (isset($result)) { if (!$result->is_allowed) { if (Request::ajax()) { return 'not permited'; } else { return \Response::error('401', get_object_vars($result)); } } } else {
public function get_new($group_id) { if (Bundle::exists('pages')) { $pages = Pages\Model\Page::where('status', '=', 'live')->get(array('id', 'title')); } else { $pages = null; } $modules = Modules\Model\Module::where('enabled', '=', 1)->where('is_frontend', '=', 1)->get(array('id', 'slug', 'name')); $groups = Groups\Model\Group::all(); return View::make('navigation::backend.links.create', $this->data)->with('nav_group_id', $group_id)->with('modules', $modules)->with('pages', $pages)->with('groups', $groups); }
<?php namespace Vane; \Bundle::$bundles['vane']['ignorePlarx'] = array('Str', 'HLEx', 'Log', 'Event', 'Validator'); if (!\Bundle::exists('plarx')) { throw new Error('Vane requires Plarx bundle installed.'); } else { \Bundle::start('plarx'); \Px\Plarx::supersede(__NAMESPACE__, \Bundle::option('vane', 'ignorePlarx')); } if (!\Bundle::exists('squall')) { throw new Error('Vane requires Squall bundle installed.'); } else { \Bundle::start('squall'); \Squall\initEx(__NAMESPACE__); } \Autoloader::namespaces(array(__NAMESPACE__ => __DIR__ . DS . 'classes')); require_once __DIR__ . DS . 'core.php'; overrideHTMLki('vane::', __NAMESPACE__); // vane::auth[:[!]perm[:[!]perm.2[...]]] [|filter:2 [|...]] // // This filter will always deny access for non-authorized users even if guest // permissions allow for given features - this is so because protected controllers // rely on current user being logged in. \Route::filter('vane::auth', function ($feature_1 = null) { $features = is_array($feature_1) ? $feature_1 : func_get_args(); $block = is_object(end($features)) ? array_pop($features) : null; $user = \Auth::user(); if ($user and !$user instanceof UserInterface) { $msg = "When using vane::auth filter object returned by Auth::user()" . " (" . get_class($user) . " here) must implement Vane\\UserInterface." . " This is not so - returned 403 for user {$user->id}.";
public function delete_destroy($group_id) { if (!ctype_digit($group_id)) { $this->data['message'] = __('groups::lang.Invalid id')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::back()->with($this->data); } if (Bundle::exists('permissions')) { $group = Groups\Model\Group::with('permissions')->find($group_id); } else { $group = Groups\Model\Group::find($group_id); } if (!isset($group) or empty($group)) { $this->data['message'] = __('groups::lang.Sorry cannot find group to delete')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::back()->with($this->data); } $users_group = Groups\Model\Group::where('slug', '=', 'users')->first(); // if there is users on this group // set all users back to users group if (isset($users_group) and isset($users_group->id)) { $update = Users\Model\User::where('group_id', '=', $group->id)->update(array('group_id' => $users_group->id)); } if (isset($group->permissions) and !empty($group->permissions)) { $group->permissions()->delete(); } $group->delete(); Event::fire('mwi.group_deleted', array($group)); $this->data['message'] = __('groups::lang.Group was successfully destroyed')->get(ADM_LANG); $this->data['message_type'] = 'success'; return Redirect::to(ADM_URI . '/groups')->with($this->data); }
<?php /* |-------------------------------------------------------------------------- | Hipchat Library |-------------------------------------------------------------------------- | | Map Hipchat Library using PSR-0 standard namespace. | */ Autoloader::namespaces(array('Hipchat' => Bundle::path('hipchat') . 'libraries')); /* |-------------------------------------------------------------------------- | Load Bundle dependencies |-------------------------------------------------------------------------- | | Should load Hybrid bundle if it's not registered. | */ if (!Bundle::exists('hybrid')) { Bundle::register('hybrid'); Bundle::start('hybrid'); }
/** * Determine class names, identifiers and arguments based on the args * passed by the build script. * * @param array Arguments to the build script. * @return void */ public function __construct($args) { // we need a writer object for file system changes $this->writer = new Writer(); // set default args $this->args = $args; // if we got an argument if (isset($args[0])) { // check to see if its bundle prefixed if (strstr($args[0], '::')) { $parts = explode('::', $args[0]); // if we have a bundle and a class if (count($parts) == 2 && $parts[0] !== '') { $this->bundle = Str::lower($parts[0]); if (!Bundle::exists($this->bundle)) { Common::error('The specified bundle does not exist, or is not loaded.'); } // remove the bundle section, we are done with that $args[0] = $parts[1]; } } else { // use the application folder if no bundle $this->bundle = DEFAULT_BUNDLE; } // set bundle path from bundle name $this->bundle_path = Bundle::path($this->bundle); // if we have a multi-level path if (strstr($args[0], '.')) { $parts = explode('.', $args[0]); // form the class prefix as in Folder_Folder_Folder_ $this->class_prefix = Str::classify(implode('_', array_slice($parts, 0, -1)) . '_'); // form the path to the class $this->class_path = Str::lower(implode('/', array_slice($parts, 0, -1)) . '/'); // unaltered case class $this->standard = $parts[count($parts) - 1]; // lowercase class $this->lower = Str::lower($parts[count($parts) - 1]); // get our class name $this->class = Str::classify($parts[count($parts) - 1]); } else { // unaltered case class $this->standard = $args[0]; // lowercase class $this->lower = Str::lower($args[0]); // get our class name $this->class = Str::classify($args[0]); } } // pass remaining arguments $this->arguments = array_slice($args, 1); }
<?php // Start Former Bundle::start('former'); // Start Bootstrapper if installed (as it sometimes alias Form) if (Bundle::exists('bootstrapper')) { Bundle::start('bootstrapper'); } // Start session (don't know why I get bugs with this sometimes) Session::start('file'); // Base Test class for matchers class FormerTests extends PHPUnit_Framework_TestCase { protected function cg($input, $label = '<label for="foo" class="control-label">Foo</label>') { return '<div class="control-group">' . $label . '<div class="controls">' . $input . '</div></div>'; } public static function setUpBeforeClass() { \Former\Former::horizontal_open(); } public static function tearDownAfterClass() { \Former\Former::close(); } /** * This function has no points * It's only here because I can't extend Framework_TestCase otherwise */ public function testTrue() {
/** * Test the Bundle::exist method. * * @group laravel */ public function testExistMethodIndicatesIfBundleExist() { $this->assertTrue(Bundle::exists('dashboard')); $this->assertFalse(Bundle::exists('foo')); }
public function post_create() { $messages = array('unique_avatar_name' => 'This combination of avatar first name and avatar last name has already been taken.'); $rules = array('email' => 'required|email|unique:users', 'username' => 'required|unique:users|alpha_dash|max:30|min:3', 'avatar_first_name' => 'required|alpha_dash|max:30|min:3|unique_avatar_name', 'avatar_last_name' => 'required|alpha_dash|max:30|min:3', 'password' => 'required|min:8', 'password_confirmation' => 'required|same:password'); Validator::register('unique_avatar_name', function ($attribute, $value, $parameters) { $user = Users\Model\User::where('avatar_first_name', '=', Input::get('avatar_first_name'))->where('avatar_last_name', '=', Input::get('avatar_last_name'))->first(); if (isset($user) and !empty($user)) { return false; } return true; }); $validation = Validator::make(Input::all(), $rules, $messages); if ($validation->passes()) { $group_id = 0; if (Bundle::exists('groups')) { $users_group = Groups\Model\Group::where('slug', '=', 'users')->first(); if (isset($users_group->id) and ctype_digit($users_group->id)) { $group_id = $users_group->id; } } $new_user = new Users\Model\User(); $new_user->status = 'inactive'; $require_confirmation = Config::get('settings::core.registration_confirmation_required'); if ($require_confirmation == 'no') { $new_user->status = 'active'; } $password = Users\Helper::hash_password(Input::get('password')); $new_user->uuid = Mwi_Core::random_uuid(); $new_user->email = Input::get('email'); $new_user->username = Input::get('username'); $new_user->avatar_first_name = Input::get('avatar_first_name'); $new_user->avatar_last_name = Input::get('avatar_last_name'); $new_user->group_id = $group_id; $new_user->hash = $password['hash']; $new_user->salt = $password['salt']; $new_user->password = Hash::make(Input::get('password')); $new_user->save(); Event::fire('registration.user_signup', array($new_user)); //Event for Robust Event::fire('users.created', array($new_user)); if ($require_confirmation == 'no') { Auth::login($new_user->id); Event::fire('registration.user_activated', array($new_user)); //Event for Robust Event::fire('users.updated', array($new_user)); $site_name = Settings\Config::get('settings::core.site_name'); $this->data['message'] = Lang::line('registration::lang.welcome_signup', array('site_name' => $site_name))->get(APP_LANG); $this->data['message_type'] = 'success'; return Redirect::to('page/home')->with($this->data); } else { // save activation record on database $activation_record = new Registration\Model\Code(); $activation_record->user_id = $new_user->id; $activation_record->code = Mwi_Core::keygen(); $activation_record->save(); // new xblade to parse the email template $xblade = new Xblade(); $xblade->scopeGlue(':'); // data to be passed to email template $data['user'] = $new_user; $data['activation_code'] = $activation_record->code; $data['url']['base'] = URL::base(); $data['settings']['site_name'] = Config::get('settings::core.site_name'); $data['request']['ip'] = Request::ip(); $data['request']['user_agent'] = implode(', ', Request::header('user-agent')); $data['request']['languages'] = implode(', ', Request::languages()); // get email template based on settings $email_address = Config::get('settings::core.server_email'); $template_id = Config::get('settings::core.registration_email_template'); $email_data = Email\Model\Template::find($template_id); //send email to user Email\Message::to($new_user->email)->from($email_address)->subject($xblade->parse($email_data->subject, $data))->body($xblade->parse($email_data->body, $data))->html($email_data->type)->send(); $this->data['message'] = __('registration::lang.Thank you Please check your email to activate your new account')->get(APP_LANG); $this->data['message_type'] = 'success'; return Redirect::to('page/home')->with($this->data); } } return Redirect::to('signup')->with_errors($validation)->with_input(); }
public function get_edit($user_id) { if (!ctype_digit($user_id)) { $this->data['message'] = __('users::lang.Invalid id to edit user')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::to(ADM_URI . '/users')->with($this->data); } $this->data['section_bar_active'] = __('users::lang.Edit')->get(ADM_LANG); $this->data['section_bar'] = array(__('users::lang.Users')->get(ADM_LANG) => URL::base() . '/' . ADM_URI . '/users', __('users::lang.New User')->get(ADM_LANG) => URL::base() . '/' . ADM_URI . '/users/new', __('users::lang.Edit')->get(ADM_LANG) => URL::base() . '/' . ADM_URI . '/users/' . $user_id . '/edit'); if (\Bundle::exists('groups')) { $this->data['groups_dropdown'] = Groups\Model\Group::all(); } $this->data['edit_user'] = Users\Model\User::find($user_id); if (!isset($this->data['edit_user']) or empty($this->data['edit_user'])) { $this->data['message'] = __('users::lang.Sorry can\'t find user to edit')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::to(ADM_URI . '/users')->with($this->data); } return $this->theme->render('users::backend.edit', $this->data); }