public function index($setting)
 {
     // Load dependencies
     $this->load->library('cackle/comment');
     // Init variables
     $chan = $_SERVER['REQUEST_URI'];
     // Init cackle
     $cackle = new CackleComment($this->db, $this->config->get('cackle_comment_site_id'), $this->config->get('cackle_comment_account_api_key'), $this->config->get('cackle_comment_site_api_key'));
     // Update comments
     #$time_updated = (int) $this->cache->get('cackle.comments.time_updated.' . md5($chan));
     // If timeout has been expired
     #if ($time_updated < time() - 432000) { // todo
     // Add new comments
     $cackle->addComments($cackle->receiveComments($chan, $cackle->getLastCommentId($chan), false));
     // Update old comments
     $cackle->updateComments($cackle->receiveComments($chan, false, $cackle->getLastCommentModified($chan)));
     // Update time updated
     #$this->cache->set('cackle.comments.time_updated.' . md5($chan), time());
     #}
     // Prepare view variables
     $this->data = $this->load->language('module/cackle_comment');
     $this->data['site_id'] = $this->config->get('cackle_comment_site_id');
     $this->data['comments'] = array();
     foreach ($cackle->getComments($chan) as $comment) {
         $this->data['comments'][] = array('creator' => $comment['user_name'] ? $comment['user_name'] : $comment['name'], 'comment_text' => $comment['msg'], 'comment_time' => date('Y-m-d', $comment['created'] / 1000));
     }
     // Render template
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/cackle_comment.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/module/cackle_comment.tpl';
     } else {
         $this->template = 'default/template/module/cackle_comment.tpl';
     }
     $this->render();
 }
 public function index()
 {
     $this->data = $this->load->language('module/cackle_comment');
     $this->document->setTitle($this->language->get('heading_title'));
     $this->load->model('setting/setting');
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
         $this->load->library('cackle/comment');
         $cackle = new CackleComment($this->db, $this->request->post['cackle_comment_site_id'], $this->request->post['cackle_comment_account_api_key'], $this->request->post['cackle_comment_site_api_key']);
         $cackle->install();
         $this->model_setting_setting->editSetting('cackle_comment', $this->request->post);
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
     }
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->error['error_site_id'])) {
         $this->data['error_site_id'] = $this->error['error_site_id'];
     } else {
         $this->data['error_site_id'] = '';
     }
     if (isset($this->error['error_account_api_key'])) {
         $this->data['error_account_api_key'] = $this->error['error_account_api_key'];
     } else {
         $this->data['error_account_api_key'] = '';
     }
     if (isset($this->error['error_site_api_key'])) {
         $this->data['error_site_api_key'] = $this->error['error_site_api_key'];
     } else {
         $this->data['error_site_api_key'] = '';
     }
     if (isset($this->request->post['cackle_comment_site_id'])) {
         $this->data['cackle_comment_site_id'] = $this->request->post['cackle_comment_site_id'];
     } else {
         $this->data['cackle_comment_site_id'] = $this->config->get('cackle_comment_site_id');
     }
     if (isset($this->request->post['cackle_comment_account_api_key'])) {
         $this->data['cackle_comment_account_api_key'] = $this->request->post['cackle_comment_account_api_key'];
     } else {
         $this->data['cackle_comment_account_api_key'] = $this->config->get('cackle_comment_account_api_key');
     }
     if (isset($this->request->post['cackle_comment_site_api_key'])) {
         $this->data['cackle_comment_site_api_key'] = $this->request->post['cackle_comment_site_api_key'];
     } else {
         $this->data['cackle_comment_site_api_key'] = $this->config->get('cackle_comment_site_api_key');
     }
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => false);
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_module'), 'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => ' :: ');
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('module/cackle_comment', 'token=' . $this->session->data['token'], 'SSL'), 'separator' => ' :: ');
     $this->data['action'] = $this->url->link('module/cackle_comment', 'token=' . $this->session->data['token'], 'SSL');
     $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
     $this->data['modules'] = array();
     if (isset($this->request->post['cackle_comment_module'])) {
         $this->data['modules'] = $this->request->post['cackle_comment_module'];
     } elseif ($this->config->get('cackle_comment_module')) {
         $this->data['modules'] = $this->config->get('cackle_comment_module');
     }
     $this->load->model('design/layout');
     $this->data['layouts'] = $this->model_design_layout->getLayouts();
     $this->template = 'module/cackle_comment.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->response->setOutput($this->render());
 }