RSS feed na https://enlacezapatista.ezln.org.mx/ naštiman
parent
0d86c42a43
commit
2f791768e8
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
// to je config za plugine za Pico 1.0 - uporablja evente, ki jih omogoča backward-compatibility plugin "PicoDeprecated"
|
||||
|
||||
// rss-content (plugin) - https://github.com/john-cheesman/pico-rss-content
|
||||
$config['rss_feed'] = 'http://enlacezapatista.ezln.org.mx/feed';
|
||||
?>
|
|
@ -59,4 +59,3 @@ DummyPlugin.enabled: false # Force the plugin "DummyPlugin" to be disab
|
|||
# Custom
|
||||
#
|
||||
my_custom_setting: Hello World! # You can access custom settings in themes using {{ config.my_custom_setting }}
|
||||
rss_feed: http://enlacezapatista.ezln.org.mx/feed
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* RSS Content *
|
||||
* @package Pico
|
||||
* @subpackage RSS Content
|
||||
* @version 1.0.3
|
||||
* @author John Cheesman <info@johncheesman.org.uk>
|
||||
*/
|
||||
class Rss_Content {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
// Get the settings from config.php
|
||||
public function config_loaded(&$settings) {
|
||||
|
||||
$this->config = $settings;
|
||||
|
||||
}
|
||||
|
||||
//Set the twig variable
|
||||
public function before_render(&$twig_vars, &$twig) {
|
||||
|
||||
$twig_vars['rss_content'] = $this->rss_content();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rss data and set the array
|
||||
* @return array
|
||||
*/
|
||||
private function rss_content() {
|
||||
|
||||
// include the config
|
||||
$config = $this->config;
|
||||
|
||||
// get the feed url
|
||||
if (isset($config['rss_feed'])) {
|
||||
$url = $config['rss_feed'];
|
||||
}
|
||||
|
||||
// set date format to default
|
||||
$date_format = $config['date_format'];
|
||||
|
||||
// build the array
|
||||
$rss = new DOMDocument();
|
||||
$rss->load($url);
|
||||
$feed = array();
|
||||
|
||||
foreach ($rss->getElementsByTagName('item') as $node) {
|
||||
$item = array (
|
||||
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
|
||||
//'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
|
||||
"description" => html_entity_decode($node->getElementsByTagName('description')->item(0)->nodeValue),
|
||||
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
|
||||
'date' => date($date_format, strtotime($node->getElementsByTagName('pubDate')->item(0)->nodeValue)),
|
||||
);
|
||||
array_push($feed, $item);
|
||||
}
|
||||
return $feed;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* RSS to Markdown *
|
||||
* @package Pico
|
||||
* @subpackage Rss_to_md
|
||||
* @version 1.0
|
||||
* @author Tom Hopcraft <tom@admirecreative.co.uk>
|
||||
*/
|
||||
|
||||
class Rss_to_md {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
// Get the settings from config.php
|
||||
public function config_loaded(&$settings) {
|
||||
|
||||
$this->config = $settings;
|
||||
|
||||
}
|
||||
|
||||
//Set the twig variable
|
||||
public function before_render(&$twig_vars, &$twig) {
|
||||
|
||||
$twig_vars['rss_to_md'] = $this->rss_to_md();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rss data
|
||||
*/
|
||||
|
||||
private function rss_to_md() {
|
||||
|
||||
/* =============================
|
||||
Debugging
|
||||
@description: Debug an array
|
||||
@lastupdated: 26/02/2014
|
||||
@updatedby: James Kemp
|
||||
|
||||
$item string/array
|
||||
$die boolean Should we kill PHP after showing the debug data?
|
||||
$vardump boolean
|
||||
============================= */
|
||||
|
||||
function d($item, $die = true, $vardump = false) {
|
||||
if($die) {
|
||||
die('<pre>' . ($vardump ? var_dump($item) : print_r($item, true)) . '</pre>');
|
||||
} else {
|
||||
echo '<pre>';
|
||||
($vardump ? var_dump($item) : print_r($item));
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['importer'])) {
|
||||
|
||||
// include the config
|
||||
$config = $this->config;
|
||||
|
||||
// get the feed url
|
||||
if (isset($config['rss_feed'])) {
|
||||
$url = $config['rss_feed'];
|
||||
}
|
||||
|
||||
// set date format to default
|
||||
$date_format = $config['date_format'];
|
||||
|
||||
// build the array
|
||||
$rss = new DOMDocument();
|
||||
$rss->load($url);
|
||||
|
||||
//d($rss);
|
||||
|
||||
function seoUrl($string) {
|
||||
//Lower case everything
|
||||
$string = strtolower($string);
|
||||
//Make alphanumeric (removes all other characters)
|
||||
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
|
||||
//Clean up multiple dashes or whitespaces
|
||||
$string = preg_replace("/[\s-]+/", " ", $string);
|
||||
//Convert whitespaces and underscore to dash
|
||||
$string = preg_replace("/[\s_]/", "-", $string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
foreach ($rss->getElementsByTagName('item') as $node) {
|
||||
|
||||
$title = $node->getElementsByTagName('title')->item(0)->nodeValue;
|
||||
$date = date($date_format, strtotime($node->getElementsByTagName('pubDate')->item(0)->nodeValue));
|
||||
$description = $node->getElementsByTagName('description')->item(0)->nodeValue;
|
||||
$permalink = seoUrl($title);
|
||||
$rssLink = $node->getElementsByTagName('link')->item(0)->nodeValue;
|
||||
|
||||
$postMd = fopen('content/sidebars/'.$permalink.".md", "w") or die("Unable to open file!");
|
||||
// open meta
|
||||
$content = "/*\n";
|
||||
fwrite($postMd, $content);
|
||||
|
||||
$content = 'Title: '.$title."\n";
|
||||
fwrite($postMd, $content);
|
||||
|
||||
$content = 'Date: '.$date."\n";
|
||||
fwrite($postMd, $content);
|
||||
|
||||
$content = 'Link: '.$rssLink."\n";
|
||||
fwrite($postMd, $content);
|
||||
|
||||
// close meta
|
||||
$content = "*/\n\n";
|
||||
fwrite($postMd, $content);
|
||||
// close meta
|
||||
$content = $description."\n";
|
||||
fwrite($postMd, $content);
|
||||
|
||||
fclose($postMd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 608 B |
|
@ -75,6 +75,7 @@
|
|||
</aside>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ include('rss_feed.twig') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>{% if meta.title %}{{ meta.title }}{% else %}{{ site_title }}{% endif %}</title>
|
||||
<meta charset="UTF-8"/>
|
||||
|
@ -66,6 +65,7 @@
|
|||
</aside>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ include('rss_feed.twig') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<aside class="widget">
|
||||
<h3 class="widget-title"><a href="https://enlacezapatista.ezln.org.mx/"><img class="rss_ikonca" src="{{ theme_url }}/images/rss.png" alt="RSS"> Enlace Zapatista</a></h3>
|
||||
<ul>
|
||||
{% for item in rss_content %}
|
||||
<li>
|
||||
<a href="{{ item.link }}">{{ item.title }}</a>
|
||||
<div>{{ item.description|raw }}</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</aside>
|
|
@ -2569,3 +2569,6 @@ header .container {
|
|||
.video { position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden; }
|
||||
.video iframe, .video-container object, .video-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
|
||||
|
||||
/* RSS feed ikonca */
|
||||
.rss_ikonca {border:0; padding-top:0.5rem;}
|
||||
|
||||
|
|
Loading…
Reference in New Issue