Exemple #1
0
 /**
  * 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 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"));
 }
Exemple #3
0
 /**
  * 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;
 }
 /**
  * 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);
 }
Exemple #5
0
 /**
  * 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();
 }
Exemple #6
0
 /**
  * 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');
     }
 }
Exemple #7
0
 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;
 }
 /**
  * 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'));
     }
 }
Exemple #9
0
 /**
  * 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;
 }
Exemple #10
0
 /**
  * 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();
 }
Exemple #11
0
 /**
  * Set default avatar type or url
  *
  * @param   string  $default
  * @return  Gravatar
  */
 public function set_default($default)
 {
     $default = (string) $default;
     if (in_array($default, array(self::DEFAULT_IDENTICON, self::DEFAULT_MONSTERID, self::DEFAULT_WAVATAR))) {
         $this->default = $default;
     } else {
         if (valid::url($default)) {
             $this->default = urlencode($default);
         }
     }
     return $this;
 }
Exemple #12
0
 /**
  * Check if a given string is a valid url or email.
  *
  * @param String $str
  * @return Boolean
  */
 public function contact_is_valid($str)
 {
     if (valid::email($str) || valid::url($str)) {
         return true;
     }
     return false;
 }
 /**
  * Generic function to get reports by given set of parameters
  *
  * @param string $where SQL where clause
  * @param int $limit No. of records to return - set to 20 by default
  * @return string XML or JSON string
  */
 public function _get_incidents($where = array())
 {
     // STEP 1.
     // Get the incidents
     $items = Incident_Model::get_incidents($where, $this->list_limit, $this->order_field, $this->sort);
     //No record found.
     if ($items->count() == 0) {
         return $this->response(4, $this->error_messages);
     }
     // Records found - proceed
     // Set the no. of records returned
     $this->record_count = $items->count();
     // Will hold the XML/JSON string to return
     $ret_json_or_xml = '';
     $json_reports = array();
     $json_report_media = array();
     $json_report_categories = array();
     $json_incident_media = array();
     $upload_path = str_replace("media/uploads/", "", Kohana::config('upload.relative_directory') . "/");
     //XML elements
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('response');
     $xml->startElement('payload');
     $xml->writeElement('domain', $this->domain);
     $xml->startElement('incidents');
     // Records found, proceed
     // Store the incident ids
     $incidents_ids = array();
     foreach ($items as $item) {
         $incident_ids[] = $item->incident_id;
     }
     //
     // STEP 2.
     // Fetch the incident categories
     //
     $this->query = "SELECT c.category_title AS categorytitle, ic.incident_id, " . "c.id AS cid, c.category_image_thumb AS categorythumb, " . "d.decayimage_thumb  AS decayimagethumb " . "FROM " . $this->table_prefix . "category AS c " . "INNER JOIN " . $this->table_prefix . "incident_category AS ic ON ic.category_id = c.id " . "LEFT JOIN " . $this->table_prefix . "decayimage as d ON c.id = d.category_id " . "WHERE ic.incident_id IN (" . implode(',', $incident_ids) . ")";
     // Execute the query
     $incident_categories = $this->db->query($this->query);
     // To hold the incident category items
     $category_items = array();
     // Temporary counter
     $i = 1;
     // Fetch items into array
     foreach ($incident_categories as $incident_category) {
         $category_items[$incident_category->incident_id][$i]['cid'] = $incident_category->cid;
         $category_items[$incident_category->incident_id][$i]['categorytitle'] = $incident_category->categorytitle;
         $category_items[$incident_category->incident_id][$i]['categorythumb'] = $incident_category->categorythumb;
         $category_items[$incident_category->incident_id][$i]['decayimagethumb'] = $incident_category->decayimagethumb;
         $i++;
     }
     // Free temporary variables from memory
     unset($incident_categories);
     //
     // STEP 3.
     // Fetch the media associated with all the incidents
     //
     $this->query = "SELECT i.id AS incident_id, m.id AS mediaid, m.media_title AS mediatitle, " . "m.media_type AS mediatype, m.media_link AS medialink, m.media_thumb AS mediathumb " . "FROM " . $this->table_prefix . "media AS m " . "INNER JOIN " . $this->table_prefix . "incident AS i ON i.id = m.incident_id " . "WHERE i.id IN (" . implode(",", $incident_ids) . ")";
     $media_items_result = $this->db->query($this->query);
     // To store the fetched media items
     $media_items = array();
     // Reset the temporary counter
     $i = 1;
     // Fetch items into array
     foreach ($media_items_result as $media_item) {
         $media_items[$media_item->incident_id][$i]['mediaid'] = $media_item->mediaid;
         $media_items[$media_item->incident_id][$i]['mediatitle'] = $media_item->mediatitle;
         $media_items[$media_item->incident_id][$i]['mediatype'] = $media_item->mediatype;
         $media_items[$media_item->incident_id][$i]['medialink'] = $media_item->medialink;
         $media_items[$media_item->incident_id][$i]['mediathumb'] = $media_item->mediathumb;
         $i++;
     }
     // Free temporary variables
     unset($media_items_result, $i);
     //
     // STEP 4.
     // Fetch the comments associated with the incidents
     //
     if ($this->comments) {
         $this->query = "SELECT id, incident_id, comment_author, comment_email, " . "comment_description, comment_rating, comment_date " . "FROM " . $this->table_prefix . "comment AS c " . "WHERE c.incident_id IN (" . implode(',', $incident_ids) . ")";
         // Execute the query
         $incident_comments = $this->db->query($this->query);
         // To hold the incident category items
         $comment_items = array();
         // Temporary counter
         $i = 1;
         // Fetch items into array
         foreach ($incident_comments as $incident_comment) {
             $comment_items[$incident_comment->incident_id][$i]['id'] = $incident_comment->id;
             $comment_items[$incident_comment->incident_id][$i]['incident_id'] = $incident_comment->incident_id;
             $comment_items[$incident_comment->incident_id][$i]['comment_author'] = $incident_comment->comment_author;
             $comment_items[$incident_comment->incident_id][$i]['comment_email'] = $incident_comment->comment_email;
             $comment_items[$incident_comment->incident_id][$i]['comment_description'] = $incident_comment->comment_description;
             $comment_items[$incident_comment->incident_id][$i]['comment_rating'] = $incident_comment->comment_rating;
             $comment_items[$incident_comment->incident_id][$i]['comment_date'] = $incident_comment->comment_date;
             $i++;
         }
         // Free temporary variables from memory
         unset($incident_comments);
     }
     //
     // STEP 5.
     // Return XML
     //
     foreach ($items as $item) {
         // Build xml file
         $xml->startElement('incident');
         $xml->writeElement('id', $item->incident_id);
         $xml->writeElement('title', $item->incident_title);
         $xml->writeElement('description', $item->incident_description);
         $xml->writeElement('date', $item->incident_date);
         $xml->writeElement('mode', $item->incident_mode);
         $xml->writeElement('active', $item->incident_active);
         $xml->writeElement('verified', $item->incident_verified);
         $xml->startElement('location');
         $xml->writeElement('id', $item->location_id);
         $xml->writeElement('name', $item->location_name);
         $xml->writeElement('latitude', $item->latitude);
         $xml->writeElement('longitude', $item->longitude);
         $xml->endElement();
         $xml->startElement('categories');
         $json_report_categories[$item->incident_id] = array();
         // Check if the incident id exists
         if (isset($category_items[$item->incident_id])) {
             foreach ($category_items[$item->incident_id] as $category_item) {
                 if ($this->response_type == 'json') {
                     $category = array("id" => $category_item['cid'], "title" => $category_item['categorytitle']);
                     $category["icon"] = url::base() . Kohana::config('upload.relative_directory') . '/' . $category_item['categorythumb'];
                     if ($category_item['decayimagethumb']) {
                         if ($category_item['decayimagethumb'] == $this->default_decayimage_thumb) {
                             $category['decayimage'] = url::site() . '/plugins/decayimage/images/' . $category_item['decayimagethumb'];
                         } else {
                             $category['decayimage'] = url::base() . Kohana::config('upload.relative_directory') . '/' . $category_item['decayimagethumb'];
                         }
                     }
                     $json_report_categories[$item->incident_id][] = array("category" => $category);
                 } else {
                     $xml->startElement('category');
                     $xml->writeElement('id', $category_item['cid']);
                     $xml->writeElement('title', $category_item['categorytitle']);
                     $xml->endElement();
                 }
             }
         }
         // End categories
         $xml->endElement();
         $xml->startElement('comments');
         $json_report_comments[$item->incident_id] = array();
         // Check if the incident id exists
         if (isset($comment_items[$item->incident_id])) {
             foreach ($comment_items[$item->incident_id] as $comment_item) {
                 if ($this->response_type == 'json') {
                     $json_report_comments[$item->incident_id][] = array("comment" => $comment_item);
                 } else {
                     $xml->startElement('comment');
                     $xml->writeElement('id', $comment_item['id']);
                     $xml->writeElement('comment_author', $comment_item['comment_author']);
                     $xml->writeElement('comment_email', $comment_item['comment_email']);
                     $xml->writeElement('comment_description', $comment_item['comment_description']);
                     $xml->writeElement('comment_rating', $comment_item['comment_rating']);
                     $xml->writeElement('comment_date', $comment_item['comment_date']);
                     $xml->endElement();
                 }
             }
         }
         // End comments
         $xml->endElement();
         $json_report_media[$item->incident_id] = array();
         if (count($media_items) > 0) {
             if (isset($media_items[$item->incident_id]) and count($media_items[$item->incident_id]) > 0) {
                 $xml->startElement('mediaItems');
                 foreach ($media_items[$item->incident_id] as $media_item) {
                     $url_prefix = url::base() . Kohana::config('upload.relative_directory') . '/';
                     // If our media is not an image, we don't need to show an upload path
                     if ($media_item['mediatype'] != 1) {
                         $upload_path = '';
                     } elseif ($media_item['mediatype'] == 1 and valid::url($media_item['medialink']) == TRUE) {
                         // If our media is an img and is a valid URL, don't show the upload path or prefix
                         $upload_path = '';
                         $url_prefix = '';
                     }
                     if ($this->response_type == 'json') {
                         $json_report_media[$item->incident_id][] = array("id" => $media_item['mediaid'], "type" => $media_item['mediatype'], "link" => $upload_path . $media_item['medialink'], "thumb" => $upload_path . $media_item['mediathumb']);
                         // If we are look at certain types of media, add some fields
                         if ($media_item['mediatype'] == 1) {
                             // Grab that last key up there
                             $add_to_key = key($json_report_media[$item->incident_id]) + 1;
                             // Give a full absolute URL to the image
                             $json_report_media[$item->incident_id][$add_to_key]["thumb_url"] = $url_prefix . $upload_path . $media_item['mediathumb'];
                             $json_report_media[$item->incident_id][$add_to_key]["link_url"] = $url_prefix . $upload_path . $media_item['medialink'];
                         }
                     } else {
                         $xml->startElement('media');
                         if ($media_item['mediaid'] != "") {
                             $xml->writeElement('id', $media_item['mediaid']);
                         }
                         if ($media_item['mediatitle'] != "") {
                             $xml->writeElement('title', $media_item['mediatitle']);
                         }
                         if ($media_item['mediatype'] != "") {
                             $xml->writeElement('type', $media_item['mediatype']);
                         }
                         if ($media_item['medialink'] != "") {
                             $xml->writeElement('link', $upload_path . $media_item['medialink']);
                         }
                         if ($media_item['mediathumb'] != "") {
                             $xml->writeElement('thumb', $upload_path . $media_item['mediathumb']);
                         }
                         if ($media_item['mediathumb'] != "" and $media_item['mediatype'] == 1) {
                             $add_to_key = key($json_report_media[$item->incident_id]) + 1;
                             $xml->writeElement('thumb_url', $url_prefix . $upload_path . $media_item['mediathumb']);
                             $xml->writeElement('link_url', $url_prefix . $upload_path . $media_item['medialink']);
                         }
                         $xml->endElement();
                     }
                 }
                 $xml->endElement();
                 // Media
             }
         }
         $xml->endElement();
         // End incident
         // Check for response type
         if ($this->response_type == 'json') {
             $json_reports[] = array("incident" => array("incidentid" => $item->incident_id, "incidenttitle" => $item->incident_title, "incidentdescription" => $item->incident_description, "incidentdate" => $item->incident_date, "incidentmode" => $item->incident_mode, "incidentactive" => $item->incident_active, "incidentverified" => $item->incident_verified, "locationid" => $item->location_id, "locationname" => $item->location_name, "locationlatitude" => $item->latitude, "locationlongitude" => $item->longitude, "incidenthasended" => $this->incidentHasEnded($item->incident_id)), "categories" => $json_report_categories[$item->incident_id], "media" => $json_report_media[$item->incident_id], "comments" => $json_report_comments[$item->incident_id]);
         }
     }
     // Get the default decayimage icon
     $decayimage_default_icon = ORM::factory('decayimage', 1);
     if ($decayimage_default_icon->decayimage_thumb == $this->default_decayimage_thumb) {
         $decayimage_default_icon = url::site() . '/plugins/decayimage/images/' . $decayimage_default_icon->decayimage_thumb;
     } else {
         $decayimage_default_icon = $prefix . '/' . $decayimage_default_icon->decayimage_thumb;
     }
     // Create the JSON array
     $data = array("payload" => array("domain" => $this->domain, "incidents" => $json_reports, "decayimage_default_icon" => $decayimage_default_icon), "error" => $this->api_service->get_error_msg(0));
     if ($this->response_type == 'json') {
         return $this->array_as_json($data);
     } else {
         $xml->endElement();
         //end incidents
         $xml->endElement();
         // end payload
         $xml->startElement('error');
         $xml->writeElement('code', 0);
         $xml->writeElement('message', 'No Error');
         $xml->endElement();
         //end error
         $xml->endElement();
         // end response
         return $xml->outputMemory(true);
     }
 }
 private function add_data_to_incident($incident_array, $incident)
 {
     /*static $incident_type;
     		if (!$incident_type)
     		{
     			$incident_type = ORM::factory('service')->select_list('id','service_name');
     		}
     		
     		if ($incident_array['incident_id'])
     		{
     			$incident_array['incident_id'] = array($incident_array['incident_id'] => array(
     				'api_url' => url::site(rest_controller::$api_base_url.'/incidents/'.$incident_array['incident_id']),
     				'url' => url::site('/reports/view/'.$incident_array['incident_id'])
     			));
     		}*/
     // Add categories
     $incident_array['category'] = array();
     foreach ($incident->category as $category) {
         // Only include visible categories unless we're an admin
         if ($this->admin or $category->category_visible) {
             $category_data = $category->as_array();
             $category_data['category_image'] = $category_data['category_image'] ? url::convert_uploaded_to_abs($category_data['category_image']) : $category_data['category_image'];
             $category_data['category_image_thumb'] = $category_data['category_image_thumb'] ? url::convert_uploaded_to_abs($category_data['category_image_thumb']) : $category_data['category_image_thumb'];
             $category_data['api_url'] = url::site(rest_controller::$api_base_url . '/categories/' . $category_data['id']);
             $incident_array['category'][] = $category_data;
         }
     }
     // Add location
     // @todo filter on location_visible
     $incident_array['location'] = $incident->location->as_array();
     // format date in ISO standard
     $incident_array['location']['location_date'] = $incident_array['location']['location_date'] != null ? date('c', strtotime($incident_array['location']['location_date'])) : null;
     // Add incident_person
     if ($this->admin) {
         $incident_array['incident_person'] = $incident->incident_person->as_array();
         //@todo sanitize
         // format date in ISO standard
         $incident_array['incident_person']['person_date'] = $incident_array['incident_person']['person_date'] != null ? date('c', strtotime($incident_array['incident_person']['person_date'])) : null;
     } else {
         // @todo check what should be public
         $incident_array['incident_person'] = array('id' => $incident->incident_person->id, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last);
     }
     // Add user?
     if ($this->admin) {
         $incident_array['user'] = $incident->user->as_array();
         //@todo sanitize
         unset($incident_array['user']['password']);
         unset($incident_array['user']['code']);
         // format date in ISO standard
         $incident_array['user']['updated'] = $incident_array['user']['updated'] != null ? date('c', strtotime($incident_array['user']['updated'])) : null;
     } else {
         // @todo check what should be public
         $incident_array['user'] = array('id' => $incident->user->id, 'name' => $incident->user->name, 'username' => $incident->user->username);
     }
     // Add media?
     $incident_array['media'] = array();
     foreach ($incident->media as $media) {
         // Only include visible categories unless we're an admin
         if ($this->admin or $media->media_active) {
             $media_data = $media->as_array();
             if ($media->media_link and !valid::url($media->media_link)) {
                 $media_data['media_link'] = url::convert_uploaded_to_abs($media_data['media_link']);
                 $media_data['media_medium'] = url::convert_uploaded_to_abs($media_data['media_medium']);
                 $media_data['media_thumb'] = url::convert_uploaded_to_abs($media_data['media_thumb']);
             }
             // format date in ISO standard
             $media_data['media_date'] = $media_data['media_date'] != null ? date('c', strtotime($media_data['media_date'])) : null;
             $incident_array['media'][] = $media_data;
         }
     }
     // Initialize custom field array - only supporting default form
     $incident_array['custom_field'] = customforms::get_custom_form_fields($incident_array['id'], 1, true);
     $incident_array['api_url'] = url::site(rest_controller::$api_base_url . '/incidents/' . $incident_array['id']);
     $incident_array['updated_at'] = $incident->incident_datemodify == null ? $incident->incident_dateadd : $incident->incident_datemodify;
     $incident_array['updated_at'] = date_create($incident_array['updated_at'])->format(DateTime::W3C);
     // format all dates in ISO standard
     $incident_array['incident_datemodify'] = $incident->incident_datemodify != null ? date_create($incident_array['incident_datemodify'])->format(DateTime::W3C) : null;
     $incident_array['incident_dateadd'] = $incident->incident_dateadd != null ? date_create($incident_array['incident_dateadd'])->format(DateTime::W3C) : null;
     $incident_array['incident_date'] = $incident->incident_date != null ? date_create($incident_array['incident_date'])->format(DateTime::W3C) : null;
     return $incident_array;
 }
 /**
  * Validation of form fields
  *
  * @param array $post Values to be validated
  */
 public static function validate(array &$post)
 {
     // Exception handling
     if (!isset($post) or !is_array($post)) {
         return FALSE;
     }
     // Create validation object
     $post = Validation::factory($post)->pre_filter('trim', TRUE)->add_rules('incident_title', 'required', 'length[3,200]')->add_rules('incident_description', 'required')->add_rules('incident_date', 'required', 'date_mmddyyyy')->add_rules('incident_hour', 'required', 'between[1,12]')->add_rules('incident_minute', 'required', 'between[0,59]')->add_rules('incident_ampm', 'required');
     if (isset($post->incident_ampm) and $post->incident_ampm != "am" and $post->incident_ampm != "pm") {
         $post->add_error('incident_ampm', 'values');
     }
     // Validate for maximum and minimum latitude values
     //$post->add_rules('latitude','required','between[-90,90]');
     // Validate for maximum and minimum longitude values
     //$post->add_rules('longitude','required','between[-180,180]');
     $post->add_rules('location_name', 'required', 'length[3,200]');
     //XXX: Hack to validate for no checkboxes checked
     if (!isset($post->incident_category)) {
         $post->incident_category = "";
         $post->add_error('incident_category', 'required');
     } else {
         $post->add_rules('incident_category.*', 'required', 'numeric');
     }
     // Validate only the fields that are filled in
     if (!empty($post->incident_news)) {
         foreach ($post->incident_news as $key => $url) {
             if (!empty($url) and !valid::url($url)) {
                 $post->add_error('incident_news', 'url');
             }
         }
     }
     // Validate only the fields that are filled in
     if (!empty($post->incident_video)) {
         foreach ($post->incident_video as $key => $url) {
             if (!empty($url) and !valid::url($url)) {
                 $post->add_error('incident_video', 'url');
             }
         }
     }
     // If deployment is a single country deployment, check that the location mapped is in the default country
     if (!Kohana::config('settings.multi_country') and isset($post->country_name)) {
         $country = Country_Model::get_country_by_name($post->country_name);
         if ($country and $country->id != Kohana::config('settings.default_country')) {
             $post->add_error('country_name', 'single_country', array(ORM::factory('country', Kohana::config('settings.default_country'))->country));
         }
     }
     // Validate photo uploads
     $max_upload_size = Kohana::config('settings.max_upload_size');
     $post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png,jpeg]', "upload::size[" . $max_upload_size . "M]");
     // Validate Personal Information
     if (!empty($post->person_first)) {
         $post->add_rules('person_first', 'length[2,100]');
     } else {
         $post->person_first = '';
     }
     if (!empty($post->person_last)) {
         $post->add_rules('person_last', 'length[2,100]');
     } else {
         $post->person_last = '';
     }
     if (!empty($post->person_email)) {
         $post->add_rules('person_email', 'email', 'length[3,100]');
     } else {
         $post->person_email = '';
     }
     $post->add_rules('location_id', 'numeric');
     $post->add_rules('incident_active', 'between[0,1]');
     $post->add_rules('incident_verified', 'between[0,1]');
     $post->add_rules('incident_zoom', 'numeric');
     // Custom form fields validation
     customforms::validate_custom_form_fields($post);
     //> END custom form fields validation
     // Return
     return $post->validate();
 }
 public function set_url($key, $url)
 {
     $this->options[$key] = valid::url($url) ? '"' . $url . '";' : '"' . url::site($url) . '";';
 }
