/administrator/components/com_zoo/helpers/submission.php
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
- <?php
- /**
- * @package com_zoo
- * @author YOOtheme http://www.yootheme.com
- * @copyright Copyright (C) YOOtheme GmbH
- * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
- */
-
- /**
- * Helper class for submissions
- *
- * @package Component.Helpers
- * @since 2.0
- */
- class SubmissionHelper extends AppHelper {
-
- /**
- * Remove html from data
- *
- * @param Traversable|object|string $data
- *
- * @return Traversable|object|string the filtered data
- * @since 2.0
- */
- public function filterData($data) {
-
- if (is_array($data) || $data instanceof Traversable) {
-
- $result = array();
- foreach ($data as $key => $value) {
- $result[$key] = $this->filterData($value);
- }
- return $result;
- } elseif (is_object($data)) {
-
- $result = new stdClass();
- foreach (get_object_vars($data) as $key => $value) {
- $result->$key = $this->filterData($value);
- }
- return $result;
- } else {
-
- // remove all html tags or escape if in [code] tag
- $data = preg_replace_callback('/\[code\](.+?)\[\/code\]/is', create_function('$matches', 'return htmlspecialchars($matches[0]);'), $data);
- $data = strip_tags($data);
-
- return $data;
- }
- }
-
- /**
- * Retrieve hash of submission, type, item.
- *
- * @param int $submission_id
- * @param string $type_id
- * @param int $item_id
- *
- * @return string The resulting hash
- * @since 2.0
- */
- public function getSubmissionHash($submission_id, $type_id, $item_id = 0) {
-
- // get secret from config
- $secret = $this->app->system->config->getValue('config.secret');
-
- $item_id = empty($item_id) ? 0 : $item_id;
-
- return md5($submission_id.$type_id.$item_id.$secret);
- }
-
- /**
- * Send notification email
- *
- * @param Item $item Item
- * @param array $recipients Array email => name
- * @param string $layout The layout
- *
- * @since 2.0
- */
- public function sendNotificationMail($item, $recipients, $layout) {
-
- // workaround to make sure JSite is loaded
- $this->app->loader->register('JSite', 'root:includes/application.php');
-
- // init vars
- $website_name = $this->app->system->application->getCfg('sitename');
- $item_link = JURI::root().'administrator/index.php?'.http_build_query(array(
- 'option' => $this->app->component->self->name,
- 'controller' => 'item',
- 'task' => 'edit',
- 'cid[]' => $item->id,
- ), '', '&');
-
- // send email to $recipients
- foreach ($recipients as $email => $name) {
-
- if (empty($email)) {
- continue;
- }
-
- $mail = $this->app->mail->create();
- $mail->setSubject(JText::_("New Submission notification")." - ".$item->name);
- $mail->setBodyFromTemplate($item->getApplication()->getTemplate()->resource.$layout, compact(
- 'item', 'submission', 'website_name', 'email', 'name', 'item_link'
- ));
- $mail->addRecipient($email);
- $mail->Send();
- }
- }
-
- }
-
- /**
- * SubmissionHelperException identifies an Exception in the SubmissionHelper class
- * @see SubmissionHelper
- */
- class SubmissionHelperException extends AppException {}