protected function _addAllImagesFromFolder(&$existingImages, $category_id, $fullPath, $rel_path, $data = array()) { $count = 0; $fileList = JFolder::files($fullPath); natcasesort($fileList); // Iterate over the files if they exist //file - abc.img, file_no - folder/abc.img if ($fileList !== false) { foreach ($fileList as $filename) { $storedfilename = ltrim(str_replace(DS, '/', JPath::clean($rel_path . DS . $filename)), '/'); $ext = strtolower(JFile::getExt($filename)); // Don't create thumbnails from defined files (don't save them into a database)... $dontCreateThumb = PhocaGalleryFileThumbnail::dontCreateThumb($filename); if ($dontCreateThumb == 1) { $ext = ''; // WE USE $ext FOR NOT CREATE A THUMBNAIL CLAUSE } if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpeg') { if (JFile::exists($fullPath . DS . $filename) && substr($filename, 0, 1) != '.' && strtolower($filename) !== 'index.html' && !$this->_ImageExist($existingImages, $storedfilename, $category_id)) { $row = $this->getTable('phocagallery'); $datam = array(); $datam['published'] = $data['published']; $datam['catid'] = $category_id; $datam['filename'] = $storedfilename; $datam['approved'] = $data['approved']; $datam['language'] = $data['language']; if ($data['title'] != '') { $datam['title'] = $data['title']; } else { $datam['title'] = PhocaGalleryFile::getTitleFromFile($filename); } if ($data['alias'] != '') { $datam['alias'] = $data['alias']; } else { $datam['alias'] = $datam['title']; //PhocaGalleryText::getAliasName($datam['title']); } $datam['imgorigsize'] = PhocaGalleryFile::getFileSize($datam['filename'], 0); $datam['format'] = PhocaGalleryFile::getFileFormat($datam['filename']); // Geo phocagalleryimport('phocagallery.geo.geo'); $coords = PhocaGalleryGeo::getGeoCoords($datam['filename']); $datam['longitude'] = $coords['longitude']; $datam['latitude'] = $coords['latitude']; if ($datam['latitude'] != '' && $datam['longitude'] != '') { $datam['zoom'] = PhocaGallerySettings::getAdvancedSettings('geozoom'); } // Save // Bind the form fields to the Phoca gallery table if (!$row->bind($datam)) { $this->setError($this->_db->getErrorMsg()); return false; } // Create the timestamp for the date $row->date = gmdate('Y-m-d H:i:s'); // if new item, order last in appropriate group if (!$row->id) { $where = 'catid = ' . (int) $row->catid; $row->ordering = $row->getNextOrder($where); } // Make sure the Phoca gallery table is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Store the Phoca gallery table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } if ($this->firstImageFolder == '') { $this->setFirstImageFolder($row->filename); } $image = new JObject(); $image->filename = $storedfilename; $image->catid = $category_id; $existingImages[] =& $image; $count++; } } } } // $this->setImageCount($count); return $count; }
function save($data) { $params =& JComponentHelper::getParams('com_phocagallery'); $clean_thumbnails = $params->get('clean_thumbnails', 0); $fileOriginalNotExist = 0; if ((int) $data['extid'] > 0) { $data['imgorigsize'] = 0; if ($data['title'] == '') { $data['title'] = 'External Image'; } } else { //If this file doesn't exists don't save it if (!PhocaGalleryFile::existsFileOriginal($data['filename'])) { //$this->setError('Original File does not exist'); //return false; $fileOriginalNotExist = 1; $errorMsg = JText::_('COM_PHOCAGALLERY_ORIGINAL_IMAGE_NOT_EXIST'); } $data['imgorigsize'] = PhocaGalleryFile::getFileSize($data['filename'], 0); $data['format'] = PhocaGalleryFile::getFileFormat($data['filename']); //If there is no title and no alias, use filename as title and alias if ($data['title'] == '') { $data['title'] = PhocaGalleryFile::getTitleFromFile($data['filename']); } } if ($data['extlink1link'] != '') { $extlink1 = str_replace('http://', '', $data['extlink1link']); $data['extlink1'] = $extlink1 . '|' . $data['extlink1title'] . '|' . $data['extlink1target'] . '|' . $data['extlink1icon']; } else { $data['extlink1'] = $data['extlink1link'] . '|' . $data['extlink1title'] . '|' . $data['extlink1target'] . '|' . $data['extlink1icon']; } if ($data['extlink2link'] != '') { $extlink2 = str_replace('http://', '', $data['extlink2link']); $data['extlink2'] = $extlink2 . '|' . $data['extlink2title'] . '|' . $data['extlink2target'] . '|' . $data['extlink2icon']; } else { $data['extlink2'] = $data['extlink2link'] . '|' . $data['extlink2title'] . '|' . $data['extlink2target'] . '|' . $data['extlink2icon']; } // Geo if ($data['longitude'] == '' || $data['latitude'] == '') { phocagalleryimport('phocagallery.geo.geo'); $coords = PhocaGalleryGeo::getGeoCoords($data['filename']); if ($data['longitude'] == '') { $data['longitude'] = $coords['longitude']; } if ($data['latitude'] == '') { $data['latitude'] = $coords['latitude']; } if ($data['latitude'] != '' && $data['longitude'] != '' && $data['zoom'] == '') { $data['zoom'] = PhocaGallerySettings::getAdvancedSettings('geozoom'); } } if ($data['alias'] == '') { $data['alias'] = $data['title']; } //clean alias name (no bad characters) //$data['alias'] = PhocaGalleryText::getAliasName($data['alias']); // if new item, order last in appropriate group //if (!$row->id) { // $where = 'catid = ' . (int) $row->catid ; // $row->ordering = $row->getNextOrder( $where ); //} // = = = = = = = = = = // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState($this->getName() . '.id'); $isNew = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } if (intval($table->date) == 0) { $table->date = JFactory::getDate()->toSql(); } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. /*$result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, $table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; }*/ // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Store to ref table if (!isset($data['tags'])) { $data['tags'] = array(); } if ((int) $table->id > 0) { PhocaGalleryTag::storeTags($data['tags'], (int) $table->id); } // Clean the cache. $cache = JFactory::getCache($this->option); $cache->clean(); // Trigger the onContentAfterSave event. //$dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, $table, $isNew)); $pkName = $table->getKeyName(); if (isset($table->{$pkName})) { $this->setState($this->getName() . '.id', $table->{$pkName}); } $this->setState($this->getName() . '.new', $isNew); // = = = = = = $task = JRequest::getVar('task'); if (isset($table->{$pkName})) { $id = $table->{$pkName}; } if ((int) $data['extid'] > 0 || $fileOriginalNotExist == 1) { } else { // - - - - - - - - - - - - - - - - - - //Create thumbnail small, medium, large //file - abc.img, file_no - folder/abc.img //Get folder variables from Helper //Create thumbnails small, medium, large $refresh_url = 'index.php?option=com_phocagallery&task=phocagalleryimg.thumbs'; $task = JRequest::getVar('task'); if (isset($table->{$pkName}) && $task == 'apply') { $id = $table->{$pkName}; $refresh_url = 'index.php?option=com_phocagallery&task=phocagalleryimg.edit&id=' . (int) $id; } if ($task == 'save2new') { // Don't create automatically thumbnails in case, we are going to add new image } else { $file_thumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($data['filename'], $refresh_url, 1, 1, 1); } //Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { phocagalleryimport('phocagallery.file.filefolder'); PhocaGalleryFileFolder::cleanThumbsFolder(); } // - - - - - - - - - - - - - - - - - - - - - } return true; }