public function action_edit_field() { $field_id = $this->request->param('options'); xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content); if (count($_POST) && isset($_POST['field_name'])) { $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::not_empty', 'field_name'); if ($post->validate()) { $post_values = $post->as_array(); if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) { $post->add_error('field_name', 'User::field_name_available'); } } // Retry if ($post->validate()) { $post_values = $post->as_array(); User::update_field($field_id, $post_values['field_name']); $this->add_message('Field ' . $post_values['field_name'] . ' updated'); $this->set_formdata(array('field_name' => $post_values['field_name'])); } else { $this->add_error('Fix errors and try again'); $this->add_form_errors($post->errors()); $this->set_formdata(array_intersect_key($post->as_array(), $_POST)); } } else { $this->set_formdata(array('field_name' => User::get_data_field_name($field_id))); } }
private function list_available_data_fields() { $fields = array(); foreach (User::get_data_fields() as $field_id => $field_name) { $fields['field id="' . $field_id . '"'] = $field_name; } $this->xml_content_users = $this->xml_content->appendChild($this->dom->createElement('users')); xml::to_XML($fields, $this->xml_content_users); }
public function action_gallery() { $this->xslt_stylesheet = 'generic'; $gallery_name = $this->request->param('gallery'); if ($gallery_name == NULL) { $gallery_name = 'all'; } xml::to_XML(array('gallery_name' => $gallery_name), $this->xml_content); }
public function action_index() { Session::instance(); $this->xslt_stylesheet = 'admin/login'; $user = User::instance(); if ($user->logged_in() && ($user->get_user_data('role') == 'admin' || is_array($user->get_user_data('role')) && in_array('admin', $user->get_user_data('role')))) { $this->redirect('/admin'); } if (isset($_SESSION['modules']['pajas']['error'])) { xml::to_XML(array('error' => $_SESSION['modules']['pajas']['error']), $this->xml_content); unset($_SESSION['modules']['pajas']['error']); } }
public function action_edit_customer() { $customer_id = $this->request->param('options'); $customer_model = new Customer($customer_id); xml::to_XML(array('customer' => $customer_model->get()), $this->xml_content, NULL, 'id'); if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); if ($post->validate()) { $customer_model->set($post->as_array()); $this->add_message('Customer "' . $post->get('name') . '" updated'); } } $this->set_formdata($customer_model->get()); }
public function action_index() { // Set the name of the template to use $this->xslt_stylesheet = empty($_GET['template']) || !isset($_GET['template']) ? 'bills/default' : 'bills/' . $_GET['template']; if (isset($_GET['billnr'])) { $bill = new Bill($_GET['billnr']); } $bill_data = $bill->data; foreach ($bill_data['items'] as $nr => $item) { $bill_data['items'][$nr . 'item'] = $item; unset($bill_data['items'][$nr]); } $bill_data['due_days'] = (strtotime($bill_data['due_date']) - strtotime($bill_data['date'])) / (24 * 60 * 60); // And round it up $bill_data['due_days'] += 1; list($bill_data['due_days']) = explode('.', strval($bill_data['due_days'])); xml::to_XML(array('bill' => $bill_data), $this->xml_content, NULL, array('id', 'artnr')); /* if (isset($_GET['billnr']) && $_GET['billnr'] == 1) { $bill = array( 'bill id="1"' => array( 'customer id="1"' => array( 'name' => 'Kristoffer Nolgren Firma', 'reference' => 'Kristoffer Nolgren', 'street' => 'Lyckostigen 10', 'zip' => '18356', 'city' => 'Täby', ), 'payment_data' => array( 'date' => '2011-01-24', 'due_date' => '2011-02-13', 'item artnr="-"' => array( 'spec' => 'Webbprogrammering', 'qty' => '1', 'price' => '700', 'delivery_date' => '2010-01-03', ), ), ), ); } else die('fail'); xml::to_XML($bill, $this->xml_content); /**/ }
public function action_index() { $this->xslt_stylesheet = 'generic'; // Get all categories $this->xml_content_categories = $this->xml_content->appendChild($this->dom->createElement('categories')); xml::to_XML(Galleries::get_categories_for_xml(), $this->xml_content_categories, 'category'); // Get all galleries $this->xml_content_galleries = $this->xml_content->appendChild($this->dom->createElement('galleries')); xml::to_XML(Galleries::get_for_xml(), $this->xml_content_galleries, 'gallery'); $images = array(); foreach (Content_image::get_images(NULL, array('frontimage' => TRUE)) as $image_name => $image_data) { $images[] = $image_name; } if (count($images)) { xml::to_XML(array('frontimage' => $images[rand(0, count($images) - 1)]), $this->xml_content); } }
public function action_index() { // Remove an image if (isset($_GET['rm'])) { $image = new Content_Image($_GET['rm']); $image->rm_image(); $this->redirect(); } // Add image if (isset($_POST['upload_image'])) { foreach ($_FILES['image']['name'] as $nr => $name) { if ($name != '') { $pathinfo = pathinfo($_FILES['image']['name'][$nr]); if (strtolower($pathinfo['extension']) == 'jpg' || strtolower($pathinfo['extension']) == 'png') { $filename = 'frontimage.' . strtolower($pathinfo['extension']); $new_filename = $filename; $counter = 1; while (!Content_Image::image_name_available($new_filename)) { $new_filename = substr($filename, 0, strlen($filename) - 4) . '_' . $counter . '.' . strtolower($pathinfo['extension']); $counter++; } if (move_uploaded_file($_FILES['image']['tmp_name'][$nr], APPPATH . '/user_content/images/' . $new_filename)) { if (strtolower($pathinfo['extension']) == 'jpg') { $gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename); } elseif (strtolower($pathinfo['extension']) == 'png') { $gd_img_object = ImageCreateFromPng(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename); } $details = array('width' => array(imagesx($gd_img_object)), 'height' => array(imagesy($gd_img_object)), 'frontimage' => NULL); Content_Image::new_image($new_filename, $details); } else { $this->add_error('Unknown error uploading image(s)'); } } } } } // Images $images = array(); foreach (Content_image::get_images(NULL, array('frontimage' => TRUE)) as $image_name => $image_data) { $images[] = array('name' => $image_name); } $this->xml_content_images = $this->xml_content->appendChild($this->dom->createElement('images')); xml::to_XML($images, $this->xml_content_images, 'image'); }
public function action_entry() { // Set employees node $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees')); $employees = array('0option' => array('@value' => '0', 'None')); $counter = 1; foreach (Employees::get() as $employee) { $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']); $counter++; } xml::to_XML($employees, $employees_node); // This is for the select box if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $post->filter('floatval', 'sum'); $post->filter('floatval', 'vat'); $post->rule('strtotime', 'accounting_date'); $post->rule('strtotime', 'transfer_date'); $post->rule('Valid::not_empty', 'description'); if ($post->Validate()) { $new_transaction_data = array('accounting_date' => $post->get('accounting_date'), 'transfer_date' => $post->get('transfer_date'), 'description' => $post->get('description'), 'journal_id' => $post->get('journal_id'), 'vat' => $post->get('vat'), 'sum' => $post->get('sum'), 'employee_id' => $post->get('employee_id')); if (!isset($_GET['id'])) { $transaction = new Transaction(NULL, $new_transaction_data); $this->add_message('Transaction ' . $transaction->get_id() . ' added'); } else { $transaction = new Transaction($_GET['id']); $transaction->set($new_transaction_data); $this->add_message('Transaction ' . $transaction->get_id() . ' updated'); $this->set_formdata($transaction->get()); } } else { $this->add_form_errors($post->errors()); $this->set_formdata($post->as_array()); } } elseif (isset($_GET['id'])) { $transaction = new Transaction($_GET['id']); $this->set_formdata($transaction->get()); } else { $this->set_formdata(array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => date('Y-m-d', time()))); } }
public function action_index() { // Set the name of the template to use $this->xslt_stylesheet = 'payslip'; if (!isset($_GET['employee_id']) || !isset($_GET['period']) || !preg_match('/^\\d{4}-\\d{1,2}$/', $_GET['period'])) { throw new Kohana_exception('Invalid parameters'); } $employee = new Employee($_GET['employee_id']); xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id'); $where = ' employee_id = ' . intval($_GET['employee_id']) . ' AND ( description = \'Social fees period ' . $_GET['period'] . '\' OR description = \'Income taxes period ' . $_GET['period'] . '\' OR ( description = \'Salary payout\' AND MONTH(transfer_date) = ' . substr($_GET['period'], 5) . ' AND YEAR(transfer_date) = ' . substr($_GET['period'], 0, 4) . ' ) )'; xml::to_XML(Transactions::get(NULL, 'accounting_date', $where), $this->xml_content->appendChild($this->dom->createElement('transactions')), 'transaction', 'id'); }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct(Request $request, Response $response) { parent::__construct($request, $response); if (class_exists('User')) { /** * Must be a logged in user with admin role to access the admin pages */ $user = User::instance(); if ($user->logged_in()) { $user_data = array('@id' => $user->get_user_id(), 'username' => $user->get_username(), 'data' => array()); foreach ($user->get_user_data() as $field_name => $field_value) { $user_data['data']['field name="' . $field_name . '"'] = $field_value; } xml::to_XML(array('user_data' => $user_data), $this->xml_meta); } } if ($this->request->controller() != 'login') { /** * Build the menu alternatives */ // First we need to create the container for the options $this->menuoptions_node = $this->xml_content->appendChild($this->dom->createElement('menuoptions')); // First add the default home-alternative xml::to_XML(array(array('name' => 'Home', '@category' => '', 'description' => 'Admin home page with descriptions of the available admin pages', 'href' => '', 'position' => 0)), $this->menuoptions_node, 'menuoption'); // Then we populate this container with options from the config files, and group them by 'menuoption' foreach (Kohana::$config->load('admin_menu_options') as $menu_option) { if (is_array($user->get_role())) { if (in_array('admin', $user->get_role()) || in_array($menu_option['href'], $user->get_roles_uri())) { xml::to_XML(array($menu_option), $this->menuoptions_node, 'menuoption'); } } } if (!$user->get_user_id()) { $this->redirect('admin/login'); } } }
/** * Edit Tags * if id is set, instanciate an edit function * if not instanciate an add tag function. */ public function action_role() { $this->xml_content_types = $this->xml_content->appendChild($this->dom->createElement('roles')); xml::to_XML(Uvtag::get_tags(), $this->xml_content_types, 'role'); if (!empty($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::not_empty', 'role'); $post->rule('Valid::not_empty', 'uri'); if (isset($role)) { $tag->update($post->as_array()); $this->add_message('Role name updated'); } else { if (Uvtag::add($post->get('role'), $post->get('uri'))) { $this->add_message('Role "' . $post->get('name') . '" was added'); } else { $this->add_message('Role "' . $post->get('name') . '" could not be added'); } } } elseif (isset($tag)) { // Set the form input to the tag name. $this->set_formdata($tag->get()); } }
public function action_employee() { $statuses = array('0option' => array('@value' => 'active', '$content' => 'Active'), '1option' => array('@value' => 'inactive', '$content' => 'Inactive')); xml::to_XML($statuses, $this->xml_content->appendChild($this->dom->createElement('statuses'))); if (isset($_GET['id'])) { $employee = new Employee($_GET['id']); if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $employee->set($post->as_array()); $this->add_message('Employee ' . $_GET['id'] . ' information updated'); } $this->set_formdata($employee->get()); xml::to_XML(array('statuses' => array('1option' => array('@value' => 'active', 'Active'), '2option' => array('@value' => 'inactive', 'Inactive'))), $this->xml_content); xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id'); } elseif (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $employee_id = Employee::new_employee($post->as_array()); $this->add_message($post->get('firstname') . ' (ID: ' . $employee_id . ') was added as employee'); } else { $this->redirect(); } }
public function action_bill() { $this->xml_content_customers = $this->xml_content->appendChild($this->dom->createElement('customers')); xml::to_XML(Customers::get_customers(), $this->xml_content_customers, 'customer', 'id'); $template = array(); foreach (glob(MODPATH . 'larvconomy/xsl/bills/*') as $file) { $file_paths = explode('/', $file); $template_file = explode('.', end($file_paths)); $template[] = reset($template_file); } $this->xml_content_bill_template = $this->xml_content->appendChild($this->dom->createElement('templates')); xml::to_XML($template, $this->xml_content_bill_template, 'template'); if (!isset($_SESSION['bills']['items'])) { $_SESSION['bills']['items']['1item'] = 1; } if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $post_array = $post->as_array(); if (isset($post_array['add_item'])) { $_SESSION['bills']['items'][count($_SESSION['bills']['items']) + 1 . 'item'] = count($_SESSION['bills']['items']) + 1; $this->set_formdata($post_array); } else { $items = array(); $sum = 0; $vat_sum = 0; foreach ($_SESSION['bills']['items'] as $item_nr) { $item = array('artnr' => $post->get('artnr_item_' . $item_nr), 'spec' => $post->get('spec_item_' . $item_nr), 'price' => (double) $post->get('price_item_' . $item_nr), 'qty' => (double) $post->get('qty_item_' . $item_nr), 'delivery_date' => date('Y-m-d', time())); if ($item != array('artnr' => '', 'spec' => '', 'price' => 0, 'qty' => 0, 'delivery_date' => date('Y-m-d', time()))) { $items[] = $item; $sum += $item['qty'] * $item['price'] * 1.25; $vat_sum += $item['qty'] * $item['price'] * 0.25; } } if (count($items) && $post->validate()) { $bill_id = Bill::new_bill($post->get('customer_id'), strtotime($post->get('due_date')), $post->get('contact'), $items, $post->get('comment'), $post->get('template'), $post->get('mail_body')); $this->add_message('Created bill nr ' . $bill_id); unset($_SESSION['bills']['items']); // Create the transaction $data = array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => '0000-00-00', 'description' => 'Bill ' . $bill_id, 'vat' => $vat_sum, 'sum' => $sum, 'employee_id' => NULL, 'journal_id' => NULL); $transaction = new Transaction(NULL, $data); // End of Create the transaction // Set new default due date $this->set_formdata(array('due_date' => date('Y-m-d', time() + 20 * 24 * 60 * 60))); // Make the PDF if (Kohana::$config->load('larv.htpassword.password') && Kohana::$config->load('larv.htpassword.username')) { shell_exec('wkhtmltopdf --ignore-load-errors --username ' . Kohana::$config->load('larv.htpassword.username') . ' --password ' . Kohana::$config->load('larv.htpassword.password') . ' "' . $_SERVER['SERVER_NAME'] . URL::site('bill?billnr=' . $bill_id . '&template=' . $post->get('template')) . '" "' . APPPATH . 'user_content/pdf/bill_' . $bill_id . '.pdf"'); } else { shell_exec('wkhtmltopdf --ignore-load-errors "' . $_SERVER['SERVER_NAME'] . URL::site('bill?billnr=' . $bill_id . '&template=' . $post->get('template')) . '" "' . APPPATH . 'user_content/pdf/bill_' . $bill_id . '.pdf"'); } if (isset($_FILES)) { Bill::upload($_FILES, 'attachments/' . $bill_id); } } else { $this->add_error('Not enough data'); $post->set('due_date', date('Y-m-d', strtotime($post->get('due_date')))); $post->set('mail_body', Kohana::$config->load('larv.email.bill_message')); $this->set_formdata($post->as_array()); } } } else { $this->set_formdata(array('due_date' => date('Y-m-d', time() + 20 * 24 * 60 * 60), 'mail_body' => Kohana::$config->load('larv.email.bill_message'))); } xml::to_XML($_SESSION['bills'], $this->xml_content); }
public function before() { // Set the name of the template to use $this->xslt_stylesheet = 'admin/images'; xml::to_XML(array('admin_page' => 'Images'), $this->xml_meta); }
public function action_payout() { // Set employees node $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees')); $employees = array(); $counter = 0; $employees_from_model = Employees::get(); foreach ($employees_from_model as $employee) { $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']); $counter++; } xml::to_XML($employees, $employees_node); // This is for the select box xml::to_XML($employees_from_model, $employees_node, 'employee', 'id'); if (isset($_GET['id'])) { if (count($_POST)) { $post = new Validation($_POST); $post->filter('trim'); $salary->set($post->as_array()); } $this->set_formdata($salary->get()); xml::to_XML(array('statuses' => array('1option' => array('@value' => 'active', 'Active'), '2option' => array('@value' => 'inactive', 'Inactive'))), $this->xml_content); xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id'); $this->add_message('Employee ' . $_GET['id'] . ' information updated'); } elseif (count($_POST)) { // Add new payout $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::digit', 'amount'); $post->rule('strtotime', 'date'); if ($post->validate()) { $post_array = $post->as_array(); $transaction_data = array('accounting_date' => date('Y-m-d', strtotime($post_array['date'])), 'transfer_date' => date('Y-m-d', strtotime($post_array['date'])), 'description' => 'Salary payout', 'journal_id' => NULL, 'vat' => 0, 'sum' => -$post_array['amount'], 'employee_id' => $post_array['employee_id']); $transaction = new Transaction(NULL, $transaction_data); if ($id = $transaction->get_id()) { $this->add_message('New transaction added (ID ' . $id . ')'); } else { $this->add_error('Something f****d up'); } } else { $this->set_formdata($post->as_array()); $errors = $post->errors(); $this->add_form_errors($errors); if (isset($errors['date'])) { $this->add_form_errors(array('date' => 'Invalid date format')); } if (isset($errors['amount'])) { $this->add_form_errors(array('amount' => 'Must be numbers ONLY')); } } } }
/** * Set form data - the data that should fill out forms * * @param arr - form data * @return boolean */ public function set_formdata($formdata) { if (!isset($this->xml_content_formdata)) { $this->xml_content_formdata = $this->xml_content->appendChild($this->dom->createElement('formdata')); } $formatted_formdata = array(); foreach ($formdata as $field => $data) { $formatted_formdata[] = array('@id' => $field, '$content' => $data); } xml::to_XML($formatted_formdata, $this->xml_content_formdata, 'field'); return TRUE; }
public function action_index() { $this->xslt_stylesheet = 'admin/galleries'; xml::to_XML(array('admin_page' => 'Galleries'), $this->xml_meta); if (!empty($_POST)) { if (!empty($_POST['gallery'])) { foreach ($_POST['gallery'] as $counter => $gallery_URI) { $contents = Content_Content::get_contents_by_tags(array('gallery' => $gallery_URI, 'type' => 'sort')); if (count($contents)) { list($sort_content_id) = array_keys($contents); list($sort_content_content) = array_values($contents); $content = new Content_Content($sort_content_id); $content->update_content($counter); } else { Content_Content::new_content($counter, array('gallery' => array($gallery_URI), 'type' => array('sort'))); } } foreach ($_POST['category'] as $counter => $category_name) { $contents = Content_Content::get_contents_by_tags(array('category' => $category_name, 'type' => 'sort')); if (count($contents)) { list($sort_content_id) = array_keys($contents); list($sort_content_content) = array_values($contents); $content = new Content_Content($sort_content_id); $content->update_content($counter); } else { Content_Content::new_content($counter, array('category' => array($category_name), 'type' => array('sort'))); } } } if (!empty($_POST['new_gallery_name'])) { $this->redirect('admin/gallery?uri=' . url::title($_POST['new_gallery_name'], '-', TRUE)); } } // Get all galleries $galleries = array(); $gallery_names = array(); $categories = array(); foreach (Content_Image::get_tags() as $tag) { if ($tag['name'] == 'gallery') { foreach ($tag['values'] as $tag_value) { if (!in_array($tag_value, $gallery_names)) { $name = ''; $sort = 0; $category = ''; // Get some content $contents = Content_Content::get_contents_by_tags(array('gallery' => $tag_value)); foreach ($contents as $content) { if ($content['tags']['type'][0] == 'name') { $name = $content['content']; } elseif ($content['tags']['type'][0] == 'sort') { $sort = $content['content']; } elseif ($content['tags']['type'][0] == 'category') { $category = $content['content']; } } if ($name == '') { $name = $tag_value; } if (!in_array($category, $categories)) { $categories[] = $category; } $galleries[] = array('URI' => $tag_value, 'name' => $name, '@sort' => $sort, 'category' => $category); } $gallery_names[] = $tag_value; } } } $this->xml_content_galleries = $this->xml_content->appendChild($this->dom->createElement('galleries')); xml::to_XML($galleries, $this->xml_content_galleries, 'gallery'); foreach ($categories as $nr => $category_real_name) { if ($category_real_name != '') { $sort = 0; foreach (Content_Content::get_contents_by_tags(array('category' => $category_real_name, 'type' => 'sort')) as $content) { $sort = $content['content']; } $categories[$nr . 'category'] = array('URI' => URL::title($category_real_name, '-', TRUE), 'name' => $category_real_name, 'sort' => $sort); } unset($categories[$nr]); } $this->xml_content_categories = $this->xml_content->appendChild($this->dom->createElement('categories')); xml::to_XML($categories, $this->xml_content_categories); }
public function action_index() { $URI = $this->request->uri(); // Empty string defaults to 'welcome' if ($URI == '' || $URI == '/') { $URI = 'welcome'; } // Set the name of the template to use $this->xslt_stylesheet = 'generic'; // Initiate the page model $content_page = new Content_Page(Content_Page::get_page_id_by_uri($URI)); // Create the DOM node <page> $this->xml_content_page = $this->xml_content->appendChild($this->dom->createElement('page')); // And load the page data into it $page_data = $content_page->get_page_data(); foreach ($page_data['tag_ids'] as $template_field_id => $tag_ids) { // Get contents $contents = array(); foreach ($tag_ids as $tag_id) { foreach (Content_Content::get_contents_by_tag_id($tag_id) as $content) { if (!isset($contents[$content['id'] . 'content'])) { $contents[$content['id'] . 'content'] = array('@id' => $content['id'], 'raw' => $content['content'], 'tags' => array()); $counter = 0; foreach ($content['tags'] as $tag_name => $tag_values) { foreach ($tag_values as $tag_value) { $counter++; $contents[$content['id'] . 'content']['tags'][$counter . 'tag']['@name'] = $tag_name; if ($tag_value) { $contents[$content['id'] . 'content']['tags'][$counter . 'tag']['$value'] = $tag_value; } } } } } } // Get images $images = array(); $image_tags = array(); foreach ($tag_ids as $tag_id) { $image_tags[Tags::get_name_by_id($tag_id)] = TRUE; } $larger_counter = 0; foreach (Content_Image::get_images(NULL, $image_tags) as $image_name => $image_tags) { $image = array('@name' => $image_name, 'tags' => array()); $counter = 0; foreach ($image_tags as $tag_name => $tag_values) { if (count($tag_values)) { foreach ($tag_values as $tag_value) { $image['tags'][$counter . 'tag'] = array('@name' => $tag_name, '$value' => $tag_value); $counter++; } } else { $image['tags'][$counter . 'tag'] = array('@name' => $tag_name); $counter++; } } $images[$larger_counter . 'image'] = $image; $larger_counter++; } // Put it all in the $page_data for transport to the XML $page_data[$template_field_id . 'template_field'] = array('@id' => $template_field_id, 'contents' => $contents, 'images' => $images); } unset($page_data['tag_ids']); xml::to_XML($page_data, $this->xml_content_page, NULL, array('id', 'template_field_id')); // We need to put some HTML in from our transformator // The reason for all this mess is that we must inject this directly in to the DOM, or else the <> will get destroyed $XPath = new DOMXpath($this->dom); foreach ($XPath->query('/root/content/page/template_field/contents/content/raw') as $raw_content_node) { $html_content = call_user_func(Kohana::$config->load('content.content_transformator'), $raw_content_node->nodeValue); $html_node = $raw_content_node->parentNode->appendChild($this->dom->createElement('html')); xml::xml_to_DOM_node($html_content, $html_node); } }
public function before() { $this->xslt_stylesheet = 'admin/content'; xml::to_XML(array('admin_page' => 'Content'), $this->xml_meta); }
public function action_edit_page() { $id = $this->request->param('options'); $content_page = new Content_Page($id); if ($content_page->get_page_id()) { $this->xml_content_page = $this->xml_content->appendChild($this->dom->createElement('page')); // Get all tags associated with pages and images $this->xml_content_tags = $this->xml_content->appendChild($this->dom->createElement('tags')); $tags = array(); foreach (Content_Page::get_tags() as $tag) { $tags[] = $tag; } foreach (Content_Image::get_tags() as $tag) { foreach ($tags as $tag_to_check) { if ($tag_to_check['name'] == $tag['name']) { break 2; } } $tags[] = $tag; } foreach ($tags as $tag) { $tag_node = $this->xml_content_tags->appendChild($this->dom->createElement('tag', $tag['name'])); $tag_node->setAttribute('id', $tag['id']); } if (count($_POST) && isset($_POST['URI']) && isset($_POST['name'])) { if ($_POST['URI'] == '') { $_POST['URI'] = $_POST['name']; } $_POST['URI'] = URL::title($_POST['URI'], '-', TRUE); $post = new Validation($_POST); $post->filter('trim'); $post->rule('Valid::not_empty', 'name'); if ($post->validate()) { $post_values = $post->as_array(); $current_page_data = $content_page->get_page_data(); if ($post_values['name'] != $current_page_data['name'] && !Content_Page::page_name_available($post_values['name'])) { $post->add_error('name', 'Content_Page::page_name_available'); } if ($post_values['URI'] != $current_page_data['URI'] && !Content_Page::page_URI_available($post_values['URI'])) { $post->add_error('URI', 'Content_Page::page_URI_available'); } } // Retry if ($post->validate()) { $tags = array(); foreach ($post_values['template_position'] as $nr => $template_position) { if ($post_values['tag_id'][$nr] > 0) { if (!isset($tags[$template_position])) { $tags[$template_position] = array(); } $tags[$template_position][] = $post_values['tag_id'][$nr]; } } $content_page->update_page_data($post_values['name'], $post_values['URI'], $tags); $this->add_message('Page "' . $post_values['name'] . '" updated'); $page_data = $content_page->get_page_data(); unset($page_data['tag_ids']); $this->set_formdata($page_data); } else { $this->add_error('Fix errors and try again'); $this->add_form_errors($post->errors()); // Fix template position data $tmp_node = $this->xml_content->appendChild($this->dom->createElement('tmp')); foreach ($post_values['template_position'] as $nr => $template_position) { $template_field_node = $tmp_node->appendChild($this->dom->createElement('template_field')); $template_field_node->setAttribute('id', $template_position); if ($post_values['tag_id'][$nr] > 0) { $tag_node = $template_field_node->appendChild($this->dom->createElement('tag')); $tag_node->setAttribute('id', $post_values['tag_id'][$nr]); } } unset($post_values['template_position'], $post_values['tag_id']); $this->set_formdata($post_values); } } else { $page_data = $content_page->get_page_data(); unset($page_data['tag_ids']); $this->set_formdata($page_data); } /** * Put the page data to the XML * */ $page_data = $content_page->get_page_data(); $page_data['template_fields'] = array(); foreach ($page_data['tag_ids'] as $template_field_id => $tag_ids) { $page_data['template_fields'][$template_field_id . 'template_field'] = array('@id' => $template_field_id); foreach ($tag_ids as $tag_id) { $page_data['template_fields'][$template_field_id . 'template_field'][$tag_id . 'tag'] = array('@id' => $tag_id); } } // Unset this, or it will cludge our XML unset($page_data['tag_ids']); // Set the page data to the page node xml::to_XML($page_data, $this->xml_content_page, NULL, 'id'); } else { $this->redirect(); } }
public function action_index() { if ($_GET['uri'] == 'all') { $this->redirect(); } // Set all-gallery-settings and sort if (isset($_POST['show_in_all']) && isset($_POST['sort'])) { foreach ($_POST['sort'] as $order => $name) { $image = new Content_Image($name); $tags = array('sort' => array($order), 'gallery' => array($_GET['uri'])); if (in_array($name, $_POST['show_in_all'])) { $tags['gallery'][] = 'all'; } $image->set_data($tags); } } // Remove an image if (isset($_GET['rm'])) { $image = new Content_Image($_GET['rm']); $image->rm_image(); $this->redirect(); } // Set gallery name if (isset($_POST['name'])) { $contents = Content_Content::get_contents_by_tags(array('gallery' => $_GET['uri'], 'type' => 'name')); if (count($contents)) { list($name_content_id) = array_keys($contents); list($name_content_content) = array_values($contents); $content = new Content_Content($name_content_id); $content->update_content($_POST['name']); } else { Content_Content::new_content($_POST['name'], array('gallery' => array($_GET['uri']), 'type' => array('name'))); } } // Set gallery category if (isset($_POST['category'])) { $contents = Content_Content::get_contents_by_tags(array('gallery' => $_GET['uri'], 'type' => 'category')); if (count($contents)) { list($category_content_id) = array_keys($contents); list($category_content_content) = array_values($contents); $content = new Content_Content($category_content_id); $content->update_content($_POST['category']); } else { Content_Content::new_content($_POST['category'], array('gallery' => array($_GET['uri']), 'type' => array('category'))); } } // Set gallery description if (isset($_POST['description'])) { $contents = Content_Content::get_contents_by_tags(array('gallery' => $_GET['uri'], 'type' => 'description')); if (count($contents)) { list($description_content_id) = array_keys($contents); list($description_content_content) = array_values($contents); $content = new Content_Content($description_content_id); $content->update_content($_POST['description']); } else { Content_Content::new_content($_POST['description'], array('gallery' => array($_GET['uri']), 'type' => array('description'))); } } // Set show in menu if (isset($_POST['show_in_menu'])) { $contents = Content_Content::get_contents_by_tags(array('gallery' => $_GET['uri'], 'type' => 'show_in_menu')); if (count($contents)) { list($description_content_id) = array_keys($contents); list($description_content_content) = array_values($contents); $content = new Content_Content($description_content_id); $content->update_content('yes'); } else { Content_Content::new_content('yes', array('gallery' => array($_GET['uri']), 'type' => array('show_in_menu'))); } } elseif (!empty($_POST)) { $contents = Content_Content::get_contents_by_tags(array('gallery' => $_GET['uri'], 'type' => 'show_in_menu')); if (count($contents)) { list($description_content_id) = array_keys($contents); list($description_content_content) = array_values($contents); $content = new Content_Content($description_content_id); $content->update_content('no'); } else { Content_Content::new_content('no', array('gallery' => array($_GET['uri']), 'type' => array('show_in_menu'))); } } // Add image if (isset($_POST['upload_image'])) { foreach ($_FILES['image']['name'] as $nr => $name) { if ($name != '') { $pathinfo = pathinfo($_FILES['image']['name'][$nr]); if (strtolower($pathinfo['extension']) == 'jpg' || strtolower($pathinfo['extension']) == 'png') { $filename = URL::title($_GET['uri'], '-', TRUE) . '.' . strtolower($pathinfo['extension']); $new_filename = $filename; $counter = 1; while (!Content_Image::image_name_available($new_filename)) { $new_filename = substr($filename, 0, strlen($filename) - 4) . '_' . $counter . '.' . strtolower($pathinfo['extension']); $counter++; } if (move_uploaded_file($_FILES['image']['tmp_name'][$nr], APPPATH . '/user_content/images/' . $new_filename)) { if (strtolower($pathinfo['extension']) == 'jpg') { $gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename); } elseif (strtolower($pathinfo['extension']) == 'png') { $gd_img_object = ImageCreateFromPng(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename); } $details = array('width' => array(imagesx($gd_img_object)), 'height' => array(imagesy($gd_img_object)), 'gallery' => array('all', URL::title($_GET['uri'], '-', TRUE))); Content_Image::new_image($new_filename, $details); } else { $this->add_error('Unknown error uploading image(s)'); } } } } } // Images $images = array(); foreach (Content_image::get_images(NULL, array('gallery' => array($_GET['uri']))) as $image_name => $image_data) { $images[] = array('name' => $image_name, 'sort' => @$image_data['sort'][0], 'all' => strval(@in_array('all', $image_data['gallery']))); } $this->xml_content_images = $this->xml_content->appendChild($this->dom->createElement('images')); xml::to_XML($images, $this->xml_content_images, 'image'); // Get some content $contents = Content_Content::get_contents_by_tags(array('gallery' => $_GET['uri'])); foreach ($contents as $content) { if ($content['tags']['type'][0] == 'name') { xml::to_XML(array('gallery_real_name' => $content['content']), $this->xml_content); } elseif ($content['tags']['type'][0] == 'description') { xml::to_XML(array('gallery_description' => $content['content']), $this->xml_content); } elseif ($content['tags']['type'][0] == 'category') { xml::to_XML(array('gallery_category' => $content['content']), $this->xml_content); } elseif ($content['tags']['type'][0] == 'show_in_menu') { xml::to_XML(array('gallery_show_in_menu' => $content['content']), $this->xml_content); } } }