Esempio n. 1
0
/**
 * Displays the Edit CSS Page
 */
function display_custom_css()
{
    $custom_css = new CustomCss();
    $slug = isset($_GET['slug']) ? $_GET['slug'] : get_transient('pb-last-custom-css-slug');
    if (!$slug) {
        $slug = 'web';
    }
    $supported = array_keys($custom_css->supported);
    if (!in_array($slug, $supported)) {
        wp_die("Unknown slug: {$slug}");
    }
    $css_post = $custom_css->getPost($slug);
    if (false === $css_post) {
        wp_die(sprintf(__('Unexpected Error: There was a problem trying to query slug: %s - Please contact technical support.', 'pressbooks'), $slug));
    }
    $vars = array('slugs_dropdown' => render_dropdown_for_slugs($custom_css, $slug), 'css_copy_dropdown' => render_dropdown_for_css_copy($custom_css, $slug), 'revisions_table' => render_revisions_table($custom_css, $slug, $css_post->ID), 'post_id' => absint($css_post->ID), 'my_custom_css' => $css_post->post_content);
    load_custom_css_template($vars);
    set_transient('pb-last-custom-css-slug', $slug);
}
 /**
  * Configure the PDF options tab using the settings API.
  */
 function init()
 {
     $_page = $_option = 'pressbooks_theme_options_' . $this->getSlug();
     $_section = $this->getSlug() . '_options_section';
     if (false == get_option($_option)) {
         add_option($_option, $this->defaults);
     }
     add_settings_section($_section, $this->getTitle(), array($this, 'display'), $_page);
     if (\Pressbooks\Container::get('Sass')->isCurrentThemeCompatible(2)) {
         add_settings_field('pdf_body_font_size', __('Body Font Size', 'pressbooks'), array($this, 'renderBodyFontSizeField'), $_page, $_section, array(__('Heading sizes are proportional to the body font size and will also be affected by this setting.', 'pressbooks'), 'pt'));
         add_settings_field('pdf_body_line_height', __('Body Line Height', 'pressbooks'), array($this, 'renderBodyLineHightField'), $_page, $_section, array('', 'em'));
     }
     add_settings_field('pdf_page_size', __('Page Size', 'pressbooks'), array($this, 'renderPageSizeField'), $_page, $_section, array(__('Digest (5.5" × 8.5")', 'pressbooks'), __('US Trade (6" × 9")', 'pressbooks'), __('US Letter (8.5" × 11")', 'pressbooks'), __('Custom (8.5" × 9.25")', 'pressbooks'), __('Duodecimo (5" × 7.75")', 'pressbooks'), __('Pocket (4.25" × 7")', 'pressbooks'), __('A4 (21cm × 29.7cm)', 'pressbooks'), __('A5 (14.8cm × 21cm)', 'pressbooks'), __('5" × 8"', 'pressbooks'), __('Custom…', 'pressbooks')));
     add_settings_field('pdf_page_width', __('Page Width', 'pressbooks'), array($this, 'renderPageWidthField'), $_page, $_section, array(__('Page width must be expressed in CSS-compatible units, e.g. ‘5.5in’ or ‘10cm’.')));
     add_settings_field('pdf_page_height', __('Page Height', 'pressbooks'), array($this, 'renderPageHeightField'), $_page, $_section, array(__('Page height must be expressed in CSS-compatible units, e.g. ‘8.5in’ or ‘10cm’.')));
     if (\Pressbooks\Container::get('Sass')->isCurrentThemeCompatible(2)) {
         add_settings_field('pdf_page_margins', __('Margins', 'pressbooks'), array($this, 'renderMarginsField'), $_page, $_section, array(__('Customize your book’s margins using the fields below.', 'pressbooks')));
         add_settings_field('pdf_page_margin_outside', __('Outside Margin', 'pressbooks'), array($this, 'renderOutsideMarginField'), $_page, $_section, array(__('Margins must be expressed in CSS-compatible units, e.g. ‘8.5in’ or ‘10cm’.', 'pressbooks')));
         add_settings_field('pdf_page_margin_inside', __('Inside Margin', 'pressbooks'), array($this, 'renderInsideMarginField'), $_page, $_section, array(__('Margins must be expressed in CSS-compatible units, e.g. ‘8.5in’ or ‘10cm’.', 'pressbooks')));
         add_settings_field('pdf_page_margin_top', __('Top Margin', 'pressbooks'), array($this, 'renderTopMarginField'), $_page, $_section, array(__('Margins must be expressed in CSS-compatible units, e.g. ‘8.5in’ or ‘10cm’.', 'pressbooks')));
         add_settings_field('pdf_page_margin_bottom', __('Bottom Margin', 'pressbooks'), array($this, 'renderBottomMarginField'), $_page, $_section, array(__('Margins must be expressed in CSS-compatible units, e.g. ‘8.5in’ or ‘10cm’.', 'pressbooks')));
     }
     add_settings_field('pdf_hyphens', __('Hyphens', 'pressbooks'), array($this, 'renderHyphenationField'), $_page, $_section, array(__('Enable hyphenation', 'pressbooks')));
     add_settings_field('pdf_paragraph_separation', __('Paragraph Separation', 'pressbooks'), array($this, 'renderParagraphSeparationField'), $_page, $_section, array('indent' => __('Indent paragraphs', 'pressbooks'), 'skiplines' => __('Skip lines between paragraphs', 'pressbooks')));
     add_settings_field('pdf_blankpages', __('Blank Pages', 'pressbooks'), array($this, 'renderBlankPagesField'), $_page, $_section, array('include' => __('Include blank pages (for print PDF)', 'pressbooks'), 'remove' => __('Remove all blank pages (for web PDF)', 'pressbooks')));
     add_settings_field('pdf_toc', __('Table of Contents', 'pressbooks'), array($this, 'renderTOCField'), $_page, $_section, array(__('Display table of contents', 'pressbooks')));
     add_settings_field('pdf_image_resolution', __('Image resolution', 'pressbooks'), array($this, 'renderImageResolutionField'), $_page, $_section, array('300dpi' => __('High (300 DPI)', 'pressbooks'), '72dpi' => __('Low (72 DPI)', 'pressbooks')));
     add_settings_field('pdf_crop_marks', __('Crop Marks', 'pressbooks'), array($this, 'renderCropMarksField'), $_page, $_section, array(__('Display crop marks', 'pressbooks')));
     if (CustomCss::isCustomCss()) {
         add_settings_field('pdf_romanize_parts', __('Romanize Part Numbers', 'pressbooks'), array($this, 'renderRomanizePartsField'), $_page, $_section, array(__('Convert part numbers into Roman numerals', 'pressbooks')));
     }
     add_settings_field('pdf_footnotes_style', __('Footnote Style', 'pressbooks'), array($this, 'renderFootnoteStyleField'), $_page, $_section, array('footnotes' => __('Regular footnotes', 'pressbooks'), 'endnotes' => __('Display as chapter endnotes', 'pressbooks')));
     add_settings_field('widows', __('Widows', 'pressbooks'), array($this, 'renderWidowsField'), $_page, $_section);
     add_settings_field('orphans', __('Orphans', 'pressbooks'), array($this, 'renderOrphansField'), $_page, $_section);
     if (\Pressbooks\Container::get('Sass')->isCurrentThemeCompatible(2)) {
         add_settings_field('running_content', __('Running Heads & Feet', 'pressbooks'), array($this, 'renderRunningContentField'), $_page, $_section, array(__('Running content appears in either running heads or running feet (at the top or bottom of the page) depending on your theme.', 'pressbooks')));
         add_settings_field('running_content_front_matter_left', __('Front Matter Left Page Running Content', 'pressbooks'), array($this, 'renderRunningContentFrontMatterLeftField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%section_title%' => __('Front Matter Title', 'pressbooks'), '%section_author%' => __('Front Matter Author', 'pressbooks'), '%section_subtitle%' => __('Front Matter Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_front_matter_right', __('Front Matter Right Page Running Content', 'pressbooks'), array($this, 'renderRunningContentFrontMatterRightField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%section_title%' => __('Front Matter Title', 'pressbooks'), '%section_author%' => __('Front Matter Author', 'pressbooks'), '%section_subtitle%' => __('Front Matter Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_introduction_left', __('Introduction Left Page Running Content', 'pressbooks'), array($this, 'renderRunningContentIntroductionLeftField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%section_title%' => __('Introduction Title', 'pressbooks'), '%section_author%' => __('Introduction Author', 'pressbooks'), '%section_subtitle%' => __('Introduction Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_introduction_right', __('Introduction Right Page Running Content', 'pressbooks'), array($this, 'renderRunningContentIntroductionRightField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%section_title%' => __('Introduction Title', 'pressbooks'), '%section_author%' => __('Introduction Author', 'pressbooks'), '%section_subtitle%' => __('Introduction Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_part_left', __('Part Left Page Running Content', 'pressbooks'), array($this, 'renderRunningContentPartLeftField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%part_number%' => __('Part Number', 'pressbooks'), '%part_title%' => __('Part Title', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_part_right', __('Part Right Page Running Content', 'pressbooks'), array($this, 'renderRunningContentPartRightField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%part_number%' => __('Part Number', 'pressbooks'), '%part_title%' => __('Part Title', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_chapter_left', __('Chapter Left Page Running Content', 'pressbooks'), array($this, 'renderRunningContentChapterLeftField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%part_number%' => __('Part Number', 'pressbooks'), '%part_title%' => __('Part Title', 'pressbooks'), '%section_title%' => __('Chapter Title', 'pressbooks'), '%section_author%' => __('Chapter Author', 'pressbooks'), '%section_subtitle%' => __('Chapter Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_chapter_right', __('Chapter Right Page Running Content', 'pressbooks'), array($this, 'renderRunningContentChapterRightField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%part_number%' => __('Part Number', 'pressbooks'), '%part_title%' => __('Part Title', 'pressbooks'), '%section_title%' => __('Chapter Title', 'pressbooks'), '%section_author%' => __('Chapter Author', 'pressbooks'), '%section_subtitle%' => __('Chapter Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_back_matter_left', __('Back Matter Left Page Running Content', 'pressbooks'), array($this, 'renderRunningContentBackMatterLeftField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%section_title%' => __('Back Matter Title', 'pressbooks'), '%section_author%' => __('Back Matter Author', 'pressbooks'), '%section_subtitle%' => __('Back Matter Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
         add_settings_field('running_content_back_matter_right', __('Back Matter Right Page Running Content', 'pressbooks'), array($this, 'renderRunningContentBackMatterRightField'), $_page, $_section, array('%book_title%' => __('Book Title', 'pressbooks'), '%book_subtitle%' => __('Book Subtitle', 'pressbooks'), '%book_author%' => __('Book Author', 'pressbooks'), '%section_title%' => __('Back Matter Title', 'pressbooks'), '%section_author%' => __('Back Matter Author', 'pressbooks'), '%section_subtitle%' => __('Back Matter Subtitle', 'pressbooks'), '%blank%' => __('Blank', 'pressbooks'), '' => __('Custom…', 'pressbooks')));
     }
     if (!\Pressbooks\Container::get('Sass')->isCurrentThemeCompatible(2)) {
         add_settings_field('pdf_fontsize', __('Increase Font Size', 'pressbooks'), array($this, 'renderFontSizeField'), $_page, $_section, array(__('Increases font size and line height for greater accessibility', 'pressbooks')));
     }
     register_setting($_option, $_option, array($this, 'sanitize'));
 }
Esempio n. 3
0
/**
 * Shortcut to \PressBooks\CustomCss::isCustomCss();
 *
 * @return bool
 */
function pb_is_custom_theme()
{
    return \PressBooks\CustomCss::isCustomCss();
}
Esempio n. 4
0
function pressbooks_theme_options_pdf_init()
{
    $_page = $_option = 'pressbooks_theme_options_pdf';
    $_section = 'pdf_options_section';
    $defaults = array('pdf_page_size' => 1, 'pdf_paragraph_separation' => 1, 'pdf_blankpages' => 1, 'pdf_toc' => 1, 'pdf_romanize_parts' => 0, 'pdf_footnotes_style' => 1, 'pdf_crop_marks' => 0, 'pdf_hyphens' => 0, 'widows' => 2, 'orphans' => 1, 'pdf_fontsize' => 0);
    if (false == get_option($_option)) {
        add_option($_option, $defaults);
    }
    add_settings_section($_section, __('PDF Options', 'pressbooks'), 'pressbooks_theme_options_pdf_callback', $_page);
    add_settings_field('pdf_page_size', __('Page Size', 'pressbooks'), 'pressbooks_theme_pdf_page_size_callback', $_page, $_section, array(__('Digest (5.5" × 8.5")', 'pressbooks'), __('US Trade (6" × 9")', 'pressbooks'), __('US Letter (8.5" × 11")', 'pressbooks'), __('Custom (8.5" × 9.25")', 'pressbooks'), __('Duodecimo (5" × 7.75")', 'pressbooks'), __('Pocket (4.25" × 7")', 'pressbooks'), __('A4 (21cm × 29.7cm)', 'pressbooks'), __('A5 (14.8cm × 21cm)', 'pressbooks'), __('5" × 8"', 'pressbooks')));
    add_settings_field('pdf_crop_marks', __('Crop Marks', 'pressbooks'), 'pressbooks_theme_pdf_crop_marks_callback', $_page, $_section, array(__('Display crop marks', 'pressbooks')));
    add_settings_field('pdf_hyphens', __('Hyphens', 'pressbooks'), 'pressbooks_theme_pdf_hyphens_callback', $_page, $_section, array(__('Enable hyphenation', 'pressbooks')));
    add_settings_field('pdf_paragraph_separation', __('Paragraph Separation', 'pressbooks'), 'pressbooks_theme_pdf_paragraph_separation_callback', $_page, $_section, array(__('Indent paragraphs', 'pressbooks'), __('Skip lines between paragraphs', 'pressbooks')));
    add_settings_field('pdf_blankpages', __('Blank Pages', 'pressbooks'), 'pressbooks_theme_pdf_blankpages_callback', $_page, $_section, array(__('Include blank pages (for print PDF)', 'pressbooks'), __('Remove all blank pages (for web PDF)', 'pressbooks')));
    add_settings_field('pdf_toc', __('Table of Contents', 'pressbooks'), 'pressbooks_theme_pdf_toc_callback', $_page, $_section, array(__('Display table of contents', 'pressbooks')));
    if (CustomCss::isCustomCss()) {
        add_settings_field('pdf_romanize_parts', __('Romanize Part Numbers', 'pressbooks'), 'pressbooks_theme_pdf_romanize_parts_callback', $_page, $_section, array(__('Convert part numbers into Roman numerals', 'pressbooks')));
    }
    add_settings_field('pdf_footnotes_style', __('Footnotes Style', 'pressbooks'), 'pressbooks_theme_pdf_footnotes_callback', $_page, $_section, array(__('Regular footnotes', 'pressbooks'), __('Force as endnotes', 'pressbooks')));
    add_settings_field('widows', __('Widows', 'pressbooks'), 'pressbooks_theme_pdf_widows_callback', $_page, $_section);
    add_settings_field('orphans', __('Orphans', 'pressbooks'), 'pressbooks_theme_pdf_orphans_callback', $_page, $_section);
    add_settings_field('pdf_fontsize', __('Increase Font Size', 'pressbooks'), 'pressbooks_theme_pdf_fontsize_callback', $_page, $_section, array(__('Increases font size and line height for greater accessibility', 'pressbooks')));
    register_setting($_option, $_option, 'pressbooks_theme_options_pdf_sanitize');
}
Esempio n. 5
0
 /**
  * Return the fullpath to an export module's Javascript file.
  *
  * @param string $type
  *
  * @return string
  */
 function getExportScriptPath($type)
 {
     $fullpath = false;
     if (CustomCss::isCustomCss()) {
         $fullpath = CustomCss::getCustomCssFolder() . "/{$type}.js";
         if (!is_file($fullpath)) {
             $fullpath = false;
         }
     }
     if (!$fullpath) {
         $fullpath = realpath(get_stylesheet_directory() . "/export/{$type}/script.js");
         if (CustomCss::isCustomCss() && CustomCss::isRomanized() && $type == 'prince') {
             $fullpath = realpath(get_stylesheet_directory() . "/export/{$type}/script-romanize.js");
         }
     }
     return $fullpath;
 }
Esempio n. 6
0
 /**
  * Return the fullpath to an export module's Javascript file.
  *
  * @param string $type
  *
  * @return string
  */
 function getExportScriptPath($type)
 {
     $fullpath = false;
     if (CustomCss::isCustomCss()) {
         $fullpath = CustomCss::getCustomCssFolder() . "/{$type}.js";
         if (!is_file($fullpath)) {
             $fullpath = false;
         }
     }
     if (!$fullpath) {
         if (Container::get('Sass')->isCurrentThemeCompatible(2)) {
             // Check for v2 themes
             $fullpath = realpath(get_stylesheet_directory() . "/assets/scripts/{$type}/script.js");
         } else {
             $fullpath = realpath(get_stylesheet_directory() . "/export/{$type}/script.js");
         }
         if (CustomCss::isCustomCss() && CustomCss::isRomanized() && 'prince' == $type) {
             $fullpath = realpath(get_stylesheet_directory() . "/export/{$type}/script-romanize.js");
         }
     }
     return $fullpath;
 }