]> git.mjollnir.org Git - s9y.git/commitdiff
Some more customization, future compatability
authorgarvinhicking <garvinhicking>
Wed, 10 May 2006 12:24:45 +0000 (12:24 +0000)
committergarvinhicking <garvinhicking>
Wed, 10 May 2006 12:24:45 +0000 (12:24 +0000)
include/functions_images.inc.php
serendipity_admin_image_selector.php

index a9ee2e8fb7504bac1eec1fb6286e59401e159f14..3bf79fc609f073841b535ee619bfbd1d76d0feff 100644 (file)
@@ -41,6 +41,11 @@ function serendipity_isActiveFile($file) {
 function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order = false, $ordermode = false, $directory = '', $filename = '', $keywords = '', $filter = array()) {
     global $serendipity;
 
+    $cond = array(
+        'joinparts' => array(),
+        'parts'     => array(),
+    );
+
     $orderfields = serendipity_getImageFields();
     if (empty($order) || !isset($orderfields[$order])) {
         $order = 'i.date';
@@ -62,13 +67,12 @@ function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order
         $limitsql = serendipity_db_limit_sql(serendipity_db_limit($start, $limit));
     }
 
-    $where_sql = "WHERE 1 \n";
     if (!empty($directory)) {
-        $where_sql .= " AND i.path LIKE '" . serendipity_db_escape_string($directory) . "%'\n";
+        $cond['parts']['directory'] = " AND i.path LIKE '" . serendipity_db_escape_string($directory) . "%'\n";
     }
 
     if (!empty($filename)) {
-        $where_sql .= " AND (i.name     like '%" . serendipity_db_escape_string($filename) . "%' OR
+        $cond['parts']['filename'] = " AND (i.name     like '%" . serendipity_db_escape_string($filename) . "%' OR
                   i.realname like '%" . serendipity_db_escape_string($filename) . "%')\n";
     }
 
@@ -84,10 +88,9 @@ function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order
         $keywords[$i] = serendipity_db_escape_string($keyword);
     }
 
-    $join_properties = $join_keywords = $join_filterproperties = $join_hiddenproperties = false;
     if (count($keywords) > 0) {
-        $where_sql .= " AND (mk.property IN ('" . implode("', '", $keywords) . "'))\n";
-        $join_keywords = true;
+        $cond['parts']['keywords'] = " AND (mk.property IN ('" . implode("', '", $keywords) . "'))\n";
+        $cond['joinparts']['keywords'] = true;
     }
 
     foreach($filter AS $f => $fval) {
@@ -107,69 +110,69 @@ function serendipity_fetchImagesFromDatabase($start=0, $limit=0, &$total, $order
 
             if (substr($f, 0, 3) === 'bp.') {
                 $realf = substr($f, 3);
-                $where_sql .= " AND (bp2.property = '$realf' AND bp2.value >= " . (int)$fval['from'] . " AND bp2.value <= " . (int)$fval['to'] . ")\n";
+                $cond['parts']['filter'] .= " AND (bp2.property = '$realf' AND bp2.value >= " . (int)$fval['from'] . " AND bp2.value <= " . (int)$fval['to'] . ")\n";
             } else {
-                $where_sql .= " AND ($f >= " . (int)$fval['from'] . " AND $f <= " . (int)$fval['to'] . ")\n";
+                $cond['parts']['filter'] .= " AND ($f >= " . (int)$fval['from'] . " AND $f <= " . (int)$fval['to'] . ")\n";
             }
         } elseif ($f == 'i.authorid') {
-            $where_sql .= " AND (
+            $cond['parts']['filter'] .= " AND (
                                     (hp.property = 'authorid' AND hp.value = " . (int)$fval . ")
                                     OR
                                     (i.authorid = " . (int)$fval . ")
                                 )\n";
-            $join_hiddenproperties = true;
+            $cond['joinparts']['hiddenproperties'] = true;
         } elseif ($orderfields[$f]['type'] == 'int') {
             if (substr($f, 0, 3) === 'bp.') {
                 $realf = substr($f, 3);
-                $where_sql .= " AND (bp2.property = '$realf' AND bp2.value = '" . serendipity_db_escape_string(trim($fval)) . "')\n";
+                $cond['parts']['filter'] .= " AND (bp2.property = '$realf' AND bp2.value = '" . serendipity_db_escape_string(trim($fval)) . "')\n";
             } else {
-                $where_sql .= " AND ($f = '" . serendipity_db_escape_string(trim($fval)) . "')\n";
+                $cond['parts']['filter'] .= " AND ($f = '" . serendipity_db_escape_string(trim($fval)) . "')\n";
             }
         } else {
             if (substr($f, 0, 3) === 'bp.') {
                 $realf = substr($f, 3);
-                $where_sql .= " AND (bp2.property = '$realf' AND bp2.value LIKE '%" . serendipity_db_escape_string(trim($fval)) . "%')\n";
+                $cond['parts']['filter'] .= " AND (bp2.property = '$realf' AND bp2.value LIKE '%" . serendipity_db_escape_string(trim($fval)) . "%')\n";
             } else {
-                $where_sql .= " AND ($f LIKE '%" . serendipity_db_escape_string(trim($fval)) . "%')\n";
+                $cond['parts']['filter'] .= " AND ($f LIKE '%" . serendipity_db_escape_string(trim($fval)) . "%')\n";
             }
         }
