コード例 #1
0
 public function testDataInsideHelper()
 {
     echo returns($this->Captcha->webroot);
     echo returns($this->Captcha->request->webroot);
     echo returns($this->Captcha->data);
     echo returns($this->Captcha->request->data);
 }
コード例 #2
0
 /**
  * Compare two sets
  *
  * @return void
  */
 public function compare()
 {
     if (count($this->args) !== 2) {
         return $this->error('left and right are required.');
     }
     $left = realpath($this->args[0]);
     $right = realpath($this->args[1]);
     if (!$left || !$right) {
         return $this->error('left or right is invalid.');
     }
     $content = file_get_contents($left);
     preg_match_all('/\\.(icon-[a-z0-9-]+)\\s*\\:/', $content, $matches);
     if (!$matches) {
         return $this->error('invalid left');
     }
     $matchesLeft = $matches[1];
     $content = file_get_contents($right);
     preg_match_all('/\\.(icon-[a-z0-9-]+)\\s*\\:/', $content, $matches);
     if (!$matches) {
         return $this->error('invalid right');
     }
     $matchesRight = $matches[1];
     $diffLeft = array();
     foreach ($matchesRight as $m) {
         if (!in_array($m, $matchesLeft)) {
             continue;
         }
         $diffLeft[] = $m;
     }
     //$diffRight =
     //echo returns($diffLeft);
     $this->out('Common icons (overlapping classes):');
     echo returns($diffLeft);
 }
コード例 #3
0
 /**
  * AuthExtComponentTest::_testCompleteAuth()
  *
  * @return void
  */
 public function _testCompleteAuth()
 {
     $is = $this->Controller->TestAuthExt->completeAuth(1);
     debug($is);
     $this->assertTrue(!empty($is));
     $is = $this->Controller->TestAuthExt->completeAuth(111);
     echo returns($is);
     $this->assertFalse($is);
 }
コード例 #4
0
ファイル: QloginTest.php プロジェクト: robksawyer/grabitdown
 public function testUse()
 {
     $key = $this->Qlogin->generate(array('controller' => 'test', 'action' => 'foo', 'bar'), 1);
     $res = $this->Qlogin->translate($key);
     echo returns($res);
     pr($res);
     $key = $this->Qlogin->generate('/test/foo/bar', 2);
     $res = $this->Qlogin->translate($key);
     echo returns($res);
     pr($res);
 }
コード例 #5
0
 public function testFieldsWithParam()
 {
     echo $this->_header(__FUNCTION__);
     $this->Comment->Behaviors->detach('Jsonable');
     $this->Comment->Behaviors->attach('Jsonable', array('fields' => array('details'), 'input' => 'param'));
     $data = array('comment' => 'blabla', 'url' => 'www.dereuromark.de', 'name' => 'some Name', 'details' => 'z:vz|y:yz|x:xz');
     $res = $this->Comment->save($data);
     $this->assertTrue($res);
     $res = $this->Comment->data;
     echo returns($res);
     $this->assertIdentical($res['JsonableTestModel']['details'], '{"z":"vz","y":"yz","x":"xz"}');
 }
コード例 #6
0
ファイル: geocoder.test.php プロジェクト: robksawyer/tools
 function testMinIncAllowed()
 {
     $this->Comment->Behaviors->detach('Geocoder');
     $this->Comment->Behaviors->attach('Geocoder', array('real' => false, 'allow_inconclusive' => true));
     // accuracy = 1
     $data = array('city' => 'Neustadt');
     $res = $this->Comment->save($data);
     echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()) . BR;
     echo returns($this->Comment->Behaviors->Geocoder->Geocode->url()) . BR;
     echo returns($this->Comment->Behaviors->Geocoder->Geocode->getResult()) . BR;
     echo returns($res);
     //echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
     $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
 }
コード例 #7
0
 function testFetch()
 {
     $url = 'http://maps.google.de';
     $is = $this->HttpSocketLib->fetch($url);
     //echo returns($is);
     $this->assertTrue(!empty($is));
     $url = 'http://sscfmaps.sfdgoogle.eede';
     $is = $this->HttpSocketLib->fetch($url);
     echo returns($is);
     $this->assertFalse($is);
     $error = $this->HttpSocketLib->error();
     echo returns($error);
     $this->assertTrue(!empty($error));
     $this->assertEqual($this->HttpSocketLib->debug, 'curl');
 }
