Skip to content

Commit

Permalink
add catalan language
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuku committed Jul 30, 2018
1 parent 6606a13 commit 9a080fb
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 18 deletions.
82 changes: 81 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ function insertThumbnailRSS($content)
add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');


/*
* Cleanup Frontend output and remove unneeded CSS and JS
*/
Expand Down Expand Up @@ -294,6 +293,87 @@ function wsds_defer_scripts($tag, $handle, $src)
return $tag;
}

/*
* Costum REST API Endpoint for newsletter
* get all posts from the past 24h
*/
function newsletter_latest($data)
{
$args = array(
'post_type' => 'post',
'nopaging' => true,
'date_query' => array(
array(
'after' => '24 hours ago'
)
),
'suppress_filters' => 0
);

$the_query = new WP_Query($args);

// Loop posts and build array with all needed informations
$latest = array();
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();

// get thumbnail as image src
$image = '';
if (has_post_thumbnail()) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium');
$image = $thumb['0'];
}

// build array with all categories (name and url)
$postcategories = wp_get_post_categories(get_the_ID());
$cats = array();
// exclude original content category
$catexlude = array(11385, 11386, 11387, 11388, 11389, 11390, 19112); // live
$key = 0;
foreach ($postcategories as $c) {
if (!in_array($c, $catexlude)) {
$cat = get_category($c);
$cats[$key]['name'] = $cat->name;
$cats[$key]['url'] = get_category_link($cat->term_id);
$key++;
}
}

// Get post place from Pods
$pod = pods('post', get_the_ID());
$place = $pod->field('place');

// build array for this post
$temppost = array(
'title' => get_the_title(),
'text' => get_the_excerpt(),
'image' => $image,
'url' => get_permalink(),
'author' => get_the_author(),
'authorurl' => get_author_posts_url(get_the_author_meta('ID')),
'categories' => $cats,
'place' => $place
);
$latest[] = $temppost;
unset($temppost);
}
}

if (empty($latest)) {
return null;
}

return $latest;
}

add_action('rest_api_init', function () {
register_rest_route('newsletter/v2', '/latest', array(
'methods' => 'GET',
'callback' => 'newsletter_latest',
));
});

