public function addToList($type, $value)
 {
     $ban = R::dispense('banlist');
     $ban->type = $type;
     $ban->value = $value;
     $ban->created = R::isoDateTime();
     $id = R::store($ban);
     return $id;
 }
 public static function add($f3, $path)
 {
     $cache_file = R::findOne("cache", "path = ?", [$path]);
     if (is_null($cache_file)) {
         $cache_file = R::dispense("cache");
         $cache_file->path = $path;
         $cache_file->filesize = filesize($path);
     }
     $cache_file->datetime = R::isoDateTime();
     R::store($cache_file);
 }
 public function add($postId, $text, $username, $userId = null)
 {
     $comment = R::dispense('comments');
     $comment['post_id'] = $postId;
     $comment['text'] = $text;
     $comment['date'] = R::isoDateTime();
     $comment['username'] = $username;
     $comment['user_id'] = $userId;
     $commentId = R::store($comment);
     return $commentId;
 }
 public function create($title, $text, $tags)
 {
     $post = R::dispense('posts');
     $post['title'] = $title;
     $post['text'] = $text;
     $post['date'] = R::isoDateTime();
     $post['visits'] = 0;
     $post['username'] = $_SESSION['username'];
     $post['user_id'] = $_SESSION['userId'];
     $post->sharedTagsList = $this->processTags($tags);
     $postId = R::store($post);
     return $postId;
 }
Example #5
0
function create_photo_model($options = array())
{
    $photo = \R::dispense('photo');
    foreach ($options as $key => $value) {
        if ($key != 'tags') {
            $photo->{$key} = $value;
        }
    }
    # Add metadata we want to keep:
    $photo->moderated = false;
    $photo->created_at = array_key_exists('created_at', $photo) ? \DateTime::createFromFormat(\DateTime::ISO8601, $photo->created_at) : \R::isoDateTime();
    $id = \R::store($photo);
}
Example #6
0
 public static function completar()
 {
     //global $logged;
     if (isset($_POST['id'])) {
         $request = R::load('request', $_POST['id']);
         $completed = R::dispense('completed');
         $completed->import($request->export(), 'name, user_id');
         $completed->date = R::isoDateTime();
         $completed->agregado = $request->date;
         $id = R::store($completed);
         R::trash($request);
         echo json_encode(["exito" => 1]);
     }
 }
 public function createSubscription($subscription_for)
 {
     if (!$this->isUserSubscribed()) {
         $user = R::dispense('subscriptions');
         $user->email = $this->_email;
         $user->category_id = $this->_category_id;
         $user->city_id = $this->_city_id;
         $user->token = token();
         $user->is_confirmed = 0;
         $user->created = R::isoDateTime();
         $id = R::store($user);
         $notif = new Notifications();
         $notif->createSubscriptionMail($id, $user->token, $user->email, $subscription_for);
         return $id;
     }
     return false;
 }
Example #8
0
 /**
  * 記錄下載對象
  * @param Object $f3
  * @param RedBean $file
  * @param String $action 動作
  * @return RedBean $file
  */
 static function create_log($f3, $file, $action)
 {
     $log = R::dispense("log");
     $log->file_id = $file->id;
     $log->action = $action;
     $log->datetime = R::isoDateTime();
     // 上傳IP
     $client_ip = PFH_Client_helper::get_client_ip($f3);
     //$data["client_ip"] = $client_ip;
     $log->client_ip = $client_ip;
     // 來源網頁
     $http_referer = getenv("HTTP_REFERER");
     //$data["http_referer"] = $http_referer;
     $log->http_referer = $http_referer;
     $log->agent = $f3->get("AGENT");
     R::store($log);
     return $file;
 }
