Exemplo n.º 1
0
 /**
  * @throws Exception
  */
 public function delete()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     $cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array');
     // Array of integers
     Joomla\Utilities\ArrayHelper::toInteger($cid);
     if (!$cid) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_NO_ATTACHMENTS_SELECTED'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     foreach ($cid as $id) {
         $attachment = KunenaAttachmentHelper::get($id);
         $message = $attachment->getMessage();
         $attachments = array($attachment->id, 1);
         $attach = array();
         $removeList = array_keys(array_diff_key($attachments, $attach));
         Joomla\Utilities\ArrayHelper::toInteger($removeList);
         $message->removeAttachments($removeList);
         $message->save();
         $topic = $message->getTopic();
         $attachment->delete();
         if ($topic->attachments > 0) {
             $topic->attachments = $topic->attachments - 1;
             $topic->save(false);
         }
     }
     $this->app->enqueueMessage(JText::_('COM_KUNENA_ATTACHMENTS_DELETED_SUCCESSFULLY'));
     $this->setRedirect(KunenaRoute::_($this->baseurl, false));
 }
Exemplo n.º 2
0
 /**
  * Remove an item.
  *
  * @throws  Exception
  * @return  void
  *
  * @since   12.2
  */
 public function delete()
 {
     // Check for request forgeries
     JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /* @var $app JApplicationAdministrator */
     // Gets the data from the form
     $cid = $this->input->post->get('cid', array(), 'array');
     $cid = Joomla\Utilities\ArrayHelper::toInteger($cid);
     $urlId = $app->getUserState("url.id");
     $redirectData = array("view" => "url", "layout" => "edit", "id" => $urlId);
     if (!$cid) {
         $this->displayWarning(JText::_("COM_ITPMETA_ERROR_INVALID_ITEMS"), $redirectData);
         return;
     }
     try {
         $model = $this->getModel();
         $model->delete($cid);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM'));
     }
     $msg = JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid));
     $this->displayMessage($msg, $redirectData);
 }
Exemplo n.º 3
0
 /**
  * Enable auto-update.
  *
  * @throws  Exception
  * @return  void
  */
 public function enableau()
 {
     // Check for request forgeries
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $redirectOptions = array("view" => "urls");
     $cid = $this->input->post->get("cid", array(), "array");
     $cid = Joomla\Utilities\ArrayHelper::toInteger($cid);
     $data = array('enableau' => 1, 'disableau' => 0);
     $task = $this->getTask();
     $value = JArrayHelper::getValue($data, $task, 0, 'int');
     if (empty($cid)) {
         $this->displayNotice(JText::_($this->text_prefix . '_ERROR_NO_ITEM_SELECTED'), $redirectOptions);
         return;
     }
     try {
         $model = $this->getModel();
         $model->updateAutoupdate($cid, $value);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM'));
     }
     if ($value == 1) {
         $msg = $this->text_prefix . '_N_ITEMS_AUTOUPDATE_ENABLED';
     } else {
         $msg = $this->text_prefix . '_N_ITEMS_AUTOUPDATE_DISABLED';
     }
     $this->displayMessage(JText::plural($msg, count($cid)), $redirectOptions);
 }
Exemplo n.º 4
0
 public function create()
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     // Get form data
     $pks = $this->input->post->get('cid', array(), 'array');
     $model = $this->getModel('Profile', 'GamificationModel');
     /** @var $model GamificationModelProfile */
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     // Check for validation errors.
     if (!$pks) {
         $this->defaultLink .= '&view=' . $this->view_list;
         $this->setMessage(JText::_('COM_GAMIFICATION_INVALID_ITEM'), 'notice');
         $this->setRedirect(JRoute::_($this->defaultLink, false));
         return;
     }
     try {
         $pks = $model->filterProfiles($pks);
         if (!$pks) {
             $this->defaultLink .= '&view=' . $this->view_list;
             $this->setMessage(JText::_('COM_GAMIFICATION_INVALID_ITEM'), 'notice');
             $this->setRedirect(JRoute::_($this->defaultLink, false));
             return;
         }
         $model->create($pks);
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_gamification');
         throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
     }
     $msg = JText::plural('COM_GAMIFICATION_N_PROFILES_CREATED', count(pks));
     $link = $this->defaultLink . '&view=' . $this->view_list;
     $this->setRedirect(JRoute::_($link, false), $msg);
 }
 /**
  * Method to remove records via AJAX.
  *
  * @throws  Exception
  * @return  void
  */
 public function remove()
 {
     // Get the input
     $app = JFactory::getApplication();
     $pks = $app->input->post->get('rid', array(), 'array');
     $userId = JFactory::getUser()->get('id');
     $response = new Prism\Response\Json();
     // Sanitize the input
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     // Validate user
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         $app->close();
     }
     // Validate primary keys
     if (!$pks) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS_SELECTED'))->failure();
         echo $response;
         $app->close();
     }
     $rewardId = Joomla\Utilities\ArrayHelper::getValue($pks, 0);
     // Validate reward owner.
     $validator = new Crowdfunding\Validator\Reward\Owner(JFactory::getDbo(), $rewardId, $userId);
     if (!$rewardId or !$validator->isValid()) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS_SELECTED'))->failure();
         echo $response;
         $app->close();
     }
     // Get the model
     $model = $this->getModel();
     try {
         $reward = new Crowdfunding\Reward(JFactory::getDbo());
         $reward->load($rewardId);
         // If the reward is part of transaction,
         // set it as trashed.
         if ($reward->isSelectedByUser()) {
             $reward->trash();
         } else {
             // Get the folder where the images are stored
             $imagesFolder = CrowdfundingHelper::getImagesFolder($userId, JPATH_ROOT);
             $model->remove($rewardId, $imagesFolder);
         }
     } catch (RuntimeException $e) {
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure();
         echo $response;
         $app->close();
     } catch (Exception $e) {
         JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding');
         $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure();
         echo $response;
         $app->close();
     }
     $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_SUCCESSFULY_REMOVED'))->success();
     echo $response;
     $app->close();
 }
