idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
60,100
function renderCopyrightLicenseField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderRadioButtons ( [ 'id' => 'copyright_license' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'copyright_license' , 'value' => getset ( $ this -> options , 'copyright_li...
Render the copyright_license checkbox .
60,101
function renderTextboxColorField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderColorField ( [ 'id' => $ args [ 'key' ] , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => $ args [ 'key' ] , 'value' => ( isset ( $ this -> options [ $ args [ 'key' ] ] ) ) ?...
Render the header color inputs .
60,102
function renderPartLabelField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'part_label' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'part_label' , 'value' => getset ( $ this -> options , 'part_label' ) , 'description' => $ args ...
Render the part_label input .
60,103
function renderChapterLabelField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'chapter_label' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'chapter_label' , 'value' => getset ( $ this -> options , 'chapter_label' ) , 'description...
Render the chapter_label input .
60,104
static function filterDefaults ( $ defaults ) { $ overrides = [ 'examples-header-color' => 'edu_textbox_examples_header_color' , 'examples-header-background' => 'edu_textbox_examples_header_background' , 'examples-background' => 'edu_textbox_examples_background' , 'exercises-header-color' => 'edu_textbox_exercises_head...
Filter the array of default values for the Global options tab .
60,105
protected function parseMetadata ( \ SimpleXMLElement $ xml ) { foreach ( $ xml -> metadata -> children ( 'dc' , true ) as $ key => $ val ) { $ val = ( string ) $ val ; if ( 'creator' === $ key && ! empty ( $ val ) ) { $ this -> authors .= trim ( $ val ) . ', ' ; } elseif ( 'contributor' === $ key && ! empty ( $ val ) ...
Parse OPF metadata nodes
60,106
protected function selectedForImport ( \ SimpleXMLElement $ xml , array $ match_ids ) { $ selected_for_import = [ ] ; foreach ( $ xml -> spine -> children ( ) as $ item ) { $ id = '' ; foreach ( $ item -> attributes ( ) as $ key => $ val ) { if ( 'idref' === $ key ) { $ id = ( string ) $ val ; } } if ( isset ( $ this -...
Iterate each spine and get each manifest item in the order of spine
60,107
protected function getOpf ( ) { $ container_xml = $ this -> getZipContent ( 'META-INF/container.xml' ) ; $ content_path = $ container_xml -> rootfiles -> rootfile [ 'full-path' ] ; $ base = dirname ( $ content_path ) ; if ( '.' !== $ base ) { $ this -> basedir = "$base/" ; } return $ this -> getZipContent ( $ content_p...
Return book . opf as a SimpleXML object
60,108
protected function setCurrentZip ( $ fullpath ) { $ result = $ this -> zip -> open ( $ fullpath ) ; if ( true !== $ result ) { throw new \ Exception ( 'Opening epub file failed' ) ; } $ ok = $ this -> getZipContent ( 'META-INF/container.xml' ) ; if ( ! $ ok ) { throw new \ Exception ( 'Bad or corrupted META-INF/contain...
Opens a new Epub for reading writing or modifying
60,109
protected function regexSearchReplace ( $ html ) { $ result = $ html ; if ( true === $ this -> isPbEpub ) { $ result = preg_replace ( '/(?:<div class="chapter+(.*)" id="(.*)">)/isU' , '<div>' , $ result ) ; $ result = preg_replace ( '/(?:<div class="chapter-title-wrap"[^>]*>)(.*)<\/div>/isU' , '' , $ result ) ; $ resul...
Cleans imported html of unwanted tags
60,110
protected function pbCheck ( $ copyright_file ) { $ result = $ this -> getZipContent ( $ copyright_file ) ; foreach ( $ result -> body -> div -> div -> p as $ node ) { if ( strpos ( $ node -> a [ 'href' ] [ 0 ] , 'pressbooks.com' , 0 ) ) { $ this -> isPbEpub = true ; } } if ( 'copyright-page' === $ result -> body -> di...
Is it an EPUB generated by PB?
60,111
function doInitialUpgrade ( ) { $ _option = $ this -> getSlug ( ) ; $ options = get_option ( 'pressbooks_theme_options_' . $ _option , $ this -> defaults ) ; if ( isset ( $ options [ 'pdf_page_size' ] ) ) { switch ( $ options [ 'pdf_page_size' ] ) { case 1 : $ options [ 'pdf_page_width' ] = '5.5in' ; $ options [ 'pdf_p...
Substitute human - readable values add new defaults replace pdf_page_size with pdf_page_width and pdf_page_height .
60,112
function upgradeSectionOpenings ( ) { $ _option = $ this -> getSlug ( ) ; $ options = get_option ( 'pressbooks_theme_options_' . $ _option , $ this -> defaults ) ; if ( ! isset ( $ options [ 'pdf_blankpages' ] ) || 1 === absint ( $ options [ 'pdf_blankpages' ] ) || 'include' === $ options [ 'pdf_blankpages' ] ) { $ opt...
Replace pdf_blankpages option with pdf_sectionopenings option .
60,113
function renderBodyFontSizeField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_body_font_size' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_body_font_size' , 'value' => ( isset ( $ this -> options [ 'pdf_body_font_size' ...
Render the pdf_body_font_size input .
60,114
function renderBodyLineHightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_body_line_height' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_body_line_height' , 'value' => ( isset ( $ this -> options [ 'pdf_body_line_h...
Render the pdf_body_line_height input .
60,115
function renderPageSizeField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; if ( ! isset ( $ this -> options [ 'pdf_page_size' ] ) ) { if ( isset ( $ this -> options [ 'pdf_page_width' ] ) && isset ( $ this -> options [ 'pdf_page_height' ] ) ) { if ( '5.5in' === $ this -> options [ 'pdf_page_width...
Render the pdf_page_size select .
60,116
function renderPageWidthField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_page_width' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_page_width' , 'value' => getset ( $ this -> options , 'pdf_page_width' ) , 'description...
Render the pdf_page_width input .
60,117
function renderPageHeightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_page_height' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_page_height' , 'value' => getset ( $ this -> options , 'pdf_page_height' ) , 'descrip...
Render the pdf_page_height input .
60,118
function renderMarginsField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; ?> <div class="margin-diagram"> <p class="description"> <?php echo $ args [ 0 ] ; ?> </p> <div class="pages"> <div class="page left"> <div class="margin outside"></div> <div class="margin top"></div> <div...
Render the margins diagram .
60,119
function renderOutsideMarginField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_page_margin_outside' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_page_margin_outside' , 'value' => getset ( $ this -> options , 'pdf_page_m...
Render the pdf_page_margin_outside input .
60,120
function renderInsideMarginField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_page_margin_inside' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_page_margin_inside' , 'value' => getset ( $ this -> options , 'pdf_page_marg...
Render the pdf_page_margin_inside input .
60,121
function renderTopMarginField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_page_margin_top' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_page_margin_top' , 'value' => getset ( $ this -> options , 'pdf_page_margin_top' )...
Render the pdf_page_margin_top input .
60,122
function renderBottomMarginField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'pdf_page_margin_bottom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_page_margin_bottom' , 'value' => getset ( $ this -> options , 'pdf_page_marg...
Render the pdf_page_margin_bottom input .
60,123
function renderHyphenationField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'pdf_hyphens' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_hyphens' , 'value' => getset ( $ this -> options , 'pdf_hyphens' ) , 'label' => $ arg...
Render the pdf_hyphens checkbox .
60,124
function renderParagraphSeparationField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderRadioButtons ( [ 'id' => 'pdf_paragraph_separation' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_paragraph_separation' , 'value' => getset ( $ this -> option...
Render the pdf_paragraph_separation radio buttons .
60,125
function renderSectionOpeningsField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderRadioButtons ( [ 'id' => 'pdf_sectionopenings' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_sectionopenings' , 'value' => getset ( $ this -> options , 'pdf_secti...
Render the pdf_sectionopenings radio buttons .
60,126
function renderTOCField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'pdf_toc' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_toc' , 'value' => getset ( $ this -> options , 'pdf_toc' ) , 'label' => $ args [ 0 ] , ] ) ; }
Render the pdf_toc checkbox .
60,127
function renderCropMarksField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'pdf_crop_marks' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_crop_marks' , 'value' => getset ( $ this -> options , 'pdf_crop_marks' ) , 'label' =...
Render the pdf_crop_marks checkbox .
60,128
function renderRomanizePartsField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'pdf_romanize_parts' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_romanize_parts' , 'value' => getset ( $ this -> options , 'pdf_romanize_part...
Render the pdf_romanize_parts checkbox .
60,129
function renderFootnoteStyleField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderRadioButtons ( [ 'id' => 'pdf_footnotes_style' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_footnotes_style' , 'value' => getset ( $ this -> options , 'pdf_footnot...
Render the pdf_footnotes_style radio buttons .
60,130
function renderWidowsField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'widows' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'widows' , 'value' => getset ( $ this -> options , 'widows' ) , 'type' => 'text' , 'class' => 'small-te...
Render the widows input .
60,131
function renderOrphansField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderField ( [ 'id' => 'orphans' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'orphans' , 'value' => getset ( $ this -> options , 'orphans' ) , 'type' => 'text' , 'class' => 'smal...
Render the orphans input .
60,132
function renderRunningContentFrontMatterLeftField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_front_matter_left' , 'name' => 'running_content_front_matter_left' , 'value' => getset ( $ this -> options , 'running_content_front_matter_left...
Render the running_content_front_matter_left input .
60,133
function renderRunningContentFrontMatterRightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_front_matter_right' , 'name' => 'running_content_front_matter_right' , 'value' => getset ( $ this -> options , 'running_content_front_matter_r...
Render the running_content_front_matter_right input .
60,134
function renderRunningContentIntroductionLeftField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_introduction_left' , 'name' => 'running_content_introduction_left' , 'value' => getset ( $ this -> options , 'running_content_introduction_lef...
Render the running_content_introduction_left input .
60,135
function renderRunningContentIntroductionRightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_introduction_right' , 'name' => 'running_content_introduction_right' , 'value' => getset ( $ this -> options , 'running_content_introduction_...
Render the running_content_introduction_right input .
60,136
function renderRunningContentPartLeftField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_part_left' , 'name' => 'running_content_part_left' , 'value' => getset ( $ this -> options , 'running_content_part_left' ) , 'choices' => $ args , ] )...
Render the running_content_part_left input .
60,137
function renderRunningContentPartRightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_part_right' , 'name' => 'running_content_part_right' , 'value' => getset ( $ this -> options , 'running_content_part_right' ) , 'choices' => $ args ,...
Render the running_content_part_right input .
60,138
function renderRunningContentChapterLeftField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_chapter_left' , 'name' => 'running_content_chapter_left' , 'value' => getset ( $ this -> options , 'running_content_chapter_left' ) , 'choices' => ...
Render the running_content_chapter_left input .
60,139
function renderRunningContentChapterRightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_chapter_right' , 'name' => 'running_content_chapter_right' , 'value' => getset ( $ this -> options , 'running_content_chapter_right' ) , 'choices'...
Render the running_content_chapter_right input .
60,140
function renderRunningContentBackMatterLeftField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_back_matter_left' , 'name' => 'running_content_back_matter_left' , 'value' => getset ( $ this -> options , 'running_content_back_matter_left' ) ...
Render the running_content_back_matter_left input .
60,141
function renderRunningContentBackMatterRightField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCustomSelect ( [ 'id' => 'running_content_back_matter_right' , 'name' => 'running_content_back_matter_right' , 'value' => getset ( $ this -> options , 'running_content_back_matter_right...
Render the running_content_back_matter_right input .
60,142
function renderFontSizeField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'pdf_fontsize' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'pdf_fontsize' , 'value' => getset ( $ this -> options , 'pdf_fontsize' ) , 'label' => $ arg...
Render the pdf_fontsize checkbox .
60,143
static function filterDefaults ( $ defaults ) { $ overrides = [ 'body-font-size' => 'pdf_body_font_size' , 'body-line-height' => 'pdf_body_line_height' , 'page-margin-top' => 'pdf_page_margin_top' , 'page-margin-inside' => 'pdf_page_margin_inside' , 'page-margin-bottom' => 'pdf_page_margin_bottom' , 'page-margin-outsid...
Filter the array of default values for the PDF options tab .
60,144
public function validate ( string $ path ) { $ command = PB_XMLLINT_COMMAND . ' --noout --schema ' . escapeshellcmd ( $ this -> getSchemaPath ( ) ) . ' ' . escapeshellcmd ( $ path ) . ' 2>&1' ; $ this -> errors = [ ] ; $ output = [ ] ; $ return_var = 0 ; exec ( $ command , $ output , $ return_var ) ; if ( isset ( $ out...
Validate an HTMLBook file
60,145
public function createBarcode ( $ isbn_number ) { if ( ! $ this -> validateIsbnNumber ( $ isbn_number ) ) { \ Pressbooks \ add_error ( __ ( 'There was a problem creating the barcode: Invalid ISBN number.' , 'pressbooks' ) ) ; return false ; } $ this -> isbnNumber = $ this -> fixIsbnNumber ( $ isbn_number ) ; $ ps = \ P...
Create an ISBN png and sideload it into WordPress
60,146
public function validateIsbnNumber ( $ isbn_number ) { @ list ( $ isbn_number , $ addon ) = preg_split ( '/\s+(?=\S*+$)/' , trim ( $ isbn_number ) ) ; $ is_valid_isbn = ( new \ Isbn \ Isbn ( ) ) -> validation -> isbn ( $ isbn_number ) ; $ is_valid_addon = true ; if ( $ addon ) { if ( ! preg_match ( '/^([0-9]{2}|[0-9]{5...
Validate an ISBN string
60,147
public function fixIsbnNumber ( $ isbn_number ) { @ list ( $ isbn_number , $ addon ) = preg_split ( '/\s+(?=\S*+$)/' , trim ( $ isbn_number ) ) ; $ isbn_number = ( new \ Isbn \ Isbn ( ) ) -> hyphens -> fixHyphens ( $ isbn_number ) ; if ( $ addon ) { $ isbn_number .= " $addon" ; } return $ isbn_number ; }
Fix an ISBN string
60,148
public function invocation ( $ isbn , $ isbn_text_font , $ isbn_text_size , $ text_font , $ text_size ) { $ ps [ ] = "50 50 moveto ({$isbn}) (includetext isbntextfont={$isbn_text_font} isbntextsize={$isbn_text_size} textfont={$text_font} textsize={$text_size})" ; $ ps [ ] = '/isbn /uk.co.terryburton.bwipp findresource ...
ISBN Invocation Code .
60,149
public function compile ( $ path_to_ps ) { if ( empty ( $ this -> isbnNumber ) ) { throw new \ LogicException ( '$this->isbnNumber is not set' ) ; } $ isbn = \ Pressbooks \ Utility \ get_contents ( PB_PLUGIN_DIR . 'symbionts/postscriptbarcode/isbn.ps' ) ; $ invocation = $ this -> invocation ( $ this -> isbnNumber , $ t...
Compile an ISBN Postscript file
60,150
public function gs ( $ input_path_to_ps , $ output_path_to_png , $ dpi ) { $ dpi = ( int ) $ dpi ; $ command = PB_GS_COMMAND . " -dQUIET -dNOPAUSE -dSAFER -dBATCH -sDEVICE=pnggray -r{$dpi} -sOutputFile=" . escapeshellarg ( $ output_path_to_png ) . ' ' . escapeshellarg ( $ input_path_to_ps ) ; $ output = [ ] ; $ return_...
Use Ghostscript to convert a PostScript file into a grayscale PNG file
60,151
public function crop ( $ path_to_png , $ border = '20x20' ) { $ command = PB_CONVERT_COMMAND . ' ' . escapeshellarg ( $ path_to_png ) . " -trim +repage -bordercolor white -border {$border} " . escapeshellarg ( $ path_to_png ) ; $ output = [ ] ; $ return_var = 0 ; exec ( $ command , $ output , $ return_var ) ; if ( ! em...
Use ImageMagick to automatically crop & pad a PNG file with a white border
60,152
protected function generateCss ( ) { $ styles = Container :: get ( 'Styles' ) ; $ scss = $ this -> getScssVars ( ) ; if ( $ styles -> isCurrentThemeCompatible ( 1 ) ) { $ scss .= "@import 'fonts-prince'; \n" ; } elseif ( $ styles -> isCurrentThemeCompatible ( 2 ) ) { $ scss .= "@import 'fonts'; \n" ; } $ scss .= \ Pres...
Generate CSS for Ebook JPG cover
60,153
protected function generateHtml ( ) { $ vars = $ this -> getHtmlTemplateVars ( ) ; $ vars [ 'css' ] = apply_filters ( 'pb_epub_cover_css_override' , $ this -> generateCss ( ) ) ; $ html = template ( PB_PLUGIN_DIR . 'templates/covergenerator/jpg-cover.php' , $ vars ) ; return $ html ; }
Generate HTML for Ebook JPG cover
60,154
public function cloneBook ( ) { try { foreach ( $ this -> cloneBookGenerator ( ) as $ percentage => $ info ) { } } catch ( \ Exception $ e ) { return false ; } return true ; }
Clone a book in its entirety .
60,155
public function cloneTerm ( $ term_id ) { foreach ( $ this -> sourceBookTerms as $ k => $ v ) { if ( $ v [ 'id' ] === absint ( $ term_id ) ) { $ term = $ this -> sourceBookTerms [ $ k ] ; break ; } } ; if ( empty ( $ term [ 'slug' ] ) || empty ( $ term [ 'taxonomy' ] ) ) { return false ; } foreach ( $ this -> targetBoo...
Clone term from a source book to a target book .
60,156
public function clonePostProcess ( ) { $ this -> fixInternalShortcodes ( ) ; if ( $ this -> sourceHasH5p === true && ( $ this -> sourceHasH5pApi === false || $ this -> targetHasH5pApi === false || $ this -> targetHasFetchedAllTheH5p === false ) ) { \ Pressbooks \ add_notice ( __ ( 'The source book contained H5P content...
Post - processor
60,157
public function buildListOfKnownMedia ( $ url ) { $ params = [ 'per_page' => 100 , ] ; $ response = $ this -> handleGetRequest ( $ url , 'wp/v2' , 'media' , $ params ) ; if ( is_wp_error ( $ response ) ) { $ _SESSION [ 'pb_errors' ] [ ] = sprintf ( '<p>%1$s</p><p>%2$s</p>' , __ ( 'The source book&rsquo;s media could no...
Use media endpoint to build an array of known media
60,158
public function createTransition ( $ type , $ old_id , $ new_id ) { $ transition = new \ Pressbooks \ Entities \ Cloner \ Transition ( ) ; $ transition -> type = $ type ; $ transition -> oldId = $ old_id ; $ transition -> newId = $ new_id ; $ this -> transitions [ ] = $ transition ; }
When cloning from one book to another the IDs change Use this method to add a transition that we can do something with later if needed
60,159
public function getBookMetadata ( $ url ) { $ response = $ this -> handleGetRequest ( $ url , 'pressbooks/v2' , 'metadata' ) ; if ( is_wp_error ( $ response ) ) { $ _SESSION [ 'pb_errors' ] [ ] = sprintf ( '<p>%1$s</p><p>%2$s</p>' , __ ( 'The source book&rsquo;s metadata could not be read.' , 'pressbooks' ) , $ respons...
Fetch an array containing the metadata of a book .
60,160
public function getBookTerms ( $ url ) { $ terms = [ ] ; foreach ( [ 'front-matter-type' , 'chapter-type' , 'back-matter-type' , 'glossary-type' ] as $ taxonomy ) { $ response = $ this -> handleGetRequest ( $ url , 'pressbooks/v2' , "$taxonomy" , [ 'per_page' => 25 , ] ) ; if ( is_wp_error ( $ response ) ) { continue ;...
Fetch an array containing the terms of a book .
60,161
public function isSourceCloneable ( $ metadata_license ) { $ restrictive_licenses = [ 'https://creativecommons.org/licenses/by-nd/4.0/' , 'https://creativecommons.org/licenses/by-nc-nd/4.0/' , 'https://choosealicense.com/no-license/' , ] ; if ( is_array ( $ metadata_license ) ) { $ license_url = $ metadata_license [ 'u...
Is the source book cloneable?
60,162
public function discoverWordPressApi ( $ url ) { $ response = wp_safe_remote_head ( $ url , [ 'redirection' => 2 , ] ) ; if ( is_wp_error ( $ response ) ) { return false ; } $ headers = wp_remote_retrieve_headers ( $ response ) ; if ( isset ( $ headers [ 'link' ] ) ) { if ( ! is_array ( $ headers [ 'link' ] ) ) { $ hea...
Discover WordPress API
60,163
public function getBookId ( $ url ) { return get_blog_id_from_url ( wp_parse_url ( $ url , PHP_URL_HOST ) , trailingslashit ( wp_parse_url ( $ url , PHP_URL_PATH ) ) ) ; }
Get a book ID from its URL .
60,164
protected function createBook ( ) { $ host = wp_parse_url ( network_home_url ( ) , PHP_URL_HOST ) ; if ( is_subdomain_install ( ) ) { $ domain = $ this -> getSubdomainOrSubDirectory ( $ this -> targetBookUrl ) . '.' . $ host ; $ path = '/' ; } else { $ domain = $ host ; $ path = '/' . $ this -> getSubdomainOrSubDirecto...
Create target book if it doesn t already exist .
60,165
protected function cloneMetadata ( ) { $ metadata_post_id = ( new \ Pressbooks \ Metadata ) -> getMetaPostId ( ) ; if ( ! $ metadata_post_id ) { return false ; } $ book_information = schema_to_book_information ( $ this -> sourceBookMetadata ) ; if ( ! \ Pressbooks \ Image \ is_default_cover ( $ book_information [ 'pb_c...
Clone book information to the target book .
60,166
protected function retrieveSectionContent ( $ section ) { if ( array_key_exists ( 'raw' , $ section [ 'content' ] ) ) { $ source_content = $ section [ 'content' ] [ 'raw' ] ; } else { $ source_content = $ section [ 'content' ] [ 'rendered' ] ; } $ characters_to_keep = [ "\xc2\xa0" ] ; foreach ( $ characters_to_keep as ...
Download media found in a section s post_content node change the href links to point to newly downloaded media etc
60,167
protected function parseLinkHeader ( $ link ) { $ parts = explode ( ';' , $ link ) ; $ attrs = [ 'href' => trim ( array_shift ( $ parts ) , '<>' ) , ] ; foreach ( $ parts as $ part ) { if ( ! strpos ( $ part , '=' ) ) { continue ; } list ( $ key , $ value ) = explode ( '=' , $ part , 2 ) ; $ key = trim ( $ key ) ; $ va...
Parse a Link header into attributes .
60,168
public static function isEnabled ( ) { $ enable_cloning = get_site_option ( 'pressbooks_sharingandprivacy_options' , [ ] ) ; $ enable_cloning = isset ( $ enable_cloning [ 'enable_cloning' ] ) ? $ enable_cloning [ 'enable_cloning' ] : SharingAndPrivacyOptions :: getDefaults ( ) [ 'enable_cloning' ] ; return ( bool ) $ e...
Is clonning feature enabled for this network?
60,169
public function addBlogUser ( $ user_id ) { $ user = get_userdata ( $ user_id ) ; if ( $ user && user_can ( $ user , 'edit_posts' ) ) { $ slug = $ user -> user_nicename ; $ name = trim ( "{$user->first_name} {$user->last_name}" ) ; if ( empty ( $ name ) ) { $ name = $ user -> display_name ; if ( empty ( $ name ) ) { $ ...
Create a matching Contributor term for a given User ID . Used when a user is added to a blog .
60,170
public function updateBlogUser ( $ user_id , $ old_user_data ) { $ user = get_userdata ( $ user_id ) ; if ( $ user && user_can ( $ user , 'edit_posts' ) ) { $ slug = $ user -> user_nicename ; $ name = trim ( "{$user->first_name} {$user->last_name}" ) ; if ( empty ( $ name ) ) { $ name = $ user -> display_name ; if ( em...
Update a matching Contributor term given a User ID . Used when a blog user is updated
60,171
public function personalName ( $ slug ) { init_book_data_models ( ) ; $ name = '' ; $ term = get_term_by ( 'slug' , $ slug , self :: TAXONOMY ) ; if ( $ term ) { $ first_name = get_term_meta ( $ term -> term_id , 'contributor_first_name' , true ) ; $ last_name = get_term_meta ( $ term -> term_id , 'contributor_last_nam...
Get personal name based on available data
60,172
function init ( ) { $ _option = 'pressbooks_theme_options_' . $ this -> getSlug ( ) ; $ _page = $ _option ; $ _section = $ this -> getSlug ( ) . '_options_section' ; $ meta = new Metadata ( ) ; if ( false === get_option ( $ _option ) ) { add_option ( $ _option , $ this -> defaults ) ; } add_settings_section ( $ _sectio...
Configure the web options tab using the settings API .
60,173
function doInitialUpgrade ( ) { $ _option = $ this -> getSlug ( ) ; $ options = get_option ( 'pressbooks_theme_options_' . $ _option , $ this -> defaults ) ; $ deprecated = [ 'toc_collapse' , 'accessibility_fontsize' , ] ; foreach ( $ options as $ key => $ value ) { if ( in_array ( $ key , $ deprecated , true ) ) { uns...
Remove deprecated keys from web options .
60,174
function renderSocialMediaField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'social_media' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'social_media' , 'value' => ( isset ( $ this -> options [ 'social_media' ] ) ) ? $ this -...
Render the social_media checkbox .
60,175
function renderWebbookWidthField ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderSelect ( [ 'id' => 'webbook_width' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'webbook_width' , 'value' => ( isset ( $ this -> options [ 'webbook_width' ] ) ) ? $ this...
Render the webbook_width dropdown .
60,176
function renderPartTitle ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'part_title' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'part_title' , 'value' => ( isset ( $ this -> options [ 'part_title' ] ) ) ? $ this -> options [ '...
Render the part_title checkbox .
60,177
function renderCollapseSections ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'collapse_sections' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'collapse_sections' , 'value' => ( isset ( $ this -> options [ 'part_title' ] ) ) ? ...
Render the collapse_sections checkbox .
60,178
function renderEnableSourceComparison ( $ args ) { unset ( $ args [ 'label_for' ] , $ args [ 'class' ] ) ; $ this -> renderCheckbox ( [ 'id' => 'enable_source_comparison' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'enable_source_comparison' , 'value' => ( isset ( $ this -> options [ '...
Render the allow_comparison checkbox .
60,179
protected function kneadCss ( ) { $ styles = Container :: get ( 'Styles' ) ; $ scss = \ Pressbooks \ Utility \ get_contents ( $ this -> exportStylePath ) ; $ custom_styles = $ styles -> getPrincePost ( ) ; if ( $ custom_styles && ! empty ( $ custom_styles -> post_content ) ) { $ scss .= "\n" . $ custom_styles -> post_c...
Return kneaded CSS string
60,180
protected function fixLatexDpi ( ) { $ fix = false ; if ( ! $ fix && ! empty ( $ _GET [ 'optimize-for-print' ] ) ) { $ fix = true ; } if ( ! $ fix && strpos ( $ this -> url , 'optimize-for-print=1' ) !== false ) { $ fix = true ; } if ( ! $ fix && stripos ( get_class ( $ this ) , 'print' ) !== false ) { $ fix = true ; }...
Increase PB - LaTeX resolution to ~300 dpi
60,181
function get ( ) { global $ wpdb ; $ sql = "SELECT * FROM {$this->dbTable} WHERE users_id = %d AND deleted = 0 " ; return $ wpdb -> get_results ( $ wpdb -> prepare ( $ sql , $ this -> userId ) , ARRAY_A ) ; }
Get an entire catalog .
60,182
function getByTagId ( $ tag_group , $ tag_id ) { global $ wpdb ; $ sql = "SELECT DISTINCT {$this->dbTable}.* FROM {$this->dbTable} INNER JOIN {$this->dbLinkTable} ON {$this->dbLinkTable}.blogs_id = {$this->dbTable}.blogs_id INNER JOIN {$this->dbTagsTable} ON {$this->dbTagsTable}.id = {$this->dbLinkTable}.tags_id...
Get catalog by tag id
60,183
function save ( array $ items ) { foreach ( $ items as $ item ) { if ( isset ( $ item [ 'blogs_id' ] ) ) { $ this -> saveBook ( $ this -> userId , $ item ) ; } } }
Save an entire catalog .
60,184
function delete ( $ for_real = false ) { global $ wpdb ; if ( $ for_real ) { return $ wpdb -> delete ( $ this -> dbTable , [ 'users_id' => $ this -> userId , ] , [ '%d' ] ) ; } else { return $ wpdb -> update ( $ this -> dbTable , [ 'deleted' => 1 , ] , [ 'users_id' => $ this -> userId , ] , [ '%d' ] , [ '%d' ] ) ; } }
Delete an entire catalog .
60,185
function getBook ( $ blog_id ) { global $ wpdb ; $ sql = "SELECT * FROM {$this->dbTable} WHERE users_id = %d AND blogs_id = %d AND deleted = 0 " ; return $ wpdb -> get_row ( $ wpdb -> prepare ( $ sql , $ this -> userId , $ blog_id ) , ARRAY_A ) ; }
Get a book from a user catalog .
60,186
function getBookIds ( ) { global $ wpdb ; $ sql = "SELECT blogs_id FROM {$this->dbTable} WHERE users_id = %d AND deleted = 0 " ; return $ wpdb -> get_col ( $ wpdb -> prepare ( $ sql , $ this -> userId ) ) ; }
Get only blog IDs .
60,187
function saveBook ( $ blog_id , array $ item ) { global $ wpdb ; unset ( $ item [ 'users_id' ] , $ item [ 'blogs_id' ] , $ item [ 'deleted' ] ) ; $ data = [ 'users_id' => $ this -> userId , 'blogs_id' => $ blog_id , 'deleted' => 0 , ] ; $ format = [ 'users_id' => $ this -> dbColumns [ 'users_id' ] , 'blogs_id' => $ thi...
Save a book to a user catalog .
60,188
function getTagsByBook ( $ blog_id , $ tag_group ) { global $ wpdb ; $ sql = "SELECT DISTINCT {$this->dbTagsTable}.id, {$this->dbTagsTable}.tag FROM {$this->dbTagsTable} INNER JOIN {$this->dbLinkTable} ON {$this->dbLinkTable}.tags_id = {$this->dbTagsTable}.id INNER JOIN {$this->dbTable} ON {$this->dbTable}.user...
Get all tags for a book
60,189
function deleteTag ( $ tag , $ blog_id , $ tag_group , $ for_real = false ) { global $ wpdb ; $ sql = "SELECT id FROM {$this->dbTagsTable} WHERE tag = %s " ; $ tag_id = $ wpdb -> get_var ( $ wpdb -> prepare ( $ sql , $ tag ) ) ; if ( ! $ tag_id ) { return false ; } if ( $ for_real && is_super_admin ( ) ) { $ wpdb -> de...
Delete a tag .
60,190
function deleteTags ( $ blog_id , $ tag_group ) { global $ wpdb ; $ result = $ wpdb -> delete ( $ this -> dbLinkTable , [ 'users_id' => $ this -> userId , 'blogs_id' => $ blog_id , 'tags_group' => $ tag_group , ] , [ '%d' , '%d' , '%d' ] ) ; return $ result ; }
Delete all tags from a user catalog
60,191
function getProfile ( ) { $ profile [ 'users_id' ] = $ this -> userId ; foreach ( $ this -> profileMetaKeys as $ key => $ type ) { $ profile [ $ key ] = get_user_meta ( $ this -> userId , $ key , true ) ; } return $ profile ; }
Get catalog profile .
60,192
function saveProfile ( array $ item ) { $ item = array_intersect_key ( $ item , $ this -> profileMetaKeys ) ; foreach ( $ item as $ key => $ val ) { if ( 'pb_catalog_logo' === $ key ) { continue ; } if ( 'pb_catalog_url' === $ key && $ val ) { $ val = \ Pressbooks \ Sanitize \ canonicalize_url ( $ val ) ; } if ( '%d' =...
Save catalog profile
60,193
protected function createOrUpdateTables ( ) { require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' ) ; $ sql = "CREATE TABLE {$this->dbTable} ( users_id INT(11) NOT null, blogs_id INT(11) NOT null, deleted TINYINT(1) NOT null, featured INT(11) DEFAULT 0 NOT null , PRIMARY KEY (users_id,blogs...
DB Delta the initial Catalog tables .
60,194
static function stringToTags ( $ tags ) { $ tags = mb_split ( ',' , $ tags ) ; foreach ( $ tags as $ key => & $ val ) { $ val = strip_tags ( $ val ) ; $ val = mb_convert_case ( $ val , MB_CASE_TITLE , 'UTF-8' ) ; $ val = mb_split ( '\W' , $ val ) ; $ val = implode ( ' ' , $ val ) ; $ val = trim ( $ val ) ; if ( ! $ val...
Return an array of tags from a comma delimited string
60,195
static function tagsToString ( array $ tags ) { $ tags = wp_list_sort ( $ tags , 'tag' , 'asc' ) ; $ str = '' ; foreach ( $ tags as $ tag ) { $ str .= $ tag [ 'tag' ] . ', ' ; } return rtrim ( $ str , ', ' ) ; }
Return a comma delimited string from an SQL array of tags in alphabetical order .
60,196
static function thumbnailFromUserId ( $ user_id , $ size ) { $ image_url = get_user_meta ( $ user_id , 'pb_catalog_logo' , true ) ; $ book = get_active_blog_for_user ( $ user_id ) ; if ( $ book ) { switch_to_blog ( $ book -> blog_id ) ; $ image_url = \ Pressbooks \ Image \ thumbnail_from_url ( $ image_url , $ size ) ; ...
Catalog image is stored in user s active Media Library .
60,197
static function isFormSubmission ( ) { if ( empty ( $ _REQUEST [ 'page' ] ) ) { return false ; } if ( 'pb_catalog' !== $ _REQUEST [ 'page' ] ) { return false ; } if ( $ _SERVER [ 'REQUEST_METHOD' ] === 'POST' ) { return true ; } if ( static :: isCurrentAction ( 'add' ) || static :: isCurrentAction ( 'remove' ) ) { retu...
Check if a user submitted something to index . php?page = pb_catalog
60,198
static function isCurrentAction ( $ action ) { if ( isset ( $ _REQUEST [ 'action' ] ) && - 1 !== ( int ) $ _REQUEST [ 'action' ] ) { $ compare = $ _REQUEST [ 'action' ] ; } elseif ( isset ( $ _REQUEST [ 'action2' ] ) && - 1 !== ( int ) $ _REQUEST [ 'action2' ] ) { $ compare = $ _REQUEST [ 'action2' ] ; } else { return ...
Two actions are possible in a generic WP_List_Table form . The first takes precedence .
60,199
static function deleteLogo ( ) { check_ajax_referer ( 'pb-delete-catalog-logo' ) ; $ image_url = $ _POST [ 'filename' ] ; $ user_id = ( int ) $ _POST [ 'pid' ] ; $ book = get_active_blog_for_user ( $ user_id ) ; if ( current_user_can_for_blog ( $ book -> blog_id , 'upload_files' ) ) { switch_to_blog ( $ book -> blog_id...
WP_Ajax hook for pb_delete_catalog_logo