Ejemplo n.º 1
0
            ?>
				<li><a href="javascript:void(0);" id="attach_link_button" onclick="$('attach_link').toggle();"><?php 
            echo image_tag('action_add_link.png') . __('Attach a link');
            ?>
</a></li>
			<?php 
        }
        ?>
		<?php 
    }
    ?>
		<?php 
    if ($issue->isUpdateable() && TBGSettings::isUploadsEnabled() && $issue->canAttachFiles()) {
        ?>
			<?php 
        if (TBGSettings::isUploadsEnabled() && $issue->canAttachFiles()) {
            ?>
				<li><a href="javascript:void(0);" id="attach_file_button" onclick="TBG.Main.showUploader('<?php 
            echo make_url('get_partial_for_backdrop', array('key' => 'uploader', 'mode' => 'issue', 'issue_id' => $issue->getID()));
            ?>
');"><?php 
            echo image_tag('action_add_file.png') . __('Attach a file');
            ?>
</a></li>
			<?php 
        } else {
            ?>
				<li class="disabled"><a href="javascript:void(0);" id="attach_file_button" onclick="TBG.Main.Helpers.Message.error('<?php 
            echo __('File uploads are not enabled');
            ?>
', '<?php 
								<td class="config_explanation" colspan="2"><?php 
    echo __('Specify whether you want to use the filesystem or database to store uploaded files. Using the database will make it easier to move your installation to another server.');
    ?>
</td>
							</tr>
							<tr>
								<td><label for="upload_localpath"><?php 
    echo __('Upload location');
    ?>
</label></td>
								<td>
									<input type="text" name="upload_localpath" id="upload_localpath" style="width: 250px;" value="<?php 
    echo TBGSettings::getUploadsLocalpath() != "" ? TBGSettings::getUploadsLocalpath() : THEBUGGENIE_PATH . 'files/';
    ?>
"<?php 
    if (!TBGSettings::isUploadsEnabled() || TBGSettings::getUploadStorage() == 'database') {
        ?>
 disabled<?php 
    }
    ?>
>
								</td>
							</tr>
							<tr>
								<td class="config_explanation" colspan="2"><?php 
    echo __("If you're storing files on the filesystem, specify where you want to save the files, here. Default location is the %files% folder in the main folder (not the public folder)", array('%files%' => '<b>files/</b>'));
    ?>
</td>
							</tr>
						</table>
					<?php 
Ejemplo n.º 3
0
 /**
  * Handles an uploaded file, stores it to the correct folder, adds an entry
  * to the database and returns a TBGFile object
  * 
  * @param string $thefile The request parameter the file was sent as
  * 
  * @return TBGFile The TBGFile object
  */
 public function handleUpload($key)
 {
     $apc_exists = self::CanGetUploadStatus();
     if ($apc_exists && !array_key_exists($this->getParameter('APC_UPLOAD_PROGRESS'), $_SESSION['__upload_status'])) {
         $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0);
     }
     try {
         if ($this->getUploadedFile($key) !== null) {
             $thefile = $this->getUploadedFile($key);
             if (TBGSettings::isUploadsEnabled()) {
                 TBGLogging::log('Uploads enabled');
                 if ($thefile['error'] == UPLOAD_ERR_OK) {
                     TBGLogging::log('No upload errors');
                     if (filesize($thefile['tmp_name']) > TBGSettings::getUploadsMaxSize(true) && TBGSettings::getUploadsMaxSize() > 0) {
                         throw new Exception(TBGContext::getI18n()->__('You cannot upload files bigger than %max_size% MB', array('%max_size%' => TBGSettings::getUploadsMaxSize())));
                     }
                     TBGLogging::log('Upload filesize ok');
                     $extension = substr(basename($thefile['name']), strpos(basename($thefile['name']), '.'));
                     if ($extension == '') {
                         TBGLogging::log('OOps, could not determine upload filetype', 'main', TBGLogging::LEVEL_WARNING_RISK);
                         //throw new Exception(TBGContext::getI18n()->__('Could not determine filetype'));
                     } else {
                         TBGLogging::log('Checking uploaded file extension');
                         $extension = substr($extension, 1);
                         $upload_extensions = TBGSettings::getUploadsExtensionsList();
                         if (TBGSettings::getUploadsRestrictionMode() == 'blacklist') {
                             TBGLogging::log('... using blacklist');
                             foreach ($upload_extensions as $an_ext) {
                                 if (strtolower(trim($extension)) == strtolower(trim($an_ext))) {
                                     TBGLogging::log('Upload extension not ok');
                                     throw new Exception(TBGContext::getI18n()->__('This filetype is not allowed'));
                                 }
                             }
                             TBGLogging::log('Upload extension ok');
                         } else {
                             TBGLogging::log('... using whitelist');
                             $is_ok = false;
                             foreach ($upload_extensions as $an_ext) {
                                 if (strtolower(trim($extension)) == strtolower(trim($an_ext))) {
                                     TBGLogging::log('Upload extension ok');
                                     $is_ok = true;
                                     break;
                                 }
                             }
                             if (!$is_ok) {
                                 TBGLogging::log('Upload extension not ok');
                                 throw new Exception(TBGContext::getI18n()->__('This filetype is not allowed'));
                             }
                         }
                         /*if (in_array(strtolower(trim($extension)), array('php', 'asp')))
                         		{
                         			TBGLogging::log('Upload extension is php or asp');
                         			throw new Exception(TBGContext::getI18n()->__('This filetype is not allowed'));
                         		}*/
                     }
                     if (is_uploaded_file($thefile['tmp_name'])) {
                         TBGLogging::log('Uploaded file is uploaded');
                         $files_dir = TBGSettings::getUploadsLocalpath();
                         $new_filename = TBGContext::getUser()->getID() . '_' . NOW . '_' . basename($thefile['name']);
                         TBGLogging::log('Moving uploaded file to ' . $new_filename);
                         if (!move_uploaded_file($thefile['tmp_name'], $files_dir . $new_filename)) {
                             TBGLogging::log('Moving uploaded file failed!');
                             throw new Exception(TBGContext::getI18n()->__('An error occured when saving the file'));
                         } else {
                             TBGLogging::log('Upload complete and ok, storing upload status and returning filename ' . $new_filename);
                             $content_type = TBGFile::getMimeType($files_dir . $new_filename);
                             $file = new TBGFile();
                             $file->setRealFilename($new_filename);
                             $file->setOriginalFilename(basename($thefile['name']));
                             $file->setContentType($content_type);
                             $file->setDescription($this->getParameter($key . '_description'));
                             if (TBGSettings::getUploadStorage() == 'database') {
                                 $file->setContent(file_get_contents($files_dir . $new_filename));
                             }
                             $file->save();
                             //$file = TBGFile::createNew($new_filename, basename($thefile['name']), $content_type, $this->getParameter($key.'_description'), ((TBGSettings::getUploadStorage() == 'database') ? file_get_contents($files_dir.$new_filename) : null));
                             if ($apc_exists) {
                                 $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => true, 'percent' => 100, 'total' => 0, 'complete' => 0, 'file_id' => $file->getID());
                             }
                             return $file;
                         }
                     } else {
                         TBGLogging::log('Uploaded file was not uploaded correctly');
                         throw new Exception(TBGContext::getI18n()->__('The file was not uploaded correctly'));
                     }
                 } else {
                     TBGLogging::log('Upload error: ' . $thefile['error']);
                     switch ($thefile['error']) {
                         case UPLOAD_ERR_INI_SIZE:
                         case UPLOAD_ERR_FORM_SIZE:
                             throw new Exception(TBGContext::getI18n()->__('You cannot upload files bigger than %max_size% MB', array('%max_size%' => TBGSettings::getUploadsMaxSize())));
                             break;
                         case UPLOAD_ERR_PARTIAL:
                             throw new Exception(TBGContext::getI18n()->__('The upload was interrupted, please try again'));
                             break;
                         case UPLOAD_ERR_NO_FILE:
                             throw new Exception(TBGContext::getI18n()->__('No file was uploaded'));
                             break;
                         default:
                             throw new Exception(TBGContext::getI18n()->__('An unhandled error occured') . ': ' . $thefile['error']);
                             break;
                     }
                 }
             } else {
                 TBGLogging::log('Uploads not enabled');
                 throw new Exception(TBGContext::getI18n()->__('Uploads are not enabled'));
             }
             TBGLogging::log('Uploaded file could not be uploaded');
             throw new Exception(TBGContext::getI18n()->__('The file could not be uploaded'));
         }
         TBGLogging::log('Could not find uploaded file' . $key);
         throw new Exception(TBGContext::getI18n()->__('Could not find the uploaded file. Please make sure that it is not too big.'));
     } catch (Exception $e) {
         TBGLogging::log('Upload exception: ' . $e->getMessage());
         if ($apc_exists) {
             $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['error'] = $e->getMessage();
             $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['finished'] = true;
             $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['percent'] = 100;
         }
         throw $e;
     }
 }
