Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
6cf9c6f7
Commit
6cf9c6f7
authored
Feb 04, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.task-on.com:ktask/task-on.com
parents
bbf4a49c
49c0dbb4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
241 additions
and
5 deletions
+241
-5
common/components/UnisenderAPI.php
common/components/UnisenderAPI.php
+230
-0
common/modules/triggers/views/trigger-admin/testing.php
common/modules/triggers/views/trigger-admin/testing.php
+10
-5
console/migrations/m160204_115214_add_schedule_table.php
console/migrations/m160204_115214_add_schedule_table.php
+1
-0
No files found.
common/components/UnisenderAPI.php
0 → 100644
View file @
6cf9c6f7
<?php
/**
* API UniSender
*
* @see http://www.unisender.com/ru/help/api/
* @version 1.3
*/
class
UnisenderAPI
{
/**
* @var string
*/
protected
$ApiKey
;
/**
* @var string
*/
protected
$Encoding
=
'UTF8'
;
/**
* @var int
*/
protected
$RetryCount
=
0
;
/**
* @var float
*/
protected
$Timeout
;
/**
* @var bool
*/
protected
$Compression
=
false
;
/**
* @param string $ApiKey
* @param string $Encoding
* @param int $RetryCount
* @param null $Timeout
* @param bool $Compression
*/
function
__construct
(
$ApiKey
=
'5p7mt1be5x6axqniwu937gqohj9k9hn7gbex1efo'
,
$Encoding
=
'UTF8'
,
$RetryCount
=
4
,
$Timeout
=
null
,
$Compression
=
false
)
{
$this
->
ApiKey
=
$ApiKey
;
if
(
!
empty
(
$Encoding
))
{
$this
->
Encoding
=
$Encoding
;
}
if
(
!
empty
(
$RetryCount
))
{
$this
->
RetryCount
=
$RetryCount
;
}
if
(
!
empty
(
$Timeout
))
{
$this
->
Timeout
=
$Timeout
;
}
if
(
$Compression
)
{
$this
->
Compression
=
$Compression
;
}
}
/**
* @param string $Name
* @param array $Arguments
* @return string
*/
function
__call
(
$Name
,
$Arguments
)
{
if
(
!
is_array
(
$Arguments
)
||
empty
(
$Arguments
))
{
$Params
=
array
();
}
else
{
$Params
=
$Arguments
[
0
];
}
return
$this
->
callMethod
(
$Name
,
$Params
);
}
public
function
createList
(
$title
=
null
){
if
(
$title
===
null
)
{
$date
=
new
DateTime
;
$title
=
$date
->
format
(
'YmdHis'
)
.
(
rand
(
100000
,
999999
));
}
return
$this
->
callMethod
(
'createList'
,
[
'title'
=>
$title
]
);
}
public
function
createCampaign
(
$message_id
){
return
$this
->
callMethod
(
'createCampaign'
,
[
'message_id'
=>
$message_id
]
);
}
public
function
createEmailMessage
(
$sender_name
,
$sender_email
,
$subject
,
$body
,
$list_id
){
return
$this
->
callMethod
(
'createEmailMessage'
,
[
'sender_name'
=>
$sender_name
,
'sender_email'
=>
$sender_email
,
'subject'
=>
$subject
,
'body'
=>
$body
,
'list_id'
=>
$list_id
]
);
}
/**
* @param array $Params
* @return string
*/
function
subscribe
(
$Params
)
{
$Params
=
(
array
)
$Params
;
if
(
empty
(
$Params
[
'request_ip'
]))
{
$Params
[
'request_ip'
]
=
$this
->
getClientIp
();
}
return
$this
->
callMethod
(
'subscribe'
,
$Params
);
}
/**
* @param string $JSON
* @return mixed
*/
protected
function
decodeJSON
(
$JSON
)
{
return
json_decode
(
$JSON
);
}
/**
* @return string
*/
protected
function
getClientIp
()
{
$Result
=
''
;
if
(
!
empty
(
$_SERVER
[
"REMOTE_ADDR"
]))
{
$Result
=
$_SERVER
[
"REMOTE_ADDR"
];
}
else
if
(
!
empty
(
$_SERVER
[
"HTTP_X_FORWARDED_FOR"
]))
{
$Result
=
$_SERVER
[
"HTTP_X_FORWARDED_FOR"
];
}
else
if
(
!
empty
(
$_SERVER
[
"HTTP_CLIENT_IP"
]))
{
$Result
=
$_SERVER
[
"HTTP_CLIENT_IP"
];
}
if
(
preg_match
(
'/([0-9]|[0-9][0-9]|[01][0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[0-9][0-9]|[01][0-9][0-9]|2[0-4][0-9]|25[0-5])){3}/'
,
$Result
,
$Match
))
{
return
$Match
[
0
];
}
return
$Result
;
}
/**
* @param string $Value
* @param string $Key
*/
protected
function
iconv
(
&
$Value
,
$Key
)
{
$Value
=
iconv
(
$this
->
Encoding
,
'UTF8//IGNORE'
,
$Value
);
}
/**
* @param string $Value
* @param string $Key
*/
protected
function
mb_convert_encoding
(
&
$Value
,
$Key
)
{
$Value
=
mb_convert_encoding
(
$Value
,
'UTF8'
,
$this
->
Encoding
);
}
/**
* @param string $MethodName
* @param array $Params
* @return array
*/
protected
function
callMethod
(
$MethodName
,
$Params
=
array
())
{
if
(
$this
->
Encoding
!=
'UTF8'
)
{
if
(
function_exists
(
'iconv'
))
{
array_walk_recursive
(
$Params
,
array
(
$this
,
'iconv'
));
}
else
if
(
function_exists
(
'mb_convert_encoding'
))
{
array_walk_recursive
(
$Params
,
array
(
$this
,
'mb_convert_encoding'
));
}
}
$Url
=
$MethodName
.
'?format=json'
;
if
(
$this
->
Compression
)
{
$Url
.=
'&api_key='
.
$this
->
ApiKey
.
'&request_compression=bzip2'
;
$Content
=
bzcompress
(
http_build_query
(
$Params
));
}
else
{
$Params
=
array_merge
((
array
)
$Params
,
array
(
'api_key'
=>
$this
->
ApiKey
));
$Content
=
http_build_query
(
$Params
);
}
$ContextOptions
=
array
(
'http'
=>
array
(
'method'
=>
'POST'
,
'header'
=>
'Content-type: application/x-www-form-urlencoded'
,
'content'
=>
$Content
,
)
);
if
(
$this
->
Timeout
)
{
$ContextOptions
[
'http'
][
'timeout'
]
=
$this
->
Timeout
;
}
$RetryCount
=
0
;
$Context
=
stream_context_create
(
$ContextOptions
);
do
{
$Host
=
$this
->
getApiHost
(
$RetryCount
);
$Result
=
file_get_contents
(
$Host
.
$Url
,
false
,
$Context
);
$RetryCount
++
;
}
while
(
$Result
===
false
&&
$RetryCount
<
$this
->
RetryCount
);
return
$Result
;
}
/**
* @param int $RetryCount
* @return string
*/
protected
function
getApiHost
(
$RetryCount
=
0
)
{
if
(
$RetryCount
%
2
==
0
)
{
return
'http://api.unisender.com/ru/api/'
;
}
else
{
return
'http://www.api.unisender.com/ru/api/'
;
}
}
}
\ No newline at end of file
common/modules/triggers/views/trigger-admin/testing.php
View file @
6cf9c6f7
<?php
use
\common\modules\triggers\components\conditions\Conditions
;
$q
=
Conditions
::
init
()
->
getConditionById
(
2
);
var_dump
(
$q
->
params
);
\ No newline at end of file
$email
=
'bystrov@kupitsite.ru'
;
$sender
=
new
UnisenderAPI
();
// Create the send list
$newListId
=
$sender
->
createList
();
// Subscribe user to new List
$sender
->
subscribe
([
'list_ids'
=>
$newListId
,
'fields'
=>
[
'email'
=>
$email
]]);
// Create new message
$newMessageId
=
$sender
->
createEmailMessage
(
'bystrov'
,
$email
,
'Testing Subject'
,
'Testing Body'
,
$newListId
);
// Create new campaign
$newCampaign
=
$sender
->
createCampaign
(
$newMessageId
);
console/migrations/m160204_115214_add_schedule_table.php
View file @
6cf9c6f7
...
...
@@ -14,6 +14,7 @@ class m160204_115214_add_schedule_table extends Migration
'id'
=>
Schema
::
TYPE_PK
,
'sended'
=>
Schema
::
TYPE_BOOLEAN
.
' DEFAULT 0 NOT NULL'
,
'checked'
=>
Schema
::
TYPE_BOOLEAN
.
' DEFAULT 0 NOT NULL'
,
'message_id'
=>
Schema
::
TYPE_INTEGER
.
' DEFAULT NULL'
,
'message'
=>
Schema
::
TYPE_TEXT
.
' NOT NULL'
,
'email'
=>
Schema
::
TYPE_STRING
.
' NOT NULL'
,
'time'
=>
Schema
::
TYPE_DATETIME
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment