示例#1
0
 protected function get_user_path()
 {
     if ($this->options['user_dirs']) {
         return $this->get_user_id() . '/';
     }
     if (JRequest::getVar('upload_token')) {
         return FSS_File_Helper::makeUploadSubdir(JRequest::getVar('upload_token')) . '/';
     }
     return '';
 }
示例#2
0
 function display($tpl = null)
 {
     $fileid = FSS_Input::getInt('fileid');
     $key = FSS_Input::getCmd('key');
     $decoded = FSS_Helper::decrypt(FSS_Helper::base64url_decode($key), FSS_Helper::getEncKey("file"));
     if ($fileid != $decoded) {
         exit;
     }
     $db = JFactory::getDBO();
     $sql = "SELECT * FROM #__fss_ticket_attach WHERE id = " . $fileid;
     $db->setQuery($sql);
     $attach = $db->loadObject();
     $image = in_array(strtolower(pathinfo($attach->filename, PATHINFO_EXTENSION)), array('jpg', 'jpeg', 'png', 'gif'));
     $image_file = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . "support" . DS . $attach->diskfile;
     require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'files.php';
     FSS_File_Helper::OutputImage($image_file, pathinfo($attach->filename, PATHINFO_EXTENSION));
 }
示例#3
0
 function VerifyDisk()
 {
     $db = JFactory::getDBO();
     $qry = "SELECT * FROM #__fss_ticket_attach";
     $db->setQuery($qry);
     $this->files = $db->loadObjectList("diskfile");
     $count = 0;
     foreach ($this->files as &$file) {
         if (file_exists(JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'support' . DS . $file->diskfile)) {
             $ticket = new SupportTicket();
             $ticket->load($file->ticket_ticket_id);
             $destpath = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'support' . DS;
             $destname = FSS_File_Helper::makeAttachFilename("support", $file->filename, $file->added, $ticket, $file->user_id);
             if (rename($destpath . $file->diskfile, $destpath . $destname)) {
                 $qry = "UPDATE #__fss_ticket_attach SET diskfile = '" . $db->escape($destname) . "' WHERE id = " . $file->id;
                 $db->setQuery($qry);
                 $db->Query();
                 $count++;
             }
         }
     }
     JFactory::getApplication()->redirect("index.php?option=com_fss&view=attachclean", "{$count} files verified.", "message");
 }
示例#4
0
 function stripImagesFromMessage($message_id)
 {
     $db = JFactory::getDBO();
     $qry = "SELECT * FROM #__fss_ticket_messages WHERE id = " . $db->escape($message_id);
     $db->setQuery($qry);
     $message = $db->loadObject();
     $body = $message->body;
     $count = 0;
     while (strpos($body, "[img]data:") !== false) {
         $start = strpos($body, "[img]data:");
         $end = strpos($body, "[/img]", $start);
         if ($end < 1) {
             break;
         }
         $count++;
         $content = substr($body, $start + 5, $end - $start - 5);
         list($type, $rest) = explode(";", $content, 2);
         list($encoding, $data) = explode(",", $rest, 2);
         $image_data = base64_decode($data);
         list($junk, $extension) = explode("/", $type, 2);
         $filename = "message-{$message_id}-inline-image-{$count}." . $extension;
         $destpath = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'support' . DS;
         $destname = FSS_File_Helper::makeAttachFilename("support", $filename, date("Y-m-d", strtotime($message->posted)), $this, $message->user_id);
         if (file_put_contents($destpath . $destname, $image_data)) {
             $size = filesize($destpath . $destname);
             $qry = "INSERT INTO #__fss_ticket_attach (ticket_ticket_id, filename, diskfile, size, user_id, added, message_id, inline) VALUES ('";
             $qry .= FSSJ3Helper::getEscaped($db, $this->id) . "',";
             $qry .= "'" . FSSJ3Helper::getEscaped($db, $filename) . "',";
             $qry .= "'" . FSSJ3Helper::getEscaped($db, $destname) . "',";
             $qry .= "'" . $size . "',";
             $qry .= "'" . FSSJ3Helper::getEscaped($db, $message->user_id) . "',";
             $qry .= "'" . $message->posted . "', " . $message->id . ", 1)";
             $db->setQuery($qry);
             $db->Query();
             $attach_id = $db->insertid();
         }
         $key = FSS_Helper::base64url_encode(FSS_Helper::encrypt($attach_id, FSS_Helper::getEncKey("file")));
         $replace = "[img]" . JURI::base() . "index.php?option=com_fss&view=image&fileid={$attach_id}&key={$key}" . "[/img]";
         $body = substr($body, 0, $start) . $replace . substr($body, $end + 6);
     }
     if ($count > 0) {
         $qry = "UPDATE #__fss_ticket_messages SET body = \"" . $db->escape($body) . "\" WHERE id = " . $db->escape($message_id);
         $db->setQuery($qry);
         $db->Query();
     }
 }
