function add() { // Insert meal into database and get array $id = $this->meals_model->insert_meal($_POST); $meal = $this->meals_model->get_meal($id); // Generate tiny URL $this->load->helper('bitly_helper'); $bitly = new Bitly(); $bitly->set('nomealpoints', 'R_cffca0da875cf25106cfeb75291148a5'); $url = $bitly->shorten(site_url("/meal/" . $id)); // Add tiny URL to DB for future access $this->meals_model->set_url($id, $url); // Tweet it $tweet = meal_to_english($meal) . " " . $url['url']; $this->load->helper('twitter_helper'); if ($meal->private == false) { $this->load->library('twitter'); $this->twitter->auth('', ''); $this->twitter->update($tweet); } // Output $this->load->view('header', $message['message'] = $tweet); $this->load->view('admin_view'); $this->load->view('footer'); }
function insert_meal($vars) { // inserts meal into db and returns confirmation message if ($vars['start'] != "") { $vars['start'] = date('Y-m-d H:i:s', strtotime($vars['start'])); } else { $vars['start'] = NULL; } if ($vars['end'] != "") { $vars['end'] = date('Y-m-d H:i:s', strtotime($vars['end'])); } else { $vars['end'] = NULL; } $this->db->insert('meals', $vars); $first_id = $this->db->insert_id(); if ($vars['repeat'] == 1) { while (strtotime($vars['start']) < 1273017600 - 604800) { // TOFIX: Hard coded May 5, 2010 if ($vars['start'] != NULL) { $vars['start'] = date('Y-m-d H:i:s', strtotime($vars['start']) + 604800); } // add a week if ($vars['end'] != NULL) { $vars['end'] = date('Y-m-d H:i:s', strtotime($vars['end']) + 604800); } $this->db->insert('meals', $vars); // This is repeated in the controller for the first instance // Generate tiny URL $this->load->helper('bitly_helper'); $bitly = new Bitly(); $bitly->set('nomealpoints', 'R_cffca0da875cf25106cfeb75291148a5'); $url = $bitly->shorten(site_url("/meal/" . $this->db->insert_id())); // Add tiny URL to DB for future access $this->meals_model->set_url($this->db->insert_id(), $url); } } return $first_id; }