• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Media_Model类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Media_Model的典型用法代码示例。如果您正苦于以下问题:PHP Media_Model类的具体用法?PHP Media_Model怎么用?PHP Media_Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Media_Model类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: _tag_media

 /**
  * Tag a news item to an incident.
  * 
  * @param int incidentid - The incident id.
  * @param string mediatype - The media type,video, picture,etc
  *
  * @return Array
  */
 private function _tag_media($incidentid, $mediatype)
 {
     if ($_POST) {
         // Check if incident ID exist
         $incidentid_exist = Incident_Model::is_valid_incident($incidentid);
         if (!$incidentid_exist) {
             return $this->set_error_message(array("error" => $this->api_service->get_error_msg(012)));
         }
         // Get the locationid for the incidentid
         $locationid = 0;
         $items = ORM::factory('incident')->select(array('location_id'))->where(array('incident.id' => $incidentid))->find();
         if ($items->count_all() > 0) {
             $locationid = $items->location_id;
         }
         $media = new Media_Model();
         //create media model object
         $url = '';
         $post = Validation::factory(array_merge($_POST, $_FILES));
         if ($mediatype == 2 or $mediatype == 4) {
             //require a url
             if (!$this->api_service->verify_array_index($this->request, 'url')) {
                 return $this->set_error_message(array("error" => $this->api_service->get_error_msg(01, 'url')));
             } else {
                 $url = $this->request['url'];
                 $media->media_link = $url;
             }
         } else {
             if (!$this->api_service->verify_array_index($this->request, 'photo')) {
                 $this->set_error_message(array("error" => $this->api_service->get_error_msg(01), 'photo'));
             }
             $post->add_rules('photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]');
             if ($post->validate(FALSE)) {
                 //assuming this is a photo
                 $filename = upload::save('photo');
                 $new_filename = $incidentid . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 $media->media_link = $new_filename . ".jpg";
                 $media->media_thumb = $new_filename . "_t.jpg";
             }
         }
         // Optional title & description
         $title = '';
         if ($this->api_service->verify_array_index($_POST, 'title')) {
             $title = $_POST['title'];
         }
         $description = '';
         if ($this->api_service->verify_array_index($_POST, 'description')) {
             $description = $_POST['description'];
         }
         $media->location_id = $locationid;
         $media->incident_id = $incidentid;
         $media->media_type = $mediatype;
         $media->media_title = $title;
         $media->media_description = $description;
         $media->media_date = date("Y-m-d H:i:s", time());
         $media->save();
         //save the thing
         // SUCESS!!!
         $ret = array("payload" => array("domain" => $this->domain, "success" => "true"), "error" => $this->api_service->get_error_msg(0));
         return $this->set_error_message($ret);
     } else {
         return $this->set_error_message(array("error" => $this->api_service->get_error_msg(03)));
     }
 }
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:77,代码来源:MY_Tag_Media_Api_Object.php


