/** * renders a smart list form content. This should be the ONLY public thing for now * @param $smart_list_settings array of settings for the smart list * @return string */ function render_from_post_content($smart_list_settings) { $this->counting_order_asc = $smart_list_settings['counting_order_asc']; // make a new tokenizer $td_tokenizer = new td_tokenizer(); $td_tokenizer->token_title_start = $smart_list_settings['td_smart_list_h']; $td_tokenizer->token_title_end = $smart_list_settings['td_smart_list_h']; // get the list items $list_items = $td_tokenizer->split_to_list_items(array('content' => $smart_list_settings['post_content'], 'extract_first_image' => $smart_list_settings['extract_first_image'])); //print_r($list_items); // no items found, we return the content as is if (empty($list_items['list_items'])) { return $smart_list_settings['post_content']; } // we need to number all the items before pagination because item 2 can have number 4 if the counting method is desc $list_items = $this->add_numbers_to_list_items($list_items); if ($this->use_pagination === true) { $current_page = $this->get_current_page($list_items); return $this->render($list_items, $current_page); } else { return $this->render($list_items); } }
function render_from_post_content($content) { // make a new tokenizer $td_tokenizer = new td_tokenizer($content); //read the smart list settings global $post; $td_smart_list = get_post_meta($post->ID, 'td_post_theme_settings', true); // check the smart list numbering preferences // the default value is already set above - if the $td_smart_list['td_smart_list_order'] is empty if (!empty($td_smart_list['td_smart_list_order'])) { $this->counting_order_asc = true; $this->counting_start = 1; } // are we using custom h tags ? if (!empty($td_smart_list['td_smart_list_h'])) { $td_tokenizer->token_title_end = $td_smart_list['td_smart_list_h']; $td_tokenizer->token_title_start = $td_smart_list['td_smart_list_h']; } else { // default $td_tokenizer->token_title_end = 'h3'; $td_tokenizer->token_title_start = 'h3'; } $list_items = $td_tokenizer->split_to_list_items($content); if (empty($list_items['list_items'])) { return $content; } //print_r($list_items); /* ---------------------------------------------------------------------------- build the item id to item name for the table of contents */ $item_id_2_item_array = array(); foreach ($list_items['list_items'] as $list_item_key => $list_item) { $item_id_2_item_array[$list_item_key + 1] = $list_item; } $buffy = ''; /* ---------------------------------------------------------------------------- add the before_list content */ if (!empty($list_items['before_list'])) { $buffy .= implode('', $list_items['before_list']); } /* ---------------------------------------------------------------------------- add the table of contents before */ $buffy .= $this->render_table_of_contents_before($item_id_2_item_array); /* ---------------------------------------------------------------------------- add the list */ $buffy .= $this->render_before_list_wrap(); //from child class //count the total number of items $total_items_number = count($list_items['list_items']) - 1 + $this->counting_start; // fix for 0 base counting (0 of 3 - to - 3 of 3) //render each item using the render_list_item method from the child class foreach ($list_items['list_items'] as $list_item_key => $list_item) { //how to count (asc or desc) if ($this->counting_order_asc === true) { $current_item_index = $list_item_key + $this->counting_start; } else { $current_item_index = $total_items_number - $list_item_key; } $buffy .= $this->render_list_item($list_item, $list_item_key + 1, $current_item_index, $total_items_number); } $buffy .= $this->render_after_list_wrap(); //from child class - render the list wrap end /* ---------------------------------------------------------------------------- add the table of contents after */ $buffy .= $this->render_table_of_contents_after($item_id_2_item_array); /* ---------------------------------------------------------------------------- add the after_list content */ if (!empty($list_items['after_list'])) { $buffy .= implode('', $list_items['after_list']); } return $buffy; }