| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- <?php
- use Illuminate\Contracts\Support\Htmlable;
- use Illuminate\Contracts\Support\Renderable;
- use Illuminate\Support\MessageBag;
- if (!function_exists('admin_section')) {
- /**
- * Get the string contents of a section.
- *
- * @param $section
- * @param null $default
- * @param array $options
- *
- * @return mixed
- */
- function admin_section($section, $default = null, array $options = [])
- {
- return app('sectionManager')->yieldContent($section, $default, $options);
- }
- }
- if (!function_exists('admin_has_section')) {
- /**
- * Check if section exists.
- *
- * @param $section
- *
- * @return mixed
- */
- function admin_has_section($section)
- {
- return app('sectionManager')->hasSection($section);
- }
- }
- if (!function_exists('admin_inject_section')) {
- /**
- * Injecting content into a section.
- *
- * @param $section
- * @param null $content
- * @param bool $append
- * @param int $priority
- */
- function admin_inject_section($section, $content = null, bool $append = true, int $priority = 10)
- {
- app('sectionManager')->inject($section, $content, $append, $priority);
- }
- }
- if (!function_exists('admin_inject_section_if')) {
- /**
- * Injecting content into a section.
- *
- * @param $condition
- * @param $section
- * @param null $content
- * @param bool $append
- * @param int $priority
- */
- function admin_inject_section_if($condition, $section, $content = null, bool $append = false, int $priority = 10)
- {
- if ($condition) {
- app('sectionManager')->inject($section, $content, $append, $priority);
- }
- }
- }
- if (!function_exists('admin_has_default_section')) {
- /**
- * Check if default section exists.
- *
- * @param $section
- *
- * @return mixed
- */
- function admin_has_default_section($section)
- {
- return app('sectionManager')->hasDefaultSection($section);
- }
- }
- if (!function_exists('admin_inject_default_section')) {
- /**
- * Injecting content into a section.
- *
- * @param $section
- * @param string|Renderable|Htmlable|callable $content
- */
- function admin_inject_default_section($section, $content)
- {
- app('sectionManager')->injectDefault($section, $content);
- }
- }
- if (!function_exists('admin_trans_field')) {
- /**
- * Translate the field name.
- *
- * @param $field
- * @param null $locale
- *
- * @return array|\Illuminate\Contracts\Translation\Translator|null|string
- */
- function admin_trans_field($field, $locale = null)
- {
- $slug = admin_controller_slug();
- return admin_trans("{$slug}.fields.{$field}", [], $locale);
- }
- }
- if (!function_exists('admin_trans_label')) {
- /**
- * Translate the label.
- *
- * @param $label
- * @param array $replace
- * @param null $locale
- *
- * @return array|\Illuminate\Contracts\Translation\Translator|null|string
- */
- function admin_trans_label($label = null, $replace = [], $locale = null)
- {
- $label = $label ?: admin_controller_name();
- $slug = admin_controller_slug();
- return admin_trans("{$slug}.labels.{$label}", $replace, $locale);
- }
- }
- if (!function_exists('admin_trans_option')) {
- /**
- * Translate the field name.
- *
- * @param $field
- * @param array $replace
- * @param null $locale
- *
- * @return array|\Illuminate\Contracts\Translation\Translator|null|string
- */
- function admin_trans_option($optionValue, $field, $replace = [], $locale = null)
- {
- $slug = admin_controller_slug();
- return admin_trans("{$slug}.options.{$field}.{$optionValue}", $replace, $locale);
- }
- }
- if (!function_exists('admin_trans')) {
- /**
- * Translate the given message.
- *
- * @param string $key
- * @param array $replace
- * @param string $locale
- *
- * @return \Illuminate\Contracts\Translation\Translator|string|array|null
- */
- function admin_trans($key, $replace = [], $locale = null)
- {
- static $method = null;
- if ($method === null) {
- $method = version_compare(app()->version(), '6.0', '>=') ? 'get' : 'trans';
- }
- $translator = app('translator');
- if ($translator->has($key)) {
- return $translator->$method($key, $replace, $locale);
- }
- if (
- strpos($key, 'global.') !== 0
- && count($arr = explode('.', $key)) > 1
- ) {
- unset($arr[0]);
- array_unshift($arr, 'global');
- $key = implode('.', $arr);
- if (!$translator->has($key)) {
- return end($arr);
- }
- return $translator->$method($key, $replace, $locale);
- }
- return last(explode('.', $key));
- }
- }
- if (!function_exists('admin_controller_slug')) {
- /**
- * @return string
- */
- function admin_controller_slug()
- {
- static $slug = [];
- $controller = admin_controller_name();
- return $slug[$controller] ?? ($slug[$controller] = \Dcat\Admin\Support\Helper::slug($controller));
- }
- }
- if (!function_exists('admin_controller_name')) {
- /**
- * Get the class "basename" of the current controller.
- *
- * @return string
- */
- function admin_controller_name()
- {
- static $name = [];
- $router = app('router');
- if (!$router->current()) {
- return 'undefined';
- }
- $actionName = $router->current()->getActionName();
- if (!isset($name[$actionName])) {
- $controller = class_basename(explode('@', $actionName)[0]);
- $name[$actionName] = str_replace('Controller', '', $controller);
- }
- return $name[$actionName];
- }
- }
- if (!function_exists('admin_path')) {
- /**
- * Get admin path.
- *
- * @param string $path
- *
- * @return string
- */
- function admin_path($path = '')
- {
- return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
- }
- }
- if (!function_exists('admin_url')) {
- /**
- * Get admin url.
- *
- * @param string $path
- * @param mixed $parameters
- * @param bool $secure
- *
- * @return string
- */
- function admin_url($path = '', $parameters = [], $secure = null)
- {
- if (url()->isValidUrl($path)) {
- return $path;
- }
- $secure = $secure ?: (config('admin.https') || config('admin.secure'));
- return url(admin_base_path($path), $parameters, $secure);
- }
- }
- if (!function_exists('admin_base_path')) {
- /**
- * Get admin url.
- *
- * @param string $path
- *
- * @return string
- */
- function admin_base_path($path = '')
- {
- $prefix = '/'.trim(config('admin.route.prefix'), '/');
- $prefix = ($prefix == '/') ? '' : $prefix;
- $path = trim($path, '/');
- if (is_null($path) || strlen($path) == 0) {
- return $prefix ?: '/';
- }
- return $prefix.'/'.$path;
- }
- }
- if (!function_exists('admin_alert')) {
- /**
- * Flash a layer message bag to session.
- *
- * @param string $message
- * @param string $type
- * @param string $offset
- */
- function admin_alert($message = '', $type = 'success', $offset = '')
- {
- $toastr = new MessageBag(get_defined_vars());
- session()->flash('layer-msg', $toastr);
- }
- }
- if (!function_exists('admin_success')) {
- /**
- * Flash a success message bag to session.
- *
- * @param string $title
- * @param string $message
- */
- function admin_success($title, $message = '')
- {
- admin_info($title, $message, 'success');
- }
- }
- if (!function_exists('admin_error')) {
- /**
- * Flash a error message bag to session.
- *
- * @param string $title
- * @param string $message
- */
- function admin_error($title, $message = '')
- {
- admin_info($title, $message, 'error');
- }
- }
- if (!function_exists('admin_warning')) {
- /**
- * Flash a warning message bag to session.
- *
- * @param string $title
- * @param string $message
- */
- function admin_warning($title, $message = '')
- {
- admin_info($title, $message, 'warning');
- }
- }
- if (!function_exists('admin_info')) {
- /**
- * Flash a message bag to session.
- *
- * @param string $title
- * @param string $message
- * @param string $type
- */
- function admin_info($title, $message = '', $type = 'info')
- {
- $message = new MessageBag(get_defined_vars());
- session()->flash($type, $message);
- }
- }
- if (!function_exists('admin_asset')) {
- /**
- * @param $path
- *
- * @return string
- */
- function admin_asset($path)
- {
- if (strpos($path, '//') === false) {
- $path = config('admin.assets_server').'/'.trim($path, '/');
- }
- return (config('admin.https') || config('admin.secure')) ? secure_asset($path) : asset($path);
- }
- }
- if (!function_exists('array_delete')) {
- /**
- * Delete from array by value.
- *
- * @param array $array
- * @param mixed $value
- */
- function array_delete(&$array, $value)
- {
- foreach ($array as $index => $item) {
- if ($value == $item) {
- unset($array[$index]);
- }
- }
- }
- }
|