return extension_loaded('gd') && function_exists('gd_info'); } /** * Flag to determine if the Imagick library has been compiled. * * @since 1.0.0 * * @return bool True if has proper extension, false otherwise. */ public function has_imagick_extension() { return extension_loaded('imagick'); } /** * Returns the singleton instance of the class. * * @since 1.0.0 * * @return object The Soliloquy_Metaboxes object. */ public static function get_instance() { if (!isset(self::$instance) && !self::$instance instanceof Soliloquy_Metaboxes) { self::$instance = new Soliloquy_Metaboxes(); } return self::$instance; } } // Load the metabox class. $soliloquy_metaboxes = Soliloquy_Metaboxes::get_instance();
/** * Callback for displaying the UI for setting fc options. * * @since 1.0.0 * * @param object $post The current post object. */ function settings_screen($post) { // Load the settings for the addon. $instance = Soliloquy_Metaboxes::get_instance(); $common = Soliloquy_Featured_Content_Common::get_instance(); ?> <div id="soliloquy-fc"> <p class="soliloquy-intro"><?php _e('The settings below adjust the Featured Content settings for the slider.', 'soliloquy-fc'); ?> </p> <h2><?php _e('Query Settings', 'soliloquy-fc'); ?> </h2> <table class="form-table"> <tbody> <tr id="soliloquy-config-fc-post-type-box"> <th scope="row"> <label for="soliloquy-config-fc-post-type"><?php _e('Select Your Post Type(s)', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-post-type" class="soliloquy-fc-chosen" name="_soliloquy[fc_post_types][]" multiple="multiple" data-placeholder="<?php esc_attr_e('Select post type(s) to query (defaults to post)...', 'soliloquy-fc'); ?> "> <?php $post_types = get_post_types(array('public' => true)); foreach ((array) $post_types as $post_type) { if (in_array($post_type, $common->get_post_types())) { continue; } $object = get_post_type_object($post_type); echo '<option value="' . esc_attr($post_type) . '"' . selected($post_type, in_array($post_type, (array) $instance->get_config('fc_post_types', $instance->get_config_default('fc_post_types'))) ? $post_type : '', false) . '>' . esc_html($object->labels->singular_name) . '</option>'; } ?> </select> <p class="description"><?php _e('Determines the post types to query.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-terms-box"> <th scope="row"> <label for="soliloquy-config-fc-terms"><?php _e('Select Your Taxonomy Term(s)', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-terms" class="soliloquy-fc-chosen" name="_soliloquy[fc_terms][]" multiple="multiple" data-placeholder="<?php esc_attr_e('Select taxonomy terms(s) to query (defaults to none)...', 'soliloquy-fc'); ?> "> <?php $taxonomies = get_taxonomies(array('public' => true), 'objects'); foreach ((array) $taxonomies as $taxonomy) { if (in_array($taxonomy, $common->get_taxonomies())) { continue; } $terms = get_terms($taxonomy->name); echo '<optgroup label="' . esc_attr($taxonomy->labels->name) . '">'; foreach ($terms as $term) { echo '<option value="' . esc_attr(strtolower($taxonomy->name) . '|' . $term->term_id . '|' . $term->slug) . '"' . selected(strtolower($taxonomy->name) . '|' . $term->term_id . '|' . $term->slug, in_array(strtolower($taxonomy->name) . '|' . $term->term_id . '|' . $term->slug, (array) $instance->get_config('fc_terms', $instance->get_config_default('fc_terms'))) ? strtolower($taxonomy->name) . '|' . $term->term_id . '|' . $term->slug : '', false) . '>' . esc_html(ucwords($term->name)) . '</option>'; } echo '</optgroup>'; } ?> </select> <p class="description"><?php _e('Determines the taxonomy terms that should be queried based on post type selection.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-terms-relation-box"> <th scope="row"> <label for="soliloquy-config-fc-terms-relation"><?php _e('Taxonomy Term(s) Relation', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-terms-relation" name="_soliloquy[fc_terms_relation]"> <?php $relations = $common->get_taxonomy_relations(); foreach ((array) $relations as $relation => $label) { $selected = selected($instance->get_config('fc_terms_relation', $instance->get_config_default('fc_terms_relation')), $relation, false); echo '<option value="' . $relation . '"' . $selected . '>' . $label . '</option>'; } ?> </select> <p class="description"><?php _e('Determines whether all or any taxonomy terms must be present in the above Posts.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-inc-ex-box"> <th scope="row"> <label for="soliloquy-config-fc-inc-ex"> <select id="soliloquy-config-fc-query" class="soliloquy-fc-chosen" name="_soliloquy[fc_query]"> <option value="include" <?php selected('include', $instance->get_config('fc_query', $instance->get_config_default('fc_query'))); ?> ><?php _e('Include', 'soliloquy-fc'); ?> </option> <option value="exclude" <?php selected('exclude', $instance->get_config('fc_query', $instance->get_config_default('fc_query'))); ?> ><?php _e('Exclude', 'soliloquy-fc'); ?> </option> </select> <?php _e(' ONLY the following items:', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-inc-ex" class="soliloquy-fc-chosen" name="_soliloquy[fc_inc_ex][]" multiple="multiple" data-placeholder="<?php esc_attr_e('Make your selection (defaults to none)...', 'soliloquy-fc'); ?> "> <?php $post_types = get_post_types(array('public' => true)); foreach ((array) $post_types as $post_type) { if (in_array($post_type, $common->get_post_types())) { continue; } $object = get_post_type_object($post_type); $posts = get_posts(array('post_type' => $post_type, 'posts_per_page' => apply_filters('soliloquy_fc_max_queried_posts', 500), 'no_found_rows' => true, 'cache_results' => false)); echo '<optgroup label="' . esc_attr($object->labels->name) . '">'; foreach ((array) $posts as $item) { echo '<option value="' . absint($item->ID) . '"' . selected($item->ID, in_array($item->ID, (array) $instance->get_config('fc_inc_ex', $instance->get_config_default('fc_inc_ex'))) ? $item->ID : '', false) . '>' . esc_html(ucwords($item->post_title)) . '</option>'; } echo '</optgroup>'; } ?> </select> <p class="description"><?php _e('Will include or exclude ONLY the selected post(s).', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-sticky-box"> <th scope="row"> <label for="soliloquy-config-fc-sticky"><?php _e('Include Sticky Posts', 'soliloquy-fc'); ?> </label> </th> <td> <input id="soliloquy-config-fc-sticky" type="checkbox" name="_soliloquy[fc_sticky]" value="<?php echo $instance->get_config('fc_sticky', $instance->get_config_default('fc_sticky')); ?> " <?php checked($instance->get_config('fc_sticky', $instance->get_config_default('fc_sticky')), 1); ?> /> <span class="description"><?php _e('If enabled, forces any Posts that are marked as Sticky to be at the start of the resultset. If disabled, Sticky Posts are treated as ordinary Posts, and will only appear if they meet the other criteria set above and below.', 'soliloquy-fc'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-orderby-box"> <th scope="row"> <label for="soliloquy-config-fc-orderby"><?php _e('Sort Posts By', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-orderby" class="soliloquy-fc-chosen" name="_soliloquy[fc_orderby]"> <?php foreach ((array) $common->get_orderby() as $array => $data) { echo '<option value="' . esc_attr($data['value']) . '"' . selected($data['value'], $instance->get_config('fc_orderby', $instance->get_config_default('fc_orderby')), false) . '>' . esc_html($data['name']) . '</option>'; } ?> </select> <p class="description"><?php _e('Determines how the posts are sorted in the slider.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-meta-key-box"> <th scope="row"> <label for="soliloquy-config-fc-meta-key"><?php _e('Meta Key', 'soliloquy-fc'); ?> </label> </th> <td> <input id="soliloquy-config-fc-meta-key" type="text" name="_soliloquy[fc_meta_key]" value="<?php echo $instance->get_config('fc_meta_key', $instance->get_config_default('fc_meta_key')); ?> " /> <p class="description"><?php _e('The meta key to use when ordering Posts. Used when Sort Posts By = Meta Value', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-order-box"> <th scope="row"> <label for="soliloquy-config-fc-order"><?php _e('Order Posts By', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-order" class="soliloquy-fc-chosen" name="_soliloquy[fc_order]"> <?php foreach ((array) $common->get_order() as $array => $data) { echo '<option value="' . esc_attr($data['value']) . '"' . selected($data['value'], $instance->get_config('fc_order', $instance->get_config_default('fc_order')), false) . '>' . esc_html($data['name']) . '</option>'; } ?> </select> <p class="description"><?php _e('Determines how the posts are ordered in the slider.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-number-box"> <th scope="row"> <label for="soliloquy-config-fc-number"><?php _e('Number of Slides', 'soliloquy-fc'); ?> </label> </th> <td> <input id="soliloquy-config-fc-number" type="number" name="_soliloquy[fc_number]" value="<?php echo $instance->get_config('fc_number', $instance->get_config_default('fc_number')); ?> " /> <p class="description"><?php _e('The number of slides in your Featured Content slider.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-offset-box"> <th scope="row"> <label for="soliloquy-config-fc-offset"><?php _e('Posts Offset', 'soliloquy-fc'); ?> </label> </th> <td> <input id="soliloquy-config-fc-offset" type="number" name="_soliloquy[fc_offset]" value="<?php echo absint($instance->get_config('fc_offset', $instance->get_config_default('fc_offset'))); ?> " /> <p class="description"><?php _e('The number of posts to offset in the query.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-status-box"> <th scope="row"> <label for="soliloquy-config-fc-status"><?php _e('Post Status', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-status" class="soliloquy-fc-chosen" name="_soliloquy[fc_status]"> <?php foreach ((array) $common->get_statuses() as $status) { echo '<option value="' . esc_attr($status->name) . '"' . selected($status->name, $instance->get_config('fc_status', $instance->get_config_default('fc_status')), false) . '>' . esc_html($status->label) . '</option>'; } ?> </select> <p class="description"><?php _e('Determines the post status to use for the query.', 'soliloquy-fc'); ?> </p> </td> </tr> <?php do_action('soliloquy_fc_box', $post); ?> </tbody> </table> <h2><?php _e('Content Settings', 'soliloquy-fc'); ?> </h2> <table class="form-table"> <tbody> <tr id="soliloquy-config-fc-post-url-box"> <th scope="row"> <label for="soliloquy-config-fc-post-url"><?php _e('Link Image to Post URL?', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-post-url" type="checkbox" name="_soliloquy[fc_post_url]" value="<?php echo $instance->get_config('fc_post_url', $instance->get_config_default('fc_post_url')); ?> " <?php checked($instance->get_config('fc_post_url', $instance->get_config_default('fc_post_url')), 1); ?> /> <span class="description"><?php _e('Links to the image to the post URL.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-post-title-box"> <th scope="row"> <label for="soliloquy-config-fc-post-title"><?php _e('Display Post Title?', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-post-title" type="checkbox" name="_soliloquy[fc_post_title]" value="<?php echo $instance->get_config('fc_post_title', $instance->get_config_default('fc_post_title')); ?> " <?php checked($instance->get_config('fc_post_title', $instance->get_config_default('fc_post_title')), 1); ?> /> <span class="description"><?php _e('Displays the post title over the image.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-post-title-link-box"> <th scope="row"> <label for="soliloquy-config-fc-post-title-link"><?php _e('Link Post Title to Post URL?', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-post-title-link" type="checkbox" name="_soliloquy[fc_post_title_link]" value="<?php echo $instance->get_config('fc_post_title_link', $instance->get_config_default('fc_post_title_link')); ?> " <?php checked($instance->get_config('fc_post_title_link', $instance->get_config_default('fc_post_title_link')), 1); ?> /> <span class="description"><?php _e('Links the post title to the post URL.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-content-type-box"> <th scope="row"> <label for="soliloquy-config-fc-content-type"><?php _e('Post Content to Display', 'soliloquy-fc'); ?> </label> </th> <td> <select id="soliloquy-config-fc-content-type" class="soliloquy-fc-chosen" name="_soliloquy[fc_content_type]"> <?php foreach ((array) $common->get_content_types() as $array => $data) { echo '<option value="' . esc_attr($data['value']) . '"' . selected($data['value'], $instance->get_config('fc_content_type', $instance->get_config_default('fc_content_type')), false) . '>' . esc_html($data['name']) . '</option>'; } ?> </select> <p class="description"><?php _e('Determines the type of content to retrieve and output in the caption.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-content-length-box"> <th scope="row"> <label for="soliloquy-config-fc-content-length"><?php _e('Number of Words in Content', 'soliloquy-fc'); ?> </label> </th> <td> <input id="soliloquy-config-fc-content-length" type="number" name="_soliloquy[fc_content_length]" value="<?php echo $instance->get_config('fc_content_length', $instance->get_config_default('fc_content_length')); ?> " /> <p class="description"><?php _e('Sets the number of words for trimming the post content.', 'soliloquy-fc'); ?> </p> </td> </tr> <tr id="soliloquy-config-fc-content-ellipses-box"> <th scope="row"> <label for="soliloquy-config-fc-content-ellipses"><?php _e('Append Ellipses to Post Content?', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-content-ellipses" type="checkbox" name="_soliloquy[fc_content_ellipses]" value="<?php echo $instance->get_config('fc_content_ellipses', $instance->get_config_default('fc_content_ellipses')); ?> " <?php checked($instance->get_config('fc_content_ellipses', $instance->get_config_default('fc_content_ellipses')), 1); ?> /> <span class="description"><?php _e('Places an ellipses at the end of the post content.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-content-html"> <th scope="row"> <label for="soliloquy-config-fc-read-more"><?php _e('Output Content as HTML?', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-content-html" type="checkbox" name="_soliloquy[fc_content_html]" value="<?php echo $instance->get_config('fc_read_more', $instance->get_config_default('fc_content_html')); ?> " <?php checked($instance->get_config('fc_content_html', $instance->get_config_default('fc_content_html')), 1); ?> /> <span class="description"><?php _e('If enabled, retrieves the Post Content as HTML, to allow for formatting to be included in the caption. Uncheck this option if you just want to get the Post Content as plain text.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-read-more-box"> <th scope="row"> <label for="soliloquy-config-fc-read-more"><?php _e('Display Read More Link?', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-read-more" type="checkbox" name="_soliloquy[fc_read_more]" value="<?php echo $instance->get_config('fc_read_more', $instance->get_config_default('fc_read_more')); ?> " <?php checked($instance->get_config('fc_read_more', $instance->get_config_default('fc_read_more')), 1); ?> /> <span class="description"><?php _e('Displays a "read more" link after the post content.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-read-more-text-box"> <th scope="row"> <label for="soliloquy-config-fc-read-more-text"><?php _e('Read More Text', 'soliloquy'); ?> </label> </th> <td> <input id="soliloquy-config-fc-read-more-text" type="text" name="_soliloquy[fc_read_more_text]" value="<?php echo $instance->get_config('fc_read_more_text', $instance->get_config_default('fc_read_more_text')); ?> " /> <span class="description"><?php _e('Sets the read more link text.', 'soliloquy'); ?> </span> </td> </tr> <tr id="soliloquy-config-fc-fallback-box"> <th scope="row"> <label for="soliloquy-config-fc-fallback"><?php _e('Fallback Image URL', 'soliloquy-fc'); ?> </label> </th> <td> <input id="soliloquy-config-fc-fallback" type="text" name="_soliloquy[fc_fallback]" value="<?php echo $instance->get_config('fc_fallback', $instance->get_config_default('fc_fallback')); ?> " /> <p class="description"><?php _e('This image URL is used if no image URL can be found for a post.', 'soliloquy-fc'); ?> </p> </td> </tr> <?php do_action('soliloquy_fc_content_box', $post); ?> </tbody> </table> </div> <?php }
/** * Refreshes the individual post selection list for the selected post type. * * @since 1.0.0 */ function refresh_posts() { // Run a security check first. check_ajax_referer('soliloquy-fc-refresh', 'nonce'); // Die early if no post type is set. if (empty($_POST['post_type'])) { echo json_encode(array('error' => true)); die; } $limit = apply_filters('soliloquy_fc_max_queried_posts', 500); $output = ''; foreach ($_POST['post_type'] as $post_type) { $posts = get_posts(array('post_type' => $post_type, 'posts_per_page' => $limit, 'no_found_rows' => true, 'cache_results' => false)); // If we have posts, loop through them and build out the HTML output. if ($posts) { $instance = Soliloquy_Metaboxes::get_instance(); $object = get_post_type_object($post_type); $output .= '<optgroup label="' . esc_attr($object->labels->name) . '">'; foreach ((array) $posts as $post) { $output .= '<option value="' . absint($post->ID) . '"' . selected($post->ID, in_array($post->ID, (array) $instance->get_config('fc_inc_ex', $instance->get_config_default('fc_inc_ex'))) ? $post->ID : '', false) . '>' . esc_html(ucwords($post->post_title)) . '</option>'; } $output .= '</optgroup>'; } } // If results found, output if (!empty($output)) { echo json_encode($output); die; } // Output an error if we can't find anything. echo json_encode(array('error' => true)); die; }
/** * Crops images based on carousel settings for the slider. * * @since 1.0.0 * * @param array $settings Array of settings to be saved. * @param int $post_id The current post ID. * @param object $post The current post object. */ function soliloquy_carousel_crop($settings, $post_id, $post) { // If the carousel option and crop option are checked, crop images accordingly. if (isset($settings['config']['slider']) && $settings['config']['slider']) { if (isset($settings['config']['carousel']) && $settings['config']['carousel']) { $instance = Soliloquy_Metaboxes::get_instance(); $args = apply_filters('soliloquy_crop_image_args', array('position' => 'c', 'width' => $instance->get_config('carousel_width', $instance->get_config_default('carousel_width')), 'height' => $instance->get_config('carousel_height', $instance->get_config_default('carousel_height')), 'quality' => 100, 'retina' => false)); $instance->crop_images($args, $post_id); } } }
/** * Refreshes the DOM view for a slider. * * @since 1.0.0 */ function soliloquy_ajax_refresh() { // Run a security check first. check_ajax_referer('soliloquy-refresh', 'nonce'); // Prepare variables. $post_id = absint($_POST['post_id']); $slider = ''; // Grab all slider data. $slider_data = get_post_meta($post_id, '_sol_slider_data', true); // If there are no slider items, don't do anything. if (empty($slider_data) || empty($slider_data['slider'])) { echo json_encode(array('error' => true)); die; } // Loop through the data and build out the slider view. foreach ((array) $slider_data['slider'] as $id => $data) { $slider .= Soliloquy_Metaboxes::get_instance()->get_slider_item($id, $data, $data['type'], $post_id); } echo json_encode(array('success' => $slider)); die; }
/** * Outputs the custom css classes meta fields. * * @since 2.1.2 * * @param int $attach_id The current attachment ID. * @param array $data Array of attachment data. * @param int $post_id The current post ID. */ function soliloquy_custom_css_meta($attach_id, $data, $post_id) { $instance = Soliloquy_Metaboxes::get_instance(); ?> <label class="setting"> <span class="name"><?php _e('CSS Classes', 'soliloquy-schedule'); ?> </span> <input id="soliloquy-custom-css-classes-<?php echo $attach_id; ?> " class="soliloquy-custom-css-classes" type="text" name="_soliloquy[custom_css_classes]" data-soliloquy-meta="custom_css_classes" value="<?php echo $instance->get_meta('custom_css_classes', $attach_id, $instance->get_meta_default('custom_css_classes', $attach_id)); ?> " /> </label> <?php }