public function show($segments)
 {
     extract($_POST);
     if (!isset($username)) {
         $username = $segments[1];
     }
     $entry = DB::query('select id,username,title,location,bio,avatar from users where username = \'' . $username . '\'', 1);
     $entry['activity'] = DB::query('select count(*) as activity from feed where user_id = \'' . $entry['id'] . '\'', 2, 'activity');
     if (!is_file(PATH_UPLOAD . 'profile/' . $entry['avatar'])) {
         $entry['avatar'] = 'default.png';
     }
     $feed = array();
     $feedraw = DB::query('select * from feed where user_id = ' . $entry['id'] . ' and privacy_id = 1 order by id desc limit 20', 0);
     foreach ($feedraw as $i => $row) {
         $feed[$i] = $row;
         $feed[$i]['status'] = Feed::parse_status($row['status']);
         $feed[$i]['files'] = Feed::get_files($row['id'], 'th');
         if (isset($row['created_ts'])) {
             $feed[$i]['timespan'] = timespan($row['created_ts']);
         }
     }
     $follow_btn = "";
     if ($entry['id'] != $_SESSION['user_id']) {
         $following = DB::query('select id from follows where user_id = ' . $_SESSION['user_id'] . ' and user2_id = ' . $entry['id'], 1);
         if ($following) {
             $follow_btn = '<button class="btn btn-success follow" data-id="' . $entry['id'] . '"><i class="ion-checkmark-round"></i> ' . _l('Following') . ' </button>';
         } else {
             $follow_btn = '<button class="btn btn-info follow" data-id="' . $entry['id'] . '"><i class="ion-ios-bolt"></i> ' . _l('Follow') . ' </button>';
         }
     }
     return array('view' => "account", 'follow_btn' => $follow_btn, 'entry' => $entry, 'feed' => $feed);
 }
Exemple #2
0
 /**
  * Массовое обновление статуса на все продукты,
  * в соответствии с их активными товарными предложениями и активными торговыми акциями
  */
 public static function massUpdateProductsStatuses()
 {
     $sql = "update " . Product::TABLE_NAME . " set status = 0";
     \DB::update($sql);
     $sql = "update " . Product::TABLE_NAME . " p\n                  join products_offers po on p.id = po.product_id\n                  join catalogs ct on ct.id = po.catalog_id\n                set p.status = 1\n                where ct.status = 1 and po.status = 1";
     \DB::update($sql);
 }