Example #9
0
function addEdit()
{
    global $db_name;
    $edit = isset($_POST['edit']);
    $type = $_REQUEST['type'];
    $errors = array();
    $db = $edit ? R::load($db_name, (int) $_POST['edit']) : R::dispense($db_name);
    foreach ($_POST as $key => $val) {
        if (substr($key, 0, 3) != 'db_') {
            continue;
        }
        $db->{substr($key, 3)} = $val;
    }
    $filename = pickFilename(array($_POST['db_sponsor_name'], $_POST['db_title']));
    $max_width = 0;
    if ($type == 'videos') {
        $max_width = 150;
    } else {
        if ($type == 'channels') {
            $max_width = 230;
        }
    }
    $image_url = imageUpload($filename, $max_width);
    if ($image_url) {
        $db->image_url = $image_url;
    } else {
        $errors[] = 'Image upload failed.';
    }
    if ($type == 'channels') {
        $db->video_list = json_encode($_REQUEST['video_urls']);
    }
    if (!$edit) {
        $db->created_on = R::isoDateTime();
    } else {
        $db->updated_on = R::isoDateTime();
    }
    $id = R::store($db);
    $returnArr = $db->export();
    if (!empty($errors)) {
        $returnArr['errors'] = $errors;
    }
    jsonForAjax($returnArr);
}
 public function applyForJob($data)
 {
     $apply = R::dispense('applications');
     $apply->job_id = $this->_job_id;
     $apply->cover_letter = $data['cover_letter'];
     $apply->full_name = $data['full_name'];
     $apply->email = $data['email'];
     $apply->location = $data['location'];
     $apply->websites = $data['websites'];
     $apply->attachment = $data['attachment'];
     $apply->token = $data['token'];
     $apply->created = R::isoDateTime();
     $id = R::store($apply);
     $job = R::load('jobs', $this->_job_id);
     $data['title'] = $job->title;
     $data['recipient'] = $job->email;
     $notif = new Notifications();
     if ($notif->applyForJobMail($data)) {
         return $id;
     }
     return false;
 }
Example #11
0
 public function propareVO()
 {
     // Get data from post
     $username = stripslashes(trim($_POST['userid']));
     // user id
     $pwd = md5(trim($_POST['pwd']));
     $email = trim($_POST['email']);
     $regtime = R::isoDateTime();
     $token = md5($username . $pwd . $regtime);
     //create activation token
     $token_exptime = time() + 60 * 60 * 24;
     //expire time 24 hours
     // create a vo for convey object info
     $user = new User();
     $user->setUserName($username);
     $user->setPassword($pwd);
     $user->setEmail($email);
     $user->setToken($token);
     $user->setTokenExptime($token_exptime);
     $user->setRegTime($regtime);
     return $user;
 }
