Esempio n. 1
0
 public static function onAfterAdminDeactivateExtension(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $params = $event->getParameters();
     if ($params['type'] == 'mod') {
         $q = "DELETE FROM extension_meta \n                WHERE extension = 'mod_hook'\n                AND rel_type = 'mod'\n                AND rel_id = :mod\n                AND meta_key = 'listener'";
         $di['db']->exec($q, array('mod' => $params['id']));
     }
     $event->setReturnValue(TRUE);
 }
Esempio n. 2
0
 public static function onBeforeAdminCronRun(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $extensionService = $di['mod_service']('extension');
     try {
         $extensionService->getExtensionsList(array());
     } catch (\Exception $e) {
         error_log($e);
     }
     return true;
 }
Esempio n. 3
0
 public static function onAfterAdminLogin(\Fuse_Event $event)
 {
     $params = $event->getParameters();
     $di = $event->getDi();
     $log = $di['db']->dispense('ActivityAdminHistory');
     $log->admin_id = $params['id'];
     $log->ip = $params['ip'];
     $log->created_at = date('Y-m-d H:i:s');
     $log->updated_at = date('Y-m-d H:i:s');
     $di['db']->store($log);
 }
Esempio n. 4
0
 public static function onBeforeAdminCronRun(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $extensionService = $di['mod_service']('extension');
     $config = $extensionService->getConfig("mod_seo");
     try {
         $seoService = $di['mod_service']('seo');
         $seoService->setDi($di);
         $seoService->pingSitemap($config);
         $seoService->pingRss($config);
     } catch (\Exception $e) {
         error_log($e->getMessage());
     }
     return true;
 }
Esempio n. 5
0
 /**
  * @param \Fuse_Event $event
  * @return bool
  */
 public static function onAfterClientOpenTicket(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $params = $event->getParameters();
     $supportTicket = $di['db']->load('SupportTicket', $params['id']);
     $client = $di['db']->load('Client', $supportTicket->client_id);
     $paidSupportService = $di['mod_service']('Paidsupport');
     $paidSupportService->setDi($di);
     if (!$paidSupportService->hasHelpdeskPaidSupport($supportTicket->support_helpdesk_id)) {
         return true;
     }
     $paidSupportService->enoughInBalanceToOpenTicket($client);
     $clientBalanceService = $di['mod_service']('Client', 'Balance');
     $clientBalanceService->setDi($di);
     $message = sprintf('Paid support ticket#%d "%s" opened', $supportTicket->id, $supportTicket->subject);
     $extra = array('rel_id' => $supportTicket->id, 'type' => 'supportticket');
     $clientBalanceService->deductFunds($client, $paidSupportService->getTicketPrice(), $message, $extra);
     return true;
 }
Esempio n. 6
0
 public function fire($data)
 {
     if (!isset($data['event']) || empty($data['event'])) {
         error_log('Invoked event call without providing event name');
         return false;
     }
     $event = $data['event'];
     $subject = isset($data['subject']) ? $data['subject'] : null;
     $params = isset($data['params']) ? $data['params'] : null;
     if (BF_DEBUG) {
         $this->di['logger']->debug($event . ': ' . var_export($params, 1));
     }
     $e = new Fuse_Event($subject, $event, $params);
     $e->setDi($this->di);
     $disp = new Fuse_EventDispatcher();
     $this->_connectDatabaseHooks($disp, $e->getName());
     $disp->notify($e);
     return $e->getReturnValue();
 }
Esempio n. 7
0
 public static function onAfterClientSignUp(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $params = $event->getParameters();
     $config = $di['mod_config']('client');
     $emailService = $di['mod_service']('email');
     try {
         $email = array();
         $email['to_client'] = $params['id'];
         $email['code'] = 'mod_client_signup';
         $email['password'] = $params['password'];
         $email['require_email_confirmation'] = false;
         if (isset($config['require_email_confirmation']) && $config['require_email_confirmation']) {
             $clientService = $di['mod_service']('client');
             $email['require_email_confirmation'] = true;
             $email['email_confirmation_link'] = $clientService->generateEmailConfirmationLink($params['id']);
         }
         $emailService->sendTemplate($email);
     } catch (\Exception $exc) {
         error_log($exc->getMessage());
     }
     return true;
 }
Esempio n. 8
0
 public static function onBeforeAdminCronRun(\Fuse_Event $event)
 {
     try {
         $di = $event->getDi();
         $domainService = $di['mod_service']('servicedomain');
         $domainService->batchSyncExpirationDates();
     } catch (\Exception $e) {
         error_log($e->getMessage());
     }
     return true;
 }