示例2: _tag_media

 /**
  * Tag a news item to an incident.
  * 
  * @param int incidentid - The incident id.
  * @param string mediatype - The media type,video, picture,etc
  *
  * @return Array
  */
 private function _tag_media($incidentid, $mediatype)
 {
     if ($_POST) {
         //get the locationid for the incidentid
         $locationid = 0;
         $this->query = "SELECT location_id FROM " . $this->table_prefix . "incident WHERE id={$incidentid}";
         $items = $this->db->query($this->query);
         if (count($items) > 0) {
             $locationid = $items[0]->location_id;
         }
         $media = new Media_Model();
         //create media model object
         $url = '';
         $post = Validation::factory(array_merge($_POST, $_FILES));
         if ($mediatype == 2 or $mediatype == 4) {
             //require a url
             if (!$this->api_service->verify_array_index($this->request, 'url')) {
                 if ($this->response_type == 'json') {
                     json_encode(array("error" => $this->api_service->get_error_msg(01, 'url')));
                 } else {
                     $err = array("error" => $this->api_service->get_error_msg(01, 'url'));
                     return $this->array_as_xml($err, array());
                 }
             } else {
                 $url = $this->request['url'];
                 $media->media_link = $url;
             }
         } else {
             if (!$this->api_service->verify_array_index($this->request, 'photo')) {
                 if ($this->response_type == 'photo') {
                     json_encode(array("error" => $this->api_service->get_error_msg(01, 'photo')));
                 } else {
                     $err = array("error" => $this->api_service->get_error_msg(01, 'photo'));
                     return $this->api_service->array_as_xml($err, array());
                 }
             }
             $post->add_rules('photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]');
             if ($post->validate()) {
                 //assuming this is a photo
                 $filename = upload::save('photo');
                 $new_filename = $incidentid . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
                 unlink($filename);
                 $media->media_link = $new_filename . ".jpg";
                 $media->media_thumb = $new_filename . "_t.jpg";
             }
         }
         // Optional title & description
         $title = '';
         if ($this->api_service->verify_array_index($_POST, 'title')) {
             $title = $_POST['title'];
         }
         $description = '';
         if ($this->api_service->verify_array_index($_POST, 'description')) {
             $description = $_POST['description'];
         }
         $media->location_id = $locationid;
         $media->incident_id = $incidentid;
         $media->media_type = $mediatype;
         $media->media_title = $title;
         $media->media_description = $description;
         $media->media_date = date("Y-m-d H:i:s", time());
         $media->save();
         //save the thing
         // SUCESS!!!
         $ret = array("payload" => array("domain" => $this->domain, "success" => "true"), "error" => $this->api_service->get_error_msg(0));
         if ($this->response_type == 'json') {
             return json_encode($ret);
         } else {
             return $this->array_as_xml($ret, array());
         }
     } else {
         if ($this->response_type == 'json') {
             return json_encode(array("error" => $this->api_service->get_error_msg(03)));
         } else {
             $err = array("error" => $this->api_service->get_error_msg(03));
             return $this->array_as_xml($err, array());
         }
     }
 }
开发者ID:mewsop,项目名称:Ushahidi_Web,代码行数:92,代码来源:MY_Tag_Media_Api_Object.php


示例3: submit


