Skip to content

Commit 8e6775f

Browse files
committed
Education news from the blog
1 parent bc63ce9 commit 8e6775f

9 files changed

+311
-11
lines changed

acf-json/group_5fb61a0866259.json

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"key": "group_5fb61a0866259",
3+
"title": "Home Featured Posts",
4+
"fields": [
5+
{
6+
"key": "field_5fb61a0e23aa0",
7+
"label": "Featured News",
8+
"name": "featured_news",
9+
"type": "repeater",
10+
"instructions": "",
11+
"required": 0,
12+
"conditional_logic": 0,
13+
"wrapper": {
14+
"width": "",
15+
"class": "",
16+
"id": ""
17+
},
18+
"collapsed": "",
19+
"min": 0,
20+
"max": 0,
21+
"layout": "table",
22+
"button_label": "Add featured post",
23+
"sub_fields": [
24+
{
25+
"key": "field_5fb61a1c23aa1",
26+
"label": "Post",
27+
"name": "post_id",
28+
"type": "select",
29+
"instructions": "",
30+
"required": 0,
31+
"conditional_logic": 0,
32+
"wrapper": {
33+
"width": "",
34+
"class": "",
35+
"id": ""
36+
},
37+
"choices": {
38+
"62469": "Meet the Winners of the CC Open GLAM Platform Activities Fund!",
39+
"62448": "Can Open GLAM Reshape the Fashion Heritage Narrative?",
40+
"62460": "Meet CC India, Our Next Feature for CC Network Fridays!",
41+
"62430": "A Look Back at the 2020 Virtual CC Global Summit",
42+
"62419": "Creative Commons 2019 Annual Report",
43+
"62404": "The Linked Commons 2.0: What’s New?",
44+
"62362": "Important Updates to the Creative Commons Catalog",
45+
"62346": "Say Hello to Our New CC Open Source Website!",
46+
"62340": "You Can Now Sponsor CC’s Open Source Work on GitHub!",
47+
"62328": "Making the CC Global Network Work Better for You",
48+
"62320": "Facing 2020 at the CC Global Summit: A Look at This Year’s Keynotes",
49+
"62316": "Internationalizing the Open COVID Pledge: Translations and Outreach",
50+
"62305": "Meet CC Tanzania, Our Next Feature for CC Network Fridays!",
51+
"62277": "Implementing the Marrakesh Treaty in Latin America: A Look at the Experiences of Four CC Community Members",
52+
"62273": "Why Universal Access to Information Matters",
53+
"62254": "Registration Is Now Open for the CC Global Summit! Join Us on 19–23 October!",
54+
"62262": "In Support of the Wikimedia Foundation WIPO Application",
55+
"62247": "Six Projects Get Funding from the Creative Commons Copyright Platform Activities Fund",
56+
"62237": "Meet CC Bangladesh, Our Next Feature for CC Network Fridays!",
57+
"62226": "We’re Happy to Introduce Our Newest CC Chapter: CC Austria!",
58+
"62215": "Creative Commons Celebrates International Literacy Day",
59+
"62208": "Welcome to the New CC Chapter in Perú!",
60+
"62201": "Download Shepard Fairey’s Creative Commons Logo Remix",
61+
"62178": "CC Open Education Platform Activities Fund: Six Winners!",
62+
"62165": "Creative Commons Is Now Leading the Open COVID Pledge—Here’s What That Means",
63+
"62146": "Meet the Program Committee Making the 2020 CC Global Summit a Reality!",
64+
"62131": "Introducing Our Google Season of Docs 2020 Participants",
65+
"62113": "Why cOAlition S’ Rights Retention Strategy Protects Researchers",
66+
"62085": "From CC’s New CEO: Working Towards Our Shared Future",
67+
"62087": "Meet CC Netherlands, Our Next Feature for CC Network Fridays!",
68+
"62080": "Your Chance to Perform for the CC Global Summit!",
69+
"62057": "Artificial Intelligence and Creativity: Can Machines Write Like Jane Austen?",
70+
"62034": "Artificial Intelligence and Creativity: Why We’re Against Copyright Protection for AI-Generated Output",
71+
"62021": "Sharing Indigenous Cultural Heritage Online: An Overview of GLAM Policies",
72+
"62001": "Nearly 500 CC-licensed Education Images are Now Available!",
73+
"61971": "From Educators to Illustrators: Meet the Users of CC Search",
74+
"61955": "CC License Suite 4.0 and CC0 Are Now Available in Romanian!",
75+
"61840": "The Increasingly Open World of Photography: A Conversation With Exposure’s Luke Beard",
76+
"61931": "Meet CC Italy, Our First Feature for CC Network Fridays!",
77+
"61918": "Announcing Creative Commons’ New CEO, <br> Catherine Stihler",
78+
"61800": "Say What? Jonathan Poritz Records All CC Certificate Content As Openly Licensed Audio!",
79+
"61787": "Introducing the CC Global Network Platforms!",
80+
"61779": "The CC Global Summit Is Going Virtual—See Our Latest Call for Proposals!",
81+
"61753": "German Public Broadcaster ZDF Releases Dozens of Videos Under CC Licenses",
82+
"61710": "Sharing Openly Licensed Content on Social Media: A Conversation with GLAM",
83+
"61697": "The CC License Suite 4.0 and CC0 Are Now Available in Slovenian!",
84+
"61692": "A Statement of Solidarity and Work to Be Done",
85+
"61670": "Our Community is Reducing the Impact of COVID-19 on Science, Education, and Culture",
86+
"61653": "Leveraging OER for COVID-19 Response Efforts and International Partnerships",
87+
"61606": "CC Search Celebrates Its First Birthday!"
88+
},
89+
"default_value": false,
90+
"allow_null": 0,
91+
"multiple": 0,
92+
"ui": 1,
93+
"ajax": 0,
94+
"return_format": "value",
95+
"placeholder": ""
96+
},
97+
{
98+
"key": "field_5fb61a4523aa2",
99+
"label": "Additional Link",
100+
"name": "additional_link",
101+
"type": "link",
102+
"instructions": "Add an additional link below the featured post. Generally used to link to blog category pages on https:\/\/creativecommons.org.",
103+
"required": 0,
104+
"conditional_logic": 0,
105+
"wrapper": {
106+
"width": "",
107+
"class": "",
108+
"id": ""
109+
},
110+
"return_format": "array"
111+
}
112+
]
113+
}
114+
],
115+
"location": [
116+
[
117+
{
118+
"param": "post_template",
119+
"operator": "==",
120+
"value": "page-home.php"
121+
}
122+
]
123+
],
124+
"menu_order": 0,
125+
"position": "normal",
126+
"style": "default",
127+
"label_placement": "top",
128+
"instruction_placement": "label",
129+
"hide_on_screen": "",
130+
"active": true,
131+
"description": "",
132+
"modified": 1605771784
133+
}

