public function index() { $this->indexPage(['buttons' => null, 'dataSource' => Module::findAll(), 'brightenFirst' => false, 'tableHead' => [trans('app.title') => null, trans('modules::enabled') => null, trans('app.state') => null], 'tableRow' => function ($module) { if ($module->enabled()) { $enabled = HTML::fontIcon('check'); } else { $enabled = HTML::fontIcon('close'); } /* * Display if the module is installed */ $state = Cache::get(self::CACHE_KEY . $module->title, null); if ($state === true) { $state = trans('app.valid'); } if ($state === false) { $state = trans('app.invalid'); } return [$module->title, raw($enabled), $state]; }, 'actions' => ['install', function ($module) { if ($module->installer() !== false) { return icon_link('plus-circle', trans('modules::install'), url('admin/modules/' . $module->title . '/install/0'), false, ['data-confirm' => trans('modules::installation')]); } }]]); }
public function index() { $this->indexPage(['buttons' => null, 'tableHead' => [trans('app.id') => 'id', trans('app.username') => 'username', trans('app.email') => 'email', trans('users::membership') => null, trans('users::banned') => null], 'tableRow' => function ($user) { if ($user->image) { Hover::image(asset('uploads/users/' . $user->image)); } if ($user->hasAccess('internal', PERM_READ)) { $membership = HTML::fontIcon('check'); } else { $membership = HTML::fontIcon('close'); } if ($user->isBanned()) { $banned = HTML::fontIcon('lock'); } else { $banned = HTML::fontIcon('unlock'); } return [$user->id, raw(Hover::pull(), $user->username), $user->email, raw($membership), raw($banned)]; }, 'searchFor' => 'username', 'actions' => ['edit', function ($user) { return icon_link('user', trans('users::edit_profile'), url('users/' . $user->id . '/edit')); }]]); }
/** * Generates an index page from a model and $data * * @param array $data Array with information how to build the form. See $defaults for details. * @param string $userInterface Frontend ("front") or backend ("admin")? * @return void */ public function index($data, $userInterface = 'admin') { $controller = $this->getControllerOrFail(); /* * Access checking is only available for the backend. * Frontend controllers have to perform it on their own. */ if ($userInterface == 'admin') { if (!$controller->checkAccessRead()) { return; } } /* * Set default values */ $defaults = ['buttons' => ['new'], 'search' => '', 'searchFor' => 'title', 'tableHead' => [], 'tableRow' => [], 'actions' => ['edit', 'delete', 'restore'], 'brightenFirst' => true, 'sortby' => 'id', 'order' => 'desc', 'filter' => false, 'permaFilter' => null, 'dataSource' => null, 'infoText' => '']; $data = array_merge($defaults, $data); $modelClass = $controller->getModelClass(); /* * Generate Buttons */ $buttons = ''; if (is_array($data['buttons'])) { foreach ($data['buttons'] as $button) { $type = strtolower($button); switch ($type) { case 'new': $url = route($userInterface . '.' . strtolower($controller->getControllerName()) . '.create'); $buttons .= button(trans('app.create'), $url, 'plus-circle'); break; case 'category': $url = route($userInterface . '.' . str_singular(strtolower($controller->getModuleName())) . 'cats.index'); $buttons .= button(trans('app.categories'), $url, 'folder'); break; case 'config': $url = url($userInterface . '/' . strtolower($controller->getModuleName()) . '/config'); $buttons .= button(trans('app.config'), $url, 'cog'); break; default: $buttons = $button; } } } /* * Get search string. */ if (Input::old('search')) { $data['search'] = Input::old('search'); } if (Input::get('search')) { $data['search'] = Input::get('search'); } /* * Get sort attributes. */ if (!is_array($data['dataSource'])) { if (Input::get('sortby')) { $sortby = strtolower(Input::get('sortby')); if (in_array($sortby, $data['tableHead'])) { $data['sortby'] = $sortby; } $order = strtolower(Input::get('order')); if ($order === 'desc' or $order === 'asc') { $data['order'] = $order; } } $sortSwitcher = sort_switcher($data['sortby'], $data['order'], $data['search']); } else { $sortSwitcher = null; } /* * Switch recycle bin mode: Show soft deleted models if recycle bin mode is enabled. */ if ($userInterface == 'admin' and (new $modelClass())->isSoftDeleting()) { // isSoftDeleting() is instance-tied $recycleBinMode = Input::get('binmode'); if ($recycleBinMode !== null) { Session::put('recycleBinMode', (bool) $recycleBinMode); } $recycleBin = recycle_bin_button(); } else { $recycleBin = ''; } /* * Retrieve models from DB (or array) and create paginator */ $perPage = Config::get('app.' . $userInterface . 'ItemsPerPage'); if (is_array($data['dataSource'])) { $page = (int) Paginator::resolveCurrentPage(); if ($page) { // Ensure $page always starts at 0: $page--; } else { $page = 0; } $offset = $page * $perPage; $models = array_slice($data['dataSource'], $offset, $perPage); // We have to take the models from the array $models = new Paginator($models, sizeof($data['dataSource']), $perPage); } else { $models = $modelClass::orderBy($data['sortby'], $data['order']); if ($userInterface == 'admin' and Session::get('recycleBinMode')) { $models = $models->withTrashed(); // Show trashed } if ($data['filter'] === true) { $models = $models->filter(); } elseif ($data['filter'] instanceof Closure) { $models = $data['filter']($models); } if ($data['permaFilter']) { $models = $data['permaFilter']($models); } if ($data['search']) { $pos = strpos($data['search'], ':'); if ($pos === false) { if (is_array($data['searchFor'])) { $models = $models->whereHas($data['searchFor'][0], function ($query) use($data) { $query->where($data['searchFor'][1], 'LIKE', '%' . $data['search'] . '%'); }); } elseif ($data['searchFor']) { $models = $models->where($data['searchFor'], 'LIKE', '%' . $data['search'] . '%'); } } else { $searchFor = substr($data['search'], 0, $pos); $search = substr($data['search'], $pos + 1); $models = $models->where($searchFor, 'LIKE', '%' . $search . '%'); // TODO: Check if attribute $searchFor exists? // Use fillables &/ tableHead attribute names } } $models = $models->paginate($perPage)->setPath(Request::url()); } $paginator = $models->appends(['sortby' => $data['sortby'], 'order' => $data['order'], 'search' => $data['search']])->render(); /* * Prepare the table head */ $tableHead = array(); foreach ($data['tableHead'] as $title => $sortby) { if ($sortby != null) { $tableHead[] = HTML::link(URL::current() . '?sortby=' . urlencode($sortby), $title); } else { $tableHead[] = $title; } } if (sizeof($data['actions']) > 0) { $tableHead[] = trans('app.actions'); } /* * Prepare the rows */ $tableRows = array(); foreach ($models as $model) { $row = $data['tableRow']($model); if (is_array($data['actions']) and sizeof($data['actions']) > 0) { $actionsCode = ''; foreach ($data['actions'] as $action) { if (is_string($action)) { $action = strtolower($action); switch ($action) { case 'edit': if ($model->modifiable()) { $actionsCode .= icon_link('edit', trans('app.edit'), route($userInterface . '.' . strtolower($controller->getControllerName()) . '.edit', [$model->id])); } break; case 'delete': $urlParams = '?method=DELETE&_token=' . csrf_token(); if ($model->modifiable()) { $actionsCode .= icon_link('trash', trans('app.delete'), route($userInterface . '.' . strtolower($controller->getControllerName()) . '.destroy', [$model->id]) . $urlParams, false, ['data-confirm-delete' => true]); } break; case 'restore': if ($model->isSoftDeleting() and $model->trashed()) { $actionsCode .= icon_link('undo', trans('app.restore'), route($userInterface . '.' . strtolower($controller->getControllerName()) . '.restore', [$model->id])); } break; } $actionsCode .= ' '; } if ($action instanceof Closure) { $actionsCode .= $action($model); } } $row[] = raw($actionsCode); } if ($data['actions'] instanceof Closure) { $row[] = $data['actions']($model); } $tableRows[] = $row; } /* * Generate the table */ $modelTable = HTML::table($tableHead, $tableRows, $data['brightenFirst']); /* * Generate the view */ $controller->pageView('model_index', ['buttons' => $buttons, 'infoText' => $data['infoText'], 'modelTable' => $modelTable, 'sortSwitcher' => $sortSwitcher, 'recycleBin' => $recycleBin, 'paginator' => $paginator, 'searchString' => $data['search'], 'showSearchBox' => $data['searchFor'] and !$data['dataSource'] ? true : false]); }
function mccss_admin() { $plugin_page = add_theme_page(__('My Custom CSS Panel', 'mccss'), __('Custom CSS', 'mccss'), 'manage_options', 'my_custom_css', 'mccss_options', icon_link()); add_action('admin_init', 'register_settings_mccss'); add_action('admin_head-' . $plugin_page, 'mccss_syntax'); // Disable "WP Editor" in this page if is active: http://wordpress.org/extend/plugins/wp-editor/ if (is_plugin_active("wp-editor/wpeditor.php") && $_SERVER['QUERY_STRING'] == 'page=my_custom_css') { function remove_wpeditor_header_info() { // Wp Editor Style wp_deregister_style('wpeditor'); wp_deregister_style('fancybox'); wp_deregister_style('codemirror'); wp_deregister_style('codemirror_dialog'); wp_deregister_style('codemirror_themes'); // Wp Editor Script wp_deregister_script('wpeditor'); wp_deregister_script('wp-editor-posts-jquery'); wp_deregister_script('fancybox'); wp_deregister_script('codemirror'); wp_deregister_script('codemirror_php'); wp_deregister_script('codemirror_javascript'); wp_deregister_script('codemirror_css'); wp_deregister_script('codemirror_xml'); wp_deregister_script('codemirror_clike'); wp_deregister_script('codemirror_dialog'); wp_deregister_script('codemirror_search'); wp_deregister_script('codemirror_searchcursor'); wp_deregister_script('codemirror_mustache'); } add_action('admin_init', 'remove_wpeditor_header_info', 20); } }