/** * Parses saved styling looking for Google Fonts references to load them. * * @since 1.0.0 */ public function render_style() { $styles = TF_Model::get_custom_styling(null, array('include_template_part' => true, 'include_global_style' => true)); if (count($styles) > 0) { $this->generate_css($styles, true); } }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { $args = shortcode_atts(array('comments_per_page' => get_option('comments_per_page'), 'avatar_size' => 64), array_filter($atts), $this->shortcode); if (TF_Model::is_template_page()) { global $post; $old_post = $post; $post_with_comment = get_posts(array('posts_per_page' => 1, 'orderby' => 'comment_count', 'order' => 'DESC')); if (!empty($post_with_comment)) { $post = current($post_with_comment); } } $this->comments_args = $args; add_filter('wp_list_comments_args', array($this, 'wp_list_comments_args')); add_filter('pre_option_comments_per_page', array($this, 'pre_option_comments_per_page')); add_filter('pre_option_page_comments', array($this, 'pre_option_page_comments')); ob_start(); ?> <?php comments_template(); ?> <?php $output = ob_get_clean(); remove_filter('wp_list_comments_args', array($this, 'wp_list_comments_args')); remove_filter('pre_option_comments_per_page', array($this, 'pre_option_comments_per_page')); remove_filter('pre_option_page_comments', array($this, 'pre_option_page_comments')); if (isset($old_post)) { wp_reset_postdata(); $post = $old_post; } return $output; }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { $atts = shortcode_atts(array('image_size' => 'blank', 'image_width' => '', 'image_height' => ''), $atts, $this->shortcode); // must add the third params $this->shortcode, for builder shortcode rendering if (!TF_Model::is_template_page()) { $output = ''; $image_size = 'blank' != $atts['image_size'] ? $atts['image_size'] : 'large'; if (has_post_thumbnail(get_the_ID())) { $post_thumbnail = get_post_thumbnail_id(get_the_ID()); $post_thumbnail_object = get_post($post_thumbnail); $thumbnail_title = is_object($post_thumbnail_object) ? $post_thumbnail_object->post_title : ''; $image_attribute = wp_get_attachment_image_src($post_thumbnail, $image_size); $post_image = sprintf('<img src="%s" alt="%s" width="%s" height="%s" />', esc_url($image_attribute[0]), esc_attr($thumbnail_title), esc_attr($atts['image_width']), esc_attr($atts['image_height'])); $output = '<figure class="tf_page_featured_image">' . $post_image . '</figure>'; } } else { if (!$atts['image_width']) { $atts['image_width'] = '350'; } if (!$atts['image_height']) { $atts['image_height'] = '150'; } $output = '<figure class="tf_page_featured_image"><img width="' . $atts['image_width'] . '" height="' . $atts['image_height'] . '" src="http://placehold.it/' . $atts['image_width'] . 'x' . $atts['image_height'] . '" /></figure>'; } return apply_filters('tf_shortcode_element_render', $output, $this->slug, $atts, $content); }
function tf_template_region_content_empty() { if (TF_Model::is_template_editable()) { echo sprintf('<h4>%s</h4>', __('This is Content Section', 'themify-flow')); echo sprintf('<p>%s</p>', __('If you would like to add content to this section, you may do so by editing active TF Template > Add Modules', 'themify-flow')); } }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { extract(wp_parse_args($atts, array('logo_type' => 'text', 'title_tag' => 'p', 'logo_text' => '', 'logo_image' => '', 'width' => '', 'height' => '', 'logo_link' => ''))); if ('' == $logo_text) { $logo_text = get_bloginfo('name'); } if ('' == $logo_link) { $logo_link = home_url(); } ob_start(); ?> <?php if ($logo_type == 'text') { ?> <<?php echo $title_tag; ?> class="tf_site_logo"> <a href="<?php echo $logo_link; ?> "><?php echo $logo_text; ?> </a> </<?php echo $title_tag; ?> ><!-- .tf_site_logo --> <?php } else { ?> <figure class="tf_site_logo"> <a href="<?php echo $logo_link; ?> "><img src="<?php echo TF_Model::get_attachment_url($logo_image); ?> " width="<?php echo $width; ?> " height="<?php echo $height; ?> " alt="<?php echo $logo_text; ?> " /></a> </figure> <?php } ?> <?php $output = ob_get_clean(); return $output; }
/** * Retrieve the archive title based on the queried object. * * @return string Archive title. */ function get_the_archive_title($before = '', $after = '') { if (!TF_Model::is_template_page()) { if (is_category()) { $title = single_cat_title('', false); } elseif (is_tag()) { $title = single_tag_title('', false); } elseif (is_author()) { $title = sprintf(__('Author: %s', 'themify-flow'), '<span class="vcard">' . get_the_author() . '</span>'); } elseif (is_year()) { $title = sprintf(__('Year: %s', 'themify-flow'), get_the_date(_x('Y', 'yearly archives date format', 'themify-flow'))); } elseif (is_month()) { $title = sprintf(__('Month: %s', 'themify-flow'), get_the_date(_x('F Y', 'monthly archives date format', 'themify-flow'))); } elseif (is_day()) { $title = sprintf(__('Day: %s', 'themify-flow'), get_the_date(_x('F j, Y', 'daily archives date format', 'themify-flow'))); } elseif (is_tax('post_format')) { if (is_tax('post_format', 'post-format-aside')) { $title = _x('Asides', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-gallery')) { $title = _x('Galleries', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-image')) { $title = _x('Images', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-video')) { $title = _x('Videos', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-quote')) { $title = _x('Quotes', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-link')) { $title = _x('Links', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-status')) { $title = _x('Statuses', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-audio')) { $title = _x('Audio', 'post format archive title', 'themify-flow'); } elseif (is_tax('post_format', 'post-format-chat')) { $title = _x('Chats', 'post format archive title', 'themify-flow'); } } elseif (is_post_type_archive()) { $title = sprintf(__('%s', 'themify-flow'), post_type_archive_title('', false)); } elseif (is_tax()) { $tax = get_taxonomy(get_queried_object()->taxonomy); /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */ $title = sprintf(__('%1$s: %2$s', 'themify-flow'), $tax->labels->singular_name, single_term_title('', false)); } else { $title = ''; } /** * Filter the archive title. * * @param string $title Archive title to be displayed. */ $title = apply_filters('get_the_archive_title', $title); if (!empty($title)) { $title = $before . $title . $after; } } else { $title = sprintf('<p>%s</p>', __('<strong>Category Title</strong>', 'themify-flow')); } return $title; }
/** * Checks if stylesheet exist. Creates it if it doesn't. * * ## EXAMPLES * * wp themifyflow make_css * * @synopsis */ function make_css($args, $assoc_args) { if (class_exists('TF_Styling_Control')) { if (TF_Model::create_stylesheets()) { WP_CLI::success("Stylesheet succesfully created."); } else { WP_CLI::error("Could not create stylesheet."); } } }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { $atts = shortcode_atts(array('title_tag' => ''), $atts, $this->shortcode); // must add the third params $this->shortcode, for builder shortcode rendering if (!TF_Model::is_template_page()) { /** We can separate the module markup in separated template file later */ $output = sprintf('<%1$s class="tf_page_title">%2$s</%1$s>', $atts['title_tag'], get_the_title()); } else { $output = sprintf('<p>%s</p>', __('<strong>Page Title</strong>', 'themify-flow')); } return $output; }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { $atts = shortcode_atts(array(), $atts, $this->shortcode); // must add the third params $this->shortcode, for builder shortcode rendering global $query_string, $TF; $output = ''; $build_query = array('post_type' => 'post'); if (TF_Model::is_template_page()) { query_posts(build_query($build_query)); } else { query_posts($query_string); } if (have_posts()) { $TF->in_archive_loop = true; the_post(); ob_start(); ?> <?php do_action('tf_single_loop_before_post'); ?> <article <?php echo tf_get_attr('post', $original_atts); ?> > <?php do_action('tf_single_loop_start_post'); ?> <?php echo do_shortcode($content); ?> <?php do_action('tf_single_loop_end_post'); ?> </article> <?php do_action('tf_single_loop_after_post'); ?> <?php $output .= ob_get_contents(); ob_get_clean(); $TF->in_archive_loop = false; } wp_reset_query(); return $output; }
/** * Module settings field * * @since 1.0.0 * @access public * @return array */ public function fields() { $template_parts = TF_Model::get_posts('tf_template_part'); if (!empty($template_parts)) { $options = array(); foreach ($template_parts as $t) { if (!isset($_REQUEST['template_id']) || $_REQUEST['template_id'] != $t->ID) { $options[] = array('name' => $t->post_title, 'value' => $t->ID); } } if (!empty($options)) { return apply_filters('tf_module_template_part_fields', array('part' => array('type' => 'select', 'label' => __('Template_Part', 'themify-flow'), 'options' => $options))); } } return apply_filters('tf_module_template_part_fields', array()); }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { /** Use condition here to prevent infinite loop issue that cause memory limit error */ /** If viewing template page (view/frontend editor) echo preview text since the actual the_content is the builder data in a bunch of shortcodes */ $output = ''; if (!TF_Model::is_template_page()) { // make sure $post exist global $post; if (is_object($post) && !is_admin()) { $output = apply_filters('the_content', $post->post_content); $output = str_replace(']]>', ']]>', $output); } } else { $output = sprintf('<p>%s</p>', __('<strong>This is only preview text.</strong> The text content here will be replaced with actual page content when viewing the real page.', 'themify-flow')); } return '<div class="tf_page_content">' . $output . '</div>'; }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { extract(shortcode_atts(array('first_page_only' => 'yes'), $atts, $this->shortcode)); if (!TF_Model::is_template_page()) { if ('yes' == $first_page_only && is_paged()) { return ''; } ob_start(); ?> <?php the_archive_description('<div class="tf_category_description">', '</div>'); ?> <?php $output = ob_get_clean(); } else { $output = sprintf('<p>%s</p>', __('<strong>This is only preview text.</strong> The text content here will be replaced with actual category description when viewing the real page.', 'themify-flow')); } return $output; }
public function get_bootstrap_styles($post_id, $args = array()) { $make_data = array(); $styles = TF_Model::get_custom_styling($post_id, $args); if (!empty($styles) && is_array($styles)) { foreach ($styles as $uniqid => $setting) { $temp_data = array('ID' => $uniqid, 'module' => $setting['module']); if (isset($setting['settings']) && count($setting['settings']) > 0) { $temp_data['settings'] = array(); foreach ($setting['settings'] as $selector_key => $properties) { $temp_setting = array('SettingKey' => $selector_key); $temp_props = array(); foreach ($properties as $property => $value) { $temp_props[$property] = $value; } $temp_data['settings'][] = array_merge($temp_setting, $temp_props); } } $make_data[] = $temp_data; } } return $make_data; }
/** * Export template and template part data. * * @since 1.0.0 * @access public */ public function do_export() { $actions = array('export_tf_theme', 'export_tf_template', 'export_tf_template_part', 'export_tf_content_builder'); if (isset($_GET['action']) && in_array($_GET['action'], $actions) && wp_verify_nonce($_GET['_wpnonce'], 'export_tf_nonce')) { global $TF; include_once sprintf("%s/includes/utilities/export.php", $TF->framework_path()); $template = get_post($_GET['post']); $meta_file = $this->get_filename_data($template->post_type); $name_prefix = $meta_file['name']; $basename = sanitize_file_name($meta_file['file']); $filename = sanitize_file_name($name_prefix . '-' . $template->post_name . '.' . date('Y-m-d') . '.xml'); $ids = 'tf_theme' == $template->post_type ? TF_Model::get_theme_data_post_ids($template->ID, $template->post_name) : array($template->ID); $ids = TF_Model::find_attachment_ids_from_posts($ids); // Include all attachments ID from each post content shortcode builder. ob_start(); export_td(array('content' => $template->post_type, 'ids' => $ids, 'filename' => $filename)); $output = ob_get_contents(); ob_end_clean(); // Load WP Filesystem if (!function_exists('WP_Filesystem')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; if (class_exists('ZipArchive')) { $datafile = $basename; $wp_filesystem->put_contents($datafile, $output, FS_CHMOD_FILE); $files_to_zip = array($datafile); $ext = pathinfo($filename, PATHINFO_EXTENSION); $file = str_replace('.' . $ext, '.zip', $filename); $result = tf_create_zip($files_to_zip, $file, true); } if (isset($result) && $result) { if (isset($file) && file_exists($file)) { ob_start(); header('Pragma: public'); header('Expires: 0'); header("Content-type: application/force-download"); header('Content-Disposition: attachment; filename="' . $file . '"'); header("Content-Transfer-Encoding: Binary"); header("Content-length: " . filesize($file)); header('Connection: close'); ob_clean(); flush(); echo $wp_filesystem->get_contents($file); unlink($datafile); unlink($file); exit; } else { return false; } } else { if (ini_get('zlib.output_compression')) { /** * Turn off output buffer compression for proper zip download. * @since 2.0.2 */ $srv_stg = 'ini' . '_' . 'set'; call_user_func($srv_stg, 'zlib.output_compression', 'Off'); } ob_start(); header('Content-Type: application/force-download'); header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); ob_clean(); flush(); echo $output; exit; } die; } }
public function shortcode_handler($atts, $content, $code) { global $TF; if ($TF->in_template_part && !TF_Model::is_template_page()) { if (is_array($this->category)) { $cat = array_intersect($this->category, array('archive', 'page', 'single')); if (!empty($cat)) { $cat = current($cat); } } else { $cat = $this->category; } if (in_array($cat, array('archive', 'page', 'single')) && !is_admin()) { if ($cat == 'page' && !is_page()) { return FALSE; } elseif ($cat == 'single' && !is_single()) { return FALSE; } elseif ($cat == 'archive' && !is_search() && !is_tax() && !is_archive() && !is_post_type_archive()) { return FALSE; } } } $atts = apply_filters('tf_shortcode_atts', $atts, $code, $this); /** * Put module wrapper markup here directly instead using apply_filters() * since this wrapper markup is required for each modules. */ if (!isset($atts['sc_id'])) { $atts['sc_id'] = TF_Model::generate_block_id(); } $classes = apply_filters('tf_module_classes', array('tf_module_wrapper', 'tf_module_block', 'tf_module_' . $this->slug, 'tf_module_block_' . $atts['sc_id']), $atts); $wrapper_atts = apply_filters('tf_module_wrapper_atts', array('class' => $classes), $atts, $content, $this); $wrapper_atts['class'] = implode(' ', $wrapper_atts['class']); $atts_output = ''; foreach ($wrapper_atts as $key => $value) { $atts_output .= sprintf(' %s="%s"', $key, esc_attr($value)); } $pre = sprintf('<div %s>', $atts_output); $after = '</div>'; $output = $pre . $this->render_shortcode($atts, $content) . $after; return apply_filters('tf_shortcode_module_render', $output, $this->slug, $atts, $content); }
/** * Render Template Regions metabox. * * @since 1.0.0 * @access public * @param object $post */ public function render_template_regions($post) { // Add an nonce field so we can check for it later. wp_nonce_field('tf_template_option_custom_box', 'tf_template_option_custom_box_nonce'); $fields = array('template_part_caption' => array('type' => 'separator', 'meta' => array('html' => sprintf(__('<h4>Select a <a href="%s">Template Part</a> for each region: Header, Sidebar, and Footer.</h4>', 'themify-flow'), admin_url('edit.php?post_type=tf_template_part')))), 'tf_template_region_header' => array('type' => 'template_part_select', 'label' => __('Header', 'themify-flow'), 'show_extra_link' => false), 'tf_template_region_sidebar' => array('type' => 'template_part_select', 'label' => __('Sidebar', 'themify-flow'), 'show_extra_link' => false), 'tf_template_region_footer' => array('type' => 'template_part_select', 'label' => __('Footer', 'themify-flow'), 'show_extra_link' => false)); $data = TF_Model::get_field_exist_values($fields, $post->ID); /* not used anymore if ( count( $data ) > 0 ) { foreach( $data as $key => $shortcode ) { preg_match('/.*slug="(.*)"/i', $shortcode, $slug ); $data[ $key ] = isset( $slug[1] ) ? $slug[1] : ''; } }*/ echo '<div class="tf_interface">'; echo TF_Form::render($fields, $data); echo '</div>'; }
/** * Save builder content data. * * @since 1.0.0 * @access public * @param int $post_id * @param array $post_data */ public function save_builder_content($post_id, $post_data) { $post_type = get_post_type($post_id); $reserved_post_types = array('tf_template', 'tf_template_part'); // Save to post_meta if (!in_array($post_type, $reserved_post_types)) { $post_content = TF_Model::array_to_shortcode($post_data['content']); update_post_meta($post_id, 'tf_builder_content', $post_content); } }
</div> <!-- /themify_builder_module_panel --> </div> <div style="display: none;"> <?php wp_editor(' ', 'tf_hidden_editor'); ?> </div> <?php } // ! TF_Model::is_tf_styling_active ?> <div id="tf_main_loader" class="tf_interface"> <?php echo tf_loader_span(); ?> </div> <script type="text/javascript"> var _tdBootstrapTemplate = <?php echo json_encode(TF_Model::read_template_data($TF_Layout->layout_id)); ?> ; var _tdBootstrapUtility = <?php echo json_encode(TF_Model::read_utility_data()); ?> ; </script>
<?php $themes = TF_Model::prepare_themes_for_js(); wp_enqueue_script('tf-theme-js', $TF->framework_uri() . '/assets/js/tf/theme.js', array('jquery'), $TF->get_version(), true); wp_localize_script('tf-theme-js', '_tfThemeSettings', array('themes' => $themes, 'settings' => array('canInstall' => !is_multisite() && current_user_can('install_themes'), 'confirmDelete' => __("Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete."), 'adminUrl' => parse_url(admin_url(), PHP_URL_PATH)), 'l10n' => array('addNew' => __('Add New Theme', 'themify-flow'), 'search' => __('Search Installed Themes', 'themify-flow'), 'searchPlaceholder' => __('Search installed themes...', 'themify-flow'), 'themesFound' => __('Number of Themes found: %d', 'themify-flow'), 'noThemesFound' => __('No themes found. Try a different search.', 'themify-flow')))); ?> <div class="wrap"> <h2><?php _e('Flow Themes', 'themify-flow'); ?> <span class="title-count theme-count"><?php echo count($themes); ?> </span> <a data-type="theme" class="add-new-h2 tf_lightbox_new" href="#"><?php _e('Add New', 'themify-flow'); ?> </a> <a data-type="theme" class="add-new-h2 tf_lightbox_import" href="#"><?php _e('Add via Import', 'themify-flow'); ?> </a> </h2> <div class="theme-browser tf-theme-browser"> <div class="themes tf-themes"> <?php /*
/** * Render Template Options metabox. * * @since 1.0.0 * @access public * @param object $post */ public function render_template_part_option($post) { // Add an nonce field so we can check for it later. wp_nonce_field('tf_template_part_option_custom_box', 'tf_template_part_option_custom_box_nonce'); $fields = $this->fields(); unset($fields['tf_template_part_name']); $data = TF_Model::get_field_exist_values($fields, $post->ID); echo '<div class="tf_interface">'; echo TF_Form::render($fields, $data); echo '</div>'; }
/** * Field Template Assignment Tab Single. * * @since 1.0.0 * @access public * @param string $field_name Field name. * @param array $selected Selected value. * @return string */ private static function print_single_tabs($field_name, $selected = array()) { $output = '<div id="visibility-tabs-single" class="visibility-tabs ui-tabs visibility-tabs-' . $field_name . ' visibility-tabs-' . $field_name . '-single"><ul class="clearfix">'; /* build the tab links */ $output .= '<li><a href="#visibility-tab-single-category">' . __('Categories', 'themify-flow') . '</a></li>'; $output .= '<li><a href="#visibility-tab-single-post-types">' . __('Post Types', 'themify-flow') . '</a></li>'; $output .= '<li><a href="#visibility-tab-single-singles">' . __('Posts', 'themify-flow') . '</a></li>'; $output .= '</ul>'; // Categories Tab $output .= '<div id="visibility-tab-single-category" class="themify-visibility-options clearfix">'; $categories = get_terms('category', array('hide_empty' => true)); $output .= wp_kses_post(__('<p><small>Check which categories to apply this template to the single view of each entry filed under the category.</small></p>', 'themify-flow')); $checked = isset($selected['single']['category']['all']) ? checked($selected['single']['category']['all'], 'on', false) : ''; $output .= '<label class="label-full"><input class="tf_toggle_prop" type="checkbox" name="' . $field_name . '[single][category][all]" ' . $checked . ' />' . __('Apply to all', 'themify-flow') . '</label>'; if (count($categories) > 0) { foreach ($categories as $term) { $checked = isset($selected['single']['category'][$term->slug]) ? checked($selected['single']['category'][$term->slug], 'on', false) : ''; $output .= '<label><input type="checkbox" name="' . $field_name . '[single][category][' . $term->slug . ']" ' . $checked . ' />' . $term->name . '</label>'; } } $output .= '</div>'; // tab-single-category // Post Types tab $output .= '<div id="visibility-tab-single-post-types" class="themify-visibility-options clearfix">'; $post_types = TF_Model::get_post_types(array(), array('tf_template', 'tf_template_part')); $output .= wp_kses_post(__('<p><small>Check which post types to apply this template to the single view of each entry of their type. Note: if "Apply to all" is checked, it will apply to all single views of all other custom post types as well.</small></p>', 'themify-flow')); $checked = isset($selected['single']['post_type']['all']) ? checked($selected['single']['post_type']['all'], 'on', false) : ''; $output .= '<label class="label-full"><input class="tf_toggle_prop" type="checkbox" name="' . $field_name . '[single][post_type][all]" ' . $checked . ' />' . __('Apply to all', 'themify-flow') . '</label>'; if (count($post_types) > 0) { foreach ($post_types as $key => $type) { $checked = isset($selected['single']['post_type'][$key]) ? checked($selected['single']['post_type'][$key], 'on', false) : ''; $output .= '<label><input type="checkbox" name="' . $field_name . '[single][post_type][' . $key . ']" ' . $checked . ' />' . $type->label . '</label>'; } } $output .= '</div>'; // tab-single-post-types // Posts tab $output .= '<div id="visibility-tab-single-singles" class="themify-visibility-options clearfix">'; $query_posts = get_posts(array('post_type' => array_keys(TF_Model::get_post_types(array(), array('page', 'tf_template', 'tf_template_part'))), 'posts_per_page' => -1)); $output .= wp_kses_post(__('<p><small>Check which posts to apply this template to its single view.</small></p>', 'themify-flow')); $checked = isset($selected['single']['singular']['all']) ? checked($selected['single']['singular']['all'], 'on', false) : ''; $output .= '<label class="label-full"><input class="tf_toggle_prop" type="checkbox" name="' . $field_name . '[single][singular][all]" ' . $checked . ' />' . __('Apply to all', 'themify-flow') . '</label>'; if (count($query_posts) > 0) { foreach ($query_posts as $post_data) { $checked = isset($selected['single']['singular'][$post_data->post_type][$post_data->post_name]) ? checked($selected['single']['singular'][$post_data->post_type][$post_data->post_name], 'on', false) : ''; $output .= '<label><input type="checkbox" name="' . $field_name . '[single][singular][' . $post_data->post_type . '][' . $post_data->post_name . ']" ' . $checked . ' />' . $post_data->post_title . '</label>'; } } $output .= '</div>'; // tab-archive-taxonomies $output .= '</div>'; return $output; }
/** * Set active theme. * * @since 1.0.0 * @access public */ public function set_initial_active_theme() { global $wpdb; $theme = $wpdb->get_row("SELECT ID FROM {$wpdb->posts} WHERE post_type='tf_theme' AND post_status='publish'"); if (!is_null($theme)) { TF_Model::set_active_theme($theme->ID); TF_Model::create_stylesheets($theme->ID); } }
</a> </li> <li> <a class="tf_lightbox_link_region-delete" title="<?php _e('Delete', 'themify-flow'); ?> " href="#"> <span class="ti-close"></span> </a> </li> </ul> </li> </ul> </div> <div class="tf_active_block_caption tf_interface"><?php echo sprintf(__('Template Part: %s', 'themify-flow'), TF_Model::get_template_part_title(TF_Model::get_shortcode_atts_val($TF_Layout->region_footer, 'slug'))); ?> </div> <div class="tf_active_block_element"> <?php echo $TF_Layout->render($TF_Layout->region_footer); ?> </div> </div> <?php } ?> </div> </div> <?php
/** * Return attributes to shortcode string. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public static function to_shortcode($sc_name, $atts, $content = null, $enclosed = true) { $shortcode = sprintf('[%s', $sc_name); $shortcode .= count($atts) > 0 ? TF_Model::parse_attr($atts) : ''; $shortcode .= ']'; $shortcode .= $enclosed ? $content . sprintf('[/%s]', $sc_name) : ''; return $shortcode; }
/** * Create new posts based on import information * * Posts marked as having a parent which doesn't exist will become top level items. * Doesn't create a new post if: the post type doesn't exist, the given post ID * is already noted as imported or a post with the same title and date already exists. * Note that new/updated terms, comments and meta are imported for the last of the above. */ function process_replace_posts() { $this->posts = apply_filters('tf_import_posts', $this->posts); foreach ($this->posts as $post) { $post = apply_filters('tf_import_post_data_raw', $post); if (!post_type_exists($post['post_type'])) { $this->errors[] = sprintf(__('Failed to import "%s": Invalid post type %s', 'themify-flow'), esc_html($post['post_title']), esc_html($post['post_type'])); do_action('tf_import_post_exists', $post); continue; } if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) { continue; } if ($post['status'] == 'auto-draft') { continue; } if ('nav_menu_item' == $post['post_type']) { continue; } $post_type_object = get_post_type_object($post['post_type']); if ('add' == $this->method && 'theme' != $this->source && 'tf_theme' != $post['post_type']) { $post['post_name'] = TF_Model::replace_theme_prefix_slug($post['post_name']); } // Replace Theme > Templates and Parts if ('theme' == $this->source && 'tf_theme' != $post['post_type']) { $the_original_theme = get_post($this->edit_import_id); $post['post_name'] = TF_Model::replace_theme_prefix_slug($post['post_name'], $the_original_theme->post_name); } if ('theme' == $this->source && 'tf_theme' == $post['post_type']) { $post_exists = $this->edit_import_id; } else { if ('theme' != $this->source && 'tf_theme' != $post['post_type']) { $post_exists = $this->edit_import_id; } else { $post_exists = TF_Model::post_exists($post['post_name']); } } $post_parent = (int) $post['post_parent']; if ($post_parent) { // if we already know the parent, map it to the new local ID if (isset($this->processed_posts[$post_parent])) { $post_parent = $this->processed_posts[$post_parent]; // otherwise record the parent for later } else { $this->post_orphans[intval($post['post_id'])] = $post_parent; $post_parent = 0; } } // map the post author $author = sanitize_user($post['post_author'], true); if (isset($this->author_mapping[$author])) { $author = $this->author_mapping[$author]; } else { $author = (int) get_current_user_id(); } $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']); $original_post_ID = $post['post_id']; $postdata = apply_filters('tf_import_post_data_processed', $postdata, $post); if ('attachment' == $postdata['post_type']) { $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']; // try to use _wp_attached file for upload folder placement to ensure the same location as the export site // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload() $postdata['upload_date'] = $post['post_date']; if (isset($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { if ($meta['key'] == '_wp_attached_file') { if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) { $postdata['upload_date'] = $matches[0]; } break; } } } if ($post_exists) { $post_id = $post_exists; } else { $post_id = $this->process_attachment($postdata, $remote_url); } } else { do_action('tf_import_before_insert_post', $postdata, $this->source); if ($post_exists) { $postdata['ID'] = $post_exists; $post_id = $post_exists; if (!$this->set_associated_theme_by_value) { unset($postdata['post_name']); unset($postdata['post_title']); } wp_update_post($postdata); } else { $post_id = wp_insert_post($postdata, true); } // Assign associated theme with current theme active if (in_array($this->source, array('template', 'template_part')) && in_array($post['post_type'], array('tf_template', 'tf_template_part'))) { global $TF; update_post_meta($post_id, 'associated_theme', $TF->active_theme->slug); } do_action('tf_import_insert_post', $post_id, $original_post_ID, $postdata, $post); } if (is_wp_error($post_id)) { $message = sprintf(__('Failed to import %s “%s”', 'themify-flow'), $post_type_object->labels->singular_name, esc_html($post['post_title'])); if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) { $message .= ': ' . $post_id->get_error_message(); } $this->errors[] = $message; continue; } if ($post['is_sticky'] == 1) { stick_post($post_id); } // map pre-import ID to local ID $this->processed_posts[intval($post['post_id'])] = (int) $post_id; if (!isset($post['postmeta'])) { $post['postmeta'] = array(); } $post['postmeta'] = apply_filters('tf_import_post_meta', $post['postmeta'], $post_id, $post); // add/update post meta if (!empty($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { $key = apply_filters('tf_import_post_meta_key', $meta['key'], $post_id, $post); $value = false; if ('_edit_last' == $key) { if (isset($this->processed_authors[intval($meta['value'])])) { $value = $this->processed_authors[intval($meta['value'])]; } else { $key = false; } } if ($key) { // export gets meta straight from the DB so could have a serialized string if (!$value) { $value = maybe_unserialize($meta['value']); } // Replace Theme > Templates and Parts if ('associated_theme' == $key && 'theme' == $this->source && 'tf_theme' != $post['post_type']) { if ($this->set_associated_theme_by_value) { update_post_meta($post_id, 'associated_theme', $value); } elseif (isset($the_original_theme) && is_object($the_original_theme)) { update_post_meta($post_id, 'associated_theme', $the_original_theme->post_name); } } else { if ('theme' == $this->source && 'tf_theme' != $post['post_type'] && in_array($key, array('tf_template_region_header', 'tf_template_region_sidebar', 'tf_template_region_footer')) && !empty($value)) { $new_meta_value = TF_Model::replace_theme_prefix_slug($value, $the_original_theme->post_name); if ($this->set_associated_theme_by_value) { update_post_meta($post_id, $key, $value); } elseif (isset($the_original_theme) && is_object($the_original_theme)) { update_post_meta($post_id, $key, $new_meta_value); } } else { update_post_meta($post_id, $key, $value); } } do_action('tf_import_post_meta', $post_id, $key, $value); // if the post has a featured image, take note of this in case of remap if ('_thumbnail_id' == $key) { $this->featured_images[$post_id] = (int) $value; } } } } } unset($this->posts); }
/** * Import theme files * Using Example flow_import(array('source1'=>array('method'=>'import','type'=>'theme','activate'=>false), * 'source2'=>array('method'=>'edit','type'=>'template_part')) * ); * @since 1.0.0 * @access public * @param array $sources * @return mixed */ public static function flow_import(array $sources) { if (empty($sources)) { return false; } include_once 'classes/import-export/class-tf-import.php'; include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/image.php'; WP_Filesystem(); global $wp_filesystem, $TF; $errors = array(); foreach ($sources as $path => $data) { if (!isset($data['method']) || !isset($data['type']) || !in_array($data['type'], array('theme', 'template', 'template_part')) || !in_array($data['method'], array('import', 'replace')) || !$wp_filesystem->exists($path)) { continue; } $file = wp_check_filetype($path); if (!isset($file['ext']) || !in_array($file['ext'], array('plain', 'rar', 'zip', 'xml'))) { continue; } $is_zip = FALSE; if ($file['ext'] == 'zip' || $file['ext'] == 'rar') { $tmp_dir = sys_get_temp_dir() . '/' . uniqid('flow') . '/'; $unzipfile = unzip_file($path, $tmp_dir); if (!$unzipfile) { $errors[$path] = 'There was an error unzipping the file ' . basename($path); continue; } $tmp_file = scandir($tmp_dir); if (empty($tmp_file)) { $errors[$path] = 'There was an error unzipping the file ' . basename($path); continue; } $xml_file = false; foreach ($tmp_file as $tmp) { if ($tmp != '.' && $tmp != '..' && $wp_filesystem->exists($tmp_dir . $tmp)) { $xml_file = $tmp; break; } } if (!$xml_file) { $errors[$path] = 'There was an error unzipping the file ' . basename($path); continue; } $xml = wp_check_filetype($tmp_dir . $xml_file, array('xml' => 'application/xml')); if ($xml['ext'] != 'xml') { $errors[$path] = 'The ' . $file['ext'] . ' file ' . basename($path) . ' doesn`t contain xml file'; continue; } $is_zip = true; $path = $tmp_dir . $xml_file; } $import = new TF_Import(); $posts = $import->parse($path); remove_filter('wp_unique_post_slug', array($TF->active_theme, 'add_prefix_post_slug'), 10, 6); if (isset($posts['posts']) && !empty($posts['posts'])) { $import->method = $data['method'] == 'import' ? 'add' : 'edit'; $import->source = $data['type']; $import->fetch_attachments = true; $import->edit_import_id = FALSE; $import->set_associated_theme_by_value = true; $errors[$path] = array(); if ($data['type'] == 'theme') { $import->exclude_theme_post = FALSE; if ($import->method == 'add') { $import->import($path); } else { foreach ($posts['posts'] as $post) { if ($post['post_type'] == 'tf_' . $data['type']) { $post_exists = TF_Model::post_exists($post['post_name']); if ($post_exists && get_post_type($post_exists) == $post['post_type']) { $import->edit_import_id = $post_exists; $import->import($path); } else { $errors[$path][] = $post['post_title'] . ' ' . $data['type'] . ' doesn`t exist.'; } break; } } } if (isset($data['activate']) && $data['activate'] && !$import->fails()) { $activate = $import->return_ID > 0 ? $import->return_ID : $import->edit_import_id; } } else { $import->exclude_theme_post = TRUE; $import->set_associated_theme_by_value = true; $import->get_authors_from_import($posts); $import->get_author_mapping(); wp_defer_term_counting(true); wp_defer_comment_counting(true); do_action('tf_import_start'); foreach ($posts['posts'] as $post) { if ('tf_' . $data['type'] == $post['post_type']) { $post_exists = TF_Model::post_exists($post['post_name']); $post_type = $post_exists ? get_post_type($post_exists) == $post['post_type'] : FALSE; $import->posts = array($post); if ($import->method == 'add') { if ($post_exists && $post_type) { $errors[$path][] = $post['post_title'] . ' ' . $data['type'] . ' already exist.'; } else { $import->processed_posts(); } } elseif ($post_exists && $post_type) { $import->edit_import_id = $post_exists; $import->process_replace_posts(); } else { $errors[$path][] = $post['post_title'] . ' ' . $data['type'] . ' doesn`t exists.'; } } } } if ($is_zip) { $wp_filesystem->delete($path); } $messages = $import->get_error_messages(); if (!empty($messages)) { foreach ($messages as $m) { $errors[$path][] = $m; } } elseif (empty($errors[$path])) { unset($errors[$path]); } } } if (isset($activate) && $activate) { global $TF_Theme, $TF; $TF_Theme->set_active_theme($activate); $TF->active_theme = new TF_Engine_Theme_Loader(); do_action('tf_import_end'); } return empty($errors) ? TRUE : $errors; }
/** * Empty Footer section content. * * @since 1.0.0 * @access public */ public function empty_footer_region() { if (TF_Model::is_template_editable()) { echo sprintf('<p>%s</p>', __('To auto display a footer here, create a new Template Part and name it "Footer".', 'themify-flow')); } }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($original_atts, $content = null) { global $wp_query, $query_string, $TF; $atts = shortcode_atts(array('layout' => 'post-list', 'order' => 'DESC', 'orderby' => 'date', 'pagination' => 'yes'), $original_atts, $this->shortcode); $output = ''; $build_query = array('posts_per_page' => get_option('posts_per_page'), 'order' => $atts['order'], 'orderby' => $atts['orderby']); if (TF_Model::is_template_page()) { query_posts(build_query($build_query)); } else { //query_posts( array_merge( $wp_query->query_vars, $build_query ) ); // Fix Product archive page (site.com/shop) doesn't query product post_type, somehow using $query_string works. query_posts($query_string . '&' . build_query($build_query)); } if (have_posts()) { ob_start(); ?> <!-- loopswrapper --> <div class="tf_loops_wrapper clearfix <?php echo esc_attr($atts['layout']); ?> "> <?php $TF->in_archive_loop = true; while (have_posts()) { the_post(); ?> <?php do_action('tf_archive_loop_before_post'); ?> <article <?php echo tf_get_attr('post', $original_atts); ?> > <?php do_action('tf_archive_loop_start_post'); ?> <?php echo do_shortcode($content); ?> <?php do_action('tf_archive_loop_end_post'); ?> </article> <?php do_action('tf_archive_loop_after_post'); ?> <?php } $TF->in_archive_loop = false; ?> </div><!-- /tf_loops_wrapper --> <?php // Pagination links if ('yes' == $atts['pagination']) { get_template_part('includes/pagination', $wp_query->query_vars['post_type']); } $output = ob_get_contents(); ob_get_clean(); } wp_reset_query(); wp_reset_postdata(); return $output; }
/** * Update template stylesheet. * * @since 1.0.0 * @access public * @return json */ public function clear_template_style() { // Check ajax referer check_ajax_referer($this->action_nonce, $this->field_nonce); global $tf_styles; $template_id = intval($_POST['template_id']); $dataStyling = isset($_POST['dataStyling']) ? json_decode(stripslashes($_POST['dataStyling']), true) : array(); TF_Model::save_styling($template_id, $dataStyling); $styles = TF_Model::get_custom_styling($template_id, array('include_template_part' => true, 'include_global_style' => true)); $data = '<style type="text/css" id="tf-template-layout-css">' . $tf_styles->generate_css($styles) . '</style>'; wp_send_json_success($data); }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { $atts = shortcode_atts(array('image_size' => 'blank', 'image_width' => '', 'image_height' => ''), $atts, $this->shortcode); // must add the third params $this->shortcode, for builder shortcode rendering if (!TF_Model::is_template_page()) { $output = ''; $cat = get_query_var('cat'); if ($cat) { $categories = get_option('tf-categories-image'); if (isset($categories[$cat]) && $categories[$cat]) { $category = get_category($cat); $thumbnail_title = $category->name; $post_image = sprintf('<img src="%s" alt="%s" width="%s" height="%s" />', esc_url($categories[$cat]), esc_attr($thumbnail_title), esc_attr($atts['image_width']), esc_attr($atts['image_height'])); $output = '<figure class="tf_category_image">' . $post_image . '</figure>'; } } } else { if (!$atts['image_width']) { $atts['image_width'] = '350'; } if (!$atts['image_height']) { $atts['image_height'] = '150'; } $output = '<figure class="tf_category_image"><img width="' . $atts['image_width'] . '" height="' . $atts['image_height'] . '" src="http://placehold.it/' . $atts['image_width'] . 'x' . $atts['image_height'] . '" /></figure>'; } return apply_filters('tf_shortcode_element_render', $output, $this->slug, $atts, $content); }