Example #1
0
 /**
  * Render uploaded image
  *
  * @param   object  &$model   Element model
  * @param   object  &$params  Element params
  * @param   string  $file     Row data for this element
  * @param   object  $thisRow  All row's data
  *
  * @return  void
  */
 public function render(&$model, &$params, $file, $thisRow = null)
 {
     $src = str_replace("\\", "/", COM_FABRIK_LIVESITE . $file);
     $ext = JString::strtolower(JFile::getExt($file));
     if (!JPluginHelper::isEnabled('content', 'jw_allvideos')) {
         $this->output = JText::_('PLG_ELEMENT_FILEUPLOAD_INSTALL_ALL_VIDEOS');
         return;
     }
     $extra = array();
     $extra[] = $src;
     if ($this->inTableView || $params->get('fu_show_image') < 2) {
         $extra[] = $params->get('thumb_max_width');
         $extra[] = $params->get('thumb_max_height');
     } else {
         $extra[] = $params->get('fu_main_max_width');
         $extra[] = $params->get('fu_main_max_height');
     }
     $src = implode('|', $extra);
     switch ($ext) {
         case 'flv':
             $this->output = "{flvremote}{$src}{/flvremote}";
             break;
         case '3gp':
             $this->output = "{3gpremote}{$src}{/3gpremote}";
             break;
         case 'divx':
             $this->output = "{divxremote}{$src}{/divxremote}";
             break;
     }
 }
 function readData($file)
 {
     $fileExtension = strtolower(JFile::getExt($file));
     $validExtensions = array('jpg', 'jpeg', 'jpe');
     $exifArray = array();
     if (in_array($fileExtension, $validExtensions)) {
         /*if(!extension_loaded('exif'))
         		{
         			$phpVersion = phpversion();
         			if (version_compare($phpVersion, '5.0.0') <= -1)
         			{
         				return array();
         			}
         			else
         			{
         				if ($this->detect())
         				{
         					$exifArray 	= $this->readDataDisabledExif($file);
         				}
         				else
         				{
         					return array();
         				}
         			}
         		}*/
         if (extension_loaded('exif')) {
             $exifArray = $this->readDataEnabledExif($file);
         }
         if (!$exifArray) {
             return array();
         } else {
             return $exifArray;
         }
     }
 }
Example #3
0
 /**
  * Upload the users avatar
  * 
  * @param	KCommandContext	A command context object
  * @return 	void
  */
 public function uploadAvatar(KCommandContext $context)
 {
     $avatar = KRequest::get('files.avatar', 'raw');
     if (!$avatar['name']) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     // is it an image
     if (!MediaHelper::isImage($avatar['name'])) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $avatar['name']));
         return;
     }
     // are we allowed to upload this filetype
     if (!MediaHelper::canUpload($avatar, $error)) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $avatar['name'], lcfirst($error)));
         return;
     }
     // @todo put in some max file size checks
     $path = 'images/com_portfolio/avatars/' . $context->data->user_id . '/';
     $ext = JFile::getExt($avatar['name']);
     $name = JFile::makeSafe($this->getService('koowa:filter.slug')->sanitize($context->data->title) . '.' . $ext);
     JFile::upload($avatar['tmp_name'], JPATH_ROOT . '/' . $path . $name);
     $context->data->avatar = $path . $name;
 }
Example #4
0
 /**
  * @param object element model
  * @param object element params
  * @param string row data for this element
  */
 function render(&$model, &$params, $file)
 {
     jimport('joomla.filesystem.file');
     $filename = basename($file);
     $filename = strip_tags($filename);
     $ext = JFile::getExt($filename);
     //$file = str_replace("\\", "/", COM_FABRIK_LIVESITE  . $file);
     if (!strstr($file, 'http://') && !strstr($file, 'https://')) {
         // $$$rob only add in livesite if we dont already have a full url (eg from amazons3)
         // $$$ hugh trim / or \ off the start of $file
         $file = JString::ltrim($file, '/\\');
         $file = COM_FABRIK_LIVESITE . $file;
     }
     $file = str_replace("\\", "/", $file);
     $file = $model->storage->preRenderPath($file);
     $thumb_path = COM_FABRIK_BASE . 'media/com_fabrik/images/' . $ext . '.png';
     // $$$ hugh - using 'make_thumbnail' to mean 'use default $ext.png as an icon
     // instead of just putting the filename.
     if ($params->get('make_thumbnail', false) && JFile::exists($thumb_path)) {
         $thumb_file = COM_FABRIK_LIVESITE . "/media/com_fabrik/images/" . $ext . ".png";
         $this->output = "<a class=\"download-archive fabrik-filetype-{$ext}\" title=\"{$file}\" href=\"{$file}\"><img src=\"{$thumb_file}\" alt=\"{$filename}\"></a>";
     } else {
         $this->output = "<a class=\"download-archive fabrik-filetype-{$ext}\" title=\"{$file}\" href=\"{$file}\">" . $filename . "</a>";
     }
 }