-        $join_filterproperties = true;
+        $cond['joinparts']['filterproperties'] = true;
     }
 
     if (isset($serendipity['authorid']) && !serendipity_checkPermission('adminImagesViewOthers')) {
-        $where_sql .= " AND (i.authorid = 0 OR i.authorid = " . (int)$serendipity['authorid'] . ")\n";
+        $cond['parts']['authorid'] .= " AND (i.authorid = 0 OR i.authorid = " . (int)$serendipity['authorid'] . ")\n";
     }
 
-    $cond = array(
-        'and' => $where_sql
-    );
+    $cond['and']  = 'WHERE 1 ' . implode("\n", $cond['parts']);
+    $cond['args'] = func_get_args();
+    serendipity_plugin_api::hook_event('fetch_images_sql', $cond);
     serendipity_ACL_SQL($cond, false, 'directory');
 
-    if ($join_keywords) {
+    if ($cond['joinparts']['keywords']) {
         $cond['joins'] .= "\n LEFT OUTER JOIN {$serendipity['dbPrefix']}mediaproperties AS mk
                                         ON (mk.mediaid = i.id AND mk.property_group = 'base_keyword')\n";
     }
 
     if (substr($order, 0, 3) === 'bp.') {
         $cond['orderproperty'] = substr($order, 3);
-        $cond['orderkey'] = 'bp.value';
-        $order            = 'bp.value';
-        $join_properties  = true;
+        $cond['orderkey']   = 'bp.value';
+        $order              = 'bp.value';
+        $cond['joinparts']['properties'] = true;
     } else {
         $cond['orderkey'] = "''";
     }
 
-    if ($join_properties) {
+    if ($cond['joinparts']['properties']) {
         $cond['joins'] .= "\n LEFT OUTER JOIN {$serendipity['dbPrefix']}mediaproperties AS bp
                                         ON (bp.mediaid = i.id AND bp.property_group = 'base_property' AND bp.property = '{$cond['orderproperty']}')\n";
     }
 
-    if ($join_filterproperties) {
+    if ($cond['joinparts']['filterproperties']) {
         $cond['joins'] .= "\n LEFT OUTER JOIN {$serendipity['dbPrefix']}mediaproperties AS bp2
                                         ON (bp2.mediaid = i.id AND bp2.property_group = 'base_property')\n";
     }
 
-    if ($join_hiddenproperties) {
+    if ($cond['joinparts']['hiddenproperties']) {
         $cond['joins'] .= "\n LEFT OUTER JOIN {$serendipity['dbPrefix']}mediaproperties AS hp
                                         ON (hp.mediaid = i.id AND hp.property_group = 'base_hidden')\n";
     }
@@ -1486,6 +1489,15 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
         $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'))) {
@@ -1494,6 +1506,17 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
             }
 
             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);
+            }
         }
     }
 
