PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Classes/UrlClass.php +53 -29 10.2.2 → 11.1.0 View file →
@@ -13,11 +13,13 @@
13 13 $this->table = 'url';
14 14 $this->pkey = 'id';
15 15 }
16 16
17 - public function save($url)
17 + public function save(object $url): ?int
18 18 {
19 - if (empty($url)) return false;
19 + if (empty($url)) {
20 + return null;
21 + }
20 22
21 23 foreach ($url as $oneAttribute => $value) {
22 24 if (empty($value)) {
23 25 continue;
@@ -22,45 +24,27 @@
22 24 if (empty($value)) {
23 25 continue;
24 26 }
25 27
26 - $url->$oneAttribute = strip_tags($value);
28 + $url->$oneAttribute = acym_stripTags($value);
27 29 }
28 30
29 31 return parent::save($url);
30 32 }
31 33
32 - public function getOneUrlById($id)
34 + public function getOneUrlById(int $id): ?object
33 35 {
34 - return acym_loadObject('SELECT * FROM #__acym_url WHERE `id` = '.intval($id));
35 - }
36 + $url = acym_loadObject('SELECT * FROM #__acym_url WHERE `id` = '.intval($id));
36 37
37 - public function getOneByUrl($url)
38 - {
39 - return acym_loadObject('SELECT * FROM #__acym_url WHERE `url` = '.acym_escapeDB($url));
38 + return empty($url) ? null : $url;
40 39 }
41 40
42 - public function getAdd($url)
41 + public function getUrl(string $url, int $mailid, int $userid, string $userkey = ''): string
43 42 {
44 - $currentUrl = $this->getOneByUrl($url);
45 - if (empty($currentUrl->id)) {
46 - $currentUrl = new \stdClass();
47 - $currentUrl->name = $url;
48 - $currentUrl->url = $url;
49 - $currentUrl->id = $this->save($currentUrl);
50 -
51 - if (empty($currentUrl->id)) {
52 - return null;
53 - }
43 + if (empty($url) || empty($mailid) || empty($userid)) {
44 + return '';
54 45 }
55 46
56 - return $currentUrl;
57 - }
58 -
59 - public function getUrl($url, $mailid, $userid)
60 - {
61 - if (empty($url) || empty($mailid) || empty($userid)) return '';
62 -
63 47 static $allurls;
64 48
65 49 $url = str_replace('&', '&', $url);
66 50
@@ -71,12 +55,19 @@
71 55 if (empty($allurls[$url]->id)) {
72 56 return $url;
73 57 }
74 58
75 - return acym_frontendLink('fronturl&task=click&urlid='.$allurls[$url]->id.'&userid='.$userid.'&mailid='.$mailid);
59 + $trackingUrl = acym_frontendLink('fronturl&task=click&urlid='.$allurls[$url]->id.'&userid='.$userid.'&mailid='.$mailid);
60 +
61 + if (!empty($userkey)) {
62 + $trackingUrl .= (strpos($trackingUrl, '?') === false ? '?' : '&').'userkey='.urlencode($userkey);
63 + }
64 +
65 + return $trackingUrl;
76 66 }
77 67
78 - public function getDuplicatedUrls()
68 + // Used in checkDB to address a bug before the 12/04/19
69 + public function getDuplicatedUrls(): array
79 70 {
80 71 return acym_loadResultArray(
81 72 'SELECT DISTINCT duplicates.id
82 73 FROM #__acym_url AS duplicates
@@ -85,6 +76,39 @@
85 76 LEFT JOIN #__acym_url_click AS click ON duplicates.id = click.url_id
86 77 WHERE click.url_id IS NULL
87 78 LIMIT 500'
88 79 );
80 + /*
81 + To clean the potential duplicated rows in the #__acym_url table, you can execute this query when no email is being sent:
82 + DELETE url.*
83 + FROM #__acym_url AS url
84 + LEFT JOIN #__acym_url_click AS urlclick ON url.id = urlclick.url_id
85 + WHERE urlclick.url_id IS NULL
86 +
87 + If an email is currently being sent, exclude its urls from the delete query
88 + */
89 + }
90 +
91 + private function getAdd(string $url): ?object
92 + {
93 + $currentUrl = $this->getOneByUrl($url);
94 + if (empty($currentUrl->id)) {
95 + $currentUrl = new \stdClass();
96 + $currentUrl->name = $url;
97 + $currentUrl->url = $url;
98 + $currentUrl->id = $this->save($currentUrl);
99 +
100 + if (empty($currentUrl->id)) {
101 + return null;
102 + }
103 + }
104 +
105 + return $currentUrl;
106 + }
107 +
108 + private function getOneByUrl(string $url): ?object
109 + {
110 + $url = acym_loadObject('SELECT * FROM #__acym_url WHERE `url` = '.acym_escapeDB($url));
111 +
112 + return empty($url) ? null : $url;
89 113 }
90 114 }