Example #5
0
 function getValue($field, $source_array)
 {
     jimport('joomla.filesystem.file');
     $upload_path = $field->getParam('upload_path', 'media' . DS . APP_EXTENSION . DS . 'files' . DS . $field->db_name);
     $allowed_extensions = explode(',', $field->getParam('file_extensions', 'jpg,gif,jpeg,png'));
     $delete_file = JArrayHelper::getValue($source_array, "{$field->db_name}_delete", 0, "INT");
     if ($delete_file) {
         return "";
     }
     $file = JRequest::getVar($field->db_name . '_replace', null, 'files');
     if (!$file['name']) {
         $file = JRequest::getVar($field->db_name, null, 'files');
     }
     $fname = $file['name'];
     if (!is_uploaded_file($file['tmp_name'])) {
         return null;
     }
     $ext = strtolower(JFile::getExt($fname));
     if (!in_array($ext, $allowed_extensions)) {
         return null;
     }
     $file_name = JFile::makesafe('custom-' . trim($field->db_name) . '-' . time() . ".{$ext}");
     JFile::upload($file['tmp_name'], $upload_path . DS . $file_name);
     return $file_name;
 }
Example #6
0
 protected function getInput()
 {
     $doc = JFactory::getDocument();
     JHtml::_('jquery.framework');
     $plg_path = JURI::root(true) . '/plugins/system/helix3';
     $doc->addScript($plg_path . '/assets/js/spimage.js');
     $doc->addStyleSheet($plg_path . '/assets/css/spimage.css');
     if ($this->value) {
         $class1 = ' hide';
         $class2 = '';
     } else {
         $class1 = '';
         $class2 = ' hide';
     }
     $output = '<div class="sp-image-field clearfix">';
     $output .= '<div class="sp-image-upload-wrapper">';
     if ($this->value) {
         $data_src = $this->value;
         $src = JURI::root(true) . '/' . $data_src;
         $basename = basename($data_src);
         $thumbnail = JPATH_ROOT . '/' . dirname($data_src) . '/' . JFile::stripExt($basename) . '_thumbnail.' . JFile::getExt($basename);
         if (file_exists($thumbnail)) {
             $src = JURI::root(true) . '/' . dirname($data_src) . '/' . JFile::stripExt($basename) . '_thumbnail.' . JFile::getExt($basename);
         }
         $output .= '<img src="' . $src . '" data-src="' . $data_src . '" alt="">';
     }
     $output .= '</div>';
     $output .= '<input type="file" class="sp-image-upload" accept="image/*" style="display:none;">';
     $output .= '<a class="btn btn-info btn-sp-image-upload' . $class1 . '" href="#"><i class="fa fa-plus"></i> Upload Image</a>';
     $output .= '<a class="btn btn-danger btn-sp-image-remove' . $class2 . '" href="#"><i class="fa fa-minus-circle"></i> Remove Image</a>';
     $output .= '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"  class="form-field-spimage">';
     $output .= '</div>';
     return $output;
 }
Example #7
0
 public function getData()
 {
     ob_clean();
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $post = JRequest::get('post');
     $files = JRequest::get('files');
     $files = $files[$post['task'] . $post['import']];
     if (isset($post['task']) && isset($post['import'])) {
         if ($files['name'] == "") {
             return JText::_('PLEASE_SELECT_FILE');
         }
         $ext = strtolower(JFile::getExt($files['name']));
         if ($ext != 'csv') {
             return JText::_('FILE_EXTENSION_WRONG');
         }
     } else {
         if (!isset($post['import'])) {
             return JText::_('PLEASE_SELECT_SECTION');
         }
     }
     // Upload csv file
     $src = $files['tmp_name'];
     $dest = JPATH_ROOT . '/components/com_redshop/assets/importcsv/' . $post['import'] . '/' . $files['name'];
     $file_upload = JFile::upload($src, $dest);
     $session->clear('ImportPost');
     $session->clear('Importfile');
     $session->clear('Importfilename');
     $session->set('ImportPost', $post);
     $session->set('Importfile', $files);
     $session->set('Importfilename', $files['name']);
     $app->Redirect('index.php?option=com_redshop&view=import&layout=importlog');
     return;
 }
