public function save() { if (!$_POST) { die; } $this->rsp = Response::instance(); if (!valid::email($_POST['email'])) { $this->rsp->msg = 'Invalid Email!'; $this->rsp->send(); } elseif ($this->owner->unique_key_exists($_POST['email'])) { $this->rsp->msg = 'Email already exists!'; $this->rsp->send(); } $pw = text::random('alnum', 8); $this->owner->email = $_POST['email']; $this->owner->password = $pw; $this->owner->save(); $replyto = 'unknown'; $body = "Hi there, thanks for saving your progess over at http://pluspanda.com \r\n" . "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda"; # to do FIX THE HEADERS. $subject = 'Your Pluspanda account information =)'; $headers = "From: welcome@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion(); mail($_POST['email'], $subject, $body, $headers); # add to mailing list. include Kohana::find_file('vendor/mailchimp', 'MCAPI'); $config = Kohana::config('mailchimp'); $mailchimp = new MCAPI($config['apikey']); $mailchimp->listSubscribe($config['list_id'], $_POST['email'], '', 'text', FALSE, TRUE, TRUE, FALSE); $this->rsp->status = 'success'; $this->rsp->msg = 'Thanks, Account Saved!'; $this->rsp->send(); }
public function page($page_id = NULL) { valid::id_key($page_id); ob_start(); #TODO: if any tools are protected on this page, search for a possible # theme template and load that within the page css. # Is page_name protected? #$page_config_value = yaml::does_key_exist($this->site_name, 'pages_config', $page_name); # parse custom page sass file if it exists. $page_sass = $this->assets->themes_dir("{$this->theme}/pages/{$page_id}.sass"); if (file_exists($page_sass)) { echo Kosass::factory('compact')->compile(file($page_sass)); } # load custom tool css files $db = new Database(); # get all tools that are added to this page. $tool_data = $db->query("\n SELECT *, LOWER(system_tools.name) AS name, tools.id AS guid\n FROM pages_tools \n JOIN tools ON pages_tools.tool_id = tools.id\n JOIN system_tools ON tools.system_tool_id = system_tools.id\n WHERE (page_id BETWEEN 1 AND 5 OR page_id = '{$page_id}')\n AND pages_tools.fk_site = '{$this->site_id}'\n ORDER BY pages_tools.container, pages_tools.position\n "); $tool_dir = $this->assets->themes_dir("{$this->theme}/tools"); foreach ($tool_data as $tool) { # get the type and the view from the system. # TODO: try and optimize this later. $table = ORM::factory($tool->name)->where('fk_site', $this->site_id)->find($tool->parent_id); $custom_file = "{$tool_dir}/{$tool->name}/{$tool->parent_id}/{$table->type}_{$table->view}.css"; if (file_exists($custom_file)) { readfile($custom_file); } } # cache the full result as the live global css file. file_put_contents("{$this->cache_dir}/{$page_id}.css", ob_get_clean()); return TRUE; }
public function url_test() { $this->assert_true(valid::url("http://foo.bar.com")); $this->assert_true(valid::url("https://foo.bar.com")); $this->assert_false(valid::url("mailto://bar")); $this->assert_false(valid::url("ftp://bar")); }
/** * Parses a remote feed into an array. * * @param string remote feed URL * @param integer item limit to fetch * @return array */ public static function parse($feed, $limit = 0) { // Check if SimpleXML is installed if (!function_exists('simplexml_load_file')) { throw new Kohana_User_Exception('Feed Error', 'SimpleXML must be installed!'); } // Make limit an integer $limit = (int) $limit; // Disable error reporting while opening the feed $ER = error_reporting(0); // Allow loading by filename or raw XML string $load = (is_file($feed) or valid::url($feed)) ? 'simplexml_load_file' : 'simplexml_load_string'; // Load the feed $feed = $load($feed, 'SimpleXMLElement', LIBXML_NOCDATA); // Restore error reporting error_reporting($ER); // Feed could not be loaded if ($feed === FALSE) { return array(); } // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported. $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry; $i = 0; $items = array(); foreach ($feed as $item) { if ($limit > 0 and $i++ === $limit) { break; } $items[] = (array) $item; } return $items; }
public function __construct($username = '', $password = '', $email = '') { // load database library into $this->db parent::__construct(); if ($username != '' and $password != '' and $email != '') { if (strlen($username) < 3) { throw new Exception('Username too short'); } elseif (strlen($username) > 12) { throw new Exception('Username too long'); } elseif (strlen($password) < 6) { throw new Exception('Password too short'); } elseif (strlen($username) > 255) { throw new Exception('Password too long'); } elseif (valid::email($email) == False) { throw new Exception('Invalid email supplied'); } elseif ($this->user_exists($username, $email)) { throw new Exception('User already exists (login or email matched)'); } if ($this->register($username, $password, $email)->valid()) { return true; } else { return false; } } }
/** * Converts a file location to an absolute URL or returns the absolute URL if absolute URL * is passed. This function is for uploaded files since it uses the configured upload dir * * @param string file location or full URL * @return string */ public static function convert_uploaded_to_abs($file) { if (valid::url($file) == true) { return $file; } return url::base() . Kohana::config('upload.relative_directory') . '/' . $file; }
/** * Allows a model to be loaded by username or email address. */ public function unique_key($id) { if (!empty($id) and is_string($id) and !ctype_digit($id)) { return valid::email($id) ? 'email' : 'username'; } return parent::unique_key($id); }
public function get_item($table, $id = FALSE) { $id = $id ? $id : valid::id_key($this->item_id); $item = ORM::factory($table)->where('fk_site', $this->site_id)->find($id); if (!$item->loaded) { die("invalid item for {$table}"); } return $item; }
/** * Method that allows sending any kind of HTTP request to remote url * * @param string $method * @param string $url * @param array $headers * @param array $data * @return HTTP_Response */ public static function request($method, $url, $headers = array(), $data = array()) { $valid_methods = array('POST', 'GET', 'PUT', 'DELETE'); $method = utf8::strtoupper($method); if (!valid::url($url, 'http')) { return FALSE; } if (!in_array($method, $valid_methods)) { return FALSE; } // Get the hostname and path $url = parse_url($url); if (empty($url['path'])) { // Request the root document $url['path'] = '/'; } // Open a remote connection $remote = fsockopen($url['host'], 80, $errno, $errstr, 5); if (!is_resource($remote)) { return FALSE; } // Set CRLF $CRLF = "\r\n"; $path = $url['path']; if ($method == 'GET' and !empty($url['query'])) { $path .= '?' . $url['query']; } $headers_default = array('Host' => $url['host'], 'Connection' => 'close', 'User-Agent' => 'Ushahidi Scheduler (+http://ushahidi.com/)'); $body_content = ''; if ($method != 'GET') { $headers_default['Content-Type'] = 'application/x-www-form-urlencoded'; if (count($data) > 0) { $body_content = http_build_query($data); } $headers_default['Content-Length'] = strlen($body_content); } $headers = array_merge($headers_default, $headers); // Send request $request = $method . ' ' . $path . ' HTTP/1.0' . $CRLF; foreach ($headers as $key => $value) { $request .= $key . ': ' . $value . $CRLF; } // Send one more CRLF to terminate the headers $request .= $CRLF; if ($body_content) { $request .= $body_content . $CRLF; } fwrite($remote, $request); $response = ''; while (!feof($remote)) { // Get 1K from buffer $response .= fread($remote, 1024); } // Close the connection fclose($remote); return new HTTP_Response($response, $method); }
public function tool() { if (empty($_GET['tool_id'])) { die('invalid tool_id'); } $tool_id = valid::id_key($_GET['tool_id']); $tool = ORM::factory('tool', $tool_id); if (!$tool->loaded) { die('invalid tool'); } $toolname = strtolower($tool->system_tool->name); # load the tool parent $parent = ORM::factory($toolname, $tool->parent_id); if (!$parent->loaded) { die('invalid parent table'); } # build the object. $export = new stdClass(); $export->name = $toolname; # export the parent table. $parent_table = new stdClass(); foreach ($parent->table_columns as $key => $value) { $parent_table->{$key} = $parent->{$key}; } $export->parent_table = $parent_table; # export any child tables. $child_tables = new stdClass(); # loop through data from available child tables. foreach ($parent->has_many as $table_name) { $table_name = inflector::singular($table_name); $child_tables->{$table_name} = array(); # get the child table model so we can iterate through the fields. $table = ORM::factory($table_name); # get any rows beloning to the parent. $rows = ORM::factory($table_name)->where(array('fk_site' => $this->site_id, "{$toolname}_id" => $parent->id))->find_all(); foreach ($rows as $row) { $object = new stdClass(); foreach ($table->table_columns as $key => $value) { $object->{$key} = $row->{$key}; } array_push($child_tables->{$table_name}, $object); } } $export->child_tables = $child_tables; # get the css file. $export->css = file_get_contents($this->assets->themes_dir("{$this->theme}/tools/{$toolname}/_created/{$parent->id}/{$parent->type}_{$parent->view}.css")); $json = json_encode($export); echo '<h2>Copy this exactly and place into the importer=)</h2>'; echo "<textarea style='width:99%;height:400px;'>{$json}</textarea>"; die; echo kohana::debug($export); die; # just testing ... echo self::import($json); die; }
private function get_tag() { valid::id_key($this->tag_id); $tag = ORM::factory('tag')->where('owner_id', $this->owner->id)->find($this->tag_id); if (!$tag->loaded) { $this->rsp->msg = 'Tag does not exist'; $this->rsp->send(); } return $tag; }
public function length() { var_dump(valid::length(1, 10, 'evan')); var_dump(valid::length(1, 10, 'evan byrne')); var_dump(valid::length(1, 10, 'evan thomas byrne')); var_dump(valid::length(1, 10, '')); var_dump(valid::length(1, 3, 'evan')); var_dump(valid::length(4, 10, 'evan')); var_dump(valid::length(5, 10, 'evan')); var_dump(valid::length(5, 6, 'evan b')); }
private function validate_email_form() { $messages = array(); if (valid::email($this->input->post('email')) == false) { $messages[] = 'The supplied email address does not appear valid'; } if ($this->input->post('body') == '') { $messages[] = 'The body of your message should not be empty'; } return $messages; }
function save_tree() { if ($_POST) { valid::id_key($this->pid); $json = json_decode($_POST['json']); if (NULL === $json or !is_array($json)) { die('invalid json'); } echo Tree::save_tree('navigation', 'navigation_item', $this->pid, $this->site_id, $json); } die; }
private function get_testimonial() { if (0 == $this->testimonial_id) { $new = ORM::factory('testimonial'); $new->owner_id = $this->owner->id; return $new; } valid::id_key($this->testimonial_id); $testimonial = ORM::factory('testimonial')->where('owner_id', $this->owner->id)->find($this->testimonial_id); if (!$testimonial->loaded) { $this->rsp->msg = 'Testimonial does not exist'; $this->rsp->send(); } return $testimonial; }
/** * Quickly pulls data from a URI. This only works with GET requests but * can handle HTTP Basic Auth * * @param string uri the url to pull from * @param string username the username for the service [Optional] * @param string password the password for the user [Optional] * @return string * @throws Kohana_User_Exception * @author Sam Clark * @access public * @static **/ public static function pull($uri, $username = FALSE, $password = FALSE) { if (!valid::url($uri)) { throw new Kohana_User_Exception('Curl::pull()', 'The URL : ' . $uri . ' is not a valid resource'); } // Initiate a curl session based on the URL supplied $curl = Curl::factory(array(CURLOPT_POST => FALSE), $uri); // If a username/password is supplied if ($username and $password) { // Add the HTTP Basic Auth headers $curl->setopt_array(array(CURLOPT_USERPWD => $username . ':' . $password)); } // Launch the request and return the result return $curl->exec()->result(); }
/** * Performs validation checks on the layer url and layer file - Checks that at least * one of them has been specified using the applicable validation rules * * @param Validation $array Validation object containing the field names to be checked */ public function layer_url_file_check(Validation $array) { // Ensure at least a layer URL or layer file has been specified if (empty($array->layer_url) and empty($array->layer_file) and empty($array->layer_file_old)) { $array->add_error('layer_url', 'atleast'); } // Add validation rule for the layer URL if specified if (!empty($array->layer_url) and (empty($array->layer_file) or empty($array->layer_file_old))) { if (!valid::url($array->layer_url)) { $array->add_error('layer_url', 'url'); } } // Check if both the layer URL and the layer file have been specified if (!empty($array->layer_url) and (!empty($array->layer_file_old) or !empty($array->layer_file))) { $array->add_error('layer_url', 'both'); } }
/** * Displays a profile page for a user */ public function user() { // Cacheable Controller $this->is_cachable = TRUE; $this->template->header->this_page = 'profile'; // Check if we are looking for a user. Argument must be set to continue. if (!isset(Router::$arguments[0])) { url::redirect('profile'); } $username = Router::$arguments[0]; // We won't allow profiles to be public if the username is an email address if (valid::email($username)) { url::redirect('profile'); } $user = User_Model::get_user_by_username($username); // We only want to show public profiles here if ($user->public_profile == 1) { $this->template->content = new View('profile/user'); $this->template->content->user = $user; // User Reputation Score $this->template->content->reputation = reputation::calculate($user->id); // All users reports $this->template->content->reports = ORM::factory('incident')->where(array('user_id' => $user->id, 'incident_active' => 1))->with('incident:location')->find_all(); // Get Badges $this->template->content->badges = Badge_Model::users_badges($user->id); // Logged in user id (false if not logged in) $logged_in_id = FALSE; if (isset(Auth::instance()->get_user()->id)) { $logged_in_id = Auth::instance()->get_user()->id; } $this->template->content->logged_in_id = $logged_in_id; // Is this the logged in user? $logged_in_user = FALSE; if ($logged_in_id == $user->id) { $logged_in_user = TRUE; } $this->template->content->logged_in_user = $logged_in_user; } else { // this is a private profile so get out of here url::redirect('profile'); } $this->template->header->page_title .= $user->name . Kohana::config('settings.title_delimiter'); $this->template->header->header_block = $this->themes->header_block(); $this->template->footer->footer_block = $this->themes->footer_block(); }
/** * Normalizes a hexadecimal HTML color value. All values will be converted * to lowercase, have a "#" prepended and contain six characters. * * @param string hexadecimal HTML color value * @return string */ public static function color($str = '') { // Reject invalid values if (!valid::color($str)) { return ''; } // Convert to lowercase $str = strtolower($str); // Prepend "#" if ($str[0] !== '#') { $str = '#' . $str; } // Expand short notation if (strlen($str) === 4) { $str = '#' . $str[1] . $str[1] . $str[2] . $str[2] . $str[3] . $str[3]; } return $str; }
public function validate($array) { $default = array("title" => "", "display_name" => "", "email" => ""); $array = arr::overwrite($default, $array); $errors = array(); if ($array['display_name'] == "") { $errors['display_name'] = "Please enter a display name"; } if (!valid::email($array['email'])) { $errors['email'] = "Please enter a valid email"; } if ($array['title'] == "") { $errors['title'] = "Please enter text for your comment"; } $array['title'] = strip_tags($array['title']); $array['errors'] = $errors; return $array; }
public function edit() { $this->template->content = new View('coaches/edit'); $this->template->title = 'Редактирование тренера'; $this->selected_page = PAGE_COACHES; $this->selected_subpage = null; if (!$this->haveAccess()) { return; } $this->getFootballerInfo(); $this->template->content->teams = $this->db->select('*')->from('teams_store')->join('cups_store', 'cups_store.cp_id', 'teams_store.cp_id', ' AND cups_store.back_up_id is null AND cups_store.moder_rating > 0')->where('1=1 and teams_store.back_up_id IS NULL')->orderby('tm_id', 'desc')->get(); if ($_POST) { $data['ch_name'] = trim($_POST['footballer']['name']); $data['tm_id'] = intval(@$_POST['footballer']['team']); $data['ch_photo'] = trim($_POST['footballer']['photo']); $data['moder_id'] = $this->moderId; $data['ch_status'] = ITEM_STATUS_NEW; if (empty($data['ch_name'])) { $this->error .= 'Укажите имя тренера' . $this->NL(); } if (!$data['tm_id']) { $this->error .= 'Укажите команду' . $this->NL(); } if (empty($data['ch_photo'])) { $this->error .= 'Укажите адрес фотографии тренера для анкеты' . $this->NL(); } elseif (!valid::URL($data['ch_photo'])) { $this->error .= 'Укажите правильный адрес фотографии для анкеты' . $this->NL(); } if (is_null($this->error)) { if (!$this->haveAccessByStatus($this->template->content->item->ch_status)) { $this->error .= 'Запрещённая операция' . $this->NL(); } else { $id = intval($this->uri->segment('id')); $this->makeCopy('coaches_store', 'ch_id', $id, 'ch_status'); $status = $this->db->update('coaches_store', $data, array('ch_id' => $id)); if (count($status)) { $this->info = 'Тренер отредактирован.'; url::redirect(url::site() . "coaches/info/id/" . intval($this->uri->segment('id')) . '/updated/yes'); exit; } } } } }
public function edit() { $this->template->content = new View('teams/edit'); $this->template->title = 'Редактирование конады'; $this->selected_page = PAGE_TEAMS; $this->selected_subpage = null; if (!$this->haveAccess()) { return; } $this->template->content->champ = $this->db->select('*')->from('cups_store')->where('1=1 AND back_up_id is null AND moder_rating > 0')->orderby('cp_name', 'asc')->get(); $this->getFootballerInfo(); if ($_POST) { $data['tm_name'] = trim($_POST['footballer']['name']); $data['tm_photo'] = trim($_POST['footballer']['photo']); $data['cp_id'] = intval(@$_POST['footballer']['champ']); $data['moder_id'] = $this->moderId; $data['tm_status'] = ITEM_STATUS_NEW; if (empty($data['tm_name'])) { $this->error .= 'Укажите название команды' . $this->NL(); } if (empty($data['cp_id'])) { $this->error .= 'Укажите чемпионат' . $this->NL(); } if (empty($data['tm_photo'])) { $this->error .= 'Укажите адрес фотографии игрока для анкеты' . $this->NL(); } elseif (!valid::URL($data['tm_photo'])) { $this->error .= 'Укажите правильный адрес фотографии для анкеты' . $this->NL(); } if (is_null($this->error)) { if (!$this->haveAccessByStatus($this->template->content->item->tm_status)) { $this->error .= 'Запрещённая операция' . $this->NL(); } else { $id = intval($this->uri->segment('id')); $this->makeCopy('teams_store', 'tm_id', $id, 'tm_status'); $status = $this->db->update('teams_store', $data, array('tm_id' => $id)); if (count($status)) { $this->info = 'Команда отредактирована.'; url::redirect(url::site() . "teams/info/id/" . intval($this->uri->segment('id')) . '/updated/yes'); exit; } } } } }
public static function status($url) { if (!valid::url($url, 'http')) { return FALSE; } // Get the hostname and path $url = parse_url($url); if (empty($url['path'])) { // Request the root document $url['path'] = '/'; } // Open a remote connection if (isset($_SERVER["SERVER_PORT"])) { $server_port = $_SERVER["SERVER_PORT"]; } else { $server_port = '80'; } $remote = fsockopen($url['host'], $server_port, $errno, $errstr, 5); if (!is_resource($remote)) { return FALSE; } // Set CRLF $CRLF = "\r\n"; // Send request fwrite($remote, 'HEAD ' . $url['path'] . ' HTTP/1.0' . $CRLF); fwrite($remote, 'Host: ' . $url['host'] . $CRLF); fwrite($remote, 'Connection: close' . $CRLF); fwrite($remote, 'User-Agent: Kohana Framework (+http://kohanaphp.com/)' . $CRLF); // Send one more CRLF to terminate the headers fwrite($remote, $CRLF); while (!feof($remote)) { // Get the line $line = trim(fgets($remote, 512)); if ($line !== '' and preg_match('#^HTTP/1\\.[01] (\\d{3})#', $line, $matches)) { // Response code found $response = (int) $matches[1]; break; } } // Close the connection fclose($remote); return isset($response) ? $response : FALSE; }
public function add() { $this->template->content = new View('sponsors/add'); $this->template->title = 'Добавление спонсора'; $this->selected_page = PAGE_SPONSORS; $this->selected_subpage = Sponsors_Controller::SUBPAGE_ADD; if (!$this->haveAccess()) { return; } if ($_POST) { $data['sp_name'] = trim($_POST['footballer']['name']); $data['sp_level'] = trim(@$_POST['footballer']['level']); $data['sp_rating'] = trim(@$_POST['footballer']['rating']); $data['sp_photo'] = trim($_POST['footballer']['photo']); $data['moder_id'] = $this->moderId; $data['sp_status'] = ITEM_STATUS_NEW; if (empty($data['sp_name'])) { $this->error .= 'Укажите название спонсора' . $this->NL(); } if (!$data['sp_level']) { $this->error .= 'Укажите уровень' . $this->NL(); } if (!$data['sp_rating']) { $this->error .= 'Укажите рейтинг' . $this->NL(); } if (empty($data['sp_photo'])) { $this->error .= 'Укажите адрес фотографии спонсора для анкеты' . $this->NL(); } elseif (!valid::URL($data['sp_photo'])) { $this->error .= 'Укажите правильный адрес фотографии' . $this->NL(); } if (is_null($this->error)) { $status = $this->db->insert('sponsors_store', $data); if (count($status)) { $this->info = 'Спонсор добавлен.'; url::redirect(url::site() . "sponsors/info/id/" . $status->insert_id()); exit; } } } }
/** * generates the request to pay at nitpay */ public function action_pay() { $this->auto_render = FALSE; $id_order = $this->request->param('id'); //retrieve info for the item in DB $order = new Model_Order(); $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find(); if ($order->loaded()) { //options send to create the invoice $options = array('buyerName' => $order->user->name, 'buyerEmail' => $order->user->email, 'currency' => $order->currency, 'redirectURL' => Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'))); $invoice = Bitpay::bpCreateInvoice($order->id_order, $order->amount, '', $options); if (!isset($invoice['error']) and valid::url($invoice['url'])) { $this->redirect($invoice['url']); } else { Alert::set(Alert::INFO, __('Could not create bitpay invoice')); $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))); } } else { Alert::set(Alert::INFO, __('Product could not be loaded')); $this->redirect(Route::url('default')); } }
public function save(array $person = array(), $person_id = null) { $result = array('success' => false, 'error' => ''); $valid = true; $person = $this->get_trimmed_allowed($person, array('space_id', 'email', 'x', 'y', 'active')); if (isset($person['space_id']) && !valid::digit($person['space_id'])) { $valid = false; } if (isset($person['email']) && !valid::email($person['email'])) { $valid = false; } if (isset($person['x']) && !valid::numeric($person['x'])) { $valid = false; } if (isset($person['y']) && !valid::numeric($person['y'])) { $valid = false; } if (isset($person['active']) && !valid::digit($person['active'])) { $valid = false; } if ($valid) { if ($person_id) { //UPDATE $this->db->from('people')->set($person)->where(array('id' => (int) $person_id))->update(); $result['success'] = true; } else { // INSERT $new_person = $this->db->from('people')->set($person)->insert(); $result['success'] = true; $person_id = $new_person->insert_id(); } $person = $this->db->select('people.*')->from('people')->where(array('id' => $person_id))->get(); $person = $this->result_as_array($person); $result['person'] = $person; } else { $result['error'] = "The supplied data was invalid"; } return $result; }
/** * Parses a remote feed into an array. * * @param string remote feed URL * @param integer item limit to fetch * @return array */ public static function parse($feed, $limit = 0) { // Make limit an integer $limit = (int) $limit; // Disable error reporting while opening the feed $ER = error_reporting(0); // Allow loading by filename/url or raw XML string if (valid::url($feed)) { $feed = remote::get($feed, 45); $feed = $feed['content']; } elseif (is_file($feed)) { $feed = file_get_contents($feed); } // Double check we have something to work with if (empty($feed)) { return FALSE; } // Load the feed $feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA); // Restore error reporting error_reporting($ER); // Feed could not be loaded if ($feed === NO) { return array(); } // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported. $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry; $i = 0; $items = array(); foreach ($feed as $item) { if ($limit > 0 and $i++ === $limit) { break; } $items[] = (array) $item; } return $items; }
/** * Delete Photo * @param int $id The unique id of the photo to be deleted */ public static function delete_photo($id) { $photo = ORM::factory('media', $id); $photo_large = $photo->media_link; $photo_medium = $photo->media_medium; $photo_thumb = $photo->media_thumb; if (file_exists(Kohana::config('upload.directory', TRUE) . $photo_large)) { unlink(Kohana::config('upload.directory', TRUE) . $photo_large); } elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($photo_large)) { cdn::delete($photo_large); } if (file_exists(Kohana::config('upload.directory', TRUE) . $photo_medium)) { unlink(Kohana::config('upload.directory', TRUE) . $photo_medium); } elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($photo_medium)) { cdn::delete($photo_medium); } if (file_exists(Kohana::config('upload.directory', TRUE) . $photo_thumb)) { unlink(Kohana::config('upload.directory', TRUE) . $photo_thumb); } elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($photo_thumb)) { cdn::delete($photo_thumb); } // Finally Remove from DB $photo->delete(); }
<h2 class="faq_header"><?php echo $format->name; ?> </h2> <dl class="faq_list"> <?php $x = 0; foreach ($format->format_items as $item) { $url_question = valid::filter_php_url($item->title); ?> <span id="format_item_<?php echo $item->id; ?> " class="format_item" rel="<?php echo $item->id; ?> "> <dt class="minus"> <?php echo ++$x; ?> . <a href="#<?php echo $url_question; ?> " class="toggle"><?php echo $item->title; ?>
/** * Tests the text::random() function. * @dataProvider random_provider * @group core.helpers.text.random * @test */ public function random($type, $length = 8) { //$this->markTestIncomplete('Test for PHP 5.3 bug needs to be counted, Kohana is still supporting 5.2'); $result = text::random($type, $length); if ((string) $type) { // Checking length $this->assertEquals(mb_strlen($result), $length); $pool = ''; switch ($type) { case 'alnum': $this->assertTrue(valid::alpha_numeric($result)); break; case 'alpha': $this->assertTrue(valid::alpha($result)); break; case 'numeric': $this->assertTrue(valid::numeric($result)); break; case 'nozero': $this->assertTrue(is_numeric($result)); break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; default: $pool = (string) $type; } if ($pool) { // PHP versions before 5.3 have a bug with preg_quote and it doesn't escape '-' $pool = version_compare(PHP_VERSION, '5.3', '>=') ? preg_quote((string) $pool, '/') : utf8::str_ireplace('-', '\\-', preg_quote((string) $pool, '/')); if (preg_match('/[' . $pool . ']*/u', $result, $match)) { $this->assertEquals($match[0], $result); } else { $this->assertTrue(FALSE); } } } else { // Checking length $this->assertEquals($result, ''); } }