diff --git a/assets/plugins/pagebuilder/config/comment.php b/assets/plugins/pagebuilder/config/comment.php new file mode 100644 index 0000000..e798c90 --- /dev/null +++ b/assets/plugins/pagebuilder/config/comment.php @@ -0,0 +1,48 @@ + 'Comment', + 'image' => 'assets/plugins/pagebuilder/images/text.jpg', + 'container' => 'comments', + 'templates' => [ + 'owner' => ' +
+
+ [+name+] on [+date+] +
+
+ [+comment+] + [[if? &is=`[+answer+]|not_empty` &separator=`|` &then=`
Admin reply
[+answer+]
`]] +
+
+ ', + ], + + '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' + ] + ], + ]; + diff --git a/assets/plugins/pagebuilder/config/container.comments.php b/assets/plugins/pagebuilder/config/container.comments.php new file mode 100644 index 0000000..37a8fa7 --- /dev/null +++ b/assets/plugins/pagebuilder/config/container.comments.php @@ -0,0 +1,6 @@ + 'Comments', + 'placement' => 'tv', + ]; + diff --git a/install/assets/chunks/pb_commentsform.tpl b/install/assets/chunks/pb_commentsform.tpl new file mode 100644 index 0000000..9060ecb --- /dev/null +++ b/install/assets/chunks/pb_commentsform.tpl @@ -0,0 +1,66 @@ +/** + * pb_commentsform + * + * Comments form + * + * @category chunk + * @internal @modx_category Comments + * @internal @installset base + * @internal @overwrite true + */ +[!FormLister? +&formTpl=`@CODE:
+

Add comment

+
+ + + [+name.error+] +
+
+ + + [+phoneoremail.error+] + We'll never share your email or phone with anyone else. +
+
+ + + [+comment.error+] +
+
+ + +
+ + + +
+` +&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=`some@mail.net` + &reportTpl=`@CODE: +

A new comment on the «[*pagetitle*]» page has been added to «[(site_name)]»

+

Name: [+name+]

+

Phone or e-mail: [+phoneoremail+]

+

Comment text

+

[+comment+]

+

Sent from page: [+title+] — [+link+]

+

To approve or edit a comment, log in to the control panel

` + &successTpl=`@CODE:

Success!

Your comment has been successfully added. Please wait for administrator to verify it.

` + &errorClass=`is-invalid` + &requiredClass=`is-invalid` + &messagesTpl=`@CODE:
[+messages+]
` + &visible=`0` + &container=`comments` + &commentBlock=`comment` + &prepareAfterProcess=`pb_addcomment` +!] diff --git a/install/assets/chunks/pb_commentslist.tpl b/install/assets/chunks/pb_commentslist.tpl new file mode 100644 index 0000000..eb2081b --- /dev/null +++ b/install/assets/chunks/pb_commentslist.tpl @@ -0,0 +1,14 @@ +/** + * pb_commentslist + * + * Pagebuilder Comments List + * + * @category chunk + * @internal @modx_category Comments + * @internal @installset base + * @internal @overwrite true + */ +
+

Comments

+ [!pageBuilder? &container=`comments`!] +
diff --git a/install/assets/plugins/pb_commentsinformer.tpl b/install/assets/plugins/pb_commentsinformer.tpl new file mode 100644 index 0000000..fbdab4d --- /dev/null +++ b/install/assets/plugins/pb_commentsinformer.tpl @@ -0,0 +1,49 @@ +//0.1 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.='

'.$e->params['list'].'

'; + }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' => '
'.$output.'
', + 'hide'=>'0' + ); + $e->output(serialize($widgets)); + } + break; +} diff --git a/install/assets/snippets/pb_addcomment.tpl b/install/assets/snippets/pb_addcomment.tpl new file mode 100644 index 0000000..19377ad --- /dev/null +++ b/install/assets/snippets/pb_addcomment.tpl @@ -0,0 +1,84 @@ +//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); +} diff --git a/install/assets/tvs/comments.tpl b/install/assets/tvs/comments.tpl new file mode 100644 index 0000000..5db8c92 --- /dev/null +++ b/install/assets/tvs/comments.tpl @@ -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 + */