Skip to content

Commit

Permalink
fix captions, apply coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
bdolor committed Nov 20, 2018
1 parent 9d78bff commit 77068c7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 89 deletions.
18 changes: 9 additions & 9 deletions inc/admin/class-textbookadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ function __construct() {
*/
function adminMenuAdjuster() {
if ( \Pressbooks\Book::isBook() ) {
add_menu_page( __( 'Import', $this->plugin_slug ), __( 'Import', $this->plugin_slug ), 'edit_posts', 'pb_import', '\Pressbooks\Admin\Laf\display_import', 'dashicons-upload', 15 );
add_options_page( __( 'Textbooks for Pressbooks Settings', $this->plugin_slug ), __( 'Textbooks for PB', $this->plugin_slug ), 'manage_options', $this->plugin_slug . '-settings', [ $this, 'displayPluginAdminPage' ] );
add_menu_page( __( 'Textbooks for Pressbooks', $this->plugin_slug ), __( 'Textbooks for PB', $this->plugin_slug ), 'edit_posts', $this->plugin_slug, [ $this, 'displayPBTPage' ], 'dashicons-tablet', 64 );
add_menu_page( __( 'Import', 'pressbooks-textbook' ), __( 'Import', 'pressbooks-textbook' ), 'edit_posts', 'pb_import', '\Pressbooks\Admin\Laf\display_import', 'dashicons-upload', 15 );
add_options_page( __( 'Textbooks for Pressbooks Settings', 'pressbooks-textbook' ), __( 'Textbooks for PB', 'pressbooks-textbook' ), 'manage_options', $this->plugin_slug . '-settings', [ $this, 'displayPluginAdminPage' ] );
add_menu_page( __( 'Textbooks for Pressbooks', 'pressbooks-textbook' ), __( 'Textbooks for PB', 'pressbooks-textbook' ), 'edit_posts', $this->plugin_slug, [ $this, 'displayPBTPage' ], 'dashicons-tablet', 64 );
// check if the functionality we need is available
if ( class_exists( '\Pressbooks\Modules\Api_v1\Api' ) ) {
add_submenu_page( $this->plugin_slug, __( 'Search and Import', $this->plugin_slug ), __( 'Search and Import', $this->plugin_slug ), 'edit_posts', 'api_search_import', [ $this, 'displayApiSearchPage' ], '', 65 );
add_submenu_page( $this->plugin_slug, __( 'Search and Import', 'pressbooks-textbook' ), __( 'Search and Import', 'pressbooks-textbook' ), 'edit_posts', 'api_search_import', [ $this, 'displayApiSearchPage' ], '', 65 );
}
add_submenu_page( $this->plugin_slug, __( 'Download Textbooks', $this->plugin_slug ), __( 'Download Textbooks', $this->plugin_slug ), 'edit_posts', 'download_textbooks', [ $this, 'displayDownloadTextbooks' ], '', 66 );
add_submenu_page( $this->plugin_slug, __( 'Download Textbooks', 'pressbooks-textbook' ), __( 'Download Textbooks', 'pressbooks-textbook' ), 'edit_posts', 'download_textbooks', [ $this, 'displayDownloadTextbooks' ], '', 66 );
if ( version_compare( PB_PLUGIN_VERSION, '2.7' ) >= 0 ) {
remove_menu_page( 'pb_publish' );
} else {
Expand Down Expand Up @@ -110,7 +110,7 @@ function addOtbNewsFeed() {
// remove PB news from their blog
remove_meta_box( 'pb_dashboard_widget_metadata', 'dashboard', 'side' );
// add our own
add_meta_box( 'pbt_news_feed', __( 'Open Textbook News', $this->plugin_slug ), [ $this, 'displayOtbFeed' ], 'dashboard', 'side', 'high' );
add_meta_box( 'pbt_news_feed', __( 'Open Textbook News', 'pressbooks-textbook' ), [ $this, 'displayOtbFeed' ], 'dashboard', 'side', 'high' );
}

/**
Expand All @@ -122,7 +122,7 @@ function displayOtbFeed() {
wp_widget_rss_output(
[
'url' => 'https://open.bccampus.ca/feed/',
'title' => __( 'Open Textbook News', $this->plugin_slug ),
'title' => __( 'Open Textbook News', 'pressbooks-textbook' ),
'items' => 5,
'show_summary' => 1,
'show_author' => 0,
Expand Down Expand Up @@ -160,7 +160,7 @@ private function remixSettings() {
// $id, $title, $callback, $page, $section
add_settings_field(
'add_api_endpoint',
__( 'Add an endpoint to your network', $this->plugin_slug ),
__( 'Add an endpoint to your network', 'pressbooks-textbook' ),
'\PBT\Settings\api_endpoint_public_callback',
$page,
$section
Expand Down Expand Up @@ -263,7 +263,7 @@ function addActionLinks( $links ) {

return array_merge(
[
'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug . '-settings' ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>',
'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug . '-settings' ) . '">' . __( 'Settings', 'pressbooks-textbook' ) . '</a>',
], $links
);
}
Expand Down
156 changes: 78 additions & 78 deletions inc/modules/catalogue/class-equellafetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@

class EquellaFetch {

private $apiBaseUrl = 'http://solr.bccampus.ca:8001/bcc/api/';
private $subjectPath1 = '/xml/item/subject_class_level1';
private $subjectPath2 = '/xml/item/subject_class_level2';
private $contributorPath = '/xml/contributordetails/institution';
private $keywordPath = '/xml/item/keywords';
private $whereClause = '';
private $url = '';
private $justTheResultsMaam = [];
private $availableResults = 0;
private $searchTerm = '';
private $keywordFlag = false;
private $byContributorFlag = false;
private $uuid = '';
private $collectionUuid = '7567d816-90cc-4547-af7a-3dbd43277639';
private $api_base_url = 'http://solr.bccampus.ca:8001/bcc/api/';
private $subject_path_1 = '/xml/item/subject_class_level1';
private $subject_path_2 = '/xml/item/subject_class_level2';
private $contributor_path = '/xml/contributordetails/institution';
private $keyword_path = '/xml/item/keywords';
private $where_clause = '';
private $url = '';
private $just_the_results_maam = [];
private $available_results = 0;
private $search_term = '';
private $keyword_flag = false;
private $by_contributor_flag = false;
private $uuid = '';
private $collection_uuid = '7567d816-90cc-4547-af7a-3dbd43277639';

const OPR_IS = ' is ';
const OPR_OR = ' OR ';
Expand All @@ -37,27 +37,27 @@ class EquellaFetch {
*
*/
public function __construct() {
$this->searchBySubject( $this->searchTerm );
$this->searchBySubject( $this->search_term );
}

public function getUuid() {
return $this->uuid;
}

public function getKeywordFlag() {
return $this->keywordFlag;
return $this->keyword_flag;
}

public function getContributorFlag() {
return $this->byContributorFlag;
return $this->by_contributor_flag;
}

public function getResults() {
return $this->justTheResultsMaam;
return $this->just_the_results_maam;
}

public function getWhereClause() {
return $this->whereClause;
return $this->where_clause;
}

/**
Expand All @@ -66,10 +66,10 @@ public function getWhereClause() {
*
* @return the encoded item
*/
private function urlEncode( $anyString ) {
private function urlEncode( $any_string ) {
$result = '';
if ( ! empty( $anyString ) ) {
$result = urlencode( $anyString );
if ( ! empty( $any_string ) ) {
$result = urlencode( $any_string );
return $result;
} else {
return false;
Expand All @@ -78,12 +78,14 @@ private function urlEncode( $anyString ) {

/**
* Private helper function that rawURL encodes (with %20 as spaces)
* @param type $anyString
*
* @param string $any_string
*
* @return string - the encoded item, or false if it's empty
*/
private function rawUrlEncode( $anyString ) {
if ( ! empty( $anyString ) ) {
return rawurlencode( $anyString );
private function rawUrlEncode( $any_string ) {
if ( ! empty( $any_string ) ) {
return rawurlencode( $any_string );
} else {
return false;
}
Expand All @@ -93,59 +95,56 @@ private function rawUrlEncode( $anyString ) {
* Makes a request to the API for resources by subject/or keyword. This method builds the
* REST url and sets the response (json to an associative array) and size in instance variables
*
* @param string $anyQuery
* @param string $any_query
* @param string $order
* @param int $start
* @param array $info
* @param int $limit
*
* @throws \Exception
*/
private function searchBySubject( $anyQuery = '', $order = 'modified', $start = 0, $info = [ 'basic', 'metadata', 'detail', 'attachment', 'drm' ], $limit = 0 ) {
$availableResults = 0;
$loop = 0;
$result = [];
private function searchBySubject( $any_query = '', $order = 'modified', $start = 0, $info = [ 'basic', 'metadata', 'detail', 'attachment', 'drm' ], $limit = 0 ) {

//the limit for the API is 50 items, so we need 50 or less. 0 is 'limitless' so we need to set
//it to the max and loop until we reach all available results, 50 at a time.
$limit = ( $limit == 0 || $limit > 50 ? $limit = 50 : $limit = $limit );

$firstSubjectPath = '';
$secondSubjectPath = '';
$is = $this->rawUrlEncode( self::OPR_IS );
$or = $this->rawUrlEncode( self::OPR_OR );
$optionalParam = '&info=' . $this->arrayToCSV( $info ) . '';
$first_subject_path = '';
$second_subject_path = '';
$is = $this->rawUrlEncode( self::OPR_IS );
$or = $this->rawUrlEncode( self::OPR_OR );
$optional_param = '&info=' . $this->arrayToCSV( $info ) . '';

// if there's a specified user query, deal with it, change the order
// to relevance as opposed to 'modified' (default)
if ( $anyQuery != '' ) {
$order = 'relevance';
$anyQuery = $this->rawUrlEncode( $anyQuery );
$anyQuery = 'q=' . $anyQuery . '&';
if ( $any_query != '' ) {
$order = 'relevance';
$any_query = $this->rawUrlEncode( $any_query );
$any_query = 'q=' . $any_query . '&';
}

// start building the URL
$searchWhere = 'search?' . $anyQuery . '&collections=' . $this->collectionUuid . '&start=' . $start . '&length=' . $limit . '&order=' . $order . '&where='; //limit 50 is the max results allowed by the API
$search_where = 'search?' . $any_query . '&collections=' . $this->collection_uuid . '&start=' . $start . '&length=' . $limit . '&order=' . $order . '&where='; //limit 50 is the max results allowed by the API
//switch the API url, depending on whether you are searching for a keyword or a subject.
if ( empty( $this->whereClause ) ) {
$this->url = $this->apiBaseUrl . $searchWhere . $optionalParam;
if ( empty( $this->where_clause ) ) {
$this->url = $this->api_base_url . $search_where . $optional_param;
} // SCENARIOS, require three distinct request urls depending...
// 1
elseif ( $this->keywordFlag == true ) {
$firstSubjectPath = $this->urlEncode( $this->keywordPath );
elseif ( $this->keyword_flag == true ) {
$first_subject_path = $this->urlEncode( $this->keyword_path );
//oh, the API is case sensitive so this broadens our results, which we want
$secondWhere = strtolower( $this->whereClause );
$firstWhere = ucwords( $this->whereClause );
$this->url = $this->apiBaseUrl . $searchWhere . $firstSubjectPath . $is . "'" . $firstWhere . "'" . $or . $firstSubjectPath . $is . "'" . $secondWhere . "'" . $optionalParam; //add the base url, put it all together
$second_where = strtolower( $this->where_clause );
$first_where = ucwords( $this->where_clause );
$this->url = $this->api_base_url . $search_where . $first_subject_path . $is . "'" . $first_where . "'" . $or . $first_subject_path . $is . "'" . $second_where . "'" . $optional_param; //add the base url, put it all together
} // 2
elseif ( $this->byContributorFlag == true ) {
$firstSubjectPath = $this->urlEncode( $this->contributorPath );
$this->url = $this->apiBaseUrl . $searchWhere . $firstSubjectPath . $is . "'" . $this->whereClause . "'" . $optionalParam;
elseif ( $this->by_contributor_flag == true ) {
$first_subject_path = $this->urlEncode( $this->contributor_path );
$this->url = $this->api_base_url . $search_where . $first_subject_path . $is . "'" . $this->where_clause . "'" . $optional_param;
} // 3
else {
$firstSubjectPath = $this->urlEncode( $this->subjectPath1 );
$secondSubjectPath = $this->urlEncode( $this->subjectPath2 );
$this->url = $this->apiBaseUrl . $searchWhere . $firstSubjectPath . $is . "'" . $this->whereClause . "'" . $or . $secondSubjectPath . $is . "'" . $this->whereClause . "'" . $optionalParam; //add the base url, put it all together
$first_subject_path = $this->urlEncode( $this->subject_path_1 );
$second_subject_path = $this->urlEncode( $this->subject_path_2 );
$this->url = $this->api_base_url . $search_where . $first_subject_path . $is . "'" . $this->where_clause . "'" . $or . $second_subject_path . $is . "'" . $this->where_clause . "'" . $optional_param; //add the base url, put it all together
}

// go and get it
Expand All @@ -165,31 +164,31 @@ private function searchBySubject( $anyQuery = '', $order = 'modified', $start =
//if the # of results we get back is less than the max we asked for
if ( $result['length'] != 50 ) {

$this->availableResults = $result['available'];
$this->justTheResultsMaam = $result['results'];
$this->available_results = $result['available'];
$this->just_the_results_maam = $result['results'];
} else {

// is the available amount greater than the what was returned? Get more!
$availableResults = $result['available'];
$start = $result['start'];
$limit = $result['length'];
$available_results = $result['available'];
$start = $result['start'];
$limit = $result['length'];

if ( $availableResults > $limit ) {
$loop = intval( $availableResults / $limit );
if ( $available_results > $limit ) {
$loop = intval( $available_results / $limit );

for ( $i = 0; $i < $loop; $i ++ ) {
$start = $start + 50;
$searchWhere = 'search?' . $anyQuery . '&collections=' . $this->collectionUuid . '&start=' . $start . '&length=' . $limit . '&order=' . $order . '&where='; //length 50 is the max results allowed by the API
$start = $start + 50;
$search_where = 'search?' . $any_query . '&collections=' . $this->collection_uuid . '&start=' . $start . '&length=' . $limit . '&order=' . $order . '&where='; //length 50 is the max results allowed by the API
//Three different scenarios here, depending..
//1
if ( ! empty( $this->whereClause ) && $this->byContributorFlag == true ) {
$this->url = $this->apiBaseUrl . $searchWhere . $firstSubjectPath . $is . "'" . $this->whereClause . "'" . $optionalParam;
if ( ! empty( $this->where_clause ) && $this->by_contributor_flag == true ) {
$this->url = $this->api_base_url . $search_where . $first_subject_path . $is . "'" . $this->where_clause . "'" . $optional_param;
} //2
elseif ( ! empty( $this->whereClause ) ) {
$this->url = $this->apiBaseUrl . $searchWhere . $firstSubjectPath . $is . "'" . $this->whereClause . "'" . $or . $secondSubjectPath . $is . "'" . $this->whereClause . "'" . $optionalParam; //add the base url, put it all together
elseif ( ! empty( $this->where_clause ) ) {
$this->url = $this->api_base_url . $search_where . $first_subject_path . $is . "'" . $this->where_clause . "'" . $or . $second_subject_path . $is . "'" . $this->where_clause . "'" . $optional_param; //add the base url, put it all together
} //3
else {
$this->url = $this->apiBaseUrl . $searchWhere . $optionalParam;
$this->url = $this->api_base_url . $search_where . $optional_param;
}
// modify the url
curl_setopt( $ch, CURLOPT_URL, $this->url );
Expand All @@ -199,44 +198,45 @@ private function searchBySubject( $anyQuery = '', $order = 'modified', $start =
throw new \Exception( 'Something went wrong with the API call to SOLR' );
}

$nextResult = json_decode( $ok2, true );
$next_result = json_decode( $ok2, true );

// push each new result onto the existing array
$partOfNextResult = $nextResult['results'];
foreach ( $partOfNextResult as $val ) {
$part_of_next_result = $next_result['results'];
foreach ( $part_of_next_result as $val ) {
array_push( $result['results'], $val );
}
}
} /* end of if */
} /* end of else */
curl_close( $ch );

$this->availableResults = $result['available'];
$this->justTheResultsMaam = $result['results'];
$this->available_results = $result['available'];
$this->just_the_results_maam = $result['results'];
}

/**
* Helper function to turn an array into a comma separated value. If it's passed
* a key (mostly an author's name) it will strip out the equella user name
*
* @param Array - an array of values
* @param array $any_array
* @param String $key - the key of the associative array you want returned
*
* @return String of comma separated values
*/
public static function arrayToCSV( $anyArray = [], $key = '' ) {
public static function arrayToCSV( $any_array = [], $key = '' ) {
$result = '';

if ( is_array( $anyArray ) ) {
if ( is_array( $any_array ) ) {
//if it's not being passed a key from an associative array
//NOTE adding a space to either side of the comma below will break the
//integrity of the url given to get_file_contents above.
if ( $key == '' ) {
foreach ( $anyArray as $value ) {
foreach ( $any_array as $value ) {
$result .= $value . ',';
}
//return the value at the key in the associative array
} else {
foreach ( $anyArray as $value ) {
foreach ( $any_array as $value ) {
//names in db sometimes contain usernames [inbrackets], strip 'em out!
$tmp = ( ! strpos( $value[ $key ], '[' ) ) ? $value[ $key ] : rtrim( strstr( $value[ $key ], '[', true ) );
$result .= $tmp . ', ';
Expand Down
4 changes: 3 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ See: https://github.com/BCcampus/pressbooks-textbook/commits/master for more det

= 4.2.2 (2018/11/19) =
* fix fontsize response to a11y function
* update dependencies
* update OTB theme 2.1.5
* compatibility with PB 5.6.0

= 4.2.1 (2018/10/17) =
Expand All @@ -105,7 +107,7 @@ See: https://github.com/BCcampus/pressbooks-textbook/commits/master for more det

= 4.1.2 (2018/07/12) =
* markup parity for textboxes
* bump up otb theme to 2.1.4
* bump up OTB theme to 2.1.4

= 4.1.1 (2018/07/11) =
* fix for parent theme change - thanks @greatislander
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//$image-caption-font-family: $font-1 !default;
//// Font size for image captions.
//// @type String
//$image-caption-font-size: .8em !default;
$image-caption-font-size: (epub: .88em, prince: .88em, web: .88rem) !default;
//// Font style for image captions.
//// @type String
//$image-caption-font-style: normal !default;
Expand Down

0 comments on commit 77068c7

Please sign in to comment.