@@ -2411,17 +2434,25 @@ function serendipity_parsePropertyForm() {
 function &serendipity_fetchMediaProperties($id) {
     global $serendipity;
 
-    $sql = "SELECT property, property_group, property_subgroup, value
+    $sql = "SELECT mediaid, property, property_group, property_subgroup, value
               FROM {$serendipity['dbPrefix']}mediaproperties
-             WHERE mediaid = " . (int)$id;
+             WHERE mediaid IN (" . (is_array($id) ? implode(',', $id) : (int)$id) . ")";
     $rows  = serendipity_db_query($sql, false, 'assoc');
     $props = array();
     if (is_array($rows)) {
         foreach($rows AS $row) {
             if (empty($row['property_subgroup'])) {
-                $props[$row['property_group']][$row['property']] = $row['value'];
+                if (is_array($id)) {
+                    $props[$row['mediaid']][$row['property_group']][$row['property']] = $row['value'];
+                } else {
+                    $props[$row['property_group']][$row['property']] = $row['value'];
+                }
             } else {
-                $props[$row['property_group']][$row['property_subgroup']][$row['property']] = $row['value'];
+                if (is_array($id)) {
+                    $props[$row['mediaid']][$row['property_group']][$row['property_subgroup']][$row['property']] = $row['value'];
+                } else {
+                    $props[$row['property_group']][$row['property_subgroup']][$row['property']] = $row['value'];
+                }
             }
         }
     }
@@ -2533,7 +2564,8 @@ function serendipity_prepareMedia(&$file, $url = '') {
         $file['thumbHeight'] = $file['dim'][1];
         $file['preview'] .= '<img src="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $sThumbSource . '" border="0" title="' . $file['path'] . $file['name'] . '" alt="'. $file['realname'] . '" />';
         if ($url) {
-            $file['preview'] = '<a href="'. $url .'&amp;serendipity[image]='. $file['id'] .'">'. $file['preview'] .'</a>';
+            $file['preview_url'] = $url .'&amp;serendipity[image]='. $file['id'];
+            $file['preview'] = '<a href="'. $file['preview_url'] .'">'. $file['preview'] .'</a>';
         }
     } elseif ($file['is_image'] && $file['hotlink']) {
         $sizes = serendipity_calculate_aspect_size($file['dimensions_width'], $file['dimensions_height'], $serendipity['thumbSize']);
@@ -2541,7 +2573,8 @@ function serendipity_prepareMedia(&$file, $url = '') {
         $file['thumbHeight'] = $sizes[1];
         $file['preview'] .= '<img src="' . $file['path'] . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" border="0" title="' . $file['path'] . '" alt="'. $file['realname'] . '" />';
         if ($url) {
-            $file['preview'] = '<a href="'. $url .'&amp;serendipity[image]='. $file['id'] .'">'. $file['preview'] .'</a>';
+            $file['preview_url'] = $url .'&amp;serendipity[image]='. $file['id'];
+            $file['preview'] = '<a href="'. $file['preview_url'] .'">'. $file['preview'] .'</a>';
         }
     /* If it's not an image, or the thumbnail does not exist */
     } else {
@@ -2551,7 +2584,8 @@ function serendipity_prepareMedia(&$file, $url = '') {
         }
         $file['preview'] .= '<img src="'. $mimeicon .'" title="' . $file['path'] . $file['name'] . ' (' . $file['mime'] . ')" alt="'. $file['mime'] .'" /><br /><span style="font-weight: bold; font-size: 8pt">- ' . (($file['hotlink']) ? MEDIA_HOTLINKED : $file['mime']) .' -</span>';
         if ($url) {
-            $file['preview'] .= '<br /><a href="' . $url . '&amp;serendipity[image]=' . $file['id'] . '">' . $file['name'] . '.' . $file['extension'] . '</a>';
+            $file['preview_url'] = $url .'&amp;serendipity[image]='. $file['id'];
+            $file['preview'] .= '<br /><a href="' . $file['preview_url'] . '">' . $file['name'] . '.' . $file['extension'] . '</a>';
         }
     }
 
index e9e8d71c30179f19df970090c5ccf09b0e30df88..1d1be8bc5402d9d1528734604e79fb60dc004a33 100644 (file)
@@ -231,6 +231,7 @@ switch ($serendipity['GET']['step']) {
         if (!empty($showfile) && file_exists($showfile)) {
             header('Content-Type: ' . $file['displaymime']);
             header('Content-Length: ' . filesize($showfile));
+            header('Content-Disposition: ' . ($serendipity['GET']['disposition'] == 'attachment' ? 'attachment' : 'inline') . '; filename=' . basename($showfile));
             $fp = fopen($showfile, 'rb');
             fpassthru($fp);
             exit;
@@ -248,6 +249,10 @@ switch ($serendipity['GET']['step']) {
         $showFile = 'admin/media_showitem.tpl';
         break;
 
+    case 'start':
+        $media['case'] = 'start';
+        break;
+
     case 'default':
     default:
         if (!empty($serendipity['GET']['adminAction']) && $serendipity['GET']['adminModule'] == 'images' && $serendipity['GET']['adminAction'] != 'default') {