예제 #1
0
 /**
  * @param $post WP_Post
  * @throws ErrorException
  */
 function __construct($post)
 {
     if (gettype($post) != 'object' or get_class($post) != 'WP_Post') {
         td_util::error(__FILE__, 'td_module: ' . get_Class($this) . '($post): $post is not WP_Post');
     }
     //this filter is used by td_unique_posts.php - to add unique posts to the array for the datasource
     apply_filters("td_wp_booster_module_constructor", $this, $post);
     $this->post = $post;
     // by default the WordPress title is not escaped on twenty fifteen
     $this->title = get_the_title($post->ID);
     $this->title_attribute = esc_attr(strip_tags($this->title));
     $this->href = esc_url(get_permalink($post->ID));
     if (has_post_thumbnail($this->post->ID)) {
         $tmp_get_post_thumbnail_id = get_post_thumbnail_id($this->post->ID);
         if (!empty($tmp_get_post_thumbnail_id)) {
             // if we have a wrong id, leave the post_thumb_id NULL
             $this->post_thumb_id = $tmp_get_post_thumbnail_id;
         }
     }
     //get the review metadata
     //$this->td_review = get_post_meta($this->post->ID, 'td_review', true); @todo $this->td_review variable name must be replaced and the 'get_quotes_on_blocks', 'get_category' methods also
     $this->td_review = get_post_meta($this->post->ID, 'td_post_theme_settings', true);
     if (!empty($this->td_review['has_review']) and (!empty($this->td_review['p_review_stars']) or !empty($this->td_review['p_review_percents']) or !empty($this->td_review['p_review_points']))) {
         $this->is_review = true;
     }
 }
예제 #2
0
 /**
  * The callback function used by spl_autoload_register
  * @param $class_name string - The class name
  */
 private function loading_classes($class_name)
 {
     $path_regex = 'td';
     // foreach regex path, the class name is verified for a start matching
     if (strpos($class_name, $path_regex) !== false and strpos($class_name, $path_regex) === 0) {
         $class_settings = td_api_base::get_by_id($class_name);
         if (!empty($class_settings)) {
             if (array_key_exists('file', $class_settings)) {
                 $class_file_path = $class_settings['file'];
                 if (isset($class_file_path) and !empty($class_file_path)) {
                     // set the autoloaded key for that component
                     td_api_base::_debug_set_class_is_autoloaded($class_name);
                     //	                    if ($class_name == 'td_page_views') {
                     //		                    print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 4)); //return only 4 call stack frames
                     //		                    die;
                     //	                    }
                     // require_once($class_file_path); - we need to use load_template to make our single_templates work like wordpress
                     // with load_template we prepare the globals ($post etc for the files)
                     // we should not use the global $post or any other globals in our classes without explicit declaration
                     load_template($class_file_path, true);
                 }
             } else {
                 td_util::error(__FILE__, "Missing parameter: 'file'");
             }
         }
     }
 }
예제 #3
0
 function get_content()
 {
     /*  ----------------------------------------------------------------------------
             Prepare the content
         */
     $content = get_the_content(__td('Continue', TD_THEME_NAME));
     $content = apply_filters('the_content', $content);
     $content = str_replace(']]>', ']]>', $content);
     /** ----------------------------------------------------------------------------
      * Smart list support. class_exists and new object WORK VIA AUTOLOAD
      * @see td_autoload_classes::loading_classes
      */
     //$td_smart_list = get_post_meta($this->post->ID, 'td_smart_list', true);
     $td_smart_list = get_post_meta($this->post->ID, 'td_post_theme_settings', true);
     if (!empty($td_smart_list['smart_list_template'])) {
         $td_smart_list_class = $td_smart_list['smart_list_template'];
         if (class_exists($td_smart_list_class)) {
             $td_smart_list_obj = new $td_smart_list_class();
             // make the class from string * magic :)
             return $td_smart_list_obj->render_from_post_content($content);
         } else {
             // there was an error?
             td_util::error(__FILE__, 'Missing smart list: ' . $td_smart_list_class . '. Did you disabled a tagDiv plugin?');
         }
     }
     /*  ----------------------------------------------------------------------------
            end smart list - if we have a list, the function returns above
         */
     /*  ----------------------------------------------------------------------------
             ad support on content
         */
     //read the current ad settings
     $tds_inline_ad_paragraph = td_util::get_option('tds_inline_ad_paragraph');
     $tds_inline_ad_align = td_util::get_option('tds_inline_ad_align');
     //add the inline ad
     if (td_util::is_ad_spot_enabled('content_inline') and is_single()) {
         if (empty($tds_inline_ad_paragraph)) {
             $tds_inline_ad_paragraph = 0;
         }
         $cnt = 0;
         $content_buffer = '';
         // we replace the content with this buffer at the end
         $content_parts = preg_split('/(<p.*>)/U', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
         foreach ($content_parts as $content_part_index => $content_part_value) {
             if (!empty($content_part_value)) {
                 if ($tds_inline_ad_paragraph == $content_part_index / 2) {
                     //it's time to show the ad
                     switch ($tds_inline_ad_align) {
                         case 'left':
                             $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'left'));
                             break;
                         case 'right':
                             $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'right'));
                             break;
                         default:
                             $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline'));
                             break;
                     }
                 }
                 $content_buffer .= $content_part_value;
                 $cnt++;
             }
         }
         $content = $content_buffer;
     }
     //add the top ad
     if (td_util::is_ad_spot_enabled('content_top') and is_single()) {
         $content = td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_top')) . $content;
     }
     //add bottom ad
     if (td_util::is_ad_spot_enabled('content_bottom') and is_single()) {
         $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_bottom'));
     }
     return $content;
 }
