public static function onAfterAdminDeactivateExtension(\Box_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); }
public static function onAfterAdminLogin(\Box_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); }
/** * @param \Box_Event $event * @return bool */ public static function onAfterClientOpenTicket(\Box_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; }
public static function onAfterClientSignUp(\Box_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; }
/** * @param \Box_Event $event */ public static function onAfterGuestPublicTicketClose(\Box_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()); } }
public function isSpam(\Box_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 \Box_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 \Box_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 \Box_Exception('Captcha verification failed.'); } } else { $privatekey = $config['captcha_recaptcha_privatekey']; if ($privatekey == null || $privatekey == '') { throw new \Box_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 BB_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 \Box_Exception('Captcha verification failed.'); } } } if (isset($config['sfs']) && $config['sfs']) { $spamCheckerService = $di['mod_service']('Spamchecker'); $spamCheckerService->isInStopForumSpamDatabase($data); } }
public static function onEventAfterInvoiceIsDue(\Box_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()); } }
public static function onAfterClientRepliedInForum(\Box_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); } }
public static function onAfterAdminPublicTicketClose(\Box_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()); } }
public static function onAfterAdminOrderUncancel(\Box_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()); } }
/** * This event hook is registered in example module client API call * @param \Box_Event $event */ public static function onAfterClientCalledExampleModule(\Box_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); }
public static function onBeforeClientCheckout(Box_Event $event) { $cart = $event->getSubject(); $params = $event->getParameters(); $ip = $params['ip']; $client = $params['client']; list($t, $domain) = explode('@', $client['email']); $rp = array(); $rp['i'] = $ip; $rp['domain'] = $domain; $rp['city'] = $client['city']; $rp['region'] = $client['state']; $rp['postal'] = $client['postcode']; $rp['txnID'] = $client['id']; $rp['custphone'] = $client['phone_cc'] . $client['phone']; $rp['country'] = $client['country']; $rp['emailMD5'] = md5($client['email']); $rp['txn_type'] = 'paypal'; /* payment gateway */ $rp['license_key'] = ''; // your MaxMind license key $rp['requested_type'] = 'standard'; /* your request type preference */ $fraudscore = 25; /* your riskScore preference */ $pdo = Box_Db::getPdo(); $q = "SELECT custom_9 FROM client WHERE id = :client_id LIMIT 1"; $stmt = $pdo->prepare($q); $stmt->execute(array('client_id' => $client['id'])); $fraudtest = $stmt->fetchColumn(); $pdo = Box_Db::getPdo(); $q = "SELECT custom_8 FROM client WHERE id = :client_id LIMIT 1"; $stmt = $pdo->prepare($q); $stmt->execute(array('client_id' => $client['id'])); $mmchecks = $stmt->fetchColumn(); if ($fraudtest == '"' . 'city' . '"') { throw new Payment_Exception('The City that you have entered does not exists. Please check spelling. '); } else { if ($fraudtest == '"' . 'fraud' . '"') { throw new Payment_Exception('Your order was flagged as suspicious by MaxMind. ' . 'Please contact support.'); } else { if ($fraudtest == '"' . 'freemail' . '"') { throw new Payment_Exception('Orders using e-mails from a free e-mail providers are disabled. Please use another e-mail to place your order. '); } else { if ($fraudtest == '"' . 'postcode' . '"') { throw new Payment_Exception('The Zip/Postcode that you have entered does not exists. Please check spelling. '); } else { $url = 'https://minfraud2.maxmind.com/app/ccv2r?' . http_build_query($rp); $content = file_get_contents($url); // enable this to debug response to the screen when clicking checkout button // throw new Exception(var_export($content, 1)); $result = array(); $keyvaluepairs = explode(";", $content); $numkeyvaluepairs = count($keyvaluepairs); for ($i = 0; $i < $numkeyvaluepairs; $i++) { list($key, $value) = explode("=", $keyvaluepairs[$i]); $result[$key] = $value; } // Do something with maxmind result. // You can throw an Exception if detected that this cliet is a fraud // In this example we simple save MaxMind result to client profile custom field 10. $pdo = Box_Db::getPdo(); $q = "UPDATE client\n SET custom_10 = :value\n WHERE id = :client_id\n LIMIT 1"; $stmt = $pdo->prepare($q); $stmt->execute(array('client_id' => $client['id'], 'value' => json_encode($result))); list($mm, $mmscore) = explode("=", $keyvaluepairs['43']); $mmv[$mm] = $mmscore; list($mmc, $mmcity) = explode("=", $keyvaluepairs['7']); $mmct[$mmc] = $mmcity; list($emmc, $mmmail) = explode("=", $keyvaluepairs['3']); $emmct[$emmc] = $mmmail; if ($mmcity == 'CITY_NOT_FOUND') { $tt = 'city'; $pdo = Box_Db::getPdo(); $q = "UPDATE client\n SET custom_9 = :value\n WHERE id = :client_id\n LIMIT 1"; $stmt = $pdo->prepare($q); $stmt->execute(array('client_id' => $client['id'], 'value' => json_encode($tt))); throw new Payment_Exception('The City that you have entered does not exists. Please check spelling. '); } else { if ($mmcity == 'POSTAL_CODE_NOT_FOUND') { $tt = 'postcode'; $pdo = Box_Db::getPdo(); $q = "UPDATE client\n SET custom_9 = :value\n WHERE id = :client_id\n LIMIT 1"; $stmt = $pdo->prepare($q); $stmt->execute(array('client_id' => $client['id'], 'value' => json_encode($tt))); throw new Payment_Exception('The Zip/Postcode that you have entered does not exists. Please check spelling. '); } else { if ($mmscore >= $fraudscore) { $tt = 'fraud'; $pdo = Box_Db::getPdo(); $q = "UPDATE client\n SET custom_9 = :value\n WHERE id = :client_id\n LIMIT 1"; $stmt = $pdo->prepare($q); $stmt->execute(array('client_id' => $client['id'], 'value' => json_encode($tt))); throw new Payment_Exception('Your order was flagged as suspicious by MaxMind. ' . 'Please contact support.'); } } } } } } } }