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_license' , 0 ) , 'choices' => $ args , ] ) ; }
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' ] ] ) ) ? $ this -> options [ $ args [ 'key' ] ] : $ this -> defaults [ $ args [ 'key' ] ] , 'default' => $ this -> defaults [ $ args [ 'key' ] ] , 'description' => $ args [ 'description' ] , ] ) ; }
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 [ 0 ] , 'type' => 'text' , 'class' => 'regular-text' , ] ) ; }
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' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'regular-text' , ] ) ; }
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_header_color' , 'exercises-header-background' => 'edu_textbox_exercises_header_background' , 'exercises-background' => 'edu_textbox_exercises_background' , 'learning-objectives-header-color' => 'edu_textbox_objectives_header_color' , 'learning-objectives-header-background' => 'edu_textbox_objectives_header_background' , 'learning-objectives-background' => 'edu_textbox_objectives_background' , 'key-takeaways-header-color' => 'edu_textbox_takeaways_header_color' , 'key-takeaways-header-background' => 'edu_textbox_takeaways_header_background' , 'key-takeaways-background' => 'edu_textbox_takeaways_background' , ] ; $ transient_name = 'pressbooks_theme_options_global_parsed_sass_variables' ; $ parsed_sass_variables = get_transient ( $ transient_name ) ; if ( $ parsed_sass_variables === false ) { $ parsed_sass_variables = [ ] ; $ sass = Container :: get ( 'Sass' ) ; $ path_to_global = $ sass -> pathToGlobals ( ) ; $ path_to_theme = get_stylesheet_directory ( ) ; $ files = [ $ path_to_global . '/variables/_specials.scss' , $ path_to_theme . '/assets/styles/components/_specials.scss' , ] ; foreach ( $ files as $ file ) { if ( file_exists ( $ file ) ) { $ parsed_sass_variables [ ] = $ sass -> parseVariables ( \ Pressbooks \ Utility \ get_contents ( $ file ) ) ; } } set_transient ( $ transient_name , $ parsed_sass_variables ) ; } foreach ( $ parsed_sass_variables as $ parsed_variables ) { foreach ( $ overrides as $ sass_var => $ wp_option ) { if ( isset ( $ parsed_variables [ $ sass_var ] ) ) { if ( ! empty ( $ parsed_variables [ $ sass_var ] ) ) { $ defaults [ $ wp_option ] = $ parsed_variables [ $ sass_var ] ; } } } } return $ defaults ; }
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 ) ) { $ this -> authors .= trim ( $ val ) . ', ' ; } } $ this -> authors = rtrim ( $ this -> authors , ', ' ) ; }
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 -> manifest [ $ id ] ) ) { $ href = ( string ) $ this -> manifest [ $ id ] [ 'href' ] ; if ( 'OEBPS/copyright.html' === $ href ) { $ this -> pbCheck ( $ href ) ; } if ( ! $ this -> flaggedForImport ( $ id ) ) { continue ; } if ( ! isset ( $ match_ids [ $ id ] ) ) { continue ; } $ selected_for_import [ ] = $ id ; } } return $ selected_for_import ; }
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_path ) ; }
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/container.xml' ) ; } }
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 ) ; $ result = preg_replace ( '/(?:<h2 class="chapter-author"[^>]*>)(.*)<\/h2>/isU' , '' , $ result ) ; $ result = preg_replace ( '/(?:<div class="ugc+(.*)">)/isU' , '<div>' , $ result ) ; $ result = preg_replace ( '/(?:<p class="(.*)+indent">)/isU' , '<p>' , $ result ) ; } return $ result ; }
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 -> div [ 0 ] -> attributes ( ) -> id [ 0 ] && 'ugc' === $ result -> body -> div -> div -> attributes ( ) -> class [ 0 ] ) { $ this -> isPbEpub = true ; } }
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_page_height' ] = '8.5in' ; break ; case 2 : $ options [ 'pdf_page_width' ] = '6in' ; $ options [ 'pdf_page_height' ] = '9in' ; break ; case 3 : $ options [ 'pdf_page_width' ] = '8.5in' ; $ options [ 'pdf_page_height' ] = '11in' ; break ; case 4 : $ options [ 'pdf_page_width' ] = '8.5in' ; $ options [ 'pdf_page_height' ] = '9.25in' ; break ; case 5 : $ options [ 'pdf_page_width' ] = '5in' ; $ options [ 'pdf_page_height' ] = '7.75in' ; break ; case 6 : $ options [ 'pdf_page_width' ] = '4.25in' ; $ options [ 'pdf_page_height' ] = '7in' ; break ; case 7 : $ options [ 'pdf_page_width' ] = '21cm' ; $ options [ 'pdf_page_height' ] = '29.7cm' ; break ; case 8 : $ options [ 'pdf_page_width' ] = '14.8cm' ; $ options [ 'pdf_page_height' ] = '21cm' ; break ; case 9 : $ options [ 'pdf_page_width' ] = '5in' ; $ options [ 'pdf_page_height' ] = '8in' ; break ; default : $ options [ 'pdf_page_width' ] = '5.5in' ; $ options [ 'pdf_page_height' ] = '8.5in' ; } unset ( $ options [ 'pdf_page_size' ] ) ; } if ( ! isset ( $ options [ 'pdf_paragraph_separation' ] ) || 1 === absint ( $ options [ 'pdf_paragraph_separation' ] ) ) { $ options [ 'pdf_paragraph_separation' ] = 'indent' ; } elseif ( 2 === absint ( $ options [ 'pdf_paragraph_separation' ] ) ) { $ options [ 'pdf_paragraph_separation' ] = 'skiplines' ; } if ( ! isset ( $ options [ 'pdf_blankpages' ] ) || 1 === absint ( $ options [ 'pdf_blankpages' ] ) ) { $ options [ 'pdf_blankpages' ] = 'include' ; } elseif ( 2 === absint ( $ options [ 'pdf_blankpages' ] ) ) { $ options [ 'pdf_blankpages' ] = 'remove' ; } if ( ! isset ( $ options [ 'pdf_footnotes_style' ] ) || 1 === absint ( $ options [ 'pdf_footnotes_style' ] ) ) { $ options [ 'pdf_footnotes_style' ] = 'footnotes' ; } elseif ( 2 === absint ( $ options [ 'pdf_footnotes_style' ] ) ) { $ options [ 'pdf_footnotes_style' ] = 'endnotes' ; } foreach ( $ this -> defaults as $ key => $ value ) { if ( ! isset ( $ options [ $ key ] ) ) { $ options [ $ key ] = $ value ; } } update_option ( 'pressbooks_theme_options_' . $ _option , $ options ) ; }
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' ] ) { $ options [ 'pdf_sectionopenings' ] = 'openauto' ; } elseif ( 2 === absint ( $ options [ 'pdf_blankpages' ] ) || 'remove' === $ options [ 'pdf_blankpages' ] ) { $ options [ 'pdf_sectionopenings' ] = 'remove' ; } unset ( $ options [ 'pdf_blankpages' ] ) ; update_option ( 'pressbooks_theme_options_' . $ _option , $ options ) ; }
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' ] ) ) ? $ this -> options [ 'pdf_body_font_size' ] : $ this -> defaults [ 'pdf_body_font_size' ] , 'description' => $ args [ 0 ] , 'append' => $ args [ 1 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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_height' ] ) ) ? $ this -> options [ 'pdf_body_line_height' ] : $ this -> defaults [ 'pdf_body_line_height' ] , 'description' => $ args [ 0 ] , 'append' => $ args [ 1 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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' ] && '8.5in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 1 ; } elseif ( '6in' === $ this -> options [ 'pdf_page_width' ] && '9in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 2 ; } elseif ( '8.5in' === $ this -> options [ 'pdf_page_width' ] && '11in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 3 ; } elseif ( '8.5in' === $ this -> options [ 'pdf_page_width' ] && '9.25in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 4 ; } elseif ( '5in' === $ this -> options [ 'pdf_page_width' ] && '7.75in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 5 ; } elseif ( '4.25in' === $ this -> options [ 'pdf_page_width' ] && '7in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 6 ; } elseif ( '21cm' === $ this -> options [ 'pdf_page_width' ] && '29.7cm' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 7 ; } elseif ( '14.8cm' === $ this -> options [ 'pdf_page_width' ] && '21cm' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 8 ; } elseif ( '5in' === $ this -> options [ 'pdf_page_width' ] && '8in' === $ this -> options [ 'pdf_page_height' ] ) { $ this -> options [ 'pdf_page_size' ] = 9 ; } else { $ this -> options [ 'pdf_page_size' ] = 10 ; } } else { $ this -> options [ 'pdf_page_size' ] = 1 ; } } $ html = "<select name='pressbooks_theme_options_pdf[pdf_page_size]' id='pdf_page_size' >" ; foreach ( $ args as $ key => $ val ) { $ html .= "<option value='" . ( $ key + 1 ) . "' " . selected ( $ key + 1 , $ this -> options [ 'pdf_page_size' ] , false ) . ">$val</option>" ; } $ html .= '</select>' ; echo $ html ; }
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' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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' ) , 'description' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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 class="margin inside"></div> <div class="margin bottom"></div> </div> <div class="page right"> <div class="margin inside"></div> <div class="margin top"></div> <div class="margin outside"></div> <div class="margin bottom"></div> </div> </div> <div class="legend"> <ul> <li class="outside"><span class="color"></span> <?php _e ( 'Outside Margin' , 'pressbooks' ) ; ?> </li> <li class="inside"><span class="color"></span> <?php _e ( 'Inside Margin' , 'pressbooks' ) ; ?> </li> <li class="top"><span class="color"></span> <?php _e ( 'Top Margin' , 'pressbooks' ) ; ?> </li> <li class="bottom"><span class="color"></span> <?php _e ( 'Bottom Margin' , 'pressbooks' ) ; ?> </li> </ul> </div> </div> <p> <strong> <?php _e ( 'IMPORTANT: If you plan to use a print-on-demand service, margins under 2cm on any side can cause your file to be rejected.' , 'pressbooks' ) ; ?> </strong> </p> <?php }
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_margin_outside' ) , 'description' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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_margin_inside' ) , 'description' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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' ) , 'description' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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_margin_bottom' ) , 'description' => $ args [ 0 ] , 'type' => 'text' , 'class' => 'small-text' , ] ) ; }
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' => $ args [ 0 ] , ] ) ; }
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 -> options , 'pdf_paragraph_separation' ) , 'choices' => $ args , ] ) ; }
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_sectionopenings' ) , 'choices' => $ args , ] ) ; }
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' => $ args [ 0 ] , ] ) ; }
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_parts' ) , 'label' => $ args [ 0 ] , ] ) ; }
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_footnotes_style' ) , 'choices' => $ args , ] ) ; }
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-text' , ] ) ; }
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' => 'small-text' , ] ) ; }
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' ) , 'choices' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_front_matter_left_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_front_matter_left' , 'value' => getset ( $ this -> options , 'running_content_front_matter_left' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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_right' ) , 'choices' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_front_matter_right_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_front_matter_right' , 'value' => getset ( $ this -> options , 'running_content_front_matter_right' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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_left' ) , 'choices' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_introduction_left_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_introduction_left' , 'value' => getset ( $ this -> options , 'running_content_introduction_left' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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_right' ) , 'choices' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_introduction_right_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_introduction_right' , 'value' => getset ( $ this -> options , 'running_content_introduction_right' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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 , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_part_left_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_part_left' , 'value' => getset ( $ this -> options , 'running_content_part_left' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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 , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_part_right_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_part_right' , 'value' => getset ( $ this -> options , 'running_content_part_right' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_chapter_left_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_chapter_left' , 'value' => getset ( $ this -> options , 'running_content_chapter_left' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_chapter_right_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_chapter_right' , 'value' => getset ( $ this -> options , 'running_content_chapter_right' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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' ) , 'choices' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_back_matter_left_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_back_matter_left' , 'value' => getset ( $ this -> options , 'running_content_back_matter_left' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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' ) , 'choices' => $ args , ] ) ; $ this -> renderField ( [ 'id' => 'running_content_back_matter_right_custom' , 'name' => 'pressbooks_theme_options_' . $ this -> getSlug ( ) , 'option' => 'running_content_back_matter_right' , 'value' => getset ( $ this -> options , 'running_content_back_matter_right' ) , 'type' => 'text' , 'class' => 'regular-text code' , ] ) ; }
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' => $ args [ 0 ] , ] ) ; }
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-outside' => 'pdf_page_margin_outside' , 'front-matter-running-content-left' => 'running_content_front_matter_left' , 'front-matter-running-content-right' => 'running_content_front_matter_right' , 'introduction-running-content-left' => 'running_content_introduction_left' , 'introduction-running-content-right' => 'running_content_introduction_right' , 'part-running-content-left' => 'running_content_part_left' , 'part-running-content-right' => 'running_content_part_right' , 'chapter-running-content-left' => 'running_content_chapter_left' , 'chapter-running-content-right' => 'running_content_chapter_right' , 'back-matter-running-content-left' => 'running_content_back_matter_left' , 'back-matter-running-content-right' => 'running_content_back_matter_right' , ] ; $ transient_name = 'pressbooks_theme_options_pdf_parsed_sass_variables' ; $ parsed_sass_variables = get_transient ( $ transient_name ) ; if ( $ parsed_sass_variables === false ) { $ parsed_sass_variables = [ ] ; $ sass = Container :: get ( 'Sass' ) ; $ path_to_global = $ sass -> pathToGlobals ( ) ; $ path_to_theme = get_stylesheet_directory ( ) ; $ files = [ $ path_to_global . '/variables/_elements.scss' , $ path_to_global . '/variables/_structure.scss' , $ path_to_theme . '/assets/styles/components/_elements.scss' , $ path_to_theme . '/assets/styles/components/_structure.scss' , ] ; foreach ( $ files as $ file ) { if ( file_exists ( $ file ) ) { $ parsed_sass_variables [ ] = $ sass -> parseVariables ( \ Pressbooks \ Utility \ get_contents ( $ file ) ) ; } } set_transient ( $ transient_name , $ parsed_sass_variables ) ; } foreach ( $ parsed_sass_variables as $ parsed_variables ) { foreach ( $ overrides as $ sass_var => $ wp_option ) { if ( isset ( $ parsed_variables [ $ sass_var ] ) ) { $ val = self :: parseSassValue ( $ parsed_variables [ $ sass_var ] ) ; if ( ! empty ( $ val ) ) { if ( in_array ( $ wp_option , self :: getFloatOptions ( ) , true ) ) { $ val = ( float ) preg_replace ( '/[^0-9.]/' , '' , $ val ) ; } elseif ( in_array ( $ wp_option , self :: getIntegerOptions ( ) , true ) ) { $ val = ( int ) preg_replace ( '/[^0-9]/' , '' , $ val ) ; } elseif ( in_array ( $ wp_option , self :: getBooleanOptions ( ) , true ) ) { $ val = filter_var ( $ val , FILTER_VALIDATE_BOOLEAN ) ; } elseif ( strpos ( $ wp_option , 'running_content' , true ) ) { $ val = self :: replaceRunningContentStrings ( $ val ) ; } $ defaults [ $ wp_option ] = $ val ; } } } } return $ defaults ; }
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 ( $ output [ 0 ] ) && str_ends_with ( $ output [ 0 ] , ' validates' ) ) { return true ; } else { $ this -> errors = $ output ; return false ; } }
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 = \ Pressbooks \ Utility \ create_tmp_file ( ) ; $ png = \ Pressbooks \ Utility \ create_tmp_file ( ) ; $ this -> compile ( $ ps ) ; $ this -> gs ( $ ps , $ png , $ this -> dpi ) ; $ this -> crop ( $ png ) ; $ old_id = \ Pressbooks \ Image \ attachment_id_from_url ( get_option ( 'pressbooks_cg_isbn' ) ) ; if ( $ old_id ) { wp_delete_attachment ( $ old_id , true ) ; } if ( ! function_exists ( 'media_handle_sideload' ) ) { require_once ( ABSPATH . 'wp-admin/includes/image.php' ) ; require_once ( ABSPATH . 'wp-admin/includes/file.php' ) ; require_once ( ABSPATH . 'wp-admin/includes/media.php' ) ; } $ pid = media_handle_sideload ( [ 'name' => "{$this->isbnNumber}.png" , 'tmp_name' => $ png , ] , 0 ) ; if ( is_wp_error ( $ pid ) ) { throw new \ Exception ( $ pid -> get_error_message ( ) ) ; } $ src = wp_get_attachment_url ( $ pid ) ; if ( false === $ src ) { throw new \ Exception ( 'No attachment url.' ) ; } update_option ( 'pressbooks_cg_isbn' , $ src ) ; return $ src ; }
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})$/' , $ addon ) ) { $ is_valid_addon = false ; } } return $ is_valid_isbn && $ is_valid_addon ; }
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 exec' ; return implode ( "\n" , $ ps ) . "\n" ; }
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 , $ this -> isbnTextFont , $ this -> isbnTextSize , $ this -> textFont , $ this -> textSize ) ; file_put_contents ( $ path_to_ps , $ isbn ) ; file_put_contents ( $ path_to_ps , $ invocation , FILE_APPEND | LOCK_EX ) ; file_put_contents ( $ path_to_ps , ( "\n" . 'showpage' ) , FILE_APPEND | LOCK_EX ) ; }
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_var = 0 ; exec ( $ command , $ output , $ return_var ) ; if ( ! empty ( $ output ) ) { debug_error_log ( $ command ) ; debug_error_log ( print_r ( $ output , true ) ) ; } }
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 ( ! empty ( $ output ) ) { debug_error_log ( $ command ) ; debug_error_log ( print_r ( $ output , true ) ) ; } }
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 .= \ Pressbooks \ Utility \ get_contents ( PB_PLUGIN_DIR . 'assets/covergenerator/_jpg.scss' ) ; $ css = $ styles -> customize ( 'prince' , $ scss ) ; $ css = \ Pressbooks \ Sanitize \ normalize_css_urls ( $ css ) ; if ( WP_DEBUG ) { Container :: get ( 'Sass' ) -> debug ( $ css , $ scss , 'cover-jpg' ) ; } return $ css ; }
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 -> targetBookTerms as $ k => $ v ) { if ( $ v [ 'slug' ] === $ term [ 'slug' ] && $ v [ 'taxonomy' ] === $ term [ 'taxonomy' ] ) { return $ v [ 'id' ] ; } } ; $ endpoint = $ term [ 'taxonomy' ] ; $ _links = array_pop ( $ term ) ; $ bad_keys = [ 'id' , 'count' , 'link' , 'parent' , 'taxonomy' ] ; foreach ( $ bad_keys as $ bad_key ) { unset ( $ term [ $ bad_key ] ) ; } $ request = new \ WP_REST_Request ( 'POST' , "/pressbooks/v2/$endpoint" ) ; $ request -> set_body_params ( $ term ) ; $ request -> set_param ( '_fields' , 'id' ) ; $ response = rest_do_request ( $ request ) -> get_data ( ) ; if ( is_wp_error ( $ response ) || @ $ response [ 'data' ] [ 'status' ] >= 400 ) { return false ; } else { return $ response [ 'id' ] ; } }
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 that could not be cloned. Please review the cloned version of your book carefully, as missing H5P content will be indicated. You may want to remove or replace these elements.' , 'pressbooks' ) ) ; } }
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 not be read.' , 'pressbooks' ) , $ response -> get_error_message ( ) ) ; return false ; } $ known_media = [ ] ; foreach ( $ response as $ item ) { $ m = $ this -> createMediaEntity ( $ item ) ; if ( $ item [ 'media_type' ] === 'image' ) { foreach ( $ item [ 'media_details' ] [ 'sizes' ] as $ size => $ info ) { $ attached_file = image_strip_baseurl ( $ info [ 'source_url' ] ) ; $ known_media [ $ attached_file ] = $ m ; } } else { $ attached_file = media_strip_baseurl ( $ m -> sourceUrl ) ; $ known_media [ $ attached_file ] = $ m ; } } return $ known_media ; }
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' ) , $ response -> get_error_message ( ) ) ; return false ; } return $ response ; }
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 ; } unset ( $ response [ '_links' ] ) ; $ terms = array_merge ( $ terms , $ response ) ; } if ( empty ( $ terms ) ) { $ _SESSION [ 'pb_errors' ] [ ] = sprintf ( '<p>%1$s</p>' , __ ( 'The source book&rsquo;s taxonomies could not be read.' , 'pressbooks' ) ) ; } return $ terms ; }
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 [ 'url' ] ; } else { $ license_url = $ metadata_license ; } $ license_url = trailingslashit ( trim ( $ license_url ) ) ; if ( ! empty ( $ this -> sourceBookId ) ) { if ( $ this -> isSuperAdmin ) { return true ; } elseif ( ! in_array ( $ license_url , $ restrictive_licenses , true ) ) { return true ; } else { return false ; } } elseif ( in_array ( $ license_url , $ restrictive_licenses , true ) ) { return false ; } return true ; }
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' ] ) ) { $ headers [ 'link' ] = [ $ headers [ 'link' ] ] ; } foreach ( $ headers [ 'link' ] as $ link ) { if ( strpos ( $ link , 'rel="https://api.w.org/"' ) !== false || strpos ( $ link , "rel='https://api.w.org/'" ) !== false ) { preg_match ( '#\<(.*?)\>.*?//api\.w\.org/#' , $ link , $ matches ) ; if ( empty ( $ matches [ 1 ] ) ) { return false ; } if ( str_ends_with ( $ matches [ 1 ] , "/{$this->restBase}/" ) ) { $ fixed_url = esc_url ( str_lreplace ( "/{$this->restBase}/" , '' , $ matches [ 1 ] ) ) ; } elseif ( str_ends_with ( $ matches [ 1 ] , "/{$this->restBase}" ) ) { $ fixed_url = esc_url ( str_lreplace ( "/{$this->restBase}" , '' , $ matches [ 1 ] ) ) ; } else { $ fixed_url = esc_url ( $ matches [ 1 ] ) ; } return untrailingslashit ( $ fixed_url ) ; } } } return false ; }
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 -> getSubdomainOrSubDirectory ( $ this -> targetBookUrl ) ; } if ( ! $ this -> targetBookTitle ) { $ this -> targetBookTitle = $ this -> sourceBookMetadata [ 'name' ] ; } $ user_id = get_current_user_id ( ) ; add_filter ( 'pb_redirect_to_new_book' , function ( ) { return false ; } ) ; add_filter ( 'pb_default_book_content' , [ $ this , 'removeDefaultBookContent' ] ) ; $ result = wpmu_create_blog ( $ domain , $ path , $ this -> targetBookTitle , $ user_id ) ; remove_all_filters ( 'pb_redirect_to_new_book' ) ; remove_filter ( 'pb_default_book_content' , [ $ this , 'removeDefaultBookContent' ] ) ; if ( is_wp_error ( $ result ) ) { return false ; } return $ result ; }
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_cover_image' ] ) ) { $ new_cover_id = $ this -> downloads -> fetchAndSaveUniqueImage ( $ book_information [ 'pb_cover_image' ] ) ; if ( $ new_cover_id > 0 ) { $ this -> clonedItems [ 'media' ] [ ] = $ new_cover_id ; $ book_information [ 'pb_cover_image' ] = wp_get_attachment_url ( $ new_cover_id ) ; } else { $ book_information [ 'pb_cover_image' ] = default_cover_url ( ) ; } } else { $ book_information [ 'pb_cover_image' ] = default_cover_url ( ) ; } $ book_information [ 'pb_is_based_on' ] = $ this -> sourceBookUrl ; $ metadata_array_values = [ 'pb_keywords_tags' , 'pb_bisac_subject' , 'pb_additional_subjects' ] ; foreach ( $ book_information as $ key => $ value ) { if ( $ this -> contributors -> isValid ( $ key ) ) { $ values = oxford_comma_explode ( $ value ) ; foreach ( $ values as $ v ) { $ this -> contributors -> insert ( $ v , $ metadata_post_id , $ key ) ; } } elseif ( in_array ( $ key , $ metadata_array_values , true ) ) { $ values = explode ( ', ' , $ value ) ; foreach ( $ values as $ v ) { add_post_meta ( $ metadata_post_id , $ key , $ v ) ; } } elseif ( $ key === 'pb_title' ) { update_post_meta ( $ metadata_post_id , $ key , $ this -> targetBookTitle ) ; } else { update_post_meta ( $ metadata_post_id , $ key , $ value ) ; if ( $ key === 'pb_book_license' ) { wp_set_object_terms ( $ metadata_post_id , $ value , \ Pressbooks \ Licensing :: TAXONOMY ) ; } } } $ user_data = get_userdata ( get_current_user_id ( ) ) ; $ this -> contributors -> unlink ( $ user_data -> user_nicename , $ metadata_post_id ) ; return $ metadata_post_id ; }
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 $ c ) { $ md5 = md5 ( $ c ) ; $ source_content = str_replace ( $ c , "<!-- pb_fixme_{$md5} , $ source_content ) ; } $ html5 = new \ Pressbooks \ HtmlParser ( ) ; $ dom = $ html5 -> loadHTML ( $ source_content ) ; $ media = $ this -> downloads -> scrapeAndKneadImages ( $ dom ) ; $ dom = $ media [ 'dom' ] ; $ attachments = $ media [ 'attachments' ] ; $ media = $ this -> downloads -> scrapeAndKneadMedia ( $ dom , $ html5 -> parser ) ; $ dom = $ media [ 'dom' ] ; $ attachments = array_merge ( $ attachments , $ media [ 'attachments' ] ) ; $ dom = $ this -> fixInternalLinks ( $ dom ) ; $ content = $ html5 -> saveHTML ( $ dom ) ; foreach ( $ characters_to_keep as $ c ) { $ md5 = md5 ( $ c ) ; $ content = str_replace ( "<!-- pb_fixme_{$md5} , $ c , $ content ) ; } foreach ( $ attachments as $ pid ) { $ this -> clonedItems [ 'media' ] [ ] = $ pid ; } return [ trim ( $ content ) , $ attachments ] ; }
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 ) ; $ value = trim ( $ value , '" ' ) ; $ attrs [ $ key ] = $ value ; } return $ attrs ; }
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 ) $ enable_cloning ; }
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 ) ) { $ name = $ slug ; } } $ results = wp_insert_term ( $ name , self :: TAXONOMY , [ 'slug' => $ slug , ] ) ; if ( is_array ( $ results ) ) { add_term_meta ( $ results [ 'term_id' ] , 'contributor_first_name' , $ user -> first_name , true ) ; add_term_meta ( $ results [ 'term_id' ] , 'contributor_last_name' , $ user -> last_name , true ) ; return $ results ; } } return false ; }
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 ( empty ( $ name ) ) { $ name = $ slug ; } } $ term = get_term_by ( 'slug' , $ old_user_data -> user_nicename , self :: TAXONOMY ) ; if ( $ term ) { $ results = wp_update_term ( $ term -> term_id , self :: TAXONOMY , [ 'name' => $ name , 'slug' => $ slug , ] ) ; update_term_meta ( $ results [ 'term_id' ] , 'contributor_first_name' , $ user -> first_name ) ; update_term_meta ( $ results [ 'term_id' ] , 'contributor_last_name' , $ user -> last_name ) ; } else { $ results = wp_insert_term ( $ name , self :: TAXONOMY , [ 'slug' => $ slug , ] ) ; add_term_meta ( $ results [ 'term_id' ] , 'contributor_first_name' , $ user -> first_name , true ) ; add_term_meta ( $ results [ 'term_id' ] , 'contributor_last_name' , $ user -> last_name , true ) ; } if ( is_array ( $ results ) ) { return $ results ; } } return false ; }
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_name' , true ) ; if ( ! empty ( $ first_name ) && ! empty ( $ last_name ) ) { $ name = "{$first_name} {$last_name}" ; } elseif ( ! empty ( $ term -> name ) ) { $ name = $ term -> name ; } } return $ name ; }
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 ( $ _section , $ this -> getTitle ( ) , [ $ this , 'display' ] , $ _page ) ; add_settings_field ( 'social_media' , __ ( 'Enable Social Media' , 'pressbooks' ) , [ $ this , 'renderSocialMediaField' ] , $ _page , $ _section , [ __ ( 'Add buttons to cover page and each chapter so that readers may share links to your book through social media: Facebook, Twitter, Google+' , 'pressbooks' ) , ] ) ; add_settings_field ( 'webbook_width' , __ ( 'Webbook Width' , 'pressbooks' ) , [ $ this , 'renderWebbookWidthField' ] , $ _page , $ _section , [ '30em' => __ ( 'Narrow' , 'pressbooks' ) , '40em' => __ ( 'Standard' , 'pressbooks' ) , '48em' => __ ( 'Wide' , 'pressbooks' ) , 'label_for' => 'webbook_width' , ] ) ; add_settings_field ( 'paragraph_separation' , __ ( 'Paragraph Separation' , 'pressbooks' ) , [ $ this , 'renderParagraphSeparationField' ] , $ _page , $ _section , [ 'indent' => __ ( 'Indent paragraphs' , 'pressbooks' ) , 'skiplines' => __ ( 'Skip lines between paragraphs' , 'pressbooks' ) , ] ) ; add_settings_field ( 'part_title' , __ ( 'Display Part Title' , 'pressbooks' ) , [ $ this , 'renderPartTitle' ] , $ _page , $ _section , [ __ ( 'Display the Part title on each chapter' , 'pressbooks' ) , ] ) ; if ( Container :: get ( 'Styles' ) -> hasBuckram ( ) ) { add_settings_field ( 'collapse_sections' , __ ( 'Collapse Sections' , 'pressbooks' ) , [ $ this , 'renderCollapseSections' ] , $ _page , $ _section , [ __ ( 'Collapse sections within front matter, chapters, and back matter' , 'pressbooks' ) , ] ) ; } if ( get_post_meta ( $ meta -> getMetaPostId ( ) , 'pb_is_based_on' , true ) ) { add_settings_field ( 'enable_source_comparison' , __ ( 'Enable Source Comparison' , 'pressbooks' ) , [ $ this , 'renderEnableSourceComparison' ] , $ _page , $ _section , [ __ ( 'Add comparison tool to the end of each front matter, part, chapter, and back matter' , 'pressbooks' ) , __ ( 'Allows readers to compare content with the original book from which it was cloned.' , 'pressbooks' ) , ] ) ; } do_action ( 'pb_theme_options_web_add_settings_fields' , $ _page , $ _section ) ; register_setting ( $ _page , $ _option , [ $ this , 'sanitize' ] ) ; }
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 ) ) { unset ( $ options [ $ key ] ) ; } } update_option ( 'pressbooks_theme_options_' . $ _option , $ options ) ; }
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 -> options [ 'social_media' ] : '' , 'label' => $ args [ 0 ] , ] ) ; }
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 -> options [ 'webbook_width' ] : $ this -> defaults [ 'webbook_width' ] , 'choices' => $ args , ] ) ; }
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 [ 'part_title' ] : '' , 'label' => $ args [ 0 ] , ] ) ; }
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' ] ) ) ? $ this -> options [ 'collapse_sections' ] : '' , 'label' => $ args [ 0 ] , ] ) ; }
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 [ 'enable_source_comparison' ] ) ) ? $ this -> options [ 'enable_source_comparison' ] : '' , 'label' => $ args [ 0 ] , 'description' => $ args [ 1 ] , ] ) ; }
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_content ; } $ css = $ styles -> customize ( 'prince' , $ scss , $ this -> cssOverrides ) ; $ css = normalize_css_urls ( $ css , $ this -> urlPath ( ) ) ; if ( WP_DEBUG ) { Container :: get ( 'Sass' ) -> debug ( $ css , $ scss , 'prince' ) ; } return $ css ; }
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 ; } if ( $ fix ) { $ this -> url .= '&pb-latex-zoom=3' ; $ this -> cssOverrides .= "\n" . 'img.latex { prince-image-resolution: 300dpi; }' . "\n" ; } }
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 WHERE {$this->dbLinkTable}.users_id = %d AND {$this->dbLinkTable}.tags_group = %d AND {$this->dbLinkTable}.tags_id = %d AND {$this->dbTable}.deleted = 0 " ; return $ wpdb -> get_results ( $ wpdb -> prepare ( $ sql , $ this -> userId , $ tag_group , $ tag_id ) , ARRAY_A ) ; }
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' => $ this -> dbColumns [ 'blogs_id' ] , 'deleted' => $ this -> dbColumns [ 'deleted' ] , ] ; foreach ( $ item as $ key => $ val ) { if ( isset ( $ this -> dbColumns [ $ key ] ) ) { $ data [ $ key ] = $ val ; $ format [ $ key ] = $ this -> dbColumns [ $ key ] ; } } $ args = [ ] ; $ sql = "INSERT INTO {$this->dbTable} ( " ; foreach ( $ data as $ key => $ val ) { $ sql .= "`$key`, " ; } $ sql = rtrim ( $ sql , ', ' ) . ' ) VALUES ( ' ; foreach ( $ format as $ key => $ val ) { $ sql .= $ val . ', ' ; $ args [ ] = $ data [ $ key ] ; } $ sql = rtrim ( $ sql , ', ' ) . ' ) ON DUPLICATE KEY UPDATE ' ; $ i = 0 ; foreach ( $ data as $ key => $ val ) { if ( 'users_id' === $ key || 'blogs_id' === $ key ) { continue ; } $ sql .= "`$key` = {$format[$key]}, " ; $ args [ ] = $ val ; ++ $ i ; } $ sql = rtrim ( $ sql , ', ' ) ; if ( ! $ i ) { $ sql .= ' users_id = users_id ' ; } return $ wpdb -> query ( $ wpdb -> prepare ( $ sql , $ args ) ) ; }
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}.users_id = {$this->dbLinkTable}.users_id AND {$this->dbTable}.blogs_id = {$this->dbLinkTable}.blogs_id WHERE {$this->dbLinkTable}.tags_group = %d AND {$this->dbLinkTable}.users_id = %d AND {$this->dbLinkTable}.blogs_id = %d ORDER BY {$this->dbTagsTable}.tag ASC " ; return $ wpdb -> get_results ( $ wpdb -> prepare ( $ sql , $ tag_group , $ this -> userId , $ blog_id ) , ARRAY_A ) ; }
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 -> delete ( $ this -> dbLinkTable , [ 'tags_id' => $ tag_id , ] , [ '%d' ] ) ; $ wpdb -> delete ( $ this -> dbTagsTable , [ 'id' => $ tag_id , ] , [ '%d' ] ) ; $ result = 1 ; } else { $ result = $ wpdb -> delete ( $ this -> dbLinkTable , [ 'users_id' => $ this -> userId , 'blogs_id' => $ blog_id , 'tags_id' => $ tag_id , 'tags_group' => $ tag_group , ] , [ '%d' , '%d' , '%d' , '%d' ] ) ; } return $ result ; }
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' === $ this -> profileMetaKeys [ $ key ] ) { $ val = ( int ) $ val ; } elseif ( '%f' === $ this -> profileMetaKeys [ $ key ] ) { $ val = ( float ) $ val ; } else { $ val = ( string ) $ val ; } update_user_meta ( $ this -> userId , $ key , $ val ) ; } }
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_id), KEY featured (featured) ); " ; dbDelta ( $ sql ) ; $ sql = "CREATE TABLE {$this->dbLinkTable} ( users_id INT(11) NOT null, blogs_id INT(11) NOT null, tags_id INT(11) NOT null, tags_group INT(3) NOT null, PRIMARY KEY (users_id,blogs_id,tags_id,tags_group) ); " ; dbDelta ( $ sql ) ; $ sql = "CREATE TABLE {$this->dbTagsTable} ( id INT(11) NOT null AUTO_INCREMENT, users_id INT(11) NOT null, tag VARCHAR(200) NOT null, PRIMARY KEY (id), UNIQUE KEY tag (tag(191)) ); " ; dbDelta ( $ sql ) ; }
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 ) { unset ( $ tags [ $ key ] ) ; } } return $ tags ; }
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 ) ; restore_current_blog ( ) ; } return $ image_url ; }
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' ) ) { return true ; } return false ; }
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 false ; } return ( $ action === $ compare ) ; }
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 ) ; $ old_id = \ Pressbooks \ Image \ attachment_id_from_url ( $ image_url ) ; if ( $ old_id ) { wp_delete_attachment ( $ old_id , true ) ; } update_user_meta ( $ user_id , 'pb_catalog_logo' , \ Pressbooks \ Image \ default_cover_url ( ) ) ; restore_current_blog ( ) ; } die ( ) ; }
WP_Ajax hook for pb_delete_catalog_logo