<?php  
class ControllerModuleBlogLatest extends Controller {
	protected function index($setting) {
		$this->language->load('module/blog_latest');
		
    	$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['text_show_all'] = $this->language->get('text_show_all');
		$this->data['text_posted_on'] = $this->language->get('text_posted_on');
		$this->data['text_read'] = $this->language->get('text_read');
		$this->data['text_time'] = $this->language->get('text_time');
		$this->data['text_not_found'] = $this->language->get('text_not_found');
    	
		//$this->data['text_contact'] = $this->language->get('text_contact');
    	//$this->data['text_sitemap'] = $this->language->get('text_sitemap');
		
		//$this->load->model('catalog/blog_latest');
		
		//$this->data['blog_latests'] = array();

		//foreach ($this->model_catalog_blog_latest->getBlogLatests() as $result) {
      	//	$this->data['blog_latests'][] = array(
        //		'title' => $result['title'],
	    //		'href'  => $this->url->link('blog_latest/blog_latest', 'blog_latest_id=' . $result['blog_latest_id'])
      	//	);
    	//}

		//$this->data['contact'] = $this->url->link('blog_latest/contact');
    	//$this->data['sitemap'] = $this->url->link('blog_latest/sitemap');
		
		$this->load->model('extras/blog');
		$this->load->model('tool/image');
		
		$data = array(
			'start' => 0,
			'limit' => $setting['limit']
		);
		
		//$this->data['blog_settings'] = array();

		foreach ($this->model_extras_blog->getLatestBlogs($data) as $result) {
      		$this->data['latest_blogs'][] = array(
        		'title' => $result['title'],
				'date_added' => $result['date_added'],
				'short_description' => substr(strip_tags(html_entity_decode($result['short_description'], ENT_QUOTES, 'UTF-8')), 0, $setting['max_chars']) . ' <a href="' . $this->url->link('extras/blog/getblog', 'blog_id=' . $result['blog_id']) . '" title="' . $this->language->get('text_read_more') . '">[...]</a>',
				'count_read' => $result['count_read'],
				'image'   		=> $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']),
	    		'href'  => $this->url->link('extras/blog/getblog', 'blog_id=' . $result['blog_id'])
      		);
    	}
		
		$this->data['blog_show_all'] = $this->url->link('extras/blog');
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/blog_latest.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/blog_latest.tpl';
		} else {
			$this->template = 'default/template/module/blog_latest.tpl';
		}
		
		$this->render();
	}
}
?>