Skip to content

Commit

Permalink
Merge pull request #5 from platform-coop-toolkit/dev
Browse files Browse the repository at this point in the history
Merge pcc platform coop changes into fork
  • Loading branch information
jpdimond authored Sep 4, 2020
2 parents adf9fac + 2ddf5f2 commit 8c6872b
Show file tree
Hide file tree
Showing 91 changed files with 10,055 additions and 638 deletions.
14 changes: 0 additions & 14 deletions .dependabot/config.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/generate-mo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Generate MO from PO files

on:
push:
branches:
- dev
paths:
- '**.po'

jobs:
generate-mo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install xgettext
run: sudo apt-get install -y gettext
- name: Generate MO files
run: for file in resources/lang/*.po ; do msgfmt $file -o `echo $file | sed 's/\(.*\.\)po/\1mo/'` ; done
- name: Commit updated MO files
uses: stefanzweifel/[email protected]
with:
commit_message: 'chore(localization): update MO files'
17 changes: 1 addition & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test, build, and deploy

on: [push]
on: [push, pull_request]

jobs:
test:
Expand Down Expand Up @@ -28,21 +28,6 @@ jobs:
run: |
composer install
composer test
update-pot:
needs: test
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install xgettext
run: sudo apt-get install -y gettext
- name: Update POT
run: npm run pot
- name: Commit updated POT
uses: stefanzweifel/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit_message: 'chore(localization): update resources/lang/pcc.pot'
deploy-staging:
needs: test
if: github.ref == 'refs/heads/dev'
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/update-pot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Update POT file

on:
push:
branches:
- dev
paths:
- '**.php'
- '**.js'

jobs:
update-pot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install xgettext
run: sudo apt-get install -y gettext
- name: Update POT
run: npm run pot
- name: Commit updated POT
uses: stefanzweifel/[email protected]
with:
commit_message: 'chore(localization): update resources/lang/pcc.pot'
17 changes: 6 additions & 11 deletions app/Controllers/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ public function mailingAddress()
return apply_filters('the_content', $mailing_address);
}

public function signupText()
{
$signup_text = (function_exists('\PCCFramework\Utils\get_config_option'))
? get_config_option(
'signup_text',
__('Once a month, we’ll email you with the latest news and activity in the community.', 'pcc')
)
: __('Once a month, we’ll email you with the latest news and activity in the community.', 'pcc');
return wpautop($signup_text);
}

public function signupLink()
{
return (function_exists('\PCCFramework\Utils\get_config_option'))
Expand Down Expand Up @@ -177,6 +166,9 @@ public function breadcrumb()
$home = get_post(get_option('page_for_posts'));
$url = get_permalink($home->post_parent);
$label = get_the_title($home->post_parent);
} elseif (is_tax('pcc-sector') || is_tax('pcc-region')) {
$url = get_permalink(get_page_by_title('Community Stories')->ID);
$label = __('Community Stories', 'pcc');
} elseif (is_post_type_archive('pcc-person')) {
// Back home.
$url = get_home_url();
Expand All @@ -187,6 +179,9 @@ public function breadcrumb()
} elseif (is_singular('pcc-person') || is_archive()) {
$url = get_permalink(get_page_by_title('People')->ID);
$label = __('People', 'pcc');
} elseif (is_singular('pcc-story') || is_archive()) {
$url = get_permalink(get_page_by_title('Community Stories')->ID);
$label = __('Community Stories', 'pcc');
}

return [
Expand Down
100 changes: 100 additions & 0 deletions app/Controllers/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Page extends Controller
{
use Partials\Story;

public function photoCredits()
{
if (basename(get_page_template()) !== 'page-photo-credits.blade.php') {
Expand Down Expand Up @@ -90,6 +92,104 @@ public function photoCredits()
return $photos;
}

/*
Create a new Wordpress Query for looping `pcc-story` post types.
*/
public function storiesQuery()
{
$args = [
'post_type' => 'pcc-story',
'posts_per_page' => -1,
'orderby' => 'post_date',
'order' => 'desc',
];

/* If the clear parameter is set, unset all parameters so they
aren't queried. */
if (get_query_var('clear')) {
/* TODO: Improve this implementation. Parameters should
be unset on submission and before reaching this point. */
remove_query_arg('org');
remove_query_arg('clear');
} elseif (get_query_var('org')) {
/* If filtering by a single organization name. */
$args ['tax_query'][] = [
'taxonomy' => 'pcc-organization',
'field' =>'name',
'terms' => get_query_var('org')
];
}

$query = new \WP_Query($args);
return $query;
}

