Пример #1
0
 public function createIndex($folder)
 {
     // Make sure we have an index.html file in the current folder
     if (!CKunenaFile::exists($folder . '/index.html')) {
         CKunenaFile::write($folder . '/index.html', '<html><body></body></html>');
     }
 }
Пример #2
0
function generateAvatarGD($gdversion, $src_img, $srcWidth, $srcHeight, $dstWidth, $dstHeight, $quality, $location)
{
    if ($srcWidth > $dstWidth || $srcHeight > $dstHeight) {
        $ratio = $srcWidth / $srcHeight;
        if ($dstWidth / $dstHeight > $ratio) {
            $dstWidth = $dstHeight * $ratio;
        } else {
            $dstHeight = $dstWidth / $ratio;
        }
    } else {
        $dstWidth = $srcWidth;
        $dstHeight = $srcHeight;
    }
    if ((int) $gdversion == 1) {
        $dst_img = imagecreate($dstWidth, $dstHeight);
        imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight);
    } else {
        $dst_img = imagecreatetruecolor($dstWidth, $dstHeight);
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight);
    }
    $tmpfile = tempnam(CKunenaPath::tmpdir(), "kn_");
    imagejpeg($dst_img, $tmpfile, $quality);
    CKunenaFile::copy($tmpfile, $location);
    unlink($tmpfile);
    imagedestroy($dst_img);
}
Пример #3
0
function saveCss($file, $csscontent, $option)
{
    require_once KUNENA_PATH_LIB . '/kunena.file.class.php';
    $kunena_app =& JFactory::getApplication();
    $tmpstr = JText::_('COM_KUNENA_CSS_SAVE');
    $tmpstr = str_replace("%file%", $file, $tmpstr);
    echo $tmpstr;
    if (CKunenaFile::write($file, $csscontent)) {
        while (@ob_end_clean()) {
        }
        $kunena_app->redirect(JURI::base() . "index.php?option={$option}&task=showCss", JText::_('COM_KUNENA_CFC_SAVED'));
    } else {
        while (@ob_end_clean()) {
        }
        $kunena_app->redirect(JURI::base() . "index.php?option={$option}&task=showCss", JText::_('COM_KUNENA_CFC_NOTSAVED'));
    }
}
Пример #4
0
 function version($file, $newpath, $newfile, $maxwidth = 800, $maxheight = 800, $quality = 70, $scale = CKunenaImage::SCALE_INSIDE)
 {
     require_once KUNENA_PATH_LIB . '/kunena.file.class.php';
     // create upload directory if it does not exist
     $imageinfo = self::getProperties($file);
     if (!$imageinfo) {
         return false;
     }
     if (!CKunenaFolder::exists($newpath)) {
         if (!CKunenaFolder::create($newpath)) {
             return false;
         }
     }
     CKunenaFolder::createIndex($newpath);
     if ($imageinfo->width > $maxwidth || $imageinfo->height > $maxheight) {
         $image = new CKunenaImage($file);
         if ($image->getError()) {
             return false;
         }
         if ($quality < 1 || $quality > 100) {
             $quality = 70;
         }
         $options = array('quality' => $quality);
         $image = $image->resize($maxwidth, $maxheight, true, $scale);
         $type = $image->getType();
         $temp = CKunenaPath::tmpdir() . '/kunena_' . md5(rand());
         $image->toFile($temp, $type, $options);
         unset($image);
         if (!CKunenaFile::move($temp, $newpath . '/' . $newfile)) {
             unlink($temp);
             return false;
         }
     } else {
         if (!CKunenaFile::copy($file, $newpath . '/' . $newfile)) {
             return false;
         }
     }
     return true;
 }