示例#5
0
 static function makeAttachFilename($subfolder, $filename, $date = null, $ticket = null, $userid = null)
 {
     $base = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . $subfolder . DS;
     $path = '';
     $path_info = pathinfo($filename);
     $file_template = $path_info['filename'] . "-{UID}." . $path_info['extension'];
     if ($date == null) {
         $date = date("Y-m-d");
     }
     $time = strtotime($date);
     if ($userid == null) {
         $userid = $ticket->user_id;
     }
     if ($ticket != null) {
         switch (FSS_Settings::get('attach_storage_filename')) {
             case 1:
                 $path .= $ticket->id . DS;
                 break;
             case 2:
                 $path .= date("Y", $time) . DS . date("Y-m", $time) . DS;
                 break;
             case 3:
                 $path .= date("Y", $time) . DS . date("Y-m", $time) . DS . date("Y-m-d", $time) . DS;
                 break;
             case 4:
                 $user = JFactory::getUser($userid);
                 if ($user->id > 0) {
                     $path .= $user->username . DS;
                 } else {
                     $path .= '_unregistered' . DS;
                 }
         }
     }
     if (!file_exists($base . $path)) {
         mkdir($base . $path, 0755, true);
     }
     $filename = str_replace("{UID}", FSS_File_Helper::shortUID($file_template), $file_template);
     while (JFile::exists($path . $filename)) {
         $filename = str_replace("{UID}", FSS_File_Helper::shortUID($file_template), $file_template);
     }
     return $path . $filename;
 }
示例#6
0
 function AttachFiles($ticketid, $userid, $messageid)
 {
     $db = JFactory::getDBO();
     if (empty($this->attachments)) {
         return false;
     }
     if (!is_array($this->attachments)) {
         return false;
     }
     if (count($this->attachments) == 0) {
         return false;
     }
     $now = FSS_Helper::CurDate();
     $st = new SupportTicket();
     $st->load($ticketid);
     foreach ($this->attachments as $filename => &$data) {
         $new = imap_mime_header_decode($filename);
         $filename = @mb_convert_encoding($new[0]->text, "UTF-8", $new[0]->charset);
         $this->Log("Attachment : {$filename} - " . strlen($data));
         $destpath = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'support' . DS;
         $destname = FSS_File_Helper::makeAttachFilename("support", $filename, date("Y-m-d"), $st, $userid);
         if (JFile::write($destpath . $destname, $data)) {
             $this->Log("Wrote file to {$destname}");
             $qry = "INSERT INTO #__fss_ticket_attach (ticket_ticket_id, filename, diskfile, size, user_id, added, message_id) VALUES ('";
             $qry .= FSSJ3Helper::getEscaped($db, $ticketid) . "',";
             $qry .= "'" . FSSJ3Helper::getEscaped($db, $filename) . "',";
             $qry .= "'" . FSSJ3Helper::getEscaped($db, $destname) . "',";
             $qry .= "'" . strlen($data) . "',";
             $qry .= "'" . FSSJ3Helper::getEscaped($db, $userid) . "',";
             $qry .= "'{$now}', {$messageid} )";
             $db->setQuery($qry);
             $db->Query();
             $file_obj = new stdClass();
             $file_obj->filename = $filename;
             $file_obj->diskfile = $destname;
             $file_obj->size = strlen($data);
             $this->files[] = $file_obj;
         } else {
             // ERROR : File cannot be uploaded! try permissions
         }
     }
     return count($this->files);
 }
示例#7
0
 static function attachDownload($ticketid, $fileid, $for_user = false)
 {
     $ticket = new SupportTicket();
     if ($ticket->load($ticketid, $for_user)) {
         $attach = $ticket->getAttach($fileid);
         if (substr($attach->diskfile, 0, 7) == "http://" || substr($attach->diskfile, 0, 8) == "https://") {
             header('Location: ' . $attach->diskfile);
             exit;
         }
         $file = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . "support" . DS . $attach->diskfile;
         $display_filename = FSS_Helper::basename($attach->filename);
         if (!$for_user) {
             $user = JFactory::GetUser($attach->user_id);
             $type = FSS_Settings::get('support_filename');
             switch ($type) {
                 case 1:
                     $display_filename = $user->username . "_" . $display_filename;
                     break;
                 case 2:
                     $display_filename = $user->username . "_" . date("Y-m-d") . "_" . $display_filename;
                     break;
                 case 3:
                     $display_filename = date("Y-m-d") . "_" . $user->username . "_" . $display_filename;
                     break;
                 case 4:
                     $display_filename = date("Y-m-d") . "_" . $display_filename;
                     break;
             }
         }
         require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'files.php';
         FSS_File_Helper::DownloadFile($file, $display_filename);
     }
     exit;
 }