Example #8
0
 public function install()
 {
     // Request forgeries check
     JRequest::checkToken() or die('Invalid Token');
     $file = JRequest::getVar('rule', '', 'FILES');
     $app = JFactory::getApplication();
     $files = array();
     // @task: If there's no tmp_name in the $file, we assume that the data sent is corrupted.
     if (!isset($file['tmp_name'])) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
         $app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
         $app->close();
     }
     // There are various MIME type for compressed file. So let's check the file extension instead.
     if ($file['name'] && JFile::getExt($file['name']) == 'xml') {
         $files = array($file['tmp_name']);
     } else {
         $jConfig = DiscussHelper::getJConfig();
         $path = rtrim($jConfig->get('tmp_path'), '/') . '/' . $file['name'];
         // @rule: Copy zip file to temporary location
         if (!JFile::copy($file['tmp_name'], $path)) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
             $app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
             $app->close();
         }
         jimport('joomla.filesystem.archive');
         $tmp = md5(DiscussHelper::getDate()->toMysQL());
         $dest = rtrim($jConfig->get('tmp_path'), '/') . '/' . $tmp;
         if (!JArchive::extract($path, $dest)) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
             $app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
             $app->close();
         }
         $files = JFolder::files($dest, '.', true, true);
         if (empty($files)) {
             // Try to do a level deeper in case the zip is on the outer.
             $folder = JFolder::folders($dest);
             if (!empty($folder)) {
                 $files = JFolder::files($dest . '/' . $folder[0], true);
                 $dest = $dest . '/' . $folder[0];
             }
         }
         if (empty($files)) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
             $app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
             $app->close();
         }
     }
     if (empty($files)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_RULE_INSTALL_FAILED'), DISCUSS_QUEUE_ERROR);
         $app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
         $app->close();
     }
     foreach ($files as $file) {
         $this->installXML($file);
     }
     DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_RULE_INSTALL_SUCCESS'), DISCUSS_QUEUE_SUCCESS);
     $app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
     $app->close();
 }
Example #9
0
 /**
  * Create a thumbnail from an image file.
  *
  * <code>
  * $myFile   = "/tmp/myfile.jpg";
  *
  * $options = array(
  *     "destination" => "image/mypic.jpg",
  *     "width" => 200,
  *     "height" => 200,
  *     "scale" => JImage::SCALE_INSIDE
  * );
  *
  * $file = new PrismFileImage($myFile);
  * $file->createThumbnail($options);
  *
  * </code>
  *
  * @param  array $options Some options used in the process of generating thumbnail.
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  *
  * @return string A location to the new file.
  */
 public function createThumbnail($options)
 {
     $width = ArrayHelper::getValue($options, "width", 100);
     $height = ArrayHelper::getValue($options, "height", 100);
     $scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
     $destination = ArrayHelper::getValue($options, "destination");
     if (!$destination) {
         throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
     }
     // Generate thumbnail.
     $image = new \JImage();
     $image->loadFile($this->file);
     if (!$image->isLoaded()) {
         throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
     }
     // Resize the file as a new object
     $thumb = $image->resize($width, $height, true, $scale);
     $fileName = basename($this->file);
     $ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
     switch ($ext) {
         case "gif":
             $type = IMAGETYPE_GIF;
             break;
         case "png":
             $type = IMAGETYPE_PNG;
             break;
         case IMAGETYPE_JPEG:
         default:
             $type = IMAGETYPE_JPEG;
     }
     $thumb->toFile($destination, $type);
     return $destination;
 }
Example #10
0
 /**
  * Render a file in form/details view, stored data in $this->output
  *
  * @param   object  &$model   Element model
  * @param   object  &$params  Element params
  * @param   string  $file     Row data for this element
  *
  * @return  void
  */
 public function render(&$model, &$params, $file)
 {
     jimport('joomla.filesystem.file');
     /*
      * $$$ hugh - TESTING - if $file is empty, we're going to just build an empty bit of DOM
      * which can then be filled in with the selected image using HTML5 in browser.
      */
     if (empty($file)) {
         if ($params->get('make_thumbnail', false)) {
             $maxWidth = $params->get('thumb_max_width', 125);
             $maxHeight = $params->get('thumb_max_height', 125);
             $this->output .= '<img style="width: ' . $maxWidth . 'px;" src="" alt="" />';
         }
     } else {
         $filename = basename($file);
         $filename = strip_tags($filename);
         $ext = JFile::getExt($filename);
         if (!strstr($file, 'http://') && !strstr($file, 'https://')) {
             // $$$rob only add in livesite if we don't already have a full url (e.g. from amazons3)
             // Trim / or \ off the start of $file
             $file = JString::ltrim($file, '/\\');
             $file = COM_FABRIK_LIVESITE . $file;
         }
         $file = str_replace("\\", "/", $file);
         $file = $model->storage->preRenderPath($file);
         $layout = $model->getLayout('file');
         $displayData = new stdClass();
         $displayData->thumb = COM_FABRIK_LIVESITE . 'media/com_fabrik/images/' . $ext . '.png';
         $displayData->useThumb = $params->get('make_thumbnail', false) && JFile::exists($displayData->thumb);
         $displayData->ext = $ext;
         $displayData->filename = $filename;
         $displayData->file = $file;
         $this->output = $layout->render($displayData);
     }
 }
