示例#1
0
 public function onContentAfterDisplay($context, &$item, &$params)
 {
     if (strcmp("com_crowdfunding.details", $context) != 0) {
         return null;
     }
     if ($this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return null;
     }
     $html = "";
     $files = new CrowdfundingFiles\Files(JFactory::getDbo());
     $files->load(array("project_id" => $item->id));
     if (count($files) > 0) {
         $mediaFolderUri = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id);
         // Get the path for the layout file
         $path = JPath::clean(JPluginHelper::getLayoutPath('content', 'crowdfundingfiles'));
         // Render the login form.
         ob_start();
         include $path;
         $html = ob_get_clean();
     }
     return $html;
 }
示例#2
0
 public function upload()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $response = new Prism\Response\Json();
     $userId = JFactory::getUser()->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $projectId = $this->input->post->get("project_id");
     // Get component parameters
     $params = $app->getParams("com_crowdfundingfiles");
     /** @var  $params Joomla\Registry\Registry */
     // Get the model
     $model = $this->getModel();
     /** @var $model CrowdfundingFilesModelFiles */
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$projectId or !$validator->isValid()) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::sprintf('COM_CROWDFUNDINGFILES_ERROR_INVALID_PROJECT_FILE_TOO_LARGE', $params->get("max_size")))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $files = $this->input->files->get("files");
     if (!$files) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_FILE_CANT_BE_UPLOADED'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get the folder where the images will be stored
     $mediaUri = CrowdfundingFilesHelper::getMediaFolderUri($userId);
     // Get the folder where the images will be stored
     $destination = CrowdfundingFilesHelper::getMediaFolder($userId);
     if (!JFolder::exists($destination)) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_FILE_CANT_BE_UPLOADED'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $options = array("legal_extensions" => $params->get("legal_extensions"), "legal_types" => $params->get("legal_types"), "max_size" => (int) $params->get("max_size", 2), "destination" => $destination);
     try {
         $files = $model->uploadFiles($files, $options);
         $files = $model->storeFiles($files, $projectId, $userId, $mediaUri);
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText($e->getMessage())->failure();
         echo $response;
         JFactory::getApplication()->close();
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_SYSTEM'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGFILES_FILES_UPLOADED'))->setData($files)->success();
     echo $response;
     JFactory::getApplication()->close();
 }
示例#3
0
文件: files.php 项目: pashakiz/crowdf
 /**
  * This method prepares a code that will be included to step "Extras" on project wizard.
  *
  * @param string    $context This string gives information about that where it has been executed the trigger.
  * @param object    $item    A project data.
  * @param Joomla\Registry\Registry $params  The parameters of the component
  *
  * @return null|string
  */
 public function onExtrasDisplay($context, &$item, &$params)
 {
     if (strcmp("com_crowdfunding.project.extras", $context) != 0) {
         return null;
     }
     if ($this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return null;
     }
     if (empty($item->user_id)) {
         return null;
     }
     // Create a media folder.
     $mediaFolder = CrowdfundingFilesHelper::getMediaFolder();
     if (!JFolder::exists($mediaFolder)) {
         CrowdfundingHelper::createFolder($mediaFolder);
     }
     // Create a media folder for a user.
     $mediaFolder = CrowdfundingFilesHelper::getMediaFolder($item->user_id);
     if (!JFolder::exists($mediaFolder)) {
         CrowdfundingHelper::createFolder($mediaFolder);
     }
     $componentParams = JComponentHelper::getParams("com_crowdfundingfiles");
     /** @var  $componentParams Joomla\Registry\Registry */
     $mediaUri = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id);
     $options = array("project_id" => $item->id, "user_id" => $item->user_id);
     $files = new CrowdfundingFiles\Files(JFactory::getDbo());
     $files->load($options);
     // Load jQuery
     JHtml::_("jquery.framework");
     JHtml::_("prism.ui.pnotify");
     JHtml::_('prism.ui.fileupload');
     JHtml::_('prism.ui.joomlaHelper');
     // Include the translation of the confirmation question.
     JText::script('PLG_CROWDFUNDING_FILES_DELETE_QUESTION');
     // Get the path for the layout file
     $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'files'));
     // Render the login form.
     ob_start();
     include $path;
     $html = ob_get_clean();
     return $html;
 }
示例#4
0
<?php

/**
 * @package      CrowdfundingFiles
 * @subpackage   Component
 * @author       Todor Iliev
 * @copyright    Copyright (C) 2014 Todor Iliev <*****@*****.**>. All rights reserved.
 * @license      http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
// no direct access
defined('_JEXEC') or die;
foreach ($this->items as $i => $item) {
    $mediaFolder = CrowdfundingFilesHelper::getMediaFolderUri($item->user_id);
    ?>
    <tr class="row<?php 
    echo $i % 2;
    ?>
">
        <td class="center hidden-phone">
            <?php 
    echo JHtml::_('grid.id', $i, $item->id);
    ?>
        </td>
        <td class="has-context">
            <a href="<?php 
    echo JRoute::_("index.php?option=com_crowdfundingfiles&view=file&layout=edit&id=" . $item->id);
    ?>
">
            <?php 
    echo $this->escape($item->title);
    ?>