Exemplo n.º 6
0
 public function emails()
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     /** @var $app JApplicationAdministrator */
     $keys = $this->input->post->get('cid', array(), 'array');
     $keys = Joomla\Utilities\ArrayHelper::toInteger($keys);
     $model = $this->getModel();
     /** @var $model EmailTemplatesModelExport */
     try {
         $output = $model->extractEmails($keys);
         $fileName = 'emails.xml';
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_SYSTEM'));
     }
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.path');
     jimport('joomla.filesystem.archive');
     $tmpFolder = JPath::clean($app->get('tmp_path'));
     $date = new JDate();
     $date = $date->format('d_m_Y_H_i_s');
     $archiveName = JFile::stripExt(basename($fileName)) . '_' . $date;
     $archiveFile = $archiveName . '.zip';
     $destination = $tmpFolder . DIRECTORY_SEPARATOR . $archiveFile;
     // compression type
     $zipAdapter = JArchive::getAdapter('zip');
     $filesToZip[] = array('name' => $fileName, 'data' => $output);
     $zipAdapter->create($destination, $filesToZip, array());
     $filesize = filesize($destination);
     $app = JFactory::getApplication();
     $app->setHeader('Content-Type', 'application/octet-stream', true);
     $app->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
     $app->setHeader('Content-Transfer-Encoding', 'binary', true);
     $app->setHeader('Pragma', 'no-cache', true);
     $app->setHeader('Expires', '0', true);
     $app->setHeader('Content-Disposition', 'attachment; filename=' . $archiveFile, true);
     $app->setHeader('Content-Length', $filesize, true);
     $doc = JFactory::getDocument();
     $doc->setMimeEncoding('application/octet-stream');
     $app->sendHeaders();
     echo file_get_contents($destination);
     JFactory::getApplication()->close();
 }
 /**
  * Method to save the submitted ordering values for records via AJAX.
  *
  * @return    void
  *
  * @since   3.0
  */
 public function saveOrderAjax()
 {
     // Get the input
     $pks = $this->input->post->get('cid', [], 'array');
     $order = $this->input->post->get('order', [], 'array');
     // Sanitize the input
     Joomla\Utilities\ArrayHelper::toInteger($pks);
     Joomla\Utilities\ArrayHelper::toInteger($order);
     // Get the model
     /** @var ChurchDirectoryModelGeoStatus $model */
     $model = $this->getModel();
     // Save the ordering
     $return = $model->saveorder($pks, $order);
     if ($return) {
         echo "1";
     }
     // Close the application
     JFactory::getApplication()->close();
 }
Exemplo n.º 8
0
 /**
  * Method to save the submitted ordering values for records via AJAX.
  *
  * @return  void
  * @throws Exception
  *
  * @since   3.0
  */
 public function saveOrderAjax()
 {
     $response = new Prism\Response\Json();
     // Get the input
     $pks = $this->input->post->get('cid', array(), 'array');
     $order = $this->input->post->get('order', array(), 'array');
     // Sanitize the input
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     $order = Joomla\Utilities\ArrayHelper::toInteger($order);
     // Get the model
     $model = $this->getModel();
     try {
         $model->saveorder($pks, $order);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM'));
     }
     $response->setTitle(JText::_('COM_USERIDEAS_SUCCESS'))->setText(JText::_('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED'))->success();
     echo $response;
     JFactory::getApplication()->close();
 }
