Skip to content

Commit

Permalink
✨ Add style
Browse files Browse the repository at this point in the history
  • Loading branch information
19h47 committed Jul 13, 2021
1 parent c286446 commit 65aa229
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 124 deletions.
122 changes: 0 additions & 122 deletions includes/class-shortcode.php

This file was deleted.

54 changes: 54 additions & 0 deletions style.css
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;
}
115 changes: 113 additions & 2 deletions weblex-rss-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 65aa229

Please sign in to comment.