Exemplo n.º 1
0
 public static function getInstance($config)
 {
     if (self::$instance instanceof self) {
         return self::$instance;
     }
     return self::$instance = new self($config);
 }
Exemplo n.º 2
0
Arquivo: Core.php Projeto: huluwa/grr
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new MySqlStorage();
     }
     return self::$instance;
 }
Exemplo n.º 3
0
function read_menu($parent_id = 0, $lang = null)
{
    $sql = "SELECT id,name,short_name FROM menu WHERE parent_id = :parent_id";
    $statement = Storage::instance()->db->prepare($sql);
    $statement->execute(array(':parent_id' => $parent_id));
    return $statement->fetchAll();
}
Exemplo n.º 4
0
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new Storage();
     }
     return self::$instance;
 }
Exemplo n.º 5
0
 public function action_fupload()
 {
     if (!empty($_FILES['file'])) {
         $user_id = Auth::instance()->get_user()->id;
         $storage_id = Storage::instance()->add($_FILES['file'], $user_id);
         if ($storage_id) {
             $image = ORM::factory('Storage', $storage_id);
             $fname = URL::media($image->file_path);
             // displaying file
             $array = array('filelink' => $fname, 'filename' => $image->name);
             echo stripslashes(json_encode($array));
             exit;
         } else {
             throw new HTTP_Exception_404('Ошибка при сохранении');
         }
     } else {
         throw new HTTP_Exception_404('Не верный формат картинки');
     }
     ////////////////////
     /*
     $dir = APPPATH . '../media/upload/';
     $fname = substr(md5(time()), 0, 8) . '_' . $_FILES['file']['name'];
     move_uploaded_file($_FILES['file']['tmp_name'], $dir . $fname);
     
     $array = array(
         'filelink' => Url::site('/media/upload/').'/'.  $fname,
         'filename' => $_FILES['file']['name']
     );
     
     echo stripslashes(json_encode($array));
     exit;
     */
 }
Exemplo n.º 6
0
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 7
0
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
         self::$instance->setHandler();
     }
     return self::$instance;
 }
Exemplo n.º 8
0
 public static function getInstance()
 {
     if (NULL == self::$instance) {
         self::$instance = new self();
         self::$instance->DBConnection = new MySQLConnection();
     }
     return self::$instance;
 }
Exemplo n.º 9
0
 public function action_upload()
 {
     if ($this->request->method() == "POST") {
         $user_id = Arr::get($_POST, 'user_id', 0);
         $photogalery = Arr::get($_POST, 'photogalery', 0);
         echo Storage::instance()->add($_FILES['Filedata'], $user_id, $photogalery);
     }
     exit;
 }
Exemplo n.º 10
0
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
         $storage_type = Config::getProperty('storage_type');
         switch ($storage_type) {
             case 'text':
                 self::$instance->setHandler(new Storage_text());
                 break;
             case 'json':
                 self::$instance->setHandler(new Storage_json());
                 break;
             case 'mysql':
                 self::$instance->setHandler(new Storage_mysql());
                 break;
             default:
                 self::$instance->setHandler(new Storage_json());
         }
     }
     return self::$instance;
 }
Exemplo n.º 11
0
unset($max_file_size);
if ($_FILES['file']['error'] != UPLOAD_ERR_OK) {
    $Page->json(['jsonrpc' => '2.0', 'error' => ['code' => 500, 'message' => '500 Internal Server Error'], 'id' => 'id']);
    return;
}
/**
 * Only registered users allowed
 */
if (!$User->user()) {
    $Page->json(['jsonrpc' => '2.0', 'error' => ['code' => 403, 'message' => '403 Forbidden'], 'id' => 'id']);
    return;
}
/**
 * Getting instances of storage and database
 */
$storage = Storage::instance()->{$module_data->storage('files')};
$cdb = DB::instance()->{$module_data->db('files')}();
if (!$storage || !$cdb) {
    $Page->json(['jsonrpc' => '2.0', 'error' => ['code' => 500, 'message' => '500 Internal Server Error'], 'id' => 'id']);
    return;
}
/**
 * Moving file into storage
 */