/*
Return an array of unique organization names sorted alphabetically,
false if there are no organizations.
*/
public function storyOrgs()
{
$terms = get_terms('pcc-organization');

if ($terms && ! is_wp_error($terms)) {
foreach ($terms as $term) {
$results[] = $term->name;
}

$results = array_unique($results);
sort($results);

return $results;
}

return false;
}

/*
Create a link list for navigating Stories by taxonomy terms. The first link
of the list is a link to the Community Stories page which lists all stories.
Returns false if there are no terms, or the supplied taxonomy name is
invalid.
*/
public static function taxonomyMenuList($taxonomy = false)
{
$output = '';
if ($taxonomy) {
$terms = get_terms($taxonomy);

if ($terms && ! is_wp_error($terms)) {
$li_class = 'link-list__item';
$output .= '<ul class="link-list">';

// If on a taxonomy page, put a link back to the Stories page.
if (is_tax()) {
$output .= '<li class="link-list__item"><a href="'
. get_permalink(get_page_by_title('Community Stories')->ID)
. '">' . __('All', 'pcc') .'</a></li>';
}

foreach ($terms as $term) {
$link = get_term_link($term->term_id);
$aria_current = '';

if (strcmp(single_term_title('', false), $term->name) == 0) {
$aria_current = ' aria-current="true"';
}

$output .= '<li class="link-list__item">';
$output .= '<a href="'.$link.'"'.$aria_current.'>'.$term->name.'</a>';
$output .= '</li>';
}
$output .= '</ul>';

return $output;
}
}

return false;
}

public function councilQuery()
{
return Page::peopleQuery('member-institute-council-of-advisors');
Expand Down
34 changes: 34 additions & 0 deletions app/Controllers/Partials/Story.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php namespace App\Controllers\Partials;

trait Story
{

/*
Get an array of regions for a story. Returns false if there are no regions.
*/
public static function storyRegions()
{
$terms = get_the_terms(get_the_id(), 'pcc-region');
if ($terms && ! is_wp_error($terms)) {
foreach ($terms as $term) {
$regions[] = $term->name;
}
return $regions;
}
return false;
}

/*
Get the organization for a story, otherwise returns false.
*/
public function storyOrg()
{
$orgs = get_the_terms(get_the_id(), 'pcc-pcc_story_organization');

if ($orgs && ! is_wp_error($orgs)) {
return $orgs[0];
}

return false;
}
}
94 changes: 94 additions & 0 deletions app/Controllers/SinglePccProject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Controllers;

use Sober\Controller\Controller;

class SinglePccProject extends Controller
{
public static function projectTitle()
{
global $id, $post;
return SinglePccProject::rootPage($id, $post)->post_title;
}

public static function rootPage($id, $post)
{
$root_id = "";

if ($post->post_parent) {
$ancestors = get_post_ancestors($id);
$root_id = (!empty($ancestors) ? array_pop($ancestors): $post_id);
} else {
$root_id = $id;
}
return get_post($root_id);
}

public static function ancestors()
{
global $id, $post;
$ancestors = array_reverse(get_post_ancestors($id));
$output = [];

foreach ($ancestors as $a_id) {
$name = get_the_title($a_id);
$output[$name] = [
'name' => $name,
'url' => get_permalink($a_id)
];
}
return $output;
}

public static function banner()
{
global $id, $post;
$banner = "";

if ($post->post_parent) {
$ancestors = get_post_ancestors($id);
$root_id = (!empty($ancestors) ? array_pop($ancestors): $post_id);
$banner = get_post($root_id)->post_title;
} else {
$title = $post->post_title;
}

return $title;
}

public static function menuName()
{
global $id, $post;
$output = [];

$root_page = SinglePccProject::rootPage($id, $post);

$menu_name = get_post_meta($root_page->ID, 'project_menu_name', true);

return $menu_name;
}

public static function researchers()
{
global $id, $wp;
$output = [];

$project_id = get_post_meta($id, 'pcc_project_id', true);

$researchers = get_post_meta($project_id, 'pcc_project_researchers', true);

if ($researchers) {
foreach ($researchers as $researcher_id) {
$name = get_the_title($researcher_id);
$output[ $name ] = [
'name' => $name,
'short_title' => get_post_meta($researcher_id, 'pcc_person_short_title', true),
'slug' => get_post($researcher_id)->post_name
];
}
}

return $output;
}
}
Loading

0 comments on commit 8c6872b

Please sign in to comment.