Exemple #1
0
 function &getImageRef()
 {
     if (!($img_path = $this->getImageFileName())) {
         return false;
     }
     require_once 'AMP/Content/Image.inc.php';
     $image = new Content_Image();
     $image->setData($this->getImageData());
     return $image;
 }
 public static function get_for_xml()
 {
     $galleries = array();
     $gallery_names = 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;
                     $show_in_menu = 'no';
                     $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'];
                         } elseif ($content['tags']['type'][0] == 'description') {
                             $description = $content['content'];
                         } elseif ($content['tags']['type'][0] == 'show_in_menu') {
                             $show_in_menu = $content['content'];
                         }
                     }
                     if ($name == '') {
                         $name = $tag_value;
                     }
                     $images = array();
                     $counter = 0;
                     foreach (Content_image::get_images(NULL, array('gallery' => array($tag_value))) as $image_name => $image_data) {
                         @($tmp_image_sort = intval($image_data['sort'][0]));
                         if ($tag_value == 'all') {
                             $tmp_sort = 0;
                             foreach ($image_data['gallery'] as $tmp_gallery_name) {
                                 if ($tmp_gallery_name != 'all') {
                                     $tmp_contents = Content_Content::get_contents_by_tags(array('gallery' => $tmp_gallery_name, 'type' => 'sort'));
                                     foreach ($tmp_contents as $tmp_content) {
                                         $tmp_sort = $tmp_content['content'];
                                     }
                                 }
                             }
                             $image_sort = intval($tmp_sort) * 10000 + $tmp_image_sort;
                         } else {
                             $image_sort = $tmp_image_sort;
                         }
                         $images[$counter . 'image'] = array('name' => $image_name, '@sort' => $image_sort);
                         $counter++;
                     }
                     $galleries[] = array('URI' => $tag_value, 'name' => $name, 'description' => $description, 'show_in_menu' => $show_in_menu, '@sort' => $sort, 'category' => $category, 'images' => $images);
                 }
                 $gallery_names[] = $tag_value;
             }
         }
     }
     return $galleries;
 }
 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');
 }
Exemple #4
0
function process_uploaded_file($file_name, $file_path, $allow_existing_file = false)
{
    include "AMP/System/Upload.inc.php";
    include "AMP/Content/Image/Resize.inc.php";
    $upLoader = new AMPSystem_Upload($file_name);
    $image_path = AMP_CONTENT_URL_IMAGES . AMP_IMAGE_CLASS_ORIGINAL;
    $folder_okay = true;
    $is_image = false;
    if (function_exists('mime_content_type')) {
        $mime_type = mime_content_type($file_path);
        if (substr($mime_type, 0, 5) == 'image') {
            $is_image = true;
        }
    } else {
        if (isset($_REQUEST['doctype']) && $_REQUEST['doctype'] == 'img') {
            $is_image = true;
        }
    }
    if ($is_image && !$upLoader->setFolder($image_path)) {
        $folder_okay = false;
    }
    if ($folder_okay && $upLoader->execute($file_path, $allow_existing_file)) {
        $new_file_name = basename($upLoader->getTargetPath());
        $result_message = "<BR><font face='arial' size=2>File was successfully uploaded.<br>" . "<br><b>Filename:</b>" . $new_file_name . "</font>";
        //"</a></font></b><br><br><br><br><br><br><br><br>\n"
        //.return_filename($new_file_name);
        if ($is_image) {
            $reSizer = new ContentImage_Resize();
            require_once 'AMP/Content/Image.inc.php';
            if ($reSizer->setImageFile($upLoader->getTargetPath()) && $reSizer->execute()) {
                $imageRef = new Content_Image($file_name);
                $result_message = '<image src="' . $imageRef->getURL(AMP_IMAGE_CLASS_THUMB) . '" align="left" border="0">' . $result_message;
            }
        }
    } else {
        $result_message = "File Upload Failed<BR>\n" . join('<BR>', $upLoader->getErrors());
    }
    return $result_message;
}
 public function __construct()
 {
     parent::__construct();
     if (Kohana::$environment == Kohana::DEVELOPMENT) {
         if (!$this->check_db_structure()) {
             $this->create_db_structure();
             $this->insert_initial_data();
         }
     }
     // Add image files that does not exist in database
     $tracked_images = $this->get_images(NULL, array(), TRUE);
     $cwd = getcwd();
     chdir(Kohana::$config->load('user_content.dir') . '/images');
     $actual_images = glob('*.jpg');
     chdir($cwd);
     foreach (array_diff($actual_images, $tracked_images) as $non_tracked_image) {
         $pathinfo = pathinfo($non_tracked_image);
         if ($pathinfo['filename'] != URL::title($pathinfo['filename'])) {
             // We need to rename the image so it fits the URL
             $new_filename = URL::title($pathinfo['filename']);
             while (!Content_Image::image_name_available($new_filename)) {
                 $new_filename = URL::title($pathinfo['filename']) . '_' . $counter . '.jpg';
                 $counter++;
             }
             copy(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image, Kohana::$config->load('user_content.dir') . '/images/' . $new_filename . '.jpg');
             @unlink(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image);
             $non_tracked_image = $new_filename . '.jpg';
         }
         if (@($gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image))) {
             $gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image);
             $width = imagesx($gd_img_object);
             $height = imagesy($gd_img_object);
             $this->new_image($non_tracked_image, array('width' => $width, 'height' => $height));
         } else {
             // This jpg file is not a valid jpg image
             $path_parts = pathinfo($non_tracked_image);
             $new_filename = $path_parts['filename'] . '.broken_jpg';
             while (file_exists(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename)) {
                 if (!isset($counter)) {
                     $counter = 1;
                 }
                 $new_filename = $path_parts['filename'] . '_' . $counter . '.broken_jpg';
                 $counter++;
             }
             @rename(Kohana::$config->load('user_content.dir') . '/images/' . $non_tracked_image, Kohana::$config->load('user_content.dir') . '/images/' . $new_filename);
         }
     }
 }