Exemple #17
0
 /**
  * Tests the valid::url() function.
  * @dataProvider url_provider
  * @group core.helpers.valid.url
  * @test
  */
 public function url($input_url, $expected_result)
 {
     $result = valid::url($input_url);
     $this->assertEquals($expected_result, $result);
 }
Exemple #18
0
<section class="mod peepbox">
	<header>
		<h4><?php 
echo text::title($member->username);
?>
</h4>
	</header>

	<?php 
if (valid::url($member->picture)) {
    ?>
	<?php 
    echo html::image($member->picture, array('width' => 160));
    ?>
	<?php 
}
?>

	<?php 
if ($member->default_image_id) {
    ?>
	<?php 
    echo html::img($member->default_image, 'normal', array('width' => 160));
    ?>
	<?php 
}
?>

</section>
Exemple #19
0
 /**
  * Add Edit Categories
  */
 public function index()
 {
     $this->template->content = new View('admin/categories');
     $this->template->content->title = Kohana::lang('ui_admin.categories');
     // Locale (Language) Array
     $locales = ush_locale::get_i18n();
     // Setup and initialize form field names
     $form = array('action' => '', 'category_id' => '', 'parent_id' => '', 'category_title' => '', 'category_description' => '', 'category_color' => '', 'category_image' => '', 'category_image_thumb' => '', 'form_auth_token' => '');
     // Add the different language form keys for fields
     foreach ($locales as $lang_key => $lang_name) {
         $form['category_title_' . $lang_key] = '';
     }
     // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     $parents_array = array();
     // Check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Fetch the post data
         $post_data = array_merge($_POST, $_FILES);
         // Extract category-specific  information
         $category_data = arr::extract($post_data, 'parent_id', 'category_title', 'category_description', 'category_color');
         // Extract category image and category languages for independent validation
         $secondary_data = arr::extract($post_data, 'category_image', 'category_title_lang', 'action');
         // Setup validation for the secondary data
         $post = Validation::factory($secondary_data)->pre_filter('trim', TRUE);
         // Add validation for the add/edit action
         if ($post->action == 'a') {
             $post->add_rules('category_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]');
             // Add the different language form keys for fields
             foreach ($locales as $lang_key => $lang_name) {
                 $post->add_rules('category_title_lang[' . $lang_key . ']', 'length[3,80]');
             }
         }
         // Category instance for the operation
         $category = (!empty($_POST['category_id']) and Category_Model::is_valid_category($_POST['category_id'])) ? new Category_Model($_POST['category_id']) : new Category_Model();
         // Check the specified action
         if ($post->action == 'a') {
             // Test to see if things passed the rule checks
             if ($category->validate($category_data) and $post->validate(FALSE)) {
                 // Save the category
                 $category->save();
                 // Get the category localization
                 $languages = $category->loaded ? Category_Lang_Model::category_langs($category->id) : FALSE;
                 $category_lang = isset($languages[$category->id]) ? $languages[$category->id] : FALSE;
                 // Save localizations
                 foreach ($post->category_title_lang as $lang_key => $localized_category_name) {
                     $cl = isset($category_lang[$lang_key]['id']) ? ORM::factory('category_lang', $category_lang[$lang_key]['id']) : ORM::factory('category_lang');
                     $cl->category_title = $localized_category_name;
                     $cl->locale = $lang_key;
                     $cl->category_id = $category->id;
                     $cl->save();
                 }
                 // Upload Image/Icon
                 $filename = upload::save('category_image');
                 if ($filename) {
                     $new_filename = "category_" . $category->id . "_" . time();
                     // Name the files for the DB
                     $cat_img_file = $new_filename . ".png";
                     $cat_img_thumb_file = $new_filename . "_16x16.png";
                     // Resize Image to 32px if greater
                     Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $cat_img_file);
                     // Create a 16x16 version too
                     Image::factory($filename)->resize(16, 16, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $cat_img_thumb_file);
                     // Okay, now we have these three different files on the server, now check to see
                     //   if we should be dropping them on the CDN
                     if (Kohana::config("cdn.cdn_store_dynamic_content")) {
                         $cat_img_file = cdn::upload($cat_img_file);
                         $cat_img_thumb_file = cdn::upload($cat_img_thumb_file);
                         // We no longer need the files we created on the server. Remove them.
                         $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/';
                         unlink($local_directory . $new_filename . ".png");
                         unlink($local_directory . $new_filename . "_16x16.png");
                     }
                     // Remove the temporary file
                     unlink($filename);
                     // Delete Old Image
                     $category_old_image = $category->category_image;
                     if (!empty($category_old_image)) {
                         if (file_exists(Kohana::config('upload.directory', TRUE) . $category_old_image)) {
                             unlink(Kohana::config('upload.directory', TRUE) . $category_old_image);
                         } elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($category_old_image)) {
                             cdn::delete($category_old_image);
                         }
                     }
                     // Save
                     $category->category_image = $cat_img_file;
                     $category->category_image_thumb = $cat_img_thumb_file;
                     $category->save();
                     Event::run('ushahidi_action.category_save', $post);
                 }
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));
                 // Empty $form array
                 array_fill_keys($form, '');
             } else {
                 // Validation failed
                 // Repopulate the form fields
                 $form = arr::overwrite($form, array_merge($category_data->as_array(), $post->as_array()));
                 // populate the error fields, if any
                 $errors = arr::overwrite($errors, array_merge($category_data->errors('category'), $post->errors('category')));
                 $form_error = TRUE;
             }
         } elseif ($post->action == 'd' and $post->validate()) {
             // Delete action
             if ($category->loaded) {
                 ORM::factory('category_lang')->where(array('category_id' => $category->id))->delete_all();
                 // Check for all subcategories tied to this category and make them top level
                 $children = ORM::factory('category')->where('parent_id', $category->id)->find_all();
                 if ($children) {
                     foreach ($children as $child) {
                         $sub_cat = new Category_Model($child->id);
                         $sub_cat->parent_id = 0;
                         $sub_cat->save();
                     }
                 }
                 // Check for all reports tied to this category to be deleted
                 $result = ORM::factory('incident_category')->where('category_id', $category->id)->find_all();
                 // If there are reports returned by the query
                 if ($result) {
                     foreach ($result as $orphan) {
                         $orphan_incident_id = $orphan->incident_id;
                         // Check if the report is tied to any other category
                         $count = ORM::factory('incident_category')->where('incident_id', $orphan_incident_id)->count_all();
                         // If this report is tied to only one category(is uncategorized)
                         if ($count == 1) {
                             // Assign it to the special category for uncategorized reports
                             $orphaned = ORM::factory('incident_category', $orphan->id);
                             $orphaned->category_id = 5;
                             $orphaned->save();
                             // Deactivate the report so that it's not accessible on the frontend
                             $orphaned_report = ORM::factory('incident', $orphan_incident_id);
                             $orphaned_report->incident_active = 0;
                             $orphaned_report->save();
                         } else {
                             ORM::factory('incident_category')->delete($orphan->id);
                         }
                     }
                 }
                 // @todo Delete the category image
                 // Delete category itself - except if it is trusted
                 ORM::factory('category')->where('category_trusted != 1')->delete($category->id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             }
         } elseif ($post->action == 'v' and $post->validate()) {
             // Show/Hide Action
             if ($category->loaded) {
                 // Check for all subcategories tied to this category
                 $children = ORM::factory('category')->where('parent_id', $category->id)->find_all();
                 // Then show/hide subcategories based on status of parent category
                 foreach ($children as $child) {
                     $sub_cat = new Category_Model($child->id);
                     $sub_cat->category_visible = $category->category_visible == 1 ? 0 : 1;
                     $sub_cat->save();
                 }
                 // Change status of the Parent Category
                 $category->category_visible = $category->category_visible == 1 ? 0 : 1;
                 $category->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             }
         } elseif ($post->action == 'i' and $post->validate()) {
             // Delete Image/Icon Action
             if ($category->loaded) {
                 $category_image = $category->category_image;
                 $category_image_thumb = $category->category_image_thumb;
                 // Delete the main image
                 if (!empty($category_image) and file_exists(Kohana::config('upload.directory', TRUE) . $category_image)) {
                     unlink(Kohana::config('upload.directory', TRUE) . $category_image);
                 }
                 // Delete the thumb
                 if (!empty($category_image_thumb) and file_exists(Kohana::config('upload.directory', TRUE) . $category_image_thumb)) {
                     unlink(Kohana::config('upload.directory', TRUE) . $category_image_thumb);
                 }
                 $category->category_image = NULL;
                 $category->category_image_thumb = NULL;
                 $category->save();
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             }
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('category')->where('parent_id', '0')->count_all()));
     $categories = ORM::factory('category')->with('category_lang')->where('parent_id', '0')->orderby('category_title', 'asc')->find_all($this->items_per_page, $pagination->sql_offset);
     $parents_array = ORM::factory('category')->where('parent_id', '0')->where('category_trusted != 1')->select_list('id', 'category_title');
     // add none to the list
     $parents_array[0] = "--- Top Level Category ---";
     // Put "--- Top Level Category ---" at the top of the list
     ksort($parents_array);
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->categories = $categories;
     $this->template->content->parents_array = $parents_array;
     // Javascript Header
     $this->template->colorpicker_enabled = TRUE;
     $this->template->tablerowsort_enabled = TRUE;
     $this->template->js = new View('admin/categories_js');
     $this->template->form_error = $form_error;
     $this->template->content->locale_array = $locales;
     $this->template->js->locale_array = $locales;
 }
