robots plugin improves

This commit is contained in:
Diego Najar 2018-09-16 19:26:23 +02:00
parent b85ecdae89
commit 5bb0a46548
5 changed files with 46 additions and 123 deletions

View File

@ -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);
}
}
}

View File

@ -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 '<!-- '.Text::firstCharUp($field).': '.$value.' -->';
}
}
// 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)

View File

@ -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();

View File

@ -2,14 +2,34 @@
class pluginRobots extends Plugin {
public function init()
{
$this->dbFields = array(
'robotstxt'=>'User-agent: *'.PHP_EOL.'Allow: /'
);
}
public function form()
{
$html = '<div class="alert alert-primary" role="alert">';
$html .= $this->description();
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.DOMAIN.'/robots.txt</label>';
$html .= '<textarea name="robotstxt" id="jsrobotstxt">'.$this->getValue('robotstxt').'</textarea>';
$html .= '</div>';
return $html;
}
public function siteHead()
{
global $WHERE_AM_I;
global $page;
$html = PHP_EOL.'<!-- Robots plugin -->'.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);
}
}
}

View File

@ -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