Esempio n. 9
0
 public static function onAfterAdminCronRun(\Fuse_Event $event)
 {
     try {
         $di = $event->getDi();
         $di['api_admin']->queue_execute(array('queue' => 'massmailer'));
     } catch (\Exception $e) {
         error_log('Error executing massmailer queue: ' . $e->getMessage());
     }
 }
Esempio n. 10
0
 /**
  * @param \Fuse_Event $event
  */
 public static function onAfterGuestPublicTicketClose(\Fuse_Event $event)
 {
     $params = $event->getParameters();
     $di = $event->getDi();
     try {
         $supportService = $di['mod_service']('Support');
         $publicTicket = $di['db']->load('SupportPTicket', $params['id']);
         $ticket = $supportService->publicToApiArray($publicTicket);
         $email = array();
         $email['to_staff'] = true;
         $email['code'] = 'mod_staff_pticket_close';
         $email['ticket'] = $ticket;
         $emailService = $di['mod_service']('Email');
         $emailService->sendTemplate($email);
     } catch (\Exception $exc) {
         error_log($exc->getMessage());
     }
 }
Esempio n. 11
0
 /**
  * This event hook is registered in example module client API call
  * @param \Fuse_Event $event
  */
 public static function onAfterClientCalledExampleModule(\Fuse_Event $event)
 {
     //error_log('Called event from example module');
     $di = $event->getDi();
     $params = $event->getParameters();
     $meta = $di['db']->dispense('extension_meta');
     $meta->extension = 'mod_example';
     $meta->meta_key = 'event_params';
     $meta->meta_value = json_encode($params);
     $meta->created_at = date('Y-m-d H:i:s');
     $meta->updated_at = date('Y-m-d H:i:s');
     $di['db']->store($meta);
 }
Esempio n. 12
0
 public static function onAfterClientRepliedInForum(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $api = $di['api_admin'];
     $params = $event->getParameters();
     $id = $params['id'];
     $message_id = $params['message_id'];
     $client_id = $params['client_id'];
     $service = $di['mod_service']('forum');
     $list = $service->getTopicSubscribers($id);
     $message = $api->forum_message_get(array('id' => $message_id));
     $topic = $api->forum_topic_get(array('id' => $id));
     foreach ($list as $cid) {
         if ($client_id == $cid) {
             //do not send email to author
             continue;
         }
         $email = array();
         $email['to_client'] = $cid;
         $email['code'] = 'mod_forum_new_post';
         $email['topic_id'] = $id;
         $email['message_id'] = $message_id;
         $email['message'] = $message;
         $email['topic'] = $topic;
         try {
             $api->email_template_send($email);
         } catch (\Exception $exc) {
             error_log($exc->getMessage());
         }
     }
     //forum points
     $mod = $di['mod']('forum');
     $config = $mod->getConfig();
     $points = $di['array_get']($config, 'points', 0);
     $points_forums = $di['array_get']($config, 'points_forums', array());
     if (isset($config['forum_points_enable']) && $config['forum_points_enable'] && !empty($points_forums) && in_array($topic['forum']['id'], $points_forums) && strlen($message['message']) >= $config['post_length'] && $points > 0) {
         $di['db']->exec('UPDATE forum_topic_message SET points = :points WHERE id = :id', array('points' => $points, 'id' => $message_id));
         $service = $mod->getService();
         $service->updateTotalPoints($client_id, $points, true);
     }
 }
Esempio n. 13
0
 public static function onAfterAdminPublicTicketClose(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $supportService = $di['mod_service']('support');
     $emailService = $di['mod_service']('email');
     $params = $event->getParameters();
     try {
         $ticketObj = $supportService->getPublicTicketById($params['id']);
         $identity = $di['loggedin_admin'];
         $ticketArr = $supportService->publicToApiArray($ticketObj, true, $identity);
         $email = array();
         $email['to'] = $ticketArr['author_email'];
         $email['to_name'] = $ticketArr['author_name'];
         $email['code'] = 'mod_support_pticket_staff_close';
         $email['ticket'] = $ticketArr;
         $emailService->sendTemplate($email);
     } catch (\Exception $exc) {
         error_log($exc->getMessage());
     }
 }