/*
* Remove unneeded CSS from Jetpack
*/
Expand Down
5 changes: 4 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@
// get Sections and recent posts
$transient = 'latest_by_sections_' . ICL_LANGUAGE_CODE;
if (false === ($seccolumn = get_transient($transient))) {
$category_ID = get_cat_ID("Section");
//$get_correct_ID_lang = icl_object_id($category_ID, 'category', false);
$get_correct_ID_lang = apply_filters( 'wpml_object_id', $category_ID, 'category', TRUE);
$c = 0;
$s = 0;
$seccolumn = array(0 => '', 1 => '');
$categories = get_categories(array('child_of' => get_cat_ID("Section")));
$categories = get_categories(array('child_of' => $get_correct_ID_lang));
$percolumn = ceil(count($categories) / 2);
foreach ($categories as $category) {
$posts = wp_get_recent_posts(array('numberposts' => '3', 'category' => $category->cat_ID, 'post_status' => 'publish', 'suppress_filters' => 0));
Expand Down
4 changes: 2 additions & 2 deletions languages/ca_ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Pressenza\n"
"POT-Creation-Date: 2015-08-27 21:58+0100\n"
"PO-Revision-Date: 2017-04-17 11:42+0100\n"
"PO-Revision-Date: 2017-09-15 14:23+0100\n"
"Last-Translator: Tom Bütikofer\n"
"Language-Team: Pressenza\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -64,7 +64,7 @@ msgstr "Nombre d'entrades"

#: /Users/tbutikofer/Documents/Work/Projects/pressenza/functions.php:13
msgid "Image by"
msgstr "Imatge de"
msgstr "Imatge:"

#: /Users/tbutikofer/Documents/Work/Projects/pressenza/functions.php:14
msgid "The original article can be found on our partner's website here"
Expand Down
37 changes: 25 additions & 12 deletions sass/_pressenza.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ h2, h3 {
}

h4 {
color : $gray;
color : $gray;
margin : 0 0 15px 0;
}

Expand Down Expand Up @@ -192,8 +192,8 @@ figcaption {
padding : 10px;
}

#text-7, #text-8, #text-9, #text-10, #text-11, #text-12, #text-15 {
border: 1px solid #f93;
#text-7, #text-8, #text-9, #text-10, #text-11, #text-12, #text-15, #text-16, #text-18 {
border : 1px solid #f93;
h3 {
background-color : #f93;
}
Expand Down Expand Up @@ -243,9 +243,9 @@ figcaption {
}

.author-box {
padding: 15px;
margin-bottom: 20px;
border: 1px solid $gray-lighter-3;
padding : 15px;
margin-bottom : 20px;
border : 1px solid $gray-lighter-3;
}

/* Article */
Expand Down Expand Up @@ -341,7 +341,7 @@ figcaption {
margin-bottom : 15px;
}
.carousel {
margin-bottom: 25px;
margin-bottom : 25px;
img {
margin-bottom : 0;
}
Expand Down Expand Up @@ -380,9 +380,22 @@ figcaption {
padding : 20px 0 16px 0;
}

.share-fb-like, .share-fb, .share-twitter, .share-google {
margin-right : 15px;
float : left;
.share-fb-like, .share-fb, .share-twitter, .share-google, .share-whatsapp, .share-telegram {
margin : 0 15px 15px 0;
float : left;
}

.share-whatsapp a {
display : block;
height : 25px;
width : 42px;
background : url(images/whatsapp.png) no-repeat;
}
.share-telegram a {
display : block;
height : 25px;
width : 41px;
background : url(images/telegram.png) no-repeat;
}

.widget_search h3,
Expand Down Expand Up @@ -464,8 +477,8 @@ figcaption {

/* Google Search */
input.gsc-search-button-v2 {
width: initial;
height: initial;
width : initial;
height : initial;
}

@media only screen and (max-width : 992px) {
Expand Down
2 changes: 1 addition & 1 deletion single.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// get post categories
$postcategories = wp_get_post_categories($post->ID);
$cats = array();
$catexlude = array(11385, 11386, 11387, 11388, 11389, 11390, 19112);
$catexlude = array(11385, 11386, 11387, 11388, 11389, 11390, 19112, 35531);
$needles = array('@de', '@es', '@fr', '@pt');
foreach ($postcategories as $c) {
if (!in_array($c, $catexlude)) {
Expand Down
2 changes: 1 addition & 1 deletion style.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions views/author.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
{% else %}
{{ author.description }}
{% endif %}
{% elseif language.language_code == 'ca' %}
{% if author.bio_ca != '' %}
{{ author.bio_ca }}
{% else %}
{{ author.description }}
{% endif %}
{% else %}
{{ author.description }}
{% endif %}
Expand Down
16 changes: 16 additions & 0 deletions views/single.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
{{ post.thumbnail.caption_pt }}
{% elseif language.language_code == 'el' %}
{{ post.thumbnail.caption_el }}
{% elseif language.language_code == 'ca' %}
{{ post.thumbnail.caption_ca }}
{% else %}
{{ post.thumbnail.caption }}
{% endif %}
Expand Down Expand Up @@ -71,6 +73,14 @@
<div class="share-google">
<div class="g-plusone" data-size="medium" data-href="{{ language.url }}"></div>
</div>

<div class="share-whatsapp visible-xs">
<a href="WhatsApp://send?text={{ language.url }}"></a>
</div>

<div class="share-telegram visible-xs">
<a href="https://t.me/share/url?url={{ language.url }}"></a>
</div>
</div>
<div id="fb-root"></div>
<script>(function (d, s, id) {
Expand Down Expand Up @@ -147,6 +157,12 @@
{% else %}
{{ post.author.description }}
{% endif %}
{% elseif language.language_code == 'ca' %}
{% if post.author.bio_ca != '' %}
{{ post.author.bio_ca }}
{% else %}
{{ post.author.description }}
{% endif %}
{% else %}
{{ post.author.description }}
{% endif %}
Expand Down

0 comments on commit 9a080fb

Please sign in to comment.