File: MsgOutgoing.php

package info (click to toggle)
kalkun 0.8.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,340 kB
  • sloc: php: 30,659; javascript: 30,443; sql: 961; sh: 766; xml: 105; makefile: 41
file content (158 lines) | stat: -rw-r--r-- 3,652 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php

/**
 * Kalkun
 * An open source web based SMS Management
 *
 * @package		Kalkun
 * @author		Kalkun Dev Team
 * @license		https://spdx.org/licenses/GPL-2.0-or-later.html
 * @link		https://kalkun.sourceforge.io/
 */
// ------------------------------------------------------------------------

/**
 * MsgOutgoing Class
 *
 * @package		Kalkun
 * @subpackage	Plugin
 */
namespace Kalkun\Plugins\StopManager;
defined('BASEPATH') OR exit('No direct script access allowed');

class MsgOutgoing {

	const TYPE_NOT_SET = MsgIncoming::TYPE_NOT_SET;
	const IGNORE_STOP_MANAGER = MsgIncoming::IGNORE_STOP_MANAGER;

	private $party = NULL;
	private $cmd = NULL;
	private $type = NULL;
	private $origMsg = NULL;
	private $cleanedMsg = NULL;
	private $config = NULL;

	public function __construct(array $sms)
	{
		$this->origMsg = $sms[1]['message'];
		$this->party = $sms[0];
		$this->config = Config::getInstance();
		$this->parseOutgoingMessage();
	}

	public function getParty()
	{
		return $this->party;
	}

	public function getType()
	{
		return $this->type;
	}

	public function getOrigMsg()
	{
		return $this->origMsg;
	}

	public function getInsertDate()
	{
		return $this->insertDate;
	}

	public function setParty($party)
	{
		$this->party = $party;
	}

	public function getCmd()
	{
		return $this->cmd;
	}

	public function setCmd($cmd)
	{
		$this->cmd = strtoupper($cmd);
	}

	public function setType($type)
	{
		$this->type = ($this->config->isTypeEnabled()) ? strtolower($type) : self::TYPE_NOT_SET;
	}

	public function setOrigMsg($origMsg)
	{
		$this->origMsg = $origMsg;
	}

	public function getCleanedMsg()
	{
		return $this->cleanedMsg;
	}

	public function parseOutgoingMessage()
	{
		// Parse the outgoing message to find its Type
		// Be careful! Kalkun may append $config['append_username_message'] to all messages.
		$CI = &get_instance();
		$ret_match = NULL;
		if ($CI->config->item('append_username'))
		{
			$ret_match = preg_match('/^(.*)~(.+)~.*/', $this->origMsg, $matches);
		}
		else
		{
			$ret_match = preg_match('/^(.*)~(.+)~$/', $this->origMsg, $matches);
		}

		// Get the type of the SMS (rappel, annul...)
		if ($ret_match)
		{
			if ($this->config->isTypeEnabled()
				&& ( ! empty($matches[2]))
				&& in_array($matches[2], $this->config->getKeywordsType()))
			{
				$this->type = $matches[2];
			}


			$this->cleanedMsg = ( ! empty($matches[1])) ? trim($matches[1]) : $this->origMsg;
		}

		if (is_null($this->type))
		{
			// type of SMS (for filtering) is not set yet.
			// The message is sent    if we enabled  the use of type ($config['enable_type'])
			// The message is dropped if we disabled the use of type ($config['enable_type']) and if it is in blacklist
			if ( ! $this->config->isTypeEnabled())
			{
				// Will drop all numbers that are in stop_manager whatever the value of type
				//$type = "%";
				// Will drop all numbers that are in stop_manager having been recorded as TYPE_NOT_SET_SO_STOP_ALL
				$this->type = MsgIncoming::TYPE_NOT_SET;
			}
			else
			{
				// IGNORE_STOP_MANAGER is just a fake value that should never match something in the table,
				// this is to keep the message
				$this->type = MsgIncoming::IGNORE_STOP_MANAGER;
			}
		}

		// Build the cleaned message = Message without the "tag" to identify the
		// type of the outgoing message.
		// eg. "~rappel~" at the end of the message
		if ($ret_match
			&& ( ! empty($matches[1]))
			&& $this->config->isTypeEnabled()
			&& ( ! empty($matches[2]))
			&& in_array($matches[2], $this->config->getKeywordsType()))
		{
			$this->cleanedMsg = trim($matches[1]);
		}
		else
		{
			$this->cleanedMsg = $this->origMsg;
		}
	}
}