function add($filePath, $fileName, $fileType, &$defRow, $store = true)
 {
     global $my, $mainframe, $database, $option, $priTask, $subTask;
     global $WBG_CONFIG, $wbGalleryDB_cat;
     $time = time() . rand(0, 99999);
     $date = date('Y_m');
     $fileName = preg_replace('/[\\s|\\\\|\\"|\\&|\\?|\']+/', '_', $fileName);
     $fileName = preg_replace('/\\_+/', '_', $fileName);
     $fileExt = preg_replace('/^\\w+\\//', '', $fileType);
     $newFileName = $date . '/' . $time . '.' . $fileExt;
     // Initial File Should be the Largest
     $origInfo = getimagesize($filePath);
     // Debug
     echo "Adding File: " . $fileName . ' -> ' . $newFileName . '<br/>';
     for ($iType = 1; $iType <= 5; $iType++) {
         $active = 0;
         // Process from Largest to Smallest
         switch ($iType) {
             case 1:
                 // ORIGINAL
                 $active = $WBG_CONFIG->save_original;
                 $width = 0;
                 $height = 0;
                 $quality = 0;
                 $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_original;
                 break;
             case 2:
                 // LARGE
                 $active = $WBG_CONFIG->save_large;
                 $width = $WBG_CONFIG->width_large;
                 $height = $WBG_CONFIG->height_large;
                 $quality = $WBG_CONFIG->quality_large;
                 $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_large;
                 break;
             case 3:
                 // MEDIUM
                 $active = $WBG_CONFIG->save_medium;
                 $width = $WBG_CONFIG->width_medium;
                 $height = $WBG_CONFIG->height_medium;
                 $quality = $WBG_CONFIG->quality_medium;
                 $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_medium;
                 break;
             case 4:
                 // THUMB
                 $active = $WBG_CONFIG->save_thumb;
                 $width = $WBG_CONFIG->width_thumb;
                 $height = $WBG_CONFIG->height_thumb;
                 $quality = $WBG_CONFIG->quality_thumb;
                 $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_thumb;
                 break;
             case 5:
                 // TACK
                 $active = $WBG_CONFIG->save_tack;
                 $width = $WBG_CONFIG->width_tack;
                 $height = $WBG_CONFIG->height_tack;
                 $quality = $WBG_CONFIG->quality_tack;
                 $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_tack;
                 break;
         }
         // Process the Image for Step
         // Check / Create Destination
         // Copy Image
         // Resize Copied
         if ($active) {
             $fullPath = $path . $newFileName;
             if (!is_writable($path)) {
                 echo "<script> alert('Permission Denied for {$path}'); window.history.go(-1); </script>\n";
                 exit;
             }
             if (!file_exists($path . $date)) {
                 if (!mkdir($path . $date)) {
                     echo "<script> alert('Failed to Create Category Folder'); window.history.go(-1); </script>\n";
                     exit;
                 }
                 mosChmod($path . $date, 0777);
             }
             if (!copy($filePath, $fullPath)) {
                 echo "<script> alert('Failed to Save Image'); window.history.go(-1); </script>\n";
                 exit;
             }
             if ($width && $height) {
                 if (!$this->resize($fullPath, $fileType, $width, $height)) {
                     echo "<script> alert('Error Resizing Image {$fileName}'); window.history.go(-1); </script>\n";
                     exit;
                 } else {
                     $imgInfo = getimagesize($fullPath);
                 }
             }
         }
     }
     // Debug
     echo "Creating Database Record: " . $fileName . '<br/>';
     // Store Record
     $row = new wbGalleryDB_img($database);
     $row->file = $newFileName;
     $row->cat_id = $defRow->cat_id;
     $row->name = strlen($defRow->name) ? $defRow->name : preg_replace('/\\.\\w+$/', '', $fileName);
     $row->description = $defRow->description;
     $row->photographer = $defRow->photographer;
     $row->price = $defRow->price;
     $row->sku = $defRow->sku;
     $row->publised = $defRow->publised;
     $row->created = date('Y-m-d H:i:s');
     $row->modified = $row->created;
     $row->ordering = 0;
     if (is_array($origInfo)) {
         $row->width = $origInfo[0];
         $row->height = $origInfo[1];
         $row->size = $origInfo['bits'];
     } elseif (is_array($imgInfo)) {
         $row->width = $imgInfo[0];
         $row->height = $imgInfo[1];
         $row->size = $imgInfo['bits'];
     }
     if ($store) {
         // Check
         if (!$row->check()) {
             echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
             exit;
         }
         // Store
         if (!$row->store()) {
             echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
             exit;
         }
         // Update Ordering
         $row->updateOrder('cat_id = ' . (int) $row->cat_id);
         echo "Image Stored Successfully <br/><br/>";
         return true;
     } else {
         return $row;
     }
 }
Esempio n. 2
0
 function order($cid)
 {
     global $my, $mainframe, $database, $option, $priTask, $subTask;
     global $WBG_CONFIG, $wbGalleryDB_cat;
     $row = new wbGalleryDB_img($database);
     $conditions = array();
     $first = mosGetParam($_POST, 'first', 0);
     $order = mosGetParam($_POST, 'order', array(0));
     if (preg_match('/\\d+\\,\\d+/', $order)) {
         $order = split(',', $order);
     }
     if ($first > 0) {
         $row->load($first);
         $database->setQuery('
     SELECT i.*
     FROM #__wbgallery_img  AS i
     WHERE i.ordering < ' . $ordering . '
     AND i.cat_id = ' . $row->cat_id);
         $database->loadObject($lowest_row);
         if ($lowest_row->id) {
             $ordering = $lowest_row->ordering + 1;
         } else {
             $ordering = 1;
         }
         $res = true;
         foreach ($order as $id) {
             $database->setQuery("\r\r\n          UPDATE #__wbgallery_img AS i\r\r\n          SET i.ordering='" . $ordering++ . "'\r\r\n          WHERE i.id= {$id}\r\r\n          ");
             if ($database->query() != 1) {
                 $res = false;
             }
         }
         if ($res) {
             echo "Order Updated...";
         } else {
             echo "Order Update Failed !!!";
         }
     } else {
         for ($i = 0, $n = count($cid); $i < $n; $i++) {
             $row->load($cid[$i]);
             if ($row->ordering != $order[$i]) {
                 $row->ordering = $order[$i];
                 if (!$row->store()) {
                     echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                     exit;
                 }
                 $condition = 'cat_id = ' . (int) $row->cat_id;
                 $found = false;
                 for ($j = 0, $k = count($conditions); $j < $k; $j++) {
                     $cond = $conditions[$j];
                     if ($cond[1] == $condition) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $conditions[] = array($row->id, $condition);
                 }
             }
         }
         for ($i = 0, $n = count($conditions); $i < $n; $i++) {
             $condition = $conditions[$i];
             $row->load($condition[0]);
             $row->updateOrder($condition[1]);
         }
         mosRedirect('index2.php?option=' . $option . '&task=image');
     }
     exit;
 }