Exemplo n.º 9
0
 /**
  * Method to save the submitted ordering values for records via AJAX.
  *
  * @throws  Exception
  * @since   3.0
  */
 public function saveOrderAjax()
 {
     // Get the input
     $pks = $this->input->post->get('cid', array(), 'array');
     $order = $this->input->post->get('order', array(), 'array');
     // Sanitize the input
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     $order = Joomla\Utilities\ArrayHelper::toInteger($order);
     // Get the model
     $model = $this->getModel();
     // Save the item
     try {
         $model->saveorder($pks, $order);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM'));
     }
     $response = array('success' => true, 'title' => JText::_('COM_ITPMETA_SUCCESS'), 'text' => JText::_('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED'), 'data' => array());
     echo json_encode($response);
     JFactory::getApplication()->close();
 }
 public function batch()
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $response = new Prism\Response\Json();
     // Get the input
     $itemsIds = $this->input->post->getString('ids');
     $itemsIds = explode(',', $itemsIds);
     $itemsIds = Joomla\Utilities\ArrayHelper::toInteger($itemsIds);
     $action = $this->input->post->get('action');
     // Get the model
     $model = $this->getModel();
     /** @var $model EmailTemplatesModelPlaceholder */
     // Check for selected packages.
     if (!$itemsIds) {
         $response->setTitle(JText::_('COM_EMAILTEMPLATES_FAIL'))->setText(JText::_('COM_EMAILTEMPLATES_PLACEHOLDERS_NOT_SELECTED'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     try {
         switch ($action) {
             case 'copy':
                 $categoryId = $this->input->post->get('catid');
                 // Check for valid category.
                 if (!$categoryId) {
                     $response->setTitle(JText::_('COM_EMAILTEMPLATES_FAIL'))->setText(JText::_('COM_EMAILTEMPLATES_CATEGORY_NOT_SELECTED'))->failure();
                     echo $response;
                     JFactory::getApplication()->close();
                 }
                 $model->copyPlaceholders($itemsIds, $categoryId);
                 $response->setTitle(JText::_('COM_EMAILTEMPLATES_SUCCESS'))->setText(JText::_('COM_EMAILTEMPLATES_PLACEHOLDERS_COPIED_SUCCESSFULLY'))->success();
                 break;
         }
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_SYSTEM'));
     }
     echo $response;
     JFactory::getApplication()->close();
 }
 /**
  * This method sends notification mail to the administrator when project owner publish a project.
  *
  * If I return NULL, an message will not be displayed in the browser.
  * If I return FALSE, an error message will be displayed in the browser.
  *
  * @param string $context
  * @param array  $ids
  * @param int    $state
  *
  * @return bool|null
  */
 public function onContentChangeState($context, $ids, $state)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isAdmin()) {
         return null;
     }
     if (strcmp('com_crowdfunding.project', $context) !== 0) {
         return null;
     }
     // Initialize plugin
     $this->init();
     // Check for enabled option for sending mail.
     // when user publish a project.
     $emailId = $this->params->get('send_when_published', 0);
     if (!$emailId) {
         $this->log->add(JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_INVALID_EMAIL_TEMPLATE', $this->name), 'PLG_CONTENT_ADMIN_EMAIL_ERROR', JText::_('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_INVALID_EMAIL_TEMPLATE_NOTE'));
         return null;
     }
     $ids = Joomla\Utilities\ArrayHelper::toInteger($ids);
     if (count($ids) > 0 and (int) $state === Prism\Constants::PUBLISHED) {
         $projects = $this->getProjectsData($ids);
         if (!$projects) {
             $this->log->add(JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_INVALID_PROJECTS', $this->name), 'PLG_CONTENT_ADMIN_EMAIL_ERROR', JText::_('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_INVALID_PROJECTS_NOTE'));
             return false;
         }
         // Load class CrowdfundingEmail.
         foreach ($projects as $project) {
             // Send email to the administrator.
             $result = $this->sendProjectMail($project, $emailId);
             // Check for error.
             if ($result !== true) {
                 return null;
             }
         }
     }
     return true;
 }
Exemplo n.º 12
0
 /**
  * Send notification mail to a user when his project be approved.
  * If I return NULL, an message will not be displayed in the browser.
  * If I return FALSE, an error message will be displayed in the browser.
  *
  * @param string $context
  * @param array $ids
  * @param int $state
  *
  * @return bool|null
  */
 public function onContentChangeState($context, $ids, $state)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if (!$app->isAdmin()) {
         return null;
     }
     if (strcmp("com_crowdfunding.project", $context) != 0) {
         return null;
     }
     // Initialize plugin
     $this->init();
     // Check for enabled option for sending mail
     // when administrator approve project.
     $emailId = $this->params->get("send_when_approved", 0);
     if (!$emailId) {
         $this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_INVALID_EMAIL_TEMPLATE", $this->name), "PLG_CONTENT_USERE_MAIL_ERROR", JText::_("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_INVALID_EMAIL_TEMPLATE_NOTE"));
         return false;
     }
     Joomla\Utilities\ArrayHelper::toInteger($ids);
     if (!empty($ids) and $state == Prism\Constants::APPROVED) {
         $projects = $this->getProjectsData($ids);
         if (!$projects) {
             $this->log->add(JText::sprintf("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_INVALID_PROJECTS", $this->name), "PLG_CONTENT_USERE_MAIL_ERROR", JText::_("PLG_CONTENT_CROWDFUNDINGUSERMAIL_ERROR_INVALID_PROJECTS_NOTE"));
             return false;
         }
         foreach ($projects as $project) {
             // Send email to the administrator.
             $return = $this->sendMail($project, $emailId);
             // If there is an error, stop the loop.
             // Let the administrator to look the errors.
             if ($return !== true) {
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 13
0
 /**
  * Method to unset the default status.
  *
  * @since   1.6
  */
 public function unsetDefault()
 {
     // Check for request forgeries
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $pks = $this->input->post->get('cid', array(), 'array');
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     $redirectOptions = array("view" => $this->view_list);
     // Check for errors
     if (!$pks) {
         $this->displayNotice(JText::_("COM_USERIDEAS_ERROR_NO_ITEM_SELECTED"), $redirectOptions);
         return;
     }
     try {
         // Pop off the first element.
         $id = array_shift($pks);
         $model = $this->getModel();
         $model->unsetDefault($id);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_USERIDEAS_STATUS_SET_NOT_DEFAULT'), $redirectOptions);
 }
 /**
  * This method sends notification mail to the administrator when project owner publish a project.
  *
  * If I return NULL, an message will not be displayed in the browser.
  * If I return FALSE, an error message will be displayed in the browser.
  *
  * @param string $context
  * @param array  $ids
  * @param int    $state
  *
  * @return bool|null
  */
 public function onContentChangeState($context, $ids, $state)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isAdmin()) {
         return null;
     }
     if (strcmp('com_crowdfunding.project', $context) !== 0) {
         return null;
     }
     // Initialize plugin
     $this->init();
     if (!JComponentHelper::isEnabled('com_emailtemplates')) {
         JLog::add($this->errorPrefix . JText::_('LIB_CROWDFUNDING_EMAIL_TEMPLATES_INSTALLATION'), JLog::WARNING, 'com_crowdfunding');
         return null;
     }
     // Check for enabled option for sending mail.
     // when user publish a project.
     $emailId = $this->params->get('send_when_published', 0);
     if (!$emailId) {
         JLog::add($this->errorPrefix . JText::sprintf('PLG_CONTENT_CROWDFUNDINGADMINMAIL_ERROR_INVALID_EMAIL_TEMPLATE'), JLog::WARNING, 'com_crowdfunding');
         return null;
     }
     $ids = Joomla\Utilities\ArrayHelper::toInteger($ids);
     if (count($ids) > 0 and (int) $state === Prism\Constants::PUBLISHED) {
         $projects = $this->getProjectsData($ids);
         // Send emails.
         foreach ($projects as $project) {
             $result = $this->sendProjectMail($project, $emailId);
             // Check for error.
             if ($result !== true) {
                 break;
             }
         }
     }
     return true;
 }
Exemplo n.º 15
0
 /**
  * Upload images.
  *
  * @param  array $files
  * @param  array $rewardsIds
  * @param  array $options
  * @param  Joomla\Registry\Registry $params
  *
  * @throws \InvalidArgumentException
  * @return array
  */
 public function uploadImages(array $files, array $rewardsIds, array $options, $params)
 {
     // Joomla! media extension parameters
     $mediaParams = JComponentHelper::getParams('com_media');
     /** @var  $mediaParams Joomla\Registry\Registry */
     $KB = 1024 * 1024;
     $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB;
     $mimeTypes = explode(',', $mediaParams->get('upload_mime'));
     $imageExtensions = explode(',', $mediaParams->get('image_extensions'));
     $images = array();
     $rewardsIds = Joomla\Utilities\ArrayHelper::toInteger($rewardsIds);
     jimport('Prism.libs.Flysystem.init');
     $temporaryAdapter = new League\Flysystem\Adapter\Local($options['temporary_path']);
     $storageAdapter = new League\Flysystem\Adapter\Local($options['destination_path']);
     $temporaryFilesystem = new League\Flysystem\Filesystem($temporaryAdapter);
     $storageFilesystem = new League\Flysystem\Filesystem($storageAdapter);
     $manager = new League\Flysystem\MountManager(['temporary' => $temporaryFilesystem, 'storage' => $storageFilesystem]);
     foreach ($files as $rewardId => $image) {
         // If the image is set to not valid reward, continue to next one.
         // It is impossible to store image to missed reward.
         if (!in_array((int) $rewardId, $rewardsIds, true)) {
             continue;
         }
         $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name');
         $uploadedName = JString::trim(Joomla\Utilities\ArrayHelper::getValue($image, 'name'));
         $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error');
         $fileOptions = new \Joomla\Registry\Registry(array('filename_length' => 12));
         $file = new Prism\File\Image($image, $options['temporary_path'], $fileOptions);
         $result = array('image' => '', 'thumb' => '', 'square' => '');
         if ($uploadedName !== null and $uploadedName !== '') {
             // Prepare size validator.
             $fileSize = (int) Joomla\Utilities\ArrayHelper::getValue($image, 'size');
             // 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.
             $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName);
             // Get allowed mime types from media manager options
             $imageValidator->setMimeTypes($mimeTypes);
             // Get allowed image extensions from media manager options
             $imageValidator->setImageExtensions($imageExtensions);
             $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator);
             // Validate the file
             if (!$file->isValid()) {
                 continue;
             }
             // Upload it in the temp folder.
             $fileData = $file->upload();
             if ($manager->has('temporary://' . $fileData['filename'])) {
                 // Copy original image.
                 $originalFile = $fileData['filename'];
                 $result['image'] = 'reward_' . $originalFile;
                 $manager->copy('temporary://' . $originalFile, 'storage://' . $result['image']);
                 // Create thumbnail.
                 $resizeOptions = array('width' => $params->get('rewards_image_thumb_width', 200), 'height' => $params->get('rewards_image_thumb_height', 200), 'scale' => $params->get('rewards_image_resizing_scale', JImage::SCALE_INSIDE));
                 $fileData = $file->resize($resizeOptions, Prism\Constants::DO_NOT_REPLACE, 'reward_thumb_');
                 $manager->move('temporary://' . $fileData['filename'], 'storage://' . $fileData['filename']);
                 $result['thumb'] = $fileData['filename'];
                 // Create square image.
                 $resizeOptions = array('width' => $params->get('rewards_image_square_width', 50), 'height' => $params->get('rewards_image_square_height', 50), 'scale' => $params->get('rewards_image_resizing_scale', JImage::SCALE_INSIDE));
                 $fileData = $file->resize($resizeOptions, Prism\Constants::DO_NOT_REPLACE, 'reward_square_');
                 $manager->move('temporary://' . $fileData['filename'], 'storage://' . $fileData['filename']);
                 $result['square'] = $fileData['filename'];
                 // Remove the original file from temporary folder.
                 $manager->delete('temporary://' . $originalFile);
                 $images[$rewardId] = $result;
             }
         }
     }
     return $images;
 }
Exemplo n.º 16
0
 /**
  * @throws Exception
  */
 function restore()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     $cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array');
     // Array of integers
     Joomla\Utilities\ArrayHelper::toInteger($cid);
     $type = JFactory::getApplication()->input->getCmd('type', 'topics', 'post');
     if (empty($cid)) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_A_NO_MESSAGES_SELECTED'), 'notice');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     $nb_items = 0;
     if ($type == 'messages') {
         $messages = KunenaForumMessageHelper::getMessages($cid, 'none');
         foreach ($messages as $target) {
             if ($target->publish(KunenaForum::PUBLISHED)) {
                 $nb_items++;
             } else {
                 $this->app->enqueueMessage($target->getError(), 'notice');
             }
         }
     } elseif ($type == 'topics') {
         $topics = KunenaForumTopicHelper::getTopics($cid, 'none');
         foreach ($topics as $target) {
             if ($target->publish(KunenaForum::PUBLISHED)) {
                 $nb_items++;
             } else {
                 $this->app->enqueueMessage($target->getError(), 'notice');
             }
         }
     } else {
         // Error...
     }
     if ($nb_items > 0) {
         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_TRASH_ITEMS_RESTORE_DONE', $nb_items));
     }
     KunenaUserHelper::recount();
     KunenaForumTopicHelper::recount();
     KunenaForumCategoryHelper::recount();
     $this->setRedirect(KunenaRoute::_($this->baseurl, false));
 }
Exemplo n.º 17
0
 /**
  *
  */
 function save()
 {
     $template = $this->app->input->get('templatename', '', 'method', 'cmd');
     $menus = $this->app->input->get('selections', array(), 'post', 'array');
     Joomla\Utilities\ArrayHelper::toInteger($menus);
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     if (!$template) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_OPERATION_FAILED') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_NOT_SPECIFIED'));
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     $this->_saveParamFile($template);
     $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_CONFIGURATION_SAVED'));
     $this->setRedirect(KunenaRoute::_($this->baseurl, false));
 }
 /**
  * Method to save the form data.
  *
  * @param   array    $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $dispatcher = JEventDispatcher::getInstance();
     $table = $this->getTable();
     $input = JFactory::getApplication()->input;
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Include the content plugins for the on save events.
     JPluginHelper::importPlugin('content');
     // Load the row if saving an existing category.
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     // Set the new parent id if parent id not matched OR while New/Save as Copy .
     if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) {
         $table->setLocation($data['parent_id'], 'last-child');
     }
     // Alter the title for save as copy
     if ($input->get('task') == 'save2copy') {
         list($title, $alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']);
         $data['title'] = $title;
         $data['alias'] = $alias;
         $data['published'] = 0;
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Bind the rules.
     if (isset($data['rules'])) {
         $rules = new JAccessRules($data['rules']);
         $table->setRules($rules);
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onContentBeforeSave event.
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     $assoc = $this->getAssoc();
     if ($assoc) {
         // Adding self to the association
         $associations = $data['associations'];
         // Unset any invalid associations
         $associations = Joomla\Utilities\ArrayHelper::toInteger($associations);
         foreach ($associations as $tag => $id) {
             if (!$id) {
                 unset($associations[$tag]);
             }
         }
         // Detecting all item menus
         $all_language = $table->language == '*';
         if ($all_language && !empty($associations)) {
             JError::raiseNotice(403, JText::_('COM_CATEGORIES_ERROR_ALL_LANGUAGE_ASSOCIATED'));
         }
         $associations[$table->language] = $table->id;
         // Deleting old association for these items
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->delete('#__languages_associations')->where($db->quoteName('context') . ' = ' . $db->quote('com_categories.item'))->where($db->quoteName('id') . ' IN (' . implode(',', $associations) . ')');
         $db->setQuery($query);
         $db->execute();
         if ($error = $db->getErrorMsg()) {
             $this->setError($error);
             return false;
         }
         if (!$all_language && count($associations)) {
             // Adding new association for these items
             $key = md5(json_encode($associations));
             $query->clear()->insert('#__languages_associations');
             foreach ($associations as $id) {
                 $query->values((int) $id . ',' . $db->quote('com_categories.item') . ',' . $db->quote($key));
             }
             $db->setQuery($query);
             $db->execute();
             if ($error = $db->getErrorMsg()) {
                 $this->setError($error);
                 return false;
             }
         }
     }
     // Trigger the onContentAfterSave event.
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
     // Rebuild the path for the category:
     if (!$table->rebuildPath($table->id)) {
         $this->setError($table->getError());
         return false;
     }
     // Rebuild the paths of the category's children:
     if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) {
         $this->setError($table->getError());
         return false;
     }
     $this->setState($this->getName() . '.id', $table->id);
     // Clear the cache
     $this->cleanCache();
     return true;
 }
Exemplo n.º 19
0
 /**
  * @param   mixed $user
  *
  * @return mixed
  */
 public function getAllowedCategories($user = null)
 {
     static $read = array();
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     if (!$user instanceof KunenaUser) {
         $user = KunenaFactory::getUser($user);
     }
     if (!isset($read[$user->userid])) {
         $id = $user->userid;
         $app = JFactory::getApplication();
         // TODO: handle guests/bots with no userstate
         $read[$id] = $app->getUserState("com_kunena.user{$id}_read");
         if ($read[$id] === null) {
             $list = array();
             $categories = KunenaForumCategoryHelper::getCategories(false, false, 'none');
             foreach ($categories as $category) {
                 // Remove unpublished categories
                 if ($category->published != 1) {
                     unset($categories[$category->id]);
                 }
                 // Moderators have always access
                 if (self::isModerator($user, $category->id)) {
                     $list[$category->id] = $category->id;
                     unset($categories[$category->id]);
                 }
             }
             // Get external authorization
             if (!empty($categories)) {
                 // @var KunenaAccess $access
                 foreach ($this->accesstypes['all'] as $access) {
                     if (method_exists($access, 'authoriseCategories')) {
                         $list += $access->authoriseCategories($id, $categories);
                     }
                 }
             }
             // Clean up and filter the resulting list by using only array keys.
             $list = array_keys($list);
             Joomla\Utilities\ArrayHelper::toInteger($list);
             $read[$id] = array_combine($list, $list);
             unset($read[$id][0]);
             $app->setUserState("com_kunena.user{$id}_read", $read[$id]);
         }
     }
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return $read[$user->userid];
 }