Esempio n. 14
0
 public static function onEventAfterInvoiceIsDue(\Fuse_Event $event)
 {
     $params = $event->getParameters();
     $di = $event->getDi();
     $service = $di['mod_service']('invoice');
     //send reminder once a day when 5 days has passed
     if ($params['days_passed'] != 5) {
         return;
     }
     try {
         $invoiceModel = $di['db']->load('Invoice', $params['id']);
         $invoice = $service->toApiArray($invoiceModel, array('id' => $params['id']));
         $email = array();
         $email['to_client'] = $invoice['client']['id'];
         $email['code'] = 'mod_invoice_due_after';
         $email['days_passed'] = $params['days_passed'];
         $email['invoice'] = $invoice;
         $emailService = $di['mod_service']('email');
         $emailService->sendTemplate($email);
     } catch (\Exception $exc) {
         error_log($exc->getMessage());
     }
 }
Esempio n. 15
0
 public function isSpam(\Fuse_Event $event)
 {
     $di = $event->getDi();
     $params = $event->getParameters();
     $data = array('ip' => $this->di['array_get']($params, 'ip', NULL), 'email' => $this->di['array_get']($params, 'email', NULL), 'recaptcha_challenge_field' => $this->di['array_get']($params, 'recaptcha_challenge_field', NULL), 'recaptcha_response_field' => $this->di['array_get']($params, 'recaptcha_response_field', NULL));
     $config = $di['mod_config']('Spamchecker');
     if (isset($config['captcha_enabled']) && $config['captcha_enabled']) {
         if (isset($config['captcha_version']) && $config['captcha_version'] == 2) {
             if (!isset($config['captcha_recaptcha_privatekey']) || $config['captcha_recaptcha_privatekey'] == '') {
                 throw new \Fuse_Exception("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
             }
             if (!isset($params['g-recaptcha-response']) || $params['g-recaptcha-response'] == '') {
                 throw new \Fuse_Exception("No response received");
             }
             $postData = array('secret' => $config['captcha_recaptcha_privatekey'], 'response' => $params['g-recaptcha-response'], 'remoteip' => $di['request']->getClientAddress());
             $request = $di['guzzle_client']->post('https://www.google.com/recaptcha/api/siteverify', null, $postData);
             $response = $di['guzzle_client']->send($request)->json();
             if (!$response['success']) {
                 throw new \Fuse_Exception('Captcha verification failed.');
             }
         } else {
             $privatekey = $config['captcha_recaptcha_privatekey'];
             if ($privatekey == null || $privatekey == '') {
                 throw new \Fuse_Exception("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
             }
             require_once BF_PATH_MODS . '/Spamchecker/recaptchalib.php';
             $resp = recaptcha_check_answer($privatekey, $data['ip'], $data["recaptcha_challenge_field"], $data["recaptcha_response_field"]);
             if (!$resp->is_valid) {
                 error_log($resp->error);
                 throw new \Fuse_Exception('Captcha verification failed.');
             }
         }
     }
     if (isset($config['sfs']) && $config['sfs']) {
         $spamCheckerService = $di['mod_service']('Spamchecker');
         $spamCheckerService->isInStopForumSpamDatabase($data);
     }
 }
Esempio n. 16
0
 /**
  * Filters a value by calling all listeners of a given event.
  *
  * @param  Fuse_Event  $event   A Fuse_Event instance
  * @param  mixed    $value   The value to be filtered
  *
  * @return Fuse_Event The Fuse_Event instance
  */
 public function filter(Fuse_Event $event, $value)
 {
     foreach ($this->getListeners($event->getName()) as $listener) {
         $value = call_user_func_array($listener, array($event, $value));
     }
     $event->setReturnValue($value);
     return $event;
 }
Esempio n. 17
0
 public static function onAfterAdminOrderUncancel(\Fuse_Event $event)
 {
     $params = $event->getParameters();
     $order_id = $params['id'];
     $di = $event->getDi();
     $service = $di['mod_service']('order');
     try {
         $order = $di['db']->getExistingModelById('ClientOrder', $order_id, 'Order not found');
         $identity = $di['loggedin_admin'];
         $s = $service->getOrderServiceData($order, $identity);
         $orderArr = $service->toApiArray($order, true, $identity);
         $email = array();
         $email['to_client'] = $orderArr['client']['id'];
         $email['code'] = sprintf('mod_service%s_renewed', $orderArr['service_type']);
         $email['order'] = $orderArr;
         $email['service'] = $s;
         $emailService = $di['mod_service']('email');
         $emailService->sendTemplate($email);
     } catch (\Exception $exc) {
         error_log($exc->getMessage());
     }
 }