From 5bb0a46548d334d8fde3d006ba1d2ef2cf12690f Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sun, 16 Sep 2018 19:26:23 +0200 Subject: [PATCH] robots plugin improves --- bl-kernel/admin/controllers/dashboard.php | 18 ++-- bl-kernel/pages.class.php | 110 ---------------------- bl-plugins/remote-content/plugin.php | 4 +- bl-plugins/robots/plugin.php | 34 ++++++- install.php | 3 +- 5 files changed, 46 insertions(+), 123 deletions(-) diff --git a/bl-kernel/admin/controllers/dashboard.php b/bl-kernel/admin/controllers/dashboard.php index 1ed04523..b924561d 100644 --- a/bl-kernel/admin/controllers/dashboard.php +++ b/bl-kernel/admin/controllers/dashboard.php @@ -9,14 +9,16 @@ function updateBludit() { if( ($site->currentBuild() < BLUDIT_BUILD) || isset($_GET['update']) ) { Log::set('UPDATE SYSTEM - Starting.'); - @mkdir(PATH_WORKSPACES, DIR_PERMISSIONS, true); - - $plugins = array('pluginRSS', 'pluginSitemap', 'pluginTimeMachineX', 'pluginBackup'); - foreach ($plugins as $plugin) { - if (pluginActivated($plugin)) { - Log::set('UPDATE SYSTEM - Re-enable plugin: '.$plugin); - deactivatePlugin($plugin); - activatePlugin($plugin); + // Updates only for version less than Bludit v3.0 rc-3 + if ($site->currentBuild()<'20180910') { + @mkdir(PATH_WORKSPACES, DIR_PERMISSIONS, true); + $plugins = array('simple-stats', 'pluginRSS', 'pluginSitemap', 'pluginTimeMachineX', 'pluginBackup'); + foreach ($plugins as $plugin) { + if (pluginActivated($plugin)) { + Log::set('UPDATE SYSTEM - Re-enable plugin: '.$plugin); + deactivatePlugin($plugin); + activatePlugin($plugin); + } } } diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php index 17b9d1f5..7c0f0af3 100644 --- a/bl-kernel/pages.class.php +++ b/bl-kernel/pages.class.php @@ -687,116 +687,6 @@ class Pages extends dbJSON { return $newKey; } - public function rescanClimode() - { - Log::set('CLI MODE'.LOG_SEP.'Starting re-scan on pages directory.'); - $pageList = array(); - - // Search for pages - $directories = Filesystem::listDirectories(PATH_PAGES, $regex='*', $sortByDate=false); - foreach($directories as $directory) { - if( Sanitize::pathFile($directory.DS.FILENAME) ) { - $pageKey = basename($directory); - $pageList[$pageKey] = true; - - // Search for children pages - $subDirectories = Filesystem::listDirectories(PATH_PAGES.$pageKey.DS, $regex='*', $sortByDate=false); - foreach($subDirectories as $subDirectory) { - if( Sanitize::pathFile($subDirectory.DS.FILENAME) ) { - $subPageKey = basename($subDirectory); - $subPageKey = $pageKey.'/'.$subPageKey; - $pageList[$subPageKey] = true; - } - } - } - } - - Log::set('CLI MODE'.LOG_SEP.'Updating pages...'); - $keys = array_keys($pageList); - foreach($keys as $pageKey) { - // Checksum - $checksum = md5_file(PATH_PAGES.$pageKey.DS.FILENAME); - - // New page - if( !isset($this->db[$pageKey]) ) { - $this->verifyFieldsClimode($pageKey, true); - } - // Update page - elseif($this->db[$pageKey]['md5file']!=$checksum) { - $this->verifyFieldsClimode($pageKey, false); - } - } - - Log::set('CLI MODE'.LOG_SEP.'Removing pages...'); - foreach( array_diff_key($this->db, $pageList) as $pageKey=>$data ) { - Log::set('CLI MODE'.LOG_SEP.'Removing page from database, key: '.$pageKey); - unset( $this->db[$pageKey] ); - } - $this->save(); - } - - private function verifyFieldsClimode($key, $insert=true) - { - $page = new Page($key); - $db = $page->getDB(); - - // Content from file - $db['content'] = $db['contentRaw']; - - // Parent - $db['parent'] = ''; - $db['slug'] = $key; - $explodeKey = explode('/', $key); - if(isset($explodeKey[1])) { - $db['parent'] = $explodeKey[0]; - $db['slug'] = $explodeKey[1]; - } - - // Date - if( !isset($db['date']) ) { - $db['date'] = Date::current(DB_DATE_FORMAT); - } - - // Status - if( !isset($db['type']) ) { - $db['type'] = CLI_STATUS; - } - - // Owner username - if( !isset($db['username']) ) { - $db['username'] = CLI_USERNAME; - } - - // New page or update page - if($insert) { - Log::set('CLI MODE'.LOG_SEP.'New page found, key:'.$key); - return $this->add($db, $climode=true); - } else { - Log::set('CLI MODE'.LOG_SEP.'Different checksum, updating page, key:'.$key); - return $this->edit($db, $climode=true); - } - } - - private function stylingFieldsForFile($field, $value) - { - // Support for Markdown files, good approach for Github - if (FILENAME==='index.md') { - if ($field==='title') { - return '#Title: '.$value; - } elseif ($field==='content') { - return '---'.PHP_EOL.$value; - } else { - return ''; - } - } - - // Legacy style of Bludit with index.txt - if ($field==='content') { - return 'Content:'.PHP_EOL.$value; - } - return Text::firstCharUp($field).': '.$value; - } - // Returns an Array, array('tagSlug'=>'tagName') // (string) $tags, tag list separated by comma. public function generateTags($tags) diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php index f5f5cabd..5f07d647 100644 --- a/bl-plugins/remote-content/plugin.php +++ b/bl-plugins/remote-content/plugin.php @@ -10,7 +10,7 @@ class pluginRemoteContent extends Plugin { // Key and value for the database of the plugin $this->dbFields = array( 'webhook'=>$randomWebhook, - 'source'=>'https://github.com/bludit/remote-content-example/archive/master.zip' + 'source'=>'' ); } @@ -48,7 +48,7 @@ class pluginRemoteContent extends Plugin { $webhook = $this->getValue('webhook'); if ($this->webhook($webhook)) { // Download files - //$this->downloadFiles(); + $this->downloadFiles(); // Delete the current content $this->deleteContent(); diff --git a/bl-plugins/robots/plugin.php b/bl-plugins/robots/plugin.php index 3dec28ea..180c5d96 100644 --- a/bl-plugins/robots/plugin.php +++ b/bl-plugins/robots/plugin.php @@ -2,14 +2,34 @@ class pluginRobots extends Plugin { + public function init() + { + $this->dbFields = array( + 'robotstxt'=>'User-agent: *'.PHP_EOL.'Allow: /' + ); + } + + public function form() + { + $html = ''; + + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + + return $html; + } + public function siteHead() { global $WHERE_AM_I; - global $page; $html = PHP_EOL.''.PHP_EOL; - if ($WHERE_AM_I=='page') { + global $page; $robots = array(); if ($page->noindex()) { @@ -33,4 +53,14 @@ class pluginRobots extends Plugin { return $html; } + public function beforeAll() + { + $webhook = 'robots.txt'; + if ($this->webhook($webhook)) { + header('Content-type: text/plain'); + echo $this->getValue('robotstxt'); + exit(0); + } + } + } \ No newline at end of file diff --git a/install.php b/install.php index 0e248198..06d4f494 100644 --- a/install.php +++ b/install.php @@ -521,7 +521,8 @@ function install($adminPassword, $timezone) PATH_PLUGINS_DATABASES.'robots'.DS.'db.php', $dataHead.json_encode( array( - 'position'=>1 + 'position'=>1, + 'robotstxt'=>'User-agent: *'.PHP_EOL.'Allow: /' ), JSON_PRETTY_PRINT), LOCK_EX