Exemple #20
0
 /**
  * Add url to sitemap
  * @param       string  url
  * @param       string  last time of modification format in YYYY-MM-DD
  * @param       string  change frequency always|hourly|daily|weekly|monthly|yearly|never
  * @return      object
  *
  */
 public function add_url($location, $lastmod = NULL, $changefreq = NULL, $priority = NULL)
 {
     $sitemap = $this->sitemap;
     if (!valid::url($location)) {
         throw new Kohana_Exception('sitemap.url_wrong_type', $location);
     }
     if ($this->url_exists($location) == true) {
         return false;
     }
     $url = $this->sitemap->createElement("url");
     $loc = $this->sitemap->createElement("loc", $location);
     $url->appendChild($loc);
     //Last modification is optional
     if ($lastmod != NULL) {
         $lastmod = $this->sitemap->createElement("lastmod", $lastmod);
         $url->appendChild($lastmod);
     }
     //Change frequency is optional
     if ($changefreq != NULL) {
         if (!in_array($changefreq, $this->changefreq)) {
             throw new Kohana_Exception('sitemap.unknown_change_frequency', $changefreq);
         }
         $changefreq = $this->sitemap->createElement("changefreq", $changefreq);
         $url->appendChild($changefreq);
     }
     //Priority is optional
     if ($priority != NULL) {
         if (!($priority >= 0 and $priority <= 1)) {
             throw new Kohana_Exception('sitemap.priority_out_of_range', $priority);
         }
         $priority = $this->sitemap->createElement("priority", $priority);
         $url->appendChild($priority);
     }
     $this->urlset->appendChild($url);
     return $this;
 }