예제 #4
0
function td_template_include_filter($wordpress_template_path)
{
    // intercept the WordPress requested template, and if it's single we put our own.
    if (is_single() and ($wordpress_template_path == TEMPLATEPATH . '/single.php' or $wordpress_template_path == STYLESHEETPATH . '/single.php')) {
        global $post;
        // if we are on a custom post type, leave the defaul loaded wordpress template
        if ($post->post_type != 'post') {
            return $wordpress_template_path;
        }
        // read the global setting
        $single_template_id = td_util::get_option('td_default_site_post_template');
        // check if we have a specific template
        $td_post_theme_settings = get_post_meta($post->ID, 'td_post_theme_settings', true);
        if (!empty($td_post_theme_settings['td_post_template'])) {
            $single_template_id = $td_post_theme_settings['td_post_template'];
        }
        if (!empty($single_template_id)) {
            // try to find the template in the API
            $single_template_path = '';
            try {
                $single_template_path = td_api_single_template::get_key($single_template_id, 'file');
            } catch (ErrorException $ex) {
                td_util::error(__FILE__, "The template {$single_template_id} isn't set. Did you disable a tagDiv plugin?");
                // this does not stop execution
            }
            // we have the file in the API, now we make sure that the file exists on disk
            if (!empty($single_template_path) and file_exists($single_template_path)) {
                $wordpress_template_path = $single_template_path;
            } else {
                td_util::error(__FILE__, "The path {$single_template_path} of the {$single_template_id} template not found. Did you disable a tagDiv plugin?");
                // this does not stop execution
            }
        }
    } else {
        if (td_global::$is_woocommerce_installed and is_single() and ($wordpress_template_path == TEMPLATEPATH . '/woocommerce/single-product.php' or $wordpress_template_path == STYLESHEETPATH . '/woocommerce/single-product.php')) {
            //echo 'SINGLE PRODUCT detected<br>';
        }
    }
    return $wordpress_template_path;
}
 /**
  * the content of a single post or single post type
  * @return mixed|string|void
  */
 function get_content()
 {
     /*  ----------------------------------------------------------------------------
     			Prepare the content
     		*/
     $content = get_the_content(__td('Continue', TD_THEME_NAME));
     $content = apply_filters('the_content', $content);
     $content = str_replace(']]>', ']]&gt;', $content);
     /** ----------------------------------------------------------------------------
      * Smart list support. class_exists and new object WORK VIA AUTOLOAD
      * @see td_autoload_classes::loading_classes
      */
     //$td_smart_list = get_post_meta($this->post->ID, 'td_smart_list', true);
     $td_smart_list = get_post_meta($this->post->ID, 'td_post_theme_settings', true);
     if (!empty($td_smart_list['smart_list_template'])) {
         $td_smart_list_class = $td_smart_list['smart_list_template'];
         if (class_exists($td_smart_list_class)) {
             /**
              * @var $td_smart_list_obj td_smart_list
              */
             $td_smart_list_obj = new $td_smart_list_class();
             // make the class from string * magic :)
             // prepare the settings for the smart list
             $smart_list_settings = array('post_content' => $content, 'counting_order_asc' => false, 'td_smart_list_h' => 'h3', 'extract_first_image' => td_api_smart_list::get_key($td_smart_list_class, 'extract_first_image'));
             if (!empty($td_smart_list['td_smart_list_order'])) {
                 $smart_list_settings['counting_order_asc'] = true;
             }
             if (!empty($td_smart_list['td_smart_list_h'])) {
                 $smart_list_settings['td_smart_list_h'] = $td_smart_list['td_smart_list_h'];
             }
             return $td_smart_list_obj->render_from_post_content($smart_list_settings);
         } else {
             // there was an error?
             td_util::error(__FILE__, 'Missing smart list: ' . $td_smart_list_class . '. Did you disabled a tagDiv plugin?');
         }
     }
     /*  ----------------------------------------------------------------------------
     			end smart list - if we have a list, the function returns above
     		 */
     /*  ----------------------------------------------------------------------------
     			ad support on content
     		*/
     //read the current ad settings
     $tds_inline_ad_paragraph = td_util::get_option('tds_inline_ad_paragraph');
     $tds_inline_ad_align = td_util::get_option('tds_inline_ad_align');
     //add the inline ad
     if (td_util::is_ad_spot_enabled('content_inline') and is_single()) {
         if (empty($tds_inline_ad_paragraph)) {
             $tds_inline_ad_paragraph = 0;
         }
         $cnt = 0;
         $content_buffer = '';
         // we replace the content with this buffer at the end
         $content_parts = preg_split('/(<p.*>)/U', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
         $p_open_tag_count = 0;
         // count how many <p> tags we have added to the buffer
         foreach ($content_parts as $content_part_index => $content_part_value) {
             if (!empty($content_part_value)) {
                 // Show the ad ONLY IF THE CURRENT PART IS A <p> opening tag and before the <p> -> so we will have <p>content</p>  ~ad~ <p>content</p>
                 // and prevent cases like <p> ~ad~ content</p>
                 if (preg_match('/(<p.*>)/U', $content_part_value) === 1) {
                     if ($tds_inline_ad_paragraph == $p_open_tag_count) {
                         switch ($tds_inline_ad_align) {
                             case 'left':
                                 $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'left'));
                                 break;
                             case 'right':
                                 $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline', 'align' => 'right'));
                                 break;
                             default:
                                 $content_buffer .= td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_inline'));
                                 break;
                         }
                     }
                     $p_open_tag_count++;
                 }
                 $content_buffer .= $content_part_value;
                 $cnt++;
             }
         }
         $content = $content_buffer;
     }
     //add the top ad
     if (td_util::is_ad_spot_enabled('content_top') and is_single()) {
         $content = td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_top')) . $content;
     }
     //add bottom ad
     if (td_util::is_ad_spot_enabled('content_bottom') and is_single()) {
         $content = $content . td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'content_bottom'));
     }
     return $content;
 }
