From: Artem Daniliants Date: Fri, 5 Mar 2010 12:15:41 +0000 (+0200) Subject: Started working on API functionality X-Git-Tag: v0.1~77 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=51387e3b67a38cf385661d80ee3d679b85927c81 Started working on API functionality Removed example files and configured database --- diff --git a/Server/.htaccess b/Server/.htaccess index b79e25f..17599f6 100644 --- a/Server/.htaccess +++ b/Server/.htaccess @@ -2,7 +2,7 @@ RewriteEngine On # Installation directory -RewriteBase / +RewriteBase /api # Protect application and system files from being viewed RewriteRule ^(application|modules|system) - [F,L] diff --git a/Server/application/config/api.php b/Server/application/config/api.php new file mode 100644 index 0000000..95ba7a7 --- /dev/null +++ b/Server/application/config/api.php @@ -0,0 +1,9 @@ + 'mysql://dbuser:secret@localhost/kohana' + * character_set - Database character set + * table_prefix - Database table prefix + * object - Enable or disable object results + * cache - Enable or disable query caching + * escape - Enable automatic query builder escaping + */ +$config['default'] = array +( + 'benchmark' => TRUE, + 'persistent' => FALSE, + 'connection' => array + ( + 'type' => 'mysql', + 'user' => 'root', + 'pass' => 'root', + 'host' => 'localhost', + 'port' => FALSE, + 'socket' => FALSE, + 'database' => 'speedfreak' + ), + 'character_set' => 'utf8', + 'table_prefix' => '', + 'object' => TRUE, + 'cache' => FALSE, + 'escape' => TRUE +); \ No newline at end of file diff --git a/Server/application/config/routes.php b/Server/application/config/routes.php new file mode 100644 index 0000000..0121b60 --- /dev/null +++ b/Server/application/config/routes.php @@ -0,0 +1,7 @@ + + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +class Api_Controller extends Controller{ + + /* + * Default action when no parameters are given to controller + */ + public function index(){ + url::redirect(Kohana::config('api.default_redirect'),301); + } + + /* + * New user registration + */ +} \ No newline at end of file diff --git a/Server/application/controllers/examples.php b/Server/application/controllers/examples.php deleted file mode 100644 index 849418b..0000000 --- a/Server/application/controllers/examples.php +++ /dev/null @@ -1,470 +0,0 @@ -Examples:\n"; - echo "\n"; - echo '

'.Kohana::lang('core.stats_footer')."

\n"; - } - - /** - * Demonstrates how to archive a directory. First enable the archive module - */ - //public function archive($build = FALSE) - //{ - // if ($build === 'build') - // { - // // Load archive - // $archive = new Archive('zip'); - - // // Download the application/views directory - // $archive->add(APPPATH.'views/', 'app_views/', TRUE); - - // // Download the built archive - // $archive->download('test.zip'); - // } - // else - // { - // echo html::anchor(Router::$current_uri.'/build', 'Download views'); - // } - //} - - /** - * Demonstrates how to parse RSS feeds by using DOMDocument. - */ - function rss() - { - // Parse an external atom feed - $feed = feed::parse('http://dev.kohanaphp.com/projects/kohana2/activity.atom'); - - // Show debug info - echo Kohana::debug($feed); - - echo Kohana::lang('core.stats_footer'); - } - - /** - * Demonstrates the Session library and using session data. - */ - function session() - { - // Gets the singleton instance of the Session library - $s = Session::instance(); - - echo 'SESSID:
'.session_id()."
\n"; - - echo '
'.print_r($_SESSION, TRUE)."
\n"; - - echo '
{execution_time} seconds'; - } - - /** - * Demonstrates how to use the form helper with the Validation libraryfor file uploads . - */ - function form() - { - // Anything submitted? - if ($_POST) - { - // Merge the globals into our validation object. - $post = Validation::factory(array_merge($_POST, $_FILES)); - - // Ensure upload helper is correctly configured, config/upload.php contains default entries. - // Uploads can be required or optional, but should be valid - $post->add_rules('imageup1', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); - $post->add_rules('imageup2', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); - - // Alternative syntax for multiple file upload validation rules - //$post->add_rules('imageup.*', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); - - if ($post->validate() ) - { - // It worked! - // Move (and rename) the files from php upload folder to configured application folder - upload::save('imageup1'); - upload::save('imageup2'); - echo 'Validation successfull, check your upload folder!'; - } - else - { - // You got validation errors - echo '

validation errors: '.var_export($post->errors(), TRUE).'

