Ejemplo n.º 1
0
 function save()
 {
     if (!igGeneralHelper::authorise('core.admin')) {
         return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
     }
     $app = JFactory::getApplication();
     $data = JRequest::getVar('jform', array(), 'post', 'NONE', 4);
     $id = (int) $data['id'];
     if (empty($id[0])) {
         if (!igGeneralHelper::authorise('core.create')) {
             return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
         }
     } else {
         if (!igGeneralHelper::authorise('core.edit')) {
             return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
         }
     }
     if (strlen($_FILES['jform']['name']['watermark_filename']) > 2) {
         $fileName = $_FILES['jform']['name']['watermark_filename'];
         $tmpPath = $_FILES['jform']['tmp_name']['watermark_filename'];
         $uploadError = $_FILES['jform']['error']['watermark_filename'];
         if (!($uploadedFile = igUploadHelper::upload_file($fileName, $tmpPath, $uploadError, IG_WATERMARK_PATH, true))) {
             return false;
         }
         $data['watermark_filename'] = $uploadedFile;
     }
     $model = $this->getModel();
     $form = $model->getForm($data, false);
     if (!$form) {
         $app->enqueueMessage($model->getError(), 'error');
         return false;
     }
     $validData = $model->validate($form, $data);
     if ($validData === false) {
         $errors = $model->getErrors();
         for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
             if (JError::isError($errors[$i])) {
                 $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
             } else {
                 $app->enqueueMessage($errors[$i], 'warning');
             }
         }
         $this->setRedirect('index.php?option=com_igallery&view=profile&id=' . $id, false);
         return false;
     }
     if (!$model->save($validData)) {
         JError::raise(2, 500, $model->getError());
         $msg = '';
     } else {
         $msg = JText::_('SUCCESSFULLY_SAVED');
     }
     switch ($this->task) {
         case 'apply':
             $url = 'index.php?option=com_igallery&view=profile&id=' . $id;
             break;
         case 'save':
             $url = 'index.php?option=com_igallery&view=profiles';
     }
     $this->setRedirect($url, $msg);
 }
Ejemplo n.º 2
0
 static function processImportedImage($filePath)
 {
     $fullPath = $filePath;
     if (!igUploadHelper::checkExtension($fullPath, false)) {
         return false;
     }
     if (!igUploadHelper::checkIsImage($fullPath, false)) {
         return false;
     }
     $slash = strrpos($fullPath, DIRECTORY_SEPARATOR) + 1;
     $filename = substr($fullPath, $slash);
     $filename = igUploadHelper::replaceSpecial($filename);
     //get the folder path
     $increment = igFileHelper::getFileIncrement('igallery_img');
     $folderName = igFileHelper::getFolderName($increment);
     igFileHelper::makeFolder(IG_ORIG_PATH . '/' . $folderName);
     $destFolderPath = IG_ORIG_PATH . '/' . $folderName;
     //make the filename
     $destFile = igFileHelper::addIncrement($filename, $increment);
     $destFile = igFileHelper::checkUniqueName($destFolderPath, $destFile);
     $destPath = $destFolderPath . '/' . $destFile;
     $imageinfo = getimagesize($fullPath);
     $params = JComponentHelper::getParams('com_igallery');
     $maxServerWidth = $params->get('server_max_width', 2100);
     $maxServerHeight = $params->get('server_max_height', 1600);
     if ($imageinfo[0] > $maxServerWidth || $imageinfo[1] > $maxServerHeight) {
         if (!igFileHelper::makeImage($fullPath, $destPath, $maxServerWidth, $maxServerHeight, 95, false)) {
             return false;
         }
     } else {
         if (!JFile::copy($fullPath, $destPath)) {
             igFileHelper::raiseError($fullPath . ' -> ' . $destPath . ' ' . JText::_('Error Moving File To Directory'), false);
             return false;
         }
     }
     $fileData = array();
     $fileData['filename'] = $destFile;
     if ($params->get('import_exif_data', 0) == 1) {
         $fileData['exif_des'] = igFileHelper::getExifData($fullPath);
     }
     if ($params->get('import_iptc_data', 0) == 1) {
         $fileData['iptc_des'] = igFileHelper::getIptcData($fullPath);
     }
     if ($params->get('import_iptc_tags', 0) == 1) {
         $fileData['iptc_tags'] = igFileHelper::getIptcTags($fullPath);
     }
     return $fileData;
 }
