Пример #1
0
 function metaWeblog_newMediaObject($args)
 {
     global $DB;
     global $session;
     $out = array();
     list($website_id, $username, $password, $file_struct) = $args;
     // check auth
     if (metaWeblog_userAllowed($username, $password, $website_id)) {
         $file_name_tmp = uniqid('metaweblog-upload-');
         file_put_contents(NAVIGATE_PRIVATE . '/' . $website_id . '/files/' . $file_name_tmp, $file_struct['bits']);
         $file = file::register_upload($file_name_tmp, $file_struct['name'], 0, NULL, false);
         @unlink(AVIGATE_PRIVATE . '/' . $website_id . '/files/' . $file_name_tmp);
         // if everything goes fine, file is renamed, so cannot be deleted here
         $out = array('id' => $file->id, 'file' => $file->name, 'url' => file::file_url($file->id, 'inline'), 'type' => $file->mime);
     } else {
         $out = new IXR_Error(401, "User not allowed.");
     }
     return $out;
 }
Пример #2
0
                     $file->refresh();
                     $DB->disconnect();
                     core_terminate();
                 }
             }
         }
     }
     echo false;
     core_terminate();
 } else {
     if ($_REQUEST['engine'] == 'tinymce') {
         $DB = new database();
         $DB->connect();
         $file = file::register_upload($_FILES['file']['tmp_name'], $_FILES['file']['name'], 0, NULL, true);
         if (!empty($file)) {
             echo json_encode(array('location' => file::file_url($file->id)));
         } else {
             echo json_encode(false);
         }
         $DB->disconnect();
         core_terminate();
     } else {
         // plUpload engine
         if ($user->permission("files.upload") == "true") {
             // Get parameters
             $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
             $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
             $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
             // Clean the fileName for security reasons
             $fileName = base64_encode($fileName);
             // Remove old temp files
Пример #3
0
 public function load_from_vimeo($reference, $cache = true)
 {
     global $website;
     if ($cache) {
         $cache = 30 * 24 * 60;
     } else {
         $cache = 0;
     }
     $info = nvweb_template_oembed_cache('vimeo', 'http://vimeo.com/api/oembed.json?url=http://vimeo.com/' . $reference . '&format=json', $cache);
     if (empty($info)) {
         return false;
     }
     $this->id = 'vimeo#' . $reference;
     $this->type = 'video';
     $this->name = $info->title;
     $this->size = NULL;
     $this->mime = 'video/vimeo';
     $this->width = $info->width;
     $this->height = $info->height;
     $this->uploaded_by = $info->author_name;
     $this->access = 0;
     $this->permission = 0;
     $this->enabled = 1;
     $this->video_thumbnail_retrieve($info->thumbnail_url, "vimeo", $reference);
     $this->extra = array('reference' => $info->video_id, 'link' => 'https://www.vimeo.com/' . $reference, 'thumbnail_url' => str_replace('http://', 'https://', $info->thumbnail_url), 'thumbnail_big' => str_replace('http://', 'https://', $info->thumbnail_url), 'thumbnail_cache' => 'private/' . $website->id . '/thumbnails/video-vimeo-' . $reference, 'thumbnail_cache_absolute' => file::file_url('private/' . $website->id . '/thumbnails/video-vimeo-' . $reference) . '&type=image', 'duration' => '', 'embed_code' => '<iframe src="https://player.vimeo.com/video/' . $reference . '?" frameborder="0" allowfullscreen></iframe>');
 }
Пример #4
0
 public static function generate_feed($id = NULL)
 {
     global $current;
     global $website;
     global $DB;
     if (empty($id)) {
         $id = $current['id'];
     }
     $item = new feed();
     $item->load($id);
     $permission = nvweb_object_enabled($item);
     if (!$permission) {
         return;
     }
     $feed = new UniversalFeedCreator();
     $feed->encoding = 'UTF-8';
     $feed->title = $item->dictionary[$current['lang']]['title'];
     $feed->description = $item->dictionary[$current['lang']]['description'];
     $feed->link = $website->absolute_path();
     $feed->syndicationURL = $website->absolute_path() . $item->paths[$current['lang']];
     if (!empty($item->image)) {
         $image = new FeedImage();
         $image->url = $website->absolute_path() . '/object?type=image&amp;id=' . $item->image;
         $image->link = $website->absolute_path();
         //$image->description = $vars['dictionary_description'];
         $feed->image = $image;
     }
     if (!empty($item->categories[0])) {
         $limit = intval($item->entries);
         if ($limit <= 0) {
             $limit = 10;
         }
         $DB->query(' SELECT SQL_CALC_FOUND_ROWS i.id, i.permission, i.date_published, i.date_unpublish,
                             i.date_to_display, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title, i.position as position,
                             i.galleries as galleries, i.template as template
                       FROM nv_items i, nv_structure s, nv_webdictionary d
                      WHERE i.category IN(' . implode(",", $item->categories) . ')
                        AND i.website = ' . $website->id . '
                        AND i.permission = 0
                        AND (i.date_published = 0 OR i.date_published < ' . core_time() . ')
                        AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ')
                        AND s.id = i.category
                        AND (s.date_published = 0 OR s.date_published < ' . core_time() . ')
                        AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ')
                        AND s.permission = 0
                        AND (s.access = 0)
                        AND (i.access = 0)
                        AND d.website = i.website
                        AND d.node_type = "item"
                        AND d.subtype = "title"
                        AND d.node_id = i.id
                        AND d.lang = ' . protect($current['lang']) . '
                      ORDER BY pdate DESC
                      LIMIT ' . $limit . '
                     OFFSET 0');
         $rs = $DB->result();
         for ($x = 0; $x < count($rs); $x++) {
             if (nvweb_object_enabled($rs[$x])) {
                 $texts = webdictionary::load_element_strings('item', $rs[$x]->id);
                 $paths = path::loadElementPaths('item', $rs[$x]->id);
                 $fitem = new FeedItem();
                 $fitem->title = $texts[$current['lang']]['title'];
                 $fitem->link = $website->absolute_path() . $paths[$current['lang']];
                 switch ($item->content) {
                     case 'title':
                         // no description
                         break;
                     case 'content':
                         $fitem->description = $texts[$current['lang']]['section-main'];
                         break;
                     case 'summary':
                     default:
                         $fitem->description = $texts[$current['lang']]['section-main'];
                         $fitem->description = str_replace(array('</p>', '<br />', '<br/>', '<br>'), array('</p>' . "\n", '<br />' . "\n", '<br/>' . "\n", '<br>' . "\n"), $fitem->description);
                         $fitem->description = core_string_cut($fitem->description, 500, '&hellip;');
                         break;
                 }
                 $fitem->date = $rs[$x]->date_to_display;
                 // find an image to attach to the item
                 // A) first enabled image in item gallery
                 // B) first image on properties
                 $image = '';
                 if (!empty($rs[$x]->galleries)) {
                     $galleries = mb_unserialize($rs[$x]->galleries);
                     $photo = @array_shift(array_keys($galleries[0]));
                     if (!empty($photo)) {
                         $image = $website->absolute_path(false) . '/object?type=image&id=' . $photo;
                     }
                 }
                 if (empty($image)) {
                     // no image found on galleries, look for image properties
                     $properties = property::load_properties("item", $rs[$x]->template, "item", $rs[$x]->id);
                     for ($p = 0; $p < count($properties); $p++) {
                         if ($properties[$p]->type == 'image') {
                             if (!empty($properties[$p]->value)) {
                                 $image = $properties[$p]->value;
                             } else {
                                 if (!empty($properties[$p]->dvalue)) {
                                     $image = $properties[$p]->dvalue;
                                 }
                             }
                             if (is_array($image)) {
                                 $image = array_values($image);
                                 $image = $image[0];
                             }
                             if (!empty($image)) {
                                 $image = $website->absolute_path(false) . '/object?type=image&id=' . $image;
                             }
                         }
                         // we only need the first image
                         if (!empty($image)) {
                             break;
                         }
                     }
                 }
                 if (!empty($image)) {
                     $fitem->image = $image;
                     // feedly will only display images of >450px --> http://blog.feedly.com/2015/07/31/10-ways-to-optimize-your-feed-for-feedly/
                     if (strpos($item->format, 'RSS') !== false) {
                         $fitem->description = '<img src="' . $image . '&width=640"><br />' . $fitem->description;
                     }
                 }
                 //$item->author = $contents->rows[$x]->author_name;
                 $feed->addItem($fitem);
             }
         }
         // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),
         // MBOX, OPML, ATOM, ATOM10, ATOM0.3, HTML, JS
         //echo $rss->saveFeed("RSS1.0", "news/feed.xml");
     }
     $xml = $feed->createFeed($item->format);
     if ($item->format == "RSS2.0") {
         // add extra tweaks to improve the feed
         $xml = str_replace('<rss ', '<rss xmlns:webfeeds="http://webfeeds.org/rss/1.0" ', $xml);
         // also available:
         // <webfeeds:cover image="http://yoursite.com/a-large-cover-image.png" />\n
         // <webfeeds:accentColor>00FF00</webfeeds:accentColor>
         $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:related layout="card" target="browser" />', $xml);
         $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:logo>' . file::file_url($item->image) . '</webfeeds:logo>', $xml);
         $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:icon>' . file::file_url($website->favicon) . '</webfeeds:icon>', $xml);
     }
     return $xml;
 }
Пример #5
0
function nvweb_properties_render($property, $vars)
{
    global $website;
    global $current;
    global $DB;
    global $session;
    global $theme;
    global $structure;
    $out = '';
    setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']);
    // if this property is null (no value assigned (null), (empty) is a value!)
    // get the default value
    if (!isset($property->value)) {
        $property->value = $property->dvalue;
    }
    // check multilanguage properties, where the value can be saved in a language but may be (null) in another language
    if (in_array($property->type, array("text", "textarea", "rich_textarea", "link")) || $property->multilanguage == 'true') {
        // cast variable as array
        if (is_object($property->value)) {
            $property->value = (array) $property->value;
        }
        if (!isset($property->value) || !isset($property->value[$current['lang']])) {
            if (isset($property->dvalue->{$current['lang']})) {
                $property->value[$current['lang']] = $property->dvalue->{$current['lang']};
            } else {
                if (!is_array($property->value)) {
                    $property->value = array();
                }
                $property->value[$current['lang']] = $property->dvalue;
            }
        }
    }
    switch ($property->type) {
        case 'value':
            $out = $property->value;
            break;
        case 'decimal':
            $out = $property->value;
            if (isset($vars['precision'])) {
                $out = number_format($property->value, $vars['precision']);
            }
            break;
        case 'boolean':
            $out = $property->value;
            break;
        case 'option':
            $options = mb_unserialize($property->options);
            $options = (array) $options;
            switch (@$vars['return']) {
                case 'value':
                    $out = $property->value;
                    break;
                default:
                    $out = $theme->t($options[$property->value]);
            }
            break;
        case 'moption':
            $options = mb_unserialize($property->options);
            $selected = explode(",", $property->value);
            switch (@$vars['return']) {
                case 'value':
                case 'values':
                    $out = $property->value;
                    break;
                default:
                    $buffer = array();
                    foreach ($selected as $seloption) {
                        $buffer[] = '<span>' . $theme->t($options[$seloption]) . '</span>';
                    }
                    $out .= implode(', ', $buffer);
            }
            break;
        case 'text':
            $out = htmlspecialchars($property->value[$current['lang']]);
            break;
        case 'textarea':
            $out = nl2br(htmlspecialchars($property->value[$current['lang']]));
            break;
        case 'rich_textarea':
            $out = $property->value[$current['lang']];
            break;
        case 'source_code':
            if (@$property->multilanguage == 'true' || $property->multilanguage == '1') {
                $out = $property->value[$current['lang']];
            } else {
                $out = $property->value;
            }
            break;
        case 'date':
            if (!empty($vars['format'])) {
                $out = Encoding::toUTF8(strftime($vars['format'], $property->value));
            } else {
                $out = date($website->date_format, $property->value);
            }
            break;
        case 'datetime':
            if (!empty($vars['format'])) {
                $out = Encoding::toUTF8(strftime($vars['format'], $property->value));
            } else {
                $out = date($website->date_format . ' H:i', $property->value);
            }
            break;
        case 'link':
            // split title and link
            $link = explode('##', $property->value[$current['lang']]);
            if (is_array($link)) {
                $target = @$link[2];
                $title = @$link[1];
                $link = $link[0];
                if (empty($title)) {
                    $title = $link;
                }
            } else {
                $title = $property->value[$current['lang']];
                $link = $property->value[$current['lang']];
                $target = '_self';
            }
            if (strpos($link, '://') === false) {
                $link = $website->absolute_path() . $link;
            }
            if ($vars['link'] === 'false') {
                $out = $link;
            } else {
                if (isset($vars['return'])) {
                    if ($vars['return'] == 'title') {
                        $out = $title;
                    } else {
                        if ($vars['return'] == 'link' || $vars['return'] == 'url') {
                            $out = $link;
                        } else {
                            if ($vars['return'] == 'target') {
                                $out = $target;
                            }
                        }
                    }
                } else {
                    $out = '<a href="' . $link . '" target="' . $target . '">' . $title . '</a>';
                }
            }
            break;
        case 'image':
            $add = '';
            $extra = '';
            if (@$property->multilanguage == 'true' || $property->multilanguage == '1') {
                $image_id = $property->value[$session['lang']];
            } else {
                $image_id = $property->value;
            }
            if (isset($vars['width'])) {
                $add .= ' width="' . $vars['width'] . '" ';
                $extra .= '&width=' . $vars['width'];
            }
            if (isset($vars['height'])) {
                $add .= ' height="' . $vars['height'] . '" ';
                $extra .= '&height=' . $vars['height'];
            }
            if (isset($vars['border'])) {
                $extra .= '&border=' . $vars['border'];
            }
            if (isset($vars['quality'])) {
                $extra .= '&quality=' . $vars['quality'];
            }
            $img_url = NVWEB_OBJECT . '?type=image&id=' . $image_id . $extra;
            if (empty($image_id)) {
                $out = '';
            } else {
                if ($vars['return'] == 'url') {
                    $out = $img_url;
                } else {
                    // retrieve additional info (title/alt), if available
                    if (is_numeric($image_id)) {
                        $f = new file();
                        $f->load($image_id);
                        $ftitle = $f->title[$current['lang']];
                        $falt = $f->description[$current['lang']];
                        if (!empty($ftitle)) {
                            $add .= ' title="' . $ftitle . '" ';
                        }
                        if (!empty($falt)) {
                            $add .= ' alt="' . $falt . '" ';
                        }
                    }
                    $out = '<img class="' . $vars['class'] . '" src="' . $img_url . '" ' . $add . ' />';
                }
            }
            break;
        case 'file':
            if (!empty($property->value)) {
                $file = $DB->query_single('name', 'nv_files', ' id = ' . protect($property->value) . ' AND website = ' . $website->id);
                if ($vars['return'] == 'url' || $vars['return'] == 'url-download') {
                    $out = NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=attachment';
                } else {
                    if ($vars['return'] == 'url-inline') {
                        $out = NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=inline';
                    } else {
                        $out = '<a href="' . NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=attachment">' . $file . '</a>';
                    }
                }
            }
            break;
        case 'comment':
            $out = $property->value;
            break;
        case 'coordinates':
            $coordinates = explode('#', $property->value);
            $out = implode(',', $coordinates);
            break;
        case 'rating':
            // half stars are always enabled (ratings fixed to 0..10)
            $out = $property->value;
            // we want nearest integer down
            if ($vars['option'] == 'floor') {
                $out = floor($out / 2);
            }
            break;
        case 'color':
            $out = $property->value;
            break;
        case 'video':
            // value may be a numeric file ID or a provider#id structure, f.e. youtube#3MteSlpxCpo
            // compatible providers: file,youtube,vimeo
            if (@$property->multilanguage == 'true' || $property->multilanguage == '1') {
                $video_id = $property->value[$session['lang']];
            } else {
                $video_id = $property->value;
            }
            $provider = '';
            $reference = '';
            $add = '';
            if (isset($vars['width'])) {
                $add .= ' width="' . $vars['width'] . '" ';
            }
            if (isset($vars['height'])) {
                $add .= ' height="' . $vars['height'] . '" ';
            }
            $url_add = '&type=image';
            if (isset($vars['width'])) {
                $url_add .= '&width=' . $vars['width'] . '';
            }
            if (isset($vars['height'])) {
                $url_add .= '&height=' . $vars['height'] . '';
            }
            if (isset($vars['border'])) {
                $url_add .= '&border=' . $vars['border'] . '';
            }
            if (strpos($video_id, '#') !== false) {
                list($provider, $reference) = explode("#", $video_id);
            }
            if ($provider == 'file') {
                $video_id = $reference;
            }
            $file = new file();
            if (is_numeric($video_id)) {
                $file->load($video_id);
                $embed = file::embed('file', $file, $add);
            } else {
                if ($provider == 'youtube') {
                    $embed = file::embed('youtube', $reference, $add);
                    if (!empty($vars['part']) || $vars['part'] != 'embed') {
                        $file->load_from_youtube($reference);
                    }
                } else {
                    if ($provider == 'vimeo') {
                        $embed = file::embed('vimeo', $reference, $add);
                        if (!empty($vars['part']) || $vars['part'] != 'embed') {
                            $file->load_from_vimeo($reference);
                        }
                    }
                }
            }
            switch (@$vars['return']) {
                case 'title':
                    $out = $file->title;
                    break;
                case 'mime':
                    $out = $file->mime;
                    break;
                case 'author':
                    if (is_numeric($file->uploaded_by)) {
                        $out = $website->name;
                    } else {
                        $out = $file->uploaded_by;
                    }
                    break;
                case 'path':
                case 'url':
                    $out = $file->extra['link'];
                    break;
                case 'thumbnail_url':
                    $out = file::file_url($file->extra['thumbnail_cache']) . $url_add;
                    break;
                case 'thumbnail':
                    $out = '<img src="' . file::file_url($file->extra['thumbnail_cache']) . $url_add . '" class="' . $vars['class'] . '" ' . $add . ' />';
                    break;
                case 'reference':
                    $out = $reference;
                    break;
                case 'provider':
                    $out = $provider;
                    break;
                case 'embed':
                default:
                    $out = $embed;
            }
            break;
        case 'article':
            // TO DO
            break;
        case 'category':
            $return = @$vars['return'];
            switch ($return) {
                case 'title':
                case 'name':
                    nvweb_menu_load_dictionary();
                    $out = $structure['dictionary'][$property->value];
                    break;
                case 'url':
                case 'link':
                    $out = nvweb_source_url('structure', $property->value);
                    break;
                default:
                    $out = $property->value;
            }
            break;
        case 'categories':
            $return = @$vars['return'];
            $value = explode(",", $property->value);
            $position = intval(@vars['position']) + 0;
            switch ($return) {
                case 'title':
                case 'name':
                    nvweb_menu_load_dictionary();
                    $out = $structure['dictionary'][$value[$position]];
                    break;
                case 'url':
                case 'link':
                    $out = nvweb_source_url('structure', $value[$position]);
                    break;
                default:
                    $out = $property->value;
            }
            break;
        case 'country':
            $return = @$vars['return'];
            switch ($return) {
                case 'name':
                    $countries = property::countries();
                    $out = $countries[$property->value];
                    break;
                case 'id':
                case 'code':
                default:
                    $out = $property->value;
                    break;
            }
            break;
        case 'elements':
            $out = $property->value;
            break;
        case 'element':
        case 'item':
            // deprecated
            $return = @$vars['return'];
            switch ($return) {
                case 'title':
                    $item = new item();
                    $item->load($property->value);
                    $out = $item->dictionary[$current['lang']]['title'];
                    break;
                case 'url':
                case 'path':
                    $out = nvweb_source_url('item', $property->value, $current['lang']);
                    break;
                case 'section':
                    $item = new item();
                    $item->load($property->value);
                    $out = $item->dictionary[$current['lang']]['section-' . $vars['section']];
                    break;
                case 'property':
                    $params = array();
                    foreach ($vars as $attr_name => $attr_value) {
                        if (strpos($attr_name, 'element-property-') === 0) {
                            $attr_name = str_replace('element-property-', '', $attr_name);
                            $params[$attr_name] = $attr_value;
                        } else {
                            if ($attr_name == 'element-property') {
                                $params['property'] = $attr_value;
                            }
                        }
                    }
                    //  default parameters
                    $params['mode'] = 'item';
                    $params['id'] = $property->value;
                    $out = nvweb_properties($params);
                    break;
                case 'id':
                default:
                    $out = $property->value;
                    break;
            }
            break;
        default:
    }
    return $out;
}
Пример #6
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new file();
    switch ($_REQUEST['act']) {
        case 1:
            // json retrieval & operations
        // json retrieval & operations
        case "json":
            if ($_REQUEST['op'] == 'upload') {
                $tmp_name = $_REQUEST['tmp_name'];
                if ($tmp_name == "{{BASE64}}") {
                    $tmp_name = base64_encode($_REQUEST['name']);
                }
                $file = file::register_upload($tmp_name, $_REQUEST['name'], $_REQUEST['parent']);
                if (!empty($file)) {
                    echo json_encode(array('id' => $file->id, 'name' => $file->name));
                } else {
                    echo json_encode(false);
                }
            }
            switch ($_REQUEST['op']) {
                case 'create_folder':
                    file::create_folder($_REQUEST['name'], $_REQUEST['mime'], $_REQUEST['parent']);
                    echo json_encode(true);
                    break;
                case 'edit_folder':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $f->mime = $_REQUEST['mime'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'edit_file':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'duplicate_file':
                    //error_reporting(~0);
                    //ini_set('display_errors', 1);
                    $status = false;
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->id = 0;
                    $f->insert();
                    if (!empty($f->id)) {
                        $done = copy(NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . intval($_REQUEST['id']), NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $f->id);
                        $status = "true";
                        if (!$done) {
                            $f->delete();
                            $status = t(56, "Unexpected error");
                        }
                    }
                    echo $status;
                    break;
                case 'move':
                    if (is_array($_REQUEST['item'])) {
                        $ok = true;
                        for ($i = 0; $i < count($_REQUEST['item']); $i++) {
                            unset($item);
                            $item = new file();
                            $item->load($_REQUEST['item'][$i]);
                            $item->parent = $_REQUEST['folder'];
                            $ok = $ok & $item->update();
                        }
                        echo json_encode($ok ? true : false);
                    } else {
                        $item->load($_REQUEST['item']);
                        $item->parent = $_REQUEST['folder'];
                        echo json_encode($item->update());
                    }
                    break;
                case 'delete':
                    try {
                        $item->load($_REQUEST['id']);
                        $status = $item->delete();
                        echo json_encode($status);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    break;
                case 'permissions':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->access = intval($_POST['access']);
                        $item->permission = intval($_POST['permission']);
                        $item->enabled = intval($_POST['enabled']);
                        $item->groups = $_POST['groups'];
                        if ($item->access < 3) {
                            $item->groups = array();
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        echo json_encode(array('access' => $item->access, 'groups' => $item->groups, 'permission' => $item->permission, 'enabled' => $item->enabled));
                    }
                    break;
                case 'description':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->title = array();
                        $item->description = array();
                        foreach ($website->languages as $language) {
                            $lcode = $language['code'];
                            if (!isset($_REQUEST['titles'][$lcode])) {
                                break;
                            }
                            $item->title[$lcode] = $_REQUEST['titles'][$lcode];
                            $item->description[$lcode] = $_REQUEST['descriptions'][$lcode];
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        // return file title and description (alt)
                        $data = array('title' => $item->title, 'description' => $item->description);
                        echo json_encode($data);
                    }
                    break;
                case 'focalpoint':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->focalpoint = $_REQUEST['top'] . '#' . $_REQUEST['left'];
                        $status = $item->save();
                        // remove cached thumbnails
                        file::thumbnails_remove($item->id);
                        echo json_encode($status);
                    } else {
                        if (empty($item->focalpoint)) {
                            $item->focalpoint = '50#50';
                            $item->save();
                            // remove cached thumbnails
                            file::thumbnails_remove($item->id);
                        }
                        echo $item->focalpoint;
                    }
                    break;
                case 'video_info':
                    if ($_REQUEST['provider'] == 'youtube') {
                        $item->load_from_youtube($_REQUEST['reference'], false);
                        // force cache reload
                    } else {
                        if ($_REQUEST['provider'] == 'vimeo') {
                            $item->load_from_vimeo($_REQUEST['reference'], false);
                            // force cache reload
                        } else {
                            if (!empty($_REQUEST['reference']) && is_numeric($_REQUEST['reference'])) {
                                $item->load($_REQUEST['reference']);
                            } else {
                                if (is_numeric($_REQUEST['provider'])) {
                                    $item->load($_REQUEST['provider']);
                                } else {
                                    unset($item);
                                }
                            }
                            if (!empty($item)) {
                                // add some extra data
                                $item->extra = array('reference' => $item->id, 'link' => '', 'thumbnail' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_big' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_url' => 'img/icons/ricebowl/mimetypes/video.png', 'duration' => '', 'embed_code' => '<video src="' . file::file_url($item->id, 'inline') . '></video>');
                            }
                        }
                    }
                    if (!empty($item)) {
                        echo json_encode($item);
                    } else {
                        echo false;
                    }
                    break;
            }
            session_write_close();
            $DB->disconnect();
            exit;
            break;
        case 2:
            // show/edit item properties
        // show/edit item properties
        case "edit":
            $item->load($_REQUEST['id']);
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    unset($item);
                    $item = new file();
                    $item->load($_REQUEST['id']);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            }
            $out = files_item_properties($item);
            break;
        case 10:
        case 'media_browser':
            files_media_browser($_GET['limit'], $_GET['offset']);
            break;
        case 92:
            // pixlr (image editor) overlay remover
        // pixlr (image editor) overlay remover
        case 'pixlr_exit':
            ob_clean();
            file::thumbnails_remove(intval($_GET['id']));
            echo '
			<html>
			<head></head>
			<body>
			<script language="javascript" type="text/javascript">
				//window.parent.eval("$(\'#thumbnail-cache\').attr(\'src\', $(\'#thumbnail-cache\').attr(\'src\') + \'&refresh=\' + new Date().getTime());");
				window.parent.eval(\'$("#image-preview").attr("src", $("#image-preview").attr("src") + "&refresh=" + new Date().getTime());\');
				window.parent.eval("pixlr.overlay.hide();");
			</script>
			</body>
			</html>	
			';
            core_terminate();
            break;
            /*	
            case 91: // picnik editing
            	ob_clean();
            	
            	// $strPicnikUrl is the URL that we use to launch Picnik.
            	$strPicnikUrl = "http://www.picnik.com/service";	
            	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
            	$aPicnikParams['_apikey'] = $website->picnik_api_key;
            	// tell Picnik where to send the exported image
            	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
            	// give the export button a title
            	$aPicnikParams['_export_title'] = t(34, 'Save');
            	// turn on the close button, and tell it to come back here
            	//$aPicnikParams['_close_target'] = $strRoot;
            	// send in the previous "king" image in case the user feels like decorating it
            	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
            	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
            	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
            
            	// tell Picnik our name.  It'll use it in a few places as appropriate
            	$aPicnikParams['_host_name'] = 'Navigate';
            	// turn off the "Save &amp; Share" tab so users don't get confused
            	$aPicnikParams['_exclude'] = "out";
            
            	echo '<html><head></head><body>';
            
            	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
            	
            	// put all the API parameters into the form as hidden inputs
            	foreach( $aPicnikParams as $key => $value ) {
            		echo "<input type='hidden' name='$key' value='$value'/>\n";
            	}
            	
            	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
            	echo "<input type='submit' value='Picnik'/>\n";
            	echo "</form>";
            	echo '<script language="javascript" type="text/javascript">
            			document.forms[0].submit();
            		  </script>';
            	echo '</body></html>';
            
            	core_terminate();
            	break;
            */
        /*	
        case 91: // picnik editing
        	ob_clean();
        	
        	// $strPicnikUrl is the URL that we use to launch Picnik.
        	$strPicnikUrl = "http://www.picnik.com/service";	
        	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
        	$aPicnikParams['_apikey'] = $website->picnik_api_key;
        	// tell Picnik where to send the exported image
        	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
        	// give the export button a title
        	$aPicnikParams['_export_title'] = t(34, 'Save');
        	// turn on the close button, and tell it to come back here
        	//$aPicnikParams['_close_target'] = $strRoot;
        	// send in the previous "king" image in case the user feels like decorating it
        	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
        	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
        	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
        
        	// tell Picnik our name.  It'll use it in a few places as appropriate
        	$aPicnikParams['_host_name'] = 'Navigate';
        	// turn off the "Save &amp; Share" tab so users don't get confused
        	$aPicnikParams['_exclude'] = "out";
        
        	echo '<html><head></head><body>';
        
        	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
        	
        	// put all the API parameters into the form as hidden inputs
        	foreach( $aPicnikParams as $key => $value ) {
        		echo "<input type='hidden' name='$key' value='$value'/>\n";
        	}
        	
        	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
        	echo "<input type='submit' value='Picnik'/>\n";
        	echo "</form>";
        	echo '<script language="javascript" type="text/javascript">
        			document.forms[0].submit();
        		  </script>';
        	echo '</body></html>';
        
        	core_terminate();
        	break;
        */
        case 0:
            // list / search result
        // list / search result
        default:
            // show requested folder or search
            $out = files_browser($_REQUEST['parent'], $_REQUEST['navigate-quicksearch']);
            users_log::action($_REQUEST['fid'], intval($_REQUEST['parent']), 'list', '', json_encode($_REQUEST));
            break;
    }
    return $out;
}