//.........这里部分代码省略.........
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // STEP 1: SAVE LOCATION
             $location = new Location_Model();
             $location->location_name = $post->location_name;
             $location->latitude = $post->latitude;
             $location->longitude = $post->longitude;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             // STEP 2: SAVE INCIDENT
             $incident = new Incident_Model();
             $incident->location_id = $location->id;
             $incident->user_id = 0;
             $incident->incident_title = $post->incident_title;
             $incident->incident_description = $post->incident_description;
             $incident_date = explode("/", $post->incident_date);
             // The $_POST['date'] is a value posted by form in mm/dd/yyyy format
             $incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1];
             $incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm;
             $incident->incident_date = $incident_date . " " . $incident_time;
             $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             $incident->save();
             // STEP 3: SAVE CATEGORIES
             foreach ($post->incident_category as $item) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
             // STEP 4: SAVE MEDIA
             // a. News
             foreach ($post->incident_news as $item) {
                 if (!empty($item)) {
                     $news = new Media_Model();
                     $news->location_id = $location->id;
                     $news->incident_id = $incident->id;
                     $news->media_type = 4;
                     // News
                     $news->media_link = $item;
                     $news->media_date = date("Y-m-d H:i:s", time());
                     $news->save();
                 }
             }
             // b. Video
             foreach ($post->incident_video as $item) {
                 if (!empty($item)) {
                     $video = new Media_Model();
                     $video->location_id = $location->id;
                     $video->incident_id = $incident->id;
                     $video->media_type = 2;
                     // Video
                     $video->media_link = $item;
                     $video->media_date = date("Y-m-d H:i:s", time());
                     $video->save();
                 }
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
开发者ID:kiirti,项目名称:Ushahidi_MHI,代码行数:67,代码来源:reports.php


示例4: add_email

 /**
  * Adds email to the database and saves the sender as a new
  * Reporter if they don't already exist
  * @param string $messages
  */
 private function add_email($messages)
 {
     $service = ORM::factory('service')->where('service_name', 'Email')->find();
     if (!$service->loaded) {
         return;
     }
     if (empty($messages) or !is_array($messages)) {
         return;
     }
     foreach ($messages as $message) {
         $reporter = ORM::factory('reporter')->where('service_id', $service->id)->where('service_account', $message['email'])->find();
         if (!$reporter->loaded == true) {
             // Add new reporter
             $names = explode(' ', $message['from'], 2);
             $last_name = '';
             if (count($names) == 2) {
                 $last_name = $names[1];
             }
             // get default reporter level (Untrusted)
             $level = ORM::factory('level')->where('level_weight', 0)->find();
             $reporter->service_id = $service->id;
             $reporter->level_id = $level->id;
             $reporter->service_account = $message['email'];
             $reporter->reporter_first = $names[0];
             $reporter->reporter_last = $last_name;
             $reporter->reporter_email = $message['email'];
             $reporter->reporter_phone = null;
             $reporter->reporter_ip = null;
             $reporter->reporter_date = date('Y-m-d');
             $reporter->save();
         }
         if ($reporter->level_id > 1 && count(ORM::factory('message')->where('service_messageid', $message['message_id'])->find_all()) == 0) {
             // Save Email as Message
             $email = new Message_Model();
             $email->parent_id = 0;
             $email->incident_id = 0;
             $email->user_id = 0;
             $email->reporter_id = $reporter->id;
             $email->message_from = $message['from'];
             $email->message_to = null;
             $email->message = $message['subject'];
             $email->message_detail = $message['body'];
             $email->message_type = 1;
             // Inbox
             $email->message_date = $message['date'];
             $email->service_messageid = $message['message_id'];
             $email->save();
             // Attachments?
             foreach ($message['attachments'] as $attachments) {
                 foreach ($attachments as $attachment) {
                     $media = new Media_Model();
                     $media->location_id = 0;
                     $media->incident_id = 0;
                     $media->message_id = $email->id;
                     $media->media_type = 1;
                     // Images
                     $media->media_link = $attachment[0];
                     $media->media_medium = $attachment[1];
                     $media->media_thumb = $attachment[2];
                     $media->media_date = date("Y-m-d H:i:s", time());
                     $media->save();
                 }
             }
             // Auto-Create A Report if Reporter is Trusted
             $reporter_weight = $reporter->level->level_weight;
             $reporter_location = $reporter->location;
             if ($reporter_weight > 0 and $reporter_location) {
                 // Create Incident
                 $incident = new Incident_Model();
                 $incident->location_id = $reporter_location->id;
                 $incident->incident_title = $message['subject'];
                 $incident->incident_description = $message['body'];
                 $incident->incident_date = $message['date'];
                 $incident->incident_dateadd = date("Y-m-d H:i:s", time());
                 $incident->incident_active = 1;
                 if ($reporter_weight == 2) {
                     $incident->incident_verified = 1;
                 }
                 $incident->save();
                 // Update Message with Incident ID
                 $email->incident_id = $incident->id;
                 $email->save();
                 // Save Incident Category
                 $trusted_categories = ORM::factory("category")->where("category_trusted", 1)->find();
                 if ($trusted_categories->loaded) {
                     $incident_category = new Incident_Category_Model();
                     $incident_category->incident_id = $incident->id;
                     $incident_category->category_id = $trusted_categories->id;
                     $incident_category->save();
                 }
                 // Add Attachments
                 $attachments = ORM::factory("media")->where("message_id", $email->id)->find_all();
                 foreach ($attachments as $attachment) {
                     $attachment->incident_id = $incident->id;
                     $attachment->save();
//.........这里部分代码省略.........
开发者ID:Dirichi,项目名称:Ushahidi_Web,代码行数:101,代码来源:s_email.php


示例5: Layout_Model

     break;
     // 	Delete
 // 	Delete
 case 2:
     $model = new Layout_Model();
     if (!empty($_POST)) {
         if ($model->deleteGallery($_POST['pictureId'])) {
             echo 1;
         }
     }
     break;
 case 3:
     $model = new Layout_Model();
     $allowedExtensions = array("jpg", "JPG", "jpeg", "png");
     $sizeLimit = 20 * 1024 * 1024;
     $uploader = new Media_Model($allowedExtensions, $sizeLimit);
     $savePath = $root . '/images/media/original/';
     $medium = $root . '/images/media/thumb/';
     $pre = 'Villa-Aqua-' . Tools::slugify($_POST['sectionName']);
     $mediumWidth = 550;
     if ($result = $uploader->handleUpload($savePath, $pre)) {
         $uploader->getThumb($result['fileName'], $savePath, $medium, $mediumWidth, 'width', '');
         $newData = getimagesize($medium . $result['fileName']);
         $wp = $newData[0];
         $hp = $newData[1];
         $lastId = 0;
         if ($newData) {
             $lastId = $model->addGallery($_POST['sectionName'], $result['fileName']);
         }
         $data = array('success' => true, 'fileName' => $result['fileName'], 'wp' => $wp, 'hp' => $hp, 'lastId' => $lastId);
         echo htmlspecialchars(json_encode($data), ENT_NOQUOTES);
开发者ID:raulcastro,项目名称:villaaqua,代码行数:31,代码来源:media-gallery.php


示例6: save_media

 /**
  * Function to save news, photos and videos
  *
  * @param mixed $location_model
  * @param mixed $post
  *
  */
 public static function save_media($post, $incident)
 {
     // Delete Previous Entries
     ORM::factory('media')->where('incident_id', $incident->id)->where('media_type <> 1')->delete_all();
     // a. News
     foreach ($post->incident_news as $item) {
         if (!empty($item)) {
             $news = new Media_Model();
             $news->location_id = $incident->location_id;
             $news->incident_id = $incident->id;
             $news->media_type = 4;
             // News
             $news->media_link = $item;
             $news->media_date = date("Y-m-d H:i:s", time());
             $news->save();
         }
     }
     // b. Video
     foreach ($post->incident_video as $item) {
         if (!empty($item)) {
             $video = new Media_Model();
             $video->location_id = $incident->location_id;
             $video->incident_id = $incident->id;
             $video->media_type = 2;
             // Video
             $video->media_link = $item;
             $video->media_date = date("Y-m-d H:i:s", time());
             $video->save();
         }
     }
     // c. Photos
     $filenames = upload::save('incident_photo');
     $i = 1;
     foreach ($filenames as $filename) {
         $new_filename = $incident->id . "_" . $i . "_" . time();
         $file_type = strrev(substr(strrev($filename), 0, 4));
         // IMAGE SIZES: 800X600, 400X300, 89X59
         // Large size
         Image::factory($filename)->resize(800, 600, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . $file_type);
         // Medium size
         Image::factory($filename)->resize(400, 300, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_m" . $file_type);
         // Thumbnail
         Image::factory($filename)->resize(89, 59, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t" . $file_type);
         // Remove the temporary file
         unlink($filename);
         // Save to DB
         $photo = new Media_Model();
         $photo->location_id = $incident->location_id;
         $photo->incident_id = $incident->id;
         $photo->media_type = 1;
         // Images
         $photo->media_link = $new_filename . $file_type;
         $photo->media_medium = $new_filename . "_m" . $file_type;
         $photo->media_thumb = $new_filename . "_t" . $file_type;
         $photo->media_date = date("Y-m-d H:i:s", time());
         $photo->save();
         $i++;
     }
 }
开发者ID:kjgarza,项目名称:thrasos,代码行数:66,代码来源:reports.php


示例7: register_checkin


//.........这里部分代码省略.........
         } else {
             $user_name = '';
         }
         if ($email) {
             $user_email = $email;
         } else {
             $user_email = $this->getRandomString();
         }
         if ($color) {
             $user_color = $color;
         } else {
             $user_color = $this->random_color();
         }
         // Check if email exists
         $query = 'SELECT id FROM ' . $this->table_prefix . 'users WHERE `email` = \'' . $user_email . '\' LIMIT 1;';
         $usercheck = $this->db->query($query);
         if (isset($usercheck[0]->id)) {
             $user_id = $usercheck[0]->id;
         } else {
             // Create a new user
             $user = ORM::factory('user');
             $user->name = $user_name;
             $user->email = $user_email;
             $user->username = $this->getRandomString();
             $user->password = 'checkinuserpw';
             $user->color = $user_color;
             $user->add(ORM::factory('role', 'login'));
             $user_id = $user->save();
         }
         //   TODO: When we have user registration down, we need to pass a user id here
         //         so we can assign it to a specific user
         User_Devices_Model::register_device($mobileid, $user_id);
     }
     // Now we have a fully registered device so lets update our user if we need to
     if ($firstname and $lastname and $email) {
         $user_id = User_Devices_Model::device_owner($mobileid);
         $user_name = $firstname . ' ' . $lastname;
         $user_email = $email;
         $user = ORM::factory('user', $user_id);
         $user->name = $user_name;
         $user->email = $user_email;
         if ($color) {
             $user->color = $color;
         }
         $user_id = $user->save();
         $user_id = $user_id->id;
     }
     // Get our user id if it hasn't already been set by one of the processes above
     if (!isset($user_id)) {
         $user_id = User_Devices_Model::device_owner($mobileid);
     }
     // Whew, now that all that is out of the way, do the flippin checkin!
     // FIRST, save the location
     $location = new Location_Model();
     $location->location_name = $lat . ',' . $lon;
     $location->latitude = $lat;
     $location->longitude = $lon;
     $location->location_date = date("Y-m-d H:i:s", time());
     $location_id = $location->save();
     // SECOND, save the checkin
     if (!$message) {
         $message = '';
     }
     $checkin = ORM::factory('checkin');
     $checkin->user_id = $user_id;
     $checkin->location_id = $location_id;
     $checkin->checkin_description = $message;
     $checkin->checkin_date = date("Y-m-d H:i:s", time());
     $checkin_id = $checkin->save();
     // THIRD, save the photo, if there is a photo
     if (isset($_FILES['photo'])) {
         $filename = upload::save('photo');
         $new_filename = 'ci_' . $user_id . '_' . time() . '_' . $this->getRandomString(4);
         $file_type = strrev(substr(strrev($filename), 0, 4));
         // IMAGE SIZES: 800X600, 400X300, 89X59
         // Large size
         Image::factory($filename)->resize(800, 600, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . $file_type);
         // Medium size
         Image::factory($filename)->resize(400, 300, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_m" . $file_type);
         // Thumbnail
         Image::factory($filename)->resize(89, 59, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t" . $file_type);
         // Remove the temporary file
         unlink($filename);
         // Save to DB
         $media_photo = new Media_Model();
         $media_photo->location_id = $location_id;
         $media_photo->checkin_id = $checkin_id;
         $media_photo->media_type = 1;
         // Images
         $media_photo->media_link = $new_filename . $file_type;
         $media_photo->media_medium = $new_filename . "_m" . $file_type;
         $media_photo->media_thumb = $new_filename . "_t" . $file_type;
         $media_photo->media_date = date("Y-m-d H:i:s", time());
         $media_photo->save();
     }
     $return = array("checkin_id" => $checkin_id->id, "user_id" => $user_id);
     // Hook on successful checkin
     Event::run('ushahidi_action.checkin_recorded', $checkin);
     return $return;
 }
开发者ID:huslage,项目名称:Ushahidi_Web,代码行数:101,代码来源:MY_Checkin_Api_Object.php


示例8: array

            if ($newData) {
                if ($_POST['lastIdLogo'] > 0) {
                    if ($model->updateCompanyLogo($_POST['lastIdLogo'], $result['fileName'])) {
                        $lastId = $_POST['lastIdLogo'];
                    }
                } else {
                    $lastId = $model->addCompanyLogo($_POST['companyId'], $result['fileName']);
                }
            }
            $data = array('success' => true, 'fileName' => $result['fileName'], 'wp' => $wp, 'hp' => $hp, 'lastId' => $lastId);
            echo htmlspecialchars(json_encode($data), ENT_NOQUOTES);
        }
        break;
        // 	Crop
    // 	Crop
    case 2:
        $model = new Media_Model();
        $data = $backend->loadBackend();
        if (!empty($_POST)) {
            $dstWidth = 300;
            $dstImageHeight = 150;
            $source = $root . '/img-up/companies_pictures/original/' . $_POST['imgId'];
            $destination = $root . '/img-up/companies_pictures/logo/' . $_POST['imgId'];
            if ($model->cropImage($_POST, $dstWidth, $dstImageHeight, $source, $destination)) {
                echo '1';
            } else {
                echo '0';
            }
        }
        break;
}
开发者ID:raulcastro,项目名称:encharoladeplayaes,代码行数:31,代码来源:company-media-logo.php


示例9: index

 /**
  * Map Settings
  */
 function index($saved = false)
 {
     // Display all maps
     $this->template->api_url = Kohana::config('settings.api_url_all');
     // Current Default Country
     $current_country = Kohana::config('settings.default_country');
     $this->template->content = new View('admin/settings');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('default_map' => '', 'api_google' => '', 'api_live' => '', 'default_country' => '', 'multi_country' => '', 'default_lat' => '', 'default_lon' => '', 'default_zoom' => '', 'default_map_all' => '', 'allow_clustering' => '', 'default_map_all_icon' => '', 'delete_default_map_all_icon' => '');
     //	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 = $saved == 'saved';
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = Validation::factory($_POST)->pre_filter('trim', TRUE)->add_rules('default_country', 'required', 'numeric', 'length[1,4]')->add_rules('multi_country', 'numeric', 'length[1,1]')->add_rules('default_map', 'required', 'length[0,100]')->add_rules('default_zoom', 'required', 'between[0,21]')->add_rules('default_lat', 'required', 'between[-85,85]')->add_rules('default_lon', 'required', 'between[-180,180]')->add_rules('allow_clustering', 'required', 'between[0,1]')->add_rules('default_map_all', 'required', 'alpha_numeric', 'length[6,6]')->add_rules('api_google', 'length[0,200]')->add_rules('api_live', 'length[0,200]');
         // Add rules for file upload
         $files = Validation::factory($_FILES);
         $files->add_rules('default_map_all_icon', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[250K]');
         // Test to see if things passed the rule checks
         if ($post->validate() and $files->validate(FALSE)) {
             // Yes! everything is valid
             $settings = new Settings_Model(1);
             $settings->default_country = $post->default_country;
             $settings->multi_country = $post->multi_country;
             $settings->default_map = $post->default_map;
             $settings->api_google = $post->api_google;
             // E.Kala 20th April 2012
             // Gangsta workaround prevent resetting og Bing Maps API Key
             // Soon to be addressed conclusively
             if (isset($post['api_live']) and !empty($post['api_live'])) {
                 $settings->api_live = $post->api_live;
             }
             $settings->default_zoom = $post->default_zoom;
             $settings->default_lat = $post->default_lat;
             $settings->default_lon = $post->default_lon;
             $settings->allow_clustering = $post->allow_clustering;
             $settings->default_map_all = $post->default_map_all;
             $settings->date_modify = date("Y-m-d H:i:s", time());
             $settings->save();
             // Deal with default category icon now
             // Check if deleting or updating a new image (or doing nothing)
             if (isset($post->delete_default_map_all_icon) and $post->delete_default_map_all_icon == 1) {
                 // Delete old badge image
                 ORM::factory('media')->delete($settings->default_map_all_icon_id);
                 // Remove from DB table
                 $settings = new Settings_Model(1);
                 $settings->default_map_all_icon_id = NULL;
                 $settings->save();
             } else {
                 // We aren't deleting, so try to upload if we are uploading an image
                 $filename = upload::save('default_map_all_icon');
                 if ($filename) {
                     $new_filename = "default_map_all_" . time();
                     $file_type = strrev(substr(strrev($filename), 0, 4));
                     // Large size
                     $l_name = $new_filename . $file_type;
                     Image::factory($filename)->save(Kohana::config('upload.directory', TRUE) . $l_name);
                     // Medium size
                     $m_name = $new_filename . "_m" . $file_type;
                     Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $m_name);
                     // Thumbnail
                     $t_name = $new_filename . "_t" . $file_type;
                     Image::factory($filename)->resize(16, 16, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $t_name);
                     // Name the files for the DB
                     $media_link = $l_name;
                     $media_medium = $m_name;
                     $media_thumb = $t_name;
                     // 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")) {
                         $media_link = cdn::upload($media_link);
                         $media_medium = cdn::upload($media_medium);
                         $media_thumb = cdn::upload($media_thumb);
                         // We no longer need the files we created on the server. Remove them.
                         $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/';
                         unlink($local_directory . $l_name);
                         unlink($local_directory . $m_name);
                         unlink($local_directory . $t_name);
                     }
                     // Remove the temporary file
                     unlink($filename);
                     // Save image in the media table
                     $media = new Media_Model();
                     $media->media_type = 1;
                     // Image
                     $media->media_link = $media_link;
                     $media->media_medium = $media_medium;
                     $media->media_thumb = $media_thumb;
                     $media->media_date = date("Y-m-d H:i:s", time());
                     $media->save();
                     // Save new image in settings
                     $settings = new Settings_Model(1);
//.........这里部分代码省略.........
开发者ID:nemmy,项目名称:Ushahidi_Web,代码行数:101,代码来源:settings.php


示例10: edit


//.........这里部分代码省略.........
                 $incident->incident_dateadd = date("Y-m-d H:i:s", time());
             }
             // Is this an SMS or Twitter submitted report?
             //XXX: It is possible that 'mobile_id' may not be available through
             //$_POST
             if (isset($messageType) && $messageType != "") {
                 if ($messageType == 'sms') {
                     $incident->incident_mode = 2;
                     // SMS - 2
                 } elseif ($messageType == 'twitter') {
                     $incident->incident_mode = 4;
                     // Twitter - 4
                 } elseif (isset($mobile_id) && $mobile_id != "") {
                     $incident->incident_mode = 2;
                     //Set the default as SMS - 2
                 }
             }
             $incident->save();
             // STEP 3: SAVE CATEGORIES
             ORM::factory('Incident_Category')->where('incident_id', $incident->id)->delete_all();
             // Delete Previous Entries
             foreach ($post->incident_category as $item) {
                 $incident_category = new Incident_Category_Model();
                 $incident_category->incident_id = $incident->id;
                 $incident_category->category_id = $item;
                 $incident_category->save();
             }
             // STEP 4: SAVE MEDIA
             ORM::factory('Media')->where('incident_id', $incident->id)->where('media_type <> 1')->delete_all();
             // Delete Previous Entries
             // a. News
             foreach ($post->incident_news as $item) {
                 if (!empty($item)) {
                     $news = new Media_Model();
                     $news->location_id = $location->id;
                     $news->incident_id = $incident->id;
                     $news->media_type = 4;
                     // News
                     $news->media_link = $item;
                     $news->media_date = date("Y-m-d H:i:s", time());
                     $news->save();
                 }
             }
             // b. Video
             foreach ($post->incident_video as $item) {
                 if (!empty($item)) {
                     $video = new Media_Model();
                     $video->location_id = $location->id;
                     $video->incident_id = $incident->id;
                     $video->media_type = 2;
                     // Video
                     $video->media_link = $item;
                     $video->media_date = date("Y-m-d H:i:s", time());
                     $video->save();
                 }
             }
             // c. Photos
             $filenames = upload::save('incident_photo');
             $i = 1;
             foreach ($filenames as $filename) {
                 $new_filename = $incident->id . "_" . $i . "_" . time();
                 // Resize original file... make sure its max 408px wide
                 Image::factory($filename)->resize(408, 248, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".jpg");
                 // Create thumbnail
                 Image::factory($filename)->resize(70, 41, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t.jpg");
                 // Remove the temporary file
开发者ID:emoksha,项目名称:freefairelections,代码行数:67,代码来源:reports.php


示例11: index

 public function index()
 {
     $apiurl = "http://tasukeai.heroku.com/all.xml";
     #$apiurl = "http://localhost/message.xml";
     $messages = simplexml_load_file($apiurl);
     foreach ($messages as $message) {
         $title = "";
         $lat = "";
         $active = 1;
         $long = "";
         $matches = array();
         if (strcmp($message->title["nil"], "true") != 0) {
             $title = (string) $message->title;
         } else {
             if (preg_match("/\\s*\\[ボランティア名称\\]\\s*\n([^\n]+)\n/", $message->body, $matches)) {
                 $title = $matches[1];
             } else {
                 if (preg_match("/\\s*\\[主催\\]\\s*([^\n]+)\n/", $message->body, $matches)) {
                     $title = $matches[1];
                 } else {
                     if (preg_match("/\\s*\\[タイトル\\]\\s*([^\n]+)\n/", $message->body, $matches)) {
                         $title = $matches[1];
                     } else {
                         $title = "無題";
                         $active = 0;
                     }
                 }
             }
         }
         if (strcmp($message->latitude["nil"], "true") != 0 && strcmp($message->longitude["nil"], "true") != 0) {
             $lat = (double) $message->latitude;
             $long = (double) $message->longitude;
         } else {
             if (preg_match("/\\s*\\[緯度経度\\]\\s*\n([^,]+),([^\n]+)/", $message->body, $matches)) {
                 $lat = $matches[1];
                 $long = $matches[2];
             }
         }
         $link = $this->input->xss_clean($message->link);
         $where_string = "media_link = '" . $link . "'";
         $db = new Database();
         $count = $db->count_records('media', $where_string);
         if ($count > 0) {
             if (strcmp($message->{"valid-f"}, "false") == 0) {
                 $search_query = "SELECT incident_id FROM media" . " WHERE (" . $where_string . ")";
                 $query = $db->query($search_query);
                 ORM::factory('Incident')->where('id', $query[0]->incident_id)->delete_all();
                 ORM::factory('Media')->where('incident_id', $query[0]->incident_id)->delete_all();
             }
             continue;
         }
         if (strcmp($message->{"valid-f"}, "true") != 0) {
             continue;
         }
         $incident = new Incident_Model();
         // STEP 1: SAVE LOCATION
         if (isset($lat) && isset($long)) {
             $location = new Location_Model("");
             $location->location_name = (string) $message->address;
             $location->latitude = $lat;
             $location->longitude = $long;
             $location->location_date = date("Y-m-d H:i:s", time());
             $location->save();
             $incident->location_id = $location->id;
         }
         $incident->incident_title = $title;
         $incident->incident_description = (string) $message->body;
         $incident->incident_date = date("Y-m-d H:i:s", strtotime($message->{"created-at"}));
         $incident->incident_dateadd = date("Y-m-d H:i:s", time());
         $incident->incident_mode = 1;
         $incident->incident_active = $active;
         $incident->incident_verified = 1;
         $incident->incident_source = 3;
         $incident->incident_information = 1;
         //Save
         $incident->save();
         $news = new Media_Model();
         $news->incident_id = $incident->id;
         if (isset($location)) {
             $news->location_id = $location->id;
         }
         $news->media_type = 4;
         // News
         $news->media_link = $link;
         $news->media_date = date("Y-m-d H:i:s", strtotime($message->{"created-at"}));
         $news->save();
         $incident_category = new Incident_Category_Model();
         $incident_category->incident_id = $incident->id;
         if (strcmp($message->target, "2") == 0) {
             $incident_category->category_id = 9;
             //救援物資
         } else {
             $incident_category->category_id = 13;
             //求む
         }
         $incident_category->save();
     }
     $this->template->content = new View('tasukeaiimport/main');
 }
开发者ID:nastasio,项目名称:Ushahidi_Web,代码行数:99,代码来源:tasukeaiimport.php


示例12: import_reports


//.........这里部分代码省略.........
                                     $match_field_defaults = $match_fields->field_default;
                                     // Grab form responses
                                     $field_response = trim($field->nodeValue);
                                     if ($field_response != '') {
                                         // Initialize form response model
                                         $new_form_response = new Form_Response_Model();
                                         $new_form_response->incident_id = $new_report->id;
                                         $new_form_response->form_field_id = $match_field_id;
                                         // For radio buttons, checkbox fields and drop downs, make sure form responses are
                                         // within bounds of allowable options for that field
                                         // Split field defaults into individual values
                                         $field_defaults = explode(',', $match_field_defaults);
                                         /* Radio buttons and Drop down fields which take single responses */
                                         if ($match_field_type == 5 or $match_field_type == 7) {
                                             foreach ($field_defaults as $match_field_default) {
                                                 // Carry out a case insensitive string comparison
                                                 $new_form_response->form_response = strcasecmp($match_field_default, $field_response) == 0 ? $match_field_default : NULL;
                                             }
                                         }
                                         // Checkboxes which
                                         if ($match_field_type == 6) {
                                             // Split user responses into individual value
                                             $responses = explode(',', $field_response);
                                             $values = array();
                                             foreach ($match_field_defaults as $match_field_default) {
                                                 foreach ($responses as $response) {
                                                     $values[] = strcasecmp($match_field_default, $response) == 0 ? $match_field_default : NULL;
                                                 }
                                             }
                                             // Concatenate checkbox values into a string, separated by a comma
                                             $new_form_response->form_response = implode(",", $values);
                                         } else {
                                             $new_form_response->form_response = $field_response;
                                         }
                                         // Only save if form response is not empty
                                         if ($new_form_response->form_response != NULL) {
                                             $new_form_response->save();
                                         }
                                         // Add this to array of form responses added
                                         $this->incident_responses_added[] = $new_form_response->id;
                                     }
                                 } else {
                                     $this->notices[] = Kohana::lang('import.xml.form_field_no_match') . $this->totalreports . ': "' . $field_name . '" on form "' . $new_report->form->form_title . '"';
                                 }
                             }
                         }
                     }
                 }
                 /* Step 5: Save incident persons for this report */
                 // Report Personal Information
                 $personal_info = $report->getElementsByTagName('personal_info');
                 // If personal info exists
                 if ($personal_info->length > 0) {
                     $report_info = $personal_info->item(0);
                     // First Name
                     $firstname = xml::get_node_text($report_info, 'first_name');
                     // Last Name
                     $lastname = xml::get_node_text($report_info, 'last_name');
                     // Email
                     $r_email = xml::get_node_text($report_info, 'email');
                     $email = ($r_email and valid::email($r_email)) ? $r_email : NULL;
                     $new_incident_person = new Incident_Person_Model();
                     $new_incident_person->incident_id = $new_report->id;
                   

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Meeting类代码示例发布时间:2022-05-23
下一篇:
PHP MediaWikiTestCase类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap