From 243bfda48f45946307eab0cb1c1a02eb829963c6 Mon Sep 17 00:00:00 2001 From: Alexander Herling Date: Fri, 29 Jan 2016 04:39:29 +0100 Subject: [PATCH 1/2] added new plugins --- .../plugins/fileManagerFileRemove.php | 23 +++++++++++ .../elements/plugins/fileManagerUpload.php | 28 +++++++++++++ .../elements/plugins/managerLogin.php | 22 ++++++++++ .../elements/plugins/managerLogout.php | 21 ++++++++++ .../elements/plugins/resourceDelete.php | 33 +++++++++++++++ .../elements/plugins/resourceSaved.php | 40 +++++++++++++++++++ 6 files changed, 167 insertions(+) create mode 100644 core/components/slackify/elements/plugins/fileManagerFileRemove.php create mode 100644 core/components/slackify/elements/plugins/fileManagerUpload.php create mode 100644 core/components/slackify/elements/plugins/managerLogin.php create mode 100644 core/components/slackify/elements/plugins/managerLogout.php create mode 100644 core/components/slackify/elements/plugins/resourceDelete.php create mode 100644 core/components/slackify/elements/plugins/resourceSaved.php diff --git a/core/components/slackify/elements/plugins/fileManagerFileRemove.php b/core/components/slackify/elements/plugins/fileManagerFileRemove.php new file mode 100644 index 0000000..0654062 --- /dev/null +++ b/core/components/slackify/elements/plugins/fileManagerFileRemove.php @@ -0,0 +1,23 @@ +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 + + $user = $modx->getUser(); + $creatorProfile = $user->getOne('Profile'); + if (!$creatorProfile) break; + $msource = $source->get('name'); + $a = new Attachment(); + $a->setColor(new Color('#ff0000')); + $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*'); + $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; +} \ No newline at end of file diff --git a/core/components/slackify/elements/plugins/fileManagerUpload.php b/core/components/slackify/elements/plugins/fileManagerUpload.php new file mode 100644 index 0000000..f356ed3 --- /dev/null +++ b/core/components/slackify/elements/plugins/fileManagerUpload.php @@ -0,0 +1,28 @@ +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 + + $user = $modx->getUser(); + $creatorProfile = $user->getOne('Profile'); + if (!$creatorProfile) break; + + $a = new Attachment(); + $a->setColor(new Color('#ff0000')); + + $a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email'))); + $filenames = ''; + foreach($files as $file){ + $filenames.= $file['name'].' '; + } + $a->setTitle(new Title("# uploaded ".$filenames." #")); + $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*'); + $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; +} \ No newline at end of file diff --git a/core/components/slackify/elements/plugins/managerLogin.php b/core/components/slackify/elements/plugins/managerLogin.php new file mode 100644 index 0000000..25c0fc2 --- /dev/null +++ b/core/components/slackify/elements/plugins/managerLogin.php @@ -0,0 +1,22 @@ +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 + 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*'); + $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; +} \ No newline at end of file diff --git a/core/components/slackify/elements/plugins/managerLogout.php b/core/components/slackify/elements/plugins/managerLogout.php new file mode 100644 index 0000000..d24b9b3 --- /dev/null +++ b/core/components/slackify/elements/plugins/managerLogout.php @@ -0,0 +1,21 @@ +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 + 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*'); + $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; +} \ No newline at end of file diff --git a/core/components/slackify/elements/plugins/resourceDelete.php b/core/components/slackify/elements/plugins/resourceDelete.php new file mode 100644 index 0000000..bc22514 --- /dev/null +++ b/core/components/slackify/elements/plugins/resourceDelete.php @@ -0,0 +1,33 @@ +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 + + $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('*deleted resource*'); + $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; +} \ No newline at end of file diff --git a/core/components/slackify/elements/plugins/resourceSaved.php b/core/components/slackify/elements/plugins/resourceSaved.php new file mode 100644 index 0000000..2f346f2 --- /dev/null +++ b/core/components/slackify/elements/plugins/resourceSaved.php @@ -0,0 +1,40 @@ +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 + + $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('#00FF00')); + $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*'); + $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; +} \ No newline at end of file From ed7a5534b62d55c1bb8294748d4b2f413dfcaf4b Mon Sep 17 00:00:00 2001 From: Alexander Herling Date: Fri, 29 Jan 2016 15:22:33 +0100 Subject: [PATCH 2/2] updated plugins and added plugin cacheUpdate --- .../slackify/elements/plugins/cacheUpdate.php | 26 +++++++++++++++++++ .../plugins/fileManagerFileRemove.php | 9 ++++--- .../elements/plugins/fileManagerUpload.php | 15 ++++++----- .../elements/plugins/managerLogin.php | 6 +++-- .../elements/plugins/managerLogout.php | 6 +++-- .../elements/plugins/resourceDelete.php | 5 ++-- .../elements/plugins/resourceSaved.php | 7 ++--- 7 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 core/components/slackify/elements/plugins/cacheUpdate.php diff --git a/core/components/slackify/elements/plugins/cacheUpdate.php b/core/components/slackify/elements/plugins/cacheUpdate.php new file mode 100644 index 0000000..6ee36f2 --- /dev/null +++ b/core/components/slackify/elements/plugins/cacheUpdate.php @@ -0,0 +1,26 @@ +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; +} \ No newline at end of file diff --git a/core/components/slackify/elements/plugins/fileManagerFileRemove.php b/core/components/slackify/elements/plugins/fileManagerFileRemove.php index 0654062..80daa01 100644 --- a/core/components/slackify/elements/plugins/fileManagerFileRemove.php +++ b/core/components/slackify/elements/plugins/fileManagerFileRemove.php @@ -4,19 +4,20 @@ $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('#ff0000')); + $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->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*'); + $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; diff --git a/core/components/slackify/elements/plugins/fileManagerUpload.php b/core/components/slackify/elements/plugins/fileManagerUpload.php index f356ed3..3247c60 100644 --- a/core/components/slackify/elements/plugins/fileManagerUpload.php +++ b/core/components/slackify/elements/plugins/fileManagerUpload.php @@ -4,24 +4,27 @@ $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('#ff0000')); + $a->setColor(new Color('#ffc600')); $a->setAuthor(new Author($creatorProfile->get('fullname'), 'mailto:' . $creatorProfile->get('email'))); - $filenames = ''; + $filename = ''; + $filesize = ''; foreach($files as $file){ - $filenames.= $file['name'].' '; + $filename.= $file['name'].' '; + $filesize.= $file['size'].' '; } - $a->setTitle(new Title("# uploaded ".$filenames." #")); + $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*'); + $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; diff --git a/core/components/slackify/elements/plugins/managerLogin.php b/core/components/slackify/elements/plugins/managerLogin.php index 25c0fc2..cf554b9 100644 --- a/core/components/slackify/elements/plugins/managerLogin.php +++ b/core/components/slackify/elements/plugins/managerLogin.php @@ -4,17 +4,19 @@ $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->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*'); + $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 diff --git a/core/components/slackify/elements/plugins/managerLogout.php b/core/components/slackify/elements/plugins/managerLogout.php index d24b9b3..5808e9e 100644 --- a/core/components/slackify/elements/plugins/managerLogout.php +++ b/core/components/slackify/elements/plugins/managerLogout.php @@ -4,17 +4,19 @@ $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->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*'); + $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; diff --git a/core/components/slackify/elements/plugins/resourceDelete.php b/core/components/slackify/elements/plugins/resourceDelete.php index bc22514..87c3c57 100644 --- a/core/components/slackify/elements/plugins/resourceDelete.php +++ b/core/components/slackify/elements/plugins/resourceDelete.php @@ -4,7 +4,8 @@ $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'); @@ -26,7 +27,7 @@ $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('*deleted resource*'); + $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; diff --git a/core/components/slackify/elements/plugins/resourceSaved.php b/core/components/slackify/elements/plugins/resourceSaved.php index 2f346f2..1299292 100644 --- a/core/components/slackify/elements/plugins/resourceSaved.php +++ b/core/components/slackify/elements/plugins/resourceSaved.php @@ -4,7 +4,8 @@ $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'); @@ -12,7 +13,7 @@ $a = new Attachment(); //$a->setPretext($creatorProfile->get('fullname').' saved a resource'); - $a->setColor(new Color('#00FF00')); + $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'))); @@ -32,7 +33,7 @@ $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*'); + $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