예제 #6
0
function td_ajax_loop()
{
    $loopState = td_util::get_http_post_val('loopState');
    //print_r($loopState);
    $buffy = '';
    /**
     * @var WP_Query
     */
    $td_query =& td_data_source::get_wp_query($loopState['atts'], $loopState['currentPage']);
    //by ref  do the query
    if (!empty($td_query->posts)) {
        td_global::$is_wordpress_loop = true;
        ///if we are in wordpress loop; used by quotes in blocks to check if the blocks are displayed in blocks or in loop
        $td_template_layout = new td_template_layout($loopState['sidebarPosition']);
        $td_module_class = td_util::get_module_class_from_loop_id($loopState['moduleId']);
        //disable the grid for some of the modules
        $td_module_api = td_api_module::get_by_id($td_module_class);
        if ($td_module_api['uses_columns'] === false) {
            $td_template_layout->disable_output();
        }
        foreach ($td_query->posts as $post) {
            $buffy .= $td_template_layout->layout_open_element();
            if (class_exists($td_module_class)) {
                $td_mod = new $td_module_class($post);
                $buffy .= $td_mod->render();
            } else {
                td_util::error(__FILE__, 'Missing module: ' . $td_module_class);
            }
            $buffy .= $td_template_layout->layout_close_element();
            $td_template_layout->layout_next();
        }
        $buffy .= $td_template_layout->close_all_tags();
    } else {
        // no posts
    }
    $loopState['server_reply_html_data'] = $buffy;
    die(json_encode($loopState));
}
예제 #7
0
 /**
  * creates a menu and adds it to a location of the theme
  * @param $menu_name
  * @param $location
  * @return bool
  */
 static function create_menu($menu_name, $location)
 {
     if (!in_array($menu_name, self::$allowed_menu_names)) {
         td_util::error(__FILE__, 'td_stacks_menu::create_menu - menu_name is not in allowed_menu_names');
         return false;
     }
     $menu_id = wp_create_nav_menu($menu_name);
     if (is_wp_error($menu_id)) {
         return false;
     }
     $menu_spots_array = get_theme_mod('nav_menu_locations');
     // activate the menu only if it's not already active
     if (!isset($menu_spots_array[$location]) or $menu_spots_array[$location] != $menu_id) {
         $menu_spots_array[$location] = $menu_id;
         set_theme_mod('nav_menu_locations', $menu_spots_array);
     }
     return $menu_id;
 }
예제 #8
0
    //not sure if we need a default here
    $loop_module_id = 1;
}
$td_module_class = td_util::get_module_class_from_loop_id($loop_module_id);
//disable the grid for some of the modules
$td_module = td_api_module::get_by_id($td_module_class);
if ($td_module['uses_columns'] === false) {
    $td_template_layout->disable_output();
}
if (have_posts()) {
    while (have_posts()) {
        the_post();
        echo $td_template_layout->layout_open_element();
        if (class_exists($td_module_class)) {
            $td_mod = new $td_module_class($post);
            echo $td_mod->render();
        } else {
            td_util::error(__FILE__, 'Missing module: ' . $td_module_class);
        }
        echo $td_template_layout->layout_close_element();
        $td_template_layout->layout_next();
    }
    //end loop
    echo $td_template_layout->close_all_tags();
} else {
    /**
     * no posts to display. This function generates the __td('No posts to display').
     * the text can be overwritten by the themplate using the global @see td_global::$custom_no_posts_message
     */
    echo td_page_generator::no_posts();
}
 /**
  * shows a single template @see \td_wp_booster_config::td_global_after
  * This function also loads single templates from our plugins
  */
 static function show_single_template($template_id)
 {
     if (array_key_exists($template_id, td_global::$post_templates_list)) {
         if (empty(td_global::$post_templates_list[$template_id]['file'])) {
             // no file parameter, try to load the template form the theme
             $td_located = locate_template($template_id . '.php', true);
             if (empty($td_located)) {
                 td_util::error(__FILE__, "Template {$template_id} not found. Fatal error");
             }
         } else {
             //echo td_global::$post_templates_list[$template_id]['file'];
             // load the template form the plugin - it was registered at runtime
             load_template(td_global::$post_templates_list[$template_id]['file']);
         }
     } else {
         // the template_id was not found in our runtime config
         td_util::error(__FILE__, "Template {$template_id} not found. Did you disable a tagDiv plugin?");
     }
 }
 static function _helper_show_top_bar()
 {
     // find the current active template's id
     $template_id = self::_helper_get_active_id();
     try {
         $template_path = self::get_key($template_id, 'file');
     } catch (ErrorException $ex) {
         td_util::error(__FILE__, "td_api_top_bar_template::_helper_show_top_bar : {$template_id} isn't set. Did you disable a tagDiv plugin?");
         //does not stop execution
     }
     // load the template
     if (!empty($template_path) and file_exists($template_path)) {
         load_template($template_path);
     } else {
         td_util::error(__FILE__, "The path {$template_path} of the template id: {$template_id} not found.");
         //shoud be fatal?
     }
 }