assets/css/child-styles.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/src/styles/mixins.scss

-1
This file was deleted.

front/src/styles/modules.scss

+37
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@
273273
}
274274
}
275275

276+
.alumni-login {
277+
width: 400px;
278+
max-width: 100%;
279+
}
280+
276281
// Scholarship "cards"
277282
.scholarship-recipients {
278283
@include desktop() {
@@ -408,4 +413,36 @@
408413
display: none;
409414
}
410415
}
416+
417+
.education-news-home {
418+
@include tablet() {
419+
display: flex;
420+
align-items: stretch;
421+
column-gap: $space-normal;
422+
margin-bottom: $space-bigger;
423+
}
424+
425+
@include desktop() {
426+
column-gap: $space-larger;
427+
}
428+
429+
.education-news-home__post {
430+
display: flex;
431+
flex-direction: column;
432+
433+
.has-background-soft-gold {
434+
flex-grow: 1;
435+
display: flex;
436+
flex-direction: column;
437+
}
438+
439+
.has-background-soft-gold > .body {
440+
flex-grow: 1;
441+
display: flex;
442+
flex-direction: column;
443+
justify-content: space-between;
444+
}
445+
flex: 1;
446+
}
447+
}
411448
}

front/src/styles/styles.scss

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ $color-primary: rgb(254, 246, 216);
77
@import "@creativecommons/vocabulary/scss/spacing.scss";
88
@import "@creativecommons/vocabulary/scss/typography.scss";
99

