Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] new option to display a "subscribe to channel" link #382

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
```
./node_modules/po2json/bin/po2json ./languages/epfl-fr_FR.po ./languages/epfl-fr_FR-wp-gutenberg-scripts.json -f jed1.x -p
```
- Update the mo file with Poedit
- Update the *.mo files with
- `msgfmt -o epfl-fr_FR.mo epfl-fr_FR.po` and
- `msgfmt -o epfl-de_DE.mo epfl-de_DE.po`

## References
- https://developer.wordpress.org/block-editor/tutorials/
8 changes: 7 additions & 1 deletion frontend/epfl-news/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function epfl_news_block( $attributes ) {
$lang = Utils::get_sanitized_attribute( $attributes, 'lang', 'en' );
$template = Utils::get_sanitized_attribute( $attributes,'template', 'listing' );
$all_news_link = Utils::get_sanitized_attribute( $attributes, 'displayLinkAllNews', FALSE );
$subscribe = Utils::get_sanitized_attribute( $attributes, 'displayLinkSubscribe', FALSE );
$nb_news = Utils::get_sanitized_attribute( $attributes, 'nbNews', 3 );
$text_position = Utils::get_sanitized_attribute( $attributes, 'highlighted1TextPosition', 'horizontal' );
$category = Utils::get_sanitized_attribute( $attributes, 'category', 0 );
Expand All @@ -135,6 +136,11 @@ function epfl_news_block( $attributes ) {
return Utils::render_user_msg("News block: Please check required parameters");
}

$subscribe_link = false;
if ($subscribe) {
$subscribe_link = BASE_NEWS_URL . "/subscription/news/subscribe/" . $channel;
}

$url = epfl_news_build_api_url(
$channel,
$template,
Expand All @@ -156,6 +162,6 @@ function epfl_news_block( $attributes ) {
return Utils::render_user_msg("News block: Please check required parameters");
}

$markup = epfl_news_render($actus->results, $template, $all_news_link, $lang, $text_position);
$markup = epfl_news_render($actus->results, $template, $all_news_link, $subscribe_link, $lang, $text_position);
return $markup;
}
2 changes: 1 addition & 1 deletion frontend/epfl-news/templates/card_with_1_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace EPFL\Plugins\Gutenberg\News;

// template = 4
function epfl_news_card_with_1_news($results, $all_news_link, $lang, $text_position) {
function epfl_news_card_with_1_news($results, $all_news_link, $subscribe_link, $lang, $text_position) {

$count = 1;
$last = count($results);
Expand Down
8 changes: 7 additions & 1 deletion frontend/epfl-news/templates/card_with_2_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace EPFL\Plugins\Gutenberg\News;

// template = 5
function epfl_news_card_with_2_news($results, $all_news_link, $lang, $text_position) {
function epfl_news_card_with_2_news($results, $all_news_link, $subscribe_link, $lang, $text_position) {
$count = 1;
$last = is_countable($results) ? count($results) : 0;
$url_channel = epfl_news_get_url_channel($results, $lang);
Expand Down Expand Up @@ -53,6 +53,12 @@ function epfl_news_card_with_2_news($results, $all_news_link, $lang, $text_posit
$markup .= '</p>';
}

if ($subscribe_link) {
$markup .= '<p class="text-center">';
$markup .= '<a class="link-pretty" href="' . $subscribe_link . '">' . __("Subscribe to channel", "epfl" ) . '</a>';
$markup .= '</p>';
}

$markup .= '</div>';
$markup .= '</div>';

Expand Down
8 changes: 7 additions & 1 deletion frontend/epfl-news/templates/card_with_3_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace EPFL\Plugins\Gutenberg\News;

// template = 6
function epfl_news_card_with_3_news($results, $all_news_link, $lang, $text_position) {
function epfl_news_card_with_3_news($results, $all_news_link, $subscribe_link, $lang, $text_position) {

$count = 1;
$header = false;
Expand Down Expand Up @@ -55,6 +55,12 @@ function epfl_news_card_with_3_news($results, $all_news_link, $lang, $text_posit
$markup .= '</p>';
}

if ($subscribe_link) {
$markup .= '<p class="text-center">';
$markup .= '<a class="link-pretty" href="' . $subscribe_link . '">' . __("Subscribe to channel", "epfl" ) . '</a>';
$markup .= '</p>';
}

$markup .= '</div>';
$markup .= '</div>';

Expand Down
8 changes: 7 additions & 1 deletion frontend/epfl-news/templates/highlighted_with_1_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace EPFL\Plugins\Gutenberg\News;

// template = 3
function epfl_news_highlighted_with_1_news($results, $all_news_link, $lang, $text_position) {
function epfl_news_highlighted_with_1_news($results, $all_news_link, $subscribe_link, $lang, $text_position) {
$count = 1;
$url_channel = epfl_news_get_url_channel($results, $lang);

Expand Down Expand Up @@ -76,6 +76,12 @@ function epfl_news_highlighted_with_1_news($results, $all_news_link, $lang, $tex
$markup .= '</p>';
}

if ($subscribe_link) {
$markup .= '<p class="text-center">';
$markup .= '<a class="link-pretty" href="' . $subscribe_link . '">' . __("Subscribe to channel", 'epfl' ) . '</a>';
$markup .= '</p>';
}

$markup .= '</div>';
$markup .= '</div>';

Expand Down
9 changes: 8 additions & 1 deletion frontend/epfl-news/templates/highlighted_with_3_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace EPFL\Plugins\Gutenberg\News;

// template = 2
function epfl_news_highlighted_with_3_news($results, $all_news_link, $lang, $text_position) {
function epfl_news_highlighted_with_3_news($results, $all_news_link, $subscribe_link, $lang, $text_position) {

$count = 1;
$header = false;
Expand Down Expand Up @@ -107,6 +107,13 @@ function epfl_news_highlighted_with_3_news($results, $all_news_link, $lang, $tex
$markup .= '</a>';
$markup .= '</p>';
}
if ($subscribe_link) {
$markup .= '<p class="text-center">';
$markup .= '<a class="link-pretty" href="' . $subscribe_link . '">';
$markup .= __('Subscribe to channel', 'epfl' );
$markup .= '</a>';
$markup .= '</p>';
}
$markup .= '</div>';
$markup .= '</div>';
$markup .= '</div>';
Expand Down
8 changes: 7 additions & 1 deletion frontend/epfl-news/templates/listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace EPFL\Plugins\Gutenberg\News;

// template = 1
function epfl_news_listing($results, $all_news_link, $lang, $text_position) {
function epfl_news_listing($results, $all_news_link, $subscribe_link, $lang, $text_position) {
$count = 1;
$url_channel = epfl_news_get_url_channel($results, $lang);

Expand Down Expand Up @@ -45,6 +45,12 @@ function epfl_news_listing($results, $all_news_link, $lang, $text_position) {
$markup .= '</p>';
}

if ($subscribe_link) {
$markup .= '<p class="text-center">';
$markup .= '<a class="link-pretty" href="' . $subscribe_link . '">' . __("Subscribe to channel", "epfl" ) . '</a>';
$markup .= '</p>';
}

$markup .= '</div>';
$markup .= '</div>';
return $markup;
Expand Down
4 changes: 2 additions & 2 deletions frontend/epfl-news/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
require_once(dirname(__FILE__) . '/templates/card_with_2_news.php');
require_once(dirname(__FILE__) . '/templates/card_with_3_news.php');

function epfl_news_render($results, $template, $all_news_link, $lang, $text_position) {
function epfl_news_render($results, $template, $all_news_link, $subscribe_link, $lang, $text_position) {
$function_to_be_called = __NAMESPACE__ . '\epfl_news_' . $template;
$markup = $function_to_be_called($results, $all_news_link, $lang, $text_position);
$markup = $function_to_be_called($results, $all_news_link, $subscribe_link, $lang, $text_position);
return $markup;
}
6 changes: 6 additions & 0 deletions languages/epfl-fr_FR-wp-gutenberg-scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
"All news": [
"Toutes les actualités"
],
"Subscribe to channel": [
"S'abonner au canal"
],
"News": [
"Actualités"
],
Expand Down Expand Up @@ -988,6 +991,9 @@
"Display the link \"all news\"": [
"Afficher le lien \"Toutes les actualités\""
],
"Display the subscribe link": [
"Afficher le lien \"S'abonner au canal\""
],
"Themes": [
"Thèmes"
],
Expand Down
Binary file modified languages/epfl-fr_FR.mo
Binary file not shown.
7 changes: 7 additions & 0 deletions languages/epfl-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ msgstr "Information & inscription"
msgid "All news"
msgstr "Toutes les actualités"

msgid "Subscribe to channel"
msgstr "S'abonner au canal"

#: frontend/epfl-news/templates/highlighted_with_1_news.php:42
#: frontend/epfl-news/templates/highlighted_with_3_news.php:55
#: frontend/epfl-news/templates/highlighted_with_3_news.php:82
Expand Down Expand Up @@ -1448,6 +1451,10 @@ msgstr "Prévisualiser la page pour voir l'application du modèle"
msgid "Display the link \"all news\""
msgstr "Afficher le lien \"Toutes les actualités\""

#: src/epfl-news/inspector.js:209
msgid "Display the subscribe link"
msgstr "Afficher le lien \"S'abonner au canal\""

#: src/epfl-news/inspector.js:209
msgid "Themes"
msgstr "Thèmes"
Expand Down
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-gutenberg-epfl",
"version": "2.26.0",
"version": "2.27.0",
"description": "Plugin for Wordpress which provides multiple blocks for EPFL services",
"author": "WordPress EPFL Team",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: wp-gutenberg-epfl
* Description: EPFL Gutenberg Blocks
* Version: 2.26.0
* Version: 2.27.0
* Author: WordPress EPFL Team
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
4 changes: 4 additions & 0 deletions src/epfl-news/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ registerBlockType(
type: 'boolean',
default: false,
},
displayLinkSubscribe: {
type: 'boolean',
default: false,
},
nbNews: {
type: 'integer',
default: 3,
Expand Down
5 changes: 5 additions & 0 deletions src/epfl-news/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ export default class InspectorControlsNews extends Component {
checked={ attributes.displayLinkAllNews }
onChange={ () => setAttributes( { displayLinkAllNews: ! attributes.displayLinkAllNews } ) }
/>
<ToggleControl
label={ __('Display the subscribe link', 'epfl') }
checked={ attributes.displayLinkSubscribe }
onChange={ () => setAttributes( { displayLinkSubscribe: ! attributes.displayLinkSubscribe } ) }
/>
</PanelBody>
<PanelBody title={ __( 'Language', 'epfl' ) }>
<RadioControl
Expand Down
12 changes: 11 additions & 1 deletion src/epfl-news/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class PreviewNews extends Component {
//console.log(this.state.newsList);
}

let linkAllNews;
let linkAllNews, linkSubscribe;
const { className, attributes } = this.props

if (attributes.displayLinkAllNews) {
Expand All @@ -99,6 +99,15 @@ export default class PreviewNews extends Component {
)
}

if (attributes.displayLinkSubscribe) {
let url = `${BASE_NEWS}/subscription/news/subscribe/${attributes.channel}`;
linkSubscribe = (
<p className="text-center">
<a className="link-pretty" href={ url }>{ __("Subscribe to channel", 'epfl') }</a>
</p>
)
}

return (
<div className={ className }>
<div className="list-group">
Expand Down Expand Up @@ -129,6 +138,7 @@ export default class PreviewNews extends Component {
)
}) }
{ linkAllNews }
{ linkSubscribe }
</div>
</div>
)
Expand Down
6 changes: 4 additions & 2 deletions src/epfl-news/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const prod = true;
if (prod) {
global.BASE_NEWS_API_REST_URL = "https://actu.epfl.ch/api/v1/";
global.BASE_NEWS = "https://actu.epfl.ch";
global.BASE_NEWS_API_REST_URL = `${BASE_NEWS}/api/v1/`;
} else {
global.BASE_NEWS_API_REST_URL = "https://stage-actu.epfl.ch/api/v1/";
global.BASE_NEWS = "https://stage-actu.epfl.ch";
global.BASE_NEWS_API_REST_URL = `${BASE_NEWS}/api/v1/`;
}