public function action_editImage() { // Load field, and the image-date field that connects to it $fieldid = $_POST["fieldid"]; $field = Wi3::inst()->model->factory("site_field")->set("id", $fieldid)->load(); // Update e-mailaddress $email = Wi3::inst()->model->factory("site_data")->setref($field)->setname("emailaddress")->load(); // If data does not exist, create it if (!$email->loaded()) { $email->create(); } // Update data field with image-id $emailaddress = $_POST["emailaddress"]; $email->data = $emailaddress; $email->update(); echo Kohana::debug($email); exit; // Update folder $data = Wi3::inst()->model->factory("site_data")->setref($field)->setname("folder")->load(); // If data does not exist, create it if (!$data->loaded()) { $data->create(); } // Update data field with image-id $fileid = $_POST["image"]; $data->data = $fileid; $data->update(); //$file = Wi3::inst()->model->factory("site_file")->set("id", $fileid)->load(); echo json_encode(array("scriptsbefore" => array("0" => "\$('[type=field][fieldid=" . $fieldid . "] [type=fieldcontent]').html('" . $field->render() . "');"))); }
public function action_create_superadmin() { try { $m = Wi3::inst()->model->factory("user"); $m->username = "******"; $m->email = "*****@*****.**"; $m->load(); foreach ($m->roles as $role) { $role->delete(); } $m->delete(); // TODO: make sure Sprig understands that the columns with $_in_db == FALSE should NOT be added to the delete() clause // Then, place the following line before the $m->password = "******" above $m->password = "******"; $m->password_confirm = "superadmin"; $m->create(); // Now create roles $role = Wi3::inst()->model->factory("role"); $role->name = "superadmin"; $role->description = "superadmin role"; $role->users = $m->id; $role->create(); $role = Wi3::inst()->model->factory("role"); $role->name = "login"; $role->description = "login role"; $role->users = $m->id; $role->create(); } catch (Exception $e) { echo Kohana::debug($e); return; } echo "<p>Superadminuser has been recreated.</p>"; echo "<p>Back to <a href='..'>setup</a></p>"; }
/** * Tests User_Model::custom_validate * * @test * @dataProvider provider_custom_validate */ public function test_custom_validate($valid, $invalid) { // set up mock, for prevent_superadmin_modification $auth = $this->getMock('Auth', array('logged_in')); $auth->expects($this->exactly(2))->method('logged_in')->with($this->equalTo('superadmin'))->will($this->returnValue(True)); // Save initial data $initial_valid = $valid; $initial_invalid = $invalid; // Test with valid data $response = User_Model::custom_validate($valid, $auth); $this->assertEquals(TRUE, $valid instanceof Validation); $this->assertTrue($response, Kohana::debug($valid->errors())); // Test with invalid data $response = User_Model::custom_validate($invalid, $auth); $this->assertEquals(TRUE, $invalid instanceof Validation); $this->assertFalse($response); // restore valid, invalid $valid = $initial_valid; $invalid = $initial_invalid; // Test modification to superadmin as admin $auth = $this->getMock('Auth', array('logged_in')); $auth->expects($this->once())->method('logged_in')->with($this->equalTo('superadmin'))->will($this->returnValue(False)); $response = User_Model::custom_validate($valid, $auth); $this->assertTrue($valid instanceof Validation); $this->assertFalse($response, Kohana::debug($valid->errors())); }
/** * Loads a class and uses [reflection](http://php.net/reflection) to parse * the class. Reads the class modifiers, constants and comment. Parses the * comment to find the description and tags. * * @param string class name * @return void */ public function __construct($class) { $this->class = new ReflectionClass($class); if ($modifiers = $this->class->getModifiers()) { $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> '; } if ($constants = $this->class->getConstants()) { foreach ($constants as $name => $value) { $this->constants[$name] = Kohana::debug($value); } } $parent = $this->class; do { if ($comment = $parent->getDocComment()) { // Found a description for this class break; } } while ($parent = $parent->getParentClass()); list($this->description, $this->tags) = Kodoc::parse($comment); // If this class extends Kodoc_Missing, add a warning about possible // incomplete documentation $parent = $this->class; while ($parent = $parent->getParentClass()) { if ($parent->name == 'Kodoc_Missing') { $warning = "[!!] **This class, or a class parent, could not be\n\t\t\t\t found or loaded. This could be caused by a missing\n\t\t\t\t\t\t module or other dependancy. The documentation for\n\t\t\t\t\t\t class may not be complete!**"; $this->description = Markdown($warning) . $this->description; } } }
function index() { if ($_POST) { echo Kohana::debug($_POST); } }
public function action_index() { //$db = new Database; $dbmanager = DBManager::instance(); //echo $dbmanager->get_version(); //echo $dbmanager->total_tables(); // List tables //echo '==================<br />List tables<br />=================='; //$tables = $dbmanager->list_tables(); //echo Kohana::debug($tables); // Only list name of tables //echo '==================<br />Only list name of tables<br />=================='; //$table_name = $db->list_tables(); //echo Kohana::debug($table_name); // List backup files //echo '==================<br />List backup files<br />=================='; //echo Kohana::debug($dbmanager->list_backfiles()); // Optimize Tables //echo '==================<br />Optimize Tables<br />==================<br />'; //$result = $dbmanager->optimize_tables($table_name); //if ( !empty($result) ) // echo $result; //else // echo '全部优化完毕'; echo '==================<br />Backup Tables<br />==================<br />'; echo 'Next Backup time: ' . $dbmanager->next_backup_time() . '<br />'; echo Kohana::debug($dbmanager->backup_db()); // Download backup file. $filename = '1234567890_-_database.sql' // $dbmanager->download_backup($filename); // Delete backup file. $filename = '1234567890_-_database.sql' // $dbmanager->delete_backup($filename); // Display the demo page //$this->template->title = 'Database Manager'; //$this->template->content = ; }
public function edit($id) { $user = User_Model::current(); $project = ORM::factory('project', $id); if (!$user->loaded && $project->user_can($user, 'edit')) { return $this->template->content = 'oh, come on!'; } if ($post = $this->input->post('project')) { $validation = Projects_utils::projects_edit_validation($post); if (!$project->validate($validation, true)) { return $this->template->content = Kohana::debug($validation->errors()); } if ($additional_user_emails = $this->input->post('additional_user_emails')) { $additional_user_roles = $this->input->post('additional_user_roles'); foreach ($additional_user_emails as $email) { Profiles_utils::reserve_email_if_available($email); } $additional_users = array_combine($additional_user_emails, $additional_user_roles); $project->add_user_roles($additional_users); } url::redirect($project->local_url); } else { HTMLPage::add_style('forms'); $this->template->content = View::factory('projects/edit')->bind('project_types', Projects_utils::get_project_types_dropdown_array())->bind('project', $project)->bind('user', $user); } }
public function demo_login() { // Attempt to complete signin if ($code = Arr::get($_REQUEST, 'code')) { // Exchange the authorization code for an access token $token = $this->provider->access_token($this->client, $code); // Store the access token $this->session->set($this->key('access'), $token); // Refresh the page to prevent errors $this->request->redirect($this->request->uri); } if ($this->token) { // Login succesful $this->content = Kohana::debug('Access token granted:', $this->token); } else { // We will need a callback URL for the user to return to $callback = $this->request->url(NULL, TRUE); // Add the callback URL to the consumer $this->client->callback($callback); // Get the login URL from the provider $url = $this->provider->authorize_url($this->client); // Redirect to the twitter login page $this->content = HTML::anchor($url, "Login to {$this->api}"); } }
public function __construct($e) { $this->message = $e->getMessage(); $this->code = $e->getCode(); $err = $e->getMessage() . "\n" . Kohana::debug($e->getTraceAsString()); Kohana::log('error', $err); }
public function __construct($class, $property) { $property = new ReflectionProperty($class, $property); list($description, $tags) = Kodoc::parse($property->getDocComment()); $this->description = $description; if ($modifiers = $property->getModifiers()) { $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> '; } if (isset($tags['var'])) { if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) { $this->type = $matches[1]; if (isset($matches[2])) { $this->description = Markdown($matches[2]); } } } $this->property = $property; // Show the value of static properties, but only if they are public or we are php 5.3 or higher and can force them to be accessible if ($property->isStatic() and ($property->isPublic() or version_compare(PHP_VERSION, '5.3', '>='))) { // Force the property to be accessible if (version_compare(PHP_VERSION, '5.3', '>=')) { $property->setAccessible(TRUE); } // Don't debug the entire object, just say what kind of object it is if (is_object($property->getValue($class))) { $this->value = '<pre>object ' . get_class($property->getValue($class)) . '()</pre>'; } else { $this->value = Kohana::debug($property->getValue($class)); } } }
public function __construct($file) { if ($filename = Kohana::find_file('config', $file)) { $this->name = $file; $source = file_get_contents($filename[0]); $start_offset = 0; // Find the config file comment first if (preg_match('~(/\\*.*?\\*/)~s', $source, $config_comment)) { $comment = Kodoc::parse($config_comment[0]); $this->description = $comment[0]; $this->tags = $comment[1]; $start_offset = strlen($config_comment[0]); } preg_match_all('~(/\\*.*?\\*/)?\\s*(\\$config\\[([^\\]]+)]\\s*=\\s*([^;]*?);)~s', $source, $matches, PREG_SET_ORDER, $start_offset); foreach ($matches as $item) { $comment = Kodoc::parse($item[1]); $default = isset($comment[1]['default'][0]) ? Kohana::debug($comment[1]['default'][0]) : NULL; // Remove the @default tag unset($comment[1]['default']); $this->options[] = (object) array('description' => $comment[0], 'source' => $item[2], 'name' => trim($item[3], '\'"'), 'default' => $default, 'tags' => $comment[1]); } } else { throw new Kohana_Exception('Error reading config file'); } }
public function __set($prop, $value) { Kohana::log('debug', $prop . ' -> ' . Kohana::debug($value)); if ('tags' == $prop && is_string($value)) { return $this->set_tags($value); } return parent::__set($prop, $value); }
public function unpublished() { $documents = new Document_Model(); $documents = ORM::factory("Document")->where('viewable', 'n')->orderby(array('create_dt' => 'asc'))->find_all(); echo Kohana::debug($documents); $this->template->title = "Listing unpublished uploads"; $this->template->content = new View('pages/doc_unpub'); $this->template->content->documents = $documents; }
public function out() { $args = func_get_args(); $str = array_shift($args); echo "<pre>{$str}</pre>"; foreach ($args as $arg) { echo Kohana::debug($arg); } }
/** * Tests the validate() method in Form Field Data * * @test * @dataProvider providerValidate * @param array $valid Valid data for the test * @param array $invalid Invalid data for the test * @param array $save Saves the record when validation succeeds */ public function testValidate($valid, $invalid, $save) { // Model instance for the test $form_field = new Form_Field_Model(); // Valid data test $this->assertEquals(TRUE, $form_field->validate($valid, $save), Kohana::debug($valid->errors())); // Invalid data test $this->assertEquals(FALSE, $form_field->validate($invalid, $save), sprintf("Expected errors not found. Error count: %d", count($invalid->errors()))); }
static function activate_sidebar_blocks($module_name) { $block_class = "{$module_name}_block"; if (method_exists($block_class, "get_site_list")) { $blocks = call_user_func(array($block_class, "get_site_list")); Kohana::log("error", Kohana::debug($blocks)); foreach (array_keys($blocks) as $block_id) { self::add("site.sidebar", $module_name, $block_id); } } }
/** * Tests User_Model::custom_validate * * @test * @dataProvider provider_custom_validate */ public function test_custom_validate($valid, $invalid) { // Test with valid data $response = User_Model::custom_validate($valid); $this->assertEquals(TRUE, $valid instanceof Validation); $this->assertTrue($response, Kohana::debug($valid->errors())); // Test with invalid data $response = User_Model::custom_validate($invalid); $this->assertEquals(TRUE, $invalid instanceof Validation); $this->assertFalse($response); }
public function upload() { $profiler = new Profiler(); $form = new Forge(); $form->input('hello')->label(TRUE); $form->upload('file', TRUE)->label(TRUE)->rules('required|size[200KB]|allow[jpg,png,gif]'); $form->submit('upload')->value('Upload'); if ($form->validate()) { echo Kohana::debug($form->as_array()); } echo $form->render(); }
/** * Loads the session data from the database. * * @return string */ public function _read() { if ($id = cookie::get($this->_name)) { $result = DB::query(Database::SELECT, 'SELECT data FROM ' . $this->_table . ' WHERE session_id = :id LIMIT 1')->set(':id', $id)->execute($this->_db); if ($result->count()) { // Set the current session id $this->_session_id = $this->_update_id = $id; echo Kohana::debug('loaded data'); // Return the data string return $result->get('data'); } } // Create a new session id $this->_regenerate(); return NULL; }
/** * Tests customforms::validate_custom_form_fields() * * @dataProvider providerTestValidateCustomFormFields */ public function testValidateCustomFormFields($valid_data, $invalid_data) { // Setup validation objects for the valid custom forms data $valid_validator = Validation::factory($valid_data)->pre_filter('trim', TRUE); // Get the return value for validation of valid date $errors = customforms::validate_custom_form_fields($valid_validator); // Assert that validation of the valid data returns no errors $this->assertEquals(0, count($errors), "Some errors have been found" . Kohana::debug($errors)); // Set up validation for the invalid custom forms data $invalid_validator = Validation::factory($invalid_data)->pre_filter('trim', TRUE); // Get the return value for validation of invalid data $errors = customforms::validate_custom_form_fields($invalid_validator); // Assert that the validation of the invalid data returns some errors $this->assertEquals(TRUE, count($errors) > 0, "Expected to encounter errors. None found: " . count($errors)); // Garbage collection unset($valid_validator, $invalid_validator, $errors); }
/** * Loads the landing page for this controller */ public function index() { // Set the current page $this->template->this_page = "addons"; // Nexmo settings view $this->template->content = new View('admin/addons/plugin_settings'); $this->template->content->title = Kohana::lang('nexmo.settings'); $this->template->content->settings_form = new View('nexmo/admin/nexmo_settings'); // Set up the form fields $form = array('nexmo_api_key' => '', 'nexmo_api_secret' => '', 'nexmo_phone_no' => ''); // Get the current settings $nexmo = ORM::factory('nexmo', 1)->loaded ? ORM::factory('nexmo', 1) : new Nexmo_Model(); // Has the form been submitted if ($_POST) { // Extract the data to be validated $nexmo_data = arr::extract($_POST, 'nexmo_api_key', 'nexmo_api_secret', 'nexmo_phone_no'); Kohana::log('debug', Kohana::debug($nexmo_data)); // Invoke model validation on the data if ($nexmo->validate($nexmo_data)) { $nexmo->save(); } } // Check if authorization keys have been set if (empty($nexmo->delivery_receipt_key)) { // Key for authenticating delivery receipt not set, therefore generate $nexmo->delivery_receipt_key = strtoupper(text::random('alnum', 10)); // Save $nexmo->save(); } if (empty($nexmo->inbound_message_key)) { // Key for authenticating incoming messages not set, therefore generate $nexmo->inbound_message_key = strtoupper(text::random('alnum', 10)); // Save $nexmo->save(); } // Set the form data $form = array('nexmo_api_key' => $nexmo->nexmo_api_key, 'nexmo_api_secret' => $nexmo->nexmo_api_secret, 'nexmo_phone_no' => $nexmo->nexmo_phone_no); // Set the content for the view $this->template->content->settings_form->form = $form; // Set the DLR and incoming message URLs $this->template->content->settings_form->delivery_receipt_url = url::site() . 'nexmo/delivery/?key=' . $nexmo->delivery_receipt_key; $this->template->content->settings_form->inbound_message_url = url::site() . 'nexmo/inbound/?key=' . $nexmo->inbound_message_key; // Javascript header $this->template->js = new View('nexmo/admin/nexmo_settings_js'); }
public function index() { if ($post = $this->input->post('contact')) { $validation = new Validation($post); $validation->pre_filter('trim')->add_rules('email', 'email', 'required')->add_rules('subject', 'required')->add_rules('body', 'required'); if (!$validation->validate()) { return $this->template->content = Kohana::debug($validation->errors()); } $post = $validation->as_array(); $message = sprintf("%s used the contact form to say: \n\n %s", $post['email'], $post['body']); $subject = sprintf('[ProjectsLounge Contact] %s', $post['subject']); email::send('*****@*****.**', '*****@*****.**', $subject, $message); return url::redirect('contact/thanks'); } HTMLPage::add_style('forms'); HTMLPage::add_style('contact'); $this->template->content = View::factory('contact/form'); }
public function __construct($class_name) { $class_prefix = Kohana::config('core.extension_prefix'); if (substr($class_name, 0, strlen($class_prefix)) === $class_prefix) { $class_name = substr($class_name, strlen($class_prefix)); } $class = $parent = new ReflectionClass($class_name); $this->name = $class->name; $this->parents = array(); if ($modifiers = $class->getModifiers()) { $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> '; } if ($constants = $class->getConstants()) { foreach ($constants as $name => $value) { $this->constants[$name] = Kohana::debug($value); } } if ($props = $class->getProperties()) { foreach ($props as $key => $property) { // Only show public properties, because Reflection can't get the private ones if ($property->isPublic()) { $this->properties[$key] = new Kodoc_Property($class->name, $property->name); } } } if ($methods = $class->getMethods()) { foreach ($methods as $key => $method) { // Only show methods declared in this class $declaring_class = str_replace('_Core', '', $method->getDeclaringClass()->name); if ($declaring_class === $class->name) { $this->methods[$key] = new Kodoc_Method($class->name, $method->name); } } } do { // Skip the comments in the bootstrap file if ($comment = $parent->getDocComment() and basename($parent->getFileName()) !== 'Bootstrap.php') { // Found a description for this class break; } } while ($parent = $parent->getParentClass()); list($this->description, $this->tags) = Kodoc::parse($comment); }
/** * query the database for valid login * * @param array $where * @return object * @author Andy Bennett */ function test_login_query($where) { $this->db->select()->from($this->get_table())->where($where); $sql = $this->db->getsql(); $sql = str_replace('`{identity}`', 'LOWER(`' . $this->conf->identity_column . '`)', $sql); $r = $this->db->query($sql); if (!$r->count()) { Kohana::log('error', 'u/p error:' . Kohana::debug($_POST)); throw new Exception('<span class="form-error">Incorrect username or password</span>'); } $r->rewind(); $row = $r->current(); // set last visit in db $sql = 'UPDATE ' . $this->table . ' SET last_visit="' . date("Y-m-d H:i:s") . '" WHERE id="' . $row->id . '"'; $this->db->query($sql); // store the data in the session Session::instance()->set('auth_data', $row); return $r; }
function editgood() { $data = Validate::factory(array_merge($_POST, $_FILES))->label('edit_name', 'наименование')->label('edit_id', 'id')->label('edit_price', 'цена')->rule('edit_name', 'not_empty')->rule('edit_price', 'not_empty')->rule('edit_id', 'not_empty')->label('edit_photo', 'фото')->rule('edit_photo', 'upload::type', array(array('gif', 'png', 'jpg'))); if ($data->check()) { for ($i = 0; $i < count($_POST['edit_id']); $i++) { // If new photo exist if (!empty($_FILES['edit_photo']['name'][$i])) { echo Kohana::debug($_FILES); $arr = array('edit_photo' => array('name' => $_FILES['edit_photo']['name'][$i], 'type' => $_FILES['edit_photo']['type'][$i], 'tmp_name' => $_FILES['edit_photo']['tmp_name'][$i], 'error' => $_FILES['edit_photo']['error'][$i], 'size' => $_FILES['edit_photo']['size'][$i])); $photo = upload::save($arr['edit_photo'], $_FILES['edit_photo']['name'][$i]); DB::update('goods')->set(array('name' => $_POST['edit_name'][$i], 'price' => $_POST['edit_price'][$i], 'description' => $_POST['edit_description'][$i], 'photo' => $_FILES['edit_photo']['name'][$i]))->where('id', '=', $_POST['edit_id'][$i])->execute(); } else { DB::update('goods')->set(array('name' => $_POST['edit_name'][$i], 'description' => $_POST['edit_description'][$i], 'price' => $_POST['edit_price'][$i]))->where('id', '=', $_POST['edit_id'][$i])->execute(); } } return TRUE; } else { return strtolower(implode(' и ', $data->errors(''))); } }
/** * Loads a class and uses [reflection](http://php.net/reflection) to parse * the class. Reads the class modifiers, constants and comment. Parses the * comment to find the description and tags. * * @param string class name * @return void */ public function __construct($class) { $this->class = new ReflectionClass($class); if ($modifiers = $this->class->getModifiers()) { $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> '; } if ($constants = $this->class->getConstants()) { foreach ($constants as $name => $value) { $this->constants[$name] = Kohana::debug($value); } } $parent = $this->class; do { if ($comment = $parent->getDocComment()) { // Found a description for this class break; } } while ($parent = $parent->getParentClass()); list($this->description, $this->tags) = Kodoc::parse($comment); }
public function _oldest_timestamp() { $oldest_timestamp = Event::$data; $db = new Database; if ($_POST) { $oldest_timestamp = $db->query("select max(i.incident_date) from incident as i, filter_incident_constituency as icon where i.incident_active = 1 and i.id = icon.incident_id"); //$oldest_timestamp = strtotime($oldest_timestamp); Event::$data = $oldest_timestamp; echo Kohana::debug($oldest_timestamp); } else { $oldest_timestamp = $db->query("select max(incident_date) from incident where incident_active = 1"); //$oldest_timestamp = strtotime($oldest_timestamp); Event::$data = $oldest_timestamp; echo Kohana::debug($oldest_timestamp); } }
function upimg($imagefile) { $this->file_type = $imagefile['type']; if (!($this->file_type != 'image/jpg' && $this->file_type != 'image/x-png' && $this->file_type != 'image/pjpeg' && $this->file_type != 'image/jpeg' && $this->file_type != 'image/gif' && $this->file_type != 'image/png')) { //Execute IF statment try { $retupload = upload::save($imagefile); } catch (Exception $e) { echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n"); die; } $retupload = explode('upload/', $retupload); if (count($retupload) > 1) { $retupload = $retupload[1]; // basics::thlizer($retupload); // echo Kohana::debug($retupload); return $retupload; } } }
public function admin() { $valid = !empty($_POST); $_POST = Validation::factory($_POST)->pre_filter('trim')->add_rules('title', 'required', 'length[4,32]')->add_rules('description', 'required', 'length[4,127]')->add_rules('link', 'length[6,127]', 'valid::url')->add_rules('address', 'required', 'length[4,127]')->add_callbacks('address', array($this, '_admin_check_address')); if ($_POST->validate()) { // Create a new location $location = ORM::factory('location'); // foreach ($_POST->as_array() as $key => $val) { $location->{$key} = $val; } echo Kohana::debug($_POST->as_array()); } if ($errors = $_POST->errors()) { foreach ($errors as $input => $rule) { // Add the errors $_POST->message($input, Kohana::lang("gmaps.form.{$input}")); } } View::factory('gmaps/admin')->render(TRUE); }
public function __construct($class, $property) { $property = new ReflectionProperty($class, $property); list($description, $tags) = Kodoc::parse($property->getDocComment()); $this->description = $description; if ($modifiers = $property->getModifiers()) { $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> '; } if (isset($tags['var'])) { if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) { $this->type = $matches[1]; if (isset($matches[2])) { $this->description = $matches[2]; } } } $this->property = $property; if ($property->isStatic()) { $this->value = Kohana::debug($property->getValue($class)); } }