Exemple #6
0
<?php

$image_name = AMP_find_banner_image();
if ($image_name) {
    require_once 'AMP/Content/Image.inc.php';
    $renderer = AMP_get_renderer();
    $imageRef = new Content_Image($image_name);
    $image_url = $imageRef->getURL(AMP_IMAGE_CLASS_ORIGINAL);
    print $renderer->image($image_url, array('class' => 'template_image'));
}
 public function update_image_name($old_image_name, $new_image_name)
 {
     if ($old_image_name != $new_image_name && Content_Image::image_name_available($new_image_name)) {
         $this->pdo->exec('UPDATE content_images_tags SET image_name = ' . $this->pdo->quote($new_image_name) . ' WHERE image_name = ' . $this->pdo->quote($old_image_name));
         $this->pdo->exec('UPDATE content_images      SET       name = ' . $this->pdo->quote($new_image_name) . ' WHERE       name = ' . $this->pdo->quote($old_image_name));
         return $this->rename_image_files($old_image_name, $new_image_name);
     }
     return FALSE;
 }
Exemple #8
0
<?php

defined('SYSPATH') or die('No direct script access.');
// Get all galleries
$galleries = 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, $galleries)) {
                $galleries[] = $tag_value;
                $category = '';
                $contents = Content_Content::get_contents_by_tags(array('gallery' => $tag_value, 'type' => 'category'));
                foreach ($contents as $content) {
                    $category = URL::title($content['content'], '-', TRUE);
                }
                if ($category != '') {
                    if (!in_array($category, $categories)) {
                        $categories[] = $category;
                    }
                }
            }
        }
    }
}
if (count($galleries)) {
    Route::set('galleries', '<gallery>', array('gallery' => implode('|', $galleries)))->defaults(array('controller' => 'generic', 'action' => 'gallery'));
}
if (count($categories)) {
    Route::set('categories', '<category>', array('category' => implode('|', $categories)))->defaults(array('controller' => 'generic', 'action' => 'category'));
}
Exemple #9
0
 function &getImageRef()
 {
     $empty_value = false;
     if (!($img_path = $this->getImageFileName())) {
         return $empty_value;
     }
     $image = new Content_Image($img_path);
     $image->setData($this->getImageData());
     return $image;
 }
 /**
  * Set the database driver
  *
  * @return boolean
  */
 public static function set_driver()
 {
     $driver_name = 'Driver_Content_' . ucfirst(Kohana::$config->load('content.driver'));
     return self::$driver = new $driver_name();
 }
 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 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_rm_image()
 {
     $content_image = new Content_Image($this->request->param('options'));
     $content_image->rm_image();
     $this->redirect();
 }
Exemple #14
0
 /**
  * The function returns current Page Image.
  * 
  * @access public
  * @return object The Image.
  */
 public function getImage()
 {
     $Image = new Content_Image();
     return $Image->findItem(array('Id = ' . $this->ImageId));
 }
Exemple #15
0
 function _makeThumb(&$source, $column_name)
 {
     require_once 'AMP/Content/Image.inc.php';
     $img = new Content_Image($source->getName());
     return $this->_HTML_link($img->getURL(AMP_IMAGE_CLASS_ORIGINAL), $this->_HTML_image(AMP_image_url($source->getName(), AMP_IMAGE_CLASS_THUMB), $this->_thumb_attr), array('target' => 'blank'));
 }
Exemple #16
0
 /**
  * The index handler.
  * 
  * @access public
  * @return string The HTML code.
  */
 public function index()
 {
     $Image = new Content_Image();
     $this->getView()->set('Images', $Image->findList(array(), 'Name asc'));
     return $this->getView()->render();
 }
 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);
         }
     }
 }