Beispiel #1
0
 public function index()
 {
     $this->load->model("content_model");
     $this->load->helper('file');
     $params = $this->content_model->_select_list();
     $this->load->model('vimeo');
     $vimeo = new vimeo();
     $vimeo->setKeyToken('3b727db2432ef47c1d3855526984d2845712caae', 'cc63242aa7ea80f09858c061862f79fd0117bbb3', '802e0070a904b7bd17f5eb0afd3c0dde', '39aa3cabd67c6a113ba99f0ada7fc14c6374ddfd');
     $vimeo->enableCache(Vimeo::CACHE_FILE, './cache', 300);
     for ($i = 0; $i < count($params); $i++) {
         if ($params[$i]['ctType'] == "VIMEO") {
             $videos = $vimeo->call('vimeo.videos.getInfo', array('video_id' => $params[$i]['ctSource']));
             foreach ($videos->video[0] as $k => $v) {
                 $apiData[$k] = $v;
             }
             if ($apiData['thumbnails']->thumbnail[0]) {
                 $data['ctThumbSOrigin'] = $apiData['thumbnails']->thumbnail[1]->_content;
                 $data['ctThumbLOrigin'] = $apiData['thumbnails']->thumbnail[2]->_content;
                 $arrFileType = explode('/', $data['ctThumbSOrigin']);
                 $cntFileType = count($arrFileType) - 1;
                 $fileTypeS = $arrFileType[$cntFileType];
                 $arrFileType = explode('/', $data['ctThumbLOrigin']);
                 $cntFileType = count($arrFileType) - 1;
                 $fileTypeL = $arrFileType[$cntFileType];
                 $data['ctThumbS'] = md5(date('YmdHis') . $data['ctThumbSOrigin']) . $fileTypeS;
                 $data['ctThumbL'] = md5(date('YmdHis') . $data['ctThumbLOrigin']) . $fileTypeL;
                 file_put_contents('./uploads/content/thumbs/' . $data['ctThumbS'], file_get_contents($data['ctThumbSOrigin']));
                 file_put_contents('./uploads/content/thumbl/' . $data['ctThumbL'], file_get_contents($data['ctThumbLOrigin']));
             }
             $this->content_model->_update($data, array('ctNO' => $params[$i]['ctNO']));
         } else {
             if ($params[$i]['ctType'] == "YOUTUBE") {
                 $url = 'https://gdata.youtube.com/feeds/api/videos/' . $params[$i]['ctSource'] . '?v=2&alt=json';
                 $contents = file_get_contents($url);
                 $video = json_decode($contents);
                 foreach ($video->entry as $k => $v) {
                     $apiData[$k] = $v;
                 }
                 if ($apiData['media$group']->{'media$thumbnail'}[1]) {
                     $data['ctThumbSOrigin'] = $apiData['media$group']->{'media$thumbnail'}[1]->{'url'};
                     $data['ctThumbLOrigin'] = $apiData['media$group']->{'media$thumbnail'}[2]->{'url'};
                     $arrFileType = explode('/', $data['ctThumbSOrigin']);
                     $cntFileType = count($arrFileType) - 1;
                     $fileTypeS = $arrFileType[$cntFileType];
                     $arrFileType = explode('/', $data['ctThumbLOrigin']);
                     $cntFileType = count($arrFileType) - 1;
                     $fileTypeL = $arrFileType[$cntFileType];
                     $data['ctThumbS'] = md5(date('YmdHis') . $data['ctThumbSOrigin']) . $fileTypeS;
                     $data['ctThumbL'] = md5(date('YmdHis') . $data['ctThumbLOrigin']) . $fileTypeL;
                     file_put_contents('./uploads/content/thumbs/' . $data['ctThumbS'], file_get_contents($data['ctThumbSOrigin']));
                     file_put_contents('./uploads/content/thumbl/' . $data['ctThumbL'], file_get_contents($data['ctThumbLOrigin']));
                 }
                 $this->content_model->_update($data, array('ctNO' => $params[$i]['ctNO']));
             }
         }
         unset($data);
     }
 }
