-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Comment', | ||
'image' => 'assets/plugins/pagebuilder/images/text.jpg', | ||
'container' => 'comments', | ||
'templates' => [ | ||
'owner' => ' | ||
<div class="card mb-2"> | ||
<div class="card-header"> | ||
<b>[+name+]</b> <small class="text-muted">on [+date+]</small> | ||
</div> | ||
<div class="card-body"> | ||
[+comment+] | ||
[[if? &is=`[+answer+]|not_empty` &separator=`|` &then=`<blockquote class="mt-3 mb-0"><h6 class="text-muted">Admin reply</h6>[+answer+]</blockquote>`]] | ||
</div> | ||
</div> | ||
', | ||
], | ||
|
||
'fields' => [ | ||
'name'=>[ | ||
'caption'=>'Name', | ||
'type'=>'text' | ||
], | ||
'phoneoremail'=>[ | ||
'caption'=>'Phone or e-mail', | ||
'type'=>'text' | ||
], | ||
'comment'=>[ | ||
'caption'=>'Comment', | ||
'type'=>'textarea' | ||
], | ||
'ip' => [ | ||
'caption'=>'IP Adress', | ||
'type'=>'text' | ||
], | ||
'date' => [ | ||
'caption'=>'Date added', | ||
'type'=>'date' | ||
], | ||
'answer'=>[ | ||
'caption'=>'Answer', | ||
'type'=>'textarea' | ||
] | ||
], | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
return [ | ||
'title' => 'Comments', | ||
'placement' => 'tv', | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* pb_commentsform | ||
* | ||
* Comments form | ||
* | ||
* @category chunk | ||
* @internal @modx_category Comments | ||
* @internal @installset base | ||
* @internal @overwrite true | ||
*/ | ||
[!FormLister? | ||
&formTpl=`@CODE:<form action="[~[*id*]~]" class="mb-5" method="post"> | ||
<h3>Add comment</h3> | ||
<div class="form-group"> | ||
<label for="name">Your name *</label> | ||
<input type="text" class="form-control [+name.errorClass+]" id="name" name="name" required="required"> | ||
[+name.error+] | ||
</div> | ||
<div class="form-group"> | ||
<label for="phoneoremail">Your phone or e-mail *</label> | ||
<input type="text" class="form-control [+phoneoremail.errorClass+]" id="phoneoremail" name="phoneoremail" aria-describedby="emailHelp" required="required"> | ||
[+phoneoremail.error+] | ||
<small id="emailHelp" class="form-text text-muted">We'll never share your email or phone with anyone else.</small> | ||
</div> | ||
<div class="form-group"> | ||
<label for="comment">Share your thoughts *</label> | ||
<textarea class="form-control [+comment.errorClass+]" id="comment" name="comment" cols="30" rows="5" required="required">[+comment.value+]</textarea> | ||
[+comment.error+] | ||
</div> | ||
<div class="form-group form-check"> | ||
<input type="checkbox" class="form-check-input" id="sogl" name="sogl" checked="checked"> | ||
<label class="form-check-label" for="sogl">I agree with privacy policy</label> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
<input type="hidden" name="formid" value="commentform"> | ||
<input type="hidden" name="link" value="[(site_url)][~[*id*]~]"> | ||
</form> | ||
` | ||
&subject=`Comment on the: [(site_name)] - [*pagetitle*]` | ||
&protectSubmit=`0` | ||
&submitLimit=`5` | ||
&formid=`commentform` | ||
&rules=`{ | ||
"name":{"required":"Name is required"}, | ||
"phoneoremail":{"required":"Phone or e-mail is required"}, | ||
"comment":{"required":"Your comment must be non-empty"}, | ||
"sogl":{"required":"You should agree with privacy policy"} | ||
}` | ||
&to=`[email protected]` | ||
&reportTpl=`@CODE: | ||
<p>A new comment on the «[*pagetitle*]» page has been added to «[(site_name)]»<b></b></p> | ||
<p><b>Name:</b> [+name+]</p> | ||
<p><b>Phone or e-mail:</b> [+phoneoremail+]</p> | ||
<h4>Comment text</h4> | ||
<p>[+comment+]</p> | ||
<p><b>Sent from page:</b> [+title+] — [+link+]</p> | ||
<p>To approve or edit a comment, log in to the control panel</p>` | ||
&successTpl=`@CODE: <h3>Success!</h3><p>Your comment has been successfully added. Please wait for administrator to verify it.</p>` | ||
&errorClass=`is-invalid` | ||
&requiredClass=`is-invalid` | ||
&messagesTpl=`@CODE: <div class="invalid-feedback">[+messages+]</div>` | ||
&visible=`0` | ||
&container=`comments` | ||
&commentBlock=`comment` | ||
&prepareAfterProcess=`pb_addcomment` | ||
!] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* pb_commentslist | ||
* | ||
* Pagebuilder Comments List | ||
* | ||
* @category chunk | ||
* @internal @modx_category Comments | ||
* @internal @installset base | ||
* @internal @overwrite true | ||
*/ | ||
<section class="comments-section mb-5"> | ||
<h3>Comments</h3> | ||
[!pageBuilder? &container=`comments`!] | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//<?php | ||
/** | ||
* pb_commentsinformer | ||
* | ||
* <b>0.1</b> Welcome Page comments informer | ||
* | ||
* @category plugin | ||
* @internal @events OnManagerWelcomeHome | ||
* @internal @modx_category Comments | ||
* @internal @properties &plugintitle=Plugin title;text;Last Comments &empty=«No new comments» text;text;No new comments &list=«New comments» text;text;New comments in documents: &container=Container;text;comments | ||
* @internal @disabled 0 | ||
* @internal @installset base | ||
*/ | ||
$output = ""; | ||
$e = &$modx->Event; | ||
switch($e->name){ | ||
case 'OnManagerWelcomeHome': | ||
$plugin_title = $e->params['plugintitle']; | ||
$output=''; | ||
$res = $modx->db->select("id,document_id", $modx->getFullTableName('pagebuilder'), "container='" . $e->params['container'] ."' AND visible='0' group by document_id"); | ||
$documents = $modx->db->makeArray( $res ); | ||
if($documents){ | ||
$output.='<p>'.$e->params['list'].'</p><ul>'; | ||
foreach($documents as $doc){ | ||
$title = $modx->runsnippet('DocInfo',['docid'=>$doc['document_id'] ]); | ||
$output.='<li><a href="?a=27&r=1&id='.$doc['document_id'].'">'.$title.'</a></li>'; | ||
} | ||
$output.='</ul>'; | ||
}else{ | ||
$output=$e->params['empty']; | ||
} | ||
|
||
if (!empty($output)){ | ||
$widgets['lastcomments'] = array( | ||
'menuindex' =>'1', | ||
'id' => 'pb_commentsinformer', | ||
'cols' => 'col-sm-12', | ||
'icon' => 'fas fa-comment', | ||
'title' => $plugin_title, | ||
'body' => '<div class="card-body">'.$output.'</div>', | ||
'hide'=>'0' | ||
); | ||
$e->output(serialize($widgets)); | ||
} | ||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//<?php | ||
/** | ||
* pb_addcomment | ||
* | ||
* Comment saving prepare for FormLister | ||
* | ||
* @category snippet | ||
* @internal @modx_category Comments | ||
* @internal @installset base | ||
* @internal @overwrite true | ||
* @internal @properties | ||
*/ | ||
|
||
|
||
// Function to get the client IP address | ||
if (!function_exists('get_comment_ip')){ | ||
function get_comment_ip() { | ||
$ipaddress = ''; | ||
if (getenv('HTTP_CLIENT_IP')) | ||
$ipaddress = getenv('HTTP_CLIENT_IP'); | ||
else if(getenv('HTTP_X_FORWARDED_FOR')) | ||
$ipaddress = getenv('HTTP_X_FORWARDED_FOR'); | ||
else if(getenv('HTTP_X_FORWARDED')) | ||
$ipaddress = getenv('HTTP_X_FORWARDED'); | ||
else if(getenv('HTTP_FORWARDED_FOR')) | ||
$ipaddress = getenv('HTTP_FORWARDED_FOR'); | ||
else if(getenv('HTTP_FORWARDED')) | ||
$ipaddress = getenv('HTTP_FORWARDED'); | ||
else if(getenv('REMOTE_ADDR')) | ||
$ipaddress = getenv('REMOTE_ADDR'); | ||
else | ||
$ipaddress = 'UNKNOWN'; | ||
return $ipaddress; | ||
} | ||
} | ||
|
||
if ($FormLister->isSubmitted()) | ||
{ | ||
date_default_timezone_set('Europe/Moscow'); | ||
$params = $FormLister->config->getConfig(); | ||
//docId | ||
if ($params['docId']) $docId = $params['docId']; | ||
else $docId = $modx->documentIdentifier; | ||
if ($params['commentBlock']) $commentBlock = $params['commentBlock']; | ||
else $commentBlock = 'comment'; | ||
if ($params['container']) $container = $params['container']; | ||
else $container = 'comments'; | ||
//publish by default | ||
if ($params['visible']) $visible = $params['visible']; | ||
else $visible=0; | ||
//prepare form values | ||
$fields = array( | ||
'name' => $FormLister->getField('name'), | ||
'phoneoremail' => $FormLister->getField('phoneoremail'), | ||
'comment' => $FormLister->getField('comment'), | ||
'date'=> date('d-m-Y H:i:00'), | ||
'ip'=>get_comment_ip(), | ||
); | ||
//table name | ||
$table = $modx->getFullTableName('pagebuilder'); | ||
//get comment index | ||
$index = $modx->db->getValue($modx->db->select("max(`index`)+1", $table, "document_id='" . $docId ."' AND container='" . $container ."'")); | ||
if(!$index) $index = 0; | ||
$fields = array( | ||
'document_id' => $docId, | ||
'config' => $commentBlock, | ||
'container'=> $container, | ||
'values' => json_encode($fields, JSON_UNESCAPED_UNICODE), | ||
'visible'=> $visible, | ||
'index'=> $index, | ||
'title'=>'' | ||
); | ||
$modx->db->insert($fields, $table); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* comments | ||
* | ||
* comments | ||
* | ||
* @category tv | ||
* @name comments | ||
* @internal @caption Comments | ||
* @internal @input_type custom_tv:pagebuilder | ||
* @internal @modx_category Comments | ||
* @internal @input_default | ||
* @internal @input_options | ||
*/ |