public function getModelatorOptions($keyValue = null) { $models = $out = []; $i = 0; $authors = File::directories(plugins_path()); foreach ($authors as $author) { foreach (File::directories($author) as $plugin) { foreach (File::files($plugin . DIRECTORY_SEPARATOR . 'models') as $modelFile) { # All links in the LinkCheck plugin table are broken. Skip. $linkCheckPluginPath = plugins_path() . DIRECTORY_SEPARATOR . 'bombozama' . DIRECTORY_SEPARATOR . 'linkcheck'; if ($plugin == $linkCheckPluginPath) { continue; } $models[] = Helper::getFullClassNameFromFile((string) $modelFile); } } } foreach ($models as $model) { $object = new $model(); foreach (Schema::getColumnListing($object->table) as $column) { $type = DB::connection()->getDoctrineColumn($object->table, $column)->getType()->getName(); if (in_array($type, ['string', 'text'])) { $out[$model . '::' . $column] = $model . '::' . $column; } } } return $out; }
/** * Checks for broken links in selected database fields and/or all CMS files * @return void */ public static function processLinks() { # Let's start by truncating the BrokenLinks table BrokenLink::truncate(); $brokenLinks = []; $settings = Settings::instance(); foreach ($settings->modelators as $el) { list($modelName, $field) = explode('::', $el['modelator']); $models = $modelName::whereNotNull($field)->get(); foreach ($models as $model) { $urls = Helper::scanForUrls($model->{$field}); $modelParts = explode('\\', $modelName); foreach ($urls as $url) { $status = BrokenLink::isBrokenLink($url); if ($status) { $brokenLinks[] = ['status' => $status, 'plugin' => $modelParts[1] . '.' . $modelParts[2], 'model' => array_pop($modelParts), 'model_id' => $model->id, 'field' => $field, 'url' => $model->{$field}]; } } } } /** * Go process the current theme */ $theme = Theme::getActiveTheme(); $theme->getPath(); /** * Should we process theme pages? */ if ($settings['checkCMS'] == '1') { foreach (File::directories($theme->getPath()) as $themeSubDir) { # Skip the assets folder if (basename($themeSubDir) == 'assets') { continue; } foreach (File::allFiles($themeSubDir) as $filePath) { $urls = Helper::scanForUrls(file_get_contents($filePath)); foreach ($urls as $url) { $status = BrokenLink::isBrokenLink($url); if ($status) { $brokenLinks[] = ['status' => $status, 'plugin' => 'CMS', 'model' => str_replace($theme->getPath() . DIRECTORY_SEPARATOR, '', $filePath), 'url' => $url]; } } } } } /** * Lets seed the BrokenLink table with any and all found links. */ foreach ($brokenLinks as $brokenLink) { BrokenLink::create($brokenLink); } return count($brokenLinks); }