Skip to content

Commit

Permalink
Merge pull request #82 from mitsukarenai/v0.3.4
Browse files Browse the repository at this point in the history
v0.3.4
  • Loading branch information
mitsukarenai authored Feb 10, 2025
2 parents 16eab4f + 14d6dc1 commit 702beb9
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 79 deletions.
Empty file modified LICENSE.md
100644 → 100755
Empty file.
99 changes: 83 additions & 16 deletions autoblogs/autoblog.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ static public function getXMLErrorsAsString($errors)
}
}

error_reporting(E_ALL);

//error_reporting(E_ALL);
error_reporting(0);
function exception_error_handler($errno, $errstr, $errfile, $errline )
{
// For @ ignored errors
Expand Down Expand Up @@ -150,6 +150,7 @@ class VroumVroum_Config
public $articles_per_page = 10;
public $update_interval = 3600;
public $update_timeout = 10;
public $disabled = false;

public function __construct()
{
Expand All @@ -173,12 +174,18 @@ public function __construct()
$this->$key = (bool) $value;
}

// Check that all required values are filled
$check = array('site_type', 'site_title', 'site_url', 'feed_url', 'update_timeout', 'update_interval', 'articles_per_page');
foreach ($check as $c)
{
if (!trim($this->$c))
throw new VroumVroum_User_Exception("Missing or empty configuration value '".$c."' which is required!");
if(empty($this->feed_url)) {
$this->disabled = true;
}

if(!$this->disabled) {
// Check that all required values are filled
$check = array('site_type', 'site_title', 'site_url', 'feed_url', 'update_timeout', 'update_interval', 'articles_per_page');
foreach ($check as $c)
{
if (!trim($this->$c))
throw new VroumVroum_User_Exception("Missing or empty configuration value '".$c."' which is required!");
}
}

}
Expand All @@ -187,6 +194,31 @@ public function __set($key, $value)
{
return;
}

public function setDisabled()
{
$res = $this->articles->query('SELECT success FROM update_log ORDER BY date DESC LIMIT 10;');
$haveSuccess = true;
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$haveSuccess &= $row;
}
if ($haveSuccess) {
$res = $this->articles->query('SELECT date FROM update_log ORDER BY date DESC LIMIT 1;');
$haveSuccess = $res + 63115200 < time(); //31557600 = 1 year
}
if (!$haveSuccess) {
if (defined('MAIL_ADMIN')) {
$title = sprintf("Autoblogs : %s", $this->site_title);
$msg = sprintf("%s is down!\n%s\n%s\n%s", $this->site_title, $this->site_url, $this->feed_url, ROOT_DIR);
mail(MAIL_ADMIN, $title, $msg);
}
$f = file_get_contents(CONFIG_FILE);
if (strpos($f, 'DISABLED="1"') === false) {
file_put_contents(CONFIG_FILE, $f."\nDISABLED=\"1\"");
}
}
return;
}
}

// BLOG
Expand Down Expand Up @@ -298,14 +330,21 @@ public function insertOrUpdateArticle($feed_id, $title, $url, $date, $content)
return false;
}

$id = $exists['id'];
// $id = $exists['id'];

if ($content != $exists['content'])
$content = $this->mirrorMediasForArticle($content, $url);

/*
$this->articles->exec('UPDATE articles SET title=\''.$this->articles->escapeString($title).'\',
url=\''.$this->articles->escapeString($url).'\', content=\''.$this->articles->escapeString($content).'\',
date=\''.(int)$date.'\' WHERE id = \''.(int)$id.'\';');
*/
$uri = self::toURI($title);
$this->articles->exec('INSERT INTO articles (id, feed_id, title, uri, url, date, content) VALUES (NULL,
\''.$this->articles->escapeString($feed_id).'\', \'[Update] '.$this->articles->escapeString($title).'\',
\''.$this->articles->escapeString($uri).'\', \''.$this->articles->escapeString($url).'\',
\''.(int)$date.'\', \''.$this->articles->escapeString($content).'\');');
$id = $this->articles->lastInsertRowId();

$title = self::removeHTML($title);
$content = self::removeHTML($content);
Expand All @@ -317,6 +356,9 @@ public function insertOrUpdateArticle($feed_id, $title, $url, $date, $content)