Пример #5
0
function deleteFile($kunena_db, $option, $fileName)
{
    $app =& JFactory::getApplication();
    $kunena_db =& JFactory::getDBO();
    if (!$fileName) {
        $app->redirect(JURI::base() . "index2.php?option={$option}&task=browseFiles");
        return;
    }
    require_once KUNENA_PATH_LIB . DS . 'kunena.file.class.php';
    // step 1: Remove file
    $ret = CKunenaFile::delete(KUNENA_PATH_UPLOADED . DS . 'files' . DS . $fileName);
    //step 2: remove the database link to the file
    if ($ret) {
        $kunena_db->setQuery("DELETE FROM #__fb_attachments where filelocation='%/files/" . $fileName . "'");
        $kunena_db->query() or trigger_dberror("Unable to delete attachment.");
    }
    if ($ret) {
        $app->enqueueMessage(_KUNENA_FILEDELETED);
    }
    $app->redirect(JURI::base() . "index2.php?option={$option}&task=browseFiles");
}
Пример #6
0
	function uploadFile($uploadPath, $input='kattachment', $filename='', $ajax=true) {
		$result = array ();
		$this->resetStatus();

		// create upload directory if it does not exist
		if (!CKunenaFolder::exists($uploadPath)) {
			if (!CKunenaFolder::create($uploadPath)) {
				$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_CREATE_DIR' ));
				return false;
			}
		}
		CKunenaFolder::createIndex($uploadPath);

		$this->fileName = CKunenaFile::makeSafe ( JRequest::getVar ( $input.'_name', '' ) );
		$this->fileSize = 0;
		$chunk = JRequest::getInt ( 'chunk', 0 );
		$chunks = JRequest::getInt ( 'chunks', 0 );

		if ($chunks && $chunk >= $chunks)
			$this->error = JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_EXTRA_CHUNK' );

		//If uploaded by using normal form (no AJAX)
		if ($ajax == false || isset ( $_REQUEST ["multipart"])) {
			$file = JRequest::getVar ( $input, NULL, 'FILES', 'array' );
			if (!is_uploaded_file ( $file ['tmp_name'] )) {
				$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_NOT_UPLOADED' ));
				return false;
			}
			$this->fileTemp = $file ['tmp_name'];
			$this->fileSize = $file ['size'];
			if (! $this->fileName)
				$this->fileName = CKunenaFile::makeSafe ( $file ['name'] );
				//any errors the server registered on uploading
			switch ($file ['error']) {
				case 0 : // UPLOAD_ERR_OK :
					break;

				case 1 : // UPLOAD_ERR_INI_SIZE :
				case 2 : // UPLOAD_ERR_FORM_SIZE :
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_SIZE' ) . "DEBUG: file[error]". $file ['error']);
					break;

				case 3 : // UPLOAD_ERR_PARTIAL :
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_PARTIAL' ));
					break;

				case 4 : // UPLOAD_ERR_NO_FILE :
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_NO_FILE' ));
					break;

				case 5 : // UPLOAD_ERR_NO_TMP_DIR :
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_NO_TMP_DIR' ));
					break;

				case 7 : // UPLOAD_ERR_CANT_WRITE, PHP 5.1.0
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_CANT_WRITE' ));
					break;

				case 8 : // UPLOAD_ERR_EXTENSION, PHP 5.2.0
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_PHP_EXTENSION' ));
					break;

				default :
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_UNKNOWN' ));
			}
		} else {
			// Currently not in use: this is meant for experimental AJAX uploads
			// Open temp file
			$this->fileTemp = CKunenaPath::tmpdir() . '/kunena_' . md5 ( $this->_my->id . '/' . $this->_my->username . '/' . $this->fileName );
			$out = fopen ($this->fileTemp, $chunk == 0 ? "wb" : "ab");
			if ($out) {
				// Read binary input stream and append it to temp file
				$in = fopen ( "php://input", "rb" );

				if ($in) {
					while ( ( $buff = fread ( $in, 8192 ) ) != false )
						fwrite ( $out, $buff );
				} else {
					$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_NO_INPUT' ));
				}

				clearstatcache();
				$fileInfo = fstat($out);
				$this->fileSize = $fileInfo['size'];
				fclose ( $out );
				if (!$this->error) $this->checkFileSize($this->fileSize);
				if ($chunk+1 < $chunks) {
					$this->status = empty($this->error);
					return $this->status;
				}
			} else {
				$this->fail(JText::_ ( 'COM_KUNENA_UPLOAD_ERROR_CANT_WRITE' ));
			}
		}
		// Terminate early if we already hit an error
		if ($this->error) {
			return false;
		}

		// assume the extension is false until we know its ok
		$extOk = false;
		$fileparts = $this->getValidExtension($this->validFileExts);
		if ($fileparts) {
			$this->_isfile = true;
			$extOk = true;
			$uploadedFileBasename = $fileparts[0];
			$uploadedFileExtension = $fileparts[1];
		}
		$fileparts = $this->getValidExtension($this->validImageExts);
		if ($fileparts) {
			$this->_isimage = true;
			$extOk = true;
			$uploadedFileBasename = $fileparts[0];
			$uploadedFileExtension = $fileparts[1];
		}

		if ($extOk == false) {
			$imglist = implode(', ',$this->validImageExts);
			$filelist = implode(', ',$this->validFileExts);
			if ($imglist && $filelist) $this->Fail(JText::sprintf ( 'COM_KUNENA_UPLOAD_ERROR_EXTENSION', $imglist, $filelist ));
			else if ($imglist && !$filelist) $this->Fail(JText::sprintf ( 'COM_KUNENA_UPLOAD_ERROR_EXTENSION_FILE', $this->_config->filetypes ));
			else if (!$imglist && $filelist) $this->Fail(JText::sprintf ( 'COM_KUNENA_UPLOAD_ERROR_EXTENSION_IMAGE', $this->_config->imagetypes ));
			else $this->Fail(JText::sprintf ( 'COM_KUNENA_UPLOAD_ERROR_NOT_ALLOWED', $filelist ));
			return false;
		}

		// Special processing for images
		if ($this->_isimage){
			$this->imageInfo = CKunenaImageHelper::getProperties( $this->fileTemp );

			// Let see if we need to check the MIME type
			if ($this->_config->checkmimetypes){
				// check against whitelist of MIME types
				$validFileTypes = explode ( ",", $this->_config->imagemimetypes );

				//if the temp file does not have a width or a height, or it has a non ok MIME, return
				if (!is_int ( $this->imageInfo->width ) || !is_int ( $this->imageInfo->height ) ||
					!in_array ( $this->imageInfo->mime, $validFileTypes )) {
					$this->fail(JText::sprintf ( 'COM_KUNENA_UPLOAD_ERROR_MIME', $this->imageInfo->mime, $this->_config->imagetypes) );
					return false;
				}
			}

			// If image is not inside allowed size limits, resize it
			if ($this->fileSize > $this->imagesize || $this->imageInfo->width > $this->imagewidth || $this->imageInfo->height > $this->imageheight) {
				$options = array('quality' => $this->imagequality);

				$imageRaw = new CKunenaImage($this->fileTemp);
				if ($imageRaw->getError()) {
					$this->fail(JText::_($imageRaw->getError()));
					return false;
				}
				$image = $imageRaw->resize($this->imagewidth, $this->imageheight);
				$type = $imageRaw->getType();
				unset($imageRaw);
				$image->toFile($this->fileTemp,$type,$options);
				clearstatcache();

				// Re-calculate physical file size: image has been shrunk
				$stat = stat($this->fileTemp);
				if (! $stat) {
					$this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_STAT').' '.$this->fileTemp);
					return false;
				}
				$this->fileSize = $stat['size'];
			}
		}

		$this->checkFileSize($this->fileSize);
		// Check again for error and terminate early if we already hit an error
		if ($this->error) {
			return false;
		}

		// Populate hash, file size and other info
		// Get a hash value from the file
		$this->fileHash = md5_file ( $this->fileTemp );

		// Override filename if given in the parameter
		if ($filename) $uploadedFileBasename = $filename;

		// Rename file if there is already one with the same name
		$newFileName = $uploadedFileBasename . "." . $uploadedFileExtension;
		if (file_exists($uploadPath .'/'. $newFileName)) {
			$newFileName = $uploadedFileBasename . date('_Y-m-d') . "." . $uploadedFileExtension;
			for ($i=2; file_exists("{$uploadPath}/{$newFileName}"); $i++) {
				$newFileName = $uploadedFileBasename . date('_Y-m-d') . "-$i." . $uploadedFileExtension;
			}
		}
		$this->fileName = $newFileName;
		$this->fileName = preg_replace('/[[:space:]]/', '',$this->fileName);

		// All the processing is complete - now we need to move the file(s) into the final location
		@chmod($this->fileTemp, 0644);
		if (! JFile::copy ( $this->fileTemp, $uploadPath.'/'.$this->fileName )) {
			$this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_NOT_MOVED', $uploadPath.'/'.$this->fileName));
			unlink($this->fileTemp);
			return false;
		}
		unlink($this->fileTemp);
		JPath::setPermissions($uploadPath.'/'.$this->fileName);

		$this->ready = true;
		return $this->status = true;
	}
