示例#1
0
 function upload_media($campaign, $action = null)
 {
     $this->load->model('setting_m');
     $this->load->library('facebook');
     $uid = $this->facebook->getUser();
     $action = $action ? $action : menu_url('upload');
     $form = new HTMLQuickForm2('uploadmedia', 'POST', 'data-ajax="false"');
     $form->setAttribute('action', $action);
     $active_campaign_gid = $campaign['GID'];
     $allowed_media_fields = $campaign['allowed_media_fields'];
     parse_str($allowed_media_fields, $fields_to_add);
     $allowed_media_source = $campaign['allowed_media_source'];
     $allowed_media_type = $campaign['allowed_media_type'];
     $allowed_maxfilesize = 5 * 1024 * 1024;
     $allowed_mimetype = @$campaign['allowed_mimetype'];
     if ($allowed_media_source == "file") {
         $form->setAttribute('enctype', 'multipart/form-data');
         //$form->addElement('hidden','MAX_FILE_SIZE')->setValue($allowed_maxfilesize);
     }
     foreach ($fields_to_add as $domid => $label) {
         $label = ucfirst($label) . '   :   ';
         switch ($domid) {
             case 'media_title':
                 //$form->addElement('static','','',array('content'=>$label));
                 $r = $form->addElement('text', $domid, '');
                 $r->setLabel($label);
                 $r->addRule('required', $label . ' is required', null, HTML_QuickForm2_Rule::SERVER);
                 break;
             case 'media_description':
                 //$form->addElement('static','','',array('content'=>$label));
                 $r = $form->addElement('textarea', $domid, 'maxlength="160"');
                 $r->setLabel($label);
                 $r->addRule('required', $label . ' is required', null, HTML_QuickForm2_Rule::SERVER);
                 $r->addRule('minlength', $label . ' length to short', 20, HTML_QuickForm2_Rule::SERVER);
                 $r->addRule('maxlength', $label . ' Character to Long, Max 160', 160, HTML_QuickForm2_Rule::SERVER);
                 break;
             case 'media_source':
                 //$form->addElement('static','','',array('content'=>$label));
                 $src = explode(',', $allowed_media_source);
                 if (in_array('facebook', $src) || in_array('youtube', $src) || in_array('twitpic', $src) || in_array('yfrog', $src) || in_array('plixi', $src)) {
                     //$form->addElement('static','','',array('content'=>'Copy and Paste YouTube URL here'));
                     $r->setLabel('YouTube URL');
                     $r = $form->addElement('text', $domid, '');
                     $r->addRule('required', $label . ' is required', null, HTML_QuickForm2_Rule::SERVER);
                     break;
                 } elseif (in_array('file', $src)) {
                     //$form->addElement('static','','',array('content'=>'Upload Photo from your computer here'));
                     $r_file = $form->addElement('file', $domid, '');
                     $r_file->setLabel('Upload Photo');
                     $r_file->addRule('required', $label . ' is required', null, HTML_QuickForm2_Rule::SERVER);
                     $r_file->addRule('mimetype', $label . ' is not valid file type', explode(',', $allowed_mimetype), HTML_QuickForm2_Rule::SERVER);
                     $r_file->addRule('maxfilesize', $label . ' filesize is exceeded ', $allowed_maxfilesize, HTML_QuickForm2_Rule::SERVER);
                     break;
                 }
         }
     }
     $button = $form->addElement('submit', 'submit', 'data-role="none" value="Upload" class="input-submit button big"');
     $button->setLabel(' ');
     if ($form->validate()) {
         $form->toggleFrozen(true);
         $data = $form->getValue();
         unset($data['submit'], $data['_qf__uploadmedia']);
         /* Array ( [media_title] => sdfsdfs [media_description] => sdfsdfsdf [media_source] => Array ( [name] => Billboard6.png [type] => image/png [tmp_name] => /tmp/php1kDGMJ [error] => 0 [size] => 274034 ) ) */
         switch (strtolower($allowed_media_type)) {
             case 'image':
                 if (strtolower($allowed_media_source) == "file") {
                     if ($data['media_source']['error'] == UPLOAD_ERR_OK) {
                         $tmp_name = $data['media_source']["tmp_name"];
                         $time = md5(uniqid(rand(), true) . time());
                         $image = resizeImage($tmp_name, CUSTOMER_IMAGE_DIR . $active_campaign_gid . "/" . $uid . "_" . $time . ".jpg", 440, 'width');
                         $image_medium = resizeImage($tmp_name, CUSTOMER_IMAGE_DIR . $active_campaign_gid . "/medium_" . $uid . "_" . $time . ".jpg", 300, 'width');
                         $thumb = resizeImage($tmp_name, CUSTOMER_IMAGE_DIR . $active_campaign_gid . "/thumb_" . $uid . "_" . $time . ".jpg", 100, null, true);
                         $data['media_source'] = 'file';
                         //$data['media_url'] = base_url()."image?gid=".$active_campaign_gid."&src=".$uid."_".$time.".jpg";
                         //$data['media_medium_url'] = base_url()."image?gid=".$active_campaign_gid."&src=medium_".$uid."_".$time.".jpg";
                         //$data['media_thumb_url'] = base_url()."image?gid=".$active_campaign_gid."&src=thumb_".$uid."_".$time.".jpg";
                         $data['media_url'] = base_url() . "image/u/" . $active_campaign_gid . "/" . $uid . "_" . $time . ".jpg";
                         $data['media_medium_url'] = base_url() . "image/u/" . $active_campaign_gid . "/medium_" . $uid . "_" . $time . ".jpg";
                         $data['media_thumb_url'] = base_url() . "image/u/" . $active_campaign_gid . "/thumb_" . $uid . "_" . $time . ".jpg";
                         $data['media_type'] = $allowed_media_type;
                         $data['media_basename'] = $uid . "_" . $time . ".jpg";
                     } else {
                         $data = array();
                     }
                 } else {
                     $meta = get_image_from_url($data['media_source']);
                     $data['media_source'] = $meta['from'];
                     $data['media_url'] = $meta['image'];
                     $data['media_thumb_url'] = $meta['thumb'];
                     $data['media_type'] = $allowed_media_type;
                 }
                 break;
             case 'video':
                 if (strtolower($allowed_media_source) == "file") {
                     if ($data['media_source']['error'] == UPLOAD_ERR_OK) {
                         $tmp_name = $data['media_source']["tmp_name"];
                         $basename = explode('.', $data['media_source']["name"]);
                         $time = md5(uniqid(rand(), true) . time());
                         if (!move_uploaded_file($tmp_name, CUSTOMER_VIDEO_DIR . $active_campaign_gid . "/" . $uid . "_" . $time . '.' . $basename[1])) {
                             return false;
                         } else {
                             $data['media_source'] = 'file';
                             $data['media_url'] = $uid . "_" . $time . '.' . $basename[1];
                             $data['media_thumb_url'] = '';
                             $data['media_type'] = $allowed_media_type;
                             $data['media_basename'] = $uid . "_" . $time . '.' . $basename[1];
                         }
                     } else {
                         $data = array();
                     }
                 } else {
                     $meta = get_video_from_url($data['media_source']);
                     $data['media_source'] = $meta['from'];
                     $data['media_url'] = $meta['video'];
                     $data['media_thumb_url'] = $meta['thumb'];
                     $data['media_type'] = $allowed_media_type;
                 }
                 break;
         }
         $time = time();
         $data['media_status'] = $campaign['media_has_approval'] ? 'pending' : 'active';
         $data['media_uploaded_date'] = date('Y-m-d H:i:s', $time);
         $data['media_uploaded_timestamp'] = $time;
         $data['GID'] = $active_campaign_gid;
         if ($media_ok = $this->media_m->addMedia($data)) {
             return "success";
         } else {
             return "error";
         }
         $form->removeChild($button);
         if ($r_file) {
             $form->removeChild($r_file);
         }
     }
     $renderer = HTML_QuickForm2_Renderer::factory('default');
     $form_layout = $form->render($renderer);
     return isset($html_done) ? $html_done : $form_layout;
 }