Exemplo n.º 20
0
 public function updateAutoupdate($pks, $state)
 {
     $pks = (array) $pks;
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     $state = !$state ? 0 : 1;
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->update($db->quoteName("#__itpm_urls", "a"))->set("a.autoupdate = " . (int) $state)->where("a.id IN (" . implode(",", $pks) . ")");
     $db->setQuery($query);
     $db->execute();
     return true;
 }
Exemplo n.º 21
0
 /**
  * @throws Exception
  */
 function permdel_posts()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirectBack();
         return;
     }
     $ids = array_keys(JFactory::getApplication()->input->get('posts', array(), 'post', 'array'));
     // Array of integer keys
     Joomla\Utilities\ArrayHelper::toInteger($ids);
     $success = 0;
     $messages = KunenaForumMessageHelper::getMessages($ids);
     if (!$messages) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_NO_MESSAGES_SELECTED'));
     } else {
         foreach ($messages as $message) {
             if ($message->authorise('permdelete') && $message->delete()) {
                 $success++;
             } else {
                 $this->app->enqueueMessage($message->getError(), 'notice');
             }
         }
     }
     if ($success) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_BULKMSG_DELETED'));
     }
     $this->setRedirectBack();
 }
Exemplo n.º 22
0
 /**
  * Method to return a list of user Ids contained in a Group (derived from Joomla 1.6)
  *
  * @param   int     $groupId   The group Id
  * @param   boolean $recursive Recursively include all child groups (optional)
  * @param   array   $inUsers   Only list selected users.
  *
  * @return    array
  */
 protected function getUsersByGroup($groupId, $recursive = false, $inUsers = array())
 {
     // Get a database object.
     $db = JFactory::getDbo();
     $test = $recursive ? '>=' : '=';
     if (empty($groupId)) {
         return array();
     }
     if (is_array($groupId)) {
         $groupId = implode(',', $groupId);
     }
     $inUsers = implode(',', $inUsers);
     // First find the users contained in the group
     $query = $db->getQuery(true);
     $query->select('DISTINCT(user_id)');
     $query->from('#__usergroups as ug1');
     $query->join('INNER', '#__usergroups AS ug2 ON ug2.lft' . $test . 'ug1.lft AND ug1.rgt' . $test . 'ug2.rgt');
     $query->join('INNER', '#__user_usergroup_map AS m ON ug2.id=m.group_id');
     $query->where("ug1.id IN ({$groupId})");
     if ($inUsers) {
         $query->where("user_id IN ({$inUsers})");
     }
     $db->setQuery($query);
     $result = (array) $db->loadColumn();
     // Clean up any NULL values, just in case
     Joomla\Utilities\ArrayHelper::toInteger($result);
     return $result;
 }
