repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
pressbooks/pressbooks | inc/modules/export/odt/class-odt.php | Odt.validate | function validate() {
// Is this an ODT?
if ( ! $this->isOdt( $this->outputPath ) ) {
$this->logError( \Pressbooks\Utility\get_contents( $this->logfile ) );
return false;
}
return true;
} | php | function validate() {
// Is this an ODT?
if ( ! $this->isOdt( $this->outputPath ) ) {
$this->logError( \Pressbooks\Utility\get_contents( $this->logfile ) );
return false;
}
return true;
} | [
"function",
"validate",
"(",
")",
"{",
"// Is this an ODT?",
"if",
"(",
"!",
"$",
"this",
"->",
"isOdt",
"(",
"$",
"this",
"->",
"outputPath",
")",
")",
"{",
"$",
"this",
"->",
"logError",
"(",
"\\",
"Pressbooks",
"\\",
"Utility",
"\\",
"get_contents",
... | Check the sanity of $this->outputPath
@return bool | [
"Check",
"the",
"sanity",
"of",
"$this",
"-",
">",
"outputPath"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/odt/class-odt.php#L257-L268 |
pressbooks/pressbooks | inc/modules/export/odt/class-odt.php | Odt.fetchAndSaveUniqueImage | protected function fetchAndSaveUniqueImage( $url, $fullpath ) {
// Cheap cache
static $already_done = [];
if ( isset( $already_done[ $url ] ) ) {
return $already_done[ $url ];
}
$response = wp_remote_get(
$url, [
'timeout' => $this->timeout,
]
);
// WordPress error?
if ( is_wp_error( $re... | php | protected function fetchAndSaveUniqueImage( $url, $fullpath ) {
// Cheap cache
static $already_done = [];
if ( isset( $already_done[ $url ] ) ) {
return $already_done[ $url ];
}
$response = wp_remote_get(
$url, [
'timeout' => $this->timeout,
]
);
// WordPress error?
if ( is_wp_error( $re... | [
"protected",
"function",
"fetchAndSaveUniqueImage",
"(",
"$",
"url",
",",
"$",
"fullpath",
")",
"{",
"// Cheap cache",
"static",
"$",
"already_done",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"already_done",
"[",
"$",
"url",
"]",
")",
")",
"{",
... | Fetch an image with wp_remote_get(), save it to $fullpath with a unique name.
Will return an empty string if something went wrong.
@param $url string
@param $fullpath string
@return string filename | [
"Fetch",
"an",
"image",
"with",
"wp_remote_get",
"()",
"save",
"it",
"to",
"$fullpath",
"with",
"a",
"unique",
"name",
".",
"Will",
"return",
"an",
"empty",
"string",
"if",
"something",
"went",
"wrong",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/odt/class-odt.php#L308-L380 |
pressbooks/pressbooks | inc/modules/export/odt/class-odt.php | Odt.deleteTmpDir | protected function deleteTmpDir() {
// Cleanup temporary directory, if any
if ( ! empty( $this->tmpDir ) ) {
\Pressbooks\Utility\rmrdir( $this->tmpDir );
}
// Cleanup deprecated junk, if any
$exports_folder = untrailingslashit( pathinfo( $this->outputPath, PATHINFO_DIRNAME ) );
if ( ! empty( $exports_fol... | php | protected function deleteTmpDir() {
// Cleanup temporary directory, if any
if ( ! empty( $this->tmpDir ) ) {
\Pressbooks\Utility\rmrdir( $this->tmpDir );
}
// Cleanup deprecated junk, if any
$exports_folder = untrailingslashit( pathinfo( $this->outputPath, PATHINFO_DIRNAME ) );
if ( ! empty( $exports_fol... | [
"protected",
"function",
"deleteTmpDir",
"(",
")",
"{",
"// Cleanup temporary directory, if any",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"tmpDir",
")",
")",
"{",
"\\",
"Pressbooks",
"\\",
"Utility",
"\\",
"rmrdir",
"(",
"$",
"this",
"->",
"tmpDir",... | Delete temporary directories | [
"Delete",
"temporary",
"directories"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/odt/class-odt.php#L385-L396 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.getProperties | protected function getProperties( $html_file ) {
$html = \Pressbooks\Utility\get_contents( $html_file );
$properties = [];
if ( empty( $html ) ) {
throw new \Exception( 'File contents empty for getProperties' );
}
if ( $this->isMathML( $html ) ) {
$properties['mathml'] = 1;
}
if ( $this->isScrip... | php | protected function getProperties( $html_file ) {
$html = \Pressbooks\Utility\get_contents( $html_file );
$properties = [];
if ( empty( $html ) ) {
throw new \Exception( 'File contents empty for getProperties' );
}
if ( $this->isMathML( $html ) ) {
$properties['mathml'] = 1;
}
if ( $this->isScrip... | [
"protected",
"function",
"getProperties",
"(",
"$",
"html_file",
")",
"{",
"$",
"html",
"=",
"\\",
"Pressbooks",
"\\",
"Utility",
"\\",
"get_contents",
"(",
"$",
"html_file",
")",
";",
"$",
"properties",
"=",
"[",
"]",
";",
"if",
"(",
"empty",
"(",
"$"... | Check for existence of properties attributes
@param string $html_file
@return array $properties
@throws \Exception | [
"Check",
"for",
"existence",
"of",
"properties",
"attributes"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L189-L209 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.isMathML | protected function isMathML( $html ) {
foreach ( $this->MathMLTags as $tag ) {
if ( false !== stripos( $html, "<$tag>" ) ) {
return true;
}
}
return false;
} | php | protected function isMathML( $html ) {
foreach ( $this->MathMLTags as $tag ) {
if ( false !== stripos( $html, "<$tag>" ) ) {
return true;
}
}
return false;
} | [
"protected",
"function",
"isMathML",
"(",
"$",
"html",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"MathMLTags",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"false",
"!==",
"stripos",
"(",
"$",
"html",
",",
"\"<$tag>\"",
")",
")",
"{",
"return",
"true",
... | Check for existence of scripting MathML elements
@param string $html
@return bool | [
"Check",
"for",
"existence",
"of",
"scripting",
"MathML",
"elements"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L218-L227 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.isScripted | protected function isScripted( $html ) {
if ( preg_match( '/<script[^>]*>.*?<\/script>/is', $html ) ) {
return true;
}
try {
$html5 = new HtmlParser( true );
$doc = $html5->loadHTML( $html );
foreach ( $doc->getElementsByTagname( '*' ) as $element ) {
foreach ( iterator_to_array( $element->attri... | php | protected function isScripted( $html ) {
if ( preg_match( '/<script[^>]*>.*?<\/script>/is', $html ) ) {
return true;
}
try {
$html5 = new HtmlParser( true );
$doc = $html5->loadHTML( $html );
foreach ( $doc->getElementsByTagname( '*' ) as $element ) {
foreach ( iterator_to_array( $element->attri... | [
"protected",
"function",
"isScripted",
"(",
"$",
"html",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/<script[^>]*>.*?<\\/script>/is'",
",",
"$",
"html",
")",
")",
"{",
"return",
"true",
";",
"}",
"try",
"{",
"$",
"html5",
"=",
"new",
"HtmlParser",
"(",
"t... | Check for existence of scripting elements
@param string $html
@return bool | [
"Check",
"for",
"existence",
"of",
"scripting",
"elements"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L237-L258 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.tidy | protected function tidy( $html ) {
// Venn diagram join between XTHML + HTML5 Deprecated Attributes
//
// Our $spec is artisanally hand crafted based on squinting very hard while reading the following docs:
//
// + 2.3 - Extra HTML specifications using the $spec parameter
// + 3.4.6 - Transformation of ... | php | protected function tidy( $html ) {
// Venn diagram join between XTHML + HTML5 Deprecated Attributes
//
// Our $spec is artisanally hand crafted based on squinting very hard while reading the following docs:
//
// + 2.3 - Extra HTML specifications using the $spec parameter
// + 3.4.6 - Transformation of ... | [
"protected",
"function",
"tidy",
"(",
"$",
"html",
")",
"{",
"// Venn diagram join between XTHML + HTML5 Deprecated Attributes",
"//",
"// Our $spec is artisanally hand crafted based on squinting very hard while reading the following docs:",
"//",
"// + 2.3 - Extra HTML specifications using... | Tidy HTML
@param string $html
@return string | [
"Tidy",
"HTML"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L267-L325 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.fetchAndSaveUniqueMedia | protected function fetchAndSaveUniqueMedia( $url, $fullpath ) {
if ( isset( $this->fetchedMediaCache[ $url ] ) ) {
return $this->fetchedMediaCache[ $url ];
}
$response = wp_remote_get(
$url, [
'timeout' => $this->timeout,
]
);
// WordPress error?
if ( is_wp_error( $response ) ) {
try {
... | php | protected function fetchAndSaveUniqueMedia( $url, $fullpath ) {
if ( isset( $this->fetchedMediaCache[ $url ] ) ) {
return $this->fetchedMediaCache[ $url ];
}
$response = wp_remote_get(
$url, [
'timeout' => $this->timeout,
]
);
// WordPress error?
if ( is_wp_error( $response ) ) {
try {
... | [
"protected",
"function",
"fetchAndSaveUniqueMedia",
"(",
"$",
"url",
",",
"$",
"fullpath",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fetchedMediaCache",
"[",
"$",
"url",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fetchedMediaCache",
"... | Fetch a url with wp_remote_get(), save it to $fullpath with a unique name.
Will return an empty string if something went wrong.
@param string $url
@param string $fullpath
@return string|array | [
"Fetch",
"a",
"url",
"with",
"wp_remote_get",
"()",
"save",
"it",
"to",
"$fullpath",
"with",
"a",
"unique",
"name",
".",
"Will",
"return",
"an",
"empty",
"string",
"if",
"something",
"went",
"wrong",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L336-L406 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.scrapeAndKneadMedia | protected function scrapeAndKneadMedia( \DOMDocument $doc ) {
$fullpath = $this->tmpDir . '/OEBPS/assets';
$tags = [ 'source', 'audio', 'video' ];
foreach ( $tags as $tag ) {
$sources = $doc->getElementsByTagName( $tag );
foreach ( $sources as $source ) {
/** @var $source \DOMElement */
if ( ! em... | php | protected function scrapeAndKneadMedia( \DOMDocument $doc ) {
$fullpath = $this->tmpDir . '/OEBPS/assets';
$tags = [ 'source', 'audio', 'video' ];
foreach ( $tags as $tag ) {
$sources = $doc->getElementsByTagName( $tag );
foreach ( $sources as $source ) {
/** @var $source \DOMElement */
if ( ! em... | [
"protected",
"function",
"scrapeAndKneadMedia",
"(",
"\\",
"DOMDocument",
"$",
"doc",
")",
"{",
"$",
"fullpath",
"=",
"$",
"this",
"->",
"tmpDir",
".",
"'/OEBPS/assets'",
";",
"$",
"tags",
"=",
"[",
"'source'",
",",
"'audio'",
",",
"'video'",
"]",
";",
"... | Parse HTML snippet, download all found <audio>, <video> and <source> tags
into /OEBPS/assets/, return the HTML with changed 'src' paths.
@param \DOMDocument $doc
@return \DOMDocument | [
"Parse",
"HTML",
"snippet",
"download",
"all",
"found",
"<audio",
">",
"<video",
">",
"and",
"<source",
">",
"tags",
"into",
"/",
"OEBPS",
"/",
"assets",
"/",
"return",
"the",
"HTML",
"with",
"changed",
"src",
"paths",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L416-L443 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.createOPF | protected function createOPF( $book_contents, $metadata ) {
if ( empty( $this->manifest ) ) {
throw new \Exception( '$this->manifest cannot be empty. Did you forget to call $this->createOEBPS() ?' );
}
$vars = [
'manifest' => $this->manifest,
'stylesheet' => $this->stylesheet,
'lang' => $this->lang,... | php | protected function createOPF( $book_contents, $metadata ) {
if ( empty( $this->manifest ) ) {
throw new \Exception( '$this->manifest cannot be empty. Did you forget to call $this->createOEBPS() ?' );
}
$vars = [
'manifest' => $this->manifest,
'stylesheet' => $this->stylesheet,
'lang' => $this->lang,... | [
"protected",
"function",
"createOPF",
"(",
"$",
"book_contents",
",",
"$",
"metadata",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"manifest",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'$this->manifest cannot be empty. Did you forget to c... | Create OPF File.
@param array $book_contents
@param array $metadata
@throws \Exception | [
"Create",
"OPF",
"File",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L453-L494 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.createNCX | protected function createNCX( $book_contents, $metadata ) {
if ( empty( $this->manifest ) ) {
throw new \Exception( '$this->manifest cannot be empty. Did you forget to call $this->createOEBPS() ?' );
}
// Sanitize variables for usage in XML template
$vars = [
'author' => ! \Pressbooks\Utility\empty_spac... | php | protected function createNCX( $book_contents, $metadata ) {
if ( empty( $this->manifest ) ) {
throw new \Exception( '$this->manifest cannot be empty. Did you forget to call $this->createOEBPS() ?' );
}
// Sanitize variables for usage in XML template
$vars = [
'author' => ! \Pressbooks\Utility\empty_spac... | [
"protected",
"function",
"createNCX",
"(",
"$",
"book_contents",
",",
"$",
"metadata",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"manifest",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'$this->manifest cannot be empty. Did you forget to c... | Create NCX file.
@param array $book_contents
@param array $metadata
@throws \Exception | [
"Create",
"NCX",
"file",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L504-L529 |
pressbooks/pressbooks | inc/modules/export/epub/class-epub3.php | Epub3.loadTemplate | protected function loadTemplate( $path, array $vars = [] ) {
$search = '/templates/epub201/';
$replace = '/templates/epub3/';
$pos = strpos( $path, $search );
if ( false !== $pos ) {
$new_path = substr_replace( $path, $replace, $pos, strlen( $search ) );
if ( file_exists( $new_path ) ) {
$path = $ne... | php | protected function loadTemplate( $path, array $vars = [] ) {
$search = '/templates/epub201/';
$replace = '/templates/epub3/';
$pos = strpos( $path, $search );
if ( false !== $pos ) {
$new_path = substr_replace( $path, $replace, $pos, strlen( $search ) );
if ( file_exists( $new_path ) ) {
$path = $ne... | [
"protected",
"function",
"loadTemplate",
"(",
"$",
"path",
",",
"array",
"$",
"vars",
"=",
"[",
"]",
")",
"{",
"$",
"search",
"=",
"'/templates/epub201/'",
";",
"$",
"replace",
"=",
"'/templates/epub3/'",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"path",... | Override load template function
Switch path from /epub201 to /epub3 when possible.
@param string $path
@param array $vars (optional)
@return string
@throws \Exception | [
"Override",
"load",
"template",
"function",
"Switch",
"path",
"from",
"/",
"epub201",
"to",
"/",
"epub3",
"when",
"possible",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/export/epub/class-epub3.php#L542-L556 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.register_routes | public function register_routes() {
register_rest_route(
$this->namespace, '/' . $this->rest_base, [
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'get_items' ],
'permission_callback' => [ $this, 'get_items_permissions_check' ],
'args' => $this->get_collection_params(),
... | php | public function register_routes() {
register_rest_route(
$this->namespace, '/' . $this->rest_base, [
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'get_items' ],
'permission_callback' => [ $this, 'get_items_permissions_check' ],
'args' => $this->get_collection_params(),
... | [
"public",
"function",
"register_routes",
"(",
")",
"{",
"register_rest_route",
"(",
"$",
"this",
"->",
"namespace",
",",
"'/'",
".",
"$",
"this",
"->",
"rest_base",
",",
"[",
"[",
"'methods'",
"=>",
"\\",
"WP_REST_Server",
"::",
"READABLE",
",",
"'callback'"... | Registers routes for Books | [
"Registers",
"routes",
"for",
"Books"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L63-L99 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.get_item_permissions_check | public function get_item_permissions_check( $request ) {
if ( $request['id'] === get_network()->site_id ) {
return false;
}
$allowed = false;
switch_to_blog( $request['id'] );
if ( 1 === absint( get_option( 'blog_public' ) ) ) {
$allowed = true;
}
restore_current_blog();
return $allowed;
} | php | public function get_item_permissions_check( $request ) {
if ( $request['id'] === get_network()->site_id ) {
return false;
}
$allowed = false;
switch_to_blog( $request['id'] );
if ( 1 === absint( get_option( 'blog_public' ) ) ) {
$allowed = true;
}
restore_current_blog();
return $allowed;
} | [
"public",
"function",
"get_item_permissions_check",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"[",
"'id'",
"]",
"===",
"get_network",
"(",
")",
"->",
"site_id",
")",
"{",
"return",
"false",
";",
"}",
"$",
"allowed",
"=",
"false",
";",
"... | @param \WP_REST_Request $request
@return bool | [
"@param",
"\\",
"WP_REST_Request",
"$request"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L180-L197 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.get_items | public function get_items( $request ) {
// Register missing routes
$this->registerRouteDependencies();
if ( ! empty( $request['search'] ) ) {
$response = rest_ensure_response( $this->searchBooks( $request ) );
$this->addNextSearchLinks( $request, $response );
} else {
$response = rest_ensure_response... | php | public function get_items( $request ) {
// Register missing routes
$this->registerRouteDependencies();
if ( ! empty( $request['search'] ) ) {
$response = rest_ensure_response( $this->searchBooks( $request ) );
$this->addNextSearchLinks( $request, $response );
} else {
$response = rest_ensure_response... | [
"public",
"function",
"get_items",
"(",
"$",
"request",
")",
"{",
"// Register missing routes",
"$",
"this",
"->",
"registerRouteDependencies",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"[",
"'search'",
"]",
")",
")",
"{",
"$",
"response... | @param \WP_REST_Request $request
@return \WP_REST_Response | [
"@param",
"\\",
"WP_REST_Request",
"$request"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L204-L218 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.get_item | public function get_item( $request ) {
// Register missing routes
$this->registerRouteDependencies();
$result = $this->renderBook( $request['id'] );
$response = rest_ensure_response( $result );
$response->add_links( $this->linkCollector );
return $response;
} | php | public function get_item( $request ) {
// Register missing routes
$this->registerRouteDependencies();
$result = $this->renderBook( $request['id'] );
$response = rest_ensure_response( $result );
$response->add_links( $this->linkCollector );
return $response;
} | [
"public",
"function",
"get_item",
"(",
"$",
"request",
")",
"{",
"// Register missing routes",
"$",
"this",
"->",
"registerRouteDependencies",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"renderBook",
"(",
"$",
"request",
"[",
"'id'",
"]",
")",
"... | @param \WP_REST_Request $request
@return \WP_REST_Response | [
"@param",
"\\",
"WP_REST_Request",
"$request"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L225-L235 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.renderBook | protected function renderBook( $id, $search = null ) {
switch_to_blog( $id );
// Search
if ( ! empty( $search ) ) {
if ( ! $this->find( $search ) ) {
restore_current_blog();
return [];
}
}
$request_metadata = new \WP_REST_Request( 'GET', '/pressbooks/v2/metadata' );
$response_metadata = res... | php | protected function renderBook( $id, $search = null ) {
switch_to_blog( $id );
// Search
if ( ! empty( $search ) ) {
if ( ! $this->find( $search ) ) {
restore_current_blog();
return [];
}
}
$request_metadata = new \WP_REST_Request( 'GET', '/pressbooks/v2/metadata' );
$response_metadata = res... | [
"protected",
"function",
"renderBook",
"(",
"$",
"id",
",",
"$",
"search",
"=",
"null",
")",
"{",
"switch_to_blog",
"(",
"$",
"id",
")",
";",
"// Search",
"if",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"-... | Switches to a book, renders it for use in JSON response if found
@param int $id
@param mixed $search (optional)
@return array | [
"Switches",
"to",
"a",
"book",
"renders",
"it",
"for",
"use",
"in",
"JSON",
"response",
"if",
"found"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L272-L323 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.listBooks | protected function listBooks( $request ) {
$results = [];
$book_ids = $this->listBookIds( $request );
foreach ( $book_ids as $id ) {
$response = rest_ensure_response( $this->renderBook( $id ) );
$response->add_links( $this->linkCollector );
$results[] = $this->prepare_response_for_collection( $response )... | php | protected function listBooks( $request ) {
$results = [];
$book_ids = $this->listBookIds( $request );
foreach ( $book_ids as $id ) {
$response = rest_ensure_response( $this->renderBook( $id ) );
$response->add_links( $this->linkCollector );
$results[] = $this->prepare_response_for_collection( $response )... | [
"protected",
"function",
"listBooks",
"(",
"$",
"request",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"$",
"book_ids",
"=",
"$",
"this",
"->",
"listBookIds",
"(",
"$",
"request",
")",
";",
"foreach",
"(",
"$",
"book_ids",
"as",
"$",
"id",
")",
"... | @param \WP_REST_Request
@return array | [
"@param",
"\\",
"WP_REST_Request"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L330-L341 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.listBookIds | protected function listBookIds( $request ) {
global $wpdb;
$limit = ! empty( $request['per_page'] ) ? $request['per_page'] : $this->limit;
$offset = ! empty( $request['page'] ) ? ( $request['page'] - 1 ) * $limit : 0;
$blogs = $wpdb->get_col(
$wpdb->prepare(
"SELECT SQL_CALC_FOUND_ROWS blog_id FROM {$... | php | protected function listBookIds( $request ) {
global $wpdb;
$limit = ! empty( $request['per_page'] ) ? $request['per_page'] : $this->limit;
$offset = ! empty( $request['page'] ) ? ( $request['page'] - 1 ) * $limit : 0;
$blogs = $wpdb->get_col(
$wpdb->prepare(
"SELECT SQL_CALC_FOUND_ROWS blog_id FROM {$... | [
"protected",
"function",
"listBookIds",
"(",
"$",
"request",
")",
"{",
"global",
"$",
"wpdb",
";",
"$",
"limit",
"=",
"!",
"empty",
"(",
"$",
"request",
"[",
"'per_page'",
"]",
")",
"?",
"$",
"request",
"[",
"'per_page'",
"]",
":",
"$",
"this",
"->",... | Count all books, update $this->>totalBooks, return a paginated subset of book ids
@param \WP_REST_Request
@return array blog ids | [
"Count",
"all",
"books",
"update",
"$this",
"-",
">>",
"totalBooks",
"return",
"a",
"paginated",
"subset",
"of",
"book",
"ids"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L350-L368 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.addPreviousNextLinks | protected function addPreviousNextLinks( $request, $response ) {
$page = (int) $request['page'];
$max_pages = (int) ceil( $this->totalBooks / (int) $request['per_page'] );
$response->header( 'X-WP-Total', (int) $this->totalBooks );
$response->header( 'X-WP-TotalPages', $max_pages );
$request_params = $requ... | php | protected function addPreviousNextLinks( $request, $response ) {
$page = (int) $request['page'];
$max_pages = (int) ceil( $this->totalBooks / (int) $request['per_page'] );
$response->header( 'X-WP-Total', (int) $this->totalBooks );
$response->header( 'X-WP-TotalPages', $max_pages );
$request_params = $requ... | [
"protected",
"function",
"addPreviousNextLinks",
"(",
"$",
"request",
",",
"$",
"response",
")",
"{",
"$",
"page",
"=",
"(",
"int",
")",
"$",
"request",
"[",
"'page'",
"]",
";",
"$",
"max_pages",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"this",
"->",
... | Add previous/next links like it's done in WP-API
@param \WP_REST_Request $request
@param \WP_REST_Response $response | [
"Add",
"previous",
"/",
"next",
"links",
"like",
"it",
"s",
"done",
"in",
"WP",
"-",
"API"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L376-L400 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.find | public function find( $search ) {
if ( ! is_array( $search ) ) {
$search = (array) $search;
}
foreach ( $search as $val ) {
if ( $this->fulltextSearchInPost( $val ) !== false ) {
return true;
}
if ( $this->fulltextSearchInMeta( $val ) !== false ) {
return true;
}
}
return false;
} | php | public function find( $search ) {
if ( ! is_array( $search ) ) {
$search = (array) $search;
}
foreach ( $search as $val ) {
if ( $this->fulltextSearchInPost( $val ) !== false ) {
return true;
}
if ( $this->fulltextSearchInMeta( $val ) !== false ) {
return true;
}
}
return false;
} | [
"public",
"function",
"find",
"(",
"$",
"search",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"search",
")",
")",
"{",
"$",
"search",
"=",
"(",
"array",
")",
"$",
"search",
";",
"}",
"foreach",
"(",
"$",
"search",
"as",
"$",
"val",
")",
"{"... | Overridable find method for how to search a book
@param mixed $search
@return bool | [
"Overridable",
"find",
"method",
"for",
"how",
"to",
"search",
"a",
"book"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L413-L429 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.fulltextSearchInPost | protected function fulltextSearchInPost( $search ) {
$s = $this->searchArgs( $search );
$q = new \WP_Query( $s );
// @codingStandardsIgnoreStart
//
// SELECT wp_2_posts.ID FROM wp_2_posts
// WHERE 1=1 AND (((wp_2_posts.post_title LIKE '%Foo%') OR (wp_2_posts.post_excerpt LIKE '%Foo%') OR (wp_2_posts.post_... | php | protected function fulltextSearchInPost( $search ) {
$s = $this->searchArgs( $search );
$q = new \WP_Query( $s );
// @codingStandardsIgnoreStart
//
// SELECT wp_2_posts.ID FROM wp_2_posts
// WHERE 1=1 AND (((wp_2_posts.post_title LIKE '%Foo%') OR (wp_2_posts.post_excerpt LIKE '%Foo%') OR (wp_2_posts.post_... | [
"protected",
"function",
"fulltextSearchInPost",
"(",
"$",
"search",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"searchArgs",
"(",
"$",
"search",
")",
";",
"$",
"q",
"=",
"new",
"\\",
"WP_Query",
"(",
"$",
"s",
")",
";",
"// @codingStandardsIgnoreStart"... | Fulltext search entire book
@param string $search
@return bool | [
"Fulltext",
"search",
"entire",
"book"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L458-L477 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.fulltextSearchInMeta | protected function fulltextSearchInMeta( $search ) {
$meta = new \Pressbooks\Metadata();
$data = $meta->getMetaPostMetadata();
foreach ( $data as $key => $haystack ) {
// Skip anything not prefixed with pb_
if ( ! preg_match( '/^pb_/', $key ) ) {
continue;
}
if ( is_array( $haystack ) ) {
$h... | php | protected function fulltextSearchInMeta( $search ) {
$meta = new \Pressbooks\Metadata();
$data = $meta->getMetaPostMetadata();
foreach ( $data as $key => $haystack ) {
// Skip anything not prefixed with pb_
if ( ! preg_match( '/^pb_/', $key ) ) {
continue;
}
if ( is_array( $haystack ) ) {
$h... | [
"protected",
"function",
"fulltextSearchInMeta",
"(",
"$",
"search",
")",
"{",
"$",
"meta",
"=",
"new",
"\\",
"Pressbooks",
"\\",
"Metadata",
"(",
")",
";",
"$",
"data",
"=",
"$",
"meta",
"->",
"getMetaPostMetadata",
"(",
")",
";",
"foreach",
"(",
"$",
... | Fulltext search all `pb_` prefixed meta keys in metadata post
@param string $search
@return bool | [
"Fulltext",
"search",
"all",
"pb_",
"prefixed",
"meta",
"keys",
"in",
"metadata",
"post"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L486-L504 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.searchBooks | protected function searchBooks( $request ) {
if ( ! empty( $request['next'] ) ) {
$this->lastKnownBookId = $request['next'];
}
$start_time = time();
$searched_books = 0;
$found_books = 0;
$results = [];
while ( $found_books < $request['per_page'] ) {
$book_ids = $this->searchBookIds( $request );
... | php | protected function searchBooks( $request ) {
if ( ! empty( $request['next'] ) ) {
$this->lastKnownBookId = $request['next'];
}
$start_time = time();
$searched_books = 0;
$found_books = 0;
$results = [];
while ( $found_books < $request['per_page'] ) {
$book_ids = $this->searchBookIds( $request );
... | [
"protected",
"function",
"searchBooks",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"[",
"'next'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"lastKnownBookId",
"=",
"$",
"request",
"[",
"'next'",
"]",
";",
"}",
"$",
"s... | Fulltext search
@param \WP_REST_Request $request
@return array | [
"Fulltext",
"search"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L513-L550 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.searchBookIds | protected function searchBookIds( $request ) {
global $wpdb;
$limit = ! empty( $request['per_page'] ) ? $request['per_page'] : $this->limit;
$blogs = $wpdb->get_col(
$wpdb->prepare(
"SELECT SQL_CALC_FOUND_ROWS blog_id FROM {$wpdb->blogs}
WHERE public = 1 AND archived = 0 AND spam = 0 AND deleted =... | php | protected function searchBookIds( $request ) {
global $wpdb;
$limit = ! empty( $request['per_page'] ) ? $request['per_page'] : $this->limit;
$blogs = $wpdb->get_col(
$wpdb->prepare(
"SELECT SQL_CALC_FOUND_ROWS blog_id FROM {$wpdb->blogs}
WHERE public = 1 AND archived = 0 AND spam = 0 AND deleted =... | [
"protected",
"function",
"searchBookIds",
"(",
"$",
"request",
")",
"{",
"global",
"$",
"wpdb",
";",
"$",
"limit",
"=",
"!",
"empty",
"(",
"$",
"request",
"[",
"'per_page'",
"]",
")",
"?",
"$",
"request",
"[",
"'per_page'",
"]",
":",
"$",
"this",
"->... | Count all books, update $this->>totalBooks, return a paginated subset of book ids
@param \WP_REST_Request
@return array blog ids | [
"Count",
"all",
"books",
"update",
"$this",
"-",
">>",
"totalBooks",
"return",
"a",
"paginated",
"subset",
"of",
"book",
"ids"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L559-L576 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-books.php | Books.addNextSearchLinks | protected function addNextSearchLinks( $request, $response ) {
$max_pages = (int) ceil( $this->totalBooks / (int) $request['per_page'] );
$response->header( 'X-WP-Total', (int) $this->totalBooks );
$response->header( 'X-WP-TotalPages', $max_pages );
if ( $this->lastKnownBookId ) {
unset( $request['page'] ... | php | protected function addNextSearchLinks( $request, $response ) {
$max_pages = (int) ceil( $this->totalBooks / (int) $request['per_page'] );
$response->header( 'X-WP-Total', (int) $this->totalBooks );
$response->header( 'X-WP-TotalPages', $max_pages );
if ( $this->lastKnownBookId ) {
unset( $request['page'] ... | [
"protected",
"function",
"addNextSearchLinks",
"(",
"$",
"request",
",",
"$",
"response",
")",
"{",
"$",
"max_pages",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"this",
"->",
"totalBooks",
"/",
"(",
"int",
")",
"$",
"request",
"[",
"'per_page'",
"]",
")",... | Add a next link for search results
@param \WP_REST_Request $request
@param \WP_REST_Response $response | [
"Add",
"a",
"next",
"link",
"for",
"search",
"results"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-books.php#L584-L598 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.registerTaxonomies | public function registerTaxonomies() {
register_extended_taxonomy(
'front-matter-type',
'front-matter',
[
'meta_box' => 'dropdown',
'meta_box_sanitize_cb' => 'taxonomy_meta_box_sanitize_cb_input',
'capabilities' => [
'manage_terms' => 'manage_sites',
'edit_terms' => 'manage_sites',
... | php | public function registerTaxonomies() {
register_extended_taxonomy(
'front-matter-type',
'front-matter',
[
'meta_box' => 'dropdown',
'meta_box_sanitize_cb' => 'taxonomy_meta_box_sanitize_cb_input',
'capabilities' => [
'manage_terms' => 'manage_sites',
'edit_terms' => 'manage_sites',
... | [
"public",
"function",
"registerTaxonomies",
"(",
")",
"{",
"register_extended_taxonomy",
"(",
"'front-matter-type'",
",",
"'front-matter'",
",",
"[",
"'meta_box'",
"=>",
"'dropdown'",
",",
"'meta_box_sanitize_cb'",
"=>",
"'taxonomy_meta_box_sanitize_cb_input'",
",",
"'capab... | Register taxonomies | [
"Register",
"taxonomies"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L83-L180 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.insertTerms | public function insertTerms() {
if ( ! taxonomy_exists( 'front-matter-type' ) ) {
$this->registerTaxonomies();
}
// Front Matter
wp_insert_term(
'Abstract', 'front-matter-type', [
'slug' => 'abstracts',
]
);
wp_insert_term(
'Acknowledgements', 'front-matter-type', [
'slug' => 'acknowle... | php | public function insertTerms() {
if ( ! taxonomy_exists( 'front-matter-type' ) ) {
$this->registerTaxonomies();
}
// Front Matter
wp_insert_term(
'Abstract', 'front-matter-type', [
'slug' => 'abstracts',
]
);
wp_insert_term(
'Acknowledgements', 'front-matter-type', [
'slug' => 'acknowle... | [
"public",
"function",
"insertTerms",
"(",
")",
"{",
"if",
"(",
"!",
"taxonomy_exists",
"(",
"'front-matter-type'",
")",
")",
"{",
"$",
"this",
"->",
"registerTaxonomies",
"(",
")",
";",
"}",
"// Front Matter",
"wp_insert_term",
"(",
"'Abstract'",
",",
"'front-... | Insert terms
If the term already exists on the same hierarchical level, or the term slug and name are not unique,
wp_insert_term() returns a WP_Error and we ignore it. | [
"Insert",
"terms"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L188-L449 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.getFrontMatterType | public function getFrontMatterType( $id ) {
$terms = get_the_terms( $id, 'front-matter-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
return $term->slug;
}
}
return 'miscellaneous';
} | php | public function getFrontMatterType( $id ) {
$terms = get_the_terms( $id, 'front-matter-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
return $term->slug;
}
}
return 'miscellaneous';
} | [
"public",
"function",
"getFrontMatterType",
"(",
"$",
"id",
")",
"{",
"$",
"terms",
"=",
"get_the_terms",
"(",
"$",
"id",
",",
"'front-matter-type'",
")",
";",
"if",
"(",
"$",
"terms",
"&&",
"!",
"is_wp_error",
"(",
"$",
"terms",
")",
")",
"{",
"foreac... | Return the first (and only) front-matter-type for a specific post
@param int $id Post ID
@return string | [
"Return",
"the",
"first",
"(",
"and",
"only",
")",
"front",
"-",
"matter",
"-",
"type",
"for",
"a",
"specific",
"post"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L458-L468 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.getBackMatterType | public function getBackMatterType( $id ) {
$terms = get_the_terms( $id, 'back-matter-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
return $term->slug;
}
}
return 'miscellaneous';
} | php | public function getBackMatterType( $id ) {
$terms = get_the_terms( $id, 'back-matter-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
return $term->slug;
}
}
return 'miscellaneous';
} | [
"public",
"function",
"getBackMatterType",
"(",
"$",
"id",
")",
"{",
"$",
"terms",
"=",
"get_the_terms",
"(",
"$",
"id",
",",
"'back-matter-type'",
")",
";",
"if",
"(",
"$",
"terms",
"&&",
"!",
"is_wp_error",
"(",
"$",
"terms",
")",
")",
"{",
"foreach"... | Return the first (and only) back-matter-type for a specific post
@param int $id Post ID
@return string | [
"Return",
"the",
"first",
"(",
"and",
"only",
")",
"back",
"-",
"matter",
"-",
"type",
"for",
"a",
"specific",
"post"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L477-L487 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.getChapterType | public function getChapterType( $id ) {
$terms = get_the_terms( $id, 'chapter-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
if ( 'type-1' === $term->slug ) {
return 'standard';
} else {
return $term->slug;
}
}
}
return 'standard';
} | php | public function getChapterType( $id ) {
$terms = get_the_terms( $id, 'chapter-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
if ( 'type-1' === $term->slug ) {
return 'standard';
} else {
return $term->slug;
}
}
}
return 'standard';
} | [
"public",
"function",
"getChapterType",
"(",
"$",
"id",
")",
"{",
"$",
"terms",
"=",
"get_the_terms",
"(",
"$",
"id",
",",
"'chapter-type'",
")",
";",
"if",
"(",
"$",
"terms",
"&&",
"!",
"is_wp_error",
"(",
"$",
"terms",
")",
")",
"{",
"foreach",
"("... | Return the first (and only) chapter-type for a specific post
@param int $id Post ID
@return string | [
"Return",
"the",
"first",
"(",
"and",
"only",
")",
"chapter",
"-",
"type",
"for",
"a",
"specific",
"post"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L496-L510 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.getGlossaryType | public function getGlossaryType( $id ) {
$terms = get_the_terms( $id, 'glossary-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
return $term->slug;
}
}
return 'miscellaneous';
} | php | public function getGlossaryType( $id ) {
$terms = get_the_terms( $id, 'glossary-type' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
return $term->slug;
}
}
return 'miscellaneous';
} | [
"public",
"function",
"getGlossaryType",
"(",
"$",
"id",
")",
"{",
"$",
"terms",
"=",
"get_the_terms",
"(",
"$",
"id",
",",
"'glossary-type'",
")",
";",
"if",
"(",
"$",
"terms",
"&&",
"!",
"is_wp_error",
"(",
"$",
"terms",
")",
")",
"{",
"foreach",
"... | Return the first (and only) glossary-type for a specific post
@param $id
@return string | [
"Return",
"the",
"first",
"(",
"and",
"only",
")",
"glossary",
"-",
"type",
"for",
"a",
"specific",
"post"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L519-L529 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.maybeUpgrade | public function maybeUpgrade() {
$taxonomy_version = get_option( 'pressbooks_taxonomy_version', 0 );
if ( $taxonomy_version < self::VERSION ) {
$this->upgrade( $taxonomy_version );
update_option( 'pressbooks_taxonomy_version', self::VERSION );
}
} | php | public function maybeUpgrade() {
$taxonomy_version = get_option( 'pressbooks_taxonomy_version', 0 );
if ( $taxonomy_version < self::VERSION ) {
$this->upgrade( $taxonomy_version );
update_option( 'pressbooks_taxonomy_version', self::VERSION );
}
} | [
"public",
"function",
"maybeUpgrade",
"(",
")",
"{",
"$",
"taxonomy_version",
"=",
"get_option",
"(",
"'pressbooks_taxonomy_version'",
",",
"0",
")",
";",
"if",
"(",
"$",
"taxonomy_version",
"<",
"self",
"::",
"VERSION",
")",
"{",
"$",
"this",
"->",
"upgrade... | Is it time to upgrade? | [
"Is",
"it",
"time",
"to",
"upgrade?"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L538-L544 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.upgrade | public function upgrade( $version ) {
if ( $version < 1 ) {
// Upgrade from version 0 (prior to Pressbooks\Taxonomy class) to version 1 (simplified chapter types)
$this->upgradeChapterTypes();
flush_rewrite_rules( false );
}
if ( $version < 2 ) {
$this->insertTerms(); // Re-trigger
}
if ( $versio... | php | public function upgrade( $version ) {
if ( $version < 1 ) {
// Upgrade from version 0 (prior to Pressbooks\Taxonomy class) to version 1 (simplified chapter types)
$this->upgradeChapterTypes();
flush_rewrite_rules( false );
}
if ( $version < 2 ) {
$this->insertTerms(); // Re-trigger
}
if ( $versio... | [
"public",
"function",
"upgrade",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"version",
"<",
"1",
")",
"{",
"// Upgrade from version 0 (prior to Pressbooks\\Taxonomy class) to version 1 (simplified chapter types)",
"$",
"this",
"->",
"upgradeChapterTypes",
"(",
")",
... | Upgrade
@param int $version | [
"Upgrade"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L551-L567 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.upgradeChapterTypes | protected function upgradeChapterTypes() {
$type_1 = get_term_by( 'slug', 'type-1', 'chapter-type' );
$type_2 = get_term_by( 'slug', 'type-2', 'chapter-type' );
$type_3 = get_term_by( 'slug', 'type-3', 'chapter-type' );
$type_4 = get_term_by( 'slug', 'type-4', 'chapter-type' );
$type_5 = get_term_by( 'slug', ... | php | protected function upgradeChapterTypes() {
$type_1 = get_term_by( 'slug', 'type-1', 'chapter-type' );
$type_2 = get_term_by( 'slug', 'type-2', 'chapter-type' );
$type_3 = get_term_by( 'slug', 'type-3', 'chapter-type' );
$type_4 = get_term_by( 'slug', 'type-4', 'chapter-type' );
$type_5 = get_term_by( 'slug', ... | [
"protected",
"function",
"upgradeChapterTypes",
"(",
")",
"{",
"$",
"type_1",
"=",
"get_term_by",
"(",
"'slug'",
",",
"'type-1'",
",",
"'chapter-type'",
")",
";",
"$",
"type_2",
"=",
"get_term_by",
"(",
"'slug'",
",",
"'type-2'",
",",
"'chapter-type'",
")",
... | Upgrade Chapter Types. | [
"Upgrade",
"Chapter",
"Types",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L611-L642 |
pressbooks/pressbooks | inc/class-taxonomy.php | Taxonomy.upgradeToContributorTaxonomy | public function upgradeToContributorTaxonomy( $meta_id, $object_id, $meta_key, $meta_value ) {
return $this->contributors->convert( $meta_key, $meta_value, $object_id );
} | php | public function upgradeToContributorTaxonomy( $meta_id, $object_id, $meta_key, $meta_value ) {
return $this->contributors->convert( $meta_key, $meta_value, $object_id );
} | [
"public",
"function",
"upgradeToContributorTaxonomy",
"(",
"$",
"meta_id",
",",
"$",
"object_id",
",",
"$",
"meta_key",
",",
"$",
"meta_value",
")",
"{",
"return",
"$",
"this",
"->",
"contributors",
"->",
"convert",
"(",
"$",
"meta_key",
",",
"$",
"meta_valu... | If some plugin is still saving to the old/deprecated contributor slugs, then upgrade to Pressbooks Five Data Model
@since 5.0.0
@param int $meta_id ID of updated metadata entry.
@param int $object_id Post ID.
@param string $meta_key Meta key.
@param mixed $meta_value Meta value.
@return array|false An array containi... | [
"If",
"some",
"plugin",
"is",
"still",
"saving",
"to",
"the",
"old",
"/",
"deprecated",
"contributor",
"slugs",
"then",
"upgrade",
"to",
"Pressbooks",
"Five",
"Data",
"Model"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-taxonomy.php#L656-L658 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.deleteIframesNotOnWhitelist | public function deleteIframesNotOnWhitelist( $content, $allowed_html ) {
// Check if this is a post, bail if it isn't
if ( ! is_array( $allowed_html ) ) {
$allowed_html = [ $allowed_html ];
}
if ( in_array( 'post', $allowed_html, true ) === false ) {
return $content;
}
// Check for iframe HTML code, b... | php | public function deleteIframesNotOnWhitelist( $content, $allowed_html ) {
// Check if this is a post, bail if it isn't
if ( ! is_array( $allowed_html ) ) {
$allowed_html = [ $allowed_html ];
}
if ( in_array( 'post', $allowed_html, true ) === false ) {
return $content;
}
// Check for iframe HTML code, b... | [
"public",
"function",
"deleteIframesNotOnWhitelist",
"(",
"$",
"content",
",",
"$",
"allowed_html",
")",
"{",
"// Check if this is a post, bail if it isn't",
"if",
"(",
"!",
"is_array",
"(",
"$",
"allowed_html",
")",
")",
"{",
"$",
"allowed_html",
"=",
"[",
"$",
... | Delete <iframe> sources not on our whitelist
Content is expected to be raw, e.g. before the_content filters have been run
Hooked into `pre_kses` filter
@param string $content Content to run through kses.
@param array $allowed_html Allowed HTML elements.
@return string | [
"Delete",
"<iframe",
">",
"sources",
"not",
"on",
"our",
"whitelist",
"Content",
"is",
"expected",
"to",
"be",
"raw",
"e",
".",
"g",
".",
"before",
"the_content",
"filters",
"have",
"been",
"run",
"Hooked",
"into",
"pre_kses",
"filter"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L114-L170 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.replaceIframes | public function replaceIframes( $content ) {
// Check for iframe HTML code, bail if there isn't any
if ( stripos( $content, '<iframe' ) === false ) {
return $content;
}
global $id; // This is the Post ID, [@see WP_Query::setup_postdata, ...]
$html5 = new HtmlParser();
$dom = $html5->loadHTML( $content ... | php | public function replaceIframes( $content ) {
// Check for iframe HTML code, bail if there isn't any
if ( stripos( $content, '<iframe' ) === false ) {
return $content;
}
global $id; // This is the Post ID, [@see WP_Query::setup_postdata, ...]
$html5 = new HtmlParser();
$dom = $html5->loadHTML( $content ... | [
"public",
"function",
"replaceIframes",
"(",
"$",
"content",
")",
"{",
"// Check for iframe HTML code, bail if there isn't any",
"if",
"(",
"stripos",
"(",
"$",
"content",
",",
"'<iframe'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"content",
";",
"}",
"glob... | Replace <iframe> with standard text
Content is expected to be rendered, e.g. after the_content filters have been run
Hooked into `the_content` filter
@param string $content
@return string | [
"Replace",
"<iframe",
">",
"with",
"standard",
"text",
"Content",
"is",
"expected",
"to",
"be",
"rendered",
"e",
".",
"g",
".",
"after",
"the_content",
"filters",
"have",
"been",
"run",
"Hooked",
"into",
"the_content",
"filter"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L181-L208 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.allowIframesInHtml | public function allowIframesInHtml( $allowed, $context ) {
if ( $context !== 'post' ) {
return $allowed;
}
if ( current_user_can( 'publish_posts' ) === false ) {
return $allowed;
}
$allowed['iframe'] = [
'src' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'marginwidth... | php | public function allowIframesInHtml( $allowed, $context ) {
if ( $context !== 'post' ) {
return $allowed;
}
if ( current_user_can( 'publish_posts' ) === false ) {
return $allowed;
}
$allowed['iframe'] = [
'src' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'marginwidth... | [
"public",
"function",
"allowIframesInHtml",
"(",
"$",
"allowed",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"!==",
"'post'",
")",
"{",
"return",
"$",
"allowed",
";",
"}",
"if",
"(",
"current_user_can",
"(",
"'publish_posts'",
")",
"===",
"... | Add <iframe> to allowed post tags in wp_kses
@param array $allowed
@param string $context
@return array | [
"Add",
"<iframe",
">",
"to",
"allowed",
"post",
"tags",
"in",
"wp_kses"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L218-L237 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.replaceOembed | public function replaceOembed( $return, $data, $url ) {
// Check for iframe HTML code, bail if there isn't any
if ( stripos( $return, '<iframe' ) === false ) {
return $return;
}
global $id; // This is the Post ID, [@see WP_Query::setup_postdata, ...]
$title = $data->title ?? $this->getTitle( $id );
$i... | php | public function replaceOembed( $return, $data, $url ) {
// Check for iframe HTML code, bail if there isn't any
if ( stripos( $return, '<iframe' ) === false ) {
return $return;
}
global $id; // This is the Post ID, [@see WP_Query::setup_postdata, ...]
$title = $data->title ?? $this->getTitle( $id );
$i... | [
"public",
"function",
"replaceOembed",
"(",
"$",
"return",
",",
"$",
"data",
",",
"$",
"url",
")",
"{",
"// Check for iframe HTML code, bail if there isn't any",
"if",
"(",
"stripos",
"(",
"$",
"return",
",",
"'<iframe'",
")",
"===",
"false",
")",
"{",
"return... | Filters the returned oEmbed HTML.
Hooked into `oembed_dataparse` filter
@param string $return The returned oEmbed HTML.
@param object $data A data object result from an oEmbed provider. See Response Parameters in https://oembed.com/ specification
@param string $url The URL of the content to be embedded.
@return strin... | [
"Filters",
"the",
"returned",
"oEmbed",
"HTML",
".",
"Hooked",
"into",
"oembed_dataparse",
"filter"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L249-L273 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.replaceInteractiveTags | public function replaceInteractiveTags( $html ) {
$tags = [
'audio',
'video',
];
// Check for HTML tags, bail if there isn't any
$found = false;
foreach ( $tags as $tag ) {
if ( stripos( $html, "<{$tag}" ) !== false ) {
$found = true;
break;
}
}
if ( ! $found ) {
return $html;
}... | php | public function replaceInteractiveTags( $html ) {
$tags = [
'audio',
'video',
];
// Check for HTML tags, bail if there isn't any
$found = false;
foreach ( $tags as $tag ) {
if ( stripos( $html, "<{$tag}" ) !== false ) {
$found = true;
break;
}
}
if ( ! $found ) {
return $html;
}... | [
"public",
"function",
"replaceInteractiveTags",
"(",
"$",
"html",
")",
"{",
"$",
"tags",
"=",
"[",
"'audio'",
",",
"'video'",
",",
"]",
";",
"// Check for HTML tags, bail if there isn't any",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"tags",
"as",
... | Replace interactive tags such as <audio>, <video>
@param string $html
@return string | [
"Replace",
"interactive",
"tags",
"such",
"as",
"<audio",
">",
"<video",
">"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L282-L325 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.addExtraOembedProviders | public function addExtraOembedProviders( $providers ) {
// Format (string), Provider (string), Is format a regular expression? (bool)
$providers['#https?://mathembed\.com/latex\?inputText=.*#i'] = [ 'https://mathembed.com/oembed', true ];
$providers['#https?://www\.openassessments\.org/assessments/.*#i'] = [ 'ht... | php | public function addExtraOembedProviders( $providers ) {
// Format (string), Provider (string), Is format a regular expression? (bool)
$providers['#https?://mathembed\.com/latex\?inputText=.*#i'] = [ 'https://mathembed.com/oembed', true ];
$providers['#https?://www\.openassessments\.org/assessments/.*#i'] = [ 'ht... | [
"public",
"function",
"addExtraOembedProviders",
"(",
"$",
"providers",
")",
"{",
"// Format (string), Provider (string), Is format a regular expression? (bool)",
"$",
"providers",
"[",
"'#https?://mathembed\\.com/latex\\?inputText=.*#i'",
"]",
"=",
"[",
"'https://mathembed.com/oembe... | Add oEmbed providers
Hooked into `oembed_providers` filter
@see \WP_oEmbed
@see https://oembed.com/
@see https://github.com/iamcal/oembed/tree/master/providers
@param array $providers
@return array | [
"Add",
"oEmbed",
"providers",
"Hooked",
"into",
"oembed_providers",
"filter"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L339-L348 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.deleteOembedCaches | public function deleteOembedCaches( $post_id = 0 ) {
if ( $post_id ) {
global $wp_embed;
$wp_embed->delete_oembed_caches( $post_id );
} else {
global $wpdb;
$post_metas = $wpdb->get_results( "SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE '_oembed_%' " );
foreach ( $post_metas as... | php | public function deleteOembedCaches( $post_id = 0 ) {
if ( $post_id ) {
global $wp_embed;
$wp_embed->delete_oembed_caches( $post_id );
} else {
global $wpdb;
$post_metas = $wpdb->get_results( "SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE '_oembed_%' " );
foreach ( $post_metas as... | [
"public",
"function",
"deleteOembedCaches",
"(",
"$",
"post_id",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"post_id",
")",
"{",
"global",
"$",
"wp_embed",
";",
"$",
"wp_embed",
"->",
"delete_oembed_caches",
"(",
"$",
"post_id",
")",
";",
"}",
"else",
"{",
"g... | Delete all oEmbed caches
@param int $post_id | [
"Delete",
"all",
"oEmbed",
"caches"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L355-L366 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.beforeExport | public function beforeExport() {
$this->overrideH5P();
$this->overridePhet();
$this->overrideIframes();
$this->overrideEmbeds();
$this->overrideVideo();
$this->overrideAudio();
} | php | public function beforeExport() {
$this->overrideH5P();
$this->overridePhet();
$this->overrideIframes();
$this->overrideEmbeds();
$this->overrideVideo();
$this->overrideAudio();
} | [
"public",
"function",
"beforeExport",
"(",
")",
"{",
"$",
"this",
"->",
"overrideH5P",
"(",
")",
";",
"$",
"this",
"->",
"overridePhet",
"(",
")",
";",
"$",
"this",
"->",
"overrideIframes",
"(",
")",
";",
"$",
"this",
"->",
"overrideEmbeds",
"(",
")",
... | Hooked into `pb_pre_export` action | [
"Hooked",
"into",
"pb_pre_export",
"action"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L380-L387 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.overrideIframes | protected function overrideIframes() {
if ( self::$instance ) {
remove_filter( 'pre_kses', [ self::$instance, 'deleteIframesNotOnWhitelist' ] );
remove_filter( 'wp_kses_allowed_html', [ self::$instance, 'allowIframesInHtml' ] );
}
add_filter( 'the_content', [ $this, 'replaceIframes' ], 999 ); // Priority e... | php | protected function overrideIframes() {
if ( self::$instance ) {
remove_filter( 'pre_kses', [ self::$instance, 'deleteIframesNotOnWhitelist' ] );
remove_filter( 'wp_kses_allowed_html', [ self::$instance, 'allowIframesInHtml' ] );
}
add_filter( 'the_content', [ $this, 'replaceIframes' ], 999 ); // Priority e... | [
"protected",
"function",
"overrideIframes",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"instance",
")",
"{",
"remove_filter",
"(",
"'pre_kses'",
",",
"[",
"self",
"::",
"$",
"instance",
",",
"'deleteIframesNotOnWhitelist'",
"]",
")",
";",
"remove_filter",
... | Override any <iframe> code found in HTML | [
"Override",
"any",
"<iframe",
">",
"code",
"found",
"in",
"HTML"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L409-L416 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.overrideEmbeds | protected function overrideEmbeds() {
global $wp_embed;
$wp_embed->usecache = false;
add_filter( 'oembed_ttl', '__return_zero', 999 );
add_filter(
'embed_defaults', function ( $attr ) {
// Embed cache keys are created by doing `md5( $url . serialize( $attr ) )`
// By adding an HTML5 Data Attribute we... | php | protected function overrideEmbeds() {
global $wp_embed;
$wp_embed->usecache = false;
add_filter( 'oembed_ttl', '__return_zero', 999 );
add_filter(
'embed_defaults', function ( $attr ) {
// Embed cache keys are created by doing `md5( $url . serialize( $attr ) )`
// By adding an HTML5 Data Attribute we... | [
"protected",
"function",
"overrideEmbeds",
"(",
")",
"{",
"global",
"$",
"wp_embed",
";",
"$",
"wp_embed",
"->",
"usecache",
"=",
"false",
";",
"add_filter",
"(",
"'oembed_ttl'",
",",
"'__return_zero'",
",",
"999",
")",
";",
"add_filter",
"(",
"'embed_defaults... | Override WordPress Embeds | [
"Override",
"WordPress",
"Embeds"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L421-L434 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.overrideVideo | protected function overrideVideo() {
/**
* @param string $output Video shortcode HTML output.
* @param array $atts Array of video shortcode attributes.
* @param string $video Video file.
*/
add_filter(
'wp_video_shortcode', function ( $output, $atts, $video ) {
$src_attributes = array_merg... | php | protected function overrideVideo() {
/**
* @param string $output Video shortcode HTML output.
* @param array $atts Array of video shortcode attributes.
* @param string $video Video file.
*/
add_filter(
'wp_video_shortcode', function ( $output, $atts, $video ) {
$src_attributes = array_merg... | [
"protected",
"function",
"overrideVideo",
"(",
")",
"{",
"/**\n\t\t * @param string $output Video shortcode HTML output.\n\t\t * @param array $atts Array of video shortcode attributes.\n\t\t * @param string $video Video file.\n\t\t */",
"add_filter",
"(",
"'wp_video_shortcode'",
",",
"f... | Override Video
@see https://codex.wordpress.org/Video_Shortcode | [
"Override",
"Video"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L441-L464 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.overrideAudio | protected function overrideAudio() {
/**
* @param string $output Audio shortcode HTML output.
* @param array $atts Array of Audio shortcode attributes.
* @param string $audio Audio file.
*/
add_filter(
'wp_audio_shortcode', function ( $output, $atts, $audio ) {
$src_attributes = array_merg... | php | protected function overrideAudio() {
/**
* @param string $output Audio shortcode HTML output.
* @param array $atts Array of Audio shortcode attributes.
* @param string $audio Audio file.
*/
add_filter(
'wp_audio_shortcode', function ( $output, $atts, $audio ) {
$src_attributes = array_merg... | [
"protected",
"function",
"overrideAudio",
"(",
")",
"{",
"/**\n\t\t * @param string $output Audio shortcode HTML output.\n\t\t * @param array $atts Array of Audio shortcode attributes.\n\t\t * @param string $audio Audio file.\n\t\t */",
"add_filter",
"(",
"'wp_audio_shortcode'",
",",
"f... | Override Audio
@see https://codex.wordpress.org/Audio_Shortcode | [
"Override",
"Audio"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L471-L494 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.getTitle | protected function getTitle( $post_id ) {
$title = get_the_title( $post_id );
if ( empty( $title ) ) {
$title = get_bloginfo( 'name' );
}
return $title;
} | php | protected function getTitle( $post_id ) {
$title = get_the_title( $post_id );
if ( empty( $title ) ) {
$title = get_bloginfo( 'name' );
}
return $title;
} | [
"protected",
"function",
"getTitle",
"(",
"$",
"post_id",
")",
"{",
"$",
"title",
"=",
"get_the_title",
"(",
"$",
"post_id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"title",
")",
")",
"{",
"$",
"title",
"=",
"get_bloginfo",
"(",
"'name'",
")",
";",
... | @param int $post_id
@return string | [
"@param",
"int",
"$post_id"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L501-L507 |
pressbooks/pressbooks | inc/interactive/class-content.php | Content.adjustOembeds | public function adjustOembeds( $html, $url, $args ) {
if ( ! strpos( $html, 'youtube' ) === false ) {
return str_replace( '?feature=oembed', '?feature=oembed&rel=0', $html );
}
return $html;
} | php | public function adjustOembeds( $html, $url, $args ) {
if ( ! strpos( $html, 'youtube' ) === false ) {
return str_replace( '?feature=oembed', '?feature=oembed&rel=0', $html );
}
return $html;
} | [
"public",
"function",
"adjustOembeds",
"(",
"$",
"html",
",",
"$",
"url",
",",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"strpos",
"(",
"$",
"html",
",",
"'youtube'",
")",
"===",
"false",
")",
"{",
"return",
"str_replace",
"(",
"'?feature=oembed'",
",",
... | @param string $html
@param string $url
@param array $args
@return string | [
"@param",
"string",
"$html",
"@param",
"string",
"$url",
"@param",
"array",
"$args"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/interactive/class-content.php#L516-L521 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.kneadAndInsert | function kneadAndInsert( $html, $post_type, $chapter_parent, $domain, $post_status ) {
$matches = [];
$meta = $this->getLicenseAttribution( $html );
$author = ( isset( $meta['authors'] ) ) ? $meta['authors'] : $this->getAuthors( $html );
$license = ( isset( $meta['license'] ) ) ? $this->extractCCLicense( $meta... | php | function kneadAndInsert( $html, $post_type, $chapter_parent, $domain, $post_status ) {
$matches = [];
$meta = $this->getLicenseAttribution( $html );
$author = ( isset( $meta['authors'] ) ) ? $meta['authors'] : $this->getAuthors( $html );
$license = ( isset( $meta['license'] ) ) ? $this->extractCCLicense( $meta... | [
"function",
"kneadAndInsert",
"(",
"$",
"html",
",",
"$",
"post_type",
",",
"$",
"chapter_parent",
",",
"$",
"domain",
",",
"$",
"post_status",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"meta",
"=",
"$",
"this",
"->",
"getLicenseAttribution",
... | Pummel then insert HTML into our database
@param string $html
@param string $post_type
@param int $chapter_parent
@param string $domain domain name of the web page
@param string $post_status | [
"Pummel",
"then",
"insert",
"HTML",
"into",
"our",
"database"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L81-L132 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.extractCCLicense | protected function extractCCLicense( $url ) {
$license = '';
// evaluate that it's a url
if ( ! is_string( $url ) ) {
return $license;
}
// look for creativecommons domain
$parts = wp_parse_url( $url );
if ( 'http' === $parts['scheme'] && 'creativecommons.org' === $parts['host'] ) {
// extract the... | php | protected function extractCCLicense( $url ) {
$license = '';
// evaluate that it's a url
if ( ! is_string( $url ) ) {
return $license;
}
// look for creativecommons domain
$parts = wp_parse_url( $url );
if ( 'http' === $parts['scheme'] && 'creativecommons.org' === $parts['host'] ) {
// extract the... | [
"protected",
"function",
"extractCCLicense",
"(",
"$",
"url",
")",
"{",
"$",
"license",
"=",
"''",
";",
"// evaluate that it's a url",
"if",
"(",
"!",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"return",
"$",
"license",
";",
"}",
"// look for creativecommo... | Expects a URL string with Creative Commons domain similar in form to:
http://creativecommons.org/licenses/by-sa/4.0/
@param string $url
@return string license meta value | [
"Expects",
"a",
"URL",
"string",
"with",
"Creative",
"Commons",
"domain",
"similar",
"in",
"form",
"to",
":",
"http",
":",
"//",
"creativecommons",
".",
"org",
"/",
"licenses",
"/",
"by",
"-",
"sa",
"/",
"4",
".",
"0",
"/"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L142-L163 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.getLicenseAttribution | protected function getLicenseAttribution( $html ) {
$meta = [];
// get license attribution statement if it exists
preg_match( '/(?:<div class="license-attribution[^>]*>)(.*)(<\/div>)/isU', $html, $matches );
if ( ! empty( $matches[1] ) ) {
$html5 = new HtmlParser();
$dom = $html5->loadHTML( $matches[1] ... | php | protected function getLicenseAttribution( $html ) {
$meta = [];
// get license attribution statement if it exists
preg_match( '/(?:<div class="license-attribution[^>]*>)(.*)(<\/div>)/isU', $html, $matches );
if ( ! empty( $matches[1] ) ) {
$html5 = new HtmlParser();
$dom = $html5->loadHTML( $matches[1] ... | [
"protected",
"function",
"getLicenseAttribution",
"(",
"$",
"html",
")",
"{",
"$",
"meta",
"=",
"[",
"]",
";",
"// get license attribution statement if it exists",
"preg_match",
"(",
"'/(?:<div class=\"license-attribution[^>]*>)(.*)(<\\/div>)/isU'",
",",
"$",
"html",
",",
... | Looks for div class created by the license module in PB, returns
author and license information.
@param string $html
@return array $meta | [
"Looks",
"for",
"div",
"class",
"created",
"by",
"the",
"license",
"module",
"in",
"PB",
"returns",
"author",
"and",
"license",
"information",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L173-L185 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.getAuthors | protected function getAuthors( $html ) {
// go for the book metadata set in PB <head>
preg_match( '/(<meta itemprop="copyrightHolder" content=")(.+)(" id="copyrightHolder")>/is', $html, $matches );
if ( empty( $matches[2] ) ) {
// grab the authors, if copyrightHolders is empty
preg_match( '/(<meta itemprop... | php | protected function getAuthors( $html ) {
// go for the book metadata set in PB <head>
preg_match( '/(<meta itemprop="copyrightHolder" content=")(.+)(" id="copyrightHolder")>/is', $html, $matches );
if ( empty( $matches[2] ) ) {
// grab the authors, if copyrightHolders is empty
preg_match( '/(<meta itemprop... | [
"protected",
"function",
"getAuthors",
"(",
"$",
"html",
")",
"{",
"// go for the book metadata set in PB <head>",
"preg_match",
"(",
"'/(<meta itemprop=\"copyrightHolder\" content=\")(.+)(\" id=\"copyrightHolder\")>/is'",
",",
"$",
"html",
",",
"$",
"matches",
")",
";",
"if"... | Looks for meta data in the <head> section of an HTML document.
Priority is given to PB generated meta data.
@param string $html
@return string $authors | [
"Looks",
"for",
"meta",
"data",
"in",
"the",
"<head",
">",
"section",
"of",
"an",
"HTML",
"document",
".",
"Priority",
"is",
"given",
"to",
"PB",
"generated",
"meta",
"data",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L195-L218 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.regexSearchReplace | protected function regexSearchReplace( $html ) {
/* cherry pick likely content areas */
// HTML5, ungreedy
preg_match( '/(?:<main[^>]*>)(.*)<\/main>/isU', $html, $matches );
$html = ( ! empty( $matches[1] ) ) ? $matches[1] : $html;
// WP content area, greedy
preg_match( '/(?:<div id="main"[^>]*>)(.*)<\/di... | php | protected function regexSearchReplace( $html ) {
/* cherry pick likely content areas */
// HTML5, ungreedy
preg_match( '/(?:<main[^>]*>)(.*)<\/main>/isU', $html, $matches );
$html = ( ! empty( $matches[1] ) ) ? $matches[1] : $html;
// WP content area, greedy
preg_match( '/(?:<div id="main"[^>]*>)(.*)<\/di... | [
"protected",
"function",
"regexSearchReplace",
"(",
"$",
"html",
")",
"{",
"/* cherry pick likely content areas */",
"// HTML5, ungreedy",
"preg_match",
"(",
"'/(?:<main[^>]*>)(.*)<\\/main>/isU'",
",",
"$",
"html",
",",
"$",
"matches",
")",
";",
"$",
"html",
"=",
"(",... | Cherry pick likely content areas, then cull known, unwanted content areas
@param string $html
@return string $html | [
"Cherry",
"pick",
"likely",
"content",
"areas",
"then",
"cull",
"known",
"unwanted",
"content",
"areas"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L227-L265 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.kneadHtml | function kneadHtml( $html, $type, $domain ) {
$html5 = new HtmlParser();
$dom = $html5->loadHTML( $html );
// Download images, change relative paths to absolute
$dom = $this->scrapeAndKneadImages( $dom, $domain );
$html = $html5->saveHTML( $dom );
return $html;
} | php | function kneadHtml( $html, $type, $domain ) {
$html5 = new HtmlParser();
$dom = $html5->loadHTML( $html );
// Download images, change relative paths to absolute
$dom = $this->scrapeAndKneadImages( $dom, $domain );
$html = $html5->saveHTML( $dom );
return $html;
} | [
"function",
"kneadHtml",
"(",
"$",
"html",
",",
"$",
"type",
",",
"$",
"domain",
")",
"{",
"$",
"html5",
"=",
"new",
"HtmlParser",
"(",
")",
";",
"$",
"dom",
"=",
"$",
"html5",
"->",
"loadHTML",
"(",
"$",
"html",
")",
";",
"// Download images, change... | Pummel the HTML into WordPress compatible dough.
@param string $html
@param string $type front-matter, part, chapter, back-matter, ...
@param string $domain domain name of the web page
@return string | [
"Pummel",
"the",
"HTML",
"into",
"WordPress",
"compatible",
"dough",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L276-L286 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.scrapeAndKneadMeta | protected function scrapeAndKneadMeta( \DOMDocument $doc ) {
$meta = [];
$urls = $doc->getElementsByTagName( 'a' );
foreach ( $urls as $anchor ) {
/** @var \DOMElement $anchor */
$license = $anchor->getAttribute( 'rel' );
$property = $anchor->getAttribute( 'property' );
// expecting to find <a hre... | php | protected function scrapeAndKneadMeta( \DOMDocument $doc ) {
$meta = [];
$urls = $doc->getElementsByTagName( 'a' );
foreach ( $urls as $anchor ) {
/** @var \DOMElement $anchor */
$license = $anchor->getAttribute( 'rel' );
$property = $anchor->getAttribute( 'property' );
// expecting to find <a hre... | [
"protected",
"function",
"scrapeAndKneadMeta",
"(",
"\\",
"DOMDocument",
"$",
"doc",
")",
"{",
"$",
"meta",
"=",
"[",
"]",
";",
"$",
"urls",
"=",
"$",
"doc",
"->",
"getElementsByTagName",
"(",
"'a'",
")",
";",
"foreach",
"(",
"$",
"urls",
"as",
"$",
... | Extracts section/book author and section/book license if they exist.
Focus is given to CreativeCommons license information generated by PB
@param \DOMDocument $doc
@return array $meta | [
"Extracts",
"section",
"/",
"book",
"author",
"and",
"section",
"/",
"book",
"license",
"if",
"they",
"exist",
".",
"Focus",
"is",
"given",
"to",
"CreativeCommons",
"license",
"information",
"generated",
"by",
"PB"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L296-L319 |
pressbooks/pressbooks | inc/modules/import/html/class-xhtml.php | Xhtml.fetchAndSaveUniqueImage | protected function fetchAndSaveUniqueImage( $url ) {
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
return '';
}
$remote_img_location = $url;
// Cheap cache
static $already_done = [];
if ( isset( $already_done[ $remote_img_location ] ) ) {
return $already_done[ $remote_img_location ];
}
/*... | php | protected function fetchAndSaveUniqueImage( $url ) {
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
return '';
}
$remote_img_location = $url;
// Cheap cache
static $already_done = [];
if ( isset( $already_done[ $remote_img_location ] ) ) {
return $already_done[ $remote_img_location ];
}
/*... | [
"protected",
"function",
"fetchAndSaveUniqueImage",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"filter_var",
"(",
"$",
"url",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"remote_img_location",
"=",
"$",
"url",
";",
"// Cheap c... | Extract url and load into WP using media_handle_sideload()
Will return an empty string if something went wrong.
@param string $url
@see media_handle_sideload
@return string $src | [
"Extract",
"url",
"and",
"load",
"into",
"WP",
"using",
"media_handle_sideload",
"()",
"Will",
"return",
"an",
"empty",
"string",
"if",
"something",
"went",
"wrong",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/html/class-xhtml.php#L366-L431 |
pressbooks/pressbooks | inc/class-eventstreams.php | EventStreams.emit | public function emit( \Generator $generator, $auto_complete = false ) {
$this->setupHeaders();
try {
foreach ( $generator as $percentage => $info ) {
$data = [
'action' => 'updateStatusBar',
'percentage' => $percentage,
'info' => $info,
];
$this->emitMessage( $data );
}
} catch ( ... | php | public function emit( \Generator $generator, $auto_complete = false ) {
$this->setupHeaders();
try {
foreach ( $generator as $percentage => $info ) {
$data = [
'action' => 'updateStatusBar',
'percentage' => $percentage,
'info' => $info,
];
$this->emitMessage( $data );
}
} catch ( ... | [
"public",
"function",
"emit",
"(",
"\\",
"Generator",
"$",
"generator",
",",
"$",
"auto_complete",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"setupHeaders",
"(",
")",
";",
"try",
"{",
"foreach",
"(",
"$",
"generator",
"as",
"$",
"percentage",
"=>",
"$... | This method accepts a generator that yields a key/value pair
The key is an integer between 1-100 that represents percentage completed
The value is a string of information for the user
Emits event-stream responses (SSE)
@param \Generator $generator
@param bool $auto_complete
@return bool | [
"This",
"method",
"accepts",
"a",
"generator",
"that",
"yields",
"a",
"key",
"/",
"value",
"pair",
"The",
"key",
"is",
"an",
"integer",
"between",
"1",
"-",
"100",
"that",
"represents",
"percentage",
"completed",
"The",
"value",
"is",
"a",
"string",
"of",
... | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-eventstreams.php#L62-L90 |
pressbooks/pressbooks | inc/class-eventstreams.php | EventStreams.emitMessage | private function emitMessage( $data ) {
$msg = "event: message\n";
$msg .= 'data: ' . wp_json_encode( $data ) . "\n\n";
$msg .= ':' . str_repeat( ' ', 2048 ) . "\n\n";
// Buffers are nested. While one buffer is active, flushing from child buffers are not really sent to the browser,
// but rather to the parent... | php | private function emitMessage( $data ) {
$msg = "event: message\n";
$msg .= 'data: ' . wp_json_encode( $data ) . "\n\n";
$msg .= ':' . str_repeat( ' ', 2048 ) . "\n\n";
// Buffers are nested. While one buffer is active, flushing from child buffers are not really sent to the browser,
// but rather to the parent... | [
"private",
"function",
"emitMessage",
"(",
"$",
"data",
")",
"{",
"$",
"msg",
"=",
"\"event: message\\n\"",
";",
"$",
"msg",
".=",
"'data: '",
".",
"wp_json_encode",
"(",
"$",
"data",
")",
".",
"\"\\n\\n\"",
";",
"$",
"msg",
".=",
"':'",
".",
"str_repeat... | Emit a Server-Sent Events message.
@param mixed $data Data to be JSON-encoded and sent in the message. | [
"Emit",
"a",
"Server",
"-",
"Sent",
"Events",
"message",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-eventstreams.php#L97-L115 |
pressbooks/pressbooks | inc/class-eventstreams.php | EventStreams.cloneBook | public function cloneBook() {
check_admin_referer( 'pb-cloner' );
$source_url = $_GET['source_book_url'] ?? '';
$target_url = Cloner::validateNewBookName( $_GET['target_book_url'] );
if ( is_wp_error( $target_url ) ) {
$this->emitOneTimeError( $target_url->get_error_message() );
return;
}
$target_t... | php | public function cloneBook() {
check_admin_referer( 'pb-cloner' );
$source_url = $_GET['source_book_url'] ?? '';
$target_url = Cloner::validateNewBookName( $_GET['target_book_url'] );
if ( is_wp_error( $target_url ) ) {
$this->emitOneTimeError( $target_url->get_error_message() );
return;
}
$target_t... | [
"public",
"function",
"cloneBook",
"(",
")",
"{",
"check_admin_referer",
"(",
"'pb-cloner'",
")",
";",
"$",
"source_url",
"=",
"$",
"_GET",
"[",
"'source_book_url'",
"]",
"??",
"''",
";",
"$",
"target_url",
"=",
"Cloner",
"::",
"validateNewBookName",
"(",
"$... | Clone a book | [
"Clone",
"a",
"book"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-eventstreams.php#L178-L218 |
pressbooks/pressbooks | inc/class-eventstreams.php | EventStreams.exportBook | public function exportBook() {
check_admin_referer( 'pb-export' );
if ( ! is_array( getset( '_GET', 'export_formats' ) ) ) {
$this->emitOneTimeError( __( 'No export format was selected.', 'pressbooks' ) );
return;
}
// Backwards compatibility with older plugins
foreach ( $_GET['export_formats'] as $k ... | php | public function exportBook() {
check_admin_referer( 'pb-export' );
if ( ! is_array( getset( '_GET', 'export_formats' ) ) ) {
$this->emitOneTimeError( __( 'No export format was selected.', 'pressbooks' ) );
return;
}
// Backwards compatibility with older plugins
foreach ( $_GET['export_formats'] as $k ... | [
"public",
"function",
"exportBook",
"(",
")",
"{",
"check_admin_referer",
"(",
"'pb-export'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"getset",
"(",
"'_GET'",
",",
"'export_formats'",
")",
")",
")",
"{",
"$",
"this",
"->",
"emitOneTimeError",
"(",
"__",... | Export book | [
"Export",
"book"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-eventstreams.php#L223-L247 |
pressbooks/pressbooks | inc/class-eventstreams.php | EventStreams.importBook | public function importBook() {
check_admin_referer( 'pb-import' );
// Backwards compatibility with older plugins
$at_least_one = false;
foreach ( $_GET['chapters'] as $k => $v ) {
$_POST['chapters'][ $k ] = $v;
if ( is_array( $v ) && ! empty( $v['import'] ) ) {
$at_least_one = true;
}
}
$_POST... | php | public function importBook() {
check_admin_referer( 'pb-import' );
// Backwards compatibility with older plugins
$at_least_one = false;
foreach ( $_GET['chapters'] as $k => $v ) {
$_POST['chapters'][ $k ] = $v;
if ( is_array( $v ) && ! empty( $v['import'] ) ) {
$at_least_one = true;
}
}
$_POST... | [
"public",
"function",
"importBook",
"(",
")",
"{",
"check_admin_referer",
"(",
"'pb-import'",
")",
";",
"// Backwards compatibility with older plugins",
"$",
"at_least_one",
"=",
"false",
";",
"foreach",
"(",
"$",
"_GET",
"[",
"'chapters'",
"]",
"as",
"$",
"k",
... | Import book | [
"Import",
"book"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-eventstreams.php#L252-L284 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.getIDs | protected function getIDs( \DOMDocument $dom_doc, $tag = 'footnoteReference', $attr = 'w:id' ) {
$fn_ids = [];
$doc_elem = $dom_doc->documentElement;
$tags_fn_ref = $doc_elem->getElementsByTagName( $tag );
// if footnotes are in the document, get the ids
if ( $tags_fn_ref->length > 0 ) {
foreach ( $tags_... | php | protected function getIDs( \DOMDocument $dom_doc, $tag = 'footnoteReference', $attr = 'w:id' ) {
$fn_ids = [];
$doc_elem = $dom_doc->documentElement;
$tags_fn_ref = $doc_elem->getElementsByTagName( $tag );
// if footnotes are in the document, get the ids
if ( $tags_fn_ref->length > 0 ) {
foreach ( $tags_... | [
"protected",
"function",
"getIDs",
"(",
"\\",
"DOMDocument",
"$",
"dom_doc",
",",
"$",
"tag",
"=",
"'footnoteReference'",
",",
"$",
"attr",
"=",
"'w:id'",
")",
"{",
"$",
"fn_ids",
"=",
"[",
"]",
";",
"$",
"doc_elem",
"=",
"$",
"dom_doc",
"->",
"documen... | Given a documentElement, it will return an array of ids
@param \DOMDocument $dom_doc
@param string $tag
@param string $attr
@return array | [
"Given",
"a",
"documentElement",
"it",
"will",
"return",
"an",
"array",
"of",
"ids"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L168-L185 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.getRelationshipPart | protected function getRelationshipPart( array $ids, $tag = 'footnotes' ) {
$footnotes = [];
$tag_name = rtrim( $tag, 's' );
// get the path for the footnotes
switch ( $tag ) {
case 'endnotes':
$target_path = $this->getTargetPath( self::ENDNOTES_SCHEMA, $tag );
break;
case 'hyperlink':
$targe... | php | protected function getRelationshipPart( array $ids, $tag = 'footnotes' ) {
$footnotes = [];
$tag_name = rtrim( $tag, 's' );
// get the path for the footnotes
switch ( $tag ) {
case 'endnotes':
$target_path = $this->getTargetPath( self::ENDNOTES_SCHEMA, $tag );
break;
case 'hyperlink':
$targe... | [
"protected",
"function",
"getRelationshipPart",
"(",
"array",
"$",
"ids",
",",
"$",
"tag",
"=",
"'footnotes'",
")",
"{",
"$",
"footnotes",
"=",
"[",
"]",
";",
"$",
"tag_name",
"=",
"rtrim",
"(",
"$",
"tag",
",",
"'s'",
")",
";",
"// get the path for the ... | Give this some ids and it returns an associative array of footnotes
@param array $ids
@param string $tag
@return array|bool
@throws \Exception if there is discrepancy between the number of footnotes in document.xml and footnotes.xml | [
"Give",
"this",
"some",
"ids",
"and",
"it",
"returns",
"an",
"associative",
"array",
"of",
"footnotes"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L196-L246 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.fetchAndSaveUniqueImage | protected function fetchAndSaveUniqueImage( $img_id ) {
// Cheap cache
static $already_done = [];
if ( isset( $already_done[ $img_id ] ) ) {
return $already_done[ $img_id ];
}
/* Process */
// Get target path
$img_location = $this->getTargetPath( self::IMAGE_SCHEMA, $img_id );
// Basename without ... | php | protected function fetchAndSaveUniqueImage( $img_id ) {
// Cheap cache
static $already_done = [];
if ( isset( $already_done[ $img_id ] ) ) {
return $already_done[ $img_id ];
}
/* Process */
// Get target path
$img_location = $this->getTargetPath( self::IMAGE_SCHEMA, $img_id );
// Basename without ... | [
"protected",
"function",
"fetchAndSaveUniqueImage",
"(",
"$",
"img_id",
")",
"{",
"// Cheap cache",
"static",
"$",
"already_done",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"already_done",
"[",
"$",
"img_id",
"]",
")",
")",
"{",
"return",
"$",
"a... | Extract url from zip and load into WP using media_handle_sideload()
Will return an empty string if something went wrong.
@param string $img_id
@return string | [
"Extract",
"url",
"from",
"zip",
"and",
"load",
"into",
"WP",
"using",
"media_handle_sideload",
"()",
"Will",
"return",
"an",
"empty",
"string",
"if",
"something",
"went",
"wrong",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L344-L420 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.addHyperlinks | protected function addHyperlinks( \DOMDocument $chapter ) {
$ln = $chapter->getElementsByTagName( 'a' );
for ( $i = $ln->length; --$i >= 0; ) { // If you're deleting elements from within a loop, you need to loop backwards
$link = $ln->item( $i );
if (
$link->hasAttribute( 'name' ) &&
in_array( $link... | php | protected function addHyperlinks( \DOMDocument $chapter ) {
$ln = $chapter->getElementsByTagName( 'a' );
for ( $i = $ln->length; --$i >= 0; ) { // If you're deleting elements from within a loop, you need to loop backwards
$link = $ln->item( $i );
if (
$link->hasAttribute( 'name' ) &&
in_array( $link... | [
"protected",
"function",
"addHyperlinks",
"(",
"\\",
"DOMDocument",
"$",
"chapter",
")",
"{",
"$",
"ln",
"=",
"$",
"chapter",
"->",
"getElementsByTagName",
"(",
"'a'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"ln",
"->",
"length",
";",
"--",
"$",
"i... | adds external hyperlinks, if they are present in a chapter
@param \DOMDocument $chapter
@return \DOMDocument | [
"adds",
"external",
"hyperlinks",
"if",
"they",
"are",
"present",
"in",
"a",
"chapter"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L522-L545 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.addFootnotes | protected function addFootnotes( \DOMDocument $chapter ) {
$fn_candidates = $chapter->getelementsByTagName( 'a' );
$fn_ids = [];
foreach ( $fn_candidates as $fn_candidate ) {
/** @var \DOMElement $fn_candidate */
$href = $fn_candidate->getAttribute( 'href' );
if ( ! empty( $href ) ) {
$fn_matches = n... | php | protected function addFootnotes( \DOMDocument $chapter ) {
$fn_candidates = $chapter->getelementsByTagName( 'a' );
$fn_ids = [];
foreach ( $fn_candidates as $fn_candidate ) {
/** @var \DOMElement $fn_candidate */
$href = $fn_candidate->getAttribute( 'href' );
if ( ! empty( $href ) ) {
$fn_matches = n... | [
"protected",
"function",
"addFootnotes",
"(",
"\\",
"DOMDocument",
"$",
"chapter",
")",
"{",
"$",
"fn_candidates",
"=",
"$",
"chapter",
"->",
"getelementsByTagName",
"(",
"'a'",
")",
";",
"$",
"fn_ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fn_candidat... | adds footnotes, if they are present in the chapter
@param \DOMDocument $chapter
@return \DOMDocument | [
"adds",
"footnotes",
"if",
"they",
"are",
"present",
"in",
"the",
"chapter"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L554-L598 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.findTheNode | protected function findTheNode( \DOMNode $node, $chapter_name ) {
if ( XML_ELEMENT_NODE !== $node->nodeType ) {
return '';
}
$current_tag = $node->tagName;
$current_value = trim( $node->nodeValue );
if ( $chapter_name === $current_value && $this->tag === $current_tag ) {
return $node;
}
// test
... | php | protected function findTheNode( \DOMNode $node, $chapter_name ) {
if ( XML_ELEMENT_NODE !== $node->nodeType ) {
return '';
}
$current_tag = $node->tagName;
$current_value = trim( $node->nodeValue );
if ( $chapter_name === $current_value && $this->tag === $current_tag ) {
return $node;
}
// test
... | [
"protected",
"function",
"findTheNode",
"(",
"\\",
"DOMNode",
"$",
"node",
",",
"$",
"chapter_name",
")",
"{",
"if",
"(",
"XML_ELEMENT_NODE",
"!==",
"$",
"node",
"->",
"nodeType",
")",
"{",
"return",
"''",
";",
"}",
"$",
"current_tag",
"=",
"$",
"node",
... | Recursive iterator to locate and return a specific node, targeting child nodes
@param \DOMNode $node
@param string $chapter_name
@return \DOMNode|mixed | [
"Recursive",
"iterator",
"to",
"locate",
"and",
"return",
"a",
"specific",
"node",
"targeting",
"child",
"nodes"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L608-L638 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.isValidZip | protected function isValidZip( $fullpath ) {
$result = $this->zip->open( $fullpath );
if ( true !== $result ) {
throw new \Exception( 'Opening docx file failed' );
}
// check if a document.xml exists
$path = $this->getTargetPath( self::DOCUMENT_SCHEMA );
$ok = $this->getZipContent( $path );
if ( ! ... | php | protected function isValidZip( $fullpath ) {
$result = $this->zip->open( $fullpath );
if ( true !== $result ) {
throw new \Exception( 'Opening docx file failed' );
}
// check if a document.xml exists
$path = $this->getTargetPath( self::DOCUMENT_SCHEMA );
$ok = $this->getZipContent( $path );
if ( ! ... | [
"protected",
"function",
"isValidZip",
"(",
"$",
"fullpath",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"zip",
"->",
"open",
"(",
"$",
"fullpath",
")",
";",
"if",
"(",
"true",
"!==",
"$",
"result",
")",
"{",
"throw",
"new",
"\\",
"Exception",
... | Checks for standard DOCX file structure
@param string $fullpath
@throws \Exception | [
"Checks",
"for",
"standard",
"DOCX",
"file",
"structure"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L724-L739 |
pressbooks/pressbooks | inc/modules/import/ooxml/class-docx.php | Docx.getTargetPath | protected function getTargetPath( $schema, $id = '' ) {
// The subfolder name "_rels", the file extension ".rels" are
// reserved names in an OPC package
if ( empty( $id ) ) {
$path_to_rel_doc = '_rels/.rels';
} else {
$path_to_rel_doc = 'word/_rels/document.xml.rels';
}
$relations = simplexml_load_s... | php | protected function getTargetPath( $schema, $id = '' ) {
// The subfolder name "_rels", the file extension ".rels" are
// reserved names in an OPC package
if ( empty( $id ) ) {
$path_to_rel_doc = '_rels/.rels';
} else {
$path_to_rel_doc = 'word/_rels/document.xml.rels';
}
$relations = simplexml_load_s... | [
"protected",
"function",
"getTargetPath",
"(",
"$",
"schema",
",",
"$",
"id",
"=",
"''",
")",
"{",
"// The subfolder name \"_rels\", the file extension \".rels\" are",
"// reserved names in an OPC package",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"pa... | Give it a schema, get back a path(s) that points to a resource
@param string $schema
@param string $id
@return string|array | [
"Give",
"it",
"a",
"schema",
"get",
"back",
"a",
"path",
"(",
"s",
")",
"that",
"points",
"to",
"a",
"resource"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/import/ooxml/class-docx.php#L749-L795 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-posts.php | Posts.overrideUsingFilterAndActions | protected function overrideUsingFilterAndActions() {
// The post type must have custom-fields support otherwise the meta fields will not appear in the REST API.
add_post_type_support( $this->post_type, 'custom-fields' );
add_filter( "rest_{$this->post_type}_query", [ $this, 'overrideQueryArgs' ] );
add_filter... | php | protected function overrideUsingFilterAndActions() {
// The post type must have custom-fields support otherwise the meta fields will not appear in the REST API.
add_post_type_support( $this->post_type, 'custom-fields' );
add_filter( "rest_{$this->post_type}_query", [ $this, 'overrideQueryArgs' ] );
add_filter... | [
"protected",
"function",
"overrideUsingFilterAndActions",
"(",
")",
"{",
"// The post type must have custom-fields support otherwise the meta fields will not appear in the REST API.",
"add_post_type_support",
"(",
"$",
"this",
"->",
"post_type",
",",
"'custom-fields'",
")",
";",
"a... | Use object inheritance as little as possible to future-proof against WP API changes
With the exception of the abstract \WP_REST_Controller class, the WordPress API documentation
strongly suggests not overriding controllers. Instead we are encouraged to create an entirely separate
controller class for each end point.
... | [
"Use",
"object",
"inheritance",
"as",
"little",
"as",
"possible",
"to",
"future",
"-",
"proof",
"against",
"WP",
"API",
"changes"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-posts.php#L28-L36 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-posts.php | Posts.overrideResponse | public function overrideResponse( $response, $post, $request ) {
if ( $post->post_type === 'chapter' ) {
// Add rest link to associated part
$response->add_link( 'part', trailingslashit( rest_url( sprintf( '%s/%s', $this->namespace, 'parts' ) ) ) . $post->post_parent );
}
if ( in_array( $post->post_type, ... | php | public function overrideResponse( $response, $post, $request ) {
if ( $post->post_type === 'chapter' ) {
// Add rest link to associated part
$response->add_link( 'part', trailingslashit( rest_url( sprintf( '%s/%s', $this->namespace, 'parts' ) ) ) . $post->post_parent );
}
if ( in_array( $post->post_type, ... | [
"public",
"function",
"overrideResponse",
"(",
"$",
"response",
",",
"$",
"post",
",",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"post",
"->",
"post_type",
"===",
"'chapter'",
")",
"{",
"// Add rest link to associated part",
"$",
"response",
"->",
"add_link",
... | Override the response object
@param \WP_REST_Response $response
@param \WP_Post $post
@param \WP_REST_Request $request
@return mixed | [
"Override",
"the",
"response",
"object"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-posts.php#L66-L97 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-posts.php | Posts.overrideTrashable | public function overrideTrashable( $supports_trash, $post ) {
global $wpdb;
if ( $post->post_type === 'part' && $supports_trash ) {
// Don't delete a part if it has chapters
$pids = $wpdb->get_col(
$wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND (post_status != 'trash' AND post... | php | public function overrideTrashable( $supports_trash, $post ) {
global $wpdb;
if ( $post->post_type === 'part' && $supports_trash ) {
// Don't delete a part if it has chapters
$pids = $wpdb->get_col(
$wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND (post_status != 'trash' AND post... | [
"public",
"function",
"overrideTrashable",
"(",
"$",
"supports_trash",
",",
"$",
"post",
")",
"{",
"global",
"$",
"wpdb",
";",
"if",
"(",
"$",
"post",
"->",
"post_type",
"===",
"'part'",
"&&",
"$",
"supports_trash",
")",
"{",
"// Don't delete a part if it has ... | @param bool $supports_trash
@param \WP_Post $post
@return bool | [
"@param",
"bool",
"$supports_trash",
"@param",
"\\",
"WP_Post",
"$post"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-posts.php#L105-L120 |
pressbooks/pressbooks | inc/api/endpoints/controller/class-posts.php | Posts.get_items_permissions_check | public function get_items_permissions_check( $request ) {
if ( current_user_can( 'edit_posts' ) ) {
return true;
}
if ( 1 !== absint( get_option( 'blog_public' ) ) ) {
return false;
}
return parent::get_items_permissions_check( $request );
} | php | public function get_items_permissions_check( $request ) {
if ( current_user_can( 'edit_posts' ) ) {
return true;
}
if ( 1 !== absint( get_option( 'blog_public' ) ) ) {
return false;
}
return parent::get_items_permissions_check( $request );
} | [
"public",
"function",
"get_items_permissions_check",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"current_user_can",
"(",
"'edit_posts'",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"1",
"!==",
"absint",
"(",
"get_option",
"(",
"'blog_public'",
")",
... | @param \WP_REST_Request $request Full details about the request.
@return bool|\WP_Error True if the request has read access, WP_Error object otherwise. | [
"@param",
"\\",
"WP_REST_Request",
"$request",
"Full",
"details",
"about",
"the",
"request",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/api/endpoints/controller/class-posts.php#L131-L142 |
pressbooks/pressbooks | inc/class-customcss.php | CustomCss.getCustomCssFolder | static function getCustomCssFolder() {
$path = \Pressbooks\Utility\get_media_prefix() . 'custom-css/';
if ( ! file_exists( $path ) ) {
wp_mkdir_p( $path );
}
return $path;
} | php | static function getCustomCssFolder() {
$path = \Pressbooks\Utility\get_media_prefix() . 'custom-css/';
if ( ! file_exists( $path ) ) {
wp_mkdir_p( $path );
}
return $path;
} | [
"static",
"function",
"getCustomCssFolder",
"(",
")",
"{",
"$",
"path",
"=",
"\\",
"Pressbooks",
"\\",
"Utility",
"\\",
"get_media_prefix",
"(",
")",
".",
"'custom-css/'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"wp_mkdir_p",
... | Get the fullpath to the Custom CSS folder
Create if not there.
@return string fullpath | [
"Get",
"the",
"fullpath",
"to",
"the",
"Custom",
"CSS",
"folder",
"Create",
"if",
"not",
"there",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-customcss.php#L23-L31 |
pressbooks/pressbooks | inc/class-customcss.php | CustomCss.getBaseTheme | static function getBaseTheme( $slug ) {
$filename = static::getCustomCssFolder() . sanitize_file_name( $slug . '.css' );
if ( ! file_exists( $filename ) ) {
return false;
}
$theme = get_file_data(
$filename, [
'ThemeURI' => 'Theme URI',
]
);
$theme_slug = str_replace( [ 'http://pressbooks.com/t... | php | static function getBaseTheme( $slug ) {
$filename = static::getCustomCssFolder() . sanitize_file_name( $slug . '.css' );
if ( ! file_exists( $filename ) ) {
return false;
}
$theme = get_file_data(
$filename, [
'ThemeURI' => 'Theme URI',
]
);
$theme_slug = str_replace( [ 'http://pressbooks.com/t... | [
"static",
"function",
"getBaseTheme",
"(",
"$",
"slug",
")",
"{",
"$",
"filename",
"=",
"static",
"::",
"getCustomCssFolder",
"(",
")",
".",
"sanitize_file_name",
"(",
"$",
"slug",
".",
"'.css'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filena... | Determine base theme that was used for the selected Custom CSS.
@param $slug string
@return string | [
"Determine",
"base",
"theme",
"that",
"was",
"used",
"for",
"the",
"selected",
"Custom",
"CSS",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-customcss.php#L66-L79 |
pressbooks/pressbooks | inc/shortcodes/complex/class-complex.php | Complex.hooks | static public function hooks( Complex $obj ) {
add_shortcode( 'anchor', [ $obj, 'anchorShortCodeHandler' ] );
add_shortcode( 'columns', [ $obj, 'columnsShortCodeHandler' ] );
add_shortcode( 'email', [ $obj, 'emailShortCodeHandler' ] );
add_shortcode( 'equation', [ $obj, 'equationShortCodeHandler' ] );
add_sho... | php | static public function hooks( Complex $obj ) {
add_shortcode( 'anchor', [ $obj, 'anchorShortCodeHandler' ] );
add_shortcode( 'columns', [ $obj, 'columnsShortCodeHandler' ] );
add_shortcode( 'email', [ $obj, 'emailShortCodeHandler' ] );
add_shortcode( 'equation', [ $obj, 'equationShortCodeHandler' ] );
add_sho... | [
"static",
"public",
"function",
"hooks",
"(",
"Complex",
"$",
"obj",
")",
"{",
"add_shortcode",
"(",
"'anchor'",
",",
"[",
"$",
"obj",
",",
"'anchorShortCodeHandler'",
"]",
")",
";",
"add_shortcode",
"(",
"'columns'",
",",
"[",
"$",
"obj",
",",
"'columnsSh... | Shortcode registration hooks.
@param Complex $obj | [
"Shortcode",
"registration",
"hooks",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/shortcodes/complex/class-complex.php#L35-L41 |
pressbooks/pressbooks | inc/shortcodes/complex/class-complex.php | Complex.anchorShortCodeHandler | public function anchorShortCodeHandler( $atts, $content, $shortcode ) {
if ( ! isset( $atts['id'] ) ) {
return '';
}
$atts = shortcode_atts(
[
'class' => null,
'id' => null,
],
$atts,
$shortcode
);
return sprintf(
'<a id="%1$s"%2$s%3$s></a>',
sanitize_title( $atts['id'] ),
( ... | php | public function anchorShortCodeHandler( $atts, $content, $shortcode ) {
if ( ! isset( $atts['id'] ) ) {
return '';
}
$atts = shortcode_atts(
[
'class' => null,
'id' => null,
],
$atts,
$shortcode
);
return sprintf(
'<a id="%1$s"%2$s%3$s></a>',
sanitize_title( $atts['id'] ),
( ... | [
"public",
"function",
"anchorShortCodeHandler",
"(",
"$",
"atts",
",",
"$",
"content",
",",
"$",
"shortcode",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"atts",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"atts",
"=",
"shortco... | Shortcode handler for [anchor].
@param array $atts Shortcode attributes.
@param string $content Shortcode content.
@param string $shortcode Shortcode name.
@return string | [
"Shortcode",
"handler",
"for",
"[",
"anchor",
"]",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/shortcodes/complex/class-complex.php#L58-L78 |
pressbooks/pressbooks | inc/shortcodes/complex/class-complex.php | Complex.columnsShortCodeHandler | public function columnsShortCodeHandler( $atts, $content, $shortcode ) {
if ( ! $content ) {
return '';
}
$atts = shortcode_atts(
[
'class' => null,
'count' => 2,
],
$atts,
$shortcode
);
$classes = $atts['class'] ?? '';
switch ( $atts['count'] ) {
case 2:
$classes .= ' twoco... | php | public function columnsShortCodeHandler( $atts, $content, $shortcode ) {
if ( ! $content ) {
return '';
}
$atts = shortcode_atts(
[
'class' => null,
'count' => 2,
],
$atts,
$shortcode
);
$classes = $atts['class'] ?? '';
switch ( $atts['count'] ) {
case 2:
$classes .= ' twoco... | [
"public",
"function",
"columnsShortCodeHandler",
"(",
"$",
"atts",
",",
"$",
"content",
",",
"$",
"shortcode",
")",
"{",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"return",
"''",
";",
"}",
"$",
"atts",
"=",
"shortcode_atts",
"(",
"[",
"'class'",
"=>",
... | Shortcode handler for [columns].
@param array $atts Shortcode attributes.
@param string $content Shortcode content.
@param string $shortcode Shortcode name.
@return string | [
"Shortcode",
"handler",
"for",
"[",
"columns",
"]",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/shortcodes/complex/class-complex.php#L89-L121 |
pressbooks/pressbooks | inc/shortcodes/complex/class-complex.php | Complex.emailShortCodeHandler | public function emailShortCodeHandler( $atts, $content, $shortcode ) {
$atts = shortcode_atts(
[
'class' => null,
'address' => null,
],
$atts,
$shortcode
);
$address = $atts['address'] ?? $content;
if ( ! is_email( $address ) ) {
return '';
}
if ( $address === $content ) {
retur... | php | public function emailShortCodeHandler( $atts, $content, $shortcode ) {
$atts = shortcode_atts(
[
'class' => null,
'address' => null,
],
$atts,
$shortcode
);
$address = $atts['address'] ?? $content;
if ( ! is_email( $address ) ) {
return '';
}
if ( $address === $content ) {
retur... | [
"public",
"function",
"emailShortCodeHandler",
"(",
"$",
"atts",
",",
"$",
"content",
",",
"$",
"shortcode",
")",
"{",
"$",
"atts",
"=",
"shortcode_atts",
"(",
"[",
"'class'",
"=>",
"null",
",",
"'address'",
"=>",
"null",
",",
"]",
",",
"$",
"atts",
",... | Shortcode handler for [email].
@param array $atts Shortcode attributes.
@param string $content Shortcode content.
@param string $shortcode Shortcode name.
@return string | [
"Shortcode",
"handler",
"for",
"[",
"email",
"]",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/shortcodes/complex/class-complex.php#L132-L162 |
pressbooks/pressbooks | inc/shortcodes/complex/class-complex.php | Complex.equationShortCodeHandler | public function equationShortCodeHandler( $atts, $content, $shortcode ) {
if ( ! $content ) {
return '';
}
$atts = shortcode_atts(
[
'size' => 0,
'color' => false,
'background' => false,
], $atts
);
return do_shortcode_by_tags(
sprintf(
'<p>[latex%1$s]%2$s[/latex]' . "</p>\n",
... | php | public function equationShortCodeHandler( $atts, $content, $shortcode ) {
if ( ! $content ) {
return '';
}
$atts = shortcode_atts(
[
'size' => 0,
'color' => false,
'background' => false,
], $atts
);
return do_shortcode_by_tags(
sprintf(
'<p>[latex%1$s]%2$s[/latex]' . "</p>\n",
... | [
"public",
"function",
"equationShortCodeHandler",
"(",
"$",
"atts",
",",
"$",
"content",
",",
"$",
"shortcode",
")",
"{",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"return",
"''",
";",
"}",
"$",
"atts",
"=",
"shortcode_atts",
"(",
"[",
"'size'",
"=>",
... | Shortcode handler for [equation].
@param array $atts Shortcode attributes.
@param string $content Shortcode content.
@param string $shortcode Shortcode name.
@return string | [
"Shortcode",
"handler",
"for",
"[",
"equation",
"]",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/shortcodes/complex/class-complex.php#L173-L204 |
pressbooks/pressbooks | inc/shortcodes/complex/class-complex.php | Complex.mediaShortCodeHandler | public function mediaShortCodeHandler( $atts, $content, $shortcode ) {
global $wp_embed;
$atts = shortcode_atts(
[
'caption' => null,
'src' => null,
], $atts
);
$src = $atts['src'] ?? $content;
if ( str_starts_with( $src, '“' ) || str_starts_with( $src, '”' ) || str_starts_with( $src, '‘' ) || s... | php | public function mediaShortCodeHandler( $atts, $content, $shortcode ) {
global $wp_embed;
$atts = shortcode_atts(
[
'caption' => null,
'src' => null,
], $atts
);
$src = $atts['src'] ?? $content;
if ( str_starts_with( $src, '“' ) || str_starts_with( $src, '”' ) || str_starts_with( $src, '‘' ) || s... | [
"public",
"function",
"mediaShortCodeHandler",
"(",
"$",
"atts",
",",
"$",
"content",
",",
"$",
"shortcode",
")",
"{",
"global",
"$",
"wp_embed",
";",
"$",
"atts",
"=",
"shortcode_atts",
"(",
"[",
"'caption'",
"=>",
"null",
",",
"'src'",
"=>",
"null",
",... | Shortcode handler for [media].
@param array $atts Shortcode attributes.
@param string $content Shortcode content.
@param string $shortcode Shortcode name.
@return string | [
"Shortcode",
"handler",
"for",
"[",
"media",
"]",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/shortcodes/complex/class-complex.php#L215-L242 |
pressbooks/pressbooks | inc/modules/themeoptions/class-ebookoptions.php | EbookOptions.init | function init() {
$_option = 'pressbooks_theme_options_' . $this->getSlug();
$_page = $_option;
$_section = $this->getSlug() . '_options_section';
if ( false === get_option( $_option ) ) {
add_option( $_option, $this->defaults );
}
add_settings_section(
$_section,
$this->getTitle(),
[ $this, '... | php | function init() {
$_option = 'pressbooks_theme_options_' . $this->getSlug();
$_page = $_option;
$_section = $this->getSlug() . '_options_section';
if ( false === get_option( $_option ) ) {
add_option( $_option, $this->defaults );
}
add_settings_section(
$_section,
$this->getTitle(),
[ $this, '... | [
"function",
"init",
"(",
")",
"{",
"$",
"_option",
"=",
"'pressbooks_theme_options_'",
".",
"$",
"this",
"->",
"getSlug",
"(",
")",
";",
"$",
"_page",
"=",
"$",
"_option",
";",
"$",
"_section",
"=",
"$",
"this",
"->",
"getSlug",
"(",
")",
".",
"'_opt... | Configure the ebook options tab using the settings API. | [
"Configure",
"the",
"ebook",
"options",
"tab",
"using",
"the",
"settings",
"API",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/themeoptions/class-ebookoptions.php#L57-L123 |
pressbooks/pressbooks | inc/modules/themeoptions/class-ebookoptions.php | EbookOptions.setEbookStartPoint | function setEbookStartPoint() {
$_option = $this->getSlug();
$options = get_option( 'pressbooks_theme_options_' . $_option, $this->defaults );
$struct = \Pressbooks\Book::getBookStructure();
foreach ( $struct['front-matter'] as $k => $v ) {
if ( get_post_meta( $v['ID'], 'pb_ebook_start', true ) ) {
$op... | php | function setEbookStartPoint() {
$_option = $this->getSlug();
$options = get_option( 'pressbooks_theme_options_' . $_option, $this->defaults );
$struct = \Pressbooks\Book::getBookStructure();
foreach ( $struct['front-matter'] as $k => $v ) {
if ( get_post_meta( $v['ID'], 'pb_ebook_start', true ) ) {
$op... | [
"function",
"setEbookStartPoint",
"(",
")",
"{",
"$",
"_option",
"=",
"$",
"this",
"->",
"getSlug",
"(",
")",
";",
"$",
"options",
"=",
"get_option",
"(",
"'pressbooks_theme_options_'",
".",
"$",
"_option",
",",
"$",
"this",
"->",
"defaults",
")",
";",
"... | Update values to human-readable equivalents within Ebook options. | [
"Update",
"values",
"to",
"human",
"-",
"readable",
"equivalents",
"within",
"Ebook",
"options",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/themeoptions/class-ebookoptions.php#L171-L205 |
pressbooks/pressbooks | inc/modules/themeoptions/class-ebookoptions.php | EbookOptions.renderEbookStartPointField | function renderEbookStartPointField( $args ) {
unset( $args['label_for'], $args['class'] );
$options = [
'' => '--',
];
$struct = \Pressbooks\Book::getBookStructure();
foreach ( $struct['front-matter'] as $k => $v ) {
$options[ $v['ID'] ] = $v['post_title'];
}
foreach ( $struct['part'] as $key => $... | php | function renderEbookStartPointField( $args ) {
unset( $args['label_for'], $args['class'] );
$options = [
'' => '--',
];
$struct = \Pressbooks\Book::getBookStructure();
foreach ( $struct['front-matter'] as $k => $v ) {
$options[ $v['ID'] ] = $v['post_title'];
}
foreach ( $struct['part'] as $key => $... | [
"function",
"renderEbookStartPointField",
"(",
"$",
"args",
")",
"{",
"unset",
"(",
"$",
"args",
"[",
"'label_for'",
"]",
",",
"$",
"args",
"[",
"'class'",
"]",
")",
";",
"$",
"options",
"=",
"[",
"''",
"=>",
"'--'",
",",
"]",
";",
"$",
"struct",
"... | Render the ebook_start_point dropdown.
@param array $args | [
"Render",
"the",
"ebook_start_point",
"dropdown",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/themeoptions/class-ebookoptions.php#L212-L241 |
pressbooks/pressbooks | inc/modules/themeoptions/class-ebookoptions.php | EbookOptions.renderParagraphSeparationField | function renderParagraphSeparationField( $args ) {
unset( $args['label_for'], $args['class'] );
$this->renderRadioButtons(
[
'id' => 'ebook_paragraph_separation',
'name' => 'pressbooks_theme_options_' . $this->getSlug(),
'option' => 'ebook_paragraph_separation',
'value' => ( isset( $this->options... | php | function renderParagraphSeparationField( $args ) {
unset( $args['label_for'], $args['class'] );
$this->renderRadioButtons(
[
'id' => 'ebook_paragraph_separation',
'name' => 'pressbooks_theme_options_' . $this->getSlug(),
'option' => 'ebook_paragraph_separation',
'value' => ( isset( $this->options... | [
"function",
"renderParagraphSeparationField",
"(",
"$",
"args",
")",
"{",
"unset",
"(",
"$",
"args",
"[",
"'label_for'",
"]",
",",
"$",
"args",
"[",
"'class'",
"]",
")",
";",
"$",
"this",
"->",
"renderRadioButtons",
"(",
"[",
"'id'",
"=>",
"'ebook_paragrap... | Render the ebook_paragraph_separation radio buttons.
@param array $args | [
"Render",
"the",
"ebook_paragraph_separation",
"radio",
"buttons",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/themeoptions/class-ebookoptions.php#L248-L259 |
pressbooks/pressbooks | inc/modules/themeoptions/class-ebookoptions.php | EbookOptions.renderCompressImagesField | function renderCompressImagesField( $args ) {
unset( $args['label_for'], $args['class'] );
$this->renderCheckbox(
[
'id' => 'ebook_compress_images',
'name' => 'pressbooks_theme_options_' . $this->getSlug(),
'option' => 'ebook_compress_images',
'value' => ( isset( $this->options['ebook_compress_im... | php | function renderCompressImagesField( $args ) {
unset( $args['label_for'], $args['class'] );
$this->renderCheckbox(
[
'id' => 'ebook_compress_images',
'name' => 'pressbooks_theme_options_' . $this->getSlug(),
'option' => 'ebook_compress_images',
'value' => ( isset( $this->options['ebook_compress_im... | [
"function",
"renderCompressImagesField",
"(",
"$",
"args",
")",
"{",
"unset",
"(",
"$",
"args",
"[",
"'label_for'",
"]",
",",
"$",
"args",
"[",
"'class'",
"]",
")",
";",
"$",
"this",
"->",
"renderCheckbox",
"(",
"[",
"'id'",
"=>",
"'ebook_compress_images'"... | Render the ebook_compress_images checkbox.
@param array $args | [
"Render",
"the",
"ebook_compress_images",
"checkbox",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/modules/themeoptions/class-ebookoptions.php#L266-L277 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.getSupportedTypes | public function getSupportedTypes( $disable_translation = false, $disable_custom = false ) {
if ( $disable_translation ) {
add_filter( 'gettext', [ $this, 'disableTranslation' ], 999, 3 );
}
// Supported
$supported = [
'public-domain' => [
'api' => [
'license' => 'mark',
'commercial' => 'y... | php | public function getSupportedTypes( $disable_translation = false, $disable_custom = false ) {
if ( $disable_translation ) {
add_filter( 'gettext', [ $this, 'disableTranslation' ], 999, 3 );
}
// Supported
$supported = [
'public-domain' => [
'api' => [
'license' => 'mark',
'commercial' => 'y... | [
"public",
"function",
"getSupportedTypes",
"(",
"$",
"disable_translation",
"=",
"false",
",",
"$",
"disable_custom",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"disable_translation",
")",
"{",
"add_filter",
"(",
"'gettext'",
",",
"[",
"$",
"this",
",",
"'disab... | Returns supported license types in array that looks like:
slug =>
api[],
url,
desc,
@param bool $disable_translation (optional)
@param bool $disable_custom (optional)
@return array | [
"Returns",
"supported",
"license",
"types",
"in",
"array",
"that",
"looks",
"like",
":"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L40-L159 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.doLicense | public function doLicense( $metadata, $post_id = 0, $title = '' ) {
if ( ! empty( $title ) ) {
_doing_it_wrong( __METHOD__, __( '$title is deprecated. Method will automatically determine title from licenses', 'pressbooks' ), 'Pressbooks 5.7.0' );
}
$book_license = isset( $metadata['pb_book_license'] ) ? $meta... | php | public function doLicense( $metadata, $post_id = 0, $title = '' ) {
if ( ! empty( $title ) ) {
_doing_it_wrong( __METHOD__, __( '$title is deprecated. Method will automatically determine title from licenses', 'pressbooks' ), 'Pressbooks 5.7.0' );
}
$book_license = isset( $metadata['pb_book_license'] ) ? $meta... | [
"public",
"function",
"doLicense",
"(",
"$",
"metadata",
",",
"$",
"post_id",
"=",
"0",
",",
"$",
"title",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"title",
")",
")",
"{",
"_doing_it_wrong",
"(",
"__METHOD__",
",",
"__",
"(",
"'$titl... | Will create an html blob of copyright information, returns empty string
if license not supported
@param array $metadata \Pressbooks\Book::getBookInformation
@param int $post_id (optional)
@param string $title (@deprecated)
@return string | [
"Will",
"create",
"an",
"html",
"blob",
"of",
"copyright",
"information",
"returns",
"empty",
"string",
"if",
"license",
"not",
"supported"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L193-L258 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.getLicenseXml | public function getLicenseXml( $type, $copyright_holder, $src_url, $title, $lang = '', $year = 0 ) {
$endpoint = 'https://api.creativecommons.org/rest/1.5/';
$lang = ( ! empty( $lang ) ) ? substr( $lang, 0, 2 ) : '';
$expected = $this->getSupportedTypes();
if ( ! array_key_exists( $type, $expected ) ) {
//... | php | public function getLicenseXml( $type, $copyright_holder, $src_url, $title, $lang = '', $year = 0 ) {
$endpoint = 'https://api.creativecommons.org/rest/1.5/';
$lang = ( ! empty( $lang ) ) ? substr( $lang, 0, 2 ) : '';
$expected = $this->getSupportedTypes();
if ( ! array_key_exists( $type, $expected ) ) {
//... | [
"public",
"function",
"getLicenseXml",
"(",
"$",
"type",
",",
"$",
"copyright_holder",
",",
"$",
"src_url",
",",
"$",
"title",
",",
"$",
"lang",
"=",
"''",
",",
"$",
"year",
"=",
"0",
")",
"{",
"$",
"endpoint",
"=",
"'https://api.creativecommons.org/rest/1... | Takes a known string from metadata, builds a url to hit an api which returns an xml response
@see https://api.creativecommons.org/docs/readme_15.html
@deprecated 5.3.0
@deprecated No longer used by internal code and no longer recommended.
@param string $type license type
@param string $copyright_holder of the page
@... | [
"Takes",
"a",
"known",
"string",
"from",
"metadata",
"builds",
"a",
"url",
"to",
"hit",
"an",
"api",
"which",
"returns",
"an",
"xml",
"response"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L277-L337 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.getLicenseHtml | public function getLicenseHtml( \SimpleXMLElement $response, $except_where_otherwise_noted = true ) {
$content = $response->asXML();
$content = trim( str_replace( [ '<p xmlns:dct="http://purl.org/dc/terms/">', '</p>', '<html>', '</html>' ], '', $content ) );
$content = preg_replace( '/http:\/\/i.creativecommons/... | php | public function getLicenseHtml( \SimpleXMLElement $response, $except_where_otherwise_noted = true ) {
$content = $response->asXML();
$content = trim( str_replace( [ '<p xmlns:dct="http://purl.org/dc/terms/">', '</p>', '<html>', '</html>' ], '', $content ) );
$content = preg_replace( '/http:\/\/i.creativecommons/... | [
"public",
"function",
"getLicenseHtml",
"(",
"\\",
"SimpleXMLElement",
"$",
"response",
",",
"$",
"except_where_otherwise_noted",
"=",
"true",
")",
"{",
"$",
"content",
"=",
"$",
"response",
"->",
"asXML",
"(",
")",
";",
"$",
"content",
"=",
"trim",
"(",
"... | Returns an HTML blob if given an XML object
@deprecated 5.3.0
@deprecated No longer used by internal code and no longer recommended.
@param \SimpleXMLElement $response
@param $except_where_otherwise_noted bool (optional)
@return string $html blob of copyright information | [
"Returns",
"an",
"HTML",
"blob",
"if",
"given",
"an",
"XML",
"object"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L350-L365 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.getLicense | public function getLicense( $license, $copyright_holder, $link, $title, $copyright_year ) {
if ( ! $this->isSupportedType( $license ) ) {
return sprintf(
'<div class="license-attribution"><p>%s</p></div>',
sprintf(
__( '%1$s Copyright ©%2$s by %3$s. All Rights Reserved.', 'pressbooks' ),
$ti... | php | public function getLicense( $license, $copyright_holder, $link, $title, $copyright_year ) {
if ( ! $this->isSupportedType( $license ) ) {
return sprintf(
'<div class="license-attribution"><p>%s</p></div>',
sprintf(
__( '%1$s Copyright ©%2$s by %3$s. All Rights Reserved.', 'pressbooks' ),
$ti... | [
"public",
"function",
"getLicense",
"(",
"$",
"license",
",",
"$",
"copyright_holder",
",",
"$",
"link",
",",
"$",
"title",
",",
"$",
"copyright_year",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isSupportedType",
"(",
"$",
"license",
")",
")",
"{",
... | Returns an HTML blob for a supported license.
@since 5.3.0
@param string $license license type
@param string $copyright_holder of the page
@param string $link of the page
@param string $title of the page
@param int $copyright_year (optional)
@return string $html License blob. | [
"Returns",
"an",
"HTML",
"blob",
"for",
"a",
"supported",
"license",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L380-L445 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.getLicenseFromUrl | public function getLicenseFromUrl( $url ) {
$licenses = $this->getSupportedTypes();
foreach ( $licenses as $license => $v ) {
if ( $url === $v['url'] ) {
return $license;
}
}
return 'all-rights-reserved';
} | php | public function getLicenseFromUrl( $url ) {
$licenses = $this->getSupportedTypes();
foreach ( $licenses as $license => $v ) {
if ( $url === $v['url'] ) {
return $license;
}
}
return 'all-rights-reserved';
} | [
"public",
"function",
"getLicenseFromUrl",
"(",
"$",
"url",
")",
"{",
"$",
"licenses",
"=",
"$",
"this",
"->",
"getSupportedTypes",
"(",
")",
";",
"foreach",
"(",
"$",
"licenses",
"as",
"$",
"license",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"url",... | Returns Book Information-compatible license value from URL.
@since 4.1.0
@param string
@return string | [
"Returns",
"Book",
"Information",
"-",
"compatible",
"license",
"value",
"from",
"URL",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L473-L482 |
pressbooks/pressbooks | inc/class-licensing.php | Licensing.getNameForLicense | public function getNameForLicense( $license ) {
$types = $this->getSupportedTypes();
if ( $this->isSupportedType( $license ) ) {
if ( isset( $types[ $license ]['longdesc'] ) ) {
return $types[ $license ]['longdesc'];
} else {
return $types[ $license ]['desc'];
}
} else {
return $types['all-ri... | php | public function getNameForLicense( $license ) {
$types = $this->getSupportedTypes();
if ( $this->isSupportedType( $license ) ) {
if ( isset( $types[ $license ]['longdesc'] ) ) {
return $types[ $license ]['longdesc'];
} else {
return $types[ $license ]['desc'];
}
} else {
return $types['all-ri... | [
"public",
"function",
"getNameForLicense",
"(",
"$",
"license",
")",
"{",
"$",
"types",
"=",
"$",
"this",
"->",
"getSupportedTypes",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isSupportedType",
"(",
"$",
"license",
")",
")",
"{",
"if",
"(",
"isset",... | Returns long description for saved license value.
@since 5.3.0
@param string
@return string | [
"Returns",
"long",
"description",
"for",
"saved",
"license",
"value",
"."
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-licensing.php#L493-L505 |
pressbooks/pressbooks | inc/class-styles.php | Styles.init | public function init() {
if ( ! Book::isBook() ) {
// Not a book, disable
return;
}
if ( class_exists( '\Pressbooks\CustomCss' ) && CustomCss::isCustomCss() ) {
// Uses old Custom CSS Editor, disable
return;
}
// Code Mirror
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] === $this::PAGE ... | php | public function init() {
if ( ! Book::isBook() ) {
// Not a book, disable
return;
}
if ( class_exists( '\Pressbooks\CustomCss' ) && CustomCss::isCustomCss() ) {
// Uses old Custom CSS Editor, disable
return;
}
// Code Mirror
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] === $this::PAGE ... | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"!",
"Book",
"::",
"isBook",
"(",
")",
")",
"{",
"// Not a book, disable",
"return",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'\\Pressbooks\\CustomCss'",
")",
"&&",
"CustomCss",
"::",
"isCustomCss",
... | Set filters & hooks | [
"Set",
"filters",
"&",
"hooks"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-styles.php#L63-L100 |
pressbooks/pressbooks | inc/class-styles.php | Styles.initPosts | public function initPosts() {
/** @var $wpdb \wpdb */
global $wpdb;
$posts = [
[
'post_title' => __( 'Custom Style for Ebook', 'pressbooks' ),
'post_name' => 'epub',
'post_type' => 'custom-style',
],
[
'post_title' => __( 'Custom Style for PDF', 'pressbooks' ),
'post_name' => 'princ... | php | public function initPosts() {
/** @var $wpdb \wpdb */
global $wpdb;
$posts = [
[
'post_title' => __( 'Custom Style for Ebook', 'pressbooks' ),
'post_name' => 'epub',
'post_type' => 'custom-style',
],
[
'post_title' => __( 'Custom Style for PDF', 'pressbooks' ),
'post_name' => 'princ... | [
"public",
"function",
"initPosts",
"(",
")",
"{",
"/** @var $wpdb \\wpdb */",
"global",
"$",
"wpdb",
";",
"$",
"posts",
"=",
"[",
"[",
"'post_title'",
"=>",
"__",
"(",
"'Custom Style for Ebook'",
",",
"'pressbooks'",
")",
",",
"'post_name'",
"=>",
"'epub'",
",... | Custom style rules will be saved in a custom post type: custom-style | [
"Custom",
"style",
"rules",
"will",
"be",
"saved",
"in",
"a",
"custom",
"post",
"type",
":",
"custom",
"-",
"style"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-styles.php#L105-L145 |
pressbooks/pressbooks | inc/class-styles.php | Styles.registerPosts | public function registerPosts() {
$args = [
'exclude_from_search' => true,
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
'supports' => [ 'revisions' ],
'label' => 'Custom Style',
'can_export' => false,
'rewrite' => false,
'capability_type' => 'page',
'capabilities... | php | public function registerPosts() {
$args = [
'exclude_from_search' => true,
'public' => false,
'publicly_queryable' => false,
'show_ui' => false,
'supports' => [ 'revisions' ],
'label' => 'Custom Style',
'can_export' => false,
'rewrite' => false,
'capability_type' => 'page',
'capabilities... | [
"public",
"function",
"registerPosts",
"(",
")",
"{",
"$",
"args",
"=",
"[",
"'exclude_from_search'",
"=>",
"true",
",",
"'public'",
"=>",
"false",
",",
"'publicly_queryable'",
"=>",
"false",
",",
"'show_ui'",
"=>",
"false",
",",
"'supports'",
"=>",
"[",
"'r... | Custom style rules will be saved in a custom post type: custom-style | [
"Custom",
"style",
"rules",
"will",
"be",
"saved",
"in",
"a",
"custom",
"post",
"type",
":",
"custom",
"-",
"style"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-styles.php#L150-L172 |
pressbooks/pressbooks | inc/class-styles.php | Styles.getPost | public function getPost( $slug ) {
// Supported post names (ie. slugs)
$supported = array_keys( $this->supported );
if ( ! in_array( $slug, $supported, true ) ) {
return false;
}
$args = [
'name' => $slug,
'post_type' => 'custom-style',
'posts_per_page' => 1,
'post_status' => 'publish',
'o... | php | public function getPost( $slug ) {
// Supported post names (ie. slugs)
$supported = array_keys( $this->supported );
if ( ! in_array( $slug, $supported, true ) ) {
return false;
}
$args = [
'name' => $slug,
'post_type' => 'custom-style',
'posts_per_page' => 1,
'post_status' => 'publish',
'o... | [
"public",
"function",
"getPost",
"(",
"$",
"slug",
")",
"{",
"// Supported post names (ie. slugs)",
"$",
"supported",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"supported",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"slug",
",",
"$",
"supported",
","... | @param string $slug post_name
@return \WP_Post|false | [
"@param",
"string",
"$slug",
"post_name"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-styles.php#L200-L226 |
pressbooks/pressbooks | inc/class-styles.php | Styles.getPathToScss | public function getPathToScss( $type, $theme = null ) {
if ( null === $theme ) {
$theme = wp_get_theme();
}
if ( $this->isCurrentThemeCompatible( 1, $theme ) ) {
if ( 'web' === $type ) {
$path_to_style = realpath( $this->getDir( $theme ) . '/style.scss' );
} else {
$path_to_style = realpath( $t... | php | public function getPathToScss( $type, $theme = null ) {
if ( null === $theme ) {
$theme = wp_get_theme();
}
if ( $this->isCurrentThemeCompatible( 1, $theme ) ) {
if ( 'web' === $type ) {
$path_to_style = realpath( $this->getDir( $theme ) . '/style.scss' );
} else {
$path_to_style = realpath( $t... | [
"public",
"function",
"getPathToScss",
"(",
"$",
"type",
",",
"$",
"theme",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"theme",
")",
"{",
"$",
"theme",
"=",
"wp_get_theme",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isCurrentThem... | Fullpath to SCSS file
@param string $type
@param \WP_Theme $theme (optional)
@return string|false | [
"Fullpath",
"to",
"SCSS",
"file"
] | train | https://github.com/pressbooks/pressbooks/blob/1a2294414a3abb7b97c5b669cee72470a8fb5806/inc/class-styles.php#L295-L314 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.