Пример #7
0
    } else {
        if (!($imgtype = KUNENA_check_image_type($imageExt))) {
            imageUploadError(_IMAGE_ERROR_TYPE);
        } else {
            if ($imageSize > $maxImgSize) {
                imageUploadError(_IMAGE_ERROR_SIZE . " (" . $fbConfig->imagesize . "kb)");
            } else {
                list($width, $height) = @getimagesize($attachimage['tmp_name']);
                // Check image width
                if ($width > $fbConfig->imagewidth) {
                    imageUploadError(_IMAGE_ERROR_WIDTH . " (" . $fbConfig->imagewidth . " pixels");
                } else {
                    if ($height > $fbConfig->imageheight) {
                        imageUploadError(_IMAGE_ERROR_HEIGHT . " (" . $fbConfig->imageheight . " pixels");
                    }
                }
            }
        }
    }
}
if ($GLOBALS['KUNENA_rc']) {
    // file is OK, move it to the proper location
    CKunenaFile::upload($attachimage['tmp_name'], $imageLocation);
    // echo '<span class="contentheading">'._IMAGE_UPLOADED."...</span>";
    $code = '[img]' . KUNENA_LIVEUPLOADEDPATH . '/images/' . $newFileName . '[/img]';
    if (preg_match("/\\[img\\/\\]/si", $message)) {
        $message = str_replace("[img/]", $code, $message);
    } else {
        $message = $message . ' ' . $code;
    }
}
Пример #8
0
    }
}
if ($GLOBALS['KUNENA_rc']) {
    //Filename + proper path
    $fileLocation = strtr(KUNENA_PATH_UPLOADED . DS . "files" . DS . $newFileName, "\\", "/");
    $allowedArray = explode(',', strtolower($fbConfig->filetypes));
    $maxImgSize = $fbConfig->filesize * 1024;
    // Check for empty filename
    if (!is_uploaded_file($attachfile['tmp_name']) || empty($attachfile['name'])) {
        fileUploadError(_FILE_ERROR_EMPTY);
    } else {
        if (!in_array($fileExt, $allowedArray)) {
            fileUploadError(_FILE_ERROR_TYPE . " " . $fbConfig->filetypes);
        } else {
            if ($fileSize > $maxImgSize) {
                fileUploadError(_FILE_ERROR_SIZE . " (" . $fbConfig->filesize . "kb)");
            }
        }
    }
}
if ($GLOBALS['KUNENA_rc']) {
    // file is OK, move it to the proper location
    CKunenaFile::upload($attachfile['tmp_name'], $fileLocation);
    // Insert file code into message
    $code = '[file name=' . $newFileName . ' size=' . $fileSize . ']' . KUNENA_LIVEUPLOADEDPATH . '/files/' . $newFileName . '[/file]';
    if (preg_match("/\\[file\\/\\]/si", $message)) {
        $message = str_replace("[file/]", $code, $message);
    } else {
        $message = $message . ' ' . $code;
    }
}