Exemplo n.º 23
0
 /**
  * @throws Exception
  */
 function remove()
 {
     $db = JFactory::getDBO();
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     $cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array');
     // Array of integers
     Joomla\Utilities\ArrayHelper::toInteger($cid);
     $cids = implode(',', $cid);
     if ($cids) {
         $db->setQuery("DELETE FROM #__kunena_ranks WHERE rank_id IN ({$cids})");
         $db->execute();
         if (KunenaError::checkDatabaseError()) {
             return;
         }
     }
     $this->app->enqueueMessage(JText::_('COM_KUNENA_RANK_DELETED'));
     $this->setRedirect(KunenaRoute::_($this->baseurl, false));
 }
Exemplo n.º 24
0
 /**
  * @throws Exception
  */
 function orderdown()
 {
     $cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array');
     // Array of integers
     Joomla\Utilities\ArrayHelper::toInteger($cid);
     $this->orderUpDown(array_shift($cid), 1);
     $this->setRedirectBack();
 }
Exemplo n.º 25
0
 /**
  * @param   JDatabaseQuery $query
  */
 protected function build(JDatabaseQuery $query)
 {
     if (!empty($this->hold)) {
         Joomla\Utilities\ArrayHelper::toInteger($this->hold, 0);
         $hold = implode(',', $this->hold);
         $query->where("a.hold IN ({$hold})");
     }
     if (isset($this->moved)) {
         $query->where('a.moved_id' . ($this->moved ? '>0' : '=0'));
     }
 }
