PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_zoo/helpers/submission.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 117 lines | 50 code | 19 blank | 48 comment | 4 complexity | ceae536d2e8952614bf0ef7ae960af82 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * @package com_zoo
  4. * @author YOOtheme http://www.yootheme.com
  5. * @copyright Copyright (C) YOOtheme GmbH
  6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
  7. */
  8. /**
  9. * Helper class for submissions
  10. *
  11. * @package Component.Helpers
  12. * @since 2.0
  13. */
  14. class SubmissionHelper extends AppHelper {
  15. /**
  16. * Remove html from data
  17. *
  18. * @param Traversable|object|string $data
  19. *
  20. * @return Traversable|object|string the filtered data
  21. * @since 2.0
  22. */
  23. public function filterData($data) {
  24. if (is_array($data) || $data instanceof Traversable) {
  25. $result = array();
  26. foreach ($data as $key => $value) {
  27. $result[$key] = $this->filterData($value);
  28. }
  29. return $result;
  30. } elseif (is_object($data)) {
  31. $result = new stdClass();
  32. foreach (get_object_vars($data) as $key => $value) {
  33. $result->$key = $this->filterData($value);
  34. }
  35. return $result;
  36. } else {
  37. // remove all html tags or escape if in [code] tag
  38. $data = preg_replace_callback('/\[code\](.+?)\[\/code\]/is', create_function('$matches', 'return htmlspecialchars($matches[0]);'), $data);
  39. $data = strip_tags($data);
  40. return $data;
  41. }
  42. }
  43. /**
  44. * Retrieve hash of submission, type, item.
  45. *
  46. * @param int $submission_id
  47. * @param string $type_id
  48. * @param int $item_id
  49. *
  50. * @return string The resulting hash
  51. * @since 2.0
  52. */
  53. public function getSubmissionHash($submission_id, $type_id, $item_id = 0) {
  54. // get secret from config
  55. $secret = $this->app->system->config->getValue('config.secret');
  56. $item_id = empty($item_id) ? 0 : $item_id;
  57. return md5($submission_id.$type_id.$item_id.$secret);
  58. }
  59. /**
  60. * Send notification email
  61. *
  62. * @param Item $item Item
  63. * @param array $recipients Array email => name
  64. * @param string $layout The layout
  65. *
  66. * @since 2.0
  67. */
  68. public function sendNotificationMail($item, $recipients, $layout) {
  69. // workaround to make sure JSite is loaded
  70. $this->app->loader->register('JSite', 'root:includes/application.php');
  71. // init vars
  72. $website_name = $this->app->system->application->getCfg('sitename');
  73. $item_link = JURI::root().'administrator/index.php?'.http_build_query(array(
  74. 'option' => $this->app->component->self->name,
  75. 'controller' => 'item',
  76. 'task' => 'edit',
  77. 'cid[]' => $item->id,
  78. ), '', '&');
  79. // send email to $recipients
  80. foreach ($recipients as $email => $name) {
  81. if (empty($email)) {
  82. continue;
  83. }
  84. $mail = $this->app->mail->create();
  85. $mail->setSubject(JText::_("New Submission notification")." - ".$item->name);
  86. $mail->setBodyFromTemplate($item->getApplication()->getTemplate()->resource.$layout, compact(
  87. 'item', 'submission', 'website_name', 'email', 'name', 'item_link'
  88. ));
  89. $mail->addRecipient($email);
  90. $mail->Send();
  91. }
  92. }
  93. }
  94. /**
  95. * SubmissionHelperException identifies an Exception in the SubmissionHelper class
  96. * @see SubmissionHelper
  97. */
  98. class SubmissionHelperException extends AppException {}