diff --git a/admin.php b/admin.php index 3c0fd923..b19d3cc4 100644 --- a/admin.php +++ b/admin.php @@ -119,12 +119,11 @@ class AdminPlugin extends Plugin * - 'password1' for password format * - 'password2' for equality to password1 * - * @param object $form The form * @param string $type The field type * @param string $value The field value * @param string $extra Any extra value required * - * @return mixed + * @return bool */ protected function validate($type, $value, $extra = '') { @@ -134,22 +133,21 @@ class AdminPlugin extends Plugin return false; } return true; - break; case 'password1': if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) { return false; } return true; - break; case 'password2': if (strcmp($value, $extra)) { return false; } return true; - break; } + + return false; } /** @@ -352,6 +350,8 @@ class AdminPlugin extends Plugin return $page; } } + + return null; }; if (empty($this->grav['page'])) { diff --git a/classes/admin.php b/classes/admin.php index 2ad43c7e..b336a37d 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -15,7 +15,6 @@ use Grav\Common\User\User; use Grav\Common\Utils; use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\File\JsonFile; -use RocketTheme\Toolbox\File\LogFile; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; use RocketTheme\Toolbox\Session\Message; use RocketTheme\Toolbox\Session\Session; @@ -71,12 +70,7 @@ class Admin public $user; /** - * @var Lang - */ - protected $lang; - - /** - * @var Grav\Common\GPM\GPM + * @var GPM */ protected $gpm; @@ -458,7 +452,7 @@ class Admin $gpm = $this->gpm(); if (!$gpm) { - return; + return false; } return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function ( @@ -479,7 +473,7 @@ class Admin $gpm = $this->gpm(); if (!$gpm) { - return; + return false; } return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use @@ -496,7 +490,7 @@ class Admin * * @param integer $count number of pages to pull back * - * @return array + * @return array|null */ public function latestPages($count = 10) { @@ -506,7 +500,7 @@ class Admin $latest = array(); if(is_null($pages->routes())){ - return; + return null; } foreach ($pages->routes() as $url => $path) { @@ -824,13 +818,21 @@ class Admin /** * Translate a string to the user-defined language * - * @param $string the string to translate + * @param string $string the string to translate + * @return string */ public function translate($string) { return $this->_translate($string, [$this->grav['user']->authenticated ? $this->grav['user']->language : 'en']); } + /** + * @param array|mixed $args + * @param array|null $languages + * @param bool $array_support + * @param bool $html_out + * @return string + */ public function _translate($args, Array $languages = null, $array_support = false, $html_out = false) { if (is_array($args)) { @@ -878,6 +880,10 @@ class Admin return $lookup; } + /** + * @param string $php_format + * @return string + */ function dateformat2Kendo($php_format) { $SYMBOLS_MATCHING = array( diff --git a/classes/controller.php b/classes/controller.php index f0dfdc03..6493288b 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -8,7 +8,7 @@ use Grav\Common\GPM\Installer; use Grav\Common\Grav; use Grav\Common\Uri; use Grav\Common\Data; -use Grav\Common\Page; +use Grav\Common\Page\Page; use Grav\Common\Page\Pages; use Grav\Common\Page\Collection; use Grav\Common\Plugin; @@ -16,8 +16,6 @@ use Grav\Common\Theme; use Grav\Common\User\User; use Grav\Common\Utils; use Grav\Common\Backup\ZipBackup; -use Grav\Common\Markdown\Parsedown; -use Grav\Common\Markdown\ParsedownExtra; use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\File\JsonFile; use Symfony\Component\Yaml\Yaml; @@ -380,7 +378,7 @@ class AdminController protected function taskClearCache() { if (!$this->authorizeTask('clear cache', ['admin.cache', 'admin.super'])) { - return; + return false; } // get optional cleartype param @@ -411,7 +409,7 @@ class AdminController { $param_sep = $this->grav['config']->get('system.param_sep', ':'); if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) { - return; + return false; } $download = $this->grav['uri']->param('download'); @@ -562,7 +560,7 @@ class AdminController protected function taskListmedia() { if (!$this->authorizeTask('list media', ['admin.pages', 'admin.super'])) { - return; + return false; } $page = $this->admin->page(true); @@ -583,11 +581,13 @@ class AdminController /** * Handles adding a media file to a page + * + * @return bool True if the action was performed. */ protected function taskAddmedia() { if (!$this->authorizeTask('add media', ['admin.pages', 'admin.super'])) { - return; + return false; } $page = $this->admin->page(true); @@ -597,7 +597,7 @@ class AdminController if (!isset($_FILES['file']['error']) || is_array($_FILES['file']['error'])) { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_PARAMETERS')]; - return; + return false; } // Check $_FILES['file']['error'] value. @@ -606,21 +606,21 @@ class AdminController break; case UPLOAD_ERR_NO_FILE: $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT')]; - return; + return false; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT')]; - return; + return false; default: $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')]; - return; + return false; } $grav_limit = $config->get('system.media.upload_limit', 0); // You should also check filesize here. if ($grav_limit > 0 && $_FILES['file']['size'] > $grav_limit) { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')]; - return; + return false; } @@ -631,19 +631,19 @@ class AdminController // If not a supported type, return if (!$config->get("media.{$fileExt}")) { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNSUPPORTED_FILE_TYPE') . ': '.$fileExt]; - return; + return false; } // Upload it if (!move_uploaded_file($_FILES['file']['tmp_name'], sprintf('%s/%s', $page->path(), $_FILES['file']['name']))) { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE')]; - return; + return false; } $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_UPLOADED_SUCCESSFULLY')]; - return; + return true; } /** @@ -654,7 +654,7 @@ class AdminController protected function taskDelmedia() { if (!$this->authorizeTask('delete media', ['admin.pages', 'admin.super'])) { - return; + return false; } $page = $this->admin->page(true); @@ -709,6 +709,8 @@ class AdminController /** * Process the page Markdown + * + * @return bool True if the action was performed. */ protected function taskProcessMarkdown() { @@ -734,11 +736,13 @@ class AdminController $html = $page->content(); $this->admin->json_response = ['status' => 'success', 'message' => $html]; - return true; } catch (\Exception $e) { $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; + return false; } + + return true; } /** @@ -749,7 +753,7 @@ class AdminController public function taskEnable() { if (!$this->authorizeTask('enable plugin', ['admin.plugins', 'admin.super'])) { - return; + return false; } if ($this->view != 'plugins') { @@ -775,7 +779,7 @@ class AdminController public function taskDisable() { if (!$this->authorizeTask('disable plugin', ['admin.plugins', 'admin.super'])) { - return; + return false; } if ($this->view != 'plugins') { @@ -801,7 +805,7 @@ class AdminController public function taskActivate() { if (!$this->authorizeTask('activate theme', ['admin.themes', 'admin.super'])) { - return; + return false; } if ($this->view != 'themes') { @@ -840,7 +844,7 @@ class AdminController { $type = $this->view === 'plugins' ? 'plugins' : 'themes'; if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) { - return; + return false; } require_once __DIR__ . '/gpm.php'; @@ -915,7 +919,7 @@ class AdminController foreach ($permissions as $type => $p) { if (!$this->authorizeTask('update ' . $type , $p)) { - return; + return false; } } @@ -951,7 +955,7 @@ class AdminController { $type = $this->view === 'plugins' ? 'plugins' : 'themes'; if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) { - return; + return false; } require_once __DIR__ . '/gpm.php'; @@ -971,6 +975,11 @@ class AdminController return true; } + /** + * @param string $key + * @param string $file + * @return bool + */ private function cleanFilesData($key, $file) { $config = $this->grav['config']; @@ -1031,6 +1040,11 @@ class AdminController return $cleanFiles[$key]; } + /** + * @param string $needle + * @param array|string $haystack + * @return bool + */ private function match_in_array($needle, $haystack) { foreach ((array)$haystack as $item) { @@ -1042,6 +1056,10 @@ class AdminController return false; } + /** + * @param mixed $obj + * @return mixed + */ private function processFiles($obj) { foreach ((array)$_FILES as $key => $file) { @@ -1062,17 +1080,17 @@ class AdminController public function taskSave() { if (!$this->authorizeTask('save', $this->dataPermissions())) { - return; + return false; } - $reorder = false; $data = $this->post; + $config = $this->grav['config']; + // Special handler for pages data. if ($this->view == 'pages') { - /** @var Page\Pages $pages */ + /** @var Pages $pages */ $pages = $this->grav['pages']; - $config = $this->grav['config']; // Find new parent page in order to build the path. $route = !isset($data['route']) ? dirname($this->admin->route) : $data['route']; @@ -1150,7 +1168,7 @@ class AdminController } // Always redirect if a page route was changed, to refresh it - if ($obj instanceof Page\Page) { + if ($obj instanceof Page) { if (method_exists($obj, 'unsetRouteSlug')) { $obj->unsetRouteSlug(); } @@ -1234,7 +1252,7 @@ class AdminController protected function taskCopy() { if (!$this->authorizeTask('copy page', ['admin.pages', 'admin.super'])) { - return; + return false; } // Only applies to pages. @@ -1243,7 +1261,7 @@ class AdminController } try { - /** @var Page\Pages $pages */ + /** @var Pages $pages */ $pages = $this->grav['pages']; $data = $this->post; @@ -1292,7 +1310,7 @@ class AdminController protected function taskReorder() { if (!$this->authorizeTask('reorder pages', ['admin.pages', 'admin.super'])) { - return; + return false; } // Only applies to pages. @@ -1313,7 +1331,7 @@ class AdminController protected function taskDelete() { if (!$this->authorizeTask('delete page', ['admin.pages', 'admin.super'])) { - return; + return false; } // Only applies to pages. @@ -1390,7 +1408,7 @@ class AdminController protected function taskSaveas() { if (!$this->authorizeTask('save', $this->dataPermissions())) { - return; + return false; } // $reorder = false; @@ -1428,7 +1446,7 @@ class AdminController $aFile = File::instance($path); $aFile->save(); - $aPage = new Page\Page(); + $aPage = new Page(); $aPage->init(new \SplFileInfo($path), $language .'.md'); $aPage->header($obj->header()); $aPage->rawMarkdown($obj->rawMarkdown()); diff --git a/classes/gpm.php b/classes/gpm.php index 38b72757..17d86742 100644 --- a/classes/gpm.php +++ b/classes/gpm.php @@ -36,7 +36,12 @@ class Gpm 'theme' => false ]; - public static function install($packages, $options) + /** + * @param Package[]|string[]|string $packages + * @param array $options + * @return bool + */ + public static function install($packages, array $options) { $options = array_merge(self::$options, $options); @@ -93,13 +98,24 @@ class Gpm return true; } - public static function update($packages, $options) + /** + * @param Package[]|string[]|string $packages + * @param array $options + * @return bool + */ + public static function update($packages, array $options) { $options['overwrite'] = true; + return static::install($packages, $options); } - public static function uninstall($packages, $options) + /** + * @param Package[]|string[]|string $packages + * @param array $options + * @return bool + */ + public static function uninstall($packages, array $options) { $options = array_merge(self::$options, $options); @@ -144,7 +160,11 @@ class Gpm return true; } - private static function download($package) + /** + * @param Package $package + * @return string + */ + private static function download(Package $package) { $contents = Response::get($package->zipball_url, []); @@ -159,7 +179,12 @@ class Gpm return $cache_dir . DS . $filename . '.zip'; } - private static function _downloadSelfupgrade($package, $tmp) + /** + * @param array $package + * @param string $tmp + * @return string + */ + private static function _downloadSelfupgrade(array $package, $tmp) { $output = Response::get($package['download'], []); Folder::mkdir($tmp); @@ -167,6 +192,9 @@ class Gpm return $tmp . DS . $package['name']; } + /** + * @return bool + */ public static function selfupgrade() { $upgrader = new Upgrader(); diff --git a/classes/popularity.php b/classes/popularity.php index 71555a0f..e2a583e5 100644 --- a/classes/popularity.php +++ b/classes/popularity.php @@ -110,6 +110,9 @@ class Popularity file_put_contents($this->daily_file, json_encode($this->daily_data)); } + /** + * @return array + */ public function getDailyChartData() { if (!$this->daily_data) { @@ -130,6 +133,9 @@ class Popularity return array('labels' => json_encode($labels), 'data' => json_encode($data)); } + /** + * @return int + */ public function getDailyTotal() { if (!$this->daily_data) { @@ -143,6 +149,9 @@ class Popularity } } + /** + * @return int + */ public function getWeeklyTotal() { if (!$this->daily_data) { @@ -160,6 +169,9 @@ class Popularity return $total; } + /** + * @return int + */ public function getMonthlyTotal() { if (!$this->monthly_data) { @@ -197,6 +209,9 @@ class Popularity file_put_contents($this->monthly_file, json_encode($this->monthly_data)); } + /** + * @return array + */ protected function getMonthyChartData() { if (!$this->monthly_data) { @@ -213,6 +228,9 @@ class Popularity return array('labels' => $labels, 'data' => $data); } + /** + * @param string $url + */ protected function updateTotals($url) { if (!$this->totals_data) { @@ -229,6 +247,9 @@ class Popularity file_put_contents($this->totals_file, json_encode($this->totals_data)); } + /** + * @param string $ip + */ protected function updateVisitors($ip) { if (!$this->visitors_data) { @@ -246,6 +267,10 @@ class Popularity file_put_contents($this->visitors_file, json_encode($this->visitors_data)); } + /** + * @param string $path + * @return array + */ protected function getData($path) { if (file_exists($path)) {