Exemplo n.º 26
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState('item.id');
     $isNew = true;
     $table = $this->getTable();
     $context = $this->option . '.' . $this->name;
     // Include the plugins for the on save events.
     JPluginHelper::importPlugin($this->events_map['save']);
     // Load the row if saving an existing item.
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     if (!$isNew) {
         if ($table->parent_id == $data['parent_id']) {
             // If first is chosen make the item the first child of the selected parent.
             if ($data['menuordering'] == -1) {
                 $table->setLocation($data['parent_id'], 'first-child');
             } elseif ($data['menuordering'] == -2) {
                 $table->setLocation($data['parent_id'], 'last-child');
             } elseif ($data['menuordering'] && $table->id != $data['menuordering'] || empty($data['id'])) {
                 $table->setLocation($data['menuordering'], 'after');
             } elseif ($data['menuordering'] && $table->id == $data['menuordering']) {
                 unset($data['menuordering']);
             }
         } else {
             $table->setLocation($data['parent_id'], 'last-child');
         }
     } else {
         $table->setLocation($data['parent_id'], 'last-child');
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Alter the title & alias for save as copy.  Also, unset the home record.
     if (!$isNew && $data['id'] == 0) {
         list($title, $alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title);
         $table->title = $title;
         $table->alias = $alias;
         $table->published = 0;
         $table->home = 0;
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the before save event.
     $result = JFactory::getApplication()->triggerEvent($this->event_before_save, array($context, &$table, $isNew));
     // Store the data.
     if (in_array(false, $result, true) || !$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the after save event.
     JFactory::getApplication()->triggerEvent($this->event_after_save, array($context, &$table, $isNew));
     // Rebuild the tree path.
     if (!$table->rebuildPath($table->id)) {
         $this->setError($table->getError());
         return false;
     }
     $this->setState('item.id', $table->id);
     $this->setState('item.menutype', $table->menutype);
     // Load associated menu items
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         // Adding self to the association
         $associations = isset($data['associations']) ? $data['associations'] : array();
         // Unset any invalid associations
         $associations = Joomla\Utilities\ArrayHelper::toInteger($associations);
         foreach ($associations as $tag => $id) {
             if (!$id) {
                 unset($associations[$tag]);
             }
         }
         // Detecting all item menus
         $all_language = $table->language == '*';
         if ($all_language && !empty($associations)) {
             JError::raiseNotice(403, JText::_('COM_MENUS_ERROR_ALL_LANGUAGE_ASSOCIATED'));
         }
         // Get associationskey for edited item
         $db = $this->getDbo();
         $query = $db->getQuery(true)->select($db->quoteName('key'))->from($db->quoteName('#__associations'))->where($db->quoteName('context') . ' = ' . $db->quote($this->associationsContext))->where($db->quoteName('id') . ' = ' . (int) $table->id);
         $db->setQuery($query);
         $old_key = $db->loadResult();
         // Deleting old associations for the associated items
         $query = $db->getQuery(true)->delete($db->quoteName('#__associations'))->where($db->quoteName('context') . ' = ' . $db->quote($this->associationsContext));
         if ($associations) {
             $query->where('(' . $db->quoteName('id') . ' IN (' . implode(',', $associations) . ') OR ' . $db->quoteName('key') . ' = ' . $db->quote($old_key) . ')');
         } else {
             $query->where($db->quoteName('key') . ' = ' . $db->quote($old_key));
         }
         $db->setQuery($query);
         try {
             $db->execute();
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             return false;
         }
         // Adding self to the association
         if (!$all_language) {
             $associations[$table->language] = (int) $table->id;
         }
         if (count($associations) > 1) {
             // Adding new association for these items
             $key = md5(json_encode($associations));
             $query->clear()->insert('#__associations');
             foreach ($associations as $id) {
                 $query->values((int) $id . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key));
             }
             $db->setQuery($query);
             try {
                 $db->execute();
             } catch (RuntimeException $e) {
                 $this->setError($e->getMessage());
                 return false;
             }
         }
     }
     // Clean the cache
     $this->cleanCache();
     if (isset($data['link'])) {
         $base = JUri::base();
         $juri = JUri::getInstance($base . $data['link']);
         $option = $juri->getVar('option');
         // Clean the cache
         parent::cleanCache($option);
     }
     return true;
 }
