/** * Returns the first key of an array * @param array $array Array * @return string First key */ function firstKey($array) { if (empty($array) || !is_array($array)) { return null; } return firstValue(array_keys($array)); }
/** * Gets the file types supported by KCFinder * @return array */ public function getTypes() { //Gets the folders list $folders = firstValue((new Folder(UPLOADED))->read(true, true)); //Each folder is a file type supported by KCFinder foreach ($folders as $type) { $types[$type] = ''; } //Adds the "images" type by default $types['images'] = '*img'; return $types; }
/** * Gets a static page * @param string $slug Slug * @return string|bool Static page or false * @uses MeCms\Core\Plugin::all() */ public static function get($slug) { //Sets the file (partial) name $file = implode(DS, af(explode('/', $slug))); //Sets the file patterns $patterns = [sprintf('%s-%s', $file, I18n::locale()), $file]; //Checks if the page exists in APP foreach ($patterns as $pattern) { $file = firstValue(App::path('Template')) . 'StaticPages' . DS . $pattern . '.ctp'; if (is_readable($file)) { return 'StaticPages' . DS . $pattern; } } //Checks if the page exists in all plugins, beginning with MeCms foreach (Plugin::all() as $plugin) { foreach ($patterns as $pattern) { $file = firstValue(App::path('Template', $plugin)) . 'StaticPages' . DS . $pattern . '.ctp'; if (is_readable($file)) { return sprintf('%s.%s', $plugin, 'StaticPages' . DS . $pattern); } } } return false; }
/** * Performs the latest update available * @return void * @uses _getAllUpdateMethods() */ public function latest() { $method = firstValue($this->_getAllUpdateMethods()); $this->verbose(__d('me_cms', 'Upgrading to {0}', $method['version'])); //Calls dynamically the method $this->{$method['name']}(); }
/** * Returns a list (`<ol>` or `<ul>` tag) * @param array $list Elements list * @param array $options HTML attributes of the list tag * @param array $itemOptions HTML attributes of the list items * @return string */ public function nestedList(array $list, array $options = [], array $itemOptions = []) { if (!empty($options['icon'])) { $itemOptions['icon'] = $options['icon']; } if (!empty($itemOptions['icon'])) { $options = $this->optionsValues(['class' => 'fa-ul'], $options); $itemOptions = $this->optionsValues(['icon' => 'li'], $itemOptions); $list = array_map(function ($element) use($itemOptions) { return firstValue($this->addIconToText($element, $itemOptions)); }, $list); } unset($options['icon'], $options['icon-align'], $itemOptions['icon'], $itemOptions['icon-align']); return parent::nestedList($list, $options, $itemOptions); }