コード例 #8
0
 public function testFind()
 {
     echo $this->_header(__FUNCTION__);
     $res = $this->Comment->find('all', array());
     $this->assertTrue(!empty($res));
     echo returns($res);
     $this->assertSame($res[0]['TestModel']['set_rate'], '0,1');
     $this->assertSame($res[0]['TestModel']['rel_rate'], '-0,02');
     echo BR . BR;
     $res = $this->Comment->find('first', array());
     $this->assertTrue(!empty($res));
     echo returns($res);
     $this->assertSame($res['TestModel']['set_rate'], '0,1');
     $this->assertSame($res['TestModel']['rel_rate'], '-0,02');
     $res = $this->Comment->find('count', array());
     echo returns($res);
     $this->assertSame($res[0][0]['count'], 2);
 }
コード例 #9
0
 function testStatic()
 {
     echo '<h2>StaticMap</h2>';
     $m = array(array('address' => 'Berlin', 'color' => 'yellow', 'char' => 'Z', 'shadow' => 'true'), array('lat' => '44.2', 'lng' => '11.1', 'color' => '#0000FF', 'char' => '1', 'shadow' => 'false'));
     $options = array('markers' => $this->GoogleMapV3->staticMarkers($m));
     echo returns(h($options['markers'])) . BR;
     $is = $this->GoogleMapV3->staticMapUrl($options);
     echo h($is);
     echo BR . BR;
     $is = $this->GoogleMapV3->staticMapLink('MyLink', $options);
     echo h($is);
     echo BR . BR;
     $is = $this->GoogleMapV3->staticMap($options);
     echo h($is) . BR;
     echo $is;
     echo BR . BR;
     $options = array('size' => '200x100', 'center' => true);
     $is = $this->GoogleMapV3->staticMapLink('MyTitle', $options);
     echo h($is);
     echo BR . BR;
     $attr = array('title' => 'Yeah');
     $is = $this->GoogleMapV3->staticMap($options, $attr);
     echo h($is) . BR;
     echo $is;
     echo BR . BR;
     $pos = array(array('lat' => 48.1, 'lng' => '11.1'), array('lat' => 48.2, 'lng' => '11.2'));
     $options = array('markers' => $this->GoogleMapV3->staticMarkers($pos));
     $attr = array('url' => $this->GoogleMapV3->url(array('to' => 'Munich, Germany')));
     $is = $this->GoogleMapV3->staticMap($options, $attr);
     echo h($is) . BR;
     echo $is;
     echo BR . BR . BR;
     $url = $this->GoogleMapV3->url(array('to' => 'Munich, Germany'));
     $attr = array('title' => 'Yeah');
     $image = $this->GoogleMapV3->staticMap($options, $attr);
     $link = $this->GoogleMapV3->Html->link($image, $url, array('escape' => false, 'target' => '_blank'));
     echo h($link) . BR;
     echo $link;
 }
コード例 #10
0
 /**
  * Put money into the prepaid account
  * @param $uid Id of user owning the account
  * @param $amount Amount of money at the beginning
  * @return boolean If $amount was successfully deposited
  * @author gh 2011-09-13
  */
 public function deposit($uid, $amount, $transaction = true)
 {
     if ($this->Behaviors->loaded('Loadable') && ($finalAmount = $this->finalAmount($amount))) {
         $amount = $finalAmount;
     }
     $account = $this->account($uid);
     $account[$this->alias]['amount'] += $amount;
     $this->set($account);
     $this->id = $account[$this->alias]['id'];
     $this->enableLog(false);
     $res = $this->save();
     $this->enableLog(true);
     if (!$res) {
         die(returns($this->validationErrors));
         return false;
     }
     $title = __('prepaidAccountDepositTitle');
     $this->customLog(__('deposited') . ' (' . number_format($amount, 2) . ')', $this->id, array('title' => $title));
     if ($transaction) {
         $this->Transaction = ClassRegistry::init('Payment.Transaction');
         $data = array('title' => $title, 'model' => $this->alias, 'foreign_id' => $this->id, 'status' => Transaction::STATUS_COMPLETED, 'amount' => $amount);
         if (is_array($transaction)) {
             $data = array_merge($data, $transaction);
         }
         $this->Transaction->initCustom('prepaid', $data);
     }
     return true;
 }
