id === 'post' || $screen->id === 'page') { if ($library === 'prism') { prismatic_prism_enqueue(); } elseif ($library === 'highlight') { prismatic_highlight_enqueue(); } } } else { if ($library === 'prism') { prismatic_prism_enqueue(); } elseif ($library === 'highlight') { prismatic_highlight_enqueue(); } } } function prismatic_enqueue_settings() { $screen = get_current_screen(); if (!property_exists($screen, 'id')) return; if ($screen->id === 'settings_page_prismatic') { wp_enqueue_style('prismatic-font-icons', PRISMATIC_URL .'css/styles-font-icons.css', array(), null); wp_enqueue_style('prismatic-settings', PRISMATIC_URL .'css/styles-settings.css', array(), null); wp_enqueue_style('wp-jquery-ui-dialog'); $js_deps = array('jquery', 'jquery-ui-core', 'jquery-ui-dialog'); wp_enqueue_script('prismatic-settings', PRISMATIC_URL .'js/scripts-settings.js', $js_deps, null); $data = prismatic_get_vars_admin(); wp_localize_script('prismatic-settings', 'prismatic_settings', $data); } } function prismatic_enqueue_buttons() { $screen = get_current_screen(); if (!property_exists($screen, 'id')) return; if ($screen->id === 'post' || $screen->id === 'page') { wp_enqueue_style('prismatic-buttons', PRISMATIC_URL .'css/styles-buttons.css', array(), null); } } function prismatic_get_vars_admin() { $data = array( 'reset_title' => __('Confirm Reset', 'prismatic'), 'reset_message' => __('Restore default options?', 'prismatic'), 'reset_true' => __('Yes, make it so.', 'prismatic'), 'reset_false' => __('No, abort mission.', 'prismatic'), ); return $data; } function prismatic_prism_enqueue() { global $prismatic_options_prism; if (isset($prismatic_options_prism['singular_only']) && $prismatic_options_prism['singular_only'] && !is_singular() && !is_admin()) return; $languages = prismatic_active_languages('prism'); $languages = array_filter($languages); if (!empty($languages)) { $theme = (isset($prismatic_options_prism['prism_theme'])) ? $prismatic_options_prism['prism_theme'] : 'default'; wp_enqueue_style('prismatic-prism', PRISMATIC_URL .'lib/prism/css/theme-'. $theme .'.css', array(), null, 'all'); wp_enqueue_script('prismatic-prism', PRISMATIC_URL .'lib/prism/js/prism-core.js', array(), null, true); if (isset($prismatic_options_prism['line_highlight']) && $prismatic_options_prism['line_highlight']) { wp_enqueue_script('prismatic-prism-line-highlight', PRISMATIC_URL .'lib/prism/js/plugin-line-highlight.js', array('prismatic-prism'), null, true); } if (isset($prismatic_options_prism['line_numbers']) && $prismatic_options_prism['line_numbers']) { wp_enqueue_script('prismatic-prism-line-numbers', PRISMATIC_URL .'lib/prism/js/plugin-line-numbers.js', array('prismatic-prism'), null, true); } if (isset($prismatic_options_prism['show_language']) && $prismatic_options_prism['show_language']) { wp_enqueue_script('prismatic-prism-show-language', PRISMATIC_URL .'lib/prism/js/plugin-show-language.js', array('prismatic-prism'), null, true); } $prefix = array('lang-', 'language-'); foreach ($languages as $language) { $language = str_replace($prefix, '', $language); $file = PRISMATIC_DIR . 'lib/prism/js/lang-'. $language .'.js'; if (file_exists($file)) { wp_enqueue_script('prismatic-prism-'. $language, PRISMATIC_URL .'lib/prism/js/lang-'. $language .'.js', array('prismatic-prism'), null, true); } } if (is_admin()) { // todo: once gutenberg is further developed, find a better way to add editor support function prismatic_prism_inline_js() { ?> post_content; $languages = prismatic_active_languages_loop($library, '', $content, array()); } else { if (is_singular()) { $excerpt = $post->post_excerpt; $content = $post->post_content; $comments = ($post->comment_count) ? get_comments(array('post_id' => $post->ID, 'status' => 'approve')) : array(); $languages = prismatic_active_languages_loop($library, $excerpt, $content, $comments); } else { foreach ($posts as $post) { $excerpt = $post->post_excerpt; $content = $post->post_content; $comments = array(); $langs_array[] = prismatic_active_languages_loop($library, $excerpt, $content, $comments); } if (!empty($langs_array) && is_array($langs_array)) { foreach($langs_array as $key => $value) { foreach ($value as $k => $v) { $languages[] = $v; } } } } } return $languages; } function prismatic_active_languages_loop($library, $excerpt, $content, $comments) { $languages = array(); $classes = ($library === 'prism') ? prismatic_prism_classes() : prismatic_highlight_classes(); foreach ($classes as $class) { foreach($class as $cls) { if (strpos($excerpt, $cls) !== false) { $languages[] = $cls; } if (strpos($content, $cls) !== false) { $languages[] = $cls; } foreach ($comments as $comment) { if (strpos($comment->comment_content, $cls) !== false) { $languages[] = $cls; } } } } $languages = array_unique($languages); return $languages; } function prismatic_prism_classes() { $classes = array( array( 'language-apacheconf', 'language-applescript', 'language-arduino', 'language-bash', 'language-c', 'language-csharp', 'language-cpp', 'language-clike', 'language-coffeescript', 'language-css', 'language-d', 'language-dart', 'language-diff', 'language-git', 'language-go', 'language-graphql', 'language-groovy', 'language-http', 'language-ini', 'language-java', 'language-javascript', 'language-json', 'language-jsx', 'language-kotlin', 'language-latex', 'language-lua', 'language-makefile', 'language-markdown', 'language-markup', 'language-nginx', 'language-objectivec', 'language-pascal', 'language-perl', 'language-php', 'language-powershell', 'language-python', 'language-ruby', 'language-sass', 'language-scala', 'language-scss', 'language-sql', 'language-swift', 'language-tsx', 'language-twig', 'language-typescript', 'language-visual-basic', 'language-yaml', ), array( 'lang-apacheconf', 'lang-applescript', 'lang-arduino', 'lang-bash', 'lang-c', 'lang-csharp', 'lang-cpp', 'lang-clike', 'lang-coffeescript', 'lang-css', 'lang-d', 'lang-dart', 'lang-diff', 'lang-git', 'lang-go', 'lang-graphql', 'lang-groovy', 'lang-http', 'lang-ini', 'lang-java', 'lang-javascript', 'lang-json', 'lang-jsx', 'lang-kotlin', 'lang-latex', 'lang-lua', 'lang-makefile', 'lang-markdown', 'lang-markup', 'lang-nginx', 'lang-objectivec', 'lang-pascal', 'lang-perl', 'lang-php', 'lang-powershell', 'lang-python', 'lang-ruby', 'lang-sass', 'lang-scala', 'lang-scss', 'lang-sql', 'lang-swift', 'lang-tsx', 'lang-twig', 'lang-typescript', 'lang-visual-basic', 'lang-yaml', ) ); return $classes; } function prismatic_highlight_classes() { $classes = array( array( 'language-' ), array( 'lang-', ) ); return $classes; }