Exemple #21
0
 /**
  * Retrieves information about predefinied Yahoo! tables. This
  * will not work for non-Yahoo! or non-Community tables, such
  * as personal blogs or other unaffiliated sites.
  *
  * @param   string       table
  * @return  YQL_Result
  * @author  Sam Clark
  * @access  public
  */
 public function desc($table)
 {
     // Clear existing queries
     $this->clear_queries();
     // If the url is valid
     if (valid::url($table)) {
         throw new Kohana_User_Exception('YQL::desc()', 'DESC only allows use of Yahoo! pre-registered tables. See http://developer.yahoo.com/yql/ for more information.');
     }
     // Set the desc statement
     $this->select = array('DESC' => $table);
     // Execute the query
     return $this->exec();
 }
Exemple #22
0
 /**
  * Quickly gets 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
  * @return  void
  * @throws  Kohana_User_Exception
  * @access  public
  * @static
  **/
 public static function get($url, $username = FALSE, $password = FALSE)
 {
     if (!valid::url($url)) {
         throw new Kohana_User_Exception(__CLASS__ . '.' . __METHOD__ . '()', 'The URL : ' . $url . ' is not a valid resource');
     }
     // Initiate a curl session based on the URL supplied
     $curl = Curl::factory(array(CURLOPT_POST => FALSE), $url);
     // If a username/password is supplied
     if ($username and $password) {
         // Add the HTTP Basic Auth headers
         $curl->setopt_array(array(CURLOPT_USERPWD => $username . ':' . $password));
     }
     // Run the curl request
     $curl->exec();
     // If there was an error, return null
     if ($curl->error()) {
         return;
     } else {
         return $curl->result();
     }
 }