コード例 #11
0
ファイル: app_model.test.php プロジェクト: robksawyer/tools
 function testAppValidateTime()
 {
     $this->out($this->_header(__FUNCTION__));
     $data = array('field' => '11:21:11');
     $res = $this->App->validateTime($data);
     $this->out(returns($res));
     $this->assertTrue($res);
     $data = array('field' => '11:71:11');
     $res = $this->App->validateTime($data);
     $this->out(returns($res));
     $this->assertFalse($res);
     $this->App->data = array($this->App->alias => array('before' => '2010-02-23 11:11:12'));
     $data = array('field' => '2010-02-23 11:11:11');
     $res = $this->App->validateTime($data, array('before' => 'before'));
     $this->out(returns($res));
     $this->assertTrue($res);
     $this->App->data = array($this->App->alias => array('after' => '2010-02-23 11:11:12'));
     $data = array('field' => '2010-02-23 11:11:11');
     $res = $this->App->validateTime($data, array('after' => 'after'));
     $this->out(returns($res));
     $this->assertFalse($res);
 }
コード例 #12
0
ファイル: services.php プロジェクト: EpykOS/mds
<?php

require 'core/core.php';
require 'model/model.php';
returns(success($services()));
コード例 #13
0
ファイル: geocode_lib.test.php プロジェクト: robksawyer/tools
 function testReverseGeocode()
 {
     $coords = array(array(-34.594445, -58.37446, 'Florida 1134-1200, Buenos Aires, Capital Federal, Argentinien'), array(48.8934, 8.70492, 'Bahnhofplatz 1, 75175 Pforzheim, Deutschland'));
     foreach ($coords as $coord) {
         $is = $this->GeocodeLib->reverseGeocode($coord[0], $coord[1]);
         echo returns($is);
         $this->assertTrue($is);
         $is = $this->GeocodeLib->getResult();
         $this->assertTrue(!empty($is));
         echo returns($is);
         $address = isset($is[0]) ? $is[0]['formatted_address'] : $is['formatted_address'];
         $this->assertEqual($coord[2], $address);
     }
 }
コード例 #14
0
ファイル: bootstrap.php プロジェクト: Jony01/LLD
/**
 * Shows pr() messages, even with debug = 0.
 * Also allows additional customization.
 *
 * @param mixed $content
 * @param bool $collapsedAndExpandable
 * @param array $options
 * - class, showHtml, showFrom, jquery, returns, debug
 * @return string HTML
 */