Example #12
0
 public static function crear()
 {
     if (isset($_POST['user']['name']) && isset($_POST['user']['password'])) {
         $usuario = $_POST['user']['name'];
         $password = hash("sha256", $_POST['user']['password']);
         $user = R::findOne('user', ' name = :name AND password = :password ', array(':name' => $usuario, ':password' => $password));
         if ($user == null) {
             $_SESSION['flash'] = 'Error al autenticar. Usuario/Contraseña incorrectos.';
             header('Location:/entrar');
         } else {
             $_SESSION['flash'] = 'Autenticado correctamente';
             $session = R::dispense('session');
             $session->name = $user->name;
             $session->hora = R::isoDateTime();
             $session->ip = $_SERVER['REMOTE_ADDR'];
             $id = R::store($session);
             $session->id = $id;
             setcookie('logged', json_encode($session->export()), time() * 2);
             header('Location:/');
         }
     }
 }
 public function jobCreateUpdate($data, $status = INACTIVE)
 {
     if (isset($data['id']) && $data['id'] != '' && $this->getJobFromToken($data['token'])) {
         $job = R::load('jobs', $data['id']);
         $data['email'] = $job->email;
     } else {
         $job = R::dispense('jobs');
         $job->created = R::isoDateTime();
         $job->email = $data['email'];
         $job->token = $data['token'];
         $job->status = $status;
     }
     $job->title = $data['title'];
     $job->category = $data['category'];
     $job->city = $data['city'];
     $job->description = $data['description'];
     $job->perks = $data['perks'];
     $job->how_to_apply = $data['how_to_apply'];
     $job->company_name = $data['company_name'];
     $job->logo = $data['logo'];
     $job->url = $data['url'];
     $job->is_featured = $data['is_featured'];
     $id = R::store($job);
     $data['access'] = accessToken($id);
     // send user an email if job is inactive
     if (!$job->status && $data['step'] == 3) {
         $notif = new Notifications();
         if ($notif->jobCreateUpdateMail($data)) {
             return true;
         }
     }
     if ($id > 0) {
         return $id;
     }
     return false;
 }
 public function sendEmailsToSubscribersMail($job_id)
 {
     global $categories, $cities;
     $message = '';
     $content = '';
     // get job information
     $j = new Jobs($job_id);
     $job = $j->showJobDetails();
     $title = $j->getSlugTitle();
     $category_name = $categories[$job->category]['name'];
     $city_name = $cities[$job->city]['name'];
     $job_link = BASE_URL . "jobs/{$job->id}/{$title}";
     $description = Parsedown::instance()->parse($job->description);
     $content .= "<p>Job Details</p>";
     $content .= "<p>-----------</p>";
     $content .= "<p><a href={$job_link}>{$job_link}</a></p>";
     $content .= "<p>Title: <strong>{$job->title}</strong></p>";
     $content .= "<p>Description: {$description}</p>";
     if ($job->perks != '') {
         $content .= "<p>Perks: {$job->perks}</p>";
     }
     $content .= "<p>How to apply: {$job->how_to_apply}</p>";
     $content .= "<p>-----------</p>";
     // get all users subscribed to the job
     $users = R::findAll('subscriptions', " is_confirmed=1 AND (category_id=:category_id OR city_id=:city_id) ", array(':category_id' => $job->category, ':city_id' => $job->city));
     foreach ($users as $user) {
         $link = BASE_URL . "subscribe/{$user->id}/delete/{$user->token}";
         $name = $user->category_id > 0 ? $category_name : $city_name;
         $subject = "A new {$name} job was posted at {$this->app_name}";
         $message .= "<p>You subcribed to receive {$name} jobs on {$this->app_name}.</p>";
         $message .= $content;
         $message .= "<p>To unsubscribe, click this link to stop receiving alerts.</p>";
         $message .= "<p><a href={$link}>{$link}</a></p>";
         if ($this->sendNotification($subject, $message, $user->email)) {
             $update = R::load('subscriptions', $user->id);
             $update->last_sent = R::isoDateTime();
             R::store($update);
         }
     }
 }
