robots plugin improves
This commit is contained in:
parent
b85ecdae89
commit
5bb0a46548
|
@ -9,9 +9,10 @@ function updateBludit() {
|
||||||
if( ($site->currentBuild() < BLUDIT_BUILD) || isset($_GET['update']) ) {
|
if( ($site->currentBuild() < BLUDIT_BUILD) || isset($_GET['update']) ) {
|
||||||
Log::set('UPDATE SYSTEM - Starting.');
|
Log::set('UPDATE SYSTEM - Starting.');
|
||||||
|
|
||||||
|
// Updates only for version less than Bludit v3.0 rc-3
|
||||||
|
if ($site->currentBuild()<'20180910') {
|
||||||
@mkdir(PATH_WORKSPACES, DIR_PERMISSIONS, true);
|
@mkdir(PATH_WORKSPACES, DIR_PERMISSIONS, true);
|
||||||
|
$plugins = array('simple-stats', 'pluginRSS', 'pluginSitemap', 'pluginTimeMachineX', 'pluginBackup');
|
||||||
$plugins = array('pluginRSS', 'pluginSitemap', 'pluginTimeMachineX', 'pluginBackup');
|
|
||||||
foreach ($plugins as $plugin) {
|
foreach ($plugins as $plugin) {
|
||||||
if (pluginActivated($plugin)) {
|
if (pluginActivated($plugin)) {
|
||||||
Log::set('UPDATE SYSTEM - Re-enable plugin: '.$plugin);
|
Log::set('UPDATE SYSTEM - Re-enable plugin: '.$plugin);
|
||||||
|
@ -19,6 +20,7 @@ function updateBludit() {
|
||||||
activatePlugin($plugin);
|
activatePlugin($plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the current build number
|
// Set the current build number
|
||||||
$site->set(array('currentBuild'=>BLUDIT_BUILD));
|
$site->set(array('currentBuild'=>BLUDIT_BUILD));
|
||||||
|
|
|
@ -687,116 +687,6 @@ class Pages extends dbJSON {
|
||||||
return $newKey;
|
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')
|
// Returns an Array, array('tagSlug'=>'tagName')
|
||||||
// (string) $tags, tag list separated by comma.
|
// (string) $tags, tag list separated by comma.
|
||||||
public function generateTags($tags)
|
public function generateTags($tags)
|
||||||
|
|
|
@ -10,7 +10,7 @@ class pluginRemoteContent extends Plugin {
|
||||||
// Key and value for the database of the plugin
|
// Key and value for the database of the plugin
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'webhook'=>$randomWebhook,
|
'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');
|
$webhook = $this->getValue('webhook');
|
||||||
if ($this->webhook($webhook)) {
|
if ($this->webhook($webhook)) {
|
||||||
// Download files
|
// Download files
|
||||||
//$this->downloadFiles();
|
$this->downloadFiles();
|
||||||
|
|
||||||
// Delete the current content
|
// Delete the current content
|
||||||
$this->deleteContent();
|
$this->deleteContent();
|
||||||
|
|
|
@ -2,14 +2,34 @@
|
||||||
|
|
||||||
class pluginRobots extends Plugin {
|
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()
|
public function siteHead()
|
||||||
{
|
{
|
||||||
global $WHERE_AM_I;
|
global $WHERE_AM_I;
|
||||||
global $page;
|
|
||||||
|
|
||||||
$html = PHP_EOL.'<!-- Robots plugin -->'.PHP_EOL;
|
$html = PHP_EOL.'<!-- Robots plugin -->'.PHP_EOL;
|
||||||
|
|
||||||
if ($WHERE_AM_I=='page') {
|
if ($WHERE_AM_I=='page') {
|
||||||
|
global $page;
|
||||||
$robots = array();
|
$robots = array();
|
||||||
|
|
||||||
if ($page->noindex()) {
|
if ($page->noindex()) {
|
||||||
|
@ -33,4 +53,14 @@ class pluginRobots extends Plugin {
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function beforeAll()
|
||||||
|
{
|
||||||
|
$webhook = 'robots.txt';
|
||||||
|
if ($this->webhook($webhook)) {
|
||||||
|
header('Content-type: text/plain');
|
||||||
|
echo $this->getValue('robotstxt');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -521,7 +521,8 @@ function install($adminPassword, $timezone)
|
||||||
PATH_PLUGINS_DATABASES.'robots'.DS.'db.php',
|
PATH_PLUGINS_DATABASES.'robots'.DS.'db.php',
|
||||||
$dataHead.json_encode(
|
$dataHead.json_encode(
|
||||||
array(
|
array(
|
||||||
'position'=>1
|
'position'=>1,
|
||||||
|
'robotstxt'=>'User-agent: *'.PHP_EOL.'Allow: /'
|
||||||
),
|
),
|
||||||
JSON_PRETTY_PRINT),
|
JSON_PRETTY_PRINT),
|
||||||
LOCK_EX
|
LOCK_EX
|
||||||
|
|
Loading…
Reference in New Issue