function pre($var, $collapsedAndExpandable = false, $options = array())
{
    $defaults = array('class' => 'cake-debug', 'showHtml' => false, 'showFrom' => false, 'jquery' => null, 'returns' => false, 'debug' => false);
    $options += $defaults;
    if ($options['debug'] && !Configure::read('debug')) {
        return '';
    }
    if (php_sapi_name() === 'cli') {
        return sprintf("\n%s\n", $options['returns'] ? returns($var) : print_r($var, true));
    }
    $res = '<div class="' . $options['class'] . '">';
    $pre = '';
    if ($collapsedAndExpandable) {
        $js = 'if (this.parentNode.getElementsByTagName(\'pre\')[0].style.display==\'block\') {this.parentNode.getElementsByTagName(\'pre\')[0].style.display=\'none\'} else {this.parentNode.getElementsByTagName(\'pre\')[0].style.display=\'block\'}';
        $jsJquery = 'jQuery(this).parent().children(\'pre\').slideToggle(\'fast\')';
        if ($options['jquery'] === true) {
            $js = $jsJquery;
        } elseif ($options['jquery'] !== false) {
            // auto
            $js = 'if (typeof jQuery == \'undefined\') {' . $js . '} else {' . $jsJquery . '}';
        }
        $res .= '<span onclick="' . $js . '" style="cursor: pointer; font-weight: bold">Debug</span>';
        if ($options['showFrom']) {
            $calledFrom = debug_backtrace();
            $from = '<em>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</em>';
            $from .= ' (line <em>' . $calledFrom[0]['line'] . '</em>)';
            $res .= '<div>' . $from . '</div>';
        }
        $pre = ' style="display: none"';
    }
    if ($options['returns']) {
        $var = returns($var);
    } else {
        $var = print_r($var, true);
    }
    $res .= '<pre' . $pre . '>' . $var . '</pre>';
    $res .= '</div>';
    return $res;
}
コード例 #15
0
ファイル: geocode_lib.php プロジェクト: robksawyer/tools
 /**
  * flattens result array and returns clean record
  * keys:
  * - formatted_address, type, country, country_code, country_province, country_province_code, locality, sublocality, postal_code, route, lat, lng, location_type, viewport, bounds
  * 2010-06-25 ms
  */
 function _transformXml($record)
 {
     $res = array();
     $components = array();
     if (!isset($record['AddressComponent'][0])) {
         $record['AddressComponent'] = array($record['AddressComponent']);
     }
     foreach ($record['AddressComponent'] as $c) {
         $types = array();
         if (isset($c['Type'])) {
             //!is_array($c['Type'])
             if (!is_array($c['Type'])) {
                 echo returns($record);
                 die;
             }
             $type = $c['Type'][0];
             array_shift($c['Type']);
             $types = $c['Type'];
         } else {
             $type = $c['type'];
         }
         if (array_key_exists($type, $components)) {
             $components[$type]['name'] .= ' ' . $c['long_name'];
             $components[$type]['abbr'] .= ' ' . $c['short_name'];
             $components[$type]['types'] += $types;
         }
         $components[$type] = array('name' => $c['long_name'], 'abbr' => $c['short_name'], 'types' => $types);
     }
     $res['formatted_address'] = $record['formatted_address'];
     $res['type'] = $this->_parse('type', $record);
     if (array_key_exists('country', $components)) {
         $res['country'] = $components['country']['name'];
         $res['country_code'] = $components['country']['abbr'];
     } else {
         $res['country'] = $res['country_code'] = '';
     }
     if (array_key_exists('administrative_area_level_1', $components)) {
         $res['country_province'] = $components['administrative_area_level_1']['name'];
         $res['country_province_code'] = $components['administrative_area_level_1']['abbr'];
     } else {
         $res['country_province'] = $res['country_province_code'] = '';
     }
     if (array_key_exists('postal_code', $components)) {
         $res['postal_code'] = $components['postal_code']['name'];
     } else {
         $res['postal_code'] = '';
     }
     if (array_key_exists('locality', $components)) {
         $res['locality'] = $components['locality']['name'];
     } else {
         $res['locality'] = '';
     }
     if (array_key_exists('sublocality', $components)) {
         $res['sublocality'] = $components['sublocality']['name'];
     } else {
         $res['sublocality'] = '';
     }
     if (array_key_exists('route', $components)) {
         $res['route'] = $components['route']['name'];
         if (array_key_exists('street_number', $components)) {
             $res['route'] .= ' ' . $components['street_number']['name'];
         }
     } else {
         $res['route'] = '';
     }
     //TODO: add more
     $res['lng'] = $record['Geometry']['Location']['lat'];
     $res['lat'] = $record['Geometry']['Location']['lng'];
     $res['location_type'] = $record['Geometry']['location_type'];
     if (!empty($record['Geometry']['Viewport'])) {
         $res['viewport'] = array('sw' => $record['Geometry']['Viewport']['Southwest'], 'ne' => $record['Geometry']['Viewport']['Northeast']);
     }
     if (!empty($record['Geometry']['Bounds'])) {
         $res['bounds'] = array('sw' => $record['Geometry']['Bounds']['Southwest'], 'ne' => $record['Geometry']['Bounds']['Northeast']);
     }
     return $res;
 }
コード例 #16
0
ファイル: features.php プロジェクト: EpykOS/mds
<?php

require 'core/core.php';
require 'model/model.php';
returns(success($features()));
コード例 #17
0
ファイル: dbdump.php プロジェクト: EpykOS/mds
    foreach ($dbo->query($sql) as $row) {
        $results[] = array("id" => (int) $row['id'], "name" => $row['name'], "email" => $row['email'], "password" => $row['password'], "verified" => $row['verified'], "facebook_id" => $row['facebook_id'], "linkedin_id" => $row['linkedin_id'], "twitter_id" => $row['twitter_id']);
    }
    return $results;
};
$user_features = function () use($dataBase) {
    $sql = "SELECT * FROM user_has_feature";
    $dbo = $dataBase();
    $results = array();
    foreach ($dbo->query($sql) as $row) {
        $results[] = array("user_id" => (int) $row['user_id'], "feature_id" => $row['feature_id'], "block" => $row['block'], "profit" => $row['profit']);
    }
    return $results;
};
$user_services = function () use($dataBase) {
    $sql = "SELECT * FROM user_has_service";
    $dbo = $dataBase();
    $results = array();
    foreach ($dbo->query($sql) as $row) {
        $results[] = array("user_id" => (int) $row['user_id'], "service_id" => $row['service_id'], "linked" => $row['linked'], "linked_data" => $row['linked_data'], "verified" => $row['verified']);
    }
    return $results;
};
$userTable = $users();
$featureTable = $features();
$serviceTable = $services();
$userFeaturesTable = $user_features();
$userServicesTable = $user_services();
$db = array('users' => $userTable, 'features' => $featureTable, 'user_features' => $userFeaturesTable, 'services' => $serviceTable, 'user_services' => $userServicesTable);
returns(success($db));
コード例 #18
0
ファイル: TextLib.php プロジェクト: robksawyer/grabitdown
 /**
  * @return array(char=>amount) for empty char or int amount for specific char
  * 2010-08-31 ms
  */
 public function maxOccurrences($caseSensitive = false)
 {
     $arr = $this->occurrences(null, $caseSensitive);
     $max = 0;
     $occ = array();
     foreach ($arr as $key => $value) {
         if ($value === $max) {
             $occ[$key] = $value;
         } elseif ($value > $max) {
             $max = $value;
             $occ = array($key => $value);
         }
     }
     echo returns($occ);
     return $occ;
 }
