function _get_f_list_id($uid) { $facebook = F3::get('Facebook'); $f_list_exists = false; try { // Try and see if they already have a "Single Yet?" friendslist // But maybe deleted their account from our site or somehow // their friendlist field went blank in the DB // And catch general Facebook errors... $f_lists = $facebook->api($uid . '/friendlists'); } catch (FacebookApiException $e) { F3::error('500'); } // Loop through each friendlist and // see if it is the Single Yet? friendlist foreach ($f_lists['data'] as $f_list) { if ($f_list['name'] == 'Single Yet?') { $f_list_exists = true; $f_list_id = $f_list['id']; // If there is a friendlist for Single Yet?, break out of loop. break; } } // If the Single Yet? friendlist doesn't exist, create it. if (!$f_list_exists) { $f_list = $facebook->api($uid . '/friendlists', 'post', array('name' => 'Single Yet?')); $f_list_id = $f_list['id']; } return $f_list_id; }
public function login($f3, $args) { self::check_configuration(); $params = json_decode($f3->get('BODY')); if ($params->username && $params->password) { $login = new DB\Jig\Mapper($this->db, 'users.json'); $temp = $login->find(array('(isset(@userName) && @userName == ?)', $params->username)); if ($temp) { $first = __::first($temp); if (password_verify($params->password, $first['password'])) { $date = new DateTime(); $date->add(new DateInterval('PT' . F3::get('custom.TTL') . 'H')); $out = array('username' => $first['userName'], 'userid' => $first['_id'], 'ttl' => $date->format('Y-m-d H:i:s'), 'roles' => self::get_roles($first['_id'])); $jwt = JWT::encode($out, F3::get('custom.SUPER-KEY')); echo json_encode(array('token' => $jwt, 'data' => array('firstName' => $first['firstName'], 'lastName' => $first['lastName'], 'userName' => $first['userName']))); } else { self::wrong_login(); } } else { self::wrong_login(); } } else { self::wrong_login(); } }
function yukle($hedef = NULL, $alan = 'file') { $yuklenen = F3::get("FILES.{$alan}.tmp_name"); // hedef ve yüklenen dosyanın boş olmasına izin veriyoruz // herhangi biri boşsa mesele yok, çağırana dön if (empty($hedef) || empty($yuklenen)) { return true; } // bu bir uploaded dosya olmalı, fake dosyalara izin yok if (is_uploaded_file($yuklenen)) { // boyutu sınırla, değeri öylesine seçtim if (filesize($yuklenen) > 600000) { F3::set('error', 'Resim çok büyük'); } else { if (exif_imagetype($yuklenen) != IMAGETYPE_JPEG) { F3::set('error', 'Resim JPEG değil'); } else { if (file_exists($hedef)) { F3::set('error', 'Resim zaten kaydedilmiş'); } else { if (!move_uploaded_file($yuklenen, $hedef)) { F3::set('error', 'Dosya yükleme hatası'); } } } } // yok başka bir ihtimal! } else { // bu aslında bir atak işareti F3::set('error', 'Dosya geçerli bir yükleme değil'); } return false; }
function logout() { if (F3::get('SESSION.onlineUser')) { F3::clear('SESSION.onlineUser'); F3::reroute('/'); } }
/** * returns items * * @return mixed items as array * @param mixed $options search, offset and filter params */ public function get($options = array()) { $options = array_merge(array('starred' => false, 'offset' => 0, 'search' => false, 'items' => \F3::get('items_perpage')), $options); $items = $this->backend->get($options); // remove private posts with private tags if (!\F3::get('auth')->showPrivateTags()) { foreach ($items as $idx => $item) { $tags = explode(',', $item['tags']); foreach ($tags as $tag) { if (strpos(trim($tag), '@') === 0) { unset($items[$idx]); break; } } } $items = array_values($items); } // remove posts with hidden tags if (!isset($options['tag']) || strlen($options['tag']) === 0) { foreach ($items as $idx => $item) { $tags = explode(',', $item['tags']); foreach ($tags as $tag) { if (strpos(trim($tag), '#') === 0) { unset($items[$idx]); break; } } } $items = array_values($items); } return $items; }
function home() { $this->view->title = 'Open Postbox | India'; $this->view->caption = 'Latest postboxes added.'; $q = 'select * from post_box order by cast(created_time as int) desc limit 14'; $POSTBOX_DB = \F3::get('POSTBOX_DB'); $result = $POSTBOX_DB->exec($q); $array_all_postboxes = array(); foreach ($result as $row) { $single_postbox = array(); $single_postbox['post_id'] = $row["post_id"]; $single_postbox['lat'] = $row["lat"]; $single_postbox['lan'] = $row["lan"]; $single_postbox['pincode'] = $row["pincode"]; $single_postbox['caption'] = $row["caption"]; $single_postbox['img'] = $row["img"]; $single_postbox['picture_url'] = $row["picture_url"]; $array_all_postboxes[$row["post_id"]] = $single_postbox; } $this->view->set('array_all_postboxes', $array_all_postboxes); $q = 'select * from stats order by sl desc limit 1'; $result = $POSTBOX_DB->exec($q); foreach ($result as $row) { $post_count = $row["post_count"]; $user_count = $row["user_count"]; $this->view->set('is_home', 1); $this->view->set('post_count', $post_count); $this->view->set('user_count', $user_count); } $out = Template::instance()->render('basic/sub_home.html'); $this->view->set('sub_out_put', $out); $this->view->set('enable_maps', 1); echo Template::instance()->render('basic/main.html'); }
/** * add new source * * @return int new id * @param string $title * @param string $tags * @param string $spout the source type * @param mixed $params depends from spout */ public function add($title, $tags, $spout, $params) { // sanitize tag list $tags = implode(',', preg_split('/\\s*,\\s*/', trim($tags), -1, PREG_SPLIT_NO_EMPTY)); $res = \F3::get('db')->exec('INSERT INTO sources (title, tags, spout, params) VALUES (:title, :tags, :spout, :params) RETURNING id', array(':title' => trim($title), ':tags' => $tags, ':spout' => $spout, ':params' => htmlentities(json_encode($params)))); return $res[0]['id']; }
function is_table_exists($table, $db = NULL) { if (is_null($db)) { $db = F3::get('DB.name'); } return $db && F3::sql(array("SELECT COUNT(*) AS found " . "FROM information_schema.tables " . "WHERE table_schema='{$db}' " . "AND table_name='{$table}';")); }
public function item($identifier, $options = array()) { try { // Configurations $this->options = array_merge($this->options, $options); // Initialize Item Object $item = new ItemModel(); // Fetch Shared Item Data DB::sql($this->query['item'], array("item" => $identifier)); $shared = F3::get('DB')->result[0]; // Presumably, no item data found if (empty($shared)) { throw new Exception("No item found."); } // Assign Class Attributes foreach ($shared as $key => $attribute) { $item->{$key} = $attribute; } // Fetch Parent // Fetch Flags // Property Collection if ($this->options['properties']) { switch ($item->rarity) { case "normal": $item->properties['normal'] = DB::sql($this->query['properties'], array("item" => $item->name)); break; case "unique": $item->properties['magic'] = DB::sql($this->query['properties_magic'], array("item" => $item->name)); break; case "set": $item->properties['magic'] = DB::sql($this->query['properties_magic'], array("item" => $item->name)); $item->properties['set'] = DB::sql($this->query['properties_set'], array("item" => $item->name)); break; default: throw new Exception("Unknown rarity."); } // Translate Item Properties $tokens = array("@param", "@min", "@max"); foreach ($item->properties as $type_key => $type) { if ($type_key != 'normal') { foreach ($type as $row_key => $row) { // Determine which string to use $field = $row['minimum'] == $row['maximum'] ? "translation" : "translation_varies"; // Order must line up with $tokens $values = array($row['parameter'], $row['minimum'], $row['maximum']); // Replace database tokens with values $item->properties[$type_key][$row_key]['translation'] = str_replace($tokens, $values, $row[$field]); // Unset unecessary string unset($item->properties[$type_key][$row_key]['translation_varies']); } } } } } catch (Excecption $e) { error_log($e->getMessage()); return false; } // Return JSON string return json_encode($item); }
function pull_data() { $this->view->set('title', 'PostBox - Instagram Data Pull'); $instagram_api_clinet_id = 'b9d4b604105648168c671293d10cc67e'; $instagram_api_url = 'https://api.instagram.com/v1/tags/openpostboxindia/media/recent?client_id=' . $instagram_api_clinet_id; $data_pull_messages = array(); $ch = curl_init($instagram_api_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $json = curl_exec($ch); curl_close($ch); $data = json_decode($json, true); //var_dump($data); if ($data['meta']['code'] == 200) { //echo 'sucess'; $picture_dicts = $data['data']; foreach ($picture_dicts as $pic) { $tags = implode(', ', $pic['tags']); $pincode = 0; foreach ($pic['tags'] as $tag) { if ($this->startswith4($tag, 'pin')) { $pincode = substr($tag, 3, 10); } } $lat = $pic['location']['latitude']; $lan = $pic['location']['longitude']; $created_time = $pic['created_time']; $picture_url = $pic['images']['standard_resolution']['url']; $post_id = $pic['id']; $username = '******' . $pic["user"]["username"]; $website = ''; //$pic["user"]["website"]; $caption = $pic["caption"]["text"]; //check if post_id exists, if yes then go to next one. else insert $data_pull_messages[] = "Processing the post_id=" . $post_id; $q = 'select count(*) as count_posts from post_box where post_id="' . $post_id . '"'; $POSTBOX_DB = \F3::get('POSTBOX_DB'); $result = $POSTBOX_DB->exec($q); //print '\n'.$q; $count_posts = 0; foreach ($result as $row) { $count_posts = $row['count_posts']; } if ($count_posts == 0) { $data_pull_messages[] = "Lets INSERT."; $i = 'insert into post_box( post_id , picture_url , tags , lat , lan , created_time , username , website,pincode, caption, provider) values(' . '"' . $post_id . '","' . $picture_url . '","' . $tags . '","' . $lat . '","' . $lan . '","' . $created_time . '","' . $username . '","' . $website . '","' . $pincode . '","' . $caption . '"' . ',"Instagram")'; //print $i; $POSTBOX_DB->exec($i); } else { $data_pull_messages[] = "Already exists."; } } } $this->view->set('data_pull_messages', $data_pull_messages); $out = Template::instance()->render('basic/sub_data_pull.html'); $this->view->set('sub_out_put', $out); echo Template::instance()->render('basic/main.html'); }
public function jwt_decode($token) { try { return JWT::decode($token, F3::get('custom.SUPER-KEY')); } catch (Exception $e) { return false; } }
/** * loads content for given source * * @return void * @param string $url */ public function load($params) { $this->apiKey = $params['api']; if (strlen(trim($this->apiKey)) == 0) { $this->apiKey = \F3::get('readability'); } parent::load(array('url' => $params['url'])); }
/** * pass any method call to the backend. * * @return methods return value * @param string $name name of the function * @param array $args arguments */ public function __call($name, $args) { if (method_exists($this->backend, $name)) { return call_user_func_array(array($this->backend, $name), $args); } else { \F3::get('logger')->log('Unimplemented method for ' . \F3::get('db_type') . ': ' . $name, \ERROR); } }
/** * cleanup orphaned and old items * * @return void * @param DateTime $date date to delete all items older than this value [optional] */ public function cleanup(\DateTime $date = NULL) { \F3::get('db')->exec('DELETE FROM items WHERE id IN ( SELECT items.id FROM items LEFT JOIN sources ON items.source=sources.id WHERE sources.id IS NULL)'); if ($date !== NULL) { \F3::get('db')->exec('DELETE FROM items WHERE starred=0 AND datetime<:date', array(':date' => $date->format('Y-m-d') . ' 00:00:00')); } }
/** * get the user agent to use for web based spouts * * @return the user agent string for this spout */ public static function getUserAgent($agentInfo = null) { $userAgent = 'Selfoss/' . \F3::get('version'); if (is_null($agentInfo)) { $agentInfo = array(); } $agentInfo[] = '+http://selfoss.aditu.de'; return $userAgent . ' (' . implode('; ', $agentInfo) . ')'; }
function toggleActive() { $id = F3::get("PARAMS.id"); $user = new Axon('tbl_user'); $user->load(array("id=:id", array(":id" => $id))); $user->active = $user->active == 'y' ? 'n' : 'y'; $user->save(); F3::reroute('/admin/user'); }
function reverse_geocode_batch() { $this->view->set('title', 'PostBox - Google Reverse Geo Code'); $data_pull_messages = array(); $POSTBOX_DB = \F3::get('POSTBOX_DB'); $q = 'select post_id,lat,lan from post_box where state is null'; $data_pull_messages[] = "START of Reverse geo code process"; $result = $POSTBOX_DB->exec($q); foreach ($result as $row) { $post_id = $row["post_id"]; $lat = $row["lat"]; $lan = $row["lan"]; $data_pull_messages[] = "For id." . $post_id; $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . $lat . "," . $lan . "&sensor=false®ion=in"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $json = curl_exec($ch); curl_close($ch); $data = json_decode($json, true); $road = ''; $locality = ''; $district = ''; $state = ''; $formatted_address = ''; foreach ($data["results"] as $key => $val) { foreach ($val["address_components"] as $key1 => $val1) { if (in_array("route", $val1['types'])) { $road = $val1['long_name']; } if (in_array("locality", $val1['types'])) { $locality = $val1['long_name']; } if (in_array("administrative_area_level_2", $val1['types'])) { $district = $val1['long_name']; } if (in_array("administrative_area_level_1", $val1['types'])) { $state = $val1['long_name']; } $data_pull_messages[] = "adding " . $val1['long_name'] . " type" . implode($val1['types']); } $formatted_address = $val["formatted_address"]; break; } $q = 'update post_box set road=:road,locality=:locality,district=:district, state=:state, formatted_address=:formatted_address where post_id=:post_id'; $data_pull_messages[] = "add the reverse geocode details for the post_id=" . $post_id; $POSTBOX_DB->exec($q, array(':post_id' => $post_id, ':road' => $road, ':locality' => $locality, ':district' => $district, ':state' => $state, ':formatted_address' => $formatted_address)); } $data_pull_messages[] = "END of Reverse geo code process"; $this->view->set('data_pull_messages', $data_pull_messages); $out = Template::instance()->render('basic/sub_data_pull.html'); $this->view->set('sub_out_put', $out); echo Template::instance()->render('basic/main.html'); }
/** * load image * * @return bool * @param string $url source url * @param int $width * @param int $height */ public function loadImage($url, $width = false, $height = false) { // load image $data = @file_get_contents($url); if ($data === false) { return false; } // get image type $tmp = \F3::get('cache') . '/' . md5($url); file_put_contents($tmp, $data); $imgInfo = @getimagesize($tmp); if (strtolower($imgInfo['mime']) == 'image/vnd.microsoft.icon') { $type = 'ico'; } elseif (strtolower($imgInfo['mime']) == 'image/png') { $type = 'png'; } elseif (strtolower($imgInfo['mime']) == 'image/jpeg') { $type = 'jpg'; } elseif (strtolower($imgInfo['mime']) == 'image/gif') { $type = 'gif'; } elseif (strtolower($imgInfo['mime']) == 'image/x-ms-bmp') { $type = 'bmp'; } else { @unlink($tmp); return false; } // convert ico to png if ($type == 'ico') { $ico = new \floIcon(); @$ico->readICO($tmp); if (count($ico->images) == 0) { @unlink($tmp); return false; } ob_start(); @imagepng($ico->images[count($ico->images) - 1]->getImageResource()); $data = ob_get_contents(); ob_end_clean(); } // parse image for saving it later @unlink($tmp); try { $wideImage = \WideImage::load($data); } catch (\Exception $e) { return false; } // resize if ($width !== false && $height !== false) { if ($wideImage->getHeight() > $height || $wideImage->getWidth() > $width) { $wideImage = $wideImage->resize($width, $height); } } // return image as png $data = $wideImage->asString('png', 0); return $data; }
public function relations() { // Select magic + class + division $division = "\n SELECT class, division\n FROM relate_loot_normal\n "; foreach (F3::sql($division) as $row) { F3::set('class', F3::get('DB.pdo')->quote($row['class'])); F3::set('division', F3::get('DB.pdo')->quote($row['division'])); $query = "\n UPDATE loot\n SET division = {@division}\n WHERE class = {@class}\n "; F3::sql($query); } }
/** * unstarr item * json * * @return void */ public function unstarr() { $this->needsLoggedIn(); $id = \F3::get('PARAMS["item"]'); $itemDao = new \daos\Items(); if (!$itemDao->isValid('id', $id)) { $this->view->error('invalid id'); } $itemDao->unstarr($id); $this->view->jsonSuccess(array('success' => true)); }
public static function add($vehicle, $form_type, $status) { $log = new Axon('admin_log'); $log->date = date("Y-m-d H:i:s"); $log->admin_username = F3::get('SESSION.username'); //admin id $log->vehicle_no = $vehicle; $log->status = $status; $log->form_type = $form_type; $log->save(); }
function logout() { if (!F3::get('SESSION.asid')) { F3: reroute('/admin'); } if (F3::get('SESSION.asid')) { $this->clear('SESSION.asid'); $this->clear('SESSION.admin'); F3::reroute('/admin'); } }
/** * login user * * @return bool * @param string $username * @param string $password */ public function login($username, $password) { if ($this->enabled()) { if ($username == \F3::get('username') && hash("sha512", \F3::get('salt') . $password) == \F3::get('password')) { $this->loggedin = true; $_SESSION['loggedin'] = true; return true; } else { return false; } } return true; }
public function basetotype() { $magic = F3::sql("SELECT * FROM loot WHERE (base != '')"); foreach ($magic as $item) { // Base $base = $item['base']; $id = $item['id']; // Fetch type F3::sql("SELECT type FROM loot WHERE code = '{$base}'"); $type = F3::get('DB.result.0.type'); echo $type . "<br>"; F3::sql("UPDATE loot SET type = '{$type}' WHERE id = {$id}"); } }
public function get() { $sources = $this->backend->get(); // remove items with private tags if (!\F3::get('auth')->showPrivateTags()) { foreach ($sources as $idx => $source) { if (strpos($source['tags'], "@") !== false) { unset($sources[$idx]); } } $sources = array_values($sources); } return $sources; }
function lst() { $user = new Axon('tbl_user'); $report = array(); $user->def("hits", "SELECT COUNT(date) FROM tbl_vote, tbl_poll WHERE date between '" . F3::get("POST.from") . "' and '" . F3::get("POST.to") . "'" . (F3::get("POST.telco") ? " and telco='" . F3::get("POST.telco") . "'" : "") . " and tbl_poll.id=tbl_vote.poll_id and tbl_poll.user_id=tbl_user.id group by tbl_user.id"); if ($user->found() > 0) { $report_list = $user->find(); foreach ($report_list as $rl) { $report[] = array('<img src="' . $rl->image . '" width="20px" height="20px" /> ' . $rl->fullname, $rl->hits ? $rl->hits : 0); } } $this->set('report', $report); echo Template::serve("template/admin/report_list.htm"); }
function transfer_feedback() { $id = F3::get("PARAMS.id"); $vehicle = new Axon("vehicle"); $vehicle->load(array('id=:id', array(':id' => $id))); $zone_id = $vehicle->zone_id; $wheeler = $vehicle->wheeler; $dates = $vehicle->date; $date = DB::sql("SELECT DATE_ADD( date, INTERVAL 15 DAY ) AS ds FROM vehicle WHERE id='{$id}' and date='{$dates}'"); $dt = new Form_elements(); $nepDate = $dt->dateConvertEn($date[0]["ds"]); // var_dump($date[0]["ds"]);die; //echo $nepDate;die; $zone = Admin::getZone($vehicle->zone_id); $symbol = Admin::getSymbolType($vehicle->vehicle_symbol_type); $vehicleNo = $zone . $vehicle->lot_number . $symbol . $vehicle->number; $zone = new Axon("zonal_office"); if ($zone->found(array('zone_id=:id and wheeler=:vid', array(':id' => $zone_id, ':vid' => $wheeler))) > 0) { $zone->load(array('zone_id=:id and wheeler=:vid', array(':id' => $zone_id, ':vid' => $wheeler))); $photos = new Axon("owner_photo"); if ($photos->found(array('vehicle_id =:id', array(':id' => $id)))) { $photos->load(array('vehicle_id =:id', array(':id' => $id))); F3::set('pic', $photos); } else { F3::set('pic', 'no photo available'); } F3::set('date', $nepDate); F3::set('refer', $id); F3::set('vehicle', $vehicleNo); F3::set('value', $zone->name); F3::set('navUser', 'userNav'); F3::set('template', 'feedbacktransfer'); echo Template::serve("template/layout.html"); } else { $photos = new Axon("owner_photo"); if ($photos->found(array('vehicle_id =:id', array(':id' => $id)))) { $photos->load(array('vehicle_id =:id', array(':id' => $id))); F3::set('pic', $photos); } else { F3::set('pic', 'no photo available'); } F3::set('date', $nepDate); F3::set('refer', $id); F3::set('navUser', 'userNav'); F3::set('value', 'no office available'); F3::set('template', 'feedbacktransfer'); echo Template::serve("template/layout.html"); } }
function pictureFolder($id = 4) { echo 123; //var_dump($_FILES);die; $filename = $id; // die(F3::get('FILES.uploadfile.tmp_name')); $path = "photo/"; if (move_uploaded_file(F3::get('FILES.uploadfile.tmp_name'), $path . $filename . ".jpg")) { $picture = new Axon("owner_photo"); $picture->picture = $filename; $picture->save(); } else { echo "there weas an error"; } }
/** * format a database-specific date/time string. * * @param optional int $unixtime the unix time (null = now) * @param optional string $dbms the database software the timestamp is for * * @return string date in format of database driver * * @todo add a switch for the f3 database driver and set the timestamp */ public static function database($unixtime = null, $dbms = null) { // use current time if bad time value or unset $unixtime = (int) $unixtime; if ($unixtime <= 0) { $unixtime = time(); } // format date/time according to database driver $dbms = empty($dbms) ? \F3::get('db.driver') : $dbms; switch ($dbms) { default: case 'mysql': return date('Y-m-d H:i:s', $unixtime); } }
/** * Proxify imgs through atmos/camo when not https * * @param string $content item content * @return string item content */ public function camoflauge($content) { if (empty($content)) { return $content; } $camo = new \WillWashburn\Phpamo\Phpamo(\F3::get('camo_key'), \F3::get('camo_domain')); $dom = new \DOMDocument(); $dom->loadHTML($content); foreach ($dom->getElementsByTagName('img') as $item) { if ($item->hasAttribute('src')) { $src = $item->getAttribute('src'); $item->setAttribute('src', $camo->camoHttpOnly($src)); } } return $dom->saveHTML(); }