Exemplo n.º 27
0
 public function save($data)
 {
     $dispatcher = JEventDispatcher::getInstance();
     $table = $this->getTable();
     $context = $this->option . '.' . $this->name;
     if (!empty($data['tags']) && $data['tags'][0] != '') {
         $table->newTags = $data['tags'];
     }
     $key = $table->getKeyName();
     $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Include the plugins for the save events.
     JPluginHelper::importPlugin($this->events_map['save']);
     // Allow an exception to be thrown.
     try {
         // Load the row if saving an existing record.
         if ($pk > 0) {
             $table->load($pk);
             $isNew = false;
         }
         // Bind the data.
         if (!$table->bind($data)) {
             $this->setError($table->getError());
             return false;
         }
         // Prepare the row for saving
         $this->prepareTable($table);
         // Check the data.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Trigger the before save event.
         $result = $dispatcher->trigger($this->event_before_save, array($context, $table, $isNew));
         if (in_array(false, $result, true)) {
             $this->setError($table->getError());
             return false;
         }
         // Store the data.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
         // Clean the cache.
         $this->cleanCache();
         // Trigger the after save event.
         $dispatcher->trigger($this->event_after_save, array($context, $table, $isNew));
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     if (isset($table->{$key})) {
         $this->setState($this->getName() . '.id', $table->{$key});
     }
     $this->setState($this->getName() . '.new', $isNew);
     if ($this->associationsContext && JLanguageAssociations::isEnabled()) {
         $associations = $data['associations'];
         // Unset any invalid associations
         $associations = Joomla\Utilities\ArrayHelper::toInteger($associations);
         // Unset any invalid associations
         foreach ($associations as $tag => $id) {
             if (!$id) {
                 unset($associations[$tag]);
             }
         }
         // Show a notice if the item isn't assigned to a language but we have associations.
         if ($associations && $table->language == '*') {
             JFactory::getApplication()->enqueueMessage(JText::_(strtoupper($this->option) . '_ERROR_ALL_LANGUAGE_ASSOCIATED'), 'notice');
         }
         // Adding self to the association
         $associations[$table->language] = (int) $table->{$key};
         // Deleting old association for these items
         $db = $this->getDbo();
         $query = $db->getQuery(true)->delete($db->qn('#__associations'))->where($db->qn('context') . ' = ' . $db->quote($this->associationsContext))->where($db->qn('id') . ' IN (' . implode(',', $associations) . ')');
         $db->setQuery($query);
         $db->execute();
         if (count($associations) > 1 && $table->language != '*') {
             // Adding new association for these items
             $key = md5(json_encode($associations));
             $query = $db->getQuery(true)->insert('#__associations');
             foreach ($associations as $id) {
                 $query->values((int) $id . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key));
             }
             $db->setQuery($query);
             $db->execute();
         }
     }
     return true;
 }
Exemplo n.º 28
0
 /**
  * Delete tags based on URL id
  *
  * @param array $pks URLs ids
  */
 public function deleteByUrlId(&$pks)
 {
     $pks = Joomla\Utilities\ArrayHelper::toInteger($pks);
     if (!empty($pks)) {
         $db = $this->getDbo();
         /* @var $db JDatabaseDriver */
         $query = $db->getQuery(true);
         // Select the required fields from the table.
         $query->delete()->from($db->quoteName('#__itpm_tags'))->where($db->quoteName('url_id') . ' IN (' . implode(",", $pks) . ')');
         $db->setQuery($query);
         $db->execute();
     }
 }
