/** * sidebar function * Create sidebar * @return string * @author joharijumali **/ public static function sidebar() { // $Menu = Header::navigationdata(); $flow = URI::segment(3) == 'step' ? true : false; $navValue = array(array(Navigation::HEADER, Str::upper(Lang::line('admin.monitor')->get())), array(Lang::line('admin.dashboard')->get(), url('admin/home/dashboard'), false, false, null, 'tasks'), array(Navigation::HEADER, Str::upper(Lang::line('admin.sysmgmt')->get())), array(Lang::line('admin.configmanagement')->get(), url('admin/system/sysConfig'), false, false, null, 'chevron-right'), array(Lang::line('admin.datamanagement')->get(), url('admin/data/board'), false, false, null, 'chevron-right'), array(Lang::line('admin.pagemanagement')->get(), url('admin/modul/page'), false, false, null, 'chevron-right'), array(Lang::line('admin.flowmanagement')->get(), url('admin/modul/flow'), $flow, false, null, 'chevron-right'), array(Lang::line('admin.navsetup')->get(), url('admin/system/navigate'), false, false, null, 'chevron-right'), array(Lang::line('admin.log')->get(), url('admin/system/logger'), false, false, null, 'chevron-right'), array(Navigation::HEADER, Str::upper(Lang::line('admin.sysuser')->get())), array(Lang::line('admin.navuserlist')->get(), url('admin/user/list'), false, false, null, 'chevron-right'), array(Lang::line('admin.navuserrole')->get(), url('admin/user/role'), false, false, null, 'chevron-right'), array(Navigation::HEADER, Lang::line('global.logout')->get()), array(Lang::line('global.logout')->get(), url('admin/login/logout'), false, false, null, 'off')); return Navigation::lists(Navigation::links($navValue)); }
/** * Register opinionated controllers * * @param array $controllers the controllers and config * @param string $bundle the bundle where the controller can be found * @param string $url_prefix a global url prefix * @param string $route_type the type of the route (pages or api) * @param array $parents */ public static function opinionated($controllers, $bundle, $url_prefix, $route_type, $parents = array()) { if (!ends_with($url_prefix, '/')) { $url_prefix .= '/'; } foreach ($controllers as $controller => $options) { list($types, $children) = $options; foreach ($types as $type) { list($method, $plural, $has_identity, $postfix) = static::$types[$type]; $segment = $controller; $action = ($bundle ? $bundle . '::' : '') . implode('.', $parents) . (count($parents) > 0 ? '.' : '') . $segment . '@' . $type; if ($plural) { $segment = Str::plural($segment); } $prefixes = array_map(function ($parent) { return $parent ? $parent . '/(:any)/' : '(:any)/'; }, $parents); $prefix = implode('', $prefixes); $route = $url_prefix . $prefix . $segment . ($has_identity ? '/(:any)' : '') . ($route_type == 'pages' && $postfix ? '/' . $postfix : ''); if ($route_type == 'pages') { $method = '*'; } Router::register($method, $route, $action); } $parents[] = $controller; if (is_array($children)) { static::opinionated($children, $bundle, $url_prefix, $route_type, $parents); } $parents = array(); } }
public static function getModel($model) { $models = static::getModels(); if (!in_array($model, $models)) { return false; } $model = Str::singular($model); return $model; }
protected function runMigration($version, $migration, $method) { $file = $this->path() . $version . DS . $migration . '.php'; $this->log('Migrate ' . $migration . '...'); $class = 'FluxBB_Update_' . Str::classify($migration); include_once $file; $instance = new $class(); $instance->{$method}(); }
public static function setData($input) { $Category = $input['id'] == NULL || !isset($input['id']) ? new Status() : Status::find($input['id']); $Category->status_name = Str::title($input['data']); $Category->status_desc = $input['description']; $Category->save(); $action = $input['id'] == NULL || !isset($input['id']) ? 'Insert' : '<b>(' . $input['id'] . ')</b> Update'; Log::write('Data', 'Status <b>' . $input['data'] . '</b> ' . $action . ' by ' . Auth::user()->username); }
/** * Get the stub migration with the proper class name. * * @param string $bundle * @param string $migration * @return string */ protected function stub($bundle, $migration) { $stub = File::get(Bundle::path('doctrine') . 'migration_stub' . EXT); $prefix = Bundle::class_prefix($bundle); // The class name is formatted simialrly to tasks and controllers, // where the bundle name is prefixed to the class if it is not in // the default "application" bundle. $class = $prefix . Str::classify($migration); return str_replace('{{class}}', $class, $stub); }
/** * Get a new session ID that isn't assigned to any current session. * * @return string */ public function id() { $session = array(); // We'll containue generating random IDs until we find an ID that is // not currently assigned to a session. This is almost definitely // going to happen on the first iteration. do { $session = $this->load($id = Str::random(40)); } while (!is_null($session)); return $id; }
public static function listData() { $allGroup = Group::paginate(Config::get('system.pagination')); $datagrid = new Datagrid(); $datagrid->setFields(array('group_name' => Str::upper(Lang::line('admin.datagroup')->get()))); $datagrid->setAction(Lang::line('global.manage')->get(), 'datacontent', false); $datagrid->setAction(Lang::line('global.edit')->get(), 'editGroup', true, array('dmid')); $datagrid->setAction(Lang::line('global.delete')->get(), 'deleteGroup', true, array('dmid', 'group_name')); $datagrid->setTable('dataGroup', 'table table-bordered table-hover table-striped table-condensed'); $datagrid->build($allGroup, 'dmid'); return $datagrid->render(); }
public static function listRole() { $rolelist = Role::paginate(Config::get('system.pagination')); $datagrid = new Datagrid(); $datagrid->setFields(array('role' => Str::upper(Lang::line('admin.rolename')->get()), 'roledesc' => Str::upper(Lang::line('admin.roledesc')->get()))); $datagrid->setAction(Lang::line('global.edit')->get(), 'editRoleModal', true, array('roleid')); //false,array('id'=>'roleid','data-toggle'=>'modal')); $datagrid->setAction(Lang::line('global.delete')->get(), 'deleteRole', true, array('roleid')); $datagrid->setContainer('list01', 'span12'); $datagrid->setTable('users', 'table table-bordered table-hover table-striped table-condensed'); $datagrid->build($rolelist, 'roleid'); return $datagrid->render(); }
/** * Generate a random key for the application. * * @param array $arguments * @return void */ public function generate($arguments = array()) { // By default the Crypter class uses AES-256 encryption which uses // a 32 byte input vector, so that is the length of string we will // generate for the application token unless another length is // specified through the CLI. $key = Str::random(array_get($arguments, 0, 32)); $config = File::get($this->path); $config = str_replace("'key' => '',", "'key' => '{$key}',", $config, $count); File::put($this->path, $config); if ($count > 0) { echo "Configuration updated with secure key!"; } else { echo "An application key already exists!"; } echo PHP_EOL; }
public function get_edit($model = null, $id = null) { $name = $model; if (is_null($model) || is_null($id)) { return Redirect::to(Adminify\Libraries\Helpers::url('/')); } $model = Helpers::getModel($model); if (is_null($model)) { return Redirect::to(Adminify\Libraries\Helpers::url('/')); } $entry = $model::find($id); $table = property_exists($model, 'table') && !is_null($model::$table) ? $model::$table : strtolower(Str::plural($model)); $structure = DB::query("SHOW COLUMNS FROM `" . $table . "`"); $excluded = Helpers::getFields($model); $this->layout->title = 'Edit ' . $model; $this->layout->nest('content', 'adminify::models.edit', array('entry' => $entry, 'model' => $model, 'name' => $name, 'structure' => $structure, 'excluded' => $excluded)); }
/** * Get a new session ID that isn't assigned to any current session. * * @return string */ public function id() { $session = array(); // If the driver is an instance of the Cookie driver, we are able to // just return any string since the Cookie driver has no real idea // of a server side persisted session with an ID. if ($this instanceof Cookie) { return Str::random(40); } // We'll continue generating random IDs until we find an ID that is // not currently assigned to a session. This is almost definitely // going to happen on the first iteration. do { $session = $this->load($id = Str::random(40)); } while (!is_null($session)); return $id; }
public static function userSearchList($input) { $operator = stripos($input['searchval'], '*') ? 'LIKE' : '='; $val = str_replace("*", "", $input['searchval']); $refval = stripos($input['searchval'], '*') ? '%' . $val . '%' : $val; $allUser = User::left_join('users_profiles', 'users.userid', '=', 'users_profiles.userid')->where('icno', $operator, $refval)->or_where('fullname', $operator, $refval)->paginate(Config::get('system.pagination')); $datagrid = new Datagrid(); $datagrid->setFields(array('userprofile/fullname' => Str::upper(Str::title(Lang::line('admin.fullname')->get())))); $datagrid->setFields(array('userprofile/emel' => Str::upper(Str::title(Lang::line('admin.activeemel')->get())))); $datagrid->setFields(array('userprofile/icno' => Str::upper(Str::title(Lang::line('admin.idno')->get())))); $datagrid->setFields(array('status' => Str::upper('Status'))); $datagrid->setAction(Lang::line('global.edit')->get(), 'viewUser', true, array('userid')); $datagrid->setAction(Lang::line('global.delete')->get(), 'deleteAccount', true, array('userid')); $datagrid->setAction(Lang::line('global.reset')->get(), 'resetAccount', true, array('userid')); $datagrid->setTable('users', 'table table-bordered table-hover table-striped table-condensed'); $datagrid->build($allUser, 'userid'); return $datagrid->render(); }
/** * Load the session for the current request. * * @param string $id * @return void */ public function load($id) { if (!is_null($id)) { $this->session = $this->driver->load($id); } // If the session doesn't exist or is invalid we will create a new session // array and mark the session as being non-existent. Some drivers, such as // the database driver, need to know whether it exists. if (is_null($this->session) or static::expired($this->session)) { $this->exists = false; $this->session = $this->driver->fresh(); } // A CSRF token is stored in every session. The token is used by the Form // class and the "csrf" filter to protect the application from cross-site // request forgery attacks. The token is simply a random string. if (!$this->has(Session::csrf_token)) { $this->put(Session::csrf_token, Str::random(40)); } }
/** * Generate Data datagrid table * * @return void * @author **/ public static function genListData() { $allContent = Content::paginate(Config::get('system.pagination')); $datagrid = new Datagrid(); $tableCol = DB::query('show columns from ' . Content::$table); foreach ($tableCol as $value) { if ($value->field != 'created_at' && $value->field != 'updated_at' && $value->field != Content::$key) { if (stristr($value->field, 'name')) { $title = Str::upper(Lang::line('global.data')->get()); } elseif (stristr($value->field, 'desc')) { $title = Str::upper(Lang::line('global.desc')->get()); } else { $title = $value->field; } $datagrid->setFields(array($value->field => $title)); } } $datagrid->setAction(Lang::line('global.edit')->get(), 'editData', true, array(Content::$key)); $datagrid->setAction(Lang::line('global.delete')->get(), 'deleteData', true, array(Content::$key)); $datagrid->setTable('contentGroup', 'table table-bordered table-hover table-striped table-condensed'); $datagrid->build($allContent, Content::$key); return $datagrid->render(); }
/** * Format a bundle and controller identifier into the controller's class name. * * @param string $bundle * @param string $controller * @return string */ protected static function format($bundle, $controller) { return Bundle::class_prefix($bundle) . Str::classify($controller) . '_Controller'; }
protected function getParameter($key) { if (isset($_SERVER['CLI'][Str::upper($key)])) { return $_SERVER['CLI'][Str::upper($key)] == '' ? true : $_SERVER['CLI'][Str::upper($key)]; } else { return false; } }
/** * Validate that an attribute is an active URL. * * @param string $attribute * @param mixed $value * @return bool */ protected function validate_active_url($attribute, $value) { $url = str_replace(array('http://', 'https://', 'ftp://'), '', Str::lower($value)); return checkdnsrr($url); }
/** * Assign a new, random ID to the session. * * @return void */ public function regenerate() { $this->session['id'] = Str::random(40); $this->exists = false; }
/** * Test the Auth::recall method. * * @group laravel */ public function testUserCanBeRecalledViaCookie() { Session::$instance = new Payload($this->getMock('Laravel\\Session\\Drivers\\Driver')); $cookie = Crypter::encrypt('1|' . Str::random(40)); Cookie::forever('authloginstub_remember', $cookie); $auth = new AuthLoginStub(); $this->assertEquals('Taylor Otwell', $auth->user()->name); $this->assertTrue($auth->user()->id === $_SERVER['auth.login.stub']['user']); }
/** * Format a bundle and task into a task class name. * * @param string $bundle * @param string $task * @return string */ protected static function format($bundle, $task) { $prefix = Bundle::class_prefix($bundle); return '\\' . $prefix . Str::classify($task) . '_Task'; }
/** * Determine the intermediate table name for a given model. * * By default, the intermediate table name is the plural names of the models * arranged alphabetically and concatenated with an underscore. * * @param string $model * @return string */ private function intermediate_table($model) { $models = array(Str::plural(static::model_name($model)), Str::plural(static::model_name($this))); sort($models); return Inflector::lower($models[0] . '_' . $models[1]); }
public static function dataModeling() { $list = array('Select Model'); $dataModel = glob('bundles/admin/models/data/*'); $namespace = 'Admin/Models/Data'; foreach ($dataModel as $folder) { if (is_dir($folder)) { $base = basename($folder); $namespace2 = $namespace . Str::title($base); $modelNode = glob($folder . '/*'); foreach ($modelNode as $value) { $class = basename($value, '.php'); $list[$namespace2 . '/' . $class] = $namespace2 . '/' . $class; } } else { $class = basename($folder, '.php'); $list[$namespace . '/' . $class] = $namespace . '/' . $class; } } return $list; }
/** * Store a user's token in a long-lived cookie. * * @param string $token * @return void */ protected function remember($token) { $token = Crypter::encrypt($token . '|' . Str::random(40)); $this->cookie($this->recaller(), $token, Cookie::forever); }
public static function schema($action, $module_slug) { try { // Does the schema task file exists? $schema_path = path('bundle') . $module_slug . DS . 'tasks' . DS . 'schema' . EXT; if (\Laravel\File::exists($schema_path)) { include_once $schema_path; // Does the class exists? $class = Str::title($module_slug . '_Schema_Task'); if (class_exists($class)) { $schema_class = new $class(); // The action is callable? if (is_callable(array($schema_class, $action))) { $schema_class->{$action}(); return true; } else { Log::error('Failed to run data schema for module ' . $module_slug . '. Schema action [' . $action . '] not found.'); } } else { Log::error('Failed to run data schema for module ' . $module_slug . '. Schema class [' . $class . '] not found.'); } } // we dont have task schema to run return true; } catch (\Exception $e) { Log::error($e->getMessage()); return false; } }
/** * Get the name of the table associated with the model. * * @return string */ public function table() { return static::$table ?: strtolower(Str::plural(class_basename($this))); }
/** * Generates resourceful routes. * * Assumes controller name is plural. * * @param string $name * @param array $include actions to generate routes for * @return void */ public static function resourceful($name, $include = array('index', 'new', 'create', 'show', 'edit', 'update', 'destroy')) { $plural = Str::plural($name); $singular = Str::singular($name); if (in_array('index', $include)) { Router::register("GET", "{$plural}", array("as" => $plural, "uses" => "{$plural}@index")); } if (in_array('new', $include)) { Router::register("GET", "{$plural}/new", array("as" => "new_{$plural}", "uses" => "{$plural}@new")); } if (in_array('create', $include)) { Router::register("POST", "{$plural}", array("as" => $plural, "uses" => "{$plural}@create")); } if (in_array('show', $include)) { Router::register("GET", "{$plural}/(:num)", array("as" => $singular, "uses" => "{$plural}@show")); } if (in_array('edit', $include)) { Router::register("GET", "{$plural}/(:num)/edit", array("as" => "edit_{$singular}", "uses" => "{$plural}@edit")); } if (in_array('update', $include)) { Router::register("PUT", "{$plural}/(:num)", array("as" => $singular, "uses" => "{$plural}@update")); } if (in_array('destroy', $include)) { Router::register("DELETE", "{$plural}/(:num)", array("as" => $singular, "uses" => "{$plural}@destroy")); } if (in_array('destroy', $include)) { Router::register("GET", "{$plural}/(:num)/destroy", array("as" => $singular . "_destroy", "uses" => "{$plural}@destroy")); } }
/** * Get the pattern filters for the route. * * @return array */ protected function patterns() { $filters = array(); // We will simply iterate through the registered patterns and // check the URI pattern against the URI for the route and // if they match we'll attach the filter. foreach (Filter::$patterns as $pattern => $filter) { if (Str::is($pattern, $this->uri)) { $filters[] = $filter; } } return (array) $filters; }
/** * Resolve an array of migration instances. * * @param array $migrations * @return array */ protected function resolve($migrations) { $instances = array(); foreach ($migrations as $migration) { $migration = (array) $migration; // The migration array contains the bundle name, so we will get the // path to the bundle's migrations and resolve an instance of the // migration using the name. $bundle = $migration['bundle']; $path = Bundle::path($bundle) . 'migrations/'; // Migrations are not resolved through the auto-loader, so we will // manually instantiate the migration class instances for each of // the migration names we're given. $name = $migration['name']; require_once $path . $name . EXT; // Since the migration name will begin with the numeric ID, we'll // slice off the ID so we are left with the migration class name. // The IDs are for sorting when resolving outstanding migrations. // // Migrations that exist within bundles other than the default // will be prefixed with the bundle name to avoid any possible // naming collisions with other bundle's migrations. $prefix = Bundle::class_prefix($bundle); $class = $prefix . \Laravel\Str::classify(substr($name, 18)); $migration = new $class(); // When adding to the array of instances, we will actually // add the migration instance, the bundle, and the name. // This allows the migrator to log the bundle and name // when the migration is executed. $instances[] = compact('bundle', 'name', 'migration'); } // At this point the migrations are only sorted within their // bundles so we need to resort them by name to ensure they // are in a consistent order. usort($instances, function ($a, $b) { return strcmp($a['name'], $b['name']); }); return $instances; }
/** * Get the class prefix for a given bundle. * * @param string $bundle * @return string */ public static function class_prefix($bundle) { return $bundle !== DEFAULT_BUNDLE ? Str::classify($bundle) . '_' : ''; }