Ejemplo n.º 3
0
 static function upload_file($fileName, $tmpPath, $uploadError, $destDir, $refresh)
 {
     if (!igUploadHelper::checkFileError($uploadError, $fileName, $refresh)) {
         return false;
     }
     if (!igUploadHelper::checkMaxFilesize($tmpPath, $fileName, $refresh)) {
         return false;
     }
     if (!igUploadHelper::checkExtension($fileName, $refresh)) {
         return false;
     }
     if (!igUploadHelper::checkIsImage($tmpPath, $refresh)) {
         return false;
     }
     $fileNameClean = igUploadHelper::replaceSpecial($fileName);
     $fileNameUnique = igUploadHelper::makeUniqueName($destDir, $fileNameClean);
     if (!igUploadHelper::moveFile($tmpPath, $destDir, $fileNameUnique, $refresh)) {
         return false;
     }
     return $fileNameUnique;
 }
Ejemplo n.º 4
0
    function display($tpl = null)
    {
        $pathVar = JRequest::getVar('path');
        $regex = array('#[^ A-Za-z0-9:_\\\\/-]#');
        $pathVar = preg_replace($regex, '', $pathVar);
        $fullPath = JPATH_SITE . $pathVar;
        $filesArray = JFolder::files($fullPath);
        $count = count($filesArray);
        for ($i = 0; $i < $count; $i++) {
            if (!igUploadHelper::checkExtension($filesArray[$i], false, false)) {
                unset($filesArray[$i]);
            } else {
                $filesArray[$i] = $fullPath . '/' . $filesArray[$i];
                $filesArray[$i] = str_replace('\\', '*', $filesArray[$i]);
            }
        }
        $filesArray = array_values($filesArray);
        $headJs = '
		window.addEvent(\'load\', function()
		{
		
		var fileNames = [';
        for ($i = 0; $i < count($filesArray); $i++) {
            $headJs .= '\'' . $filesArray[$i] . '\', ';
        }
        $headJs = substr($headJs, 0, -2);
        $headJs .= ']
		
		';
        $headJs .= '
		
		var importClass = new Class
		({
			Implements: Options,
			options: {},
		
		    initialize: function(options)
		    {
		    	this.setOptions(options);
		    	this.index = 0;
		    	this.doRequest();
		    },
		    
		    doRequest: function()
    		{
				this.serverUrl = \'index.php?option=com_igallery&task=image.serverImport&format=raw&catid=' . JRequest::getInt('catid') . '&path=\' + this.options.fileNames[this.index];
				
				this.serverAjax = new Request({url:this.serverUrl, method: \'get\', 
				onComplete: function(response)
				{
					if(response != 1)
					{
						$(\'error_msg\').innerHTML = \'Error, response from server:<br /> \' + response;
						return;
					}
					
					$(\'fileProgress\').set(\'html\', this.index + 1);
					if(this.index < this.options.fileNames.length - 1)
					{
						this.index ++;
						this.doRequest();
					}
					else
					{
						window.parent.location = \'index.php?option=com_igallery&view=images&catid=' . JRequest::getInt('catid') . '\'
					}
				}.bind(this)
				});
				
				this.serverAjax.send();
			}
		    
		 })
		 
		 var importClass1 = new importClass({fileNames: fileNames});
		
		});';
        $document = JFactory::getDocument();
        $document->addScriptDeclaration($headJs);
        ?>
		<p><?php 
        echo JText::_('IMPORTING_IMAGES');
        ?>
...</p>
		<p><span id="fileProgress">1</span> &#47; <?php 
        echo count($filesArray);
        ?>
</p>
		<div id="error_msg"></div>
		
		<?php 
    }