Example #11
0
 public function uploadFiles($files, $options)
 {
     $result = array();
     $destination = JArrayHelper::getValue($options, "destination");
     $maxSize = JArrayHelper::getValue($options, "max_size");
     $legalExtensions = JArrayHelper::getValue($options, "legal_extensions");
     $legalFileTypes = JArrayHelper::getValue($options, "legal_types");
     // check for error
     foreach ($files as $fileData) {
         // Upload image
         if (!empty($fileData['name'])) {
             $uploadedFile = JArrayHelper::getValue($fileData, 'tmp_name');
             $uploadedName = JArrayHelper::getValue($fileData, 'name');
             $errorCode = JArrayHelper::getValue($fileData, 'error');
             $file = new Prism\File\File();
             // Prepare size validator.
             $KB = 1024 * 1024;
             $fileSize = JArrayHelper::getValue($fileData, "size");
             $uploadMaxSize = $maxSize * $KB;
             // Prepare file size validator
             $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize);
             // Prepare server validator.
             $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE));
             // Prepare image validator.
             $typeValidator = new Prism\File\Validator\Type($uploadedFile, $uploadedName);
             // Get allowed MIME types.
             $mimeTypes = explode(",", $legalFileTypes);
             $mimeTypes = array_map('trim', $mimeTypes);
             $typeValidator->setMimeTypes($mimeTypes);
             // Get allowed file extensions.
             $fileExtensions = explode(",", $legalExtensions);
             $fileExtensions = array_map('trim', $fileExtensions);
             $typeValidator->setLegalExtensions($fileExtensions);
             $file->addValidator($sizeValidator)->addValidator($typeValidator)->addValidator($serverValidator);
             // Validate the file
             if (!$file->isValid()) {
                 throw new RuntimeException($file->getError());
             }
             // Generate file name
             $baseName = JString::strtolower(JFile::makeSafe(basename($fileData['name'])));
             $ext = JFile::getExt($baseName);
             $generatedName = new Prism\String();
             $generatedName->generateRandomString(6);
             $destinationFile = $destination . DIRECTORY_SEPARATOR . $generatedName . "." . $ext;
             // Prepare uploader object.
             $uploader = new Prism\File\Uploader\Local($uploadedFile);
             $uploader->setDestination($destinationFile);
             // Upload temporary file
             $file->setUploader($uploader);
             $file->upload();
             // Get file
             $fileSource = $file->getFile();
             if (!JFile::exists($fileSource)) {
                 throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED"));
             }
             $result[] = array("title" => $baseName, "filename" => basename($fileSource));
         }
     }
     return $result;
 }
Example #12
0
 function _getSubscriberCSV()
 {
     $keys = array();
     $subscribers = array();
     $subscriber = array();
     jimport('joomla.filesystem.file');
     $allowedExts = array('csv');
     $csvFile = $_FILES['csv_subscribers'];
     $csvFileName = $csvFile['tmp_name'];
     $fileName = $csvFile['name'];
     $fileExt = strtolower(JFile::getExt($fileName));
     if (in_array($fileExt, $allowedExts)) {
         $line = 0;
         $fp = fopen($csvFileName, 'r');
         while (($cells = fgetcsv($fp)) !== FALSE) {
             if ($line == 0) {
                 foreach ($cells as $key) {
                     $keys[] = $key;
                 }
                 $line++;
             } else {
                 $i = 0;
                 foreach ($cells as $cell) {
                     $subscriber[$keys[$i]] = $cell;
                     $i++;
                 }
                 $subscribers[] = $subscriber;
             }
         }
         fclose($fp);
         return $subscribers;
     }
 }
Example #13
0
 /**
  * checks uploaded file, and uploads it
  * @return true csv file uploaded ok, false error (JErrir warning raised)
  */
 function checkUpload()
 {
     if (!(bool) ini_get('file_uploads')) {
         JError::raiseWarning(500, JText::_("The installer can't continue before file uploads are enabled. Please use the install from directory method."));
         return false;
     }
     $userfile = JRequest::getVar('userfile', null, 'files');
     if (!$userfile) {
         JError::raiseWarning(500, JText::_('No file selected'));
         return false;
     }
     jimport('joomla.filesystem.file');
     $allowed = array('txt', 'csv', 'tsv');
     if (!in_array(JFile::getExt($userfile['name']), $allowed)) {
         JError::raiseError(500, 'File must be a csv file');
         return false;
     }
     $config =& JFactory::getConfig();
     $tmp_dir = $config->getValue('config.tmp_path');
     if (empty($tmp_dir) || !JFolder::exists($tmp_dir)) {
         JError::raiseError(500, 'Joomla tmp_path not configured or does not exist');
         return false;
     }
     $tmp_name = 'fabrik_csv_' . md5(uniqid());
     $to = JPath::clean($tmp_dir . DS . $tmp_name);
     $resultdir = JFile::upload($userfile['tmp_name'], $to);
     if ($resultdir === false) {
         JError::raiseWarning(500, JText::_('Upload Error'));
         return false;
     }
     return $tmp_name;
 }
Example #14
0
 /**
  * Process sampledata
  *
  * @access public
  * @return true on success
  * @since 0.9
  */
 function loaddata()
 {
     //determine sql file
     foreach ($this->_filelist['files'] as $key => $file) {
         if (JFile::getExt($file) == 'sql') {
             $scriptfile = $file;
             unset($this->_filelist['files'][$key]);
         }
     }
     //load sql file
     if (!($buffer = file_get_contents($this->_filelist['folder'] . DS . $scriptfile))) {
         return false;
     }
     //extract queries out of sql file
     $queries = $this->_splitSql($buffer);
     //Process queries
     foreach ($queries as $query) {
         $query = trim($query);
         if ($query != '' && $query[0] != '#') {
             $this->_db->setQuery($query);
             $this->_db->query();
         }
     }
     //move images in proper directory
     $this->_moveimages();
     //delete temporary extraction folder
     if (!$this->_deletetmp()) {
         JError::raiseWarning('SOME ERROR CODE', JText::_('UNABLE TO DELETE TMP FOLDER'));
     }
     return true;
 }