if (!$module_data->directory_created) {
    $storage->mkdir('Plupload');
    $module_data->directory_created = 1;
}
$destination_file = 'Plupload/' . date('Y-m-d');
if (!$storage->file_exists($destination_file)) {
    $storage->mkdir($destination_file);
Exemplo n.º 12
0
</ul>

                <div class='search'>
                    <form method='GET' action=''>
                        <input class='search' type='text' value='Search...' onfocus='this.value=""' onblur='if(this.value=="")
                            this.value="Search..."' name='' />
                        <input class='submit' type='submit' value='' />
                    </form>
                </div>
            </div>

            <div id="map" class="middle">
            </div>

            <?php 
echo Storage::instance()->content;
?>

            <hr class='bottom' id='myhr' />

            <div class='bottom'>
                © 2011 OPEN TAPS. &nbsp;&nbsp; Designed and developed by <a href='http://jumpstart.ge/'>Jumpstart Georgia</a>
            </div>
            <div class='bottom1'>Donate | About Us | Report</div>
            <div class='bottom2'>GEORGIAN WATER PROJECT </div>
            <div class='bottom3'><img src='<?php 
echo URL;
?>
images/connect_fb.jpg' /> &nbsp;CONNECT HERE&nbsp; <img src='<?php 
echo URL;
?>
Exemplo n.º 13
0
 public function action_register()
 {
     $post = $this->post;
     $username = Security::xss_clean(Arr::get($post, 'login', ''));
     $email = Security::xss_clean(Arr::get($post, 'email', ''));
     $password = Security::xss_clean(Arr::get($post, 'password', ''));
     $password_confirm = Security::xss_clean(Arr::get($post, 'password', ''));
     $social_token = Security::xss_clean(Arr::get($post, 'token', ''));
     if (!Auth::instance()->logged_in()) {
         if (!empty($post) || $social_token != '') {
             if ($social_token != '') {
                 $s = file_get_contents('http://ulogin.ru/token.php?token=' . $social_token . '&host=' . $_SERVER['HTTP_HOST']);
                 /* узнать как будет выглядеть массив от клиента с данными из соц сети */
                 $ulogin = json_decode($s, true);
                 //var_dump($ulogin);
                 //$ulogin = Security::xss_clean(Arr::get($post, 'ulogin', ''));
                 $identity = $ulogin['network'] . '_' . $ulogin['uid'];
                 $user = ORM::factory('user')->where('username', '=', $identity)->or_where('email', 'LIKE', '%' . Arr::get($ulogin, 'email', '1NrJH43ksWlrn'))->find();
                 if (!$user->loaded()) {
                     $pass = strtotime(date("Y-m-d H:i:s")) . $social_token;
                     $role = ORM::factory('Role', 1);
                     $user = ORM::factory('User')->values(array('username' => $identity, 'password' => $pass, 'password_confirm' => $pass, 'email' => $ulogin['network'] . '_' . $ulogin['uid'] . '_' . Arr::get($ulogin, 'email', $identity . '@test.kz'), 'network_reg' => 1))->save();
                     $user->add('roles', $role);
                     if ($ulogin['network'] != "yandex") {
                         $photo = Storage::instance()->save_social_photo(Arr::get($ulogin, 'photo', ''), $user->pk());
                     } else {
                         $photo = 0;
                     }
                     ORM::factory('User_Profile')->values(array('user_id' => $user->pk(), 'first_name' => Arr::get($ulogin, 'first_name', ''), 'last_name' => Arr::get($ulogin, 'last_name', ''), 'photo' => $photo, 'phone' => Arr::get($ulogin, 'phone', ''), 'email' => Arr::get($ulogin, 'email', ''), 'location_id' => 0))->save();
                     //Auth::instance()->force_login($identity);
                     //успешная регистрация
                     $this->data['socialReg'] = true;
                 } else {
                     $this->data['error'] = 'Social user is already registered';
                     //Auth::instance()->force_login($user->username);
                     //Пользоатель уже существует
                 }
             } else {
                 $findusername = ORM::factory('User')->where('username', '=', $username)->find_all()->count();
                 if ($findusername == 0) {
                     $findemail = ORM::factory('User')->where('email', '=', $email)->find_all()->count();
                     if ($findemail == 0) {
                         $date = date("Y-m-d H:i:s");
                         $code = md5($date . $password);
                         $user = ORM::factory('User')->values(array('username' => $username, 'email' => $email, 'password' => $password, 'password_confirm' => $password_confirm, 'network_reg' => 0, 'link_activate' => $code));
                         $user->save();
                         Email::connect();
                         Email::View('activate');
                         Email::set(array('username' => $username, 'id' => $code, 'url' => URL::site('/', true)));
                         Email::send($email, array('*****@*****.**', 'e-history.kz'), "Подтверждение регистрации на сайте E-history.kz", '', true);
                         $this->data[] = true;
                         //Успешная простая регистрация
                     } else {
                         $this->data['error'] = 'Email is already registered';
                         //такой ящик уже есть
                     }
                 } else {
                     $this->data['error'] = 'Login is already registered';
                 }
                 //Message::success('На указанный email отправлено письмо со ссылкой на подтверждение регистрации.');
             }
         }
     }
     $this->response->body(json_encode($this->data));
 }
Exemplo n.º 14
0
 public function action_register()
 {
     $username = Security::xss_clean(Arr::get($_POST, 'username', ''));
     $email = Security::xss_clean(Arr::get($_POST, 'email', ''));
     $class = Security::xss_clean(Arr::get($_POST, 'class', ''));
     $vuz = Security::xss_clean(Arr::get($_POST, 'vuz', ''));
     $radio = Security::xss_clean(Arr::get($_POST, 'radio', ''));
     $password = Security::xss_clean(Arr::get($_POST, 'password', ''));
     $password_confirm = Security::xss_clean(Arr::get($_POST, 'password_confirm', ''));
     $errors = NULL;
     $res = Session::instance()->get('return');
     if (!empty($res)) {
         $return = $res;
     } else {
         $return = "/";
     }
     if (!Auth::instance()->logged_in()) {
         if ($this->request->post()) {
             if (!empty($_POST['token'])) {
                 $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
                 $ulogin = json_decode($s, true);
                 $ulogin['token'] = md5($ulogin['identity'] . 'hdhHgth');
                 $identity = $ulogin['network'] . '_' . $ulogin['uid'];
                 $user = ORM::factory('user')->where('username', '=', $identity)->or_where('email', 'LIKE', '%' . Arr::get($ulogin, 'email', '1NrJH43ksWlrn'))->find();
                 if (!$user->loaded()) {
                     $pass = strtotime(date("Y-m-d H:i:s")) . $ulogin['token'];
                     $role = ORM::factory('role', 1);
                     $user = ORM::factory('user')->values(array('username' => $identity, 'password' => $pass, 'password_confirm' => $pass, 'email' => $ulogin['network'] . '_' . $ulogin['uid'] . '_' . Arr::get($ulogin, 'email', $identity . '@test.kz'), 'network_reg' => 1))->save();
                     $user->add('roles', $role);
                     $photo = Storage::instance()->save_social_photo(Arr::get($ulogin, 'photo', ''), $user->pk());
                     ORM::factory('User_Profile')->values(array('user_id' => $user->pk(), 'first_name' => Arr::get($ulogin, 'first_name', ''), 'last_name' => Arr::get($ulogin, 'last_name', ''), 'photo' => $photo, 'phone' => Arr::get($ulogin, 'phone', ''), 'email' => Arr::get($ulogin, 'email', ''), 'location_id' => 0))->save();
                     Auth::instance()->force_login($identity);
                 } else {
                     Auth::instance()->force_login($user->username);
                 }
                 //запомнить токен для соц сети
                 $this->redirect($return, 301);
             } else {
                 if (Captcha::valid($_POST['captcha'])) {
                     try {
                         //$role = ORM::factory('Role', 1);
                         $date = date("Y-m-d H:i:s");
                         $code = md5($date . $password);
                         $user = ORM::factory('User')->values(array('username' => $username, 'email' => $email, 'class' => $class, 'vuz' => $vuz, 'role' => $radio, 'password' => $password, 'password_confirm' => $password_confirm, 'network_reg' => 0, 'link_activate' => $code));
                         $extra_rules = Validation::factory($_POST)->rule('password_confirm', 'matches', array(':validation', ':field', 'password'));
                         if ($extra_rules->check()) {
                             //                                die($password);
                             $user->save();
                             Email::connect();
                             Email::View('activate');
                             Email::set(array('username' => $username, 'id' => $code, 'url' => str_replace('/auth/register', '', URL::current(true))));
                             Email::send($email, array('*****@*****.**', 'e-history.kz'), "Подтверждение регистрации на сайте shkolkovo.kz", '', true);
                             Message::success('На указанный email отправлено письмо со ссылкой на подтверждение регистрации.');
                             $this->redirect('/', 301);
                         } else {
                             $errors = $extra_rules->errors('validation');
                         }
                     } catch (ORM_Validation_Exception $e) {
                         $errors = $e->errors($e->alias());
                     }
                 } else {
                     $errors['captcha'] = I18n::get("Неправильно ввели код подтверждения.");
                 }
             }
         }
     }
     $this->set('username', $username)->set('email', $email)->set('url', 'http://' . $_SERVER['SERVER_NAME'] . '/' . Request::$initial->uri())->set('errors', $errors)->set('return', $return);
 }
Exemplo n.º 15
0
 public function action_enter()
 {
     $username = Security::xss_clean(Arr::get($_POST, 'username', ''));
     $password = Security::xss_clean(Arr::get($_POST, 'password', ''));
     $remember = (bool) Arr::get($_POST, 'remember', false);
     $error = false;
     $template = View::factory('enter');
     $config = Kohana::$config->load('login');
     $captcha = false;
     if (!Auth::instance()->logged_in()) {
         if ($this->request->method() == Request::POST) {
             if (!empty($_POST['token']) && $config['type'] == 'social') {
                 $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
                 $ulogin = json_decode($s, true);
                 $ulogin['token'] = md5($ulogin['identity'] . 'hdhHgth');
                 $identity = $ulogin['network'] . '_' . $ulogin['uid'];
                 $user = ORM::factory('user')->where('username', '=', $identity)->or_where('email', 'LIKE', '%' . Arr::get($ulogin, 'email', '1NrJH60ksWlrn'))->find();
                 if (!$user->loaded()) {
                     $pass = strtotime(date("Y-m-d H:i:s")) . $ulogin['token'];
                     $role = ORM::factory('Role', 1);
                     $user = ORM::factory('User')->values(array('username' => $identity, 'password' => $pass, 'password_confirm' => $pass, 'email' => $ulogin['network'] . '_' . $ulogin['uid'] . '_' . Arr::get($ulogin, 'email', $identity . '@test.kz'), 'network_reg' => 1))->save();
                     $user->add('roles', $role);
                     $photo = Storage::instance()->save_social_photo(Arr::get($ulogin, 'photo', ''), $user->pk());
                     ORM::factory('User_Profile')->values(array('user_id' => $user->pk(), 'first_name' => Arr::get($ulogin, 'first_name', ''), 'last_name' => Arr::get($ulogin, 'last_name', ''), 'photo' => $photo, 'email' => Arr::get($ulogin, 'email', '')))->save();
                     Auth::instance()->force_login($identity);
                 } else {
                     Auth::instance()->force_login($user->username);
                 }
                 $this->redirect('/');
             } else {
                 $flag = true;
                 if (isset($_POST['captcha'])) {
                     if (!Captcha::valid($_POST['captcha'])) {
                         $flag = false;
                         $captcha = true;
                         $error = true;
                     }
                 }
                 if ($flag) {
                     //$token = Arr::get($_POST, 'token_auth', false);
                     //if (Security::token() === $token && Auth::instance()->login($username, $password, $remember)) {
                     if (Auth::instance()->login($username, $password, $remember)) {
                         $brute = ORM::factory('User_Bruteforce')->where('user_id', '=', Auth::instance()->get_user()->id)->find();
                         if ($brute->loaded()) {
                             ORM::factory('User_Bruteforce', $brute->id)->delete();
                         }
                         $this->redirect('/');
                     } else {
                         $user = ORM::factory('user')->where('username', '=', $username)->or_where('email', '=', $username)->find();
                         if ($user->loaded()) {
                             $bruteforce = ORM::factory('User_Bruteforce')->where('user_id', '=', $user->id)->find();
                             if ($bruteforce->loaded()) {
                                 if ($bruteforce->attempt >= 1) {
                                     $captcha = true;
                                 } else {
                                     $brute = ORM::factory('User_Bruteforce', $bruteforce->id);
                                     $brute->attempt = $bruteforce->attempt + 1;
                                     $brute->save();
                                 }
                             } else {
                                 ORM::factory('User_Bruteforce')->values(array('user_id' => $user->id))->save();
                             }
                         }
                         $error = true;
                     }
                 }
             }
         }
     } else {
         $this->redirect('/');
     }
     $template->set('username', $username)->set('remember', $remember ? 'checked' : '')->set('url', 'http://' . $_SERVER['SERVER_NAME'] . '/' . Request::$initial->uri())->set('error', $error)->set('captcha', $captcha)->set('return', '/')->render();
     $this->response->body($template->render());
 }
Exemplo n.º 16
0
<?
  echo isset($alert) ? "<i>".$alert."</i><br />" : "";

  $menu = Storage::instance()->menu;

  echo "
	<div class=\"admin\">
	    <p>Menu</p>
	    <div class='admin_show'>";
  for($i = 0, $c = count($menu); $i < $c; $i ++)
  {
    $link_add = URL . 'menu/' . 'add';
    $link_edit = URL . 'menu/' . $menu[$i]['id'] . '/edit';
    $link_del = URL . 'menu/' . $menu[$i]['id'] . '/delete';
    echo "
		<div class='name'>" . strtoupper($menu[$i]['name']) . "</div>
		<div class='link'>
		    <a href=\" " . $link_edit . " \">Edit</a> | 
		    <a href=\" " . $link_del . " \">Delete</a>
		</div><br/><hr />
	 ";
  }
    echo "
  	        <center>
  	          <div class='add'><a href=\" " . $link_add . " \">Add Menu</a></div>
  	        </center>
	    </div>
	</div><br />
	<div class=\"admin\">
	    <a href=\" " . URL . " \">News</a>
	    <ul style=\" display:none; \">
Exemplo n.º 17
0
<?php

session_start();
define('DIR', getcwd() . '/');
define('URL', 'http://www.localhost.com/OpenTaps/');
require_once DIR . 'application/storage.php';
Storage::instance()->config = (require DIR . 'application/config.php');
require_once DIR . 'application/functions.php';
try {
    Storage::instance()->db = new PDO('mysql:dbname=opentaps;host=127.0.0.1', config('db_user'), config('db_pass'));
} catch (PDOException $exception) {
    exit($exception->getMessage());
}
require_once DIR . 'application/Slim/Slim.php';
Slim::init();
Storage::instance()->title = 'Home Page';
Storage::instance()->menu = read_menu();
Storage::instance()->viewmenu = template('menu');
Storage::instance()->content = template('home');
require_once DIR . 'application/routes.php';
Slim::run();
echo template('layout');
Exemplo n.º 18
0
 public static function instance()
 {
     NULL === self::$instance and self::$instance = new self();
     return self::$instance;
 }
Exemplo n.º 19
0
 /**
  * Deletes this object from the database
  *
  * @return boolean
  */
 public function delete()
 {
     return Storage::instance()->delete($this);
 }
Exemplo n.º 20
0
 public function action_picturecut()
 {
     $x1 = (int) Arr::get($_POST, 'x1', 0);
     $h = (int) Arr::get($_POST, 'h', 0);
     $y1 = (int) Arr::get($_POST, 'y1', 0);
     $w = (int) Arr::get($_POST, 'w', 0);
     $path = Arr::get($_POST, 'path', 0);
     $user_id = Auth::instance()->get_user()->id;
     $storage_id = Storage::instance()->save_jcrop_photo(URL::media($path, true), $user_id);
     $storage = ORM::factory('Storage', $storage_id);
     $newpath = $storage->file_path;
     $targ_w = 280;
     $targ_h = 186;
     $ext = explode('.', $path);
     $ext = $ext[1];
     if ($ext != 'png') {
         $img_r = imagecreatefromjpeg(URL::media($newpath, true));
     } else {
         $img_r = imagecreatefrompng(URL::media($newpath, true));
     }
     $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
     imagecopyresampled($dst_r, $img_r, 0, 0, $x1, $y1, $targ_w, $targ_h, $w, $h);
     if ($ext != 'png') {
         imagejpeg($dst_r, $newpath, 90);
     } else {
         imagepng($dst_r, $newpath, 9);
     }
     $result['path'] = $newpath;
     $result['id'] = $storage_id;
     $this->response->body(json_encode($result));
 }
Exemplo n.º 21
0
<?php

Slim::get('/', function () {
});
Slim::get('/page/:short_name', function ($short_name) {
    Storage::instance()->content = $short_name;
});
Slim::get('/login', function () {
    if (!isset($_SESSION['username'])) {
        Storage::instance()->content = template('login');
    }
});
Slim::post('/login', function () {
    $user = authenticate($_POST['username'], $_POST['password']);
    if ($user) {
        $_SESSION['id'] = $user['id'];
        $_SESSION['username'] = $user['username'];
        Storage::instance()->content = template('admin', array('alert' => 'Admin logged in successfully'));
    } else {
        Storage::instance()->content = template('login', array('alert' => 'Incorrect Username/Password'));
    }
});
Slim::get('/admin', function () {
    if (@$_SESSION['id'] && $_SESSION['username']) {
        Storage::instance()->content = template('admin');
    }
});
Slim::get('/logout', function () {
    session_destroy();
});