public function mustUpdate()
{
if ($this->config->disabled) {
return false;
}
if (isset($_GET['update']))
return true;

Expand Down Expand Up @@ -348,15 +390,17 @@ protected function _getStreamContext()

public function update()
{
if (!$this->mustUpdate())
if (!$this->mustUpdate() || $this->config->disabled) {
return false;
}

try {
$body = file_get_contents($this->config->feed_url, false, $this->_getStreamContext());
}
catch (ErrorException $e)
{
$this->log_update(false, $e->getMessage() . "\n\n" . (!empty($http_response_header) ? implode("\n", $http_response_header) : ''));
$this->config->setDisabled();
throw new VroumVroum_Feed_Exception("Can't retrieve feed: ".$e->getMessage());
}

Expand All @@ -367,6 +411,7 @@ public function update()
{
$errors = VroumVroum_Feed_Exception::getXMLErrorsAsString(libxml_get_errors());
$this->log_update(false, implode("\n", $errors) . "\n\n" . $body);
$this->config->setDisabled();
throw new VroumVroum_Feed_Exception("Feed is invalid - XML error: ".implode(" - ", $errors));
}

Expand Down Expand Up @@ -434,14 +479,24 @@ public function update()
}

public function updateXsaf() {
if($this->mustUpdateXsaf()) {
if($this->mustUpdateXsaf() && !$this->config->disabled) {
$json = json_decode(file_get_contents('import.json'), true);
$count = count($json['files']);
file_put_contents('import.lock', $count); /* one-process locking */
$remoteurl = $json['url'];
if (!file_exists('media')) {
mkdir('media');
}
mkdir('media');
}
if(!file_exists('media/.htaccess')){
file_put_contents('media/.htaccess',
"Options -ExecCGI
RemoveHandler .php .phtml .php3 .php4 .php5 .html .htm .js
RemoveType .php .phtml .php3 .php4 .php5 .html .htm .js
php_flag engine off
AddType text/plain .php .phtml .php3 .php4 .php5 .html .htm .js
");
}

$time = time();
$maxtime = $time + 3; /* max exec time: 3 seconds */

Expand Down Expand Up @@ -523,6 +578,15 @@ public function mirrorMediasForArticle($content, $url)
{
mkdir(MEDIA_DIR);
}
if(!file_exists(MEDIA_DIR.'/.htaccess')){
file_put_contents(MEDIA_DIR.'/.htaccess',
"Options -ExecCGI
RemoveHandler .php .phtml .php3 .php4 .php5 .html .htm .js
RemoveType .php .phtml .php3 .php4 .php5 .html .htm .js
php_flag engine off
AddType text/plain .php .phtml .php3 .php4 .php5 .html .htm .js
");
}

$schemes = array('http', 'https');
$extensions = explode(',', preg_quote('jpg,jpeg,png,apng,gif,svg,pdf,odt,ods,epub,webp,wav,mp3,ogg,aac,wma,flac,opus,mp4,webm', '!'));
Expand Down Expand Up @@ -731,7 +795,8 @@ protected function _copy($from, $to)
body > article { background-color:white;padding: 12px 10px 33px;border:1px solid #aaa;max-width:70em;margin:0 auto;box-shadow:0px 5px 7px #aaa; }
body > article .source { font-size: 0.8em; color: #666; }
body > footer { margin-top:1em;text-align:center; font-size: small; color:#333; clear: both; }
.content {font-size:0.9em;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}';
.content {font-size:0.9em;overflow: hidden;text-overflow: ellipsis;}';
//.content {font-size:0.9em;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}';
break;
case 'shaarli':
$css .= "\n".' /* shaarli style */
Expand Down Expand Up @@ -775,7 +840,9 @@ protected function _copy($from, $to)
<h1><a href="../../" style="font-size:0.8em;">PROJET AUTOBLOG'. (strlen(HEAD_TITLE) > 0 ? ' ~ '. HEAD_TITLE : '') .'</a></h1>
<hr />
<h1><a href="./">'.escape($config->site_title).'</a></h1>';

if ($config->disabled) {
echo "Archivé";
}
if (!empty($config->site_description))
echo '
<p>'.$config->site_description.'</p>
Expand Down
Empty file modified config.php.example
100644 → 100755
Empty file.
Empty file modified docs/docs.txt
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
define('LOCAL_URI', '');
if (!defined('AUTOBLOGS_FOLDER')) define('AUTOBLOGS_FOLDER', './autoblogs/');
if (!defined('DOC_FOLDER')) define('DOC_FOLDER', './docs/');
if (!defined('DOC_FOLDER')) define('DOC_FOLDER', '../streisand/');
if (!defined('RESOURCES_FOLDER')) define('RESOURCES_FOLDER', './resources/');
if (!defined('FOLDER_MAX_LENGTH')) define('FOLDER_MAX_LENGTH', 80);
date_default_timezone_set('Europe/Paris');
Expand Down
Empty file modified index.php
100644 → 100755
Empty file.
Empty file modified resources/autoblog.css
100644 → 100755
Empty file.
Empty file modified resources/icon-generic.svg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified resources/icon-logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 702beb9

Please sign in to comment.