protected function checkPermissions($action, $params) { try { $permissions = array(); if (!empty($this->permissions)) { foreach ($this->permissions as $key => $value) { if ($action === $key) { $permissions = array_merge($permissions, (array) $value); } elseif (substr($key, 0, 1) === '^' && $action !== substr($key, 1)) { $permissions = array_merge($permissions, (array) $value); } elseif (is_numeric($key)) { $permissions = array_merge($permissions, (array) $value); } } } if (!empty($permissions)) { Account::validate($permissions); } parent::beforeAction($action, $params); } catch (LoginRequiredException $e) { $loginUrl = array('route://admin_login', array('redirect' => \Simplify::request()->base() . \Simplify::request()->uri())); \Simplify::response()->redirect($loginUrl); } catch (SecurityException $e) { \Simplify::session()->warnings($e->getMessage()); \Simplify::response()->redirect('route://admin'); } }
/** * Instantiate a view * * @param string $class * @param RenderableInterface $object * @return ViewInterface */ public static function factory($class = null, RenderableInterface $object = null) { if (empty($class)) { $class = \Simplify::config()->get('view:default', View::TWIG, \Simplify\Dictionary::FILTER_EMPTY); } return new $class($object); }
/** * * @return \Simplify\Router */ public static function router() { if (!self::$router) { self::$router = new Simplify\Router(); } return self::$router; }
static function line($pointList, $epsilon) { // Find the point with the maximum distance $dmax = 0; $index = 0; $totalPoints = count($pointList); for ($i = 1; $i < $totalPoints - 1; $i++) { $d = Simplify::perpendicularDistance($pointList[$i]['x'], $pointList[$i]['y'], $pointList[0]['x'], $pointList[0]['y'], $pointList[$totalPoints - 1]['x'], $pointList[$totalPoints - 1]['y']); if ($d > $dmax) { $index = $i; $dmax = $d; } } $resultList = array(); // If max distance is greater than epsilon, recursively simplify if ($dmax >= $epsilon) { // Recursive call $recResults1 = Simplify::line(array_slice($pointList, 0, $index + 1), $epsilon); $recResults2 = Simplify::line(array_slice($pointList, $index, $totalPoints - $index), $epsilon); // Build the result list $resultList = array_merge(array_slice($recResults1, 0, count($recResults1) - 1), array_slice($recResults2, 0, count($recResults2))); } else { $resultList = array($pointList[0], $pointList[$totalPoints - 1]); } // Return the result return $resultList; }
/** * Init Simplify SDK. */ protected function init_simplify_sdk() { // Include lib require_once dirname(__FILE__) . '/includes/Simplify.php'; Simplify::$publicKey = $this->public_key; Simplify::$privateKey = $this->private_key; Simplify::$userAgent = 'WooCommerce/' . WC()->version; }
/** * (non-PHPdoc) * @see Localization::add() */ public function add($name, $domain = Localization::DOMAIN_DEFAULT) { $filename = \Simplify::config()->get('locale_dir', \Simplify::config()->get('app:dir') . '/language', Dictionary::FILTER_EMPTY); $filename .= '/' . $this->locale . '/' . $domain . '.php'; if (file_exists($filename)) { $lang = (require_once $filename); $this->lang[$domain] = array_merge((array) $this->lang[$domain], (array) $lang); } }
/** * * @return mixed[string] */ public function getOptions() { if ($this->options === false) { $options = \Simplify::db()->query()->from($this->form->getTable())->select($this->getFieldName())->orderBy($this->getFieldName())->execute()->fetchCol(); $options = array_combine($options, $options); } else { $options = (array) $this->options; } return $options; }
/** * Return a new instance of \Simplify\Thumb with optional params * * @param mixed $params * @return \Simplify\Thumb */ public static function factory($params = null) { $thumb = new self(); if ($params !== false) { $thumb->baseDir = sy_get_param($params, 'baseDir', \Simplify::config()->get('www_dir')); $thumb->filesPath = sy_get_param($params, 'filesPath', \Simplify::config()->get('files_path')); $thumb->cachePath = sy_get_param($params, 'cachePath', $thumb->filesPath . 'cache/'); } return $thumb; }
/** * (non-PHPdoc) * * @see Form_Action::onExecute() */ public function onExecute() { parent::onExecute(); $this->onLoadData(); $this->onValidate(); foreach ($this->formData as $row) { $this->form->dispatch(\Simplify\Form::ON_BEFORE_DELETE, $this, $row); } if (\Simplify::request()->method(\Simplify\Request::POST) && \Simplify::request()->post('deleteAction') == 'confirm') { $this->onDelete(); return \Simplify\Form::RESULT_SUCCESS; } }
/** * (non-PHPdoc) * * @see \Simplify\Form\Provider::getData() */ public function getData() { if ($this->data === false) { $query = $this->query; if (is_array($query)) { $query = \Simplify::db()->query()->select($this->value)->select($this->label)->setParams($query); } elseif (is_string($query)) { $query = \Simplify::db()->query()->select($this->value)->select($this->label)->from($query); } $data = $query->execute()->fetchAll(); $this->data = sy_array_to_options($data, $this->value, $this->label); } return $this->data; }
/** * (non-PHPdoc) * * @see \Simplify\Controller::indexAction() */ protected function indexAction() { try { $this->Form = new \Simplify\Form('options', __('Opções')); $this->Form->showMenu = false; $this->Form->addAction(new \Simplify\Form\Action\Config('config', __('Gerais'), \Simplify::config()->get('amp:tables:options'), 'option_name', 'option_value')); $this->Form->addElement(new \Simplify\Form\Element\Text('site_name', __('Nome do site')), \Simplify\Form::ACTION_CONFIG); $url = new \Simplify\Form\Element\Text('site_url', __('URL do site')); $this->Form->addElement($url, \Simplify\Form::ACTION_CONFIG); $this->Form->execute(); } catch (\Simplify\ValidationException $e) { \Simplify::session()->warnings(__('Ocorreram erros')); } $this->set('formBody', $this->Form->render()); }
public function match($uri) { if (isset($this->options['method']) && !preg_match('#^' . $this->options['method'] . '$#i', Simplify::request()->method())) { return false; } if (!preg_match($this->regex, $uri, $found)) { throw new RouterException("Route does not match uri: <b>{$uri}</b>"); } array_shift($found); $params = $this->defaults; foreach ($this->names as $i => $name) { $params[$name] = sy_get_param($found, $i, sy_get_param($this->defaults, $name)); } return new MatchedRoute($this, $params, $uri); }
protected function indexAction() { if (\Simplify::request()->get('activate')) { \Amplify\Modules::activateModule(\Simplify::request()->get('module')); \Simplify::response()->redirect(\Simplify::request()->route()); } elseif (\Simplify::request()->get('deactivate')) { \Amplify\Modules::deactivateModule(\Simplify::request()->get('module')); \Simplify::response()->redirect(\Simplify::request()->route()); } try { $modules = \Amplify\Modules::getAllModules(); $this->set('modules', $modules); } catch (AmplifyException $e) { // } }
/** * (non-PHPdoc) * @see \Simplify\Form::execute() */ public function execute($action = null) { $Action = $this->getAction($action); /** * * order * */ if ($Action->show(\Simplify\Form::ACTION_LIST)) { $Action->limit = false; $listAction = \Simplify::request()->get('listAction'); if ($listAction == self::LIST_ACTION_SORT) { $id = \Simplify::request()->get(\Simplify\Form::ID); $index = \Simplify::request()->get('index'); $this->repository()->moveTo($id, $index); } } return parent::execute($action); }
function upload() { require_once APPPATH . 'third_party/ShapeFile.php'; require_once APPPATH . 'third_party/Simplify.php'; $options = array('noparts' => false); try { $shp = new ShapeFile($_FILES['shp_file']['tmp_name'], null, $options); $polygons = array(); while ($record = $shp->getNext()) { $shpData = $record->getShpData(); foreach ($shpData['parts'] as $part) { $polygons[] = Simplify::line($part['points'], count($part['points']) / 1000000); } } } catch (Exception $e) { $this->session->set_flashdata('error', $e->getMessage()); } $this->user_polygons_model->save(array('user_id' => $this->tank_auth->get_user_id(), 'name' => $_FILES['shp_file']['name'], 'points' => json_encode($polygons))); redirect('/areas'); }
/** * (non-PHPdoc) * @see \Simplify\Application::outputResponse() */ protected function outputResponse($output) { if (defined('SY_IN_ADMIN') && $output instanceof \Simplify\View) { if (\Amplify\Install::installed() && !$output instanceof \Simplify\View\Json) { $output->set('user', \Amplify\Account::getUser()); $output->set('menu', $this->menu()); AssetManager::load('fancybox/jquery.fancybox.css', 'vendor'); AssetManager::load('fancybox/jquery.fancybox.pack.js', 'vendor'); AssetManager::load('amplify.js', 'app'); } if (\Simplify::session()->warnings()) { $output->set('warnings', \Simplify::session()->warnings()); } if (\Simplify::session()->notices()) { $output->set('notices', \Simplify::session()->notices()); } \Simplify::session()->clearMessages(); } return parent::outputResponse($output); }
protected function buildPermalink(Action $action, $data, $post) { $id = $action->form->getId(); $id = $id[0]; $perma = call_user_func($this->callback, $data, $post); $perma = sy_slugify($perma); $pk = $action->form->getPrimaryKey(); $table = $action->form->getTable(); $field = $this->getFieldName(); $i = 0; do { $c = $i ? '-' . $i : ''; $sql = "SELECT {$pk} FROM {$table} WHERE {$field} LIKE '{$perma}{$c}'"; if ($id) { $sql .= " AND {$pk} != {$id}"; } $_row = \Simplify::db()->query($sql)->execute()->fetchOne(); $i++; } while (!empty($_row) && $i < 10); $perma .= $c; return $perma; }
protected function indexAction() { $username = ''; $email = ''; $password = ''; if (\Simplify::request()->method(\Simplify\Request::POST)) { try { $username = \Simplify::request()->post('username'); $email = \Simplify::request()->post('email'); $password = \Simplify::request()->post('password'); \Amplify\Install::performInstall($username, $email, $password); \Simplify::session()->notices(__('Instalação realizada com sucesso.')); $url = \Simplify::request()->get('redirect', \Simplify::router()->make('admin')); \Simplify::response()->redirect($url); } catch (\Simplify\ValidationException $e) { \Simplify::session()->warnings($e->getErrors()); } } $this->set('username', $username); $this->set('email', $email); $this->set('password', $password); }
/** * * @return string */ protected function filter() { if ($this->sortGroupColumn) { if (!\Simplify::request()->get()->has($this->sortGroupColumn)) { throw new \Exception("Missing sort group column value"); } $value = \Simplify::request()->get($this->sortGroupColumn); $value = \Simplify::db()->quote($value); $filter = " {$this->sortGroupColumn} = {$value} "; return $filter; } return ' TRUE '; }
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* Instructions: * 1. Replace public key and private key with your respective API keys * 2. This sample code charges $10 to the card token submitted. You can pass the charge parameter by uncommenting * the charge parameter */ header('Content-Type: application/json'); error_reporting(E_ALL); require_once "./lib/Simplify.php"; Simplify::$publicKey = 'YOUR_PUBLIC_API_KEY'; // such as 'sbpb_MzIxYmFjYzItYThiYS00ZDA3LTllZTctY2ZjYjIxY2QzYWMw'; Simplify::$privateKey = 'YOUR_PRIVATE_API_KEY'; // such as 'gEEh+NSgYUi4dqG+u3F3iTuOK4n1L01StM60skz7CUR5YFFQL0ODSXAOkNtXTToq'; $token = $_POST['simplifyToken']; //You can get the charge from the client by uncommenting line below // $charge = $_POST['charge']; $charge = 1000; // charges $10 $c = array('amount' => $charge, 'token' => $token, 'description' => 'product description', 'currency' => 'USD'); try { $charge = Simplify_Payment::createPayment($c); $chargeId = $charge->{'id'}; echo $charge->{'paymentStatus'} . " charged :" . $charge->{'amount'} / 100; } catch (Exception $e) { echo ' Caught exception: ', $e->getMessage(), "\n", $e; }
<?php require_once "./lib/Simplify.php"; Simplify::$publicKey = 'sbpb_YmFhN2JmZTMtZDBkZi00MzA5LWI5M2EtYTBjNjlkNTE3ZTVm'; Simplify::$privateKey = 'Eu/MTPwWMsL97YuJ5XCI8oIW0Sl7uGskdUbY4VXsWsx5YFFQL0ODSXAOkNtXTToq'; $plan = Simplify_Plan::createPlan(array('amount' => '1000', 'renewalReminderLeadDays' => '7', 'name' => 'plan2', 'billingCycle' => 'FIXED', 'frequency' => 'WEEKLY', 'billingCycleLimit' => '4', 'frequencyPeriod' => '2')); print_r($plan); print_r($plan->id); ?>
public function createRepository() { $create = ' CREATE TABLE `%1$s` ( `%2$s` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT, `%3$s` MEDIUMINT(8) UNSIGNED NOT NULL, `%4$s` MEDIUMINT(8) UNSIGNED NOT NULL, `%5$s` MEDIUMINT(8) UNSIGNED NOT NULL, PRIMARY KEY (`%2$s`), INDEX `tree_parent_id` (`%3$s`), INDEX `tree_left_id` (`%4$s`), INDEX `tree_right_id` (`%5$s`) ) COLLATE=\'utf8_general_ci\' ENGINE=InnoDB '; $sql = sprintf($create, $this->table, $this->pk, $this->parent, $this->left, $this->right); if (\Simplify::db()->query($sql)->executeRaw() === false) { throw new \Simplify\Db\DatabaseException('Could not create table'); } }
<?php $points = array(array('x' => 224.55, 'y' => 250.15), array('x' => 226.91, 'y' => 244.19), array('x' => 233.31, 'y' => 241.45), array('x' => 234.98, 'y' => 236.06), array('x' => 244.21, 'y' => 232.76), array('x' => 262.59, 'y' => 215.31), array('x' => 267.76, 'y' => 213.81), array('x' => 273.57, 'y' => 201.84), array('x' => 273.12, 'y' => 192.16), array('x' => 277.62, 'y' => 189.03), array('x' => 280.36, 'y' => 181.41), array('x' => 286.51, 'y' => 177.74), array('x' => 292.41, 'y' => 159.37), array('x' => 296.91, 'y' => 155.64), array('x' => 314.95, 'y' => 151.37), array('x' => 319.75, 'y' => 145.16), array('x' => 330.33, 'y' => 137.57), array('x' => 341.48, 'y' => 139.96), array('x' => 369.98, 'y' => 137.89), array('x' => 387.39, 'y' => 142.51), array('x' => 391.28, 'y' => 139.39), array('x' => 409.52, 'y' => 141.14), array('x' => 414.82, 'y' => 139.75), array('x' => 427.72, 'y' => 127.3), array('x' => 439.6, 'y' => 119.74), array('x' => 474.93, 'y' => 107.87), array('x' => 486.51, 'y' => 106.75), array('x' => 489.2, 'y' => 109.45), array('x' => 493.79, 'y' => 108.63), array('x' => 504.74, 'y' => 119.66), array('x' => 512.96, 'y' => 122.35), array('x' => 518.63, 'y' => 120.89), array('x' => 524.09, 'y' => 126.88), array('x' => 529.5700000000001, 'y' => 127.86), array('x' => 534.21, 'y' => 140.93), array('x' => 539.27, 'y' => 147.24), array('x' => 567.6900000000001, 'y' => 148.91), array('x' => 575.25, 'y' => 157.26), array('x' => 580.62, 'y' => 158.15), array('x' => 601.53, 'y' => 156.85), array('x' => 617.74, 'y' => 159.86), array('x' => 622.0, 'y' => 167.04), array('x' => 629.55, 'y' => 194.6), array('x' => 638.9, 'y' => 195.61), array('x' => 641.26, 'y' => 200.81), array('x' => 651.77, 'y' => 204.56), array('x' => 671.55, 'y' => 222.55), array('x' => 683.6799999999999, 'y' => 217.45), array('x' => 695.25, 'y' => 219.15), array('x' => 700.64, 'y' => 217.98), array('x' => 703.12, 'y' => 214.36), array('x' => 712.26, 'y' => 215.87), array('x' => 721.49, 'y' => 212.81), array('x' => 727.8099999999999, 'y' => 213.36), array('x' => 729.98, 'y' => 208.73), array('x' => 735.3200000000001, 'y' => 208.2), array('x' => 739.9400000000001, 'y' => 204.77), array('x' => 769.98, 'y' => 208.42), array('x' => 779.6, 'y' => 216.87), array('x' => 784.2, 'y' => 218.16), array('x' => 800.24, 'y' => 214.62), array('x' => 810.53, 'y' => 219.73), array('x' => 817.1900000000001, 'y' => 226.82), array('x' => 820.77, 'y' => 236.17), array('x' => 827.23, 'y' => 236.16), array('x' => 829.89, 'y' => 239.89), array('x' => 851.0, 'y' => 248.94), array('x' => 859.88, 'y' => 255.49), array('x' => 865.21, 'y' => 268.53), array('x' => 857.95, 'y' => 280.3), array('x' => 865.48, 'y' => 291.45), array('x' => 866.8099999999999, 'y' => 298.66), array('x' => 864.6799999999999, 'y' => 302.71), array('x' => 867.79, 'y' => 306.17), array('x' => 859.87, 'y' => 311.37), array('x' => 860.08, 'y' => 314.35), array('x' => 858.29, 'y' => 314.94), array('x' => 858.1, 'y' => 327.6), array('x' => 854.54, 'y' => 335.4), array('x' => 860.92, 'y' => 343.0), array('x' => 856.4299999999999, 'y' => 350.15), array('x' => 851.42, 'y' => 352.96), array('x' => 849.84, 'y' => 359.59), array('x' => 854.5599999999999, 'y' => 365.53), array('x' => 849.74, 'y' => 370.38), array('x' => 844.09, 'y' => 371.89), array('x' => 844.75, 'y' => 380.44), array('x' => 841.52, 'y' => 383.67), array('x' => 839.5700000000001, 'y' => 390.4), array('x' => 845.59, 'y' => 399.05), array('x' => 848.4, 'y' => 407.55), array('x' => 843.71, 'y' => 411.3), array('x' => 844.09, 'y' => 419.88), array('x' => 839.51, 'y' => 432.76), array('x' => 841.33, 'y' => 441.04), array('x' => 847.62, 'y' => 449.22), array('x' => 847.16, 'y' => 458.44), array('x' => 851.38, 'y' => 462.79), array('x' => 853.97, 'y' => 471.15), array('x' => 866.36, 'y' => 480.77)); $simplified = array(array('x' => 224.55, 'y' => 250.15), array('x' => 267.76, 'y' => 213.81), array('x' => 296.91, 'y' => 155.64), array('x' => 330.33, 'y' => 137.57), array('x' => 409.52, 'y' => 141.14), array('x' => 439.6, 'y' => 119.74), array('x' => 486.51, 'y' => 106.75), array('x' => 529.5700000000001, 'y' => 127.86), array('x' => 539.27, 'y' => 147.24), array('x' => 617.74, 'y' => 159.86), array('x' => 629.55, 'y' => 194.6), array('x' => 671.55, 'y' => 222.55), array('x' => 727.8099999999999, 'y' => 213.36), array('x' => 739.9400000000001, 'y' => 204.77), array('x' => 769.98, 'y' => 208.42), array('x' => 779.6, 'y' => 216.87), array('x' => 800.24, 'y' => 214.62), array('x' => 820.77, 'y' => 236.17), array('x' => 859.88, 'y' => 255.49), array('x' => 865.21, 'y' => 268.53), array('x' => 857.95, 'y' => 280.3), array('x' => 867.79, 'y' => 306.17), array('x' => 859.87, 'y' => 311.37), array('x' => 854.54, 'y' => 335.4), array('x' => 860.92, 'y' => 343.0), array('x' => 849.84, 'y' => 359.59), array('x' => 854.5599999999999, 'y' => 365.53), array('x' => 844.09, 'y' => 371.89), array('x' => 839.5700000000001, 'y' => 390.4), array('x' => 848.4, 'y' => 407.55), array('x' => 839.51, 'y' => 432.76), array('x' => 853.97, 'y' => 471.15), array('x' => 866.36, 'y' => 480.77)); require 'Simplify.php'; // TODO PHPUnit echo serialize($simplified) == serialize(Simplify::run($points, 5)) ? 'pass' : 'fail'; echo PHP_EOL;
/** * * @param unknown_type $data * @return multitype:multitype:Ambigous <unknown, ArrayAccess> multitype:unknown */ public function getOptions($data) { $t = $this->getTable(); $pk = $this->getPrimaryKey(); $fk = $this->getForeignKey(); $at = $this->getAssociationTable(); $apk = $this->getAssociationPrimaryKey(); $afk = $this->getAssociationForeignKey(); $q = \Simplify::db()->query()->select("{$t}.{$fk}")->select("{$t}.{$this->labelField}")->select("{$at}.{$afk} AS checked")->from($t)->leftJoin("{$at} ON ({$t}.{$fk} = {$at}.{$afk} AND {$at}.{$apk} = :{$pk})"); $data = $q->execute(array($pk => $data[\Simplify\Form::ID]))->fetchAll(); $options = sy_array_to_options($data, $fk, $this->labelField); $checked = array(); foreach ($data as $row) { if ($row['checked']) { $checked[] = $row[$fk]; } } return array('options' => $options, 'checked' => $checked); }
/** * * @return \Simplify\MatchedRoute */ protected function parseRoute() { return \Simplify::router()->parse(); }
public static function addGroupPermission($group_id, $permission_id) { if (is_string($permission_id)) { $permission_id = \Simplify::db()->query()->from(\Simplify::config()->get('amp:tables:permissions'))->select('permission_id')->where('permission_name = ?')->execute($permission_id)->fetchOne(); if (empty($permission_id)) { throw new \Exception("Could not add group permission: invalid permission id"); } } $data = array('permission_id' => $permission_id, 'group_id' => $group_id); \Simplify::db()->query('INSERT IGNORE INTO ' . \Simplify::config()->get('amp:tables:groups_permissions') . ' VALUES (:permission_id, :group_id)')->execute($data); }
/** * (non-PHPdoc) * @see Component::getValue() */ public function getValue() { return $this->editable ? \Simplify::request()->get($this->getName(), $this->getDefaultValue()) : $this->getDefaultValue(); }
<?php if (!defined('SY_APP_DIR')) { die; } /** * routes */ Simplify::router()->match('/', array('controller' => 'HomeController', 'action' => 'index', 'as' => 'home'));
protected static function loadExtensions(\Twig_Environment $twig) { foreach ((array) \Simplify::config()->get('view:twig:globals') as $name => $value) { $twig->addGlobal($name, $value); } $twig->addGlobal('config', \Simplify::config()); $twig->addGlobal('request', \Simplify::request()); $twig->addGlobal('router', \Simplify::router()); $twig->addFunction(new \Twig_SimpleFunction('makeUrl', array('\\Simplify\\URL', 'make'))); $twig->addFunction(new \Twig_SimpleFunction('optionsValue', array('\\Amplify\\Options', 'value'))); $twig->addFunction(new \Twig_SimpleFunction('thumb', array('\\Simplify\\Thumb', 'factory'))); $twig->addFunction(new \Twig_SimpleFunction('asset', array('\\Simplify\\AssetManager', 'asset'))); $twig->addFunction(new \Twig_SimpleFunction('assets', array('\\Simplify\\AssetManager', 'assets'))); $twig->addFilter(new \Twig_SimpleFilter('truncate', 'sy_truncate')); }
/** * * @return \Simplify\URL */ public function url() { if (empty($this->url)) { $this->url = new URL(null, array('formAction' => \Simplify::request()->get('formAction'))); } return $this->url; }