Exemple #1
0
 /**
  * Convert a field value to something renderable.
  *
  * @param  array			The field details
  * @param  mixed			The raw value
  * @return mixed			Rendered field (tempcode or string)
  */
 function render_field_value($field, $ev)
 {
     if (is_object($ev)) {
         return $ev;
     }
     if ($ev == '') {
         return '';
     }
     $original_filename = basename($ev);
     $download_url = (url_is_local($ev) ? get_custom_base_url() . '/' : '') . $ev;
     if (strpos($ev, '::') !== false) {
         list($ev, $original_filename) = explode('::', $ev);
         $keep = symbol_tempcode('KEEP');
         $download_url = find_script('catalogue_file') . '?original_filename=' . urlencode($original_filename) . '&file=' . urlencode(basename($ev)) . $keep->evaluate();
     }
     $extension = get_file_extension($ev);
     require_code('mime_types');
     $mime_type = get_mime_type($extension);
     if ((strpos($mime_type, 'video') !== false || strpos($mime_type, 'audio') !== false) && addon_installed('galleries')) {
         // Video/Audio HTML
         switch ($mime_type) {
             case 'video/quicktime':
                 $tpl = 'GALLERY_VIDEO_QT';
                 break;
             case 'audio/x-pn-realaudio':
                 $tpl = 'GALLERY_VIDEO_RM';
                 break;
             default:
                 $tpl = 'GALLERY_VIDEO_GENERAL';
         }
         return do_template($tpl, array('URL' => url_is_local($ev) ? get_custom_base_url() . '/' . $ev : $ev, 'WIDTH' => get_option('default_video_width'), 'HEIGHT' => get_option('default_video_height'), 'MIME_TYPE' => $mime_type));
     }
     return hyperlink($download_url, $original_filename, true, true);
 }
Exemple #2
0
 /**
  * @param string $contentId unique id
  * @param array $image 'data' or 'path' are required.
  *   'data' => image data,
  *   'path' => image path,
  *   'mimetype' => mime type,
  *   'encoding' => encoding('base64'(default) or 'quoted-printable')
  *
  * @return self
  */
 public function addImage($contentId, $image)
 {
     if (is_array($image)) {
         foreach ($image as $k => $v) {
             if (($lk = strtolower($k)) !== $k) {
                 $image[$lk] = $v;
                 unset($image[$k]);
             }
         }
     } else {
         $image = array("path" => $image);
     }
     if (!isset($image["data"]) && !isset($image["path"])) {
         $message = __METHOD__ . "() must set arg2[data](image data) or arg2[path](image path).";
         throw new Sabel_Exception_InvalidArgument($message);
     }
     if (!isset($image["data"])) {
         if (($image["data"] = @file_get_contents($image["path"])) === false) {
             $message = __METHOD__ . "() failed to open stream: No such file or directory in '{$image['path']}'.";
             throw new Sabel_Exception_FileNotFound($message);
         }
     }
     if (!isset($image["encoding"])) {
         $image["encoding"] = "base64";
     }
     if (!isset($image["mimetype"])) {
         $mimetype = get_mime_type($image["data"]);
         $image["mimetype"] = !$mimetype ? "application/octet-stream" : $mimetype;
     }
     $this->inlineImages[] = array("cid" => $contentId, "data" => $image["data"], "mimetype" => $image["mimetype"], "encoding" => $image["encoding"]);
     return $this;
 }
function metaCreateForm($metadata, $oldFilename, $real_filename)
{
    // globals
    global $course_code, $group_hidden_input;
    // lang globals
    global $langAddMetadata, $langWorkFile, $langTitle, $langTitleHelp, $langDescription, $langDescriptionHelp, $langAuthor, $langAuthorHelp, $langLanguage, $langGreek, $langEnglish, $langFrench, $langGerman, $langItalian, $langSpanish, $langLanguageHelp, $langLearningResourceType, $langLearningResourceTypeHelp, $langKeywords, $langKeywordsHelp, $langTopic, $langTopicHelp, $langSubTopic, $langSubTopicHelp, $langLevel, $langLevelHelp, $langTypicalAgeRange, $langTypicalAgeRangeHelp, $langComment, $langCommentHelp, $langCopyright, $langCopyrightHelp, $langIntentedEndUserRole, $langIntentedEndUserRoleHelp, $langOkComment, $langNotRequired;
    // variable definitions
    $metaTitle = "";
    $metaLanguage = "";
    $metaDescription = "";
    $metaAuthors = "";
    $metaKeywords = "";
    $metaRights = "";
    $metaLearningResourceTypes = "";
    $metaIntendedEndUserRoles = "";
    $metaLevels = "";
    $metaTypicalAgeRanges = "";
    $metaNotes = "";
    $metaTopic = "";
    $metaSubTopic = "";
    if (file_exists($real_filename . ".xml")) {
        $sxe = simplexml_load_file($real_filename . ".xml");
        if ($sxe) {
            $metaTitle = $sxe->general->title->string;
            $metaLanguage = $sxe->general->language;
            $metaDescription = $sxe->general->description->string;
            $metaAuthors = $sxe->lifeCycle->contribute->entity;
            $metaKeywords = $sxe->general->keyword;
            $metaRights = $sxe->rights->description->string;
            $metaLearningResourceTypes = $sxe->educational->learningResourceType;
            $metaIntendedEndUserRoles = $sxe->educational->intendedEndUserRole;
            $metaLevels = $sxe->educational->context;
            $metaTypicalAgeRanges = $sxe->educational->typicalAgeRange;
            $metaNotes = $sxe->educational->description->string;
            $metaTopic = $sxe->classification->taxonPath->source->string;
            $metaSubTopic = $sxe->classification->taxonPath->taxon->entry->string;
        }
    }
    $checkMap['meta_learningresourcetype'] = metaBuildCheckMap($metaLearningResourceTypes, "meta_learningresourcetype");
    $checkMap['meta_intendedenduserrole'] = metaBuildCheckMap($metaIntendedEndUserRoles, "meta_intendedenduserrole");
    $checkMap['meta_level'] = metaBuildCheckMap($metaLevels, "meta_level");
    $output = "\n\t<form method='post' action='index.php?course={$course_code}'>\n\t<fieldset>\n\t  <input type='hidden' name='metadataPath' value='" . q($metadata) . "' />\n\t  <input type='hidden' name='meta_filename' value='{$oldFilename}' />\n\t  <input type='hidden' name='meta_mimetype' value='" . get_mime_type($oldFilename) . "' />\n\t  {$group_hidden_input}\n\t  <legend>{$langAddMetadata}</legend>\n\t  <table class='tbl' width='100%'>\n\t  <tr>\n\t    <th>{$langWorkFile}:</th>\n\t    <td>{$oldFilename}</td>\n\t  </tr>";
    $output .= metaTextAreaRow($langTitle, "meta_title", $metaTitle, $langTitleHelp) . metaTextAreaRow($langDescription, "meta_description", $metaDescription, $langDescriptionHelp, 4) . metaCommaTextAreaRow($langAuthor, "meta_author", $metaAuthors, $langAuthorHelp);
    $cellLang = selection(array('el' => $langGreek, 'en' => $langEnglish, 'fr' => $langFrench, 'de' => $langGerman, 'it' => $langItalian, 'es' => $langSpanish), 'meta_language', $metaLanguage);
    $output .= metaFormRow($langLanguage, $cellLang, $langLanguageHelp);
    $resourceTypes = array("narrative text", "simulation", "photo", "experiment", "image", "microexperiment", "figure", "map", "diagram", "interactivemap", "graph", "exploration", "table", "interactivegame", "sound", "conceptualmap", "music", "index", "narration", "problem statement", "video", "self assessment", "animation", "questionnaire", "3danimation", "quiz", "slide", "exam", "presentation", "exercise", "lecture", "learningscenario", "textbook");
    $output .= metaCheckBoxRow($langLearningResourceType, "meta_learningresourcetype", $resourceTypes, $checkMap, $langLearningResourceTypeHelp, true) . metaCommaTextAreaRow($langKeywords, "meta_keywords", $metaKeywords, $langKeywordsHelp, 2, "string") . metaInputTextRow($langTopic, "meta_topic", $metaTopic, $langTopicHelp) . metaInputTextRow($langSubTopic, "meta_subtopic", $metaSubTopic, $langSubTopicHelp);
    $levels = array("nursery", "primary", "secondary", "highschool", "technical", "training", "higher education", "other");
    $output .= metaCheckBoxRow($langLevel, "meta_level", $levels, $checkMap, $langLevelHelp) . metaCommaInputTextRow($langTypicalAgeRange, "meta_typicalagerange", $metaTypicalAgeRanges, $langTypicalAgeRangeHelp, "string") . metaTextAreaRow($langComment, "meta_notes", $metaNotes, $langCommentHelp, 4) . metaTextAreaRow($langCopyright, "meta_rights", $metaRights, $langCopyrightHelp);
    $userRoles = array("teacher", "learner", "author", "manager", "other");
    $output .= metaCheckBoxRow($langIntentedEndUserRole, "meta_intendedenduserrole", $userRoles, $checkMap, $langIntentedEndUserRoleHelp);
    $output .= "<tr>\n\t    <th>&nbsp;</th>\n\t    <td class='right'><input class='btn btn-primary' type='submit' value='{$langOkComment}' /></td>\n\t  </tr>\n\t  <tr>\n\t    <th>&nbsp;</th>\n\t    <td class='right'>{$langNotRequired}</td>\n\t  </tr>\n\t  </table>\n\t</fieldset>\n\t</form>";
    return $output;
}
function send_file_to_client($real_filename, $filename, $disposition = null, $send_name = false, $delete = false)
{
    if (!file_exists($real_filename)) {
        return false;
    }
    $content_type = get_mime_type($filename);
    if ($content_type == 'text/html') {
        $charset = '; charset=' . html_charset($real_filename);
    } elseif ($content_type == 'text/plain') {
        $charset = '; charset=' . text_charset($real_filename);
    } else {
        $charset = '';
    }
    if ($send_name) {
        if (preg_match('/[^\\x20-\\x7E]/', $filename) and strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
            $filename = urlencode($filename);
        }
        // Add quotes to filename if it contains spaces
        if (strpos($filename, ' ') !== false) {
            $filename = '"' . $filename . '"';
        }
        $filenameattr = '; filename=' . $filename;
        if (!isset($disposition)) {
            $disposition = 'attachment';
        }
    } else {
        $filenameattr = '';
    }
    header("Content-type: {$content_type}{$charset}");
    if (isset($disposition)) {
        header("Content-Disposition: {$disposition}{$filenameattr}");
    }
    header('Pragma:');
    header('Cache-Control: public');
    header('Content-length: ' . filesize($real_filename));
    $mtime = filemtime($real_filename);
    $mdate = gmdate('D, d M Y H:i:s', $mtime);
    $etag = md5($real_filename . $mdate . $filename . filesize($real_filename));
    header('Last-Modified: ' . $mdate . ' GMT');
    header("Etag: {$etag}");
    if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER) and strtotime(preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'])) >= $mtime or array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER) and trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
        header("HTTP/1.0 304 Not Modified");
    } else {
        stop_output_buffering();
        if ($delete) {
            register_shutdown_function('unlink', $real_filename);
        }
        readfile($real_filename);
    }
    return true;
}
Exemple #5
0
 public function getMediaType($filename)
 {
     $type = get_mime_type($filename);
     switch ($type) {
         case 'image/gif':
         case 'image/jpeg':
         case 'image/pjpeg':
         case 'image/png':
             return self::typePhoto;
         case 'video/mpeg':
         case 'video/mp4':
         case 'video/ogg':
         case 'video/quicktime':
         case 'video/webm':
             return self::typeVideo;
     }
     return false;
 }