Exemplo n.º 29
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  *
  * @since   1.6
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     // Select the required fields from the table.
     $query->select($db->quoteName(explode(', ', $this->getState('list.select', 'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid, a.user_id' . ', a.published, a.access, a.created, a.created_by, a.ordering, a.featured, a.language' . ', a.publish_up, a.publish_down'))));
     $query->from($db->quoteName('#__contact_details', 'a'));
     // Join over the users for the linked user.
     $query->select(array($db->quoteName('ul.name', 'linked_user'), $db->quoteName('ul.email')))->join('LEFT', $db->quoteName('#__users', 'ul') . ' ON ' . $db->quoteName('ul.id') . ' = ' . $db->quoteName('a.user_id'));
     // Join over the language
     $query->select($db->quoteName('l.title', 'language_title'))->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language'));
     // Join over the users for the checked out user.
     $query->select($db->quoteName('uc.name', 'editor'))->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'));
     // Join over the asset groups.
     $query->select($db->quoteName('ag.title', 'access_level'))->join('LEFT', $db->quoteName('#__viewlevels', 'ag') . ' ON ' . $db->quoteName('ag.id') . ' = ' . $db->quoteName('a.access'));
     // Join over the categories.
     $query->select($db->quoteName('c.title', 'category_title'))->join('LEFT', $db->quoteName('#__categories', 'c') . ' ON ' . $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid'));
     // Join over the associations.
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $query->select('COUNT(' . $db->quoteName('asso2.id') . ') > 1 as ' . $db->quoteName('association'))->join('LEFT', $db->quoteName('#__associations', 'asso') . ' ON ' . $db->quoteName('asso.id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('asso.context') . ' = ' . $db->quote('com_contact.item'))->join('LEFT', $db->quoteName('#__associations', 'asso2') . ' ON ' . $db->quoteName('asso2.key') . ' = ' . $db->quoteName('asso.key'))->group($db->quoteName(array('a.id', 'ul.name', 'l.title', 'uc.name', 'ag.title', 'c.title')));
     }
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $query->where($db->quoteName('a.access') . ' = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where($db->quoteName('a.access') . ' IN (' . $groups . ')');
     }
     // Filter by published state
     $published = $this->getState('filter.published');
     if (is_numeric($published)) {
         $query->where($db->quoteName('a.published') . ' = ' . (int) $published);
     } elseif ($published === '') {
         $query->where('(' . $db->quoteName('a.published') . ' = 0 OR ' . $db->quoteName('a.published') . ' = 1)');
     }
     // Filter by a single or group of categories.
     $categoryId = $this->getState('filter.category_id');
     if (is_numeric($categoryId)) {
         $query->where($db->quoteName('a.catid') . ' = ' . (int) $categoryId);
     } elseif (is_array($categoryId)) {
         $categoryId = Joomla\Utilities\ArrayHelper::toInteger($categoryId);
         $categoryId = implode(',', $categoryId);
         $query->where($db->quoteName('a.catid') . ' IN (' . $categoryId . ')');
     }
     // Filter by search in name.
     $search = $this->getState('filter.search');
     if (!empty($search)) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } elseif (stripos($search, 'author:') === 0) {
             $search = $db->quote('%' . $db->escape(substr($search, 7), true) . '%');
             $query->where('(' . $db->quoteName('uc.name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('uc.username') . ' LIKE ' . $search . ')');
         } else {
             $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
             $query->where('(' . $db->quoteName('a.name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('a.alias') . ' LIKE ' . $search . ')');
         }
     }
     // Filter on the language.
     if ($language = $this->getState('filter.language')) {
         $query->where($db->quoteName('a.language') . ' = ' . $db->quote($language));
     }
     // Filter by a single tag.
     $tagId = $this->getState('filter.tag');
     if (is_numeric($tagId)) {
         $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_contact.contact'));
     }
     // Add the list ordering clause.
     $orderCol = $this->state->get('list.ordering', 'a.name');
     $orderDirn = $this->state->get('list.direction', 'asc');
     if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
         $orderCol = $db->quoteName('c.title') . ' ' . $orderDirn . ', ' . $db->quoteName('a.ordering');
     }
     $query->order($db->escape($orderCol . ' ' . $orderDirn));
     return $query;
 }
Exemplo n.º 30
0
 public function doVoid()
 {
     // Get component parameters
     $params = JComponentHelper::getParams('com_crowdfunding');
     /** @var $params Joomla\Registry\Registry */
     // Check for disabled payment functionality
     if ($params->get('debug_payment_disabled', 0)) {
         throw new Exception(JText::_($this->text_prefix . '_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE'));
     }
     $cid = $this->input->get('cid', array(), 'array');
     $cid = Joomla\Utilities\ArrayHelper::toInteger($cid);
     $messages = array();
     try {
         if (count($cid) > 0) {
             $options = array('ids' => $cid, 'txn_status' => 'pending');
             $items = new Crowdfunding\Transactions(JFactory::getDbo());
             $items->load($options);
             if (count($items) === 0) {
                 throw new UnexpectedValueException(JText::_($this->text_prefix . '_ERROR_INVALID_TRANSACTIONS'));
             }
             // Import Crowdfunding Payment Plugins
             $dispatcher = JEventDispatcher::getInstance();
             JPluginHelper::importPlugin('crowdfundingpayment');
             foreach ($items as $item) {
                 $item = Joomla\Utilities\ArrayHelper::toObject($item);
                 $context = $this->option . '.payments.void.' . $item->service_alias;
                 // Trigger onContentPreparePayment event.
                 $results = $dispatcher->trigger('onPaymentsVoid', array($context, &$item, &$params));
                 foreach ($results as $message) {
                     if ($message !== null and is_array($message)) {
                         $messages[] = $message;
                     }
                 }
             }
         }
     } catch (UnexpectedValueException $e) {
         $this->setMessage($e->getMessage(), 'notice');
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=transactions', false));
         return;
     } catch (Exception $e) {
         // Store log data in the database
         $this->log->add(JText::_($this->text_prefix . '_ERROR_SYSTEM'), 'CONTROLLER_PAYMENTS_DOCAPTURE_ERROR', $e->getMessage());
         throw new Exception(JText::_($this->text_prefix . '_ERROR_SYSTEM'));
     }
     // Set messages.
     if (count($messages) > 0) {
         foreach ($messages as $message) {
             $this->app->enqueueMessage($message['text'], $message['type']);
         }
     }
     $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=transactions', false));
 }