'; - echo Kohana::debug($post); - } - } - - // Display the form - echo form::open('examples/form', array('enctype' => 'multipart/form-data')); - echo form::label('imageup', 'Image Uploads').':
'; - // Use discrete upload fields - // Alternative syntax for multiple file uploads - // echo form::upload('imageup[]').'
'; - - echo form::upload('imageup1').'
'; - echo form::upload('imageup2').'
'; - echo form::submit('upload', 'Upload!'); - echo form::close(); - - } - - /** - * Demontrates how to use the Validation library to validate an arbitrary array. - */ - function validation() - { - // To demonstrate Validation being able to validate any array, I will - // be using a pre-built array. When you load validation with no arguments - // it will default to validating the POST array. - $data = array - ( - 'user' => 'hello', - 'pass' => 'bigsecret', - 'reme' => '1' - ); - - $validation = new Validation($data); - - $validation->add_rules('user', 'required', 'length[1,12]')->pre_filter('trim', 'user'); - $validation->add_rules('pass', 'required')->post_filter('sha1', 'pass'); - $validation->add_rules('reme', 'required'); - - $result = $validation->validate(); - - var_dump($validation->errors()); - var_dump($validation->as_array()); - - // Yay! - echo '{execution_time} ALL DONE!'; - } - - /** - * Demontrates how to use the Captcha library. - */ - public function captcha() - { - // Look at the counters for valid and invalid - // responses in the Session Profiler. - new Profiler; - - // Load Captcha library, you can supply the name - // of the config group you would like to use. - $captcha = new Captcha; - - // Ban bots (that accept session cookies) after 50 invalid responses. - // Be careful not to ban real people though! Set the threshold high enough. - if ($captcha->invalid_count() > 49) - exit('Bye! Stupid bot.'); - - // Form submitted - if ($_POST) - { - // Captcha::valid() is a static method that can be used as a Validation rule also. - if (Captcha::valid($this->input->post('captcha_response'))) - { - echo '

Good answer!

'; - } - else - { - echo '

Wrong answer!

'; - } - - // Validate other fields here - } - - // Show form - echo form::open(); - echo '

Other form fields here...

'; - - // Don't show Captcha anymore after the user has given enough valid - // responses. The "enough" count is set in the captcha config. - if ( ! $captcha->promoted()) - { - echo '

'; - echo $captcha->render(); // Shows the Captcha challenge (image/riddle/etc) - echo '

'; - echo form::input('captcha_response'); - } - else - { - echo '

You have been promoted to human.

'; - } - - // Close form - echo form::submit(array('value' => 'Check')); - echo form::close(); - } - - /** - * Demonstrates the features of the Database library. - * - * Table Structure: - * CREATE TABLE `pages` ( - * `id` mediumint( 9 ) NOT NULL AUTO_INCREMENT , - * `page_name` varchar( 100 ) NOT NULL , - * `title` varchar( 255 ) NOT NULL , - * `content` longtext NOT NULL , - * `menu` tinyint( 1 ) NOT NULL default '0', - * `filename` varchar( 255 ) NOT NULL , - * `order` mediumint( 9 ) NOT NULL , - * `date` int( 11 ) NOT NULL , - * `child_of` mediumint( 9 ) NOT NULL default '0', - * PRIMARY KEY ( `id` ) , - * UNIQUE KEY `filename` ( `filename` ) - * ) ENGINE = MYISAM DEFAULT CHARSET = utf8 PACK_KEYS =0; - * - */ - function database() - { - $db = new Database; - - $table = 'pages'; - echo 'Does the '.$table.' table exist? '; - if ($db->table_exists($table)) - { - echo '

YES! Lets do some work =)

'; - - $query = $db->select('DISTINCT pages.*')->from($table)->get(); - echo $db->last_query(); - echo '

Iterate through the result:

'; - foreach ($query as $item) - { - echo '

'.$item->title.'

'; - } - echo '

Numrows using count(): '.count($query).'

'; - echo 'Table Listing:
'.print_r($db->list_tables(), TRUE).'
'; - - echo '

Try Query Binding with objects:

'; - $sql = 'SELECT * FROM '.$table.' WHERE id = ?'; - $query = $db->query($sql, array(1)); - echo '

'.$db->last_query().'

'; - $query->result(TRUE); - foreach ($query as $item) - { - echo '
'.print_r($item, true).'
'; - } - - echo '

