Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new plugins #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions core/components/slackify/elements/plugins/cacheUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnCacheUpdate':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
$user = $modx->getUser();
if (!$user) break;
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;

$a = new Attachment();
//$a->setPretext($creatorProfile->get('fullname').' saved a resource');
$a->setColor(new Color('#00bba7'));
$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$a->setTitle(new Title("cleared cache"));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$message = new Message('*cleared cache* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message

$slackify->send($message); // and send message to Slack
break;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnFileManagerFileRemove':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
$user = $modx->getUser();
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;
$msource = $source->get('name');
$a = new Attachment();
$a->setColor(new Color('#ff7e00'));
$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$a->setTitle(new Title("deleted ".$path." on Mediasource ".$msource));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$a->addField(new Field('User agent', $_SERVER['HTTP_USER_AGENT']));
$message = new Message('*deleted file* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message
$slackify->send($message); // and send message to Slack
break;
}
31 changes: 31 additions & 0 deletions core/components/slackify/elements/plugins/fileManagerUpload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnFileManagerUpload':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
$user = $modx->getUser();
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;

$a = new Attachment();
$a->setColor(new Color('#ffc600'));

$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$filename = '';
$filesize = '';
foreach($files as $file){
$filename.= $file['name'].' ';
$filesize.= $file['size'].' ';
}
$a->setTitle(new Title("# uploaded ".$filename." with ".$filesize." bytes #"));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$a->addField(new Field('User agent', $_SERVER['HTTP_USER_AGENT']));
$message = new Message('*uploaded file* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message
$slackify->send($message); // and send message to Slack
break;
}
24 changes: 24 additions & 0 deletions core/components/slackify/elements/plugins/managerLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnManagerLogin':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
if (!$user) break;
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;
$a = new Attachment();
$a->setColor(new Color('#666666'));
$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$a->setTitle(new Title("logged in"));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$a->addField(new Field('User agent', $_SERVER['HTTP_USER_AGENT']));
$message = new Message('*manager login* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message

$slackify->send($message); // and send message to Slack
break;
}
23 changes: 23 additions & 0 deletions core/components/slackify/elements/plugins/managerLogout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnManagerLogout':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
if (!$user) break;
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;
$a = new Attachment();
$a->setColor(new Color('#666666'));
$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$a->setTitle(new Title("logged out"));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$a->addField(new Field('User agent', $_SERVER['HTTP_USER_AGENT']));
$message = new Message('*manager logout* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message
$slackify->send($message); // and send message to Slack
break;
}
34 changes: 34 additions & 0 deletions core/components/slackify/elements/plugins/resourceDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnResourceDelete':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
$user = $modx->getUser();
if (!$user) break;
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;

$a = new Attachment();
$a->setColor(new Color('#ff7e00'));
$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$resourceTitle = new Link($modx->makeUrl($resource->get('id'), 'web', '', 'full'), $resource->get('pagetitle'));
$a->setTitle(new Title("deleted resource '$resourceTitle' in Context ".$resource->get('context_key')));
$a->setText($resource->get('description'));
$a->addField(new Field('Context',$resource->get('context_key'), true));
$a->addField(new Field('ID', $resource->get('id'), true));
$a->addField(new Field('Alias', $resource->get('alias'), true));
$a->addField(new Field('Menu-Title', $resource->get('menutitle'), true));
if ($resource->get('published')==1){ $published = 'yes'; } else { $published = 'no'; }
$a->addField(new Field('Published', $published, true));
$templateObj = $resource->getOne('Template');
$a->addField(new Field('Template', $resource->get('template').' - '.$templateObj->get('templatename'), true));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$message = new Message('*resource deleted* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message
$slackify->send($message); // and send message to Slack
break;
}
41 changes: 41 additions & 0 deletions core/components/slackify/elements/plugins/resourceSaved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
switch ($modx->event->name) { // as usual, check event name for run it only for needed event, if plugin attached to several events
case 'OnDocFormSave':
$slackify = $modx->getService('slackify'); // Important, you should initialize Slackify service before usage
// modx will load class Slackify and all related classes for work
// create message
$sitename = $modx->getOption('site_name');
$siteurl = $modx->getOption('site_url');
$user = $modx->getUser();
if (!$user) break;
$creatorProfile = $user->getOne('Profile');
if (!$creatorProfile) break;

$a = new Attachment();
//$a->setPretext($creatorProfile->get('fullname').' saved a resource');
$a->setColor(new Color('#0216d1'));
$a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email')));
$resourceTitle = new Link($modx->makeUrl($resource->get('id'), 'web', '', 'full'), $resource->get('pagetitle'));
$a->setTitle(new Title("saved resource '$resourceTitle' in Context ".$resource->get('context_key')));
$a->setText($resource->get('description'));
$a->addField(new Field('Context',$resource->get('context_key'), true));
$a->addField(new Field('ID', $resource->get('id'), true));
$a->addField(new Field('Alias', $resource->get('alias'), true));
$a->addField(new Field('Menu-Title', $resource->get('menutitle'), true));
if ($resource->get('published')==1){
$published = 'yes';
} else {
$published = 'no';
}

$a->addField(new Field('Published', $published, true));
$templateObj = $resource->getOne('Template');
$a->addField(new Field('Template', $resource->get('template').' - '.$templateObj->get('templatename'), true));
$a->addField(new Field('When', (new DateTime())->format('d M Y - G:i:s'), true));
$a->addField(new Field('User IP', $_SERVER['REMOTE_ADDR'], true));
$message = new Message('*resource saved* on '.$sitename.' at '.$siteurl);
$message->attach($a); // attach attachment to message. You cn create several attachments and attach their to message

$slackify->send($message); // and send message to Slack
break;
}