I will start with images::
when saving a submission there is first
the savefile_controller which is being called (com_remository/c-classes)
which in turn is calling the savethumb_controller (c-classes)
which is calling function addImage in remositoryThumbnails (p-classes)
Code: |
public function addImage ($physicalFile, $fileid, $legend='', $remositoryFile=false) {
$interface = remositoryInterface::getInstance();
if ($nextfree = $this->getNextFree()) {
$filepath = $interface->getCfg('absolute_path').$this->filepath;
if (!is_dir($filepath)) mkdir($filepath);
$file_to_fix = $filepath.time().$physicalFile->proper_name;
if ($remositoryFile) $physicalFile->copyToFileSystem($file_to_fix);
else $physicalFile->fileToFile($file_to_fix, 0, false, false);
$file_ext = remositoryAbstract::lastPart($file_to_fix,'.');
if ($file_ext != 'png' AND $file_ext != 'jpg' AND $file_ext != 'jpeg' AND $file_ext != 'gif') {
if (!$remositoryFile) echo _DOWN_THUMB_WRONG_TYPE;
}
elseif (file_exists($file_to_fix)) {
$large_image = $filepath.'img_'.$fileid.'_'.$nextfree.'.'.$file_ext;
$small_image = $filepath.'th_'.$fileid.'_'.$nextfree.'.'.$file_ext;
$repository = remositoryRepository::getInstance();
$this->imgresize($file_to_fix, $large_image, $repository->Large_Image_Width, $repository->Large_Image_Height, true);
$physicalimage = new remositoryPhysicalFile();
$physicalimage->setData($large_image);
$physicalimage->setPerms();
$this->imgresize($file_to_fix, $small_image, $repository->Small_Image_Width, $repository->Small_Image_Height, true);
$physicalimage->setData($small_image);
$physicalimage->setPerms();
unlink ($file_to_fix);
if ($legend) {
$legend_path = $filepath.'txt_'.$fileid.'_'.$nextfree.'.'.$file_ext;
if ($fp = fopen($legend_path, 'wb')) {
fputs($fp, $legend);
fclose($fp);
}
}
}
else echo '<h3>'._ERR1.'</h3>';
}
}
|
there are some other snippets in p-classes/remositoryThumbnails that might be relevant for this matter:
Code: |
public function __construct ($file) {
$interface = remositoryInterface::getInstance();
srand((double)microtime()*1000000);
$this->fileid=$file->id;
$repository = remositoryRepository::getInstance();
$this->maxcount = $repository->Max_Thumbnails;
$this->allow_large = $repository->Allow_Large_Images;
$this->filepath = remositoryThumbnails::baseFilePath().remositoryThumbnails::dirPattern().$file->id.'/';
if ($this->maxcount) $this->findFiles();
elseif ($file->screenurl) {
$this->thumb_URLs[] = $file->screenurl;
$this->img_URLs[] = $file->screenurl;
$filepath = str_replace($interface->getCfg('live_site'), $interface->getCfg('absolute_path'), $file->screenurl);
$this->thumb_paths[] = $filepath;
$this->img_paths[] = $filepath;
$this->count = 1;
}
else $this->count = 0;
}
|
Code: |
public static function baseFilePath () {
return '/components/com_remository_files/';
}
|
Code: |
public static function dirPattern () {
return 'file_image_';
}
|
and
Code: |
private function findFiles () {
$interface = remositoryInterface::getInstance();
$thumb_pattern = 'th_'.$this->fileid.'_';
$dir = new remositoryDirectory($interface->getCfg('absolute_path').$this->filepath);
$thumbfiles = $dir->listFiles($thumb_pattern);
$this->count = 0;
foreach ($thumbfiles as $i=>$thumb) {
$numberandext = remositoryAbstract::lastPart($thumb,'_');
$k = intval(remositoryAbstract::allButLast($numberandext,'.'));
$marker[$k] = 'X';
$thumbpath = $this->filepath.$thumb;
$this->thumb_paths[$i] = $interface->getCfg('absolute_path').$thumbpath;
$this->thumb_URLs[$i] = $interface->getCfg('live_site').$thumbpath;
$imagefile = str_replace('th_','img_',$thumbpath);
$textfile = $interface->getCfg('absolute_path').str_replace('th_', 'txt_', $thumbpath);
if (file_exists($interface->getCfg('absolute_path').$imagefile)) {
$this->img_paths[$i] = $interface->getCfg('absolute_path').$imagefile;
$this->img_URLs[$i] = $interface->getCfg('live_site').$imagefile;
}
else {
$this->img_paths[$i] = $this->thumb_paths[$i];
$this->img_URLs[$i] = $this->thumb_URLs[$i];
}
if (file_exists($textfile)) {
if ($fp = fopen($textfile, 'rb')) {
$this->img_texts[$i] = fgets($fp);
fclose($fp);
}
}
$this->count = $i+1;
}
$freecount = 0;
unset($this->allfree);
for ($i=1; $i<=$this->maxcount AND ($this->count + $freecount) < $this->maxcount; $i++) {
if (!isset($marker[$i])) {
$this->allfree[] = substr($i+100,1);
$freecount++;
}
}
$this->freecount = $freecount;
}
|
I will be posting code for saving file in a separate post