Try Query Binding with arrays (returns both associative and numeric because I pass MYSQL_BOTH to result():

'; - $sql = 'SELECT * FROM '.$table.' WHERE id = ?'; - $query = $db->query($sql, array(1)); - echo '

'.$db->last_query().'

'; - $query->result(FALSE, MYSQL_BOTH); - foreach ($query as $item) - { - echo '
'.print_r($item, true).'
'; - } - - echo '

Look, we can also manually advance the result pointer!

'; - $query = $db->select('title')->from($table)->get(); - echo 'First:
'.print_r($query->current(), true).'

'; - $query->next(); - echo 'Second:
'.print_r($query->current(), true).'

'; - $query->next(); - echo 'Third:
'.print_r($query->current(), true).'
'; - echo '

And we can reset it to the beginning:

'; - $query->rewind(); - echo 'Rewound:
'.print_r($query->current(), true).'
'; - - echo '

Number of rows using count_records(): '.$db->count_records('pages').'

'; - } - else - { - echo 'NO! The '.$table.' table doesn\'t exist, so we can\'t continue =( '; - } - echo "

\n"; - echo 'done in {execution_time} seconds'; - } - - /** - * Demonstrates how to use the Pagination library and Pagination styles. - */ - function pagination() - { - $pagination = new Pagination(array( - // Base_url will default to the current URI - // 'base_url' => 'welcome/pagination_example/page/x', - - // The URI segment (integer) in which the pagination number can be found - // The URI segment (string) that precedes the pagination number (aka "label") - 'uri_segment' => 'page', - - // You could also use the query string for pagination instead of the URI segments - // Just set this to the $_GET key that contains the page number - // 'query_string' => 'page', - - // The total items to paginate through (probably need to use a database COUNT query here) - 'total_items' => 254, - - // The amount of items you want to display per page - 'items_per_page' => 10, - - // The pagination style: classic (default), digg, extended or punbb - // Easily add your own styles to views/pagination and point to the view name here - 'style' => 'classic', - - // If there is only one page, completely hide all pagination elements - // Pagination->render() will return an empty string - 'auto_hide' => TRUE, - )); - - // Just echo to display the links (__toString() rocks!) - echo 'Classic style: '.$pagination; - - // You can also use the render() method and pick a style on the fly if you want - echo '
Digg style: ', $pagination->render('digg'); - echo '
Extended style: ', $pagination->render('extended'); - echo '
PunBB style: ', $pagination->render('punbb'); - echo 'done in {execution_time} seconds'; - } - - /** - * Demonstrates the User_Agent library. - */ - function user_agent() - { - foreach (array('agent', 'browser', 'version') as $key) - { - echo $key.': '.Kohana::user_agent($key).'
'."\n"; - } - - echo "

