Ejemplo n.º 1
0
 case 'scale':
     $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
     if (!is_array($file) || !serendipity_checkFormToken() || !serendipity_checkPermission('adminImagesDelete') || !serendipity_checkPermission('adminImagesMaintainOthers') && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid']) {
         return;
     }
     $data['case_scale'] = true;
     $data['print_SCALING_IMAGE'] = sprintf(SCALING_IMAGE, $file['path'] . $file['name'] . '.' . $file['extension'], (int) $serendipity['GET']['width'], (int) $serendipity['GET']['height']);
     $data['extraParems'] = serendipity_generateImageSelectorParems();
     $data['print_serendipity_scaleImg'] = serendipity_scaleImg($serendipity['GET']['fid'], $serendipity['GET']['width'], $serendipity['GET']['height']);
     break;
 case 'scaleSelect':
     $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
     if (!is_array($file) || !serendipity_checkPermission('adminImagesDelete') || !serendipity_checkPermission('adminImagesMaintainOthers') && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid']) {
         return;
     }
     $data['extraParems'] = serendipity_generateImageSelectorParems("form");
     $data['case_scaleSelect'] = true;
     $s = getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . ($file['extension'] ? '.' . $file['extension'] : ""));
     $data['img_width'] = $s[0];
     $data['img_height'] = $s[1];
     $data['print_RESIZE_BLAHBLAH'] = sprintf(RESIZE_BLAHBLAH, serendipity_specialchars($serendipity['GET']['fname']));
     $data['print_ORIGINAL_SIZE'] = sprintf(ORIGINAL_SIZE, $s[0], $s[1]);
     $data['formtoken'] = serendipity_setFormToken();
     $data['file'] = $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . ($file['extension'] ? '.' . $file['extension'] : "");
     break;
 case 'choose':
     $file = serendipity_fetchImageFromDatabase($serendipity['GET']['fid']);
     $media['file'] =& $file;
     if (!is_array($file)) {
         $media['perm_denied'] = true;
         break;
Ejemplo n.º 2
0
/**
 * Display the list of images in our database
 *
 * @access public
 * @param   int     The current page number
 * @param   string  The HTML linebreak to use after a row of images
 * @param   boolean Is this the ML-Version for managing everything (true), or is it about selecting one image for the editor? (false)
 * @param   string  The URL to use for pagination
 * @param   boolean Show the "upload media item" feature?
 * @param   boolean Restrict viewing images to a specific directory
 * @param   array   Map of smarty vars transported into all following templates
 * @return  string   Generated HTML
 */
function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = false, $url = NULL, $show_upload = false, $limit_path = NULL, $smarty_vars = array())
{
    global $serendipity;
    static $debug = false;
    $extraParems = serendipity_generateImageSelectorParems();
    $serendipity['GET']['only_path'] = serendipity_uploadSecure($limit_path . $serendipity['GET']['only_path'], true);
    $serendipity['GET']['only_filename'] = serendipity_specialchars(str_replace(array('*', '?'), array('%', '_'), $serendipity['GET']['only_filename']));
    $perPage = !empty($serendipity['GET']['sortorder']['perpage']) ? (int) $serendipity['GET']['sortorder']['perpage'] : 8;
    while ($perPage % $lineBreak !== 0) {
        $perPage++;
    }
    $start = ($page - 1) * $perPage;
    if ($manage && $limit_path == NULL) {
        ## SYNCH START ##
        $aExclude = array("CVS" => true, ".svn" => true, "_vti_cnf" => true);
        // _vti_cnf to exclude possible added servers frontpage extensions
        serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude);
        $paths = array();
        $aFilesOnDisk = array();
        $aResultSet = serendipity_traversePath($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $limit_path, '', false, NULL, 1, NULL, FALSE, $aExclude);
        foreach ($aResultSet as $sKey => $sFile) {
            if ($sFile['directory']) {
                if ($debug) {
                    echo "<span class='block_level'>{$sFile['relpath']} is a directory.</span>";
                }
                array_push($paths, $sFile);
            } else {
                if ($debug) {
                    echo "<span class='block_level'>{$sFile['relpath']} is a file.</span>";
                }
                // Store the file in our array, remove any ending slashes
                $aFilesOnDisk[$sFile['relpath']] = 1;
            }
            unset($aResultSet[$sKey]);
        }
        usort($paths, 'serendipity_sortPath');
        if ($debug) {
            echo "<p>Got files: <pre>" . print_r($aFilesOnDisk, true) . "</pre></p>";
        }
        $serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk));
        $nTimeStart = microtime_float();
        // MTG 21/01/06: request all images from the database, delete any which don't exist
        // on the filesystem, and mark off files from the file list which are already
        // in the database
        $nCount = 0;
        if ($debug) {
            echo "<p>Image Sync Right: " . serendipity_checkPermission('adminImagesSync') . " Onthefly Sync: " . $serendipity['onTheFlySynch'] . " Hash: " . $serendipity['current_image_hash'] . "!=" . $serendipity['last_image_hash'] . "</p>";
        }
        if ($serendipity['onTheFlySynch'] && serendipity_checkPermission('adminImagesSync') && ($debug || $serendipity['current_image_hash'] != $serendipity['last_image_hash'])) {
            $aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id\n                                                FROM {$serendipity['dbPrefix']}images", false, 'assoc');
            if ($debug) {
                echo "<p>Got images: <pre>" . print_r($aResultSet, true) . "</pre></p>";
            }
            if (is_array($aResultSet)) {
                foreach ($aResultSet as $sKey => $sFile) {
                    serendipity_plugin_api::hook_event('backend_thumbnail_filename_select', $sFile);
                    $sThumbNailFile = '';
                    if (isset($sFile['thumbnail_filename'])) {
                        $sThumbNailFile = $sFile['thumbnail_filename'];
                    } else {
                        $sThumbNailFile = $sFile['path'] . $sFile['name'] . '.' . $sFile['thumbnail_name'] . (empty($sFile['extension']) ? '' : '.' . $sFile['extension']);
                    }
                    $sFileName = $sFile['path'] . $sFile['name'] . (empty($sFile['extension']) ? '' : '.' . $sFile['extension']);
                    if ($debug) {
                        echo "<p>File name is {$sFileName}, thumbnail is {$sThumbNailFile}</p>";
                    }
                    unset($aResultSet[$sKey]);
                    if (isset($aFilesOnDisk[$sFileName])) {
                        unset($aFilesOnDisk[$sFileName]);
                    } else {
                        if ($debug) {
                            echo "<span class='block_level'>Deleting Image {$sFile['id']}</span>";
                        }
                        serendipity_deleteImage($sFile['id']);
                        ++$nCount;
                    }
                    unset($aFilesOnDisk[$sThumbNailFile]);
                }
            }
            if ($nCount > 0) {
                if ($debug) {
                    echo "<p>Cleaned up " . $nCount . " database entries</p>";
                }
            }
            serendipity_set_config_var('last_image_hash', $serendipity['current_image_hash'], 0);
            $aUnmatchedOnDisk = array_keys($aFilesOnDisk);
            if ($debug) {
                echo "<p>Got unmatched files: <pre>" . print_r($aUnmatchedOnDisk, true) . "</pre></p>";
            }
            $nCount = 0;
            foreach ($aUnmatchedOnDisk as $sFile) {
                if (preg_match('@\\.' . $serendipity['thumbSuffix'] . '\\.@', $sFile)) {
                    if ($debug) {
                        echo "<p>Skipping thumbnailed file {$sFile}</p>";
                    }
                    continue;
                } else {
                    if ($debug) {
                        echo "<p>Checking {$sFile}</p>";
                    }
                }
                // MTG: 21/01/06: put files which have just 'turned up' into the database
                $aImageData = serendipity_getImageData($sFile);
                if (serendipity_isImage($aImageData, false, '(image)|(video)|(audio)/')) {
                    $nPos = strrpos($sFile, "/");
                    if (is_bool($nPos) && !$nPos) {
                        $sFileName = $sFile;
                        $sDirectory = "";
                    } else {
                        ++$nPos;
                        $sFileName = substr($sFile, $nPos);
                        $sDirectory = substr($sFile, 0, $nPos);
                    }
                    if ($debug) {
                        echo "<p>Inserting image {$sFileName} from {$sDirectory} <pre>" . print_r($aImageData, true) . "</pre> into database</p>";
                    }
                    # TODO: Check if the thumbnail generation goes fine with Marty's code
                    serendipity_makeThumbnail($sFileName, $sDirectory);
                    serendipity_insertImageInDatabase($sFileName, $sDirectory);
                    ++$nCount;
                }
            }
            if ($nCount > 0) {
                if ($debug) {
                    echo "<p>Inserted " . $nCount . " images into the database</p>";
                }
            }
        } else {
            if ($debug) {
                echo "<p>Media Gallery database is up to date</p>";
            }
        }
        /*
         $nTimeEnd = microtime_float ( );
         $nDifference = $nTimeEnd - $nTimeStart;
         echo "<p> total time taken was " . $nDifference . "</p>";
        */
        ## SYNCH FINISHED ##
    }
    ## Aply ACL afterwards:
    serendipity_directoryACL($paths, 'read');
    $serendipity['imageList'] = serendipity_fetchImagesFromDatabase($start, $perPage, $totalImages, isset($serendipity['GET']['sortorder']['order']) ? $serendipity['GET']['sortorder']['order'] : false, isset($serendipity['GET']['sortorder']['ordermode']) ? $serendipity['GET']['sortorder']['ordermode'] : false, isset($serendipity['GET']['only_path']) ? $serendipity['GET']['only_path'] : '', isset($serendipity['GET']['only_filename']) ? $serendipity['GET']['only_filename'] : '', isset($serendipity['GET']['keywords']) ? $serendipity['GET']['keywords'] : '', isset($serendipity['GET']['filter']) ? $serendipity['GET']['filter'] : '');
    $pages = ceil($totalImages / $perPage);
    $linkPrevious = '?' . $extraParems . 'serendipity[page]=' . ($page - 1);
    $linkNext = '?' . $extraParems . 'serendipity[page]=' . ($page + 1);
    if (is_null($lineBreak)) {
        $lineBreak = floor(750 / ($serendipity['thumbSize'] + 20));
    }
    $dprops = $keywords = array();
    if ($serendipity['parseMediaOverview']) {
        $ids = array();
        foreach ($serendipity['imageList'] as $k => $file) {
            $ids[] = $file['id'];
        }
        $allprops =& serendipity_fetchMediaProperties($ids);
    }
    if (count($serendipity['imageList']) > 0) {
        foreach ($serendipity['imageList'] as $k => $file) {
            if (!($serendipity['authorid'] == $file['authorid'] || $file['authorid'] == '0' || serendipity_checkPermission('adminImagesViewOthers'))) {
                // This is a fail-safe continue. Basically a non-matching file should already be filtered in SQL.
                continue;
            }
            serendipity_prepareMedia($serendipity['imageList'][$k], $url);
            if ($serendipity['parseMediaOverview']) {
                $serendipity['imageList'][$k]['props'] =& $allprops[$file['id']];
                if (!is_array($serendipity['imageList'][$k]['props']['base_metadata'])) {
                    $serendipity['imageList'][$k]['metadata'] =& serendipity_getMetaData($serendipity['imageList'][$k]['realfile'], $serendipity['imageList'][$k]['header']);
                } else {
                    $serendipity['imageList'][$k]['metadata'] = $serendipity['imageList'][$k]['props']['base_metadata'];
                    serendipity_plugin_api::hook_event('media_getproperties_cached', $serendipity['imageList'][$k]['metadata'], $serendipity['imageList'][$k]['realfile']);
                }
                serendipity_parseMediaProperties($dprops, $keywords, $serendipity['imageList'][$k], $serendipity['imageList'][$k]['props'], 3, false);
            }
        }
    }
    $smarty_vars = array_merge($smarty_vars, array('limit_path' => $limit_path, 'perPage' => $perPage, 'show_upload' => $show_upload, 'page' => $page, 'pages' => $pages, 'linkNext' => $linkNext, 'linkPrevious' => $linkPrevious, 'extraParems' => $extraParems, 'totalImages' => $totalImages));
    return serendipity_showMedia($serendipity['imageList'], $paths, $url, $manage, $lineBreak, true, $smarty_vars);
}