Example #15
0
 /**
  * Test beautification of column names.
  * 
  * @return void
  */
 public function testBeautifulColumnNames()
 {
     testpack('Beautiful column names');
     $town = R::dispense('town');
     $town->isCapital = FALSE;
     $town->hasTrainStation = TRUE;
     $town->name = 'BeautyVille';
     $houses = R::dispense('house', 2);
     $houses[0]->isForSale = TRUE;
     $town->ownHouse = $houses;
     R::store($town);
     $town = R::load('town', $town->id);
     asrt($town->isCapital == FALSE, TRUE);
     asrt($town->hasTrainStation == TRUE, TRUE);
     asrt($town->name == 'BeautyVille', TRUE);
     testpack('Accept datetime objects.');
     $cal = R::dispense('calendar');
     $cal->when = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
     asrt($cal->when, '2000-01-01 00:00:00');
     testpack('Affected rows test');
     $currentDriver = $this->currentlyActiveDriverID;
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $bean = $redbean->dispense('bean');
     $bean->prop = 3;
     //make test run with strict mode as well
     $redbean->store($bean);
     $adapter->exec('UPDATE bean SET prop = 2');
     asrt($adapter->getAffectedRows(), 1);
     testpack('Testing Logger');
     R::$adapter->getDatabase()->setLogger(new RedBean_Logger_Default());
     asrt(R::$adapter->getDatabase()->getLogger() instanceof RedBean_Logger, TRUE);
     asrt(R::$adapter->getDatabase()->getLogger() instanceof RedBean_Logger_Default, TRUE);
     $bean = R::dispense('bean');
     $bean->property = 1;
     $bean->unsetAll(array('property'));
     asrt($bean->property, NULL);
     asrt($bean->setAttr('property', 2) instanceof RedBean_OODBBean, TRUE);
     asrt($bean->property, 2);
     asrt(preg_match('/\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d/', R::isoDate()), 1);
     asrt(preg_match('/\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d/', R::isoDateTime()), 1);
     $redbean = R::getRedBean();
     $adapter = R::getDatabaseAdapter();
     $writer = R::getWriter();
     asrt($redbean instanceof RedBean_OODB, TRUE);
     asrt($adapter instanceof RedBean_Adapter, TRUE);
     asrt($writer instanceof RedBean_QueryWriter, TRUE);
     R::setRedBean($redbean);
     pass();
     //cant really test this
     R::setDatabaseAdapter($adapter);
     pass();
     //cant really test this
     R::setWriter($writer);
     pass();
     //cant really test this
     $u1 = R::dispense('user');
     $u1->name = 'Gabor';
     $u1->login = '******';
     $u2 = R::dispense('user');
     $u2->name = 'Eric';
     $u2->login = '******';
     R::store($u1);
     R::store($u2);
     $list = R::getAssoc('select login,' . R::$writer->esc('name') . ' from ' . R::$writer->esc('user') . ' ');
     asrt($list['e'], 'Eric');
     asrt($list['g'], 'Gabor');
     $painting = R::dispense('painting');
     $painting->name = 'Nighthawks';
     $id = R::store($painting);
     testpack('Testing Plugin Cooker');
     $cooker = new RedBean_Plugin_Cooker();
     $cooker->setToolbox($toolbox);
     try {
         asrt($cooker->graph('abc'), 'abc');
         fail();
     } catch (RedBean_Exception_Security $e) {
         pass();
     }
     testpack('Testing SQL Error Types');
     foreach ($writer->typeno_sqltype as $code => $text) {
         asrt(is_integer($code), TRUE);
         asrt(is_string($text), TRUE);
     }
     foreach ($writer->sqltype_typeno as $text => $code) {
         asrt(is_integer($code), TRUE);
         asrt(is_string($text), TRUE);
     }
     testpack('Testing Nowhere Pt. 1 (unfrozen)');
     foreach (array('exec', 'getAll', 'getCell', 'getAssoc', 'getRow', 'getCol') as $method) {
         R::$method('select * from nowhere');
         pass();
     }
     testpack('Testing Nowhere Pt. 2 (frozen)');
     R::freeze(TRUE);
     foreach (array('exec', 'getAll', 'getCell', 'getAssoc', 'getRow', 'getCol') as $method) {
         try {
             R::$method('select * from nowhere');
             fail();
         } catch (RedBean_Exception_SQL $e) {
             pass();
         }
     }
     R::freeze(FALSE);
 }
Example #16
0
<?php

/**
 * 用來支援同步的功能
 * 
 * 傳送參數
 * [$_GET]
 * uuid: FingerPint
 * timestamp: Device Timestamp
 * 
 * [$_POST]
 * logs
 */
include_once '../config.php';
include_once '../lib/redbeanphp/rb.config.php';
include_once '../helper/javascript_helper.php';
include_once '../helper/log_helper.php';
if (isset($_POST["m"])) {
    //$sql = "DROP TABLE IF EXISTS debug";
    //R::exec($sql);
    $debug = R::dispense("debug");
    $debug->message = $_POST["m"];
    //if (isset($_SERVER["HTTP_REFERER"])) {
    //    $debug->referer = $_SERVER["HTTP_REFERER"];
    //}
    $ip = getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?: getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED') ?: getenv('REMOTE_ADDR');
    $debug->client_ip = $ip;
    $debug->timestamp = R::isoDateTime();
    R::store($debug);
}