Example #15
0
function uploadImage($file, $path, $override = 0)
{
    //Import filesystem libraries. Perhaps not necessary, but does not hurt
    jimport('joomla.filesystem.file');
    //Clean up filename to get rid of strange characters like spaces etc
    $filenameTmp = JFile::makeSafe($file['name']);
    $ext = strtolower(JFile::getExt($filenameTmp));
    $filename = str_replace(' ', '-', JFile::stripExt($filenameTmp)) . '.' . $ext;
    $src = $file['tmp_name'];
    $dest = $path . $filename;
    //First check if the file has the right extension, we need jpg only
    if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg' or $ext == 'zip' or $ext = 'rar' or $ext = 'pdf') {
        //check exits
        if (!$override) {
            if (JFile::exists($dest)) {
                $dest = checkExists($filenameTmp, $ext);
            }
        }
        if (JFile::upload($src, $dest)) {
            return $filename;
        } else {
            echo "Error upload image";
            exit;
        }
    } else {
        echo "Chi cho phep cac loai anh: jpg, gif, png";
        exit;
    }
    return false;
}
Example #16
0
 public function onContentDisplayMediaType($context, &$article, $params, $page = 0, $layout = null)
 {
     if ($article) {
         if ($media = $article->media) {
             $image = null;
             if (isset($media->image)) {
                 $image = clone $media->image;
                 if (isset($image->url) && $image->url) {
                     if ($size = $params->get('mt_image_size', 'o')) {
                         if (isset($image->url) && !empty($image->url)) {
                             $image_url_ext = JFile::getExt($image->url);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url);
                             $image->url = JURI::root() . $image_url;
                         }
                         if (isset($image->url_hover) && !empty($image->url_hover)) {
                             $image_url_ext = JFile::getExt($image->url_hover);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url_hover);
                             $image->url_hover = JURI::root() . $image_url;
                         }
                     }
                 }
             }
             $this->setVariable('image', $image);
         }
         $this->setVariable('item', $article);
         return parent::onContentDisplayMediaType($context, $article, $params, $page, $layout);
     }
 }
Example #17
0
 public static function thumb($image, $width, $height, $ratio = false, $uniqid)
 {
     // remove any / that begins the path
     if (substr($image, 0, 1) == '/') {
         $image = substr($image, 1);
     }
     // create a thumb filename
     $file_dir = dirname($image);
     $thumb_dir = $file_dir . DS . "tzslider_thumbs";
     if (!JFolder::exists($thumb_dir)) {
         JFolder::create($thumb_dir);
     }
     $file_name = JFile::stripExt(basename($image));
     $file_ext = JFile::getExt($image);
     $thumb_path = $thumb_dir . DS . $file_name . '_' . $uniqid . "_thumb." . $file_ext;
     // check to see if this file exists, if so we don't need to create it
     if (function_exists("gd_info")) {
         //Check existing thumbnails dimensions
         if (file_exists($thumb_path)) {
             $size = GetImageSize($thumb_path);
             $currentWidth = $size[0];
             $currentHeight = $size[1];
         }
         //Creating thumbnails
         if (!file_exists($thumb_path) || $currentWidth != $width || $currentHeight != $height) {
             modTzContentSliderCommonHelper::crop($image, $width, $height, $ratio, $thumb_path);
         }
     }
     return str_replace("\\", "/", $thumb_path);
 }
 private function readFileList($path)
 {
     $filter = '^[wW][^\\.].*\\.([Pp][Nn][Gg]|[Jj][Pp][Ee]?[Gg])';
     $recurse = true;
     $excludefiles = array();
     $excludeexts = array();
     jimport('joomla.filesystem.folder');
     $filelist = JFolder::files($path, $filter, $recurse, true, $excludefiles);
     $files = array();
     $files[] =& $this->getFile(null);
     $count = 0;
     while (list($i, $file) = each($filelist)) {
         $count++;
         if ($count > 500) {
             break;
         }
         if (in_array(JFile::getName($file), $excludefiles)) {
             continue;
         }
         if (in_array(JFile::getExt($file), $excludeexts)) {
             continue;
         }
         $file =& $this->getFile($file);
         $files[] = $file;
     }
     $this->fileSort($files);
     return $files;
 }
 function upload($file, $path, $override = 0)
 {
     //Import filesystem libraries. Perhaps not necessary, but does not hurt
     jimport('joomla.filesystem.file');
     //Clean up filename to get rid of strange characters like spaces etc
     $filename = JFile::makeSafe($file['name']);
     $filename = str_replace(' ', '-', $filename);
     //Set up the source and destination of the file
     $src = $file['tmp_name'];
     $dest = $path . $filename;
     //First check if the file has the right extension, we need jpg only
     $ext = strtolower(JFile::getExt($filename));
     if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg') {
         //check exits
         if (!$override) {
             if (JFile::exists($dest)) {
                 echo "<script> alert('Image {$filename} exists on server');\r\n\t\t\t\t\t\twindow.history.go(-1); </script>\n";
                 exit;
             }
         }
         if (JFile::upload($src, $dest)) {
             return $filename;
         } else {
             echo "<script> alert('Error upload image');\r\n\t\t\twindow.history.go(-1); </script>\n";
             exit;
         }
     } else {
         echo "<script> alert('Chi cho phep cac loai anh: jpg, gif, png');\r\n\t\t\twindow.history.go(-1); </script>\n";
         exit;
     }
     return false;
 }
 function isFileOK($file, $checkPatterns = false)
 {
     $fOK = true;
     $file = JFile::stripExt($file) . '.' . strtolower(JFile::getExt($file));
     if ($checkPatterns) {
         $fOK = false;
         foreach ($this->permittedFilePatterns as $p) {
             if (fnmatch($p, $file)) {
                 $fOK = true;
                 break;
             }
         }
     }
     if ($fOK) {
         foreach ($this->excludedDirs as $dir => $flag) {
             if (!$flag) {
                 continue;
             }
             if ($this->_inDir($file, $dir)) {
                 $fOK = false;
                 break;
             }
         }
     }
     if ($fOK) {
         // if the file was excluded
         if (isset($this->excludedFiles[$file]) && $this->excludedFiles[$file]) {
             $fOK = false;
         }
     }
     return $fOK;
 }
