Ejemplo n.º 1
0
 public static function storeMedias($item_id, $type, $files, $source_path, $target_path, $table_name)
 {
     $db = JFactory::getDbo();
     $destination = DJCatalog2FileHelper::getDestinationFolder($target_path, $item_id, $type);
     $sub_path = DJCatalog2FileHelper::getDestinationPath($item_id, $type);
     if (!JFolder::exists($destination)) {
         $destExist = JFolder::create($destination, 0755);
     } else {
         $destExist = true;
     }
     if ($destExist && !empty($files)) {
         $ordering = 1;
         foreach ($files as $file) {
             $file = trim($file);
             if ($file && JFile::exists($source_path . DS . $file)) {
                 $obj = new stdClass();
                 $obj->id = null;
                 $obj->fullname = DJCatalog2FileHelper::createFileName($file, $destination);
                 $obj->name = JFile::stripExt($obj->fullname);
                 $obj->ext = JFile::getExt($obj->fullname);
                 $obj->item_id = $item_id;
                 $obj->path = $sub_path;
                 $obj->fullpath = $sub_path . '/' . $obj->fullname;
                 $obj->type = $type;
                 $obj->caption = JFile::stripExt($file);
                 $obj->ordering = $ordering++;
                 if (JFile::copy($source_path . DS . $file, $destination . DS . $obj->fullname)) {
                     $db->insertObject($table_name, $obj, 'id');
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function moveToFolders()
 {
     die('NO NO NO!');
     $db = JFactory::getDbo();
     $errors = array();
     $db->setQuery('select * from #__djc2_images');
     $images = $db->loadObjectList();
     foreach ($images as $image) {
         if (!empty($image->path)) {
             continue;
         }
         $dest = DJCatalog2ImageHelper::getDestinationFolder(DJCATIMGFOLDER, $image->item_id, $image->type);
         if (!JFolder::exists($dest)) {
             JFolder::create($dest);
         }
         if (JFile::copy(DJCATIMGFOLDER . DS . $image->fullname, $dest . DS . $image->fullname)) {
             $path = DJCatalog2ImageHelper::getDestinationPath($image->item_id, $image->type);
             $fullpath = $path . '/' . $image->fullname;
             $db->setQuery('update #__djc2_images set fullpath=' . $db->quote($fullpath) . ', path=' . $db->quote($path) . ' where id=' . $image->id);
             if (!$db->query()) {
                 $errors[] = array('DB', $image->fullname);
                 continue;
             }
             JFile::delete(DJCATIMGFOLDER . DS . $image->fullname);
         } else {
             $errors['images'] = array('COPY', $image->fullname);
         }
     }
     $db->setQuery('select * from #__djc2_files');
     $files = $db->loadObjectList();
     foreach ($files as $file) {
         if (!empty($file->path)) {
             continue;
         }
         $dest = DJCatalog2FileHelper::getDestinationFolder(DJCATATTFOLDER, $file->item_id, $file->type);
         if (!JFolder::exists($dest)) {
             JFolder::create($dest);
         }
         if (JFile::copy(DJCATATTFOLDER . DS . $file->fullname, $dest . DS . $file->fullname)) {
             $path = DJCatalog2ImageHelper::getDestinationPath($file->item_id, $file->type);
             $fullpath = $path . '/' . $file->fullname;
             $db->setQuery('update #__djc2_files set fullpath=' . $db->quote($fullpath) . ', path=' . $db->quote($path) . ' where id=' . $file->id);
             if (!$db->query()) {
                 $errors[] = array('DB', $file->fullname);
                 continue;
             }
             JFile::delete(DJCATATTFOLDER . DS . $file->fullname);
         } else {
             $errors['files'] = array('COPY', $file->fullname);
         }
     }
     echo '<pre>';
     print_r($errors);
     echo '</pre>';
     die;
 }
Ejemplo n.º 3
0
 public static function getDestinationFolder($path, $itemid, $itemtype)
 {
     return parent::getDestinationFolder($path, $itemid, $itemtype);
 }