Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
apply coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
bdolor committed Jun 20, 2018
1 parent 74cee2b commit dff7b84
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 135 deletions.
50 changes: 26 additions & 24 deletions autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@
*
* @return void
*/
\spl_autoload_register( function ( $class ) {
\spl_autoload_register(
function ( $class ) {

// project-specific namespace prefix
$prefix = 'BCcampus';
// project-specific namespace prefix
$prefix = 'BCcampus';

// base directory for the namespace prefix
$base_dir = __DIR__ . '/inc';
// base directory for the namespace prefix
$base_dir = __DIR__ . '/inc';

// does the class use the namespace prefix?
$len = \strlen( $prefix );
// does the class use the namespace prefix?
$len = \strlen( $prefix );

if ( \strncmp( $prefix, $class, $len ) !== 0 ) {
// no, move to the next registered autoloader
return;
}
if ( \strncmp( $prefix, $class, $len ) !== 0 ) {
// no, move to the next registered autoloader
return;
}

// get the relative class name
$relative_class = \substr( $class, $len );
// get the relative class name
$relative_class = \substr( $class, $len );

if ( false !== ( $last_ns_pos = strripos( $relative_class, '\\' ) ) ) {
$namespace = substr( $relative_class, 0, $last_ns_pos );
$class = substr( $relative_class, $last_ns_pos + 1 );
$file = str_replace( '\\', DIRECTORY_SEPARATOR, $namespace ) . DIRECTORY_SEPARATOR;
}
$file .= 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( false !== ( $last_ns_pos = strripos( $relative_class, '\\' ) ) ) {
$namespace = substr( $relative_class, 0, $last_ns_pos );
$class = substr( $relative_class, $last_ns_pos + 1 );
$file = str_replace( '\\', DIRECTORY_SEPARATOR, $namespace ) . DIRECTORY_SEPARATOR;
}
$file .= 'class-' . str_replace( '_', '-', $class ) . '.php';

$path = $base_dir . strtolower( $file );
$path = $base_dir . strtolower( $file );

// if the file exists, require it
if ( \file_exists( $path ) ) {
require $path;
// if the file exists, require it
if ( \file_exists( $path ) ) {
require $path;
}
}
} );
);
22 changes: 12 additions & 10 deletions inc/import/openstax/class-cnx.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

namespace BCcampus\Import\OpenStax;

use \Pressbooks\Modules\Import\Import;
use \Pressbooks\Book;
use Pressbooks\Modules\Import\Import;
use Pressbooks\Book;

class Cnx extends Import {
/**
* added for pb5 compatibility
*/
CONST TYPE_OF = 'zip';
const TYPE_OF = 'zip';

/**
* @var \ZipArchive
Expand Down Expand Up @@ -88,7 +88,7 @@ function setCurrentImportOption( array $upload ) {
// blockers
if ( isset( $upload['url'] ) && 0 !== strcmp( $valid_domain['host'], 'cnx.org' ) && ( 0 !== strcmp( $valid_domain['scheme'], 'https' ) ) ) {
return false;
} elseif ( $upload['url'] == null && $upload['type'] !== 'application/zip' ) {
} elseif ( $upload['url'] === null && $upload['type'] !== 'application/zip' ) {
return false;
}

Expand Down Expand Up @@ -360,8 +360,8 @@ private function parseManifestContent() {
];

// otherwise the array gets loooong
unset ( $title_name );
unset ( $dir_name );
unset( $title_name );
unset( $dir_name );

}

Expand All @@ -372,7 +372,6 @@ private function parseManifestContent() {
foreach ( $back_matter->module as $mod ) {
$app[ (string) $mod->attributes()->document ] = (string) $mod->children( $namespaces['md'] );
}

}
$book['APPENDIX'] = $app;

Expand Down Expand Up @@ -711,7 +710,6 @@ protected function scrapeCnxCruft( \DOMDocument $doc ) {
if ( $new_att ) {
$element->setAttribute( 'class', $new_att );
}

}

$sections = $doc->getElementsByTagName( 'section' );
Expand Down Expand Up @@ -827,7 +825,12 @@ protected function fetchAndSaveUniqueImage( $href, $id ) {
}
}

$pid = media_handle_sideload( [ 'name' => $filename, 'tmp_name' => $tmp_name ], 0 );
$pid = media_handle_sideload(
[
'name' => $filename,
'tmp_name' => $tmp_name,
], 0
);

if ( is_wp_error( $pid ) ) {
$error_message = $pid->get_error_message();
Expand Down Expand Up @@ -967,7 +970,6 @@ protected function getPostMeta( $html ) {
$content['author'] = $m->getAttribute( 'content' );
break;
}

}

$content['license'] = $this->extractLicense( $content['license'] );
Expand Down
Loading

0 comments on commit dff7b84

Please sign in to comment.