コード例 #19
0
 /**
  * Should only be done once at the very beginning
  */
 public function import_from_core()
 {
     if (!empty($this->request->params['named']['reset'])) {
         $this->Languages->truncate();
     }
     //$languages = $this->Languages->iso3ToIso2();
     $languages = $this->Languages->catalog();
     $count = 0;
     $errors = [];
     foreach ($languages as $language) {
         if (!($code = $this->Languages->iso3ToIso2($language['localeFallback']))) {
             $code = '';
         }
         $data = ['name' => $language['language'], 'ori_name' => $language['language'], 'code' => $code, 'locale' => $language['locale'], 'locale_fallback' => $language['localeFallback'], 'direction' => $language['direction']];
         $this->Languages->create();
         if ($this->Languages->save($data)) {
             $count++;
         } else {
             $errors[] = ['data' => $language, 'errors' => $this->Languages->validationErrors];
         }
     }
     $this->Flash->success($count . ' of ' . count($languages) . ' ' . __('languages added'));
     $errorMessage = [];
     foreach ($errors as $error) {
         $errorMessage[] = $error['data']['language'] . ' (' . returns($error['errors']) . ')';
     }
     $this->Flash->warning(__('not added') . ' ' . implode(', ', $errorMessage));
     return $this->redirect(['action' => 'index']);
     //pr($errors);
 }
コード例 #20
0
ファイル: MyModelTest.php プロジェクト: Jony01/LLD
 /**
  * Test auto inc value of the current table
  *
  * @return void
  */
 public function testGetNextAutoIncrement()
 {
     $this->db = ConnectionManager::getDataSource('test');
     $this->skipIf(!$this->db instanceof Mysql, 'The test is only compatible with Mysql.');
     $is = $this->User->getNextAutoIncrement();
     $this->out(returns($is));
     $schema = $this->User->schema('id');
     if ($schema['length'] == 36) {
         $this->assertFalse($is);
     } else {
         $this->assertTrue(is_int($is));
     }
 }