Beispiel #2
0
 public function videoContentUpdate_vimeo()
 {
     $params = $this->input->post();
     $this->load->model('vimeo');
     $vimeo = new vimeo();
     $vimeo->setKeyToken('3b727db2432ef47c1d3855526984d2845712caae', 'cc63242aa7ea80f09858c061862f79fd0117bbb3', '802e0070a904b7bd17f5eb0afd3c0dde', '39aa3cabd67c6a113ba99f0ada7fc14c6374ddfd');
     $vimeo->enableCache(Vimeo::CACHE_FILE, './cache', 300);
     $idx = 0;
     $videos = $vimeo->call('vimeo.channels.getVideos', array('per_page' => 10000, 'channel_id' => $params['ctChannelId']));
     if ($videos) {
         foreach ($videos->videos->video as $v) {
             $apiData[$idx]['title'] = $v->title;
             $apiData[$idx++]['channelId'] = $v->id;
         }
         $data = json_encode($apiData);
         write_file('./assets/json/vimeo/' . $params['ctChannelId'] . '.json', $data);
         unset($apiData);
     }
     redirect(base_url("/media_link/index"));
 }
Beispiel #3
0
 public function process()
 {
     $params = $this->input->post();
     unset($params['videoCheck']);
     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      *  컨텐츠 등록 처리.
      *  뭔가 굉장히 많다. 소스를 줄일 수 있을것 같지만 그건 나중에(= _ =;;)
      *  Api를 통해 받은 썸네일의 URL 로 썸네일 파일을 서버에 내려받음
      *  URL 을 '/' 구분자로 자른 후 파일명을 추출하여 원본파일명 컬럼에 저장.
      *         '.' 구분자로 자른 후 파일확장자를 랜덤파일명에 붙여줌
      *         ( 랜덤파일명은 '년월일시분초+파일명' 을 m5로 변환한 값 )
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
     if ($params['mode'] == "write") {
         if ($params['ctMP3'] && strpos($params['ctMP3'], "soundcloud.com") && !strpos($params['ctMP3'], "download")) {
             $lastStr = substr($params['ctMP3'], -1);
             $params['ctMP3'] = $lastStr == "/" ? $params['ctMP3'] . "download" : $params['ctMP3'] . "/download";
         }
         if ($params['prCode']) {
             $program = $this->common_model->_select_row('program_data', array('prCode' => $params['prCode']));
             $strFileName = '';
             if ($params['ctVideoNormal'] || $params['ctVideoLow']) {
                 /*  간편다운로드 체크되어있는 프로그램이면 mp4 일반화질, 저화질 자동등록하기    */
             } else {
                 if ($program['prIsSimpleDown'] == "YES") {
                     $strLenPrCode = strlen($program['prCode']);
                     for ($i = 6; $i < $strLenPrCode; $i += 3) {
                         $prCode = substr($program['prCode'], 0, $i);
                         $tmpProgram = $this->common_model->_select_row('program_data', array('prCode' => $prCode));
                         $strFileName .= $tmpProgram['prDir'] . '-';
                     }
                     $strFileName .= $program['prDir'] . '-' . str_replace('-', '', $params['ctEventDate']);
                     $params['ctVideoNormal'] = $strFileName . '-normal.mp4';
                     $params['ctVideoLow'] = $strFileName . '-low.mp4';
                 }
             }
         }
         $arrThumb = explode('/', $params['ctThumbS']);
         $cntThumb = count($arrThumb) - 1;
         $ThumbSOrigin = $arrThumb[$cntThumb];
         $arrThumb = explode('/', $params['ctThumbL']);
         $cntThumb = count($arrThumb) - 1;
         $ThumbLOrigin = $arrThumb[$cntThumb];
         $params['ctThumbSOrigin'] = $ThumbSOrigin;
         $params['ctThumbLOrigin'] = $ThumbLOrigin;
         $arrFileType = explode('/', $ThumbSOrigin);
         $cntFileType = count($arrFileType) - 1;
         $fileTypeS = $arrFileType[$cntFileType];
         $arrFileType = explode('/', $ThumbLOrigin);
         $cntFileType = count($arrFileType) - 1;
         $fileTypeL = $arrFileType[$cntFileType];
         $ctThumbS = $params['ctThumbS'];
         $ctThumbL = $params['ctThumbL'];
         $params['ctThumbS'] = md5(date('YmdHis') . $ThumbSOrigin) . $fileTypeS;
         $params['ctThumbL'] = md5(date('YmdHis') . $ThumbLOrigin) . $fileTypeL;
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $ctThumbS);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         $contentsS = curl_exec($ch);
         curl_close($ch);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $ctThumbL);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         $contentsL = curl_exec($ch);
         curl_close($ch);
         file_put_contents('./uploads/content/thumbs/' . $params['ctThumbS'], $contentsS);
         file_put_contents('./uploads/content/thumbl/' . $params['ctThumbL'], $contentsL);
         if (count($params['ctRelative_ctNO']) > 0) {
             for ($i = 0; $i < count($params['ctRelative_ctNO']); $i++) {
                 $params['ctRelativeContents'] .= $params['ctRelative_ctNO'][$i] . ",";
             }
         }
         $params['ctRemoteIP'] = $_SERVER['REMOTE_ADDR'];
         $params['ctModDate'] = 'NOW()';
         $params['ctRegDate'] = 'NOW()';
         unset($params['ctRelative_ctNO']);
         unset($params['isChangeContent']);
         unset($params['mode']);
         $this->common_model->_insert('content_data', $params);
         $path = "./_cache/%cache";
         delete_files($path, true);
         /*  XML, JSON 파일 만들기    */
         if ($params['prCode']) {
             // $this->makeExternalFiles($params['prCode']);
             echo "<script>location.href='/adm/content/index';</script>";
         }
         exit;
         // 관리자 컨텐츠 수정
     } else {
         if ($params['mode'] == "modify") {
             if ($params['prCode']) {
                 $program = $this->common_model->_select_row('program_data', array('prCode' => $params['prCode']));
                 $strFileName = '';
                 if ($params['ctVideoNormal'] || $params['ctVideoLow']) {
                     /*  간편다운로드 체크되어있는 프로그램이면 mp4 일반화질, 저화질 자동등록하기    */
                 } else {
                     if ($program['prIsSimpleDown'] == "YES") {
                         $strLenPrCode = strlen($program['prCode']);
                         for ($i = 6; $i < $strLenPrCode; $i += 3) {
                             $prCode = substr($program['prCode'], 0, $i);
                             $tmpProgram = $this->common_model->_select_row('program_data', array('prCode' => $prCode));
                             $strFileName .= $tmpProgram['prDir'] . '-';
                         }
                         $strFileName .= $program['prDir'] . '-' . str_replace('-', '', $params['ctEventDate']);
                         $params['ctVideoNormal'] = $strFileName . '-normal.mp4';
                         $params['ctVideoLow'] = $strFileName . '-low.mp4';
                     }
                 }
             }
             if ($params['ctMP3'] && strpos($params['ctMP3'], "soundcloud.com") && !strpos($params['ctMP3'], "download")) {
                 $lastStr = substr($params['ctMP3'], -1);
                 $params['ctMP3'] = $lastStr == "/" ? $params['ctMP3'] . "download" : $params['ctMP3'] . "/download";
             }
             if ($params['isChangeContent'] == 'Y') {
                 $arrThumb = explode('/', $params['ctThumbS']);
                 $cntThumb = count($arrThumb) - 1;
                 $ThumbSOrigin = $arrThumb[$cntThumb];
                 $arrThumb = explode('/', $params['ctThumbL']);
                 $cntThumb = count($arrThumb) - 1;
                 $ThumbLOrigin = $arrThumb[$cntThumb];
                 $params['ctThumbSOrigin'] = $ThumbSOrigin;
                 $params['ctThumbLOrigin'] = $ThumbLOrigin;
                 $arrFileType = explode('/', $ThumbSOrigin);
                 $cntFileType = count($arrFileType) - 1;
                 $fileTypeS = $arrFileType[$cntFileType];
                 $arrFileType = explode('/', $ThumbLOrigin);
                 $cntFileType = count($arrFileType) - 1;
                 $fileTypeL = $arrFileType[$cntFileType];
                 $ctThumbS = $params['ctThumbS'];
                 $ctThumbL = $params['ctThumbL'];
                 $params['ctThumbS'] = md5(date('YmdHis') . $ThumbSOrigin) . $fileTypeS;
                 $params['ctThumbL'] = md5(date('YmdHis') . $ThumbLOrigin) . $fileTypeL;
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $ctThumbS);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                 $contentsS = curl_exec($ch);
                 curl_close($ch);
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $ctThumbL);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                 $contentsL = curl_exec($ch);
                 curl_close($ch);
                 file_put_contents('./uploads/content/thumbs/' . $params['ctThumbS'], $contentsS);
                 file_put_contents('./uploads/content/thumbl/' . $params['ctThumbL'], $contentsL);
             }
             $params['ctModDate'] = 'NOW()';
             foreach ($params as $k => $v) {
                 if ($v == "") {
                     unset($params[$k]);
                 }
             }
             if (count($params['ctRelative_ctNO']) > 0) {
                 for ($i = 0; $i < count($params['ctRelative_ctNO']); $i++) {
                     $params['ctRelativeContents'] .= $params['ctRelative_ctNO'][$i] . ",";
                 }
             }
             unset($params['ctRelative_ctNO']);
             unset($params['isChangeContent']);
             unset($params['mode']);
             //echo'<pre>';print_r($params);echo"</pre>";
             $this->common_model->_update('content_data', $params, array('ctNO' => $params['ctNO']));
             //mainFocus 업데이트
             $paramMainFocus['mFName'] = $params['ctName'];
             $params['mFModDate'] = 'NOW()';
             $this->common_model->_update('mainFocus_data', $paramMainFocus, array('ctNO' => $params['ctNO']));
             $path = "./_cache/%cache";
             delete_files($path, true);
             /*  XML, JSON 파일 만들기    */
             if ($params['prCode']) {
                 //   $this->makeExternalFiles($params['prCode']);
                 echo "<script>location.href='/adm/content/view/ctNO/" . $params['ctNO'] . "';</script>";
             }
             exit;
             // 관리자 컨텐츠 삭제
         } else {
             if ($params['mode'] == "delete") {
                 if ($params['chk']) {
                     for ($i = 0; $i < count($params['chk']); $i++) {
                         $Code[] = $params['chk'][$i];
                     }
                     for ($i = 0; $i < count($Code); $i++) {
                         $data = $this->common_model->_select_row('content_data', array('ctNO' => $Code[$i]));
                         $this->common_model->_delete('livecontent_data', array('ctNO' => $data['ctNO']));
                         $this->common_model->_delete('view_log', array('ctNO' => $data['ctNO']));
                         $this->common_model->_delete('mypage_log', array('ctNO' => $data['ctNO'], 'mpSection' => 'VIEW'));
                         $this->common_model->_delete('content_data', array('ctNO' => $data['ctNO'], 'prCode' => $data['prCode']));
                     }
                 } else {
                     $this->common_model->_delete('livecontent_data', array('ctNO' => $params['ctNO']));
                     $this->common_model->_delete('view_log', array('ctNO' => $params['ctNO']));
                     $this->common_model->_delete('mypage_log', array('ctNO' => $params['ctNO'], 'mpSection' => 'VIEW'));
                     $this->common_model->_delete('content_data', array('ctNO' => $params['ctNO'], 'prCode' => $params['prCode']));
                 }
                 //$this->makeExternalFiles($params['prCode']);
                 $path = "./_cache/%cache";
                 delete_files($path, true);
                 redirect(base_url("/adm/content/index"));
             } else {
                 if ($params['mode'] == "media_source") {
                     $data = array('youtube' => $params['source']);
                     $jsonData = json_encode($data);
                     write_file('./assets/json/config/media_source.json', $jsonData);
                     redirect(base_url("/adm/content/media_source"));
                 } else {
                     if ($params['mode'] == "homeshopping") {
                         $jsonData = json_encode($params);
                         write_file('./assets/json/config/homeshopping.json', $jsonData);
                         redirect(base_url("/adm/content/homeshopping"));
                     } else {
                         if ($params['mode'] == "uefa") {
                             $jsonData = json_encode($params);
                             write_file('./assets/json/config/uefa.json', $jsonData);
                             redirect(base_url("/adm/content/uefa"));
                         } else {
                             if ($params['mode'] == "thumbUpdate") {
                                 $data = $this->common_model->_select_row('content_data', array("ctNO" => $params['ctNO']));
                                 unlink("./uploads/content/thumbl/" . $data['ctThumbL']);
                                 unlink("./uploads/content/thumbs/" . $data['ctThumbS']);
                                 if ($data['ctType'] == "VIMEO") {
                                     $this->load->model('vimeo');
                                     $vimeo = new vimeo();
                                     $vimeo->setKeyToken('3b727db2432ef47c1d3855526984d2845712caae', 'cc63242aa7ea80f09858c061862f79fd0117bbb3', '802e0070a904b7bd17f5eb0afd3c0dde', '39aa3cabd67c6a113ba99f0ada7fc14c6374ddfd');
                                     $vimeo->enableCache(Vimeo::CACHE_FILE, './cache', 300);
                                     $videos = $vimeo->call('vimeo.videos.getInfo', array('video_id' => $data['ctSource']));
                                     foreach ($videos->video[0] as $k => $v) {
                                         $apiData[$k] = $v;
                                     }
                                     if ($apiData['thumbnails']->thumbnail[0]) {
                                         $data['ctThumbSOrigin'] = $apiData['thumbnails']->thumbnail[1]->_content;
                                         $data['ctThumbLOrigin'] = $apiData['thumbnails']->thumbnail[2]->_content;
                                         $arrFileType = explode('/', $data['ctThumbSOrigin']);
                                         $cntFileType = count($arrFileType) - 1;
                                         $fileTypeS = $arrFileType[$cntFileType];
                                         $arrFileType = explode('/', $data['ctThumbLOrigin']);
                                         $cntFileType = count($arrFileType) - 1;
                                         $fileTypeL = $arrFileType[$cntFileType];
                                         $data['ctThumbS'] = md5(date('YmdHis') . $data['ctThumbSOrigin']) . $fileTypeS;
                                         $data['ctThumbL'] = md5(date('YmdHis') . $data['ctThumbLOrigin']) . $fileTypeL;
                                         file_put_contents('./uploads/content/thumbs/' . $data['ctThumbS'], file_get_contents($data['ctThumbSOrigin']));
                                         file_put_contents('./uploads/content/thumbl/' . $data['ctThumbL'], file_get_contents($data['ctThumbLOrigin']));
                                     }
                                     $data['ctModDate'] = 'NOW()';
                                     $this->common_model->_update('content_data', $data, array('ctNO' => $data['ctNO']));
                                 } else {
                                     if ($data['ctType'] == "YOUTUBE") {
                                         $url = 'https://gdata.youtube.com/feeds/api/videos/' . $data['ctSource'] . '?v=2&alt=json';
                                         $contents = file_get_contents($url);
                                         $video = json_decode($contents);
                                         foreach ($video->entry as $k => $v) {
                                             $apiData[$k] = $v;
                                         }
                                         if ($apiData['media$group']->{'media$thumbnail'}[1]) {
                                             $data['ctThumbSOrigin'] = $apiData['media$group']->{'media$thumbnail'}[1]->{'url'};
                                             $data['ctThumbLOrigin'] = $apiData['media$group']->{'media$thumbnail'}[2]->{'url'};
                                             $arrFileType = explode('/', $data['ctThumbSOrigin']);
                                             $cntFileType = count($arrFileType) - 1;
                                             $fileTypeS = $arrFileType[$cntFileType];
                                             $arrFileType = explode('/', $data['ctThumbLOrigin']);
                                             $cntFileType = count($arrFileType) - 1;
                                             $fileTypeL = $arrFileType[$cntFileType];
                                             $data['ctThumbS'] = md5(date('YmdHis') . $data['ctThumbSOrigin']) . $fileTypeS;
                                             $data['ctThumbL'] = md5(date('YmdHis') . $data['ctThumbLOrigin']) . $fileTypeL;
                                             file_put_contents('./uploads/content/thumbs/' . $data['ctThumbS'], file_get_contents($data['ctThumbSOrigin']));
                                             file_put_contents('./uploads/content/thumbl/' . $data['ctThumbL'], file_get_contents($data['ctThumbLOrigin']));
                                         }
                                         $data['ctModDate'] = 'NOW()';
                                         $this->common_model->_update('content_data', $data, array('ctNO' => $data['ctNO']));
                                     }
                                 }
                                 redirect(base_url("/adm/content/view/ctNO/" . $data['ctNO']));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #4
0
 /**
  * 비메오 transcoding 여부 체크
  * @param none
  * @return none
  */
 public function isTranscoding()
 {
     $params = $this->input->post();
     $this->load->model('vimeo');
     $vimeo = new vimeo();
     $vimeo->setKeyToken('3b727db2432ef47c1d3855526984d2845712caae', 'cc63242aa7ea80f09858c061862f79fd0117bbb3', '802e0070a904b7bd17f5eb0afd3c0dde', '39aa3cabd67c6a113ba99f0ada7fc14c6374ddfd');
     $vimeo->enableCache(Vimeo::CACHE_FILE, './cache', 300);
     $videos = $vimeo->call('vimeo.videos.getInfo', array('video_id' => $params['ctSource']));
     echo json_encode(array('isTranscoding' => $videos->video[0]->is_transcoding));
 }
Beispiel #5
0
 public function ajax_process()
 {
     $params = $this->input->post();
     $this->load->helper('file');
     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      *  Vimeo 카테고리 Data 를 Json 으로 생성
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
     if ($params['mode'] == "getApiContent") {
         $media = strtolower($params['ctType']);
         $url = "./assets/json/" . $media . "/" . $params['ctCate'] . ".json";
         $contents = file_get_contents($url);
         $cate = json_decode($contents);
         $mediaID = $media == "youtube" ? "playlistId" : "channelId";
         $html = '<select name="ctSource" class="form-control">';
         $html .= '<option value="">선택</option>';
         foreach ($cate as $v) {
             $html .= '<option value="' . $v->{$mediaID} . '">' . $v->title . '</option>';
         }
         $html .= '</select>';
         echo json_encode($html);
     } else {
         if ($params['ctType'] == "VIMEO") {
             $this->load->model('vimeo');
             $vimeo = new vimeo();
             $vimeo->setKeyToken('3b727db2432ef47c1d3855526984d2845712caae', 'cc63242aa7ea80f09858c061862f79fd0117bbb3', '802e0070a904b7bd17f5eb0afd3c0dde', '39aa3cabd67c6a113ba99f0ada7fc14c6374ddfd');
             $vimeo->enableCache(Vimeo::CACHE_FILE, './cache', 300);
             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
              *  Vimeo 카테고리 Data 를 Json 으로 생성
              * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
             if ($params['mode'] == "videoCateUpdate") {
                 $idx = 0;
                 $videos = $vimeo->call('vimeo.channels.getAll', array('per_page' => 1000));
                 if ($videos) {
                     foreach ($videos->channels->channel as $k => $v) {
                         $apiData[$idx]['title'] = $v->name;
                         $apiData[$idx++]['channelId'] = $v->id;
                     }
                     $data = json_encode($apiData);
                     write_file('./assets/json/vimeo/vimeo_cate.json', $data);
                 }
                 redirect(base_url("/adm/content/index"));
                 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                  *  Vimeo 컨텐츠 Data 를 Json 으로 생성
                  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
             } else {
                 if ($params['mode'] == "videoContentUpdate") {
                     $url = "./assets/json/vimeo/vimeo_cate.json";
                     $contents = file_get_contents($url);
                     $cate = json_decode($contents);
                     foreach ($cate as $val) {
                         $idx = 0;
                         $videos = $vimeo->call('vimeo.channels.getVideos', array('per_page' => 10000, 'channel_id' => $val->channelId));
                         if ($videos) {
                             foreach ($videos->videos->video as $v) {
                                 $apiData[$idx]['title'] = $v->title;
                                 $apiData[$idx++]['channelId'] = $v->id;
                             }
                             $data = json_encode($apiData);
                             write_file('./assets/json/vimeo/' . $val->channelId . '.json', $data);
                             unset($apiData);
                         }
                     }
                     redirect(base_url("/adm/content/index"));
                     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *  VIMEO API 를 이용하여 컨텐츠의 데이터를 가져옴
                      *  Api 에서 제공하는 영상 재생 시간은 초 단위로 받기 때문에 시:분:초 형태로 변경함
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                 } else {
                     if ($params['mode'] == "getApiInfo") {
                         $videos = $vimeo->call('vimeo.videos.getInfo', array('video_id' => $params['ctSource']));
                         foreach ($videos->video[0] as $k => $v) {
                             $apiData[$k] = $v;
                         }
                         if ($apiData['thumbnails']->thumbnail[0]) {
                             $seconds = $apiData['duration'];
                             $h = sprintf("%02d", intval($seconds) / 3600);
                             $tmp = $seconds % 3600;
                             $m = sprintf("%02d", $tmp / 60);
                             $s = sprintf("%02d", $tmp % 60);
                             $data['video']['apiID'] = $apiData['id'];
                             $data['video']['apiTitle'] = $apiData['title'];
                             $data['video']['apiDescription'] = $apiData['description'];
                             $data['video']['apiRegDate'] = $apiData['upload_date'];
                             $data['video']['apiThumb']['s'] = $apiData['thumbnails']->thumbnail[1]->_content;
                             $data['video']['apiThumb']['l'] = $apiData['thumbnails']->thumbnail[2]->_content;
                             $data['video']['apiDuration'] = $h . ':' . $m . ':' . $s;
                             $data['video']['apiViewCount'] = $apiData['number_of_plays'];
                             $data['video']['apiLikeCount'] = $apiData['number_of_likes'];
                         }
                         echo json_encode($data);
                     }
                 }
             }
         } else {
             if ($params['ctType'] == "YOUTUBE") {
                 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                  *  Youtube 카테고리 Data 를 Json 으로 생성
                  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                 if ($params['mode'] == "videoCateUpdate") {
                     $url = 'https://gdata.youtube.com/feeds/api/users/gbsafrica/playlists?v=2&alt=json&max-results=50';
                     $contents = file_get_contents($url);
                     $videos = json_decode($contents);
                     $idx = 0;
                     foreach ($videos->feed->entry as $value) {
                         $apiData[$idx]['title'] = $value->{'title'}->{'$t'};
                         $apiData[$idx++]['playlistId'] = $value->{'yt$playlistId'}->{'$t'};
                     }
                     $data = json_encode($apiData);
                     write_file('./assets/json/youtube/youtube_cate.json', $data);
                     redirect(base_url("/adm/content/index"));
                     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                      *  Youtube 컨텐츠 Data 를 Json 으로 생성
                      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                 } else {
                     if ($params['mode'] == "videoContentUpdate") {
                         $url = "./assets/json/youtube/youtube_cate.json";
                         $contents = file_get_contents($url);
                         $cate = json_decode($contents);
                         foreach ($cate as $val) {
                             $idx = 0;
                             $start_index = 1;
                             $max_results = 50;
                             while (true) {
                                 $url = 'https://gdata.youtube.com/feeds/api/playlists/' . $val->playlistId . '?v=2&alt=json&max-results=' . $max_results . '&start-index=' . $start_index;
                                 //                  $url = 'https://gdata.youtube.com/feeds/api/playlists/PL2468E4A9108D8F5B?v=2&alt=json&max-results='.$max_results.'&start-index='.$start_index;
                                 $contents = file_get_contents($url);
                                 $videos = json_decode($contents);
                                 foreach ($videos->feed->entry as $value) {
                                     $apiData[$idx]['title'] = $value->{'media$group'}->{'media$title'}->{'$t'};
                                     $apiData[$idx++]['playlistId'] = $value->{'media$group'}->{'yt$videoid'}->{'$t'};
                                 }
                                 $crStartIndex = $videos->{'feed'}->{'openSearch$startIndex'};
                                 $crPerPage = $videos->{'feed'}->{'openSearch$itemsPerPage'};
                                 $crTotalResult = $videos->{'feed'}->{'openSearch$totalResults'};
                                 if ((int) ($crStartIndex + $crPerPage) - 1 > $crTotalResult) {
                                     break;
                                 }
                                 $start_index += $max_results;
                             }
                             $data = json_encode($apiData);
                             write_file('./assets/json/youtube/' . $val->playlistId . '.json', $data);
                             unset($apiData);
                         }
                         redirect(base_url("/adm/content/index"));
                         /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                          *  Youtube API 를 이용하여 컨텐츠의 데이터를 가져옴
                          *  Api 에서 제공하는 영상 재생 시간은 초 단위로 받기 때문에 시:분:초 형태로 변경함
                          * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                     } else {
                         if ($params['mode'] == "getApiInfo") {
                             $url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=' . $params['ctSource'] . '&fields=items&key=AIzaSyBeMZu_8m8NXoVqlU1r5DSOIhKSV04DKHo';
                             $contents = file_get_contents($url);
                             /*$ch = curl_init();
                             
                             				curl_setopt($ch, CURLOPT_URL, $url);
                             				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                             				curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                             				$contents = curl_exec($ch);
                             				curl_close($ch);*/
                             $video = json_decode($contents)->items;
                             foreach ($video[0] as $k => $v) {
                                 $apiData[$k] = $v;
                             }
                             if ($apiData['snippet']) {
                                 $duration = $apiData['contentDetails']->{'duration'};
                                 $temp = explode('PT', $duration);
                                 if (strpos($temp[1], 'H')) {
                                     $h = explode('H', $temp[1]);
                                     if ($h[0] < 10) {
                                         $h[0] = '0' . $h[0];
                                     }
                                     if (strpos($temp[1], 'M')) {
                                         $m = explode('M', $h[1]);
                                         if ($m[0] < 10) {
                                             $m[0] = '0' . $m[0];
                                         }
                                         if (strpos($temp[1], 'S')) {
                                             $s = explode('S', $m[1]);
                                         }
                                     } else {
                                         $m[0] = '00';
                                         if (strpos($temp[1], 'S')) {
                                             $s = explode('S', $temp[1]);
                                         }
                                     }
                                 } else {
                                     $h[0] = '00';
                                     if (strpos($temp[1], 'M')) {
                                         $m = explode('M', $temp[1]);
                                         if ($m[0] < 10) {
                                             $m[0] = '0' . $m[0];
                                         }
                                         if (strpos($temp[1], 'S')) {
                                             $s = explode('S', $m[1]);
                                         }
                                     } else {
                                         $m[0] = '00';
                                         if (strpos($temp[1], 'S')) {
                                             $s = explode('S', $temp[1]);
                                         }
                                     }
                                 }
                                 $data['video']['apiID'] = $apiData['id'];
                                 $data['video']['apiTitle'] = $apiData['snippet']->{'title'};
                                 $data['video']['apiDescription'] = $apiData['snippet']->{'description'};
                                 $data['video']['apiRegDate'] = $apiData['snippet']->{'publishedAt'};
                                 $data['video']['apiThumb']['s'] = $apiData['snippet']->{'thumbnails'}->{'medium'}->{'url'};
                                 $data['video']['apiThumb']['l'] = $apiData['snippet']->{'thumbnails'}->{'high'}->{'url'};
                                 $data['video']['apiDuration'] = $h[0] . ':' . $m[0] . ':' . $s[0];
                                 $data['video']['apiViewCount'] = 0;
                                 $data['video']['apiLikeCount'] = 0;
                             }
                             echo json_encode($data);
                         }
                     }
                 }
             }
         }
     }
 }