예제 #1
0
_::define_controller('registro2', function () {
    // todo: codigo promocional; seleccion de servidor
    define('EXTERA_PAGE', true);
    $nick = _::$post['username'];
    $email = _::$post['email'];
    $pass = _::$post['password'];
    $email = _::$post['email'];
    $pass2 = _::$post['passwordConfirm'];
    $error = null;
    // chequeamos que el nick sea razonable
    try {
        if ($nick->len() < 3 || $nick->len() > 32) {
            throw new exception('nick no valido, al menos 3 y menos de 32 caracteres');
        }
        if (!$email->isEmail()) {
            throw new exception('email no valido');
        }
        if ($pass->len() < 8) {
            throw new exception('La pass debe tener al menos 8 caracteres');
        }
        if ((string) $pass !== (string) $pass2) {
            throw new exception('Las pass no coinciden');
        }
        // bueno esta todo ok asique revisamos si existe alguien con este nick
        if (usuarios::exists((string) $nick)) {
            throw new exception('ya existe un usuario con este nick');
        }
        $user = new usuarios();
        $user->nick_usuario = (string) $nick;
        $user->pass_usuario = (string) $pass->hash();
        $user->plan_usuario = 0;
        // por cuanto tiempo?
        $fecha = new _date();
        $user->fecha_pago_usuario = $fecha->count();
        // si hay código de promoción
        if (isset(_::$post['codigopromocional'])) {
            // comprobamos si existe el código
            // evaluamos qué da
            $user->plan_usuario = 1;
            // dentro de 99 años, 11 meses
            $user->fecha_pago_usuario = $fecha->years(99)->months(11)->count();
        }
        if (isset(_::$post['referido'])) {
            $idref = usuarios::exists((string) _::$post['referido']);
            if ($idref) {
                $user->referido = $idref;
            } else {
                throw new Exception('el usuario referido no existe');
            }
        } else {
            $user->referido = 0;
        }
        $user->email_paypal = (string) $email;
        // DESIGNAMOS SERVIDOR
        $user->server_asignado = 1;
        $user->fondos_usuario = 0;
        $user->cuenta_activa = 1;
        // THIS SAVE THE NEW DATA IN THE OBJECT, DUMPING ALL DATA IN TABLE
        // like as INSERT or UPDATE depending if the object construct using parametter to specify primary key or not
        $user->save();
        // hay que enviar mail aquí
        _::$view->show('registro_ok');
    } catch (Exception $e) {
        _::$view->assign('error', $e->getMessage());
        _::$view->show('registro');
    }
});
예제 #2
0
<?php

_::define_controller('mail', function () {
    // simple mail, not SMTP!
    _::declare_component('mailer');
    $html = 'hello <b>world</b>, go to mi site please <a href="http://google.com">mi site</a>';
    $mail = new mailer('*****@*****.**', '*****@*****.**', 'testing mailer', $html);
    $result = $mail->send();
    if (!$result) {
        die($mail->error_message);
    }
}, true);
<?php

_::define_controller('ipn_request', function () {
    _::declare_component('ipn');
    $data = new ipn();
    $data->transaction_id;
    $data->item_name;
    $data->payment_status;
    $data->amount;
    $data->currency;
    $data->receiver_email;
    $data->client_email;
}, true);
예제 #4
0
<?php

_::define_controller('search', function () {
    _::declare_component('searcher');
    $toSearch = _::$post['q'];
    $search = new Buscador((string) $toSearch);
    // get querys to execute in db
    $querys = $search->getQuerys();
    foreach ($querys as $query) {
        $pdo = _::$db->prepare('SELECT id FROM posts WHERE title_post LIKE \'%' . $query . '%\'');
        $pdo->execute();
        $results = $pdo->fetchAll();
        // join all results
        $search->merge($results);
    }
    $LIMIT = 10;
    // limit of results
    // delete repeated results
    $results = $search->filterQuerys('id', $LIMIT);
    // $search->error (BOOLEAN)
    /* $search->error_id (ONE OF THIS CONSTANTS:
     * BUSCADOR_TEXTO_PEQUENIO, BUSCADOR_PALABRAS_PEQUENIAS, BUSCADOR_MUCHAS_PALABRAS
     * Little TEXT, little words, many words, respectively)
     */
    // now, in $results is array of results
}, true);
예제 #5
0
<?php

_::define_controller('download', function () {
    _::declare_component('file');
    // force download uploads/file.php
    $file = new file('uploads/', 'file.php');
    $file->download();
});
_::define_controller('upload', function () {
    _::declare_component('file');
    // for upload:
    $file = new file();
    $location = $file->upload('FIELD', 'uploads/', true, true, array('jpg', 'jpeg', 'png', 'gif'));
});
예제 #6
0
_::define_controller('ajax_example', function () {
    // you need load userErrorHandler component, the framework don't load by default this component, you load it if you use.
    _::declare_component('userErrorHandler');
    // you can put declaration line in index.php if you use the component in all controllers, or out of define_controller if you use in all controllers of this file.
    // first make a erros using a key word
    _e::set('KEY_WORD', 'this is a example');
    // now when you need error, use get function:
    try {
        // This is an error
        if (true) {
            throw new Exception(_e::get('KEY_WORD'));
        }
        // use _e::get('KEY_WORD'); to get json of error
    } catch (Exception $error) {
        // now, show the standarized error json.
        _::$view->ajax_plain($error->getMessage());
    }
    // the json error, have this structure
    /*
    
    {
    	code: 000,
    	key: "KEY_WORD",
    	message: "message of error"
    }
    
    code is number automatically generated.
    */
    // if you like load other lenguaje use a json in this format:
    // {KEY_WORD: 'en otro idioma', KEY_WORD_OTHER: 'in other language'}
    // and send location of file to function loadLanguage('FILE.json');
    // _e::loadLanguage('FILE.json');
    // then automatically translate all errors.
});
예제 #7
0
_::define_controller('example_4', function () {
    // if you need redirect te code to other controller
    // isn't necessary redirect the client, you can redirect the code using
    // _::redirect('new controller');
    // this line call new controller, and stop execution of current.
    _::redirect('example_3');
    // from here it doesn't execute.
    // if you like redirect client web browser, use:
    _::redirect('http://google.com', false);
    // this stop execution of current code.
    // if you need make all records of a table, you can use:
    $records = model::getAll();
    // this is SELECT * FROM TABLE;
    // if you like add limit, you can use second parammeter:
    $records = model::getAll('LIMIT 1');
    // in the second parammeter you can use WHERE clausule, ORDER BY and LIMIT.
    // getAll is a magic function of ORM, you don't need define it in the model.
    // now, $records get an Array of ids, you need make one object at each.
    // you can use foreach:
    /**
     $objects = array();
     foreach($records as $one_record)
     {
       $objects[] = new model($one_record['primary_key']);
     }
    */
    // OR YOU CAN USE FRAMEWORK TO MAKE EASY:
    $objects = _::factory($records, 'primary_key', 'model');
    // of course, you replace primary_key and model.
    // now you have one object each record.
    // and you can set new values, use the current values, delete the record, etc.
    // you can make new functions for check if exists record, and custom functions of getAll in the model using parent::getAll('query');
    // remember, the objets represents records, the class represent the table.
    // the static functions affect all records.
    // the functions of the object affect one record.
});