コード例 #21
0
 /**
  * Lat and lng + abbr if available!
  *
  * @param id
  * - NULL: update all records with missing coordinates only
  * - otherwise: specific update
  */
 public function updateCoordinates($id = null)
 {
     $geocoder = new GeocodeLib();
     $override = false;
     if ($id == -1) {
         $id = '';
         $override = true;
     }
     if (!empty($id)) {
         $res = $this->find('first', ['conditions' => [$this->alias() . '.id' => $id], 'contain' => ['Country.name']]);
         if (!empty($res['name']) && !empty($res[$this->Country->alias]['name']) && $geocoder->geocode($res['name'] . ', ' . $res[$this->Country->alias]['name'])) {
             $data = $geocoder->getResult();
             //pr($data); die();
             $saveArray = ['id' => $id, 'lat' => $data['lat'], 'lng' => $data['lng'], 'country_id' => $res['country_id']];
             if (!empty($data['country_province_code']) && mb_strlen($data['country_province_code']) <= 3 && preg_match('/^([A-Z])*$/', $data['country_province_code'])) {
                 $saveArray['abbr'] = $data['country_province_code'];
             }
             $this->id = $id;
             if (!$this->save($saveArray, true, ['id', 'lat', 'lng', 'abbr', 'country_id'])) {
                 if ($data['country_province_code'] !== 'DC') {
                     /*
                     echo returns($this->id);
                     pr($res);
                     pr($data);
                     pr($saveArray);
                     die(returns($this->validationErrors));
                     */
                     throw new \Exception('Update Error');
                 }
             }
             return true;
         }
     } else {
         $conditions = [];
         if (!$override) {
             $conditions = [$this->alias() . '.lat' => 0, $this->alias() . '.lng' => 0];
         }
         $results = $this->find('all', ['conditions' => $conditions, 'contain' => ['Country.name'], 'order' => ['CountryProvince.modified' => 'ASC']]);
         $count = 0;
         foreach ($results as $res) {
             if (!empty($res['name']) && !empty($res[$this->Country->alias]['name']) && $geocoder->geocode($res['name'] . ', ' . $res[$this->Country->alias]['name'])) {
                 $data = $geocoder->getResult();
                 //pr($data); die();
                 //pr ($geocoder->debug());
                 $saveArray = ['id' => $res['id'], 'country_id' => $res['country_id']];
                 if (isset($data['lat']) && isset($data['lng'])) {
                     $saveArray = array_merge($saveArray, ['lat' => $data['lat'], 'lng' => $data['lng']]);
                 }
                 if (!empty($data['country_province_code']) && mb_strlen($data['country_province_code']) <= 3 && preg_match('/^([A-Z])*$/', $data['country_province_code'])) {
                     $saveArray['abbr'] = $data['country_province_code'];
                 }
                 $this->id = $res['id'];
                 if ($this->save($saveArray, true, ['lat', 'lng', 'abbr', 'country_id'])) {
                     $count++;
                     if (!empty($saveArray['abbr']) && $saveArray['abbr'] != $res['abbr']) {
                         $this->log('Abbr for country province \'' . $data['country_province'] . '\' changed from \'' . $res['abbr'] . '\' to \'' . $saveArray['abbr'] . '\'', LOG_NOTICE);
                     }
                 } else {
                     //pr($data); pr($geocoder->debug()); die();
                     if ($data['country_province_code'] !== 'DC') {
                         echo returns($this->id);
                         pr($res);
                         pr($data);
                         pr($saveArray);
                         die(returns($this->validationErrors));
                     }
                 }
                 $geocoder->pause();
             }
         }
         return $count;
     }
     return false;
 }
コード例 #22
0
 public function getLastTransactions($limit = null)
 {
     $from = date(FORMAT_DB_DATE, time() - DAY);
     $to = date(FORMAT_DB_DATE);
     //die(returns($this->settings));
     $transactionDataObj = new SofortLib_TransactionData($this->_configKey());
     $transactionDataObj->setTime($from, $to);
     if ($limit) {
         $transactionDataObj->setNumber($limit);
     }
     $res = $transactionDataObj->sendRequest();
     if (!empty($res->errors)) {
         trigger_error(returns($this->errors));
         return false;
     }
     return $transactionDataObj->getTransaction(0);
 }