Example #21
0
 function _fileData()
 {
     $file = JRequest::getVar('file', '', 'files', 'array');
     // Checks
     if (strlen($file['name']) < 5) {
         $this->setError(JText::_('INVALID_CSV'));
         return false;
     }
     jimport('joomla.filesystem.file');
     $format = strtolower(JFile::getExt($file['name']));
     if ($format != 'csv') {
         $this->setError(JText::_('INVALID_CSV'));
         return false;
     }
     // See administrator >> components >> com_media >> helpers >> media.php
     $xss = JFile::read($file['tmp_name'], false, 256);
     $tags = array('abbr', 'acronym', 'address', 'applet', 'area', 'audioscope', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blackface', 'blink', 'blockquote', 'body', 'bq', 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'comment', 'custom', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'fn', 'font', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'iframe', 'ilayer', 'img', 'input', 'ins', 'isindex', 'keygen', 'kbd', 'label', 'layer', 'legend', 'li', 'limittext', 'link', 'listing', 'map', 'marquee', 'menu', 'meta', 'multicol', 'nobr', 'noembed', 'noframes', 'noscript', 'nosmartquotes', 'object', 'ol', 'optgroup', 'option', 'param', 'plaintext', 'pre', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'server', 'shadow', 'sidebar', 'small', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var', 'wbr', 'xml', 'xmp', '!DOCTYPE', '!--');
     foreach ($tags as $t) {
         if (stristr($xss, '<' . $t . ' ') || stristr($xss, '<' . $t . '>')) {
             $this->setError(JText::_('INVALID_CSV'));
             return false;
         }
     }
     return JFile::read($file['tmp_name'], false);
 }