function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false)
{
    if (!$structure) {
        //$imap_uid = imap_uid ($imap, $uid);
        //echo "$uid->".$uid;
        $structure = imap_fetchstructure($imap, $uid, FT_UID);
    }
    //echo "<br/>structure-><pre>".print_r($structure)."</pre>";
    if ($structure) {
        if ($mimetype == get_mime_type($structure)) {
            if (!$partNumber) {
                $partNumber = 1;
            }
            $text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
            switch ($structure->encoding) {
                case 3:
                    return imap_base64($text);
                case 4:
                    return imap_qprint($text);
                default:
                    return $text;
            }
        }
        // multipart
        if ($structure->type == 1) {
            foreach ($structure->parts as $index => $subStruct) {
                $prefix = "";
                if ($partNumber) {
                    $prefix = $partNumber . ".";
                }
                $data = get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
                if ($data) {
                    return $data;
                }
            }
        }
    }
    return false;
}
Exemple #7
0
 /**
  * Loads an image from a file path
  *
  * @param string $filename Full path to the file which will be manipulated
  * @return ImageGD
  */
 public function load($filename)
 {
     if ($this->image) {
         imagedestroy($this->image);
         $this->image = null;
     }
     $this->type = get_mime_type($filename);
     if (preg_match('/png$/', $this->type)) {
         $this->image = imagecreatefrompng($filename);
     } elseif (preg_match('/gif$/', $this->type)) {
         $this->image = @imagecreatefromgif($filename);
     } else {
         $this->image = @imagecreatefromjpeg($filename);
     }
     if (!$this->image) {
         OPException::raise(new OPInvalidImageException('Could not create image with GD library'));
     }
     $this->filename = $filename;
     $this->width = imagesx($this->image);
     $this->height = imagesy($this->image);
     return $this;
 }
Exemple #8
0
function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
{
    if (!$structure) {
        $structure = imap_fetchstructure($stream, $msg_number);
    }
    if ($structure) {
        if ($mime_type == get_mime_type($structure)) {
            if (!$part_number) {
                $part_number = "1";
            }
            $text = imap_fetchbody($stream, $msg_number, $part_number);
            if ($structure->encoding == 3) {
                return imap_base64($text);
            } else {
                if ($structure->encoding == 4) {
                    return imap_qprint($text);
                } else {
                    return $text;
                }
            }
        }
        if ($structure->type == 1) {
            while (list($index, $sub_structure) = each($structure->parts)) {
                if ($part_number) {
                    $prefix = $part_number . '.';
                }
                $data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
                if ($data) {
                    return $data;
                }
            }
            // END OF WHILE
        }
        // END OF MULTIPART
    }
    // END OF STRUTURE
    return false;
}
Exemple #9
0
function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false)
{
    if (!$structure) {
        $structure = imap_fetchstructure($imap, $uid, FT_UID);
    }
    if ($structure) {
        if ($mimetype == get_mime_type($structure)) {
            if (!$partNumber) {
                $partNumber = 1;
            }
            $text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
            switch ($structure->encoding) {
                case 3:
                    return imap_base64($text);
                case 4:
                    return imap_qprint($text);
                default:
                    return $text;
            }
        }
        /*/ multipart */
        if ($structure->type == 1) {
            foreach ($structure->parts as $index => $subStruct) {
                $prefix = "";
                if ($partNumber) {
                    $prefix = $partNumber . ".";
                }
                $imap = '';
                $data = get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
                if ($data) {
                    return $data;
                }
            }
        }
    }
    return false;
}
Exemple #10
0
 public function getFile($file)
 {
     if (is_array($file)) {
         foreach ($file as $filepath) {
             if (file_exists($filepath)) {
                 $file = (string) $filepath;
                 break;
             }
         }
     }
     if (is_string($file) && file_exists($file)) {
         $size = filesize($file);
         $info = pathinfo($file);
         $time = date('r', filemtime($file));
         $mime = get_mime_type($info['extension']);
         if ($size > 0) {
             if ($mime !== false) {
                 $this->res->setStatus(200);
                 $this->res->addHeader('Content-Type', $mime);
                 $this->res->addHeader('Cache-Control', 'public, max-age=' . (time() + 1800));
                 $this->res->addHeader('Pragma', 'cache');
                 $this->res->addHeader('Content-Length', $size);
                 $this->res->addHeader('Content-Transfer-Encoding', 'binary');
                 $this->res->addHeader('Last-Modified', $time);
                 $this->res->write(file_get_contents($file));
             } else {
                 $this->_error(403, 'The requested filetype "' . $info['extension'] . '" are not supported');
             }
         } else {
             $this->_error(403, 'The requested file is empty (0 byte)');
         }
     } else {
         $this->_error(404, 'The requested file was not found');
     }
     // end function
 }