Exemple #23
0
<?php

/**
 * Member pictures
 *
 * @package    Anqh
 * @author     Antti Qvickström
 * @copyright  (c) 2010 Antti Qvickström
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 */
?>

<?php 
if (valid::url($user->picture)) {
    echo html::image($user->picture);
}
?>

<?php 
if ($user->default_image_id) {
    echo html::img($user->default_image);
}
 /**
  * Accessor method for setting the default image if the supplied email address or rating return an empty result
  *
  * @param   string       url  the url of the image to use instead of the Gravatar
  * @return  self
  * @access  public
  * @author  Sam Clark
  */
 public function default_image($url)
 {
     if (valid::url($url)) {
         $this->config['default'] = $url;
     } else {
         throw new Kohana_User_Exception('Invalid default image URL', 'The url \'' . $url . '\' is improperly formatted');
     }
     return $this;
 }
Exemple #25
0
 public function valid_url_test()
 {
     $this->assert_true_strict(valid::url('http://eightphp.com'))->assert_false_strict(valid::url('eightphp.com'));
 }
 private function _handle_new_decayimage_fileupload($id)
 {
     $filename = upload::save('decayimage_file');
     if ($filename) {
         $new_filename = "decayimage_" . $id . "_" . time();
         // Name the files for the DB
         $cat_img_file = $new_filename . ".png";
         $cat_img_thumb_file = $new_filename . "_16x16.png";
         // Resize Image to 32px if greater
         Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $cat_img_file);
         // Create a 16x16 version too
         Image::factory($filename)->resize(16, 16, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $cat_img_thumb_file);
     } else {
         Kohana::log('error', 'we were not able to save the file upload');
         return false;
     }
     // Okay, now we have these three different files on the server, now check to see
     //   if we should be dropping them on the CDN
     if (Kohana::config("cdn.cdn_store_dynamic_content")) {
         $cat_img_file = cdn::upload($cat_img_file);
         $cat_img_thumb_file = cdn::upload($cat_img_thumb_file);
         // We no longer need the files we created on the server. Remove them.
         $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/';
         unlink($local_directory . $new_filename . ".png");
         unlink($local_directory . $new_filename . "_16x16.png");
     }
     // Remove the temporary file
     if (file_exists($filename)) {
         unlink($filename);
     }
     // Delete Old Image, unless its the default image
     $decayimage = ORM::factory('decayimage')->where('id', $id);
     if ($decayimage && $id != 0) {
         $category_old_image = $decayimage->decayimage_image;
         if (!empty($category_old_image)) {
             if (file_exists(Kohana::config('upload.directory', TRUE) . $category_old_image)) {
                 unlink(Kohana::config('upload.directory', TRUE) . $category_old_image);
             } elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($category_old_image)) {
                 cdn::delete($category_old_image);
             }
         }
     }
     return array($cat_img_file, $cat_img_thumb_file);
 }
Exemple #27
0
 public function valid_url_test()
 {
     $this->assert_true_strict(valid::url('http://www.kohanaphp.com'))->assert_false_strict(valid::url('www.kohanaphp.com'));
 }