protected function getConfig() { $token = 'config.' . Bootstrap::$main->getConfig('site'); $config = Tools::memcache($token); if ($config && !$this->data('debug')) { return $config; } $config = json_config(__DIR__ . '/../config/merlin.json', false, false); $config['words'] = []; $config['words-with-space'] = []; $extended = ['number']; foreach ($config['dict'] as $field => $fields) { foreach ($fields as $code => $values) { foreach ($values['words'] as $d) { $w = []; if ($field != 'extended') { $w['field'] = $field; } foreach ($extended as $f) { if (isset($values[$f])) { $w[$f] = $values[$f]; } } $value = 'value'; if (isset($values['name'])) { $value = $values['name']; } if (isset($values['evalue'])) { $w[$value] = '~' . $values['evalue']; } elseif (isset($values['value'])) { $w[$value] = $values['value']; } elseif (!in_array($field, $extended)) { $w[$value] = $code; } $config['words'][$d] = $w; } } } unset($config['dict']); //mydie($config['words']); $reg = $this->merlin->getRegions('F', null, $this->data('debug') ? false : true, true); $dest = []; $i = 0; $far = []; foreach ($reg as $r) { if (!isset($r['region'])) { $r['region'] = ''; } if (!isset($r['country'])) { continue; } $country = trim(mb_strtolower($r['country'], 'utf-8')); $region = trim(mb_strtolower($r['region'], 'utf-8')); if ($r['price'] >= Bootstrap::$main->getConfig('merlin.far.price') && !in_array($country, ['bułgaria', 'portugalia', 'hiszpania', 'włochy', 'grecja', 'francja', 'niemcy', 'cypr', 'chorwacja'])) { $far[] = $r['id']; } foreach ($config['dest_shit'] as $shit) { for ($ii = 0; $ii < 2; $ii++) { if (strstr($country, ' ') && strstr($country, $shit)) { $country = trim(str_replace($shit, '', $country)); } if (strstr($region, ' ') && strstr($region, $shit)) { $region = trim(str_replace($shit, '', $region)); } } } $i++; if (strstr($country, ' ') || strstr($region, ' ')) { continue; mydie($r, "{$country}:{$region}:{$i}/" . count($reg)); } foreach ([$country, $region] as $w) { if (!$w) { continue; } if (!isset($dest[$w])) { $dest[$w] = ['field' => 'dest', 'value' => $r['id']]; } else { $dest[$w]['value'] .= ',' . $r['id']; } $w2 = Tools::str_to_url($w); if ($w2 == $w) { continue; } $w = $w2; if (!isset($dest[$w])) { $dest[$w] = ['field' => 'dest', 'value' => $r['id']]; } else { $dest[$w]['value'] .= ',' . $r['id']; } } } foreach (['dest'] as $field) { foreach ($config[$field] as $code => $dep) { foreach ($dep as $d) { if (isset($dest[$d])) { $dest[$d]['value'] .= ',' . $code; } else { $dest[$d] = ['field' => 'dest', 'value' => $code]; } } } } foreach ($dest as $w => $r) { if (!isset($config['words'][$w])) { $config['words'][$w] = $r; } } $config['far'] = $far; if ($this->data('debug') == 1) { $hotels = $this->merlin->getFilters(['ofr_type' => 'F'], 'obj_xCode', $this->data('debug') ? false : true); Tools::log('hotels-' . $token, $hotels); $words = array_keys($config['words']); $hotel_map = []; foreach ($hotels as $hotel) { $hotel = str_replace(['+', ',', ';', '~', '(', ')', '"'], ' ', $hotel); $hotel = str_replace(["'"], '"', $hotel); $hotel = preg_replace('/\\s+/', ' ', trim($hotel)); $hotel = mb_strtolower($hotel, 'utf-8'); foreach (explode(' ', $hotel) as $h) { $h = Tools::str_to_url($h); if (strlen($h) < 4) { continue; } if (isset($config['words'][$h])) { continue; } if (isset($hotel_map[$h])) { continue; } $lev = false; foreach ($words as $w) { if (levenshtein($h, $w) <= 2) { $lev = true; break; } } if ($lev) { continue; } $hotel_map[$h] = ['field' => 'ftsName', 'value' => $h]; } } $config['hotels'] = $hotel_map; } //mydie($config,count($config['words'])); foreach (array_keys($config['words']) as $word) { if (strstr($word, ' ')) { $config['words-with-space'][] = $word; } } Tools::log('get-config', [$token]); return Tools::memcache($token, $config, 4 * 3600); }
public function delete() { require_once __DIR__ . '/../models/paymentModel.php'; require_once __DIR__ . '/../models/imageLabelModel.php'; require_once __DIR__ . '/../models/rateModel.php'; require_once __DIR__ . '/../models/guestModel.php'; require_once __DIR__ . '/../models/tagModel.php'; $this->requiresLogin(); if ($this->id && $this->id != Bootstrap::$main->user['id']) { $this->requiresLogin(true); } $user_id = $this->id ?: Bootstrap::$main->user['id']; $backup = []; $backup['user'] = $this->user($user_id)->data(); $md5hash = $backup['user']['md5hash']; $images = new imageModel(); $labels = new imageLabelModel(); $rates = new rateModel(); $guests = new guestModel(); $events = new eventModel(); $tags = new tagModel(); $payments = new paymentModel(); $backup['image'] = $images->getUsersImages($user_id) ?: []; $backup['imageLabels'] = []; foreach ($backup['image'] as $img) { $backup['imageLabels'] = array_merge($backup['imageLabels'], $labels->select(['image' => $img['id']]) ?: []); } $backup['event'] = $events->select(['user' => $user_id]) ?: []; $backup['tag'] = $tags->select(['user' => $user_id]) ?: []; foreach ($backup['event'] as $event) { $backup['tag'] = array_merge($backup['tag'], $tags->select(['event' => $event['id']]) ?: []); } $backup['rate'] = $rates->select(['user' => $user_id]) ?: []; $backup['rate'] = array_merge($backup['rate'], $rates->select(['host' => $user_id]) ?: []); $backup['guest'] = $guests->select(['user' => $user_id]) ?: []; $backup['payment'] = []; foreach ($backup['guest'] as $guest) { $backup['payment'] = array_merge($backup['payment'], $payments->select(['guest' => $guest['id']]) ?: []); } $backup_json = json_encode($backup, JSON_NUMERIC_CHECK); $path = 'arch/' . $md5hash . '/' . Bootstrap::$main->human_datetime_format(Bootstrap::$main->now); Tools::save($path . '/data.json', $backup_json); Tools::save($path . '/img', null, 'img/' . $md5hash); Tools::log('remove-user', Bootstrap::$main->user['id']); $this->user()->remove(); if (!$this->id || $this->id == Bootstrap::$main->user['id']) { return $this->get_logout(); } return $this->status(); }
public static function log($logmsg, $level = false, $file = "", $line = 0) { if (!config::$loggingLevel) { return; } $level = $level === false ? VERBOSE : $level; if ($level > (config::$loggingLevel == 1 ? E_USER_ERROR : (config::$loggingLevel == 2 ? E_USER_WARNING : (config::$loggingLevel == 3 ? E_USER_NOTICE : VERBOSE)))) { return; } switch ($level) { case E_USER_ERROR: $l = " Error"; break; case E_USER_WARNING: $l = "Warning"; break; case E_USER_NOTICE: $l = " Notice"; break; default: $l = "Verbose"; break; } if ($level < E_USER_NOTICE && $file) { $logmsg .= " in {$file} on line {$line}."; } $logmsg = config::$displayLogLevel ? "{$l}:\t{$logmsg}" : "{$logmsg}"; if (config::$fileLogging && isset($GLOBALS['_debug_f']) && $GLOBALS['_debug_f'] === true) { Tools::log("{$logmsg}"); } if (isset($GLOBALS['_debug']) && $GLOBALS['_debug'] === true) { self::output($logmsg); } }
public function get($limit = 0) { $opt = $this->nav_array($limit ?: Bootstrap::$main->getConfig('merlin.search.limit')); $opt['totalPrice'] = Bootstrap::$main->session('total'); $site = Bootstrap::$main->getConfig('site'); $config = $this->getConfig(); Bootstrap::$main->system('cfg'); $cond = $this->data('q') ? $this->q2cond($this->data('q')) : []; Bootstrap::$main->system('q2c'); Bootstrap::$main->session('q', $this->data('q')); $social_url = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $social_text = ''; $social_words = []; if (count($cond)) { if (isset($cond[1])) { foreach ($cond[1] as $arr) { foreach ($arr as $ar) { if (isset($social_words[$ar])) { continue; } $social_words[$ar] = true; $social_url .= str_replace(' ', '-', $ar) . '/'; $social_text .= $ar . ' '; } } } if (!isset($cond[0]['type'])) { $cond[0]['type'] = 'F'; } if (!isset($cond[0]['adt'])) { $cond[0]['adt'] = 2; } $cond[0]['total'] = $opt['totalPrice'] ? true : false; $rowattr = []; $rowattr['total'] = $opt['totalPrice']; $results = $this->results($cond, $opt['limit'], $opt['offset'], $config, $rowattr); $offers = $results['offers']; $result = $results['result']; $offers2 = $offers; $opt['next_offset'] = $opt['offset'] + $opt['limit']; $limit = $opt['limit']; $security = 20; while (count($offers2['result']) == $limit && count($result) < $opt['limit']) { $offset = $opt['next_offset']; $limit = $opt['limit'] - count($result); $opt['next_offset'] += $limit; $results = $this->results($cond, $limit, $offset, $config, $rowattr); if (count($results['result'])) { $result = array_merge($result, $results['result']); } $offers2 = $results['offers']; if (!$security--) { break; } } if (!isset($cond['memcache']) && !$this->data('debug')) { @Tools::log('query-' . $site, ['q' => $this->data('q'), 'count' => $offers['count'], 'cond' => $cond]); if (isset($cond[2]) && is_array($cond[2]) && count($cond[2])) { foreach ($cond[2] as $w) { $query = new queryModel(); $query->datetime = date('c'); $query->q = $this->data('q'); $query->site = Bootstrap::$main->getConfig('site'); $query->word = $w; $query->ip = Bootstrap::$main->ip; $query->save(); } } } } else { $offers = ['result' => [], 'count' => 0]; $result = []; $opt['next_offset'] = $opt['offset']; } Bootstrap::$main->system('mds'); $social_subject = trim(str_replace('{q}', trim($social_text), Bootstrap::$main->getConfig('mail.subject'))); $opt['f'] = 'https://www.facebook.com/sharer/sharer.php?t=' . urlencode($social_subject) . '&u=' . urlencode($social_url); $opt['m'] = 'mailto:?subject=' . urlencode($social_subject) . '&body=' . urlencode($social_url); $opt['results'] = 'Wyniki: '; if (isset($offers['count'])) { if ($offers['count'] >= 1000) { $opt['results'] .= 'ponad 1000'; } else { $opt['results'] .= $offers['count']; } } $opt['change'] = isset($cond[3]) && strlen($cond[3]) ? $cond[3] : ''; if (isset($cond[2]) && is_array($cond[2])) { foreach ($cond[2] as $unknown) { if (strstr($opt['change'], $unknown)) { $opt['change'] = str_replace($unknown, "<i>{$unknown}</i>", $opt['change']); } else { if (strlen($opt['change'])) { $opt['change'] .= ' '; } $opt['change'] .= "<i>{$unknown}</i>"; } } } if ($this->data('debug')) { $ret = ['conditions' => $cond, 'result' => $result]; if ($this->data('debug') == 2) { $ret['merlin'] = $this->merlin->debug; } mydie($ret); } return array('status' => true, 'options' => $opt, 'data' => $result); }
public function delete($auto = false) { $this->requiresLogin(); $event = $this->event()->get(0 + $this->id); if (!isset($event['user']) || $event['user'] != Bootstrap::$main->user['id']) { return $this->error(19); } $model = new eventModel($event); if (!$model->getGuests() && count($model->get_dates($model->id, false)) == 1) { $model->remove(); return $this->status(); } elseif (!$auto && $model->d_event_start < Bootstrap::$main->now) { return $this->error(60); } else { $guests = $model->getGuests(); $guestModel = new guestModel(); $otoken = $auto ? 'auto-cancel' : 'host-cancel'; Bootstrap::$main->human_datetime_format(); $event = $this->event()->get(0 + $this->id); $host = $this->user()->get($event['user']); if (is_array($guests)) { foreach ($guests as $guest) { $guestModel->get($guest['guest_id']); $guestModel->cancel_reason = $this->data('reason'); $guestModel->d_cancel = Bootstrap::$main->now; $guestModel->canceler = Bootstrap::$main->user['id']; $guestModel->save(); $ics = Ics::cancelation($event, $host, $guest, $event['create'], $event['change']); $data = $guestModel->data(); $data['event'] = $event; $data['guest'] = $guest; $data['host'] = $host; if ($guestModel->d_payment) { Tools::observe($otoken, $data, [['cancel.ics' => $ics]]); } } } $model->active = -1; $model->save(); Tools::log('event-' . $otoken, ['event' => $model->data(), 'guests' => $guests]); } return $this->status(); }
require_once __DIR__ . '/../lib/class/payu.php'; $guest = new guestModel(); $payment = new paymentModel(); $timetoapprove = 10 * 24 * 3600; $from = Bootstrap::$main->now - $timetoapprove; $payu = new payu(); $payus = $payment->getAllForChannel('payu', $from, 5); if (is_array($payus)) { foreach ($payus as $p) { $prc = 100 * (Bootstrap::$main->now - $p['d_payment_create']) / $timetoapprove; if ($p['d_cancel']) { $r = $payu->cancel_payment($p); Tools::log('payu', ['cancel', $r, $p]); } elseif ($p['d_deadline'] + 3600 < Bootstrap::$main->now || $prc > 90) { $r = $payu->confirm_payment($p); Tools::log('payu', ['confirm', $r, $p]); } } } foreach ($guest->getCanceledGuests() ?: [] as $g) { $payments = $payment->getForGuest($g['id']); if (is_array($payments)) { foreach ($payments as $p) { $classname = $p['channel']; $classfile = __DIR__ . '/../lib/class/' . $classname . '.php'; if (!file_exists($classfile)) { continue; } require_once $classfile; $c = new $classname(); $c->cancel_payment($p);
function log($obj, $label = '') { return Tools::log($obj, $label); }
require_once __DIR__ . '/../rest/models/userModel.php'; require_once __DIR__ . '/../rest/models/eventModel.php'; require_once __DIR__ . '/../rest/controllers/userController.php'; if (Bootstrap::$main->isAdmin() && isset($_GET['pretend'])) { $id = null; $data = []; if ($_GET['pretend'] + 0 > 0) { $id = $_GET['pretend']; } elseif (strstr($_GET['pretend'], '@')) { $data['email'] = $_GET['pretend']; } else { $data['url'] = $_GET['pretend']; } $user = new userController($id, $data); $user->get_pretend(); Tools::log('pretend', ['admin' => Bootstrap::$main->user['email'], 'id' => $id, 'data' => $data]); header('location: ' . Bootstrap::$main->getConfig('app.root') . 'profile'); die; } if (Bootstrap::$main->isAdmin() && isset($_GET['vip'])) { $vip = explode(',', $_GET['vip']); $model = new userModel($vip[0]); $model->_vip = $vip[1] + 0; $model->save(); } $us = false; if (Bootstrap::$main->isAdmin() && isset($_GET['q'])) { $model = new userModel(); if ($_GET['q'] + 0 > 0) { $us = $model->get($_GET['q']); } elseif (strstr($_GET['q'], '@')) {
protected function paid(paymentModel $payment, $amount) { if (0.9 * $payment->amount < $amount) { $image = new imageModel(); $guest = new guestModel($payment->guest); if ($guest->d_payment) { return; } $guest->d_payment = Bootstrap::$main->now; $guest->save(); $e = $this->event()->get($guest->event); Tools::userHasAccessToEvent($guest->event, $guest->user, true); $data = []; $data['event'] = $this->event()->data(); $user = new userModel($data['event']['user']); $data['host'] = $user->data(); Bootstrap::$main->session('time_delta', $user->delta); Bootstrap::$main->human_datetime_format(); $data['event'] = $this->event()->get($guest->event); $data['event']['img'] = $image->get($data['event']['img']); $user->get($guest->user); $data['guest'] = $user->data(); $data['data'] = $guest->data(); $data['payment'] = $payment->data(); if (isset($data['payment']['notify'])) { $data['notify'] = json_decode($data['payment']['notify'], true); } $ics = Ics::invitation($e, $data['host'], $data['guest'], $e['create'], $guest->create); Tools::observe('event-paid-to-host', $data); Tools::observe('event-paid-to-guest', $data, [['invite.ics' => $ics]]); Tools::log('guest', $data); $eventController = new eventController(); $eventController->recalculate_fullhouse($guest->event); } }
$itemscope = 'Events'; if (isset($event['event']['rate'])) { $rate = $event['event']['rate']; } $title = $event['event']['name']; $pagetitle = $title . ' - ' . $event['event']['city']; $description = $event['event']['about']; $photo = $event['event']['img']['url']; $img = $event['event']['host']['photo']; if (isset($event['event']['tags']) && is_array($event['event']['tags'])) { $tags = []; foreach ($event['event']['tags'] as $t) { $tags[] = $t['name']; } $keywords = implode(',', $tags) . ',' . $keywords; } $img_url .= $event['event']['host']['url']; $url .= $event['event']['url']; $button = Tools::translate('ClickToJoin', $lang); if (substr($description, -1) != '.' && substr($description, -1) != '!') { $description .= '.'; } $description .= ' ' . $button; } } } if (!isset($pagetitle)) { $pagetitle = $title; } Tools::log('bots', ['server' => $_SERVER]); include __DIR__ . '/embedded.html';
static function embed_images($mail, $body) { // get all img tags preg_match_all('/<img.*?>/', $body, $matches); if (!isset($matches[0])) { return; } // foreach tag, create the cid and embed image $i = 1; foreach ($matches[0] as $img) { // make cid $id = 'img' . $i++; // replace image web path with local path preg_match('/src="(.*?)"/', $body, $m); if (!isset($m[1])) { continue; } $arr = parse_url($m[1]); // if (!isset($arr['host']) || !isset($arr['path']))continue; $logInfo = $arr['path'] . ''; Tools::log($logInfo); // add $mail->AddEmbeddedImage(Yii::getPathOfAlias('webroot') . $arr['path'], $id, 'attachment', 'base64', 'image/jpeg'); $body = str_replace($img, '<img alt="" src="cid:' . $id . '" style="border: none;" />', $body); } return $body; }
$bootstrap = new Bootstrap($config); function sitemap_date($t) { return date('c', $t); } $url = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $sitemap = []; $sitemap[] = ['loc' => $url, 'priority' => 1, 'lastmod' => sitemap_date(strtotime(date('Y-m-d')))]; $map = json_decode(file_get_contents(Tools::saveRoot('map.json')), true); foreach ($map as $from => $reg) { foreach (array_keys($reg) as $r) { $sitemap[] = ['loc' => $url . $r . '/' . $from, 'priority' => 0.9, 'lastmod' => sitemap_date(strtotime(date('Y-m-d')))]; } } if (isset($_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['REQUEST_URI'])) { Tools::log('bots', ['agent' => $_SERVER['HTTP_USER_AGENT'], 'uri' => $_SERVER['REQUEST_URI']]); } header('Content-type: application/xml; charset=utf-8'); ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <?php foreach ($sitemap as $url) { ?> <url> <loc><?php echo $url['loc']; ?> </loc> <lastmod><?php echo $url['lastmod']; ?>
protected function error($id = 0, $ctx = null) { if (!is_null($this->error_trap)) { return; } require_once __DIR__ . '/../../rest/class/Error.php'; $result['error'] = Error::e($id); if (!is_null($ctx)) { $result['ctx'] = $ctx; } echo 'Error: ' . json_encode($result) . '<br/>'; Tools::log('calendar', $result); $this->userstatus = false; }