idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
60,300 | protected function importPbPostMeta ( $ pid , $ p ) { $ data_model = $ this -> figureOutDataModel ( $ p [ 'postmeta' ] ) ; $ meta_to_update = apply_filters ( 'pb_import_metakeys' , [ 'pb_section_license' , 'pb_short_title' , 'pb_subtitle' , 'pb_show_title' ] ) ; foreach ( $ meta_to_update as $ meta_key ) { $ meta_val = $ this -> searchForMetaValue ( $ meta_key , $ p [ 'postmeta' ] ) ; if ( $ meta_val ) { update_post_meta ( $ pid , $ meta_key , $ meta_val ) ; if ( $ meta_key === 'pb_section_license' ) { wp_set_object_terms ( $ pid , $ meta_val , Licensing :: TAXONOMY ) ; } } } if ( $ data_model === 5 ) { $ meta_val = $ this -> searchForMetaValue ( 'pb_authors' , $ p [ 'postmeta' ] ) ; if ( $ meta_val ) { add_post_meta ( $ pid , 'pb_authors' , $ meta_val ) ; wp_set_object_terms ( $ pid , $ meta_val , Contributors :: TAXONOMY ) ; } } else { $ meta_val = $ this -> searchForMetaValue ( 'pb_section_author' , $ p [ 'postmeta' ] ) ; if ( $ meta_val ) { $ this -> contributors -> convert ( 'pb_section_author' , $ meta_val , $ pid ) ; } } } | Import Pressbooks specific post meta |
60,301 | protected function searchForMetaValue ( $ meta_key , array $ postmeta ) { if ( empty ( $ postmeta ) ) { return '' ; } foreach ( $ postmeta as $ meta ) { if ( $ meta_key === $ meta [ 'key' ] ) { $ meta_val = $ meta [ 'value' ] ; if ( is_serialized ( $ meta_val ) ) { $ meta_val = unserialize ( $ meta_val ) ; if ( is_object ( $ meta_val ) ) { $ meta_val = '' ; } } return $ meta_val ; } } return '' ; } | Check for PB specific metadata returns empty string if not found . |
60,302 | public function buildListOfKnownMedia ( $ xml ) { $ known_media = [ ] ; foreach ( $ xml [ 'posts' ] as $ item ) { if ( $ item [ 'post_type' ] !== 'attachment' ) { continue ; } $ x = [ ] ; foreach ( $ item [ 'postmeta' ] as $ meta ) { if ( $ meta [ 'key' ] === '_wp_attachment_metadata' ) { $ x = maybe_unserialize ( $ meta [ 'value' ] ) ; break ; } } if ( ! is_array ( $ x ) || empty ( $ x ) ) { continue ; } $ m = $ this -> createMediaEntity ( $ item ) ; if ( preg_match ( $ this -> downloads -> getPregSupportedImageExtensions ( ) , $ m -> sourceUrl ) ) { $ prefix = str_replace ( $ this -> downloads -> basename ( $ m -> sourceUrl ) , '' , $ x [ 'file' ] ) ; foreach ( $ x [ 'sizes' ] as $ size => $ info ) { $ attached_file = $ prefix . $ info [ 'file' ] ; $ known_media [ $ attached_file ] = $ m ; } } else { $ attached_file = media_strip_baseurl ( $ m -> sourceUrl ) ; $ known_media [ $ attached_file ] = $ m ; } } return $ known_media ; } | Parse XML to build an array of known images |
60,303 | protected function fixInternalShortcodes ( ) { $ fix = function ( $ post_id , $ transition_type , $ shortcode ) { $ replace_pairs = [ ] ; $ post = get_post ( $ post_id ) ; foreach ( $ this -> transitions as $ transition ) { if ( $ transition -> type === $ transition_type ) { $ md5 = md5 ( $ transition -> oldId . $ transition -> newId . rand ( ) ) ; $ to = "<!-- pb_fixme_{$md5} ; $ replace_pairs [ $ to ] = $ transition -> newId ; $ post -> post_content = \ Pressbooks \ Utility \ shortcode_att_replace ( $ post -> post_content , $ shortcode , 'id' , $ transition -> oldId , $ to ) ; } } if ( ! empty ( $ replace_pairs ) ) { $ post -> post_content = strtr ( $ post -> post_content , $ replace_pairs ) ; wp_update_post ( $ post ) ; } } ; foreach ( $ this -> postsWithGlossaryShortcodesToFix as $ post_id ) { $ fix ( $ post_id , 'glossary' , \ Pressbooks \ Shortcodes \ Glossary \ Glossary :: SHORTCODE ) ; } foreach ( $ this -> postsWithAttachmentsShortcodesToFix as $ post_id ) { $ fix ( $ post_id , 'attachment' , \ Pressbooks \ Shortcodes \ Attributions \ Attachments :: SHORTCODE ) ; } } | Fix shortcodes with references to internal IDs |
60,304 | protected function paramSearchMeta ( array $ search ) { $ request_metadata = new \ WP_REST_Request ( 'GET' , '/pressbooks/v2/metadata' ) ; $ response_metadata = rest_do_request ( $ request_metadata ) ; $ book_metadata = $ response_metadata -> get_data ( ) ; if ( $ this -> keyValueSearchInMeta ( $ search , $ book_metadata ) ) { return true ; } $ request_metadata = new \ WP_REST_Request ( 'GET' , '/pressbooks/v2/toc' ) ; $ response_metadata = rest_do_request ( $ request_metadata ) ; $ toc = $ response_metadata -> get_data ( ) ; foreach ( $ toc [ 'front-matter' ] as $ fm ) { if ( $ this -> keyValueSearchInMeta ( $ search , $ fm [ 'metadata' ] ) ) { return true ; } } foreach ( $ toc [ 'parts' ] as $ p ) { foreach ( $ p [ 'chapters' ] as $ ch ) { if ( $ this -> keyValueSearchInMeta ( $ search , $ ch [ 'metadata' ] ) ) { return true ; } } } foreach ( $ toc [ 'back-matter' ] as $ bm ) { if ( $ this -> keyValueSearchInMeta ( $ search , $ bm [ 'metadata' ] ) ) { return true ; } } return false ; } | Parameter based search |
60,305 | function addOptions ( ) { if ( is_array ( $ this -> options ) ) extract ( $ this -> options , EXTR_SKIP ) ; global $ themecolors ; if ( empty ( $ bg ) ) $ bg = isset ( $ themecolors [ 'bg' ] ) ? $ themecolors [ 'bg' ] : 'transparent' ; if ( empty ( $ fg ) ) $ fg = isset ( $ themecolors [ 'text' ] ) ? $ themecolors [ 'text' ] : '000000' ; if ( empty ( $ method ) ) $ method = 'Automattic_Latex_WPCOM' ; if ( empty ( $ css ) ) $ css = 'img.latex { vertical-align: middle; border: none; background: none; }' ; if ( empty ( $ wrapper ) ) $ wrapper = false ; $ this -> options = compact ( 'bg' , 'fg' , 'method' , 'css' , 'wrapper' ) ; update_option ( 'pb_latex' , $ this -> options ) ; } | Sets up default options |
60,306 | public function invocation ( $ sku , $ not_used_1 , $ not_used_2 , $ text_font , $ text_size ) { $ ps [ ] = "50 50 moveto ({$sku}) (includetext textfont={$text_font} textsize={$text_size} height=0.5)" ; $ ps [ ] = '/code128 /uk.co.terryburton.bwipp findresource exec' ; return implode ( "\n" , $ ps ) . "\n" ; } | SKU Invocation Code . |
60,307 | public function compile ( $ path_to_ps ) { if ( empty ( $ this -> sku ) ) { throw new \ LogicException ( '$this->sku is not set' ) ; } $ sku = \ Pressbooks \ Utility \ get_contents ( PB_PLUGIN_DIR . 'symbionts/postscriptbarcode/code128.ps' ) ; $ invocation = $ this -> invocation ( $ this -> sku , null , null , $ this -> textFont , $ this -> textSize ) ; file_put_contents ( $ path_to_ps , $ sku ) ; file_put_contents ( $ path_to_ps , $ invocation , FILE_APPEND | LOCK_EX ) ; file_put_contents ( $ path_to_ps , ( "\n" . 'showpage' ) , FILE_APPEND | LOCK_EX ) ; } | Compile a SKU Postscript file |
60,308 | public function lockTheme ( ) { if ( true === $ this -> copyAssets ( ) ) { $ time = time ( ) ; $ data = $ this -> generateLock ( $ time ) ; $ _SESSION [ 'pb_notices' ] [ ] = sprintf ( '<strong>%s</strong>' , sprintf ( __ ( 'Your book’s theme, %1$s, has been locked in its current state as of %2$s at %3$s.' , 'pressbooks' ) , $ data [ 'name' ] , strftime ( '%x' , $ data [ 'timestamp' ] ) , strftime ( '%X' , $ data [ 'timestamp' ] ) ) ) ; return $ data ; } else { $ option = get_option ( 'pressbooks_export_options' ) ; unset ( $ option [ 'theme_lock' ] ) ; update_option ( 'pressbooks_export_options' , $ option ) ; $ _SESSION [ 'pb_errors' ] [ ] = sprintf ( '<strong>%s</strong>' , __ ( 'Your book’s theme could not be locked. Please ensure that you have write access to the uploads directory.' , 'pressbooks' ) ) ; } return false ; } | Lock the current theme by copying assets to the lock directory and generating a timestamped lockfile . |
60,309 | public function isLocked ( ) { $ options = get_option ( 'pressbooks_export_options' ) ; if ( realpath ( $ this -> getLockDir ( false ) . '/lock.json' ) && isset ( $ options [ 'theme_lock' ] ) && 1 === absint ( $ options [ 'theme_lock' ] ) ) { return true ; } return false ; } | Check for a lockfile . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.