function json_decode_debug($string, $assoc, $depth)
{
    $string = json_clean($string);
    $result = json_decode($string, $assoc, $depth);
    switch (json_last_error()) {
        case JSON_ERROR_NONE:
            #            echo 'No errors: ';
            break;
        case JSON_ERROR_DEPTH:
            echo 'Maximum stack depth exceeded: ';
            break;
        case JSON_ERROR_STATE_MISMATCH:
            echo 'Underflow or the modes mismatch: ';
            break;
        case JSON_ERROR_CTRL_CHAR:
            echo 'Unexpected control character found: ';
            break;
        case JSON_ERROR_SYNTAX:
            echo 'Syntax error, malformed JSON: ';
            break;
        case JSON_ERROR_UTF8:
            echo 'Malformed UTF-8 characters, possibly incorrectly encoded: ';
            break;
        default:
            echo 'Unknown error: ';
            break;
    }
    # Only print out an error if we have one
    if (json_last_error()) {
        print $string . "\n";
    }
    return $result;
}
コード例 #2
0
ファイル: DirList.class.php プロジェクト: fnocke/dirList
 /**
  * actually renders the file set
  */
 public function render($mode = 'auto', $size = 'auto')
 {
     $c =& $this->config;
     // shorthand
     out('');
     if ($mode === 'auto') {
         // do not count readme for decision (otherwise 2 pics and one readme would be only 66% ...)
         // ignorereadmeCompensate (otherwise 2 pics and one readme would be only 66% ...)
         $total = $this->totalFiles() - (empty($this->readme_content) ? 0 : 1);
         if ($total > 0 && $this->thumbCount / $total > $c->GRID_THRESHOLD) {
             $mode = 'grid';
         } else {
             $mode = 'list';
         }
     }
     if ($size === 'auto') {
         if ($mode === 'gallery') {
             $size = 1280;
         }
         if ($mode === 'grid') {
             $size = 128;
         } else {
             $size = 32;
         }
     }
     enforce(is_int($size));
     if ($mode === 'gallery') {
         foreach ($this->fileList as $file) {
             $o = (object) $file;
             // shorthand
             // only images matter
             if (!isset(self::$thumb_support[$o->ext])) {
                 continue;
             }
             $url = Cache::getThumb($c->origUrl . '/' . $o->filename, 'b', $size, $size, false, true, $c->thumbScale, $imgW, $imgH);
             out("<a href='{$url}' id='" . $file['thumbID'] . "'></a>");
         }
         return;
     }
     //for (potentially larger thumbs)
     enforce(in_array($size, array(32, 64, 128, 256)), 'non-available icon size');
     // OLD enforce( in_array($thumbSize, Cache::$PERMITTED_SIZES),'invalid thumb size' );
     $ulClass = array("dirList");
     $ulClass[] = "dirList-{$mode}";
     $ulClass[] = "dirList-{$size}";
     $ulClass[] = "dirList-{$mode}-{$size}";
     /* use singleCol rather than styling dirList list width 780px
      * since singeCol is already adjust-styled for Mobile... */
     if ($mode === 'list') {
         $ulClass[] = 'singleCol';
     }
     outPush("<ul class='" . implode(' ', $ulClass) . "'>", $c->indent);
     if (count($this->fileList) < 2) {
         //if empty aka only .. in there
         out("<li class='item item-empty'>This directory is empty.</li>");
     }
     // odd-even class
     $even = true;
     // iterate file-list
     foreach ($this->fileList as $file) {
         $o = (object) $file;
         // shorthand
         $liClass = array('item');
         if ($even) {
             $liClass[] = 'item-even';
         }
         $even = !$even;
         // links open in external tab
         $target = $o->type === 'link' ? " target='_blank'" : '';
         // single-column (folders and other no-downloaders)
         $hasDownload = $o->type === 'file';
         $singleCol = !$hasDownload;
         if ($singleCol) {
             $liClass[] = 'item-singleCol';
         }
         // computer right icon and path, default fallback.
         $iconBaseUrl = $c->ICONURL . $size . '/';
         $iconUrl = $iconBaseUrl . $o->icon;
         $iconPath = $this->ROOT . '/' . $c->ICONPATH . $size . '/';
         if (!is_file($iconPath . $o->icon)) {
             error_log("missing ICONPATH: " . $iconPath . $o->icon);
             $iconUrl = $iconBaseUrl . $c->ICON_DEFAULT;
         }
         //get prior .meta(data) file
         $meta = array();
         // assume empty array for now
         $metaFile = $this->ROOT . $c->origUrl . '/' . $o->filename . '.meta';
         if (is_file($metaFile)) {
             $metaString = file_get_contents($metaFile);
             $metaString = str_replace('\\\\r\\\\n', '<br>', $metaString);
             $meta = json_decode($metaString);
         }
         $title = $o->filename;
         if (isset($meta->caption)) {
             $title = json_clean($meta->caption);
         }
         // COULDO:
         // $download-Only stuff gets singleCol and download-Button...
         $iconOrThumb = isset(self::$thumb_support[$o->ext]) ? 'thumb' : 'icon';
         $liClass[] = $iconOrThumb;
         outPush("<li class='" . implode(' ', $liClass) . "'>");
         $thumbID = isset($o->thumbID) ? " data-thumbid='{$o->thumbID}'" : '';
         outPush("<a class='view'{$thumbID}{$target} href='{$o->link}' title='{$o->title}'>");
         if ($iconOrThumb === 'thumb') {
             $imgW = $imgH = 0;
             $url = Cache::getThumb($c->origUrl . '/' . $o->filename, 'b', $size, $size, false, true, $c->thumbScale, $imgW, $imgH);
             $marginTop = floor(($size - $imgH) / 2) . 'px';
             $marginLeft = floor(($size - $imgW) / 2) . 'px';
             out("<img src='{$url}' alt='{$title}' width='{$imgW}' height='{$imgH}' style='margin-top:{$marginTop};margin-left:{$marginLeft}'>");
         } else {
             out("<img src='{$iconUrl}' alt='' width='{$size}' height='{$size}'>");
         }
         if ($o->size !== null && $o->size !== '') {
             out("<span class='filesize'>" . self::humanSize($o->size) . "</span>");
         }
         out("<span class='filename'>{$title}</span>");
         outPop("</a>");
         if ($hasDownload) {
             out("<a class='download neverprint' title='Herunterladen' href='?download={$o->link}'><span>Download</span></a>");
         }
         outPop("</li>");
     }
     // foreach $file
     outPop("</ul>");
     if ($mode !== 'list') {
         out("<hr class='clear'/>");
     }
     out("<div style='text-align:center;font-size: x-small;color:#888'>powered by " . "<a href='http://github.com/fran-kee/dirList' target='_blank'>" . "dirList</a></div>");
 }