Skip to content

Commit cb0211a

Browse files
authored
Merge pull request #14 from AleksanderKoko/master
fixed String problem on PHP7
2 parents 988f63a + cb9b9b9 commit cb0211a

File tree

10 files changed

+53
-23
lines changed

10 files changed

+53
-23
lines changed

core/Admin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace phpList;
33

4-
use phpList\helper\String;
4+
use phpList\helper\StringClass;
55
use phpList\helper\Util;
66
use phpList\Entity\AdminEntity;
77

@@ -23,7 +23,7 @@ public function __construct( $adminModel, $pass )
2323
*/
2424
public function setLoginname($loginname)
2525
{
26-
$this->loginname = strtolower(String::normalize($loginname));
26+
$this->loginname = strtolower(StringClass::normalize($loginname));
2727
return $this->isLoginUnique();
2828
}
2929

@@ -34,7 +34,7 @@ public function setLoginname($loginname)
3434
*/
3535
public function setNamelc($namelc)
3636
{
37-
$this->namelc = strtolower(String::normalize($namelc));
37+
$this->namelc = strtolower(StringClass::normalize($namelc));
3838
}
3939

4040
public $email;
@@ -105,7 +105,7 @@ public static function getAdmins($search = '')
105105
$admins = array();
106106
$condition = '';
107107
if ($search != '') {
108-
$search = String::sqlEscape($search);
108+
$search = StringClass::sqlEscape($search);
109109
$condition = sprintf(' WHERE loginname LIKE "%%%s%%" OR email LIKE "%%%s%%"', $search, $search);
110110
}
111111