コード例 #23
0
 /**
  * Lat and lng + abbr if available!
  *
  * @param id
  * - NULL: update all records with missing coordinates only
  * - otherwise: specific update
  * @return bool Success
  */
 public function updateCoordinatesNew($id = null)
 {
     $Geocoder = new Geocode();
     $override = false;
     if ($id == -1) {
         $id = '';
         $override = true;
     }
     if (!empty($id)) {
         $res = $this->find('first', ['conditions' => [$this->alias() . '.id' => $id], 'contain' => []]);
         if (!empty($res['ori_name']) && $Geocoder->geocode($res['ori_name']) || $res['name'] != $res['ori_name'] && $Geocoder->geocode($res['name'])) {
             $data = $Geocoder->getResult();
             //pr($data); die();
             $saveArray = ['lat' => $data['lat'], 'lng' => $data['lng']];
             if (!empty($data['country_code']) && mb_strlen($data['country_code']) === 3 && preg_match('/^([A-Z])*$/', $data['country_code'])) {
                 $saveArray['iso3'] = $data['country_code'];
                 throw new \Exception(returns($saveArray));
             } elseif (!empty($data['country_code']) && mb_strlen($data['country_code']) === 2 && preg_match('/^([A-Z])*$/', $data['country_code'])) {
                 $saveArray['iso2'] = $data['country_code'];
                 throw new \Exception(returns($saveArray));
             }
             $this->id = $id;
             if (!$this->save($saveArray, true, ['lat', 'lng', 'iso2', 'iso3'])) {
                 //echo returns($this->id);
                 //pr($res); pr($data); pr($saveArray); die(returns($this->validationErrors));
                 throw new \Exception();
             }
             return true;
         }
     } else {
         $conditions = [];
         if (!$override) {
             $conditions = [$this->alias() . '.lat' => 0, $this->alias() . '.lng' => 0];
         }
         $results = $this->find('all', ['conditions' => $conditions, 'contain' => []]);
         $count = 0;
         foreach ($results as $res) {
             if (!empty($res['ori_name']) && $Geocoder->geocode($res['ori_name']) || $res['name'] != $res['ori_name'] && $Geocoder->geocode($res['name'])) {
                 $data = $Geocoder->getResult();
                 # seems to be very problematic: country "Georgien" results in "Georgia, USA"
                 $saveArray = [];
                 if (isset($data['lat']) && isset($data['lng'])) {
                     $saveArray = ['lat' => $data['lat'], 'lng' => $data['lng']];
                 }
                 if (!empty($data['country_code']) && mb_strlen($data['country_code']) === 3 && preg_match('/^([A-Z])*$/', $data['country_code'])) {
                     $saveArray['iso3'] = $data['country_code'];
                     //die(returns($saveArray));
                 } elseif (!empty($data['country_code']) && mb_strlen($data['country_code']) === 2 && preg_match('/^([A-Z])*$/', $data['country_code'])) {
                     $saveArray['iso2'] = $data['country_code'];
                     //die(returns($saveArray));
                 }
                 $this->id = $res['id'];
                 if ($this->save($saveArray, true, ['lat', 'lng', 'iso2', 'iso3'])) {
                     $count++;
                     if (!empty($saveArray['iso2']) && $saveArray['iso2'] != $res['iso2']) {
                         $this->log('Iso2 for country \'' . $data['country'] . '\' changed from \'' . $res['iso2'] . '\' to \'' . $saveArray['iso2'] . '\'', LOG_NOTICE);
                     }
                     if (!empty($saveArray['iso3']) && $saveArray['iso3'] != $res['iso3']) {
                         $this->log('Iso3 for country \'' . $data['country'] . '\' changed from \'' . $res['iso3'] . '\' to \'' . $saveArray['iso3'] . '\'', LOG_NOTICE);
                     }
                 } else {
                     //pr($data); pr($Geocoder->debug()); die();
                 }
                 $Geocoder->pause();
             }
         }
         return $count;
     }
     return false;
 }
コード例 #24
0
 /**
  *
  */
 public function admin_index()
 {
     App::import('Component', 'Payment.PaymentNetwork');
     $this->PaymentNetwork = new PaymentNetworkComponent($this->Components);
     $this->PaymentNetwork->initialize($this);
     $transactions = $this->PaymentNetwork->getLastTransactions();
     die(returns($transactions));
 }
コード例 #25
0
ファイル: register.php プロジェクト: EpykOS/mds
    }
    return true;
};
// Validates data
$validates = function ($json) {
    if ($json === NULL) {
        returns(error('Body request not found'));
        return false;
    }
    if (!isString($json->{'name'})) {
        returns(error('Name field is empty'));
        return false;
    }
    if (!isEmail($json->{'email'})) {
        returns(error('E-mail field is empty'));
        return false;
    }
    if (!isString($json->{'password'})) {
        returns(error('Password field is empty'));
        return false;
    }
    return true;
};
// Now, read it as a human and execute our orders :)
$theData = $jsonFrom($input());
if ($validates($theData)) {
    $token = $saves($theData);
    if ($sendmail($token, $theData->{'email'})) {
        returns(success());
    }
}
コード例 #26
0
 /**
  * array(Number=>..., Message=>...)
  */
 public function setError($error)
 {
     die(returns($error));
 }
