-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
167 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.quizz-hebdo-item { | ||
padding: 0.5em; | ||
margin: 0.5em; | ||
border-bottom: 1px solid black; | ||
} | ||
.quizz-close { | ||
visibility: hidden; | ||
position: absolute; | ||
} | ||
.quizz-open { | ||
visibility: visible; | ||
position: relative; | ||
} | ||
.fiches-item { | ||
padding: 0.5em; | ||
margin: 0.5em; | ||
border-bottom: 1px solid black; | ||
} | ||
.indicateurs-item { | ||
padding: 0.5em; | ||
margin: 0.5em; | ||
border-bottom: 1px solid black; | ||
} | ||
.phdj-item { | ||
padding: 0.5em; | ||
margin: 0.5em; | ||
border-bottom: 1px solid black; | ||
} | ||
.agenda-item { | ||
padding: 0.5em; | ||
margin: 0.5em; | ||
border-bottom: 1px solid black; | ||
} | ||
.agenda-item-day { | ||
font-size: 0.8rem; | ||
} | ||
.quizz-hebdo-item-title { | ||
font-weight: 800; | ||
} | ||
.phdj-item-title { | ||
font-weight: 800; | ||
} | ||
.indicateurs-item-title { | ||
font-weight: 800; | ||
} | ||
.fiches-item-title { | ||
font-weight: 800; | ||
} | ||
.actus-item-title { | ||
font-weight: 800; | ||
} | ||
.agenda-item-desc { | ||
font-size: 0.9rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,120 @@ | |
* @package WebLexRSSFeed | ||
*/ | ||
|
||
const _WEBLEXRSSFEED_PLUGIN_FILE = __FILE__; | ||
class Shortcode { | ||
|
||
require_once plugin_dir_path( __FILE__ ) . 'includes/class-shortcode.php'; | ||
/** | ||
* Runs initialization tasks. | ||
* | ||
* @see https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/shortcodes.php#L63 | ||
* | ||
* @return void | ||
*/ | ||
public function run() : void { | ||
add_shortcode( 'weblex_rss_feed', array( $this, 'feed' ) ); | ||
} | ||
|
||
/** | ||
* Button | ||
* | ||
* @param array $atts Array of attributes. | ||
* @param string|null $content The shortcode content or null if not set. | ||
* @param string $shortcode_tag The shortcode tag. | ||
* | ||
* @return string | ||
*/ | ||
public function feed( array $atts, string $content, string $shortcode_tag ) : string { | ||
|
||
wp_enqueue_script( 'vuejs', '//cdn.jsdelivr.net/npm/[email protected]' ); | ||
wp_enqueue_script( 'weblex-rss-feed-script', plugin_dir_url( __FILE__ ) . 'script.js', 'vuejs', false ); | ||
wp_enqueue_style( 'weblex-rss-feed-style', plugin_dir_url( __FILE__ ) . 'style.css', null, false ); | ||
|
||
// agenda -> L'agenda | ||
// phdj -> La petite histoire du jour | ||
// actus -> Les actus | ||
// quizz-hebdo -> Le quiz hebdo | ||
// indicateurs -> Les indicateurs | ||
// fiches -> Les fiches | ||
|
||
$feeds = array( | ||
array( | ||
'title' => 'L’agenda', | ||
'url' => 'https://www.weblex.fr/passerelle/363-1460/b3e932dfcd/flux.rss', | ||
'component' => 'agenda', | ||
), | ||
array( | ||
'title' => 'La petite histoire du jour', | ||
'url' => 'https://www.weblex.fr/passerelle/360-4b11/0eb54cc01e/flux.rss', | ||
'component' => 'phdj', | ||
), | ||
array( | ||
'title' => 'Les actus', | ||
'url' => 'https://www.weblex.fr/passerelle/361-0e00/6c4b7da188/flux.rss', | ||
'component' => 'actus', | ||
), | ||
array( | ||
'title' => 'Le quiz hebdo', | ||
'url' => 'https://www.weblex.fr/passerelle/362-78e2/ad35f6dbf4/flux.rss', | ||
'component' => 'quizz-hebdo', | ||
), | ||
array( | ||
'title' => 'Les indicateurs', | ||
'url' => 'https://www.weblex.fr/passerelle/364-162b/bfe450b810/flux.rss', | ||
'component' => 'indicateurs', | ||
), | ||
array( | ||
'title' => 'Les fiches', | ||
'url' => 'https://www.weblex.fr/passerelle/365-0cee/ae02b875da/flux.rss', | ||
'component' => 'fiches', | ||
), | ||
); | ||
|
||
$args = shortcode_atts( | ||
array( | ||
'title' => __( 'Title', 'weblexrssfeed' ), | ||
), | ||
$atts | ||
); | ||
|
||
$index = array_search( $args['title'], array_column( $feeds, 'title' ), true ); | ||
$feed = $feeds[ $index ]; | ||
|
||
$html = '<div class="weblex-rss-feed-app">'; | ||
$html .= '<component is="' . $feed['component'] . '" '; | ||
$html .= 'data-rss = "' . $this->parse( $feed['url'] ) . '" '; | ||
$html .= 'data-title="' . $feed['title'] . '" '; | ||
$html .= 'data-url = "' . $feed['url'] . '" '; | ||
$html .= 'style-needed="true" />'; | ||
$html .= '</div>'; | ||
|
||
return $html; | ||
} | ||
|
||
/** | ||
* Parse | ||
*/ | ||
public function parse( string $url ) { | ||
$simplexml = simplexml_load_file( $url, 'SimpleXMLElement', LIBXML_NOCDATA ); | ||
$array = $this->xml2array( $simplexml ); | ||
|
||
$array['channel']['item'] = array_slice( $simplexml->xpath( ' / rss / channel / item' ), 0, 10 ); | ||
|
||
$json = htmlspecialchars( json_encode( $array ), ENT_QUOTES, 'UTF-8' ); | ||
|
||
return $json; | ||
} | ||
|
||
/** | ||
* xml2array | ||
*/ | ||
public function xml2array( $xml_object, $out = array() ) { | ||
foreach ( (array) $xml_object as $index => $node ) { | ||
$out[ $index ] = is_object( $node ) ? $this->xml2array( $node ) : $node; | ||
} | ||
|
||
return $out; | ||
} | ||
} | ||
|
||
$plugin = new Shortcode(); | ||
$plugin->run(); |