Example #22
0
 /**
  * Upload an icon for a work
  * 
  * @param   KCommandContext A command context object
  * @return  void
  */
 public function uploadIcon(KCommandContext $context)
 {
     $icon = KRequest::get('files.icon', 'raw');
     if (!$icon['name']) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     // is it an image
     if (!MediaHelper::isImage($icon['name'])) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $icon['name']));
         return;
     }
     // are we allowed to upload this filetype
     if (!MediaHelper::canUpload($icon, $error)) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $icon['name'], lcfirst($error)));
         return;
     }
     $slug = $this->getService('koowa:filter.slug');
     $path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/icon/';
     $ext = JFile::getExt($icon['name']);
     $name = JFile::makeSafe($slug->sanitize($context->data->title) . '.' . $ext);
     JFile::upload($icon['tmp_name'], JPATH_ROOT . '/' . $path . $name);
     $context->data->icon = $path . $name;
 }
 function getPackageFromUpload()
 {
     $install_file = JRequest::getVar('package', null, 'files', 'array');
     if (!(bool) ini_get('file_uploads')) {
         $msg = 'File upload function is disabled, please enable it in file "php.ini"';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if (!extension_loaded('zlib')) {
         $msg = 'Zlib library is disabled, please enable it in file "php.ini"';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if ($install_file['name'] == '') {
         $msg = 'The package is not selected, please download and select it';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if (JFile::getExt($install_file['name']) != 'zip') {
         $msg = 'The package has incorrect format, please use exactly the file you downloaded';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     $tmp_dest = JPATH_ROOT . DS . 'tmp' . DS . $install_file['name'];
     $tmp_src = $install_file['tmp_name'];
     if (!JFile::upload($tmp_src, $tmp_dest)) {
         $msg = 'Folder "tmp" is Unwritable, please set it to Writable (chmod 777). You can set the folder back to Unwritable after sample data installation';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     $package = JInstallerHelper::unpack($tmp_dest);
     return $package;
 }
Example #24
0
 /**
  * checks uploaded file, and uploads it
  * @return true csv file uploaded ok, false error (JErrir warning raised)
  */
 function checkUpload()
 {
     if (!(bool) ini_get('file_uploads')) {
         JError::raiseWarning(500, JText::_("The installer can't continue before file uploads are enabled. Please use the install from directory method."));
         return false;
     }
     $userfile = JRequest::getVar('jform', null, 'files');
     if (!$userfile) {
         JError::raiseWarning(500, JText::_('COM_FABRIK_IMPORT_CSV_NO_FILE_SELECTED'));
         return false;
     }
     jimport('joomla.filesystem.file');
     $allowed = array('txt', 'csv', 'tsv');
     if (!in_array(JFile::getExt($userfile['name']['userfile']), $allowed)) {
         JError::raiseError(500, 'File must be a csv file');
         return false;
     }
     $tmp_name = $this->getCSVFileName();
     $tmp_dir = $this->getBaseDir();
     $to = JPath::clean($tmp_dir . DS . $tmp_name);
     $resultdir = JFile::upload($userfile['tmp_name']['userfile'], $to);
     if ($resultdir == false && !JFile::exists($to)) {
         JError::raiseWarning(500, JText::_('Upload Error'));
         return false;
     }
     return true;
 }
Example #25
0
 public function display($tpl = null)
 {
     $state = $this->get('State');
     $params = $state->get('params');
     $this->params = $params;
     $item = $this->item;
     if (!$item) {
         $item = $this->get('Item');
     }
     if ($item) {
         if ($media = $item->media) {
             if (isset($media->image)) {
                 $image = clone $media->image;
                 if ($params->get('mt_image_show_feed_image', 1)) {
                     $title = $this->escape($item->title);
                     $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
                     $link = JRoute::_(TZ_Portfolio_PlusHelperRoute::getArticleRoute($item->slug, $item->catid, true, -1));
                     if ($size = $params->get('mt_image_feed_size', 'o')) {
                         if (isset($image->url) && !empty($image->url)) {
                             $image_url_ext = JFile::getExt($image->url);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url);
                             $image->url = JURI::root() . $image_url;
                             echo '<a href="' . $link . '"><img src="' . $image->url . '" alt="' . $title . '"/></a>';
                         } elseif (isset($image->url_hover) && !empty($image->url_hover)) {
                             $image_url_ext = JFile::getExt($image->url_hover);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url_hover);
                             $image->url_hover = JURI::root() . $image_url;
                             echo '<a href="' . $link . '"><img src="' . $image->url . '" alt="' . $title . '"/></a>';
                         }
                     }
                 }
             }
         }
     }
 }
Example #26
0
 function access($attr, $path, $data, $volume)
 {
     $mainframe = JFactory::getApplication();
     // Hide PHP files.
     $ext = strtolower(JFile::getExt(basename($path)));
     if ($ext == 'php') {
         return true;
     }
     // Hide files and folders starting with .
     if (strpos(basename($path), '.') === 0 && $attr == 'hidden') {
         return true;
     }
     // Read only access for front-end. Full access for administration section.
     switch ($attr) {
         case 'read':
             return true;
             break;
         case 'write':
             return $mainframe->isSite() ? false : true;
             break;
         case 'locked':
             return $mainframe->isSite() ? true : false;
             break;
         case 'hidden':
             return false;
             break;
     }
 }
 public function saveCategoryData($post)
 {
     //print_r($post);  die;
     $db = JFactory::getDbo();
     $creationDate = date('Y-m-d H:i:s');
     $query = $db->getQuery(true);
     $allawExtation = array('jpg', 'jpeg', 'png', 'gif');
     # These extantion allowed for upload logo file
     $file = JRequest::getVar('categoryLogo', null, 'files', 'array');
     $filename = JFile::makeSafe($file['name']);
     $filextantion = strtolower(JFile::getExt($filename));
     $fileScr = $file['tmp_name'];
     $error = $this->validate($post, $filename, $filextantion, $allawExtation, $fileScr);
     if (count($error) == 0) {
         // Logo update start there
         if ($filename != '') {
             $tempFname = time() . '.' . $filextantion;
             $logoName = str_replace(' ', '', $post['categoryName']) . '_' . $tempFname;
             # File name to store into database
             $src = $fileScr;
             $dest = JPATH_BASE . "/images/productLogo/" . $logoName;
             if (JFile::upload($src, $dest)) {
                 $conditional = $logoName;
             }
         }
         $columns = array('categoryName', 'categoryImage', 'creationDate');
         $values = array($db->quote($post['categoryName']), $db->quote($conditional), $db->quote($creationDate));
         $query->insert($db->quoteName('onm_product_category'))->columns($db->quoteName($columns))->values(implode(',', $values));
         $db->setQuery($query);
         $result = $db->execute();
         echo "<SCRIPT LANGUAGE='JavaScript'>\n    window.alert('Category Added')\n    window.location.href='index.php?option=com_membercheckin&view=addcategory';\n    </SCRIPT>";
     } else {
         return $error;
     }
 }
Example #28
0
 public static function getThumbnailLink($src, $width, $height, $params)
 {
     $src = JPATH_ROOT . '/' . $src;
     if (JFile::exists($src)) {
         require_once __DIR__ . '/libraries/imager.php';
         require_once __DIR__ . '/libraries/imager/abstract.php';
         require_once __DIR__ . '/libraries/imager/gd.php';
         require_once __DIR__ . '/libraries/imager/sizer.php';
         $ext = JFile::getExt($src);
         $cacheFile = JPATH_ROOT . '/cache/' . $width . '_' . $height . '_' . md5($src) . '.' . $ext;
         if (!JFile::exists($cacheFile)) {
             $imager = new ZtNewsImager('gd');
             $imager->loadFile($src);
             $method = $params->get('thumbnail_method', 'resize');
             if ($method == 'crop') {
                 $imager->crop($width, $height, array('position' => $params->get('thumbnail_crop_position', 'center')));
             } else {
                 $imager->{$method}($width, $height);
             }
             if ($imager->saveToFile($cacheFile)) {
                 return str_replace(JPATH_ROOT, rtrim(JUri::root(), '/'), $cacheFile);
             }
         } else {
             return str_replace(JPATH_ROOT, rtrim(JUri::root(), '/'), $cacheFile);
         }
     }
     return $src;
 }
Example #29
0
 public function display($tpl = null)
 {
     $state = $this->get('State');
     $params = $state->get('params');
     $this->state = $state;
     $this->params = $params;
     $item = $this->get('Item');
     $this->image = null;
     if ($item) {
         if ($media = $item->media) {
             if (isset($media->image)) {
                 $image = clone $media->image;
                 if (isset($image->url) && $image->url) {
                     if ($size = $params->get('mt_image_related_size', 'o')) {
                         if (isset($image->url) && !empty($image->url)) {
                             $image_url_ext = JFile::getExt($image->url);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url);
                             $image->related_url = JURI::root() . $image_url;
                         }
                     }
                     if ($params->get('mt_image_use_cloud', 1)) {
                         $doc = JFactory::getDocument();
                         if (!$this->head) {
                             $doc->addStyleSheet(TZ_Portfolio_PlusUri::base(true) . '/addons/mediatype/image/css/cloud-zoom.min.css');
                             $doc->addScript(TZ_Portfolio_PlusUri::base(true) . '/addons/mediatype/image/js/cloud-zoom.1.0.3.min.js');
                             $this->head = true;
                         }
                         if ($params->get('mt_image_cloud_size', 'o')) {
                             $image_url_ext = JFile::getExt($image->url);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $params->get('mt_image_cloud_size', 'o') . '.' . $image_url_ext, $image->url);
                             $image->url_cloud_zoom = JURI::root() . $image_url;
                         }
                     }
                     if ($size = $params->get('mt_image_size', 'o')) {
                         if (isset($image->url) && !empty($image->url)) {
                             $image_url_ext = JFile::getExt($image->url);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url);
                             $image->url = JURI::root() . $image_url;
                             if ($this->getLayout() != 'related') {
                                 JFactory::getDocument()->addCustomTag('<meta property="og:image" content="' . $image->url . '"/>');
                                 if ($author = $item->author_info) {
                                     JFactory::getDocument()->setMetaData('twitter:image', $image->url);
                                 }
                             }
                         }
                         if (isset($image->url_hover) && !empty($image->url_hover)) {
                             $image_url_ext = JFile::getExt($image->url_hover);
                             $image_url = str_replace('.' . $image_url_ext, '_' . $size . '.' . $image_url_ext, $image->url_hover);
                             $image->url_hover = JURI::root() . $image_url;
                         }
                     }
                     $this->image = $image;
                 }
             }
         }
         $this->item = $item;
     }
     parent::display($tpl);
 }
Example #30
-1
 function import_rules()
 {
     $app = JFactory::getApplication();
     $file = $app->input->files->get('rule-file', array(), 'array');
     if ($file['error'] > 0) {
         $this->setError('File/File Size Error. File Error=' . $file['error'] . '| File Size=' . $file['size']);
         return false;
     }
     //check the file extension is ok
     if (JFile::getExt($file['name']) != 'xml') {
         $this->setError('Invalid file extension.');
         return false;
     }
     $plugin = simplexml_load_file($file['tmp_name']);
     if (empty($plugin) || empty($plugin['name']) || $plugin['type'] != 'cjblog_badges') {
         return false;
     }
     $filename = $plugin['name'] . '.xml';
     if (file_exists($filename)) {
         return false;
     }
     if (JFile::upload($file['tmp_name'], CJBLOG_PLUGINS_BASE_DIR . 'badges/' . $filename)) {
         return true;
     }
     return false;
 }