Exemple #11
0
function view()
{
    global $doc_root, $path_info, $url_info, $current_dir, $islinux, $filename, $passthru;
    if (intval($passthru)) {
        $file = $current_dir . $filename;
        if (file_exists($file)) {
            $is_denied = false;
            foreach ($download_ext_filter as $key => $ext) {
                if (eregi($ext, $filename)) {
                    $is_denied = true;
                    break;
                }
            }
            if (!$is_denied) {
                if ($fh = fopen("{$file}", "rb")) {
                    fclose($fh);
                    $ext = pathinfo($file, PATHINFO_EXTENSION);
                    $ctype = get_mime_type($ext);
                    if ($ctype == "application/octet-stream") {
                        $ctype = "text/plain";
                    }
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Connection: close");
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header("Cache-Control: public");
                    header("Content-Description: File Transfer");
                    header("Content-Type: " . $ctype);
                    header("Content-Disposition: inline; filename=\"" . pathinfo($file, PATHINFO_BASENAME) . "\";");
                    header("Content-Transfer-Encoding: binary");
                    header("Content-Length: " . filesize($file));
                    @readfile($file);
                    exit;
                } else {
                    alert(et('ReadDenied') . ": " . $file);
                }
            } else {
                alert(et('ReadDenied') . ": " . $file);
            }
        } else {
            alert(et('FileNotFound') . ": " . $file);
        }
        echo "\r\n\t    <script language=\"Javascript\" type=\"text/javascript\">\r\n\t    <!--\r\n\t        window.close();\r\n\t    //-->\r\n\t    </script>";
    } else {
        html_header();
        echo "<body marginwidth=\"0\" marginheight=\"0\">";
        $is_reachable_thru_webserver = stristr($current_dir, $doc_root) !== false;
        if ($is_reachable_thru_webserver) {
            $url = $url_info["scheme"] . "://" . $url_info["host"];
            if (strlen($url_info["port"])) {
                $url .= ":" . $url_info["port"];
            }
            // Malditas variaveis de sistema!! No windows doc_root é sempre em lowercase... cadê o str_ireplace() ??
            $url .= str_replace($doc_root, "", "/" . $current_dir) . $filename;
        } else {
            $url = addslashes($path_info["basename"]) . "?action=4&current_dir=" . addslashes($current_dir) . "&filename=" . addslashes($filename) . "&passthru=1";
        }
        echo "\r\n\t    <script language=\"Javascript\" type=\"text/javascript\">\r\n\t    <!--\r\n        \twindow.moveTo((window.screen.width-800)/2,((window.screen.height-600)/2)-20);\r\n\t        document.location.href='{$url}';\r\n\t    //-->\r\n\t    </script>\r\n    \t</body>\n</html>";
    }
}
function print_table($dir, $list, $allow)
{
    // print table of files
    global $dir_up;
    if (!is_array($list)) {
        return;
    }
    if ($dir != "" || strstr($dir, _EXT_PATH)) {
        echo "<tr class=\"sectiontableentry1\"><td valign=\"baseline\"><a href=\"" . make_link("list", $dir_up, NULL) . "\">";
        echo "<img border=\"0\" align=\"absmiddle\" src=\"" . _EXT_URL . "/images/up.png\" ";
        echo "alt=\"" . $GLOBALS["messages"]["uplink"] . "\" title=\"" . $GLOBALS["messages"]["uplink"] . "\"/>&nbsp;&nbsp;..</a></td>\n";
        echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
        echo "</tr>";
    }
    $i = 0;
    while (list($item, ) = each($list)) {
        if ($item == 'index.html') {
            continue;
        }
        $abs_item = get_abs_item($dir, $item);
        $is_writable = is_writable($abs_item);
        $is_chmodable = $GLOBALS['ext_File']->is_chmodable($abs_item);
        $is_readable = is_readable($abs_item);
        $is_deletable = $GLOBALS['ext_File']->is_deletable($abs_item);
        $file_info = @stat($abs_item);
        $is_file = false;
        //if(is_link($abs_item)) $extra=" -> ".@readlink($abs_item);
        if (@is_dir($abs_item)) {
            $link = make_link("list", get_rel_item($dir, $item), NULL);
        } else {
            //if(get_is_editable($dir,$item) || get_is_image($dir,$item)) {
            $link = make_link("download", $dir, $item);
            $is_file = true;
        }
        //else $link = "";
        $class = $i % 2 ? 'sectiontableentry1' : 'sectiontableentry2';
        //echo "<tr class=\"rowdata\">"
        echo '<tr class="' . $class . '">';
        // Icon + Link
        echo "<td nowrap=\"nowrap\">";
        if ($is_readable) {
            echo "<a href=\"" . $link . "\"";
            if ($is_file) {
                echo " title=\"" . $GLOBALS["messages"]["downlink"] . ": " . $item . "\"";
            }
            echo ">";
        }
        //else echo "<A>";
        echo "<img border=\"0\" ";
        echo "align=\"absmiddle\" vspace=\"5\" hspace=\"5\" src=\"" . _EXT_URL . "/images/" . get_mime_type($abs_item, "img") . "\" alt=\"\">&nbsp;";
        $s_item = $item;
        if (strlen($s_item) > 50) {
            $s_item = substr($s_item, 0, 47) . "...";
        }
        $s_item = htmlspecialchars($s_item);
        if (!$is_file) {
            echo '<strong>' . $s_item . '</strong>';
        } else {
            echo $s_item;
        }
        if ($is_readable) {
            echo "</a>";
            // ...$extra...
        }
        echo "</td>\n";
        // Size
        echo "<td>" . parse_file_size(get_file_size($abs_item)) . "</td>\n";
        // type
        echo "<td>" . get_mime_type($abs_item, "type") . "</td>\n";
        // modified
        echo "<td>" . parse_file_date(get_file_date($abs_item)) . "</td>\n";
        // actions
        echo "</tr>\n";
        $i++;
    }
}
Exemple #13
0
if (Request::int('zip') && is_file($path_file)) {
    $tmp_id = md5(uniqid("suppe"));
    $zip_path_file = "{$TMP_PATH}/{$tmp_id}";
    $tmp_file_name = escapeshellcmd("{$TMP_PATH}/{$file_name}");
    @copy($path_file, $tmp_file_name);
    if (create_zip_from_file($tmp_file_name, "{$zip_path_file}.zip") === false) {
        @unlink($zip_path_file . '.zip');
        @unlink($tmp_file_name);
        throw new Exception(_("Fehler beim Erstellen des Zip-Archivs!"));
    } else {
        $file_name = $file_name . ".zip";
        $path_file = $zip_path_file . ".zip";
        @unlink($tmp_file_name);
    }
}
$content_type = get_mime_type($file_name);
if (Request::int('force_download') || $content_type == "application/octet-stream") {
    $content_disposition = "attachment";
} else {
    $content_disposition = "inline";
}
// check if linked file is obtainable
if ($type == 6) {
    $link_data = parse_link($path_file);
    if ($link_data['response_code'] != 200) {
        throw new Exception(_("Diese Datei wird von einem externen Server geladen und ist dort momentan nicht erreichbar!"));
    }
    $filesize = $link_data['Content-Length'];
    if (!$filesize) {
        $filesize = false;
    }
Exemple #14
0
function print_table($dir, $list, $allow)
{
    // print table of files
    global $dir_up;
    if (!is_array($list)) {
        return;
    }
    if ($dir != "" || strstr($dir, _QUIXPLORER_PATH)) {
        echo "<tr class=\"row1\">\n\t  \t\t\t<td>&nbsp;</td>\n\t  \t\t\t<td valign=\"baseline\">\n\t  \t\t\t\t<a href=\"" . make_link("list", $dir_up, NULL) . "\">\n\t  \t\t\t\t<img border=\"0\" width=\"22\" height=\"22\" align=\"absmiddle\" src=\"" . _QUIXPLORER_URL . "/images/_up.png\" alt=\"" . $GLOBALS["messages"]["uplink"] . "\" title=\"" . $GLOBALS["messages"]["uplink"] . "\"/>&nbsp;&nbsp;..</a>\n\t  \t\t\t</td>\n\t  \t\t\t<td>&nbsp;</td>\n\t  \t\t\t<td>&nbsp;</td>\n\t  \t\t\t<td>&nbsp;</td>\n\t  \t\t\t<td>&nbsp;</td>\n\t  \t\t\t<td>&nbsp;</td>";
        if (extension_loaded("posix")) {
            echo "<td>&nbsp;</td>";
        }
        echo "</tr>";
    }
    $i = 0;
    $toggle = false;
    while (list($item, $info) = each($list)) {
        // link to dir / file
        if (is_array($info)) {
            $abs_item = $info;
            if (extension_loaded('posix')) {
                $user_info = posix_getpwnam($info['user']);
                $file_info['uid'] = $user_info['uid'];
                $file_info['gid'] = $user_info['gid'];
            }
        } else {
            $abs_item = get_abs_item($dir, $item);
            $file_info = @stat($abs_item);
        }
        $is_writable = @$GLOBALS['jx_File']->is_writable($abs_item);
        $is_chmodable = @$GLOBALS['jx_File']->is_chmodable($abs_item);
        $is_readable = @$GLOBALS['jx_File']->is_readable($abs_item);
        $is_deletable = @$GLOBALS['jx_File']->is_deletable($abs_item);
        $target = "";
        $extra = "";
        if (@$GLOBALS['jx_File']->is_link($abs_item)) {
            $extra = " -> " . @readlink($abs_item);
        }
        if (@get_is_dir($abs_item, '')) {
            $link = make_link("list", get_rel_item($dir, $item), NULL);
        } else {
            if (get_is_editable($abs_item) && $is_writable) {
                $link = make_link('edit', $dir, $item);
            } elseif ($is_readable) {
                if (strstr(get_abs_dir($dir), $GLOBALS['mosConfig_absolute_path']) && !$GLOBALS['jx_File']->is_link($abs_item)) {
                    $link = $GLOBALS["home_url"] . "/" . get_rel_item($dir, $item);
                    $target = '_blank';
                } else {
                    $link = make_link('download', $dir, $item);
                }
            }
        }
        if (jx_isIE()) {
            echo '<tr onmouseover="style.backgroundColor=\'#D8ECFF\';" onmouseout="style.backgroundColor=\'#EAECEE\';" bgcolor=\'#EAECEE\'>';
        } else {
            $toggle = $toggle ? '1' : '0';
            echo "<tr class=\"row{$toggle}\">";
            $toggle = !$toggle;
        }
        echo "<td><input type=\"checkbox\" id=\"item_{$i}\" name=\"selitems[]\" value=\"";
        echo urlencode($item) . "\" onclick=\"javascript:Toggle(this);\" /></td>\n";
        // Icon + Link
        echo "<td nowrap=\"nowrap\" align=\"left\">";
        if ($is_readable) {
            echo "<a href=\"" . $link . "\" target=\"" . $target . "\">";
        }
        //else echo "<<>";
        echo "<img border=\"0\" width=\"22\" height=\"22\" ";
        echo "align=\"absmiddle\" src=\"" . _QUIXPLORER_URL . "/images/" . get_mime_type($abs_item, "img") . "\" alt=\"\" />&nbsp;";
        $s_item = $item;
        if (strlen($s_item) > 50) {
            $s_item = substr($s_item, 0, 47) . "...";
        }
        echo htmlspecialchars($s_item . $extra);
        if ($is_readable) {
            echo "</a>";
            // ...$extra...
        }
        echo "</td>\n";
        // Size
        echo "<td>" . parse_file_size(get_file_size($abs_item)) . "</td>\n";
        // type
        echo "<td>" . get_mime_type($abs_item, "type") . "</td>\n";
        // modified
        echo "<td>" . parse_file_date(get_file_date($abs_item)) . "</td>\n";
        // permissions
        echo "<td>";
        if ($allow && $is_chmodable) {
            echo "<a href=\"" . make_link("chmod", $dir, $item) . "\" title=\"";
            echo $GLOBALS["messages"]["permlink"] . "\">";
        }
        $perms = get_file_perms($abs_item);
        if (strlen($perms) > 3) {
            $perms = substr($perms, 2);
        }
        echo '<strong>' . $perms . '</strong><br />' . parse_file_type($dir, $item) . parse_file_perms($perms);
        if ($allow && $is_chmodable) {
            echo "</a>";
        }
        echo "</td>\n";
        // Owner
        error_reporting(E_ALL);
        if (extension_loaded("posix")) {
            echo "<td>\n";
            $user_info = posix_getpwuid($file_info["uid"]);
            $group_info = posix_getgrgid($file_info["gid"]);
            echo $user_info["name"] . " (" . $file_info["uid"] . ") /<br/>";
            echo $group_info["name"] . " (" . $file_info["gid"] . ")";
            echo "</td>\n";
        }
        // actions
        echo "<td style=\"white-space:nowrap;\">\n";
        // Rename
        // A file that could be deleted can also be renamed
        if ($allow && $is_deletable) {
            echo "<a href=\"" . make_link("rename", $dir, $item) . "\">";
            echo "<img border=\"0\" width=\"22\" height=\"22\" ";
            echo "src=\"" . _QUIXPLORER_URL . "/images/_rename.gif\" alt=\"" . $GLOBALS["messages"]["renamelink"] . "\" title=\"";
            echo $GLOBALS["messages"]["renamelink"] . "\" /></a>\n";
        } else {
            echo "<img border=\"0\" width=\"22\" height=\"22\" ";
            echo "src=\"" . _QUIXPLORER_URL . "/images/_rename_.gif\" alt=\"" . $GLOBALS["messages"]["renamelink"] . "\" title=\"";
            echo $GLOBALS["messages"]["renamelink"] . "\" />\n";
        }
        // EDIT
        if (get_is_editable($abs_item)) {
            if ($allow && $is_writable) {
                echo "<a href=\"" . make_link("edit", $dir, $item) . "\">";
                echo "<img border=\"0\" width=\"22\" height=\"22\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_edit.png\" alt=\"" . $GLOBALS["messages"]["editlink"] . "\" title=\"";
                echo $GLOBALS["messages"]["editlink"] . "\" /></a>\n";
            } else {
                echo "<img border=\"0\" width=\"22\" height=\"22\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_edit_.png\" alt=\"" . $GLOBALS["messages"]["editlink"] . "\" title=\"";
                echo $GLOBALS["messages"]["editlink"] . "\" />\n";
            }
        } else {
            // Extract Link
            if (jx_isArchive($item) && !jx_isFTPMode()) {
                echo "<a ";
                echo "onclick=\"javascript: ClearAll();if( confirm('" . $GLOBALS["messages"]["extract_warning"] . "') ) { return true } else { return false;}\" ";
                echo "href=\"" . make_link("extract", $dir, $item) . "\" title=\"" . $GLOBALS["messages"]["extractlink"] . "\">";
                echo "<img border=\"0\" width=\"22\" height=\"20\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_extract.png\" alt=\"" . $GLOBALS["messages"]["extractlink"];
                echo "\" title=\"" . $GLOBALS["messages"]["extractlink"] . "\" /></a>\n";
            } else {
                echo "<img border=\"0\" width=\"16\" height=\"16\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_.gif\" alt=\"\" />\n";
            }
        }
        // VIEW
        if (get_is_editable($abs_item) && $GLOBALS['jx_File']->is_readable($abs_item) && get_is_file($abs_item)) {
            $link = str_replace('/index2.php', '/index3.php', make_link("view", $dir, $item));
            $status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=750,height=580,directories=no,location=no,screenX=100,screenY=100';
            echo "<a href=\"" . $link . "\" onclick=\"window.open('{$link}','win2','{$status}'); return false;\" title=\"" . $GLOBALS["messages"]["viewlink"] . "\">";
            echo "<img border=\"0\" width=\"22\" height=\"22\" ";
            echo "src=\"" . _QUIXPLORER_URL . "/images/src.gif\" alt=\"" . $GLOBALS["messages"]["viewlink"] . "\" /></a>\n";
        }
        // DOWNLOAD / Extract
        if (get_is_file($abs_item)) {
            if ($allow) {
                echo "<a href=\"" . make_link("download", $dir, $item) . "\" title=\"" . $GLOBALS["messages"]["downlink"] . "\">";
                echo "<img border=\"0\" width=\"22\" height=\"22\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_download.png\" alt=\"" . $GLOBALS["messages"]["downlink"];
                echo "\" title=\"" . $GLOBALS["messages"]["downlink"] . "\" /></a>\n";
            } else {
                if (!$allow) {
                    echo "<td><img border=\"0\" width=\"22\" height=\"22\" ";
                    echo "src=\"" . _QUIXPLORER_URL . "/images/_download_.png\" alt=\"" . $GLOBALS["messages"]["downlink"];
                    echo "\" title=\"" . $GLOBALS["messages"]["downlink"] . "\" />\n";
                }
            }
        } else {
            echo "<img border=\"0\" width=\"16\" height=\"16\" ";
            echo "src=\"" . _QUIXPLORER_URL . "/images/_.gif\" alt=\"\" />\n";
        }
        // DELETE
        if (get_is_file($abs_item)) {
            if ($allow && $GLOBALS['jx_File']->is_deletable($abs_item)) {
                $confirm_msg = sprintf($GLOBALS["messages"]["confirm_delete_file"], $item);
                echo "<a name=\"link_item_{$i}\" href=\"#link_item_{$i}\" title=\"" . $GLOBALS["messages"]["dellink"] . "\" \n\t\t\t\tonclick=\"javascript: ClearAll(); getElementById('item_{$i}').checked = true; if( confirm('" . $confirm_msg . "') ) { document.selform.do_action.value='delete'; document.selform.submit(); } else {  getElementById('item_{$i}').checked = false; return false;}\">";
                echo "<img border=\"0\" width=\"22\" height=\"22\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_delete.gif\" alt=\"" . $GLOBALS["messages"]["dellink"];
                echo "\" title=\"" . $GLOBALS["messages"]["dellink"] . "\" /></a>\n";
            } else {
                echo "<img border=\"0\" width=\"22\" height=\"22\" ";
                echo "src=\"" . _QUIXPLORER_URL . "/images/_delete_.gif\" alt=\"" . $GLOBALS["messages"]["dellink"];
                echo "\" title=\"" . $GLOBALS["messages"]["dellink"] . "\" />\n";
            }
        } else {
            echo "<img border=\"0\" width=\"16\" height=\"16\" ";
            echo "src=\"" . _QUIXPLORER_URL . "/images/_.gif\" alt=\"\" />\n";
        }
        echo "</td></tr>\n";
        $i++;
    }
}
Exemple #15
0
function ldRegisterFile($field = "file", &$error)
{
    global $ARnls, $store, $arguments;
    debug("ldRegisterFile([{$field}], [error])");
    require_once $store->code . "modules/mod_mimemagic.php";
    $result = array();
    $file_data = $arguments[$field];
    if ($file_data) {
        $file_data = base64_decode($file_data);
        if (!$file_data) {
            $error = "could not base64_decode file '{$field}'";
        } else {
            $file_temp = tempnam($store->get_config("files") . "temp", "upload");
            $fp = fopen($file_temp, "wb+");
            if (!$fp) {
                $error = "could not write file '{$field}'";
            } else {
                debug("\tfile_data (" . $file_data . ")");
                fwrite($fp, $file_data, strlen($file_data));
                fclose($fp);
                $file_type = get_mime_type($file_temp);
                $result[$field] = $field;
                $result[$field . "_temp"] = substr($file_temp, strlen($store->get_config("files") . "temp/"));
                $result[$field . "_size"] = filesize($file_temp);
                $result[$field . "_type"] = $file_type;
                debug(" http_post_vars (" . serialize($result) . ")");
            }
        }
    }
    debug("ldRegisterFile[end] ({$result})");
    return $result;
}
function sendFile($filename)
{
    $suffix = pathinfo($filename, PATHINFO_EXTENSION);
    $size = filesize_unlimited($filename);
    header('Content-Transfer-Encoding: binary');
    header('Content-Disposition: attachment; filename="' . mb_basename($filename) . '"');
    header('Content-Type: ' . get_mime_type($filename, $suffix));
    header('Content-Length: ' . $size);
    header("Content-Type: application/octet-stream");
    ob_end_flush();
    readfile($filename);
}
Exemple #17
0
function get_mime_type_from_filename($filename)
{
    $baseName = basename($filename);
    $parts = explode('.', $baseName);
    $ext = end($parts);
    return get_mime_type($ext);
}
Exemple #18
0
 private function dealWithPublic($request, $response)
 {
     $uri = $request->server['request_uri'];
     $file = realpath($this->public_path . $uri);
     if (is_file($file)) {
         if (!strncasecmp($file, $uri, strlen($this->public_path))) {
             $response->status(403);
             $response->end();
         } else {
             $response->header('Content-Type', get_mime_type($file));
             $response->sendfile($file);
         }
         return true;
     } else {
     }
     return false;
 }
function print_table($list)
{
    // print table of found items
    if (!is_array($list)) {
        return;
    }
    $cnt = count($list);
    for ($i = 0; $i < $cnt; ++$i) {
        $dir = $list[$i][0];
        $item = $list[$i][1];
        $s_dir = $dir;
        if (strlen($s_dir) > 65) {
            $s_dir = substr($s_dir, 0, 62) . "...";
        }
        $s_item = $item;
        if (strlen($s_item) > 45) {
            $s_item = substr($s_item, 0, 42) . "...";
        }
        $link = "";
        $target = "";
        if (get_is_dir($dir, $item)) {
            $img = "dir.gif";
            $link = make_link("list", get_rel_item($dir, $item), NULL);
        } else {
            $img = get_mime_type($dir, $item, "img");
            $link = make_link("download", $dir, $item);
        }
        echo "<TR><TD>" . "<IMG border=\"0\" width=\"16\" height=\"16\" ";
        echo "align=\"ABSMIDDLE\" src=\"_img/" . $img . "\" ALT=\"\">&nbsp;";
        /*if($link!="")*/
        echo "<A HREF=\"" . $link . "\" TARGET=\"" . $target . "\">";
        //else echo "<A>";
        echo $s_item . "</A></TD><TD><A HREF=\"" . make_link("list", $dir, NULL) . "\"> /";
        echo $s_dir . "</A></TD></TR>\n";
    }
}
function edit_file($dir, $item)
{
    if (!permissions_grant($dir, $item, "change")) {
        show_error($GLOBALS["error_msg"]["accessfunc"]);
    }
    if (!get_is_file($dir, $item)) {
        show_error($item . ": " . $GLOBALS["error_msg"]["fileexist"]);
    }
    if (!get_show_item($dir, $item)) {
        show_error($item . ": " . $GLOBALS["error_msg"]["accessfile"]);
    }
    $fname = get_abs_item($dir, $item);
    if (isset($GLOBALS['__POST']["dosave"]) && $GLOBALS['__POST']["dosave"] == "yes") {
        // Save / Save As
        $item = basename(stripslashes($GLOBALS['__POST']["fname"]));
        $fname2 = get_abs_item($dir, $item);
        if (!isset($item) || $item == "") {
            show_error($GLOBALS["error_msg"]["miscnoname"]);
        }
        if ($fname != $fname2 && @file_exists($fname2)) {
            show_error($item . ": " . $GLOBALS["error_msg"]["itemdoesexist"]);
        }
        savefile($fname2);
        $fname = $fname2;
    }
    // open file
    $fp = @fopen($fname, "r");
    if ($fp === false) {
        show_error($item . ": " . $GLOBALS["error_msg"]["openfile"]);
    }
    // header
    $s_item = get_rel_item($dir, $item);
    if (strlen($s_item) > 50) {
        $s_item = "..." . substr($s_item, -47);
    }
    show_header($GLOBALS["messages"]["actedit"] . ": /" . $s_item);
    // Wordwrap (works only in IE)
    ?>
<script language="JavaScript1.2" type="text/javascript">
<!--
	function chwrap() {
		if(document.editfrm.wrap.checked) {
			document.editfrm.code.wrap="soft";
		} else {
			document.editfrm.code.wrap="off";
		}
	}
// -->
</script>

<script language="Javascript" type="text/javascript">
		// initialisation
		editAreaLoader.init({
			id: "txtedit"	// id of the textarea to transform		
			,start_highlight: true	// if start with highlight
			,allow_resize: "both"
			//,min_width = 400
			//,min_height = 100
			//,allow_resize: "y"
			,allow_toggle: true
			,word_wrap: true
			,language: "<?php 
    echo $GLOBALS["language"];
    ?>
"
			,syntax: "<?php 
    echo get_mime_type($dir, $item, "ext");
    ?>
"	
		});
</script>

<?php 
    // Form
    echo "<BR><FORM name=\"editfrm\" method=\"post\" action=\"" . make_link("edit", $dir, $item) . "\">\n";
    echo "<input type=\"hidden\" name=\"dosave\" value=\"yes\">\n";
    echo "<TEXTAREA NAME=\"code\" ID=\"txtedit\" rows=\"25\" cols=\"120\" wrap=\"off\">";
    // Show File In TextArea
    $buffer = "";
    while (!feof($fp)) {
        $buffer .= fgets($fp, 4096);
    }
    @fclose($fp);
    //echo htmlspecialchars($buffer);
    echo $buffer;
    echo "</TEXTAREA><BR>\n<TABLE><TR><TD>Wordwrap: (IE only)</TD><TD><INPUT type=\"checkbox\" name=\"wrap\" ";
    echo "onClick=\"javascript:chwrap();\" value=\"1\"></TD></TR></TABLE><BR>\n";
    echo "<TABLE><TR><TD><INPUT type=\"text\" name=\"fname\" value=\"" . $item . "\"></TD>";
    echo "<TD><input type=\"submit\" value=\"" . $GLOBALS["messages"]["btnsave"];
    echo "\"></TD>\n<TD><input type=\"reset\" value=\"" . $GLOBALS["messages"]["btnreset"] . "\"></TD>\n<TD>";
    echo "<input type=\"button\" value=\"" . $GLOBALS["messages"]["btnclose"] . "\" onClick=\"javascript:location='";
    echo make_link("list", $dir, NULL) . "';\"></TD></TR></FORM></TABLE><BR>\n";
    ?>
<script language="JavaScript1.2" type="text/javascript">
<!--
	if(document.editfrm) document.editfrm.code.focus();
// -->
</script><?php 
}
Exemple #21
0
                $downloads = query("SELECT COUNT(*) FROM log l LEFT JOIN tokens t ON (l.token = t.token) LEFT JOIN files f ON (t.file = f.id) WHERE f.id = %d", $f['id'], QUERY_SINGLEVALUE);
                ?>
		<tr>
			<td><a href="admin.php?p=file&id=<?php 
                echo $f['id'];
                ?>
"><?php 
                echo $f['file'];
                ?>
</a></td>
			<td><?php 
                echo filesize($config['file_base'] . '/' . $f['file']);
                ?>
</td>
			<td><?php 
                echo get_mime_type($config['file_base'] . '/' . $f['file']);
                ?>
</td>
			<td><?php 
                echo $f['active'] ? 'yes' : 'no';
                ?>
</td>
			<td><a href="admin.php?p=tokenlist&file=<?php 
                echo $f['id'];
                ?>
"><?php 
                echo $tokens['count'];
                ?>
</a></td>
			<td><?php 
                echo $downloads;
$send_function_name = wpws_ImageUtils::get_send_function_name($file);
if (wpws_cacheIsFunctional()) {
    // Use the cache
    $mtime = filemtime($file);
    if (wpws_ImageUtils::cached_file_is_needed($src, $width, $height, $quality, $mtime)) {
        // Cache image
        wpws_ImageUtils::remove_cached_file($src, $width, $height, $quality);
        $resized_image = wpws_ImageUtils::generate_resized_image($file, $width, $height);
        $cache_filename = wpws_ImageUtils::generate_timestamped_cache_filename($src, $width, $height, $quality, $mtime);
        $send_function_name($resized_image, WPWS_CACHE_DIR . "/" . $cache_filename, $quality);
    }
    $cached_file = wpws_ImageUtils::get_cached_file($src, $width, $height, $quality);
    header("Content-Type: " . wpws_ImageUtils::get_mime_type($file));
    header("Content-Length: " . filesize($cached_file));
    readfile($cached_file);
} else {
    // Do not use the cache
    $resized_image = wpws_ImageUtils::generate_resized_image($file, $width, $height);
    ob_start();
    $send_function_name($resized_image, "", $quality);
    header("Content-Type: " . get_mime_type($file));
    header("Content-Length: " . ob_get_length());
    ob_end_flush();
}
// Delete temporary resources
if ($resized_image) {
    imagedestroy($resized_image);
}
exit;
?>
 
 /**
  * saves a file and returns the URL. returns NULL on error
  * @param string $file local path to the file that should be saved
  * @return string
  */
 public function save($file)
 {
     $object = $this->getObjectUri($file);
     $url = $this->getUrl($object);
     $headers = array();
     $headers['Content-Length'] = filesize($file);
     $headers['Content-Type'] = get_mime_type($file);
     if (isset($this->options['store_public'])) {
         $headers['x-goog-acl'] = 'public-read';
     }
     $headers = $this->getHeaders('PUT', $headers, $object);
     $curl = ch_curl($url, 'PUT', $headers, $file, NULL, 200);
     if ($curl === 200) {
         print_msg(sprintf('Upload of file %s to GCS successful. URL is %s (%s)', $file, $url, isset($this->options['store_public']) ? 'URL is publicly accessible' : 'URL is private'), isset($this->options['verbose']), __FILE__, __LINE__);
     } else {
         $url = NULL;
         print_msg(sprintf('Upload of file %s to GCS failed', $file), isset($this->options['verbose']), __FILE__, __LINE__, TRUE);
     }
     return $url;
 }
Exemple #24
0
function get_result_array($list)
{
    // print table of found items
    if (!is_array($list)) {
        return;
    }
    $cnt = count($list);
    $array = array();
    for ($i = 0; $i < $cnt; ++$i) {
        $dir = $list[$i][0];
        $item = $list[$i][1];
        $s_dir = str_replace($GLOBALS['home_dir'], '', $dir);
        if (strlen($s_dir) > 65) {
            $s_dir = substr($s_dir, 0, 62) . "...";
        }
        $s_item = $item;
        if (strlen($s_item) > 45) {
            $s_item = substr($s_item, 0, 42) . "...";
        }
        $link = "";
        $target = "";
        if (get_is_dir($dir, $item)) {
            $img = "dir.png";
            $link = ext_make_link("list", get_rel_item($dir, $item), NULL);
        } else {
            $img = get_mime_type($item, "img");
            //if(get_is_editable($dir,$item) || get_is_image($dir,$item)) {
            $link = $GLOBALS["home_url"] . "/" . get_rel_item($dir, $item);
            $target = "_blank";
            //}
        }
        $array[$i]['last_mtime'] = ext_isFTPMode() ? $GLOBALS['ext_File']->filemtime($GLOBALS['home_dir'] . '/' . $dir . '/' . $item) : filemtime($dir . '/' . $item);
        $array[$i]['file_id'] = md5($s_dir . $s_item);
        $array[$i]['dir'] = str_replace($GLOBALS['home_dir'], '', $dir);
        $array[$i]['s_dir'] = empty($s_dir) ? '' : $s_dir;
        $array[$i]['file'] = $s_item;
        $array[$i]['link'] = $link;
        $array[$i]['icon'] = _EXT_URL . "/images/{$img}";
    }
    return $array;
}
Exemple #25
0
        }
        $doc = (object) $doc;
        $doc->name = isset($doc->document_name) && $doc->document_name != '' ? $doc->document_name : 'temp.pdf';
        $doc->is_temp = 'true';
        $document = base64ToBinary($doc->document);
    } else {
        $d = MatchaModel::setSenchaModel('App.model.patient.PatientDocuments');
        $doc = $d->load($_REQUEST['id'])->one();
        if ($doc === false) {
            die('No Document Found, Please contact Support Desk. Thank You!');
        }
        $doc = (object) $doc;
        $doc->is_temp = 'false';
        $document = base64ToBinary($doc->document, $doc->encrypted);
    }
    $mineType = get_mime_type($doc->name);
    if (preg_match('/^image/', $mineType)) {
        $document = base64_encode($document);
        $html = <<<HTML
<!doctype html>
<html>
\t<head>
\t \t<meta charset="UTF-8">
\t  \t<link rel="stylesheet" href="../lib/darkroomjs/build/css/darkroom.min.css">
\t</head>
\t<body>
       \t<div class="image-container target">
\t      \t<img src="data:{$mineType};base64,{$document}" style="width:100%;" alt="" id="target" crossOrigin="anonymous">
        </div>
\t\t<script src="../lib/darkroomjs/vendor/fabric.js" data-illuminations="true"></script>
\t\t<script src="../lib/darkroomjs/build/js/darkroom.min.js" data-illuminations="true"></script>
Exemple #26
0
/**
 * Get tempcode for a Comcode rich-media attachment.
 *
 * @param  ID_TEXT		The attachment tag
 * @set attachment attachment_safe attachment2
 * @param  array			A map of the attributes (name=>val) for the tag
 * @param  array			A map of the attachment properties (name=>val) for the attachment
 * @param  string			A special identifier to mark where the resultant tempcode is going to end up (e.g. the ID of a post)
 * @param  MEMBER			The member who is responsible for this Comcode
 * @param  boolean		Whether to check as arbitrary admin
 * @param  object			The database connection to use
 * @param  ?array			A list of words to highlight (NULL: none)
 * @param  ?MEMBER		The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating)
 * @param  boolean		Whether to parse so as to create something that would fit inside a semihtml tag. It means we generate HTML, with Comcode written into it where the tag could never be reverse-converted (e.g. a block).
 * @return tempcode		The tempcode for the attachment
 */
function render_attachment($tag, $attributes, $attachment, $pass_id, $source_member, $as_admin, $connection, $highlight_bits = NULL, $on_behalf_of_member = NULL, $semiparse_mode = false)
{
    require_code('comcode_renderer');
    $extension = get_file_extension($attachment['a_original_filename']);
    require_code('mime_types');
    $mime_type = get_mime_type($extension);
    $attachment['CLEAN_SIZE'] = clean_file_size($attachment['a_file_size']);
    $attachment['MIME_TYPE'] = $mime_type;
    $attachment['PASS_ID'] = intval($pass_id) < 0 ? strval(mt_rand(0, 10000)) : $pass_id;
    $attachment['SCRIPT'] = find_script('attachment');
    $attachment['RAND'] = strval(mt_rand(0, 32000));
    if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
        $attachment['SUP_PARAMS'] = '&forum_db=1';
        $attachment['FORUM_DB_BIN'] = '1';
    } else {
        $attachment['SUP_PARAMS'] = '';
        $attachment['FORUM_DB_BIN'] = '';
    }
    $type = trim(array_key_exists('type', $attributes) ? $attributes['type'] : 'auto');
    $attachment['id'] = strval($attachment['id']);
    $attachment['a_member_id'] = strval($attachment['a_member_id']);
    $attachment['a_file_size'] = strval($attachment['a_file_size']);
    $attachment['a_last_downloaded_time'] = is_null($attachment['a_last_downloaded_time']) ? '' : strval($attachment['a_last_downloaded_time']);
    $attachment['a_add_time'] = strval($attachment['a_add_time']);
    $attachment['a_num_downloads'] = integer_format($attachment['a_num_downloads']);
    require_code('images');
    $attachment['a_width'] = array_key_exists('width', $attributes) ? strval(intval($attributes['width'])) : '';
    $attachment['a_height'] = array_key_exists('height', $attributes) ? strval(intval($attributes['height'])) : '';
    if ($attachment['a_width'] == '' || $attachment['a_height'] == '') {
        if (addon_installed('galleries') && is_video($attachment['a_original_filename']) && url_is_local($attachment['a_url'])) {
            require_code('galleries2');
            $vid_details = get_video_details(get_custom_file_base() . '/' . rawurldecode($attachment['a_url']), $attachment['a_original_filename'], true);
            if ($vid_details !== false) {
                list($_width, $_height, ) = $vid_details;
                if ($attachment['a_width'] == '') {
                    $attachment['a_width'] = strval($_width);
                }
                if ($attachment['a_height'] == '') {
                    $attachment['a_height'] = strval($_height);
                }
            }
        }
        if ($attachment['a_width'] == '' || $attachment['a_height'] == '') {
            if ($attachment['a_width'] == '') {
                $attachment['a_width'] = '240';
            }
            if ($attachment['a_height'] == '') {
                $attachment['a_height'] = '216';
            }
        }
    }
    $attachment['a_align'] = array_key_exists('align', $attributes) ? $attributes['align'] : 'left';
    if (!array_key_exists('a_description', $attachment)) {
        if (array_key_exists('description', $attributes)) {
            $attachment['description'] = $attributes['description'];
        }
        if (!array_key_exists('description', $attachment)) {
            $attachment['description'] = '';
        }
        $attachment['a_description'] = is_object($attachment['description']) ? $attachment['description'] : comcode_to_tempcode($attachment['description'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, NULL, $on_behalf_of_member);
    } else {
        $attachment['a_description'] = comcode_to_tempcode($attachment['a_description'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, NULL, $on_behalf_of_member);
    }
    $attachment['a_type'] = $type;
    $attachment['a_thumb'] = array_key_exists('thumb', $attributes) ? $attributes['thumb'] : '1';
    if ($attachment['a_thumb'] != '0') {
        $attachment['a_thumb'] = '1';
    }
    $attachment['a_thumb_url'] = array_key_exists('thumb_url', $attributes) ? $attributes['thumb_url'] : $attachment['a_thumb_url'];
    switch ($type) {
        case 'email':
            require_code('mail');
            global $EMAIL_ATTACHMENTS;
            if (url_is_local($attachment['a_url'])) {
                $attachment['a_url'] = get_custom_base_url() . '/' . $attachment['a_url'];
            }
            $EMAIL_ATTACHMENTS[$attachment['a_url']] = $attachment['a_original_filename'];
            $temp_tpl = new ocp_tempcode();
            break;
        case 'code':
            $url = $attachment['a_url'];
            if (url_is_local($url)) {
                $url = get_custom_base_url() . '/' . $url;
            }
            $file_contents = http_download_file($url, 1024 * 1024 * 20);
            list($_embed, $title) = do_code_box($extension, make_string_tempcode($file_contents));
            if ($attachment['a_original_filename'] != '') {
                $title = escape_html($attachment['a_original_filename']);
            }
            $temp_tpl = do_template('COMCODE_CODE', array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true, 'STYLE' => '', 'TYPE' => $extension, 'CONTENT' => $_embed, 'TITLE' => $title));
            break;
        case 'hyperlink':
            if ($tag == 'attachment') {
                $keep = symbol_tempcode('KEEP');
                $_url = new ocp_tempcode();
                $_url->attach(find_script('attachment') . '?id=' . urlencode($attachment['id']) . $keep->evaluate());
                if (get_option('anti_leech') == '1') {
                    $_url->attach('&for_session=');
                    $_url->attach(symbol_tempcode('SESSION_HASHED'));
                }
            } else {
                $url = $attachment['a_url'];
                if (url_is_local($url)) {
                    $url = get_custom_base_url() . '/' . $url;
                }
                $_url = make_string_tempcode($url);
            }
            $temp_tpl = hyperlink($_url, is_object($attachment['a_description']) ? $attachment['a_description']->evaluate() : $attachment['a_description'] != '' ? $attachment['a_description'] : $attachment['a_original_filename'], true);
            break;
        default:
            if (is_image($attachment['a_original_filename'])) {
                if ($type == 'inline' || $type == 'left_inline' || $type == 'right_inline') {
                    $attachment['mini'] = '1';
                }
                require_code('images');
                ensure_thumbnail($attachment['a_url'], $attachment['a_thumb_url'], 'attachments', 'attachments', intval($attachment['id']), 'a_thumb_url');
                $temp_tpl = do_template('ATTACHMENT_IMG' . (array_key_exists('mini', $attachment) && $attachment['mini'] == '1' ? '_MINI' : ''), map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
                if ($type == 'left' || $type == 'left_inline') {
                    $temp_tpl = do_template('ATTACHMENT_LEFT', array('_GUID' => 'aee2a6842d369c8dae212c3478a3a3e9', 'WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true, 'CONTENT' => $temp_tpl));
                }
                if ($type == 'right' || $type == 'right_inline') {
                    $temp_tpl = do_template('ATTACHMENT_RIGHT', array('_GUID' => '1a7209d67d91db740c86e7a331720195', 'WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true, 'CONTENT' => $temp_tpl));
                }
                break;
            } elseif ($extension == 'swf') {
                $temp_tpl = do_template('ATTACHMENT_SWF', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
                break;
            } elseif (addon_installed('jwplayer') && ($mime_type == 'video/x-flv' || $mime_type == 'video/mp4' || $mime_type == 'video/webm')) {
                $temp_tpl = do_template('ATTACHMENT_FLV', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
                break;
            } elseif ($mime_type == 'video/quicktime') {
                $temp_tpl = do_template('ATTACHMENT_QT', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
                break;
            } elseif ($mime_type == 'audio/x-pn-realaudio') {
                $temp_tpl = do_template('ATTACHMENT_RM', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
                break;
            } elseif (substr($mime_type, 0, 5) == 'video' || substr($mime_type, 0, 5) == 'audio') {
                $temp_tpl = do_template('ATTACHMENT_MEDIA', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
                break;
            }
            // Continues on, as it's not a media type...
        // Continues on, as it's not a media type...
        case 'download':
            if (is_null($attachment['a_file_size'])) {
                $temp_tpl = do_template('ATTACHMENT_DOWNLOAD_REMOTE', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
            } else {
                $temp_tpl = do_template('ATTACHMENT_DOWNLOAD', map_keys_to_upper($attachment) + array('WYSIWYG_SAFE' => $tag == 'attachment' ? NULL : true));
            }
            break;
    }
    return $temp_tpl;
}
    $altfilename = hook("downloadfilenamealt");
    if (!$altfilename) {
        $filename = preg_replace('/:/', '_', $filename);
    } else {
        $filename = $altfilename;
    }
    hook("downloadfilename");
    if (!$direct) {
        # We use quotes around the filename to handle filenames with spaces.
        header(sprintf('Content-Disposition: attachment; filename="%s"', $filename));
    }
}
# We assign a default mime-type, in case we can find the one associated to the file extension.
$mime = "application/octet-stream";
if ($noattach == "") {
    $mime = get_mime_type($path);
}
# We declare the downloaded content mime type.
header("Content-Type: {$mime}");
set_time_limit(0);
if (!hook("replacefileoutput")) {
    # New method
    $sent = 0;
    $handle = fopen($path, "r");
    // Now we need to loop through the file and echo out chunks of file data
    while ($sent < $filesize) {
        echo fread($handle, $download_chunk_size);
        ob_flush();
        $sent += $download_chunk_size;
    }
}
function load_url($url, $fix_encoding = true, $if_modified_since = false)
{
    /*{{{*/
    $cookie_file =& $GLOBALS['_system_cookie_file'];
    if (!$cookie_file) {
        $cookie_file = new tmpfile_manager();
    }
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 20);
    if ($if_modified_since !== false) {
        curl_setopt($curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
        curl_setopt($curl, CURLOPT_TIMEVALUE, $if_modified_since);
    }
    $content = curl_exec($curl);
    if ($if_modified_since !== false) {
        if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 304) {
            return true;
        }
        // Not modified
    }
    if (curl_getinfo($curl, CURLINFO_HTTP_CODE) >= 400 || curl_errno($curl) != 0 || !$content) {
        throw new Exception("Die URL konnte nicht geladen werden: " . curl_error($curl));
    }
    curl_close($curl);
    $maximal_cache_size = parse_human_readable_file_size($GLOBALS['allowed_cache_file_size']);
    if (strlen($content) > $maximal_cache_size) {
        throw new Exception("Datei zu groß. Dateien über " . round($maximal_cache_size / 1024 / 1024) . "Mb Größe können aus Sicherheitsgründen nicht heruntergeladen werden.");
    }
    $type = get_mime_type($content, true);
    if (preg_match('/^[^;]+/', $type, $match)) {
        $type = $match[0];
    }
    if (array_search($type, $GLOBALS['allowed_cache_types']) === false) {
        throw new Exception("Dateityp " . $type . " unbekannt. Aus Sicherheitsgründen können nur bestimmte Dateitypen heruntergeladen werden.");
    }
    if (!$fix_encoding) {
        return $content;
    }
    return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
Exemple #29
0
function xmldb_artefact_file_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2007010900) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('adminfiles');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
        add_field($table, $field);
        set_field('artefact_file_files', 'adminfiles', 0);
        // Put all folders into artefact_file_files
        $folders = get_column_sql("\n            SELECT a.id\n            FROM {artefact} a\n            LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact\n            WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
        if ($folders) {
            foreach ($folders as $folderid) {
                $data = (object) array('artefact' => $folderid, 'adminfiles' => 0);
                insert_record('artefact_file_files', $data);
            }
        }
    }
    if ($oldversion < 2007011800) {
        // Make sure the default quota is set
        set_config_plugin('artefact', 'file', 'defaultquota', 10485760);
    }
    if ($oldversion < 2007011801) {
        // Create image table
        $table = new XMLDBTable('artefact_file_image');
        $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
        $status = $status && create_table($table);
        $images = get_column('artefact', 'id', 'artefacttype', 'image');
        log_debug(count($images));
        require_once get_config('docroot') . 'artefact/lib.php';
        foreach ($images as $imageid) {
            $image = artefact_instance_from_id($imageid);
            $path = $image->get_path();
            $image->set('dirty', false);
            $data = new StdClass();
            $data->artefact = $imageid;
            if (file_exists($path)) {
                list($data->width, $data->height) = getimagesize($path);
            }
            if (empty($data->width) || empty($data->height)) {
                $data->width = 0;
                $data->height = 0;
            }
            insert_record('artefact_file_image', $data);
        }
    }
    if ($oldversion < 2007013100) {
        // Add new tables for file/mime types
        $table = new XMLDBTable('artefact_file_file_types');
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
        create_table($table);
        $table = new XMLDBTable('artefact_file_mime_types');
        $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
        $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        create_table($table);
        safe_require('artefact', 'file');
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2007021400) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('oldextension');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
    }
    if ($oldversion < 2007042500) {
        // migrate everything we had to change to  make mysql happy
        execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
    }
    if ($oldversion < 2008091100) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('fileid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        add_field($table, $field);
        execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL");
    }
    if ($oldversion < 2008101602) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('filetype');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
        // Guess mime type for existing files
        $fileartefacts = get_records_sql_array('
            SELECT
                a.artefacttype, f.artefact, f.oldextension, f.fileid
            FROM
                {artefact} a,
                {artefact_file_files} f
            WHERE
                a.id = f.artefact
        ', array());
        require_once get_config('libroot') . 'file.php';
        if ($fileartefacts) {
            foreach ($fileartefacts as $a) {
                $type = null;
                if ($a->artefacttype == 'image') {
                    $size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                    $type = $size['mime'];
                } else {
                    if ($a->artefacttype == 'profileicon') {
                        $size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        $type = $size['mime'];
                    } else {
                        if ($a->artefacttype == 'file') {
                            $type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        }
                    }
                }
                if ($type) {
                    set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact);
                }
            }
        }
        delete_records('config', 'field', 'pathtofile');
    }
    if ($oldversion < 2008101701) {
        if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
            $olddata = unserialize($data);
            $newdata = array();
            foreach ($olddata as $d) {
                if ($d == 'mov') {
                    $newdata[] = 'quicktime';
                } else {
                    if ($d == 'mp4') {
                        $newdata[] = 'mp4_video';
                    } else {
                        if ($d != 'mpg') {
                            $newdata[] = $d;
                        }
                    }
                }
            }
            set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata));
        }
    }
    if ($oldversion < 2009021200) {
        $table = new XMLDBTable('artefact_file_mime_types');
        $key = new XMLDBKey('artefilemimetype_des_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        drop_key($table, $key);
        $table = new XMLDBTable('artefact_file_file_types');
        drop_table($table);
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2009021301) {
        // IE has been uploading jpegs with the image/pjpeg mimetype,
        // which is not recognised as an image by the download script.
        // Fix all existing jpegs in the db:
        set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg');
        // This won't happen again because we now read the contents of the
        // uploaded file to detect image artefacts, and overwrite the mime
        // type declared by the browser if we see an image.
    }
    if ($oldversion < 2009033000) {
        if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) {
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1));
        }
    }
    return $status;
}
Exemple #30
0
/**
 * This function assembles an array (list) of files or directories in the directory specified by $dir
 * The result array is send using JSON
 *
 * @param string $dir
 * @param string $sendWhat Can be "files" or "dirs"
 */
function send_dircontents($dir, $sendWhat = 'files')
{
    // print table of files
    global $dir_up, $mainframe;
    // make file & dir tables, & get total filesize & number of items
    get_dircontents($dir, $dir_list, $file_list, $tot_file_size, $num_items);
    if ($sendWhat == 'files') {
        $list = $file_list;
    } elseif ($sendWhat == 'dirs') {
        $list = $dir_list;
    } else {
        $list = make_list($dir_list, $file_list);
    }
    $i = 0;
    $items['totalCount'] = count($list);
    $items['items'] = array();
    $dirlist = array();
    if ($sendWhat != 'dirs') {
        // Replaced array_splice, because it resets numeric indexes (like files or dirs with a numeric name)
        // Here we reduce the list to the range of $limit beginning at $start
        $a = 0;
        $output_array = array();
        foreach ($list as $key => $value) {
            if ($a >= $GLOBALS['start'] && $a - $GLOBALS['start'] < $GLOBALS['limit']) {
                $output_array[$key] = $value;
            }
            $a++;
        }
        $list = $output_array;
    }
    while (list($item, $info) = each($list)) {
        // link to dir / file
        if (is_array($info)) {
            $abs_item = $info;
            if (extension_loaded('posix')) {
                $user_info = posix_getpwnam($info['user']);
                $file_info['uid'] = $user_info['uid'];
                $file_info['gid'] = $user_info['gid'];
            }
        } else {
            $abs_item = get_abs_item(ext_TextEncoding::fromUTF8($dir), $item);
            $file_info = @stat($abs_item);
        }
        $is_dir = get_is_dir($abs_item);
        if ($GLOBALS['use_mb']) {
            if (ext_isFTPMode()) {
                $items['items'][$i]['name'] = $item;
            } else {
                if (mb_detect_encoding($item) == 'ASCII') {
                    $items['items'][$i]['name'] = ext_TextEncoding::toUTF8($item);
                } else {
                    $items['items'][$i]['name'] = ext_TextEncoding::toUTF8($item);
                }
            }
        } else {
            $items['items'][$i]['name'] = ext_isFTPMode() ? $item : ext_TextEncoding::toUTF8($item);
        }
        $items['items'][$i]['is_file'] = get_is_file($abs_item);
        $items['items'][$i]['is_archive'] = ext_isArchive($item) && !ext_isFTPMode();
        $items['items'][$i]['is_writable'] = $is_writable = @$GLOBALS['ext_File']->is_writable($abs_item);
        $items['items'][$i]['is_chmodable'] = $is_chmodable = @$GLOBALS['ext_File']->is_chmodable($abs_item);
        $items['items'][$i]['is_readable'] = $is_readable = @$GLOBALS['ext_File']->is_readable($abs_item);
        $items['items'][$i]['is_deletable'] = $is_deletable = @$GLOBALS['ext_File']->is_deletable($abs_item);
        $items['items'][$i]['is_editable'] = get_is_editable($abs_item);
        $items['items'][$i]['icon'] = _EXT_URL . "/images/" . get_mime_type($abs_item, "img");
        $items['items'][$i]['size'] = parse_file_size(get_file_size($abs_item));
        // type
        $items['items'][$i]['type'] = get_mime_type($abs_item, "type");
        // modified
        $items['items'][$i]['modified'] = parse_file_date(get_file_date($abs_item));
        // permissions
        $perms = get_file_perms($abs_item);
        if ($perms) {
            if (strlen($perms) > 3) {
                $perms = substr($perms, 2);
            }
            $items['items'][$i]['perms'] = $perms . ' (' . parse_file_perms($perms) . ')';
        } else {
            $items['items'][$i]['perms'] = ' (unknown) ';
        }
        $items['items'][$i]['perms'] = $perms . ' (' . parse_file_perms($perms) . ')';
        if (extension_loaded("posix")) {
            if ($file_info["uid"]) {
                $user_info = posix_getpwuid($file_info["uid"]);
                //$group_info = posix_getgrgid($file_info["gid"]);
                $items['items'][$i]['owner'] = $user_info["name"] . " (" . $file_info["uid"] . ")";
            } else {
                $items['items'][$i]['owner'] = " (unknown) ";
            }
        } else {
            $items['items'][$i]['owner'] = 'n/a';
        }
        if ($is_dir && $sendWhat != 'files') {
            $id = str_replace('/', $GLOBALS['separator'], $dir) . $GLOBALS['separator'] . $item;
            $id = str_replace($GLOBALS['separator'], '_RRR_', $id);
            $qtip = "<strong>" . ext_Lang::mime('dir', true) . "</strong><br /><strong>" . ext_Lang::msg('miscperms', true) . ":</strong> " . $perms . "<br />";
            $qtip .= '<strong>' . ext_Lang::msg('miscowner', true) . ':</strong> ' . $items['items'][$i]['owner'];
            if ($GLOBALS['use_mb']) {
                if (ext_isFTPMode()) {
                    $dirlist[] = array('text' => htmlspecialchars($item), 'id' => $id, 'qtip' => $qtip, 'is_writable' => $is_writable, 'is_chmodable' => $is_chmodable, 'is_readable' => $is_readable, 'is_deletable' => $is_deletable, 'cls' => 'folder');
                } else {
                    if (mb_detect_encoding($item) == 'ASCII') {
                        $dirlist[] = array('text' => htmlspecialchars(ext_TextEncoding::toUTF8($item)), 'id' => utf8_encode($id), 'qtip' => $qtip, 'is_writable' => $is_writable, 'is_chmodable' => $is_chmodable, 'is_readable' => $is_readable, 'is_deletable' => $is_deletable, 'cls' => 'folder');
                    } else {
                        $dirlist[] = array('text' => htmlspecialchars($item), 'id' => $id, 'qtip' => $qtip, 'is_writable' => $is_writable, 'is_chmodable' => $is_chmodable, 'is_readable' => $is_readable, 'is_deletable' => $is_deletable, 'cls' => 'folder');
                    }
                }
            } else {
                $dirlist[] = array('text' => htmlspecialchars(ext_isFTPMode() ? $item : ext_TextEncoding::toUTF8($item)), 'id' => ext_isFTPMode() ? $id : ext_TextEncoding::toUTF8($id), 'qtip' => $qtip, 'is_writable' => $is_writable, 'is_chmodable' => $is_chmodable, 'is_readable' => $is_readable, 'is_deletable' => $is_deletable, 'cls' => 'folder');
            }
        }
        if (!$is_dir && $sendWhat == 'files' || $sendWhat == 'both') {
            $i++;
        }
    }
    while (@ob_end_clean()) {
    }
    if ($sendWhat == 'dirs') {
        $result = $dirlist;
    } else {
        $result = $items;
    }
    $classname = class_exists('ext_Json') ? 'ext_Json' : 'Services_JSON';
    $json = new $classname();
    echo $json->encode($result);
    ext_exit();
}