PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / conditionalrules / attach_file.php

attach_file.php in VikBooking Hotel Booking Engine & PMS 1.8.6, at admin/helpers/conditionalrules/attach_file.php

145 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Class handler for conditional rule "attach file".
15 *
16 * @since 1.4.0
17 */
18 class VikBookingConditionalRuleAttachFile extends VikBookingConditionalRule
19 {
20 /**
21 * Class constructor will define the rule name, description and identifier.
22 */
23 public function __construct()
24 {
25 // call parent constructor
26 parent::__construct();
27
28 $this->ruleName = JText::translate('VBO_CONDTEXT_RULE_ATTFILES');
29 $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_ATTFILES_DESCR');
30 $this->ruleId = basename(__FILE__);
31 }
32
33 /**
34 * Displays the rule parameters.
35 *
36 * @return void
37 */
38 public function renderParams()
39 {
40 $serv_base_path = $this->getServerBasePath(true);
41 ?>
42 <div class="vbo-param-container">
43 <div class="vbo-param-label"><?php echo JText::translate('VBO_FILE_FROM_MEDIAMNG'); ?></div>
44 <div class="vbo-param-setting">
45 <?php echo $this->vbo_app->getMediaField($this->inputName('attachment'), $this->getParam('attachment')); ?>
46 </div>
47 </div>
48 <div class="vbo-param-container">
49 <div class="vbo-param-label"><?php echo JText::translate('VBO_FILE_FROM_LOCALDIR'); ?></div>
50 <div class="vbo-param-setting">
51 <input type="text" name="<?php echo $this->inputName('attachment_local'); ?>" value="<?php echo $this->getParam('attachment_local', ''); ?>" />
52 <span class="vbo-param-setting-comment"><?php echo JText::sprintf('VBO_FILE_FROM_LOCALDIR_HELP', $serv_base_path); ?></span>
53 </div>
54 </div>
55 <?php
56 }
57
58 /**
59 * Tells whether the rule is compliant.
60 *
61 * @return bool True on success, false otherwise.
62 */
63 public function isCompliant()
64 {
65 // this is not a real filter-rule, so we always return true
66 return true;
67 }
68
69 /**
70 * Override callback action method to add an attachment.
71 *
72 * @return void
73 */
74 public function callbackAction()
75 {
76 /**
77 * DO NOT use `getServerBasePath()` because on WordPress it would
78 * repeat /wp-content/uploads/. In this case it is correct to
79 * directly use ABSPATH.
80 *
81 * @since 1.5
82 */
83 // $serv_base_path = $this->getServerBasePath();
84 if (VBOPlatformDetection::isWordPress())
85 {
86 $serv_base_path = ABSPATH;
87 }
88 else
89 {
90 $serv_base_path = JPATH_SITE;
91 }
92
93 $serv_base_path = rtrim($serv_base_path, DIRECTORY_SEPARATOR);
94
95 $attachment = $this->getParam('attachment', '');
96
97 if (!empty($attachment)) {
98 // make sure to convert it to a proper full path
99 if (strpos($attachment, $serv_base_path) === false && !is_file($attachment)) {
100 // relative path obtained from the media manager
101 if (substr($attachment, 0, 1) == DIRECTORY_SEPARATOR) {
102 $attachment = substr($attachment, 1);
103 }
104 $attachment = $serv_base_path . DIRECTORY_SEPARATOR . $attachment;
105 }
106 // register a file attachment
107 VikBooking::addEmailAttachment($attachment);
108 }
109
110 $attachment_local = $this->getParam('attachment_local', '');
111
112 if (!empty($attachment_local) && $attachment_local != $serv_base_path) {
113 // register a file attachment
114 VikBooking::addEmailAttachment($attachment_local);
115 }
116
117 return;
118 }
119
120 /**
121 * Internal function for this rule only.
122 *
123 * @param bool $trailing whether to add a trailing directory separator.
124 *
125 * @return string
126 */
127 protected function getServerBasePath($trailing = false)
128 {
129 $base = '';
130 if (defined('JPATH_SITE')) {
131 $base = JPATH_SITE;
132 } elseif (function_exists('wp_upload_dir')) {
133 $updir = wp_upload_dir();
134 $base = $updir['basedir'];
135 }
136
137 if ($trailing) {
138 $base .= DIRECTORY_SEPARATOR;
139 }
140
141 return $base;
142 }
143
144 }
145