コード例 #27
0
 /**
  * load money into prepaid account
  */
 public function deposit($id = null)
 {
     $this->PrepaidAccount->Behaviors->load('Payment.Loadable');
     $this->Common->loadComponent(array('Payment.Paypal'));
     if (empty($this->request->query('token'))) {
         throw new MethodNotAllowedException(__('Invalid Access'));
     }
     $token = $this->request->query('token');
     $payerId = $this->request->query('PayerID');
     $this->Transaction = ClassRegistry::init('Payment.Transaction');
     $transaction = $this->Transaction->find('first', array('conditions' => array('Transaction.model' => 'PrepaidAccount', 'Transaction.token' => $token)));
     if (!$transaction) {
         //
         throw new MethodNotAllowedException(__('Invalid Access'));
         $this->Common->autoRedirect(array('action' => 'view'));
     }
     $res = $this->Paypal->getExpressCheckoutDetails($token);
     $array = array('token' => $token, 'payerid' => $payerId, 'amount' => $transaction['Transaction']['amount']);
     $res = $this->Paypal->doExpressCheckoutPayment($array);
     if (empty($res['ACK']) || $res['ACK'] !== 'Success') {
         $message = null;
         if (!empty($res['Error']['Message'])) {
             $message = $res['Error']['Message'];
         }
         $this->log(returns($res), 'paypal');
         throw new InternalErrorException($message);
     }
     $this->Transaction->updatePaypal($transaction['Transaction']['id'], $res);
     if ($res['PAYMENTSTATUS'] === 'Completed') {
         $amount = $transaction['Transaction']['amount'];
         if ($finalAmount = $this->PrepaidAccount->finalAmount($amount)) {
             $amount = $finalAmount;
         }
         $title = $this->PrepaidAccount->getPaymentDescription($transaction['Transaction']['amount'], true);
         /*
         if ($transaction['Transaction']['amount'] != $amount) {
         	$title .= ' ('.number_format((float)$amount-(float)$transaction['Transaction']['amount'], 2, ',', '.').' € + Bonus)';
         }
         */
         $this->PrepaidAccount->deposit($this->Session->read('Auth.User.id'), $amount, array('title' => $title));
         $this->Common->flashMessage('Einzahlung erfolgreich abgeschlossen', 'success');
     } else {
         $this->Common->flashMessage('Einzahlung ist erfolgt, konnte aber noch nicht gutgeschrieben werden.', 'warning');
     }
     $this->redirect(array('action' => 'view'));
 }
コード例 #28
0
ファイル: DatetimeLib.php プロジェクト: robksawyer/grabitdown
 /**
  * try to parse date from various input formats
  * - DD.MM.YYYY, DD/MM/YYYY, YYYY-MM-DD, YYYY, YYYY-MM, ... 
  * - i18n: Today, Yesterday, Tomorrow
  * @param string $date to parse
  * @param format to parse (null = auto)
  * @param type
  * - start: first second of this interval
  * - end: last second of this interval
  * @return int timestamp
  * 2011-11-19 ms
  */
 public static function parseLocalizedDate($date, $format = null, $type = 'start')
 {
     $date = trim($date);
     echo returns($date);
     $i18n = array(strtolower(__('Today')) => array('start' => date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), 'end' => date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')))), strtolower(__('Tomorrow')) => array('start' => date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y')) + DAY), 'end' => date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')) + DAY)), strtolower(__('Yesterday')) => array('start' => date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y')) - DAY), 'end' => date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')) - DAY)), strtolower(__('The day after tomorrow')) => array('start' => date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y')) + 2 * DAY), 'end' => date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')) + 2 * DAY)), strtolower(__('The day before yesterday')) => array('start' => date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y')) - 2 * DAY), 'end' => date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')) - 2 * DAY)));
     if (isset($i18n[strtolower($date)])) {
         return $i18n[strtolower($date)][$type];
     }
     if ($format) {
         $res = DateTime::createFromFormat($format, $date);
         $res = $res->format(FORMAT_DB_DATE) . ' ' . ($type == 'end' ? '23:59:59' : '00:00:00');
         return $res;
     }
     if (strpos($date, '.') !== false) {
         $explode = explode('.', $date, 3);
         $explode = array_reverse($explode);
     } elseif (strpos($date, '/') !== false) {
         $explode = explode('/', $date, 3);
         $explode = array_reverse($explode);
     } elseif (strpos($date, '-') !== false) {
         $explode = explode('-', $date, 3);
     } else {
         $explode = array($date);
     }
     if (isset($explode)) {
         for ($i = 0; $i < count($explode); $i++) {
             $explode[$i] = str_pad($explode[$i], 2, '0', STR_PAD_LEFT);
         }
         $explode[0] = str_pad($explode[0], 4, '20', STR_PAD_LEFT);
         if (count($explode) === 3) {
             return implode('-', $explode) . ' ' . ($type == 'end' ? '23:59:59' : '00:00:00');
         } elseif (count($explode) === 2) {
             return implode('-', $explode) . '-' . ($type == 'end' ? self::daysInMonth($explode[0], $explode[1]) : '01') . ' ' . ($type == 'end' ? '23:59:59' : '00:00:00');
         } else {
             return $explode[0] . '-' . ($type == 'end' ? '12' : '01') . '-' . ($type == 'end' ? '31' : '01') . ' ' . ($type == 'end' ? '23:59:59' : '00:00:00');
         }
     }
     return false;
 }