/** Function for the administrator to add feeds. */ public function add($feedtype = 'rss2') { //$this->template->header->this_page = 'feed_add'; $this->template->content = new View('feed_add'); // setup and initialize form field names $form = array('feed_name' => '', 'feed_url' => '', 'feed_active' => 1, 'feed_category' => 0); //copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; // check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things $post = Validation::factory(array_merge($_POST, $_FILES)); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('feed_name', 'required', 'length[3,200]'); $post->add_rules('feed_url', 'required'); //$post->add_rules('feed_active', 'required'); $post->add_rules('feed_category', 'required'); // echo " post->feed_active ".(isset($post->feed_active))?"True","FALSE" ; // exit(0); // Test to see if things passed the rule checks if ($post->validate()) { // STEP 2: SAVE INCIDENT $feed = new Feed_Model(); $feed->feed_name = $post->feed_name; $feed->feed_url = $post->feed_url; $feed->feed_active = isset($post->feed_active) ? 1 : 0; $feed->category_id = $post->feed_category; if (ORM::factory('feed')->where('feed_url', $post->feed_url)->count_all() == 0) { $feed->save(); } else { $errors['feed_url'] = 'This url is already in the database'; // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } // Notify Admin Of New Report $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_report.subject'), Kohana::lang('notifications.admin_new_report.message') . "\n\n'" . strtoupper($feed->feed_name) . "'" . "\n" . $feed->feed_url); // url::redirect('reports/thanks'); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } } $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->categories = $this->_get_categories($form['feed_category']); $this->template->header->render(TRUE); $this->template->content->render(TRUE); $this->template->Render(); }
function feeds() { $this->template->content = new View('admin/feeds'); // setup and initialize form field names $form = array('action' => '', 'feed_id' => '', 'feed_name' => '', 'feed_url' => '', 'feed_active' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; if ($_POST) { //print_r($_POST); $post = Validation::factory($_POST); // Add some filters $post->pre_filter('trim', TRUE); if ($post->action == 'a') { // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('feed_name', 'required', 'length[3,70]'); $post->add_rules('feed_url', 'required', 'url'); } if ($post->validate()) { $feed_id = $post->feed_id; $feed = new Feed_Model($feed_id); if ($post->action == 'd') { // Delete Action if ($feed->loaded == true) { ORM::factory('feed_item')->where('feed_id', $feed_id)->delete_all(); } $feed->delete($feed_id); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.deleted')); } else { if ($post->action == 'v') { // Active/Inactive Action if ($feed->loaded == true) { if ($feed->feed_active == 1) { $feed->feed_active = 0; } else { $feed->feed_active = 1; } $feed->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.modified')); } } else { if ($post->action == 'r') { $this->_parse_feed(); } else { // Save Action // SAVE Feed $feed->feed_name = $post->feed_name; $feed->feed_url = $post->feed_url; $feed->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.added_edited')); } } } } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('feeds')); $form_error = TRUE; } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('feed')->count_all())); $feeds = ORM::factory('feed')->orderby('feed_name', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset); $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->feeds = $feeds; $this->template->content->errors = $errors; // Javascript Header $this->template->colorpicker_enabled = TRUE; $this->template->js = new View('admin/feeds_js'); }
private function _save_feed($feed_id, $feed_url, $feed_category, $feed_name = "none", $weight) { $feedname = $feed_name == "none" ? $feed_url : $feed_name; if (isset($feed_url) && !empty($feed_url) && $feed_url != '' && $feed_category > 0) { $feed = new Feed_Model(); //if unique url then create new else update old. $numItems = ORM::factory('feed')->where('feed_url', $feed_url)->count_all(); if ($numItems == 0 && $feed_id == 0) { $feed->feed_name = $feedname; $feed->feed_url = $feed_url; $feed->weight = $weight; $feed->category_id = $feed_category; $feed->save(); } else { if ($feed_id != 0) { $db = new Database(); $sql = " UPDATE feed SET feed_url = '" . $feed_url . "' , feed_name = '" . $feedname . "' , weight= " . $weight . "\t"; $sql .= " WHERE id = " . $feed_id; // echo $sql."<br/>"; $Result = $db->query($sql); } } $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_report.subject'), Kohana::lang('notifications.admin_new_report.message') . "\n\n'" . strtoupper($feed->feed_name) . "'" . "\n" . $feed->feed_url); } }