示例#2
0
 /**
  * Import Page for this controller.
  */
 public function import($url = FALSE)
 {
     $this->load->library('user_check');
     if (!$url) {
         $this->not_found();
         return;
     } else {
         $this->load->helper(array('get_images', 'url_encode', 'string'));
         $decoded_url = prep_url(base64_decode_url($url));
         if (!$this->assessment_model->check_existed_garment($decoded_url)) {
             $this->general_error("It's a duplicate garment!", "It's a duplicate garment!");
             return;
         }
         list($filtered_images, $garment_name) = get_image_from_url($decoded_url);
         $data = $this->data;
         $data['title'] = "Import Garment";
         $data['extraJS'] = '<script src="/js/garment-import.js?v=2.2.0.4"></script><script src="/js/jquery-ui.min.js"></script><script src="/js/jquery.multiselect.min.js"></script><link href="/css/jquery.multiselect.css" rel="stylesheet">';
         $data['extraDiv'] = '<div id="hiddenURL" style="display:none">' . $url . '</div>';
         $data['images'] = array_slice($filtered_images, 0, 7);
         $data['garment_name'] = $garment_name;
         $data['colours1'] = $this->colour_model->get_available_colours();
         $data['colours2'] = $this->colour_model->get_available_colours(TRUE);
         $data['occasions'] = $this->occasion_model->get_available_occasions();
         $data['categories'] = $this->category_model->get_available_categories();
         $this->load->view('templates/header', $data);
         $this->load->view('templates/menu', $data);
         $this->load->view('templates/menu_mall', $data);
         $this->load->view('garment/import', $data);
         $this->load->view('templates/footer', $data);
     }
 }