/** * Send Clockwork request message * * @param Message|\Model $objMessage * @param array $arrTokens * @param string $strLanguage * * @return bool */ public function send(Message $objMessage, array $arrTokens, $strLanguage = '') { if ($this->objModel->clockwork_api_key == '') { \System::log(sprintf('Please provide the Clockwork API key for message ID "%s"', $objMessage->id), __METHOD__, TL_ERROR); return false; } /** @var ClockworkSmsMessageDraft $objDraft */ $objDraft = $this->createDraft($objMessage, $arrTokens, $strLanguage); // return false if no language found for BC if ($objDraft === null) { return false; } $arrMessages = array(); //@todo We're waiting for a proper official composer integration of Clockwork. While so, a fork (used below) does it too $objClockwork = new \Clockwork($this->objModel->clockwork_api_key, array('from' => $objDraft->getFrom(), 'long' => (bool) $objMessage->long, 'truncate' => (bool) $objMessage->truncate)); foreach ($objDraft->getRecipients() as $recipient) { $arrMessages[] = array('to' => $recipient, 'message' => $objDraft->getText()); } try { $result = $objClockwork->send($arrMessages); } catch (\ClockworkException $e) { \System::log(sprintf('Error with message "%s" (Code %s) while sending the Clockwork request for message ID "%s" occurred.', $e->getMessage(), $e->getCode(), $objMessage->id), __METHOD__, TL_ERROR); return false; } $blnError = false; foreach ($result as $message) { if (!$message['success']) { \System::log(sprintf('Error with message "%s" (Code %s) while sending the Clockwork request for message ID "%s" occurred.', $message['error_message'], $message['error_code'], $objMessage->id), __METHOD__, TL_ERROR); $blnError = true; } } return !$blnError; }
/** * Return plugin class for $name * * @param string $name * * @return object; */ public static function getInstance($name = null) { if (!$name) { $name = get_called_class(); } return Clockwork::getInstance()->loadedPlugins[strtolower($name)]; }
/** * Autoloader, load or create classes and objects. * @package Clockwork/Core * * @param string $class Class to load. * * @return void */ function autoload($class) { $file = $class . '.php'; //core if (file_exists(CORE_DIR . $file)) { include_once CORE_DIR . $file; } else { if (file_exists(APP_DIR . 'model/' . $file)) { include_once APP_DIR . 'model/' . $file; } else { //plugin $pclass = explode('_', $class); if (Clockwork::isPluginLoaded($pclass[0])) { $file = Plugin::getInstance($pclass[0])->dir() . 'model/' . $pclass[1] . '.php'; if (file_exists($file)) { include_once $file; $loaded = true; } } // if (!isset($loaded)) { $code = 'class ' . $class . ' extends Model { public function __construct($mixed = null, $column = \'id\') { parent::__construct($mixed, $column); } }'; eval($code); } } } }
/** * Load .ini file and parse contents. * * @return void */ public function load() { $ini = APP_DIR . 'config/' . ENVIRONMENT . '.ini'; if (!file_exists($ini)) { Clockwork::throwError('Could not load config (' . $ini . ')'); } $this->data = parse_ini_file($ini, true); $this->setValues(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $routeName = 'settings'; $routeMethod = 'index'; $settings = $this->setting->getAllByGroupOrdered(); $data = compact('routeName', 'routeMethod', 'settings'); \Clockwork::info($settings); return view('admin.sections.settings.index', $data); }
/** * Create a new instance of the Clockwork wrapper * * Also supports passing a username and a password as first and second parameter, but ONLY when * used in WordPressClockwork for the purposes of converting to an API key. * * @param string key Your Clockwork API Key * @param array options Optional parameters for sending SMS * @author James Inman */ public function __construct($arg1, $arg2 = array()) { if (!isset($arg2) || is_array($arg2)) { parent::__construct($arg1, $arg2); } else { $this->username = $arg1; $this->password = $arg2; } }
/** * Constructor * */ public function __construct() { if (!Clockwork::getInstance()->isModuleLoaded('Cache')) { Clockwork::throwError('Login module depends on Cache module, which is not loaded', Clockwork::ERROR_FATAL, 1); } if (!Clockwork::getInstance()->isModuleLoaded('Hash')) { Clockwork::throwError('Login module depends on Hash module, which is not loaded', Clockwork::ERROR_FATAL, 1); } }
public function send_sms($api, $args) { try { $error_array = $this->validate_args($args); if (!is_null($error_array)) { return $error_array; } $api_key = $this->getApiKeyFromConfig(); $sms_body = $args['message']; $from_name = isset($args['from_name']) ? $args['from_name'] : 'SugarCRM'; $GLOBALS['log']->fatal("The value of api_key is: {$api_key}"); $clockwork = new Clockwork($api_key); $message = array('to' => $args['to_number'], 'message' => $sms_body, 'from' => $from_name); $result = $clockwork->send($message); return $result; } catch (ClockworkException $e) { // $GLOBALS['log']->fatal("$e->getMessage()"); return $e->getMessage(); } }
/** * Save data to cache. * * @param string $key Data to save as. * @param mixed $value Data to save. * @param boolean $db Cache to database. * * @return void */ public static function saveData($key, $value, $db = false) { $cache = Cache::getInstance(); $cache->data[$key] = $value; if ($key != 'ModelCachingFields' && $db && Config::getSetting('cache_to_database', false, false) && Clockwork::isModuleLoaded('Data/Database')) { $lifespan = $db === true ? 0 : $db; if (($obj = Caching::create($key, '*`key`')) === false) { $obj = new Caching(); } $obj->set('key', $key)->set('value', serialize($value))->set('object', is_object($value) ? get_class($value) : '')->set('lifespan', $lifespan)->save(); } }
/** * Validate e-mail addresses in the comma separated list * * @param mixed * @param \DataContainer * * @return mixed * @throws \Exception */ public function validateSmsSender($varValue, \DataContainer $dc) { if ($varValue != '') { if (strpos($varValue, '##') !== false || strpos($varValue, '{{') !== false) { return $varValue; } if (!\Validator::isAlphanumeric($varValue) && !\Clockwork::is_valid_msisdn($varValue) || \Validator::isAlphanumeric($varValue) && strlen($varValue) > 11) { throw new \Exception($GLOBALS['TL_LANG']['ERR']['invalidClockworkSmsSender']); } } return $varValue; }
/** * Log the query into the internal store * * @return array */ public function registerQuery($query, $bindings, $time, $connection) { $currentTime = microtime(true); $explainResults = []; if (preg_match('/^(SELECT) /i', $query)) { $pdo = DB::connection($connection)->getPdo(); $statement = $pdo->prepare('EXPLAIN ' . $query); $statement->execute($bindings); $explainResults = $statement->fetchAll(\PDO::FETCH_CLASS); foreach ($explainResults as $key => $value) { $explainResults[$key] = (array) $value; } } $this->queries[] = array('query' => $query, 'bindings' => $bindings, 'time' => $time, 'connection' => $connection, 'explain' => $explainResults); \Clockwork::addEvent(uniqid('query_'), 'Sql query', $currentTime - $time / 1000, $currentTime, ['query' => $query, 'bindings' => $bindings]); }
/** * @return array */ public function getRecipients() { // Replaces tokens first so that tokens can contain a list of recipients. $strRecipients = StringUtil::recursiveReplaceTokensAndTags($this->objLanguage->sms_recipients, $this->arrTokens, StringUtil::NO_TAGS | StringUtil::NO_EMAILS | StringUtil::NO_BREAKS); $arrRecipients = array(); foreach ((array) trimsplit(',', $strRecipients) as $strRecipient) { if ($strRecipient != '') { $strRecipient = StringUtil::recursiveReplaceTokensAndTags($strRecipient, $this->arrTokens, StringUtil::NO_TAGS | StringUtil::NO_EMAILS | StringUtil::NO_BREAKS); $strRecipient = $this->normalizePhoneNumber($strRecipient); // Address could become empty through invalid insert tag if ($strRecipient === false || !\Clockwork::is_valid_msisdn($strRecipient)) { \System::log(sprintf('Recipient "%s" for message ID %s was skipped as it was no valid MSISDN.', $strRecipient, $this->objMessage->id), __METHOD__, TL_ERROR); continue; } $arrRecipients[] = $strRecipient; } } return $arrRecipients; }
/** * Display the specified resource. * * @param int $hash * @return \Illuminate\Http\Response */ public function show($hash, Request $request) { $routeName = 'map'; $routeMethod = 'show'; $map = $this->map->getByHash($hash); if (!$map) { $data = compact('routeName', 'routeMethod'); return view('public.sections.map.unavailable', $data); } if ($request->input('redirect') == null) { if (Auth::check()) { return redirect()->route('admin.map.show', $map->id); } } $this->map->countView($map); $environment = collect(['settings' => \Cache::get('settings')]); $data = compact('routeName', 'routeMethod', 'map', 'environment'); \Clockwork::info($map); return view('public.sections.map.show', $data); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $routeName = 'role'; $routeMethod = 'edit'; $role = $this->role->getById($id); $permissions = $this->permission->getAllOrderedBy('name'); $data = compact('routeName', 'routeMethod', 'role', 'permissions'); \Clockwork::info($permissions); return view('admin.sections.role.edit', $data); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(TagRepository $tag, SourceRepository $source, $id) { $routeName = 'map'; $routeMethod = 'edit'; $map = $this->map->getById($id); if (!$map) { return redirect()->route('admin.map.index'); } $tags = $tag->getAllOrderedBy('name'); $sources = $source->getAllOrderedBy('name'); $environment = collect(['settings' => \Cache::get('settings')]); $environment = $environment->toJSON(); $data = compact('routeName', 'routeMethod', 'map', 'tags', 'sources', 'environment'); \Clockwork::info($data); return view('admin.sections.map.edit', $data); }
<?php // define('CW_CRON', true); include_once 'index.php'; extract($_GET); // if (preg_match('/(css|js|image)/', $type)) { if (Clockwork::getInstance()->isPluginLoaded($plugin)) { if ($type != 'image' || preg_match('/jpg|jpeg|gif|png/i', $ext)) { $file = Plugin::getInstance($plugin)->dir() . 'asset/' . $type . '/' . $file . '.' . $ext; if (file_exists($file)) { if ($type == 'image') { header('Content-Type: image/' . str_replace('jpg', 'jpeg', $ext)); } else { if ($type == 'css') { header('Content-Type: text/css'); } else { if ($type == 'js') { header('Content-Type: application/javascript'); } } } readfile($file); exit; } } } } // --- 404 new Template(['view' => '404']);
$message = array('to' => $lostSheepNumber, 'message' => $lostSheepMessage); $result = $clockwork->send($message); // Check if the send was successful if ($result['success']) { echo 'Message sent - ID: ' . $result['id'] . ' '; } else { echo 'Message failed - Error: ' . $result['error_message'] . ' '; } } catch (ClockworkException $e) { echo 'Exception sending SMS: ' . $e->getMessage() . ' '; } $shepherdNumber = $shepherd->getSheepMobile(); // TODO limit to 160 characters $shepherdMessage = "You have lost one of your sheep! " . $sheep->getSheepName() . " is currently " . $distanceFromShepherd . "m away! He is currently here: " . "www.google.com/maps/place/" . $newY . "," . $newX . ". You could give them a ring on " . $sheep->getSheepMobile() . " so you can explain what a silly Sheep they are. To stop tracking your flock, reply to this number and write \"FLOCKMENOT\"."; try { // Create a Clockwork object using your API key $clockwork2 = new Clockwork('787b4673e0ac4b043aab8a4764f0205ab06dc309'); // Setup and send a message $message2 = array('to' => $shepherdNumber, 'message' => $shepherdMessage); $result2 = $clockwork2->send($message2); // Check if the send was successful if ($result2['success']) { echo 'Message sent - ID: ' . $result2['id'] . ' '; } else { echo 'Message failed - Error: ' . $result2['error_message'] . ' '; } } catch (ClockworkException $e) { echo 'Exception sending SMS: ' . $e->getMessage() . ' '; } } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $routeName = 'permission'; $routeMethod = 'edit'; $permission = $this->permission->getById($id); $data = compact('routeName', 'routeMethod', 'permission'); \Clockwork::info($permission); return view('admin.sections.permission.edit', $data); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $routeName = 'user'; $routeMethod = 'edit'; $user = $this->user->getById($id); $roles = $this->role->getAllOrderedBy('name'); $data = compact('routeName', 'routeMethod', 'user', 'roles'); \Clockwork::info($user); return view('admin.sections.user.edit', $data); }
<?php echo "Hello"; require "safest_route.php"; require_once "key.php"; require "clockwork/class-Clockwork.php"; function interpretClockwork($text) { $message = substr($text, 9); $arr = explode(" to ", $message); return array("start" => urlencode($arr[0]), "end" => urlencode($arr[1])); } $phone = $_GET["from"]; $locations = interpretClockwork($_GET["content"]); $clockwork = new Clockwork($clock_key); $route = getSafestRoute($locations["start"], $locations["end"], true, true)[0]; $message = "(1 / 2)"; foreach ($route["instructions"] as $instruction) { $message .= " " . strip_tags($instruction) . "\n"; } echo $message; var_dump($clockwork->send(array(array("to" => $phone, "message" => "(2 / 2) The rest of your journey and a map can be viewed at http://pedalplan.tk/results.php?start={$locations['start']}&end={$locations['end']}&congestion=on&safest=on."), array("to" => $phone, "message" => $message))));
$app->group(['middleware' => 'csrf'], function () use($app) { $app->post('auth/register', ['as' => 'auth.register', 'uses' => \App\Http\Controllers\Register::class . '@register']); $app->post('auth/change-lost-password', ['as' => 'auth.changeLostPassword', 'uses' => \App\Http\Controllers\Password::class . '@changeLostPassword']); $app->post('auth/lost-password', ['as' => 'auth.lostPassword', 'uses' => \App\Http\Controllers\Password::class . '@lostPassword']); $app->post('auth/login', ['as' => 'auth.login', 'uses' => \App\Http\Controllers\Auth::class . '@login']); $app->get('oauth/google/connect', ['as' => 'oauth.google.connect', 'uses' => \App\Http\Controllers\OAuth\Google::class . '@connect']); $app->get('oauth/google/callback', ['as' => 'oauth.google.callback', 'uses' => \App\Http\Controllers\OAuth\Google::class . '@callback']); }); $app->group(['middleware' => 'auth|csrf'], function () use($app) { $app->get('auth/logout', ['as' => 'auth.logout', 'uses' => \App\Http\Controllers\Auth::class . '@logout']); $app->get('/', function () use($app) { Clockwork::info('Message text.'); // 'Message text.' appears in Clockwork log tab Log::info('Lumen logger interface.'); // 'Message text.' appears in Clockwork log tab as well as application log file Clockwork::info(array('hello' => 'world')); // logs json representation of the array return view('index'); }); $app->get('/acl', ['middleware' => 'acl:test.test', 'as' => 'acl.test', function () { dd('OK'); }]); }); /* |-------------------------------------------------------------------------- | API |-------------------------------------------------------------------------- */ $app->group(['prefix' => 'api/v1', 'middleware' => 'cors'], function () use($app) { $app->post('oauth/access_token', ['as' => 'oauth.login', 'uses' => App\Http\Controllers\Api\Auth::class . '@login']); $app->group(['middleware' => 'cors|oauth', 'prefix' => 'api/v1'], function () use($app) {
/** * Extend $this with ActiveRecord. * * @param string $object Object to extend. * * @return self */ public function find($object) { if (Clockwork::getInstance()->isModuleLoaded('Data/ActiveRecord')) { if (!$this->ActiveRecord || $this->ActiveRecord != $object) { $this->ActiveRecord = new ActiveRecord($object, $this); } } return $this; }
/** * Register a plugin * * @param string $name * * @return void */ public static function registerPlugin($name, $plugin) { Clockwork::getInstance()->loadedPlugins[strtolower($name)] = $plugin; }
/** * Setup Twig template engine * * @return void */ public function setupTwig() { Twig_Autoloader::register(true); if (!is_dir($this->basedir . 'template/')) { Clockwork::throwError('Template directory (' . $this->basedir . 'template/) does not exists'); } $paths = [$this->basedir . 'template/', APP_DIR . 'template/']; $plugins = Clockwork::getInstance()->loadedPlugins; foreach ($plugins as $plugin) { if (is_dir($plugin->dir() . 'template/')) { $paths[] = $plugin->dir() . 'template/'; } } $loader = new Twig_Loader_Filesystem($paths); $this->twig = new Twig_Environment($loader, array('cache' => Config::getSetting('twig_cache') ? appdir('template/cache/') : false)); $functions = get_defined_functions(); foreach ($functions['user'] as $function) { if (strpos(strtolower($function), 'twig') === false) { $this->twig->addFunction(new Twig_SimpleFunction($function, $function)); } } $this->twig->addFunction(new Twig_SimpleFunction('PluginLoader', [Clockwork::getInstance(), 'pluginLoader'])); }
/** * Find objects by column * * @param string $method * @param array $args * * @throws Clockwork Warning when requirements are not met * * @return array */ public function __call($method, $args) { if (preg_match('/^(by)/', $method)) { $this->by(array(lcfirst(end(preg_split('/^(by)/', $method))) . ' = ' . $args[0][0])); } else { $trace = debug_backtrace(); Clockwork::throwError('Call to undefined method ' . ucfirst($this->caller) . '::' . $method . '() in <b>' . $trace[0]['file'] . '</b> on line <b>' . $trace[0]['line'] . '</b><br />', Clockwork::ERROR_WARNING, 1); } }
if (isset($_POST)) { $sheepTable = new SheepTable(); $flockTable = new FlockTable(); $flockID = $_POST['flockID']; $flock = $flockTable->getFlockUsingFlockID($flockID); $sheepMobile = '44' . substr($_POST['mobile'], 1); $sheepID = $flockID . $sheepMobile; // Composite Key $sheep = new Sheep($sheepID, $sheepMobile, $_POST['sheepName'], NULL, NULL, false, false, false, $flockID); // FlockID if ($sheepTable->addSheep($sheep)) { http_response_code(200); $messageForSheep = "You have been added to the '" . $flock->getFlockName() . "' Flock by " . $flock->getShepherd()->getSheepName() . ". To enable tracking permission, text \"FLOCKME\" to 84433 (Texts cost 10p). Confused? Find out more at www.flockbuddy.com"; try { // Create a Clockwork object using your API key $clockwork = new Clockwork('787b4673e0ac4b043aab8a4764f0205ab06dc309'); // Setup and send the message $message = array('to' => $sheepMobile, 'message' => $messageForSheep); $result = $clockwork->send($message); // Check if the send was successful if ($result['success']) { echo 'Message sent - ID: ' . $result['id']; } else { echo 'Message failed - Error: ' . $result['error_message']; } } catch (ClockworkException $e) { echo 'Exception sending SMS: ' . $e->getMessage(); } } else { http_response_code(400); echo " FAILED to add sheep to flock.";
$app->register(App\Providers\AppServiceProvider::class); $app->register(App\Providers\EventServiceProvider::class); $app->register(Clockwork\Support\Lumen\ClockworkServiceProvider::class); $app->register(App\Providers\AclProvider::class); $app->register(Appzcoder\LumenRoutesList\RoutesCommandServiceProvider::class); $app->register(LucaDegasperi\OAuth2Server\Storage\FluentStorageServiceProvider::class); $app->register(LucaDegasperi\OAuth2Server\Lumen\OAuth2ServerServiceProvider::class); $app->register(Barryvdh\Cors\LumenServiceProvider::class); $app->register(TwigBridge\ServiceProvider::class); $app->configure('profiler'); $app->configure('oauth2'); $app->configure('cors'); $app->configure('twigbridge'); /* |-------------------------------------------------------------------------- | Load The Application Routes |-------------------------------------------------------------------------- | | Next we will include the routes file so that they can all be added to | the application. This will provide all of the URLs the application | can respond to, as well as the controllers that may handle them. | */ if (!class_exists('Authorizer')) { class_alias(\LucaDegasperi\OAuth2Server\Facades\Authorizer::class, 'Authorizer'); } $app->group(['namespace' => 'App\\Http\\Controllers'], function ($app) { require __DIR__ . '/../app/Http/routes.php'; }); Clockwork::addEvent('app.bootstrap', 'App bootstraping', $startBootstraping, microtime(true)); return $app;
/** * Get columns from database. * * @param string|boolean $key Field to return. * * @return array */ public function getFields($key = null) { if (Clockwork::isModuleLoaded('Cache') && count($this->fields) == 0) { $this->fields = Cache::loadData('Model' . ucfirst($this->modelName) . 'Fields'); } if (count($this->fields) == 0 && Clockwork::isModuleLoaded('Data/Database')) { $this->fields = Database::getInstance()->fetchAll("SHOW COLUMNS FROM " . $this->tableName); if (Clockwork::isModuleLoaded('Cache')) { Cache::saveData('Model' . ucfirst($this->modelName) . 'Fields', $this->fields, true); } } if (!$key) { return $this->fields; } else { if ($key === true) { $fields = array(); foreach ($this->fields as $field) { $fields[] = $field['Field']; } return $fields; } else { if ($key == 'primary' && !empty($this->fields)) { $pri = array(); foreach ($this->fields as $field) { if ($field['Key'] == 'PRI') { $pri[] = $field['Field']; } } return $pri; } else { if (!empty($this->fields)) { foreach ($this->fields as $field) { if ($field['Field'] == $key) { return $field; } } } return null; } } } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $routeName = 'source'; $routeMethod = 'edit'; $source = $this->source->getById($id); $data = compact('routeName', 'routeMethod', 'source'); \Clockwork::info($source); return view('admin.sections.source.edit', $data); }