Exemple #3
0
 static function get_files($id, $type = 'th')
 {
     $data = DB::query('select filename from files where feed_id = ' . $id, 4, 'filename');
     $files = array();
     foreach ($data as $value) {
         if (file_exists(PATH_UPLOAD . 'feed/' . $type . '-' . $value)) {
             $files[] = $value;
         }
     }
     return $files;
 }
 public function add()
 {
     $email = $_REQUEST['email'];
     $exists = DB::query("select * from suscribers where email = '" . $email . "'", 1);
     $json = "already_suscribed";
     if (!$exists) {
         DB::write("insert into suscribers set email = '" . $email . "'");
         $json = "success";
     }
     return array('result' => $json);
 }
 public function add_cam_code()
 {
     $webcams = DB::query('select * from webcams', 0);
     foreach ($webcams as $cam) {
         if ($cam['code'] == '') {
             $code = substr(md5(uniqid(mt_rand(), true)), 0, 12);
             DB::write('update webcams set code = \'' . $code . '\' where id = ' . $cam['id']);
         }
     }
     return [];
 }
 public function login()
 {
     extract($_REQUEST);
     $data = DB::query("select * from users \n\t\t\twhere email = '" . $email . "' and pass = '******' \n\t\t\tor username = '******' and pass = '******'", 1);
     DB::write('update users set lastlogin_ts = ' . time() . ' where id = ' . $data['id']);
     $json = 0;
     if ($data) {
         $json = 1;
         AuthController::add_session($data);
     }
     return array('result' => $json);
 }
 public function register_preview()
 {
     extract($_REQUEST);
     $exists = DB::query("select * from users where email = '" . $email . "'", 1);
     $json = "email_not_evailable";
     $id = 0;
     if (!$exists) {
         $id = DB::write("insert into suscribers set \n\t\t\t\t\ttitle = '" . $title . "',\n\t\t\t\t\temail = '" . $email . "',\n\t\t\t\t\tusername = '******'");
         $json = "email_evailable";
     }
     return array('result' => $json, 'id' => $id);
 }
 public function user_username()
 {
     extract($_REQUEST);
     $exists = DB::query("select * from users where username = '******'", 1);
     $ion = "alert-circled";
     $status = "danger";
     $message = 'username_not_available';
     if (!$exists) {
         $ion = "checkmark-round";
         $status = "success";
         $message = 'username_available';
     }
     return array('ion' => $ion, 'status' => $status, 'message' => $message);
 }
 public function upload()
 {
     $ds = DIRECTORY_SEPARATOR;
     //1
     $storeFolder = PATH_UPLOAD . 'feed/';
     //2
     extract($_POST);
     if (!empty($_FILES)) {
         $feedid = DB::update('feed', $feed_id, '*');
         $filename = Str::sanitize($_FILES['file']['name']);
         if (copy($_FILES['file']['tmp_name'], $storeFolder . $filename)) {
             $data = array('filename' => $filename, 'feed_id' => $feedid, 'user_id' => $_SESSION['user_id']);
             $fileid = DB::update('files', 0, '*', $data);
             Image::resize_group($storeFolder, $filename);
             return array('success' => true, 'id' => $fileid, 'feed_id' => $feedid);
         }
         return array("error" => "Could not write to fs");
     }
 }
    public function add()
    {
        extract($_REQUEST);
        $now = time();
        $lastid = DB::update('feed', $id, '*');
        /*
        		preg_match_all('/(#\w+)/', $status, $matches);
        		foreach ($matches[0] as $hashtag)
           echo $hashtag . ' ';
        */
        preg_match_all("/(@\\w+)/", $status, $matches);
        foreach ($matches[0] as $mentiontag) {
            $user_id = DB::query('select id from users where username = \'' . str_replace('@', '', $mentiontag) . '\'', '2', 'id');
            if ($user_id) {
                DB::write('insert into mentions set 
					user_id = ' . $_SESSION['user_id'] . ', 
					user2_id = ' . $user_id . ', 
					feed_id = ' . $lastid . ', 
					created_ts = ' . $now);
            }
        }
        $entry = feedController::status($lastid);
        return array('entry' => $entry);
    }
Exemple #11
0
 public static function getIsoBeginningDowDate($timeCardHoursWorkedId)
 {
     $data = \DB::table('time_card_hours_worked')->join('time_card', 'time_card_hours_worked.time_card_id', '=', 'time_card.id')->where('time_card_hours_worked.id', $timeCardHoursWorkedId)->select('time_card.iso_beginning_dow_date')->first();
     return $data->iso_beginning_dow_date;
 }
 public function update()
 {
     $_POST['user_id'] = $_SESSION['user_id'];
     return DB::update('webcams', $_POST['id'], '*', $_POST);
 }
 public function index()
 {
     $count = DB::query('select count(*) from users', 2, 'count(*)');
     return array('count' => $count);
 }
 public function index()
 {
     $entry = DB::query('select * from users where id = ' . $_SESSION['user_id'], 1);
     return array('entry' => $entry);
 }
Exemple #15
0
 private function keep_online()
 {
     DB::write('update users set last_ts = ' . time() . ' where id = ' . $_SESSION['user_id']);
 }
Exemple #16
0
            if (count($_POST)) {
                debug('POST ' . json_encode(array($_POST)));
            }
            if (count($_GET)) {
                debug('GET ' . json_encode(array($_GET)));
            }
        } else {
            if (!is_file('views' . $request_uri . '.html')) {
                header('Content-Type: application/json', true);
                echo json_encode(array('view' => "missing"));
            }
        }
    } else {
        if (!is_file($request_uri)) {
            include $missing_page;
        }
    }
} else {
    if (isset($segments[0]) && $segments[0] == 'api') {
        $link = DB::connect();
        include 'app/controllers/ApiController.php';
        header('Content-Type: application/json', true);
        $obj = "App\\Controllers\\ApiController";
        $method = strstr($segments[1], '?', true);
        $c = new $obj();
        echo call_method($c, $method, $segments);
    } else {
        include "../app/index.php";
    }
}
http_response_code(200);