@@ -159,7 +159,7 @@ public function save()
159159
*/
160160
public function update($modifiedby)
161161
{
162-
$privileges = String::sqlEscape(serialize($this->privileges));
162+
$privileges = StringClass::sqlEscape(serialize($this->privileges));
163163
phpList::DB()->query(
164164
sprintf(
165165
'UPDATE %s SET

core/Campaign.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Exception;
55
use phpList\Entity\CampaignEntity;
66
use phpList\Entity\MailingListEntity;
7-
use phpList\helper\String;
7+
use phpList\helper\StringClass;
88
use phpList\helper\Util;
99

1010
class Campaign
@@ -123,7 +123,7 @@ public function getCampaignsBy($status, $subject = '', $owner = 0, $order = '',
123123
$condition .= ') ';
124124

125125
if ($subject != '') {
126-
$condition .= ' AND subject LIKE "%' . String::sqlEscape($subject) . '%" ';
126+
$condition .= ' AND subject LIKE "%' . StringClass::sqlEscape($subject) . '%" ';
127127
}
128128
if ($owner != 0) {
129129
$condition .= sprintf(' AND owner = %d', $owner);

core/Model/AdminModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace phpList\Model;
33

44
use phpList\Entity\SubscriberEntity;
5-
use phpList\helper\String;
5+
use phpList\helper\StringClass;
66

77
class AdminModel {
88

core/Model/ListModel.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace phpList\Model;
33

44
use phpList\Entity\SubscriberEntity;
5-
use phpList\helper\String;
5+
use phpList\helper\StringClass;
66

77
class ListModel {
88

@@ -21,6 +21,14 @@ public function __construct( \phplist\Config $config, \phplist\helper\Database $
2121
*/
2222
public function addSubscriber( $subscriberId, $listId )
2323
{
24+
25+
$lists = $this->getListsForSubscriber((int) $subscriberId);
26+
foreach ($lists as $list){
27+
if((int) $list["id"] === (int) $listId){
28+
throw new \Exception("Subscriber is already subscribed on that list");
29+
}
30+
}
31+
2432
$result = $this->db->query(
2533
sprintf(
2634
'INSERT INTO
@@ -202,7 +210,7 @@ public function getListsForSubscriber( $subscriber_id )
202210
, $subscriber_id
203211
)
204212
);
205-
return $this->makeLists( $result );
213+
return $result->fetchAll( \PDO::FETCH_ASSOC );
206214
}
207215

208216
/**

core/Model/SubscriberModel.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace phpList\Model;
33

44
use phpList\Entity\SubscriberEntity;
5-
use phpList\helper\String;
5+
use phpList\helper\StringClass;
66

77
class SubscriberModel {
88

@@ -115,6 +115,19 @@ public function getSubscriberById( $id )
115115
return $result->fetch( \PDO::FETCH_ASSOC );
116116
}
117117

118+
public function getSubscriberByEmail( $emailAddress )
119+
{
120+
$result = $this->db->query(
121+
sprintf(
122+
"SELECT * FROM %s
123+
WHERE email = '%s'",
124+
$this->config->getTableName( 'user', true ),
125+
$emailAddress
126+
)
127+
);
128+
return $result->fetch( \PDO::FETCH_ASSOC );
129+
}
130+
118131
/**
119132
* Cleanly delete all records of a subscriber from DB
120133
* @param int $id ID of subscriber to delete

core/SubscriberManager.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use phpList\Subscriber;
55
use phpList\Entity\SubscriberEntity;
6-
use phpList\helper\String;
6+
use phpList\helper\StringClass;
77

88
class SubscriberManager
99
{
@@ -135,6 +135,10 @@ public function add( \phpList\Entity\SubscriberEntity $scrEntity )
135135
throw new \Exception( 'Cannot insert subscriber with invalid email address: "' . $scrEntity->emailAddress . '"' );
136136
}
137137

138+
$entity = $this->subscriberModel->getSubscriberByEmail($scrEntity->emailAddress);
139+
if($entity["email"] !== null)
140+
throw new \Exception("Subscriber with that email already exists");
141+
138142
// Save subscriber to db
139143
$newSubscriberId = $this->subscriberModel->save(
140144
$scrEntity->emailAddress
@@ -177,6 +181,11 @@ public function update( SubscriberEntity $subscriber )
177181
*/
178182
public function delete( $id )
179183
{
184+
185+
$subscriber = $this->subscriberModel->getSubscriberById($id);
186+
if(!$subscriber)
187+
throw new \Exception("Subscriber doesn't exists");
188+
180189
$results = $this->subscriberModel->delete( $id );
181190

182191
// TODO: Add a check of $results to ensure delete was successful before
@@ -290,7 +299,7 @@ public function getCleanAttributes(SubscriberEntity $scrEntity)
290299
foreach ($scrEntity->getAttributes() as $key => $val) {
291300
## in the help, we only list attributes with "strlen < 20"
292301
if (strlen($key) < 20) {
293-
$clean_attributes[String::cleanAttributeName($key)] = $val;
302+
$clean_attributes[StringClass::cleanAttributeName($key)] = $val;
294303
}
295304
}
296305
return $clean_attributes;

core/helper/PrepareCampaign.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public static function sendEmail(
276276

277277
if ($cached_campaign->htmlformatted) {
278278
if (empty($cached_campaign->textcontent)) {
279-
$textcontent = String::HTML2Text($content);
279+
$textcontent = StringClass::HTML2Text($content);
280280
} else {
281281
$textcontent = $cached_campaign->textcontent;
282282
}
@@ -1584,7 +1584,7 @@ public static function precacheCampaign($campaign, $forwardContent = false)
15841584
$cached_campaign->footer = $forwardContent ? stripslashes($campaign->forwardfooter) : $campaign->footer;
15851585

15861586
if (strip_tags($cached_campaign->footer) != $cached_campaign->footer) {
1587-
$cached_campaign->textfooter = String::HTML2Text($cached_campaign->footer);
1587+
$cached_campaign->textfooter = StringClass::HTML2Text($cached_campaign->footer);
15881588
$cached_campaign->htmlfooter = $cached_campaign->footer;
15891589
} else {
15901590
$cached_campaign->textfooter = $cached_campaign->footer;
@@ -1644,7 +1644,7 @@ public static function precacheCampaign($campaign, $forwardContent = false)
16441644

16451645

16461646
/*if ($cached_campaign->htmlformatted) {
1647-
# $cached->content = String::compressContent($cached->content);
1647+
# $cached->content = StringClass::compressContent($cached->content);
16481648
}*/
16491649

16501650
//$cached_campaign->google_track = $campaign->google_track;

core/helper/String.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Class containing string helper functions
99
* @package phpList
1010
*/
11-
class String
11+
class StringClass
1212
{
1313
/**
1414
* Normalize text
@@ -121,7 +121,7 @@ public static function HTML2Text($text)
121121
500
122122
);
123123

124-
$text = String::replaceChars($text);
124+
$text = StringClass::replaceChars($text);
125125

126126
$text = preg_replace("/###NL###/", "\n", $text);
127127
$text = preg_replace("/\n /", "\n", $text);

core/helper/Util.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,15 @@ public function blacklistEmail($email_address, $reason = '', $date = '')
610610
} else {
611611
$sqldate = '"' . $date . '"';
612612
}
613-
$email_address = String::sqlEscape($email_address);
613+
$email_address = StringClass::sqlEscape($email_address);
614614

615615
#0012262: blacklist only email when email bounces. (not subscribers): Function split so email can be blacklisted without blacklisting subscriber
616616
$this->db->query(
617617
sprintf(
618618
'INSERT IGNORE INTO %s (email,added)
619619
VALUES("%s",%s)',
620620
$this->config->getTableName('user_blacklist'),
621-
String::sqlEscape($email_address),
621+
StringClass::sqlEscape($email_address),
622622
$sqldate
623623
)
624624
);
@@ -726,7 +726,7 @@ public function parseEmailAndName($string, $default_address)
726726

727727
return [
728728
'email' => $email_address,
729-
'name' => String::removeDoubleSpaces(trim($name))
729+
'name' => StringClass::removeDoubleSpaces(trim($name))
730730
];
731731
}
732732

core/phpListMailer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace phpList;
33

4-
use phpList\helper\String;
4+
use phpList\helper\StringClass;
55
use phpList\helper\Util;
66
use PHPMailer;
77

@@ -685,7 +685,7 @@ public static function constructSystemMail($message, $subject = '')
685685

686686
if ($hasHTML) {
687687
$message = stripslashes($message);
688-
$textmessage = String::HTML2Text($message);
688+
$textmessage = StringClass::HTML2Text($message);
689689
$htmlmessage = $message;
690690
} else {
691691
$textmessage = $message;

0 commit comments

Comments
 (0)