\n"; - echo 'done in {execution_time} seconds'; - } - - /** - * Demonstrates the Payment library. - */ - /*function payment() - { - $credit_card = new Payment; - - // You can also pass the driver name to the library to use multiple ones: - $credit_card = new Payment('Paypal'); - $credit_card = new Payment('Authorize'); - - // You can specify one parameter at a time: - $credit_card->login = 'this'; - $credit_card->first_name = 'Jeremy'; - $credit_card->last_name = 'Bush'; - $credit_card->card_num = '1234567890'; - $credit_card->exp_date = '0910'; - $credit_card->amount = '478.41'; - - // Or you can also set fields with an array and the method: - $credit_card->set_fields(array('login' => 'test', - 'first_name' => 'Jeremy', - 'last_name' => 'Bush', - 'card_num' => '1234567890', - 'exp_date' => '0910', - 'amount' => '487.41')); - - echo '
'.print_r($credit_card, true).'
'; - - echo 'Success? '; - echo ($response = $credit_card->process() == TRUE) ? 'YES!' : $response; - }*/ - - function calendar() - { - $profiler = new Profiler; - - $calendar = new Calendar($this->input->get('month', date('m')), $this->input->get('year', date('Y'))); - $calendar->attach($calendar->event() - ->condition('year', 2008) - ->condition('month', 8) - ->condition('day', 8) - ->output(html::anchor('http://forum.kohanaphp.com/comments.php?DiscussionID=275', 'Learning about Kohana Calendar'))); - - echo $calendar->render(); - } - - /** - * Demonstrates how to use the Image libarary.. - */ - function image() - { - // For testing only, save the new image in DOCROOT - $dir = realpath(DOCROOT); - - // Original Image filename - $image = DOCROOT.'kohana.png'; - - // Create an instance of Image, with file - // The orginal image is not affected - $image = new Image($image); - - // Most methods are chainable - // Resize the image, crop the center left - $image->resize(200, 100)->crop(150, 50, 'center', 'left'); - - // Display image in browser. - // Keep the actions, to be applied when saving the image. - $image->render($keep_actions = TRUE); - - // Save the image, as a jpeg - // Here the actions will be discarded, by default. - $image->save($dir.'/mypic_thumb.jpg'); - - //echo Kohana::debug($image); - } - - /** - * Demonstrates how to use vendor software with Kohana. - */ - function vendor() - { - // Let's do a little Markdown shall we. - $br = "\n\n"; - $output = '#Marked Down!#'.$br; - $output .= 'This **_markup_** is created *on-the-fly*, by '; - $output .= '[php-markdown-extra](http://michelf.com/projects/php-markdown/extra)'.$br; - $output .= 'It\'s *great* for user & writing about ``'.$br; - $output .= 'It\'s also good at footnotes :-) [^1]'.$br; - $output .= '[^1]: A footnote.'; - - // looks in system/vendor for Markdown.php - require Kohana::find_file('vendor', 'Markdown'); - - echo Markdown($output); - - echo 'done in {execution_time} seconds'; - } -} // End Examples diff --git a/Server/application/controllers/welcome.php b/Server/application/controllers/welcome.php deleted file mode 100644 index 8941953..0000000 --- a/Server/application/controllers/welcome.php +++ /dev/null @@ -1,54 +0,0 @@ -template->content = new View('welcome_content'); - - // You can assign anything variable to a view by using standard OOP - // methods. In my welcome view, the $title variable will be assigned - // the value I give it here. - $this->template->title = 'Welcome to Kohana!'; - - // An array of links to display. Assiging variables to views is completely - // asyncronous. Variables can be set in any order, and can be any type - // of data, including objects. - $this->template->content->links = array - ( - 'Home Page' => 'http://kohanaphp.com/', - 'Documentation' => 'http://docs.kohanaphp.com/', - 'Forum' => 'http://forum.kohanaphp.com/', - 'License' => 'Kohana License.html', - 'Donate' => 'http://kohanaphp.com/donate', - ); - } - - public function __call($method, $arguments) - { - // Disable auto-rendering - $this->auto_render = FALSE; - - // By defining a __call method, all pages routed to this controller - // that result in 404 errors will be handled by this method, instead of - // being displayed as "Page Not Found" errors. - echo 'This text is generated by __call. If you expected the index page, you need to use: welcome/index/'.substr(Router::$current_uri, 8); - } - -} // End Welcome Controller \ No newline at end of file diff --git a/Server/application/views/welcome_content.php b/Server/application/views/welcome_content.php deleted file mode 100644 index 0adcab6..0000000 --- a/Server/application/views/welcome_content.php +++ /dev/null @@ -1,15 +0,0 @@ - -
-

This is the default Kohana index page. You may also access this page as .

- -

- To change what gets displayed for this page, edit application/controllers/welcome.php.
- To change this text, edit application/views/welcome_content.php. -

-
- - \ No newline at end of file diff --git a/Server/install.php b/Server/install.php deleted file mode 100644 index a380710..0000000 --- a/Server/install.php +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - -Kohana Installation - - - - - - -

Environment Tests

- -

The following tests have been run to determine if Kohana will work in your environment. If any of the tests have failed, consult the documentation for more information on how to correct the problem.

- -
- - - - -=')): ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PHP VersionKohana requires PHP 5.2 or newer, this version is .
System DirectoryThe configured system directory does not exist or does not contain required files.
Application DirectoryThe configured application directory does not exist or does not contain required files.
Modules DirectoryThe configured modules directory does not exist or does not contain required files.
PCRE UTF-8PCRE support is missing.PCRE has not been compiled with UTF-8 support.PCRE has not been compiled with Unicode property support.Pass
Reflection EnabledPassPHP reflection is either not loaded or not compiled in.
Filters EnabledPassThe filter extension is either not loaded or not compiled in.
Iconv Extension LoadedPassThe iconv extension is not loaded.
SPL EnabledPassSPL is not enabled.
Mbstring Not OverloadedThe mbstring extension is overloading PHP's native string functions.Pass
XML supportPHP is compiled without XML support, thus lacking support for utf8_encode()/utf8_decode().Pass
URI DeterminationPassNeither $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF'] is available.
- -
- -

Kohana may not work correctly with your environment.

- -

Your environment passed all requirements. Remove or rename the install file now.

- -
- -
- - - \ No newline at end of file