10-
@import "mixins";
1110
@import "base";
1211
@import "modules";
13-
@import "widgets";
1412
@import "shame";

front/src/styles/widgets.scss

-1
This file was deleted.

inc/certificates-functions.php

+93
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,96 @@ function get_faqs_by_titles($titles = array(), $faqs = array()) {
8181

8282
return $filtered_faqs;
8383
}
84+
85+
// @todo: Also store in transient (even if short)
86+
function load_home_featured_posts() {
87+
$url = 'https://creativecommons.org/wp-json/wp/v2/posts?per_page=50';
88+
$media_url = 'https://creativecommons.org/wp-json/wp/v2/media';
89+
$author_url = 'https://creativecommons.org/wp-json/wp/v2/users';
90+
91+
$transient_key = 'home_posts' . $url;
92+
93+
foreach ( get_field( 'featured_news', get_option( 'page_on_front' ) ) as $news ) {
94+
if ($news['post_id']) {
95+
$url .= '&include[]=' . $news['post_id'];
96+
}
97+
}
98+
99+
if ( false === ( $results = get_transient( $transient_key ) ) ) {
100+
101+
$posts = query_api($url);
102+
103+
foreach ($posts as $post) {
104+
// Attach featured image info
105+
if ( ! empty( $post->featured_media ) ) {
106+
$api_response = query_api( $media_url . '/' . $post->featured_media );
107+
108+
if ( ! empty( $api_response ) ) {
109+
$post->featured_media_url = $api_response->media_details->sizes->cc_list_post_thumbnail->source_url;
110+
$post->alt_text = $api_response->alt_text;
111+
}
112+
}
113+
114+
// Attach author info
115+
if ( ! empty( $post->author ) ) {
116+
$api_response = query_api( $author_url . '/' . $post->author );
117+
118+
if ( ! empty( $api_response ) ) {
119+
$post->author_name = $api_response->name;
120+
$post->author_url = $api_response->link;
121+
}
122+
}
123+
}
124+
125+
$results = [];
126+
foreach ($posts as $post) {
127+
$results[$post->id] = $post;
128+
}
129+
130+
set_transient( $transient_key, $results, HOUR_IN_SECONDS ); // @todo Maybe longer?
131+
}
132+
133+
return $results;
134+
}
135+
136+
function query_api( $url ) {
137+
$response = wp_remote_get( $url );
138+
$http_code = wp_remote_retrieve_response_code( $response );
139+
if ( $http_code == 200 ) {
140+
$api_response = json_decode( wp_remote_retrieve_body( $response ) );
141+
return $api_response;
142+
} else {
143+
return false;
144+
}
145+
}
146+
147+
function load_org_blog_posts() {
148+
$posts_url = 'https://creativecommons.org/wp-json/wp/v2/posts?per_page=50';
149+
$posts = query_api( $posts_url );
150+
151+
if(!$posts) {
152+
return [];
153+
}
154+
155+
return $posts;
156+
}
157+
158+
/**
159+
* This only runs on the back-end, when editing a page using the page-home.php template.
160+
* @todo Maybe add a short transient here? Not sure if necessary since on the back-end only.
161+
* @todo Maybe need to load more than 50 most recent posts? Download multiple pages and build list.
162+
*/
163+
function acf_load_blog_posts( $field ) {
164+
// reset choices
165+
$field['choices'] = array();
166+
$blog_posts = load_org_blog_posts();
167+
168+
foreach ($blog_posts as $post) {
169+
$field['choices'][$post->id] = $post->title->rendered;
170+
}
171+
172+
// return the field
173+
return $field;
174+
}
175+
176+
add_filter('acf/load_field/name=blog_posts', 'acf_load_blog_posts');