Ejemplo n.º 4
0
    ?>
				<?php 
    $attachments = $article->getFiles();
    ?>
				<div id="article_attachments">
					<?php 
    /*if (TBGSettings::isUploadsEnabled() && $article->canEdit()): ?>
    			<?php include_component('main/uploader', array('article' => $article, 'mode' => 'article')); ?>
    		<?php endif;*/
    ?>
					<h4>
						<?php 
    echo __('Article attachments');
    ?>
						<?php 
    if (TBGSettings::isUploadsEnabled() && $article->canEdit()) {
        ?>
							<button class="button button-silver" onclick="TBG.Main.showUploader('<?php 
        echo make_url('get_partial_for_backdrop', array('key' => 'uploader', 'mode' => 'article', 'article_name' => $article_name));
        ?>
');"><?php 
        echo __('Attach a file');
        ?>
</button>
						<?php 
    } else {
        ?>
							<button class="button button-silver disabled" onclick="TBG.Main.Helpers.Message.error('<?php 
        echo __('File uploads are not enabled');
        ?>
');"><?php 
Ejemplo n.º 5
0
								<li><input type="radio" id="large_no_change" name="large_icon_action" value="0" checked><label for="large_no_change"><?php 
echo __('Leave as is') . '</span>';
?>
</label></li>
								<?php 
if (TBGSettings::isUsingCustomHeaderIcon()) {
    ?>
									<li><input type="radio" id="large_clear_icon" name="large_icon_action" value="clear_file"><label for="large_clear_icon"><?php 
    echo __('Remove icon and return to default');
    ?>
</label></li>
								<?php 
}
?>
								<?php 
if (TBGSettings::isUploadsEnabled()) {
    ?>
									<li><input type="radio" id="large_upload" name="large_icon_action" value="upload_file"><label for="large_upload"><?php 
    echo __('Upload new icon');
    ?>
:</label><br><input type="file" name="large_icon"></li>
								<?php 
} else {
    ?>
									<li class="faded_out" style="padding: 2px; font-style: italic;"><?php 
    echo __('Enable file uploads to upload site icons');
    ?>
</li>
								<?php 
}
?>
Ejemplo n.º 6
0
 public function componentReportIssue()
 {
     $introarticle = TBGArticlesTable::getTable()->getArticleByName(ucfirst(TBGContext::getCurrentProject()->getKey()) . ':ReportIssueIntro');
     $this->introarticle = $introarticle instanceof TBGWikiArticle ? $introarticle : TBGArticlesTable::getTable()->getArticleByName('ReportIssueIntro');
     $reporthelparticle = TBGArticlesTable::getTable()->getArticleByName(ucfirst(TBGContext::getCurrentProject()->getKey()) . ':ReportIssueHelp');
     $this->reporthelparticle = $reporthelparticle instanceof TBGWikiArticle ? $reporthelparticle : TBGArticlesTable::getTable()->getArticleByName('ReportIssueHelp');
     $this->uniqid = TBGContext::getRequest()->getParameter('uniqid', uniqid());
     $this->_setupReportIssueProperties();
     $dummyissue = new TBGIssue();
     $dummyissue->setProject(TBGContext::getCurrentProject());
     $this->canupload = TBGSettings::isUploadsEnabled() && $dummyissue->canAttachFiles();
 }
Ejemplo n.º 7
0
            ?>
						<?php 
            if ($article->getID()) {
                ?>
							<li<?php 
                if ($mode == 'history') {
                    ?>
 class="selected"<?php 
                }
                ?>
><?php 
                echo link_tag(make_url('publish_article_history', array('article_name' => $article_name)), __('History'));
                ?>
</li>
							<?php 
                if (in_array($mode, array('show', 'edit')) && TBGSettings::isUploadsEnabled() && $article->canEdit()) {
                    ?>
								<li><a href="javascript:void(0);" onclick="TBG.Main.showUploader('<?php 
                    echo make_url('get_partial_for_backdrop', array('key' => 'uploader', 'mode' => 'article', 'article_name' => $article->getName()));
                    ?>
');"><?php 
                    echo __('Attach a file');
                    ?>
</a></li>
							<?php 
                }
                ?>
							<?php 
                if (isset($article) && $article->canEdit()) {
                    ?>
								<li<?php