page-home.php

+42-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
get_header();
17-
17+
$featured_posts = load_home_featured_posts();
1818
?>
1919

2020
<main>
@@ -65,19 +65,57 @@
6565
<section class="padding-top-xl padding-bottom-xxl">
6666
<div class="container">
6767

68-
<div class="padding-bottom-xl">
68+
<section class="padding-bottom-xl">
6969
<h2>Education News From The Blog</h2>
7070

71-
<div class="columns is-variable is-6">
71+
<div class="education-news-home margin-top-bigger">
72+
<?php if( have_rows('featured_news') ): while( have_rows('featured_news') ) : the_row();
73+
$post = $featured_posts[get_sub_field('post_id')];
74+
$date = new DateTime($post->date);
75+
$pretty_date = $date->format('F d, Y');
76+
77+
$link = get_sub_field('additional_link');
78+
$link_url = $link['url'];
79+
$link_title = $link['title'];
80+
$link_target = $link['target'] ? $link['target'] : '_self';
81+
?>
82+
<div class="education-news-home__post">
83+
<div class="has-background-soft-gold">
84+
<figure class="image is-5by3">
85+
<a href="<?php echo $post->link; ?>">
86+
<img src="<?php echo $post->featured_media_url; ?>" alt="<?php echo $post->featured_media_alt_text; ?>">
87+
</a>
88+
</figure>
89+
<div class="padding-big">
90+
<h4 class="subtitle is-5">
91+
<a href="<?php echo $post->link; ?>">
92+
<?php echo $post->title->rendered; ?>
93+
</a>
94+
</h4>
95+
<p class="caption margin-top-normal">
96+
<span><?php echo $post->author_name; ?></span>
97+
<svg class="margin-horizontal-smaller" width="6" height="6" viewBox="0 0 6 6" fill="none" xmlns="http://www.w3.org/2000/svg">
98+
<circle opacity="0.2" cx="3" cy="3" r="3" fill="black" />
99+
</svg>
100+
<span><?php echo $pretty_date; ?></span>
101+
</p>
102+
</div>
103+
</div>
104+
<a href="<?php echo $link_url; ?>" target="<?php echo $link_target; ?>" class="is-block margin-top-big has-text-weight-bold">
105+
<?php echo $link_title; ?>
106+
</a>
72107
</div>
108+
<?php endwhile; endif; ?>
73109
</div>
74110

111+
</section>
112+
75113
<div class="home-tweets">
76114
<div class="margin-bottom-big home-tweets__header">
77115
<h2>Conversations in the Community</h2>
78116
<a class="button small twitter margin-right-big" target="_blank" rel="noreferrer nofollow" href="https://twitter.com/hashtag/OpenGLAM">See #OpenGLAM Posts</a>
79117
</div>
80-
<div class="home-tweets__tweets is-variable is-6">
118+
<div class="home-tweets__tweets">
81119
<?php if( have_rows('featured_tweets') ): while( have_rows('featured_tweets') ) : the_row();
82120
$tweet = get_sub_field('tweet_url'); ?>
83121
<div class="tweet">

template-alumni-login.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
<div class="container">
1515
<div class="columns">
16-
<div class="column is-12">
16+
<div class="column is-8">
1717
<section class="entry-page-content padding-top-xl">
1818
<div class="text-format content body-big">
1919
<?php the_content(); ?>
20-
<?php wp_login_form(); ?>
20+
21+
<div class="alumni-login has-background-grey-lighter padding-vertical-bigger padding-horizontal-large">
22+
<?php wp_login_form(); ?>
23+
</div>
2124
</div>
2225
</section>
2326
</div>

0 commit comments

Comments
 (0)