/** * Get additional content data selected * * @param $result = Query result */ public static function post_find($result) { if ($result !== null) { if (is_array($result)) { foreach ($result as $item) { // It will first check if we already have result in temporary result, // and only execute query if we dont. That way we dont have duplicate queries // Get video parent $item->get_parent = static::lazy_load(function () use($item) { return Model_Application::find_one_by_id($item->content_id); }, $item->id, 'parent', 'object'); // Get video details $item->get_youtube = static::lazy_load(function () use($item) { $object = new \stdClass(); $youtube = \App\Youtube::forge(); $object->data = $youtube->parse($item->url)->get(); $object->embed = $youtube->embed($item->url); return $object; }, $item->id, 'youtube', 'object'); } } } // return the result return $result; }
if (!\Config::get('details.video.required', false) && !empty($product->videos) || count($product->videos) > 1) { ?> <th scope="col" class="center">Delete</th> <?php } ?> </tr> <?php if (is_array($product->videos)) { ?> <?php foreach ($product->videos as $video) { ?> <?php $youtube = \App\Youtube::forge(); $video->details = $youtube->parse($video->url)->get(); ?> <tr id="sort_<?php echo $video->id . '_' . $video->sort; ?> "> <td class="center noresize video_thumbnail"> <?php if ($video->thumbnail) { ?> <img src="<?php echo \Uri::create('media/videos/' . $video->thumbnail); ?> " class="default" width="80"/> <div style="margin-top: 5px; position: relative;">
/** * Edit product hotspot position * * @param $content_id = Content ID * @param $infotab_id = Infotab ID * */ public function action_hotspot($content_id = false, $hotspot_id = false) { // Check for product if (!is_numeric($content_id)) { \Response::redirect('admin/application/list'); } // Get news item to edit if (!($content = Model_Application::find_one_by_id($content_id))) { \Response::redirect('admin/application/list'); } // Get hotspot is exist if (is_numeric($hotspot_id)) { if (!($hotspot = Model_Application_Image::find_by_pk($hotspot_id))) { unset($hotspot); } } if (\Input::post()) { $insert = \Input::post(); if (!\Input::is_ajax()) { $val = Model_Application_Image::validate('create'); if (!$val->run()) { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create hotspot</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } \Response::redirect(\Uri::create('admin/application/hotspot/show/' . $content->id . (isset($hotspot) ? '/' . $hotspot->id : ''))); } $insert['title'] = trim($insert['title']) != '' ? $insert['title'] : NULL; $insert['description'] = trim($insert['description']) != '' ? $insert['description'] : NULL; } $insert['application_id'] = $content->id; if (\Input::post('create', false)) { $hotspot = Model_Application_Image::forge($insert); try { $hotspot->save(); if (\Input::is_ajax()) { $return['hotspot_id'] = $hotspot->id; echo json_encode($return); exit; } } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create hotspot</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); if (\Input::is_ajax()) { $return['message'] = \Messages::display(); $return['hotspot_id'] = false; echo json_encode($return); exit; } } } if (\Input::post('update', false)) { if (isset($hotspot)) { /** IMAGES **/ // Upload image and display errors if there are any $image = $this->upload_infotab_image(); if (!$image['exists'] && \Config::get('infotab.image.required', false) && empty($hotspot->image)) { // No previous images and image is not selected and it is required \Messages::error('<strong>There was an error while trying to upload hotspot image</strong>'); \Messages::error('You have to select image'); } elseif ($image['errors']) { \Messages::error('<strong>There was an error while trying to upload hotspot image</strong>'); foreach ($image['errors'] as $error) { \Messages::error($error); } } if ($image['is_valid'] && !(!$image['exists'] && \Config::get('infotab.image.required', false) && empty($hotspot->image)) || \Input::post('use_cover_image', false)) { // Clear previous messages if exists \Messages::reset(); $item_image['alt_text'] = \Input::post('alt_text', false) ? \Input::post('alt_text', false) : NULL; // Save images if new files are submitted if (isset($this->_infotab_image_data)) { foreach ($this->_infotab_image_data as $image_data) { $item_image['image'] = $image_data['saved_as']; // Delete old infotab image if (\Input::post('image_db', false)) { $this->delete_infotab_image(\Input::post('image_db', '')); } } } if (isset($item_image)) { $insert['alt_text'] = isset($item_image['alt_text']) ? $item_image['alt_text'] : NULL; $insert['image'] = isset($item_image['image']) ? $item_image['image'] : $hotspot->image; } } else { // Delete uploaded images if there is product saving error if (isset($this->_infotab_image_data)) { foreach ($this->_infotab_image_data as $image_data) { $this->delete_infotab_image($image_data['saved_as']); } } } /** END OF IMAGES **/ /** VIDEOS **/ $item_video['video_title'] = \Input::post('video_title', false) ? \Input::post('video_title', false) : NULL; $item_video['video'] = \Input::post('video_url', false) ? \Input::post('video_url', false) : NULL; if (!is_null($item_video['video'])) { // Check video $youtube = \App\Youtube::forge(); $video = $youtube->parse($item_video['video'])->get(); if (!$video) { \Messages::error('"' . $item_video['video'] . '" is invalid video URL. Video not updated.'); // Revert to old values $item_video['video_title'] = $hotspot->video_title; $item_video['video'] = $hotspot->video; } } if (isset($item_video)) { $insert['video'] = isset($item_video['video']) ? $item_video['video'] : NULL; $insert['video_title'] = isset($item_video['video_title']) ? $item_video['video_title'] : NULL; // Unset video title is there is no video if (is_null($insert['video'])) { $insert['video_title'] = NULL; } } /** END OF: VIDEOS **/ $hotspot->set($insert); try { $hotspot->save(); \Messages::success('Hotspot sucessfully updated.'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('There was an error while trying to update hotspot.'); \Messages::error('Please try again.'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); // Delete uploaded images if there is product saving error if (isset($this->_infotab_image_data)) { foreach ($this->_infotab_image_data as $image_data) { $this->delete_infotab_image($image_data['saved_as']); } } } if (\Input::is_ajax()) { echo \Messages::display(); exit; } } } } \Response::redirect(\Uri::create('admin/application/hotspot/show/' . $content->id . (isset($hotspot) ? '/' . $hotspot->id : ''))); }
public function action_update_files($id = false) { if (!is_numeric($id)) { \Response::redirect('admin/application/list'); } // Get news item to edit if (!($item = Model_Application::find_one_by_id($id))) { \Response::redirect('admin/application/list'); } \View::set_global('title', 'Edit Application Files'); if (\Input::post()) { if (\Input::post('file_upload', false)) { // Upload files and display errors if there are any $file = $this->upload_file(); if (!$file['exists'] && \Config::get('details.image.required', false) && empty($item->images)) { // No previous images and image is not selected and it is required \Messages::error('<strong>There was an error while trying to upload content file</strong>'); \Messages::error('You have to select image'); } elseif ($file['errors']) { \Messages::error('<strong>There was an error while trying to upload content file</strong>'); foreach ($file['errors'] as $error) { \Messages::error($error); } } if ($file['is_valid'] && !(!$file['exists'] && \Config::get('details.file.required', false) && empty($item->files))) { /** FILES **/ // Get all alt texts to update if there is no image change foreach (\Arr::filter_prefixed(\Input::post(), 'title_') as $file_id => $title) { if (strpos($file_id, 'new_') === false) { $item_files[$file_id] = array('id' => $file_id, 'data' => array('title' => \Input::post('title_' . $file_id, ''))); } } // Save files if new ones are submitted if (isset($this->_file_data)) { foreach ($this->_file_data as $file_data) { $cover_count = count($item->files); if (strpos($file_data['field'], 'new_') === false) { // Update existing file if (str_replace('file_', '', $file_data['field']) != 0) { $file_id = (int) str_replace('file_', '', $file_data['field']); $cover_count--; $item_files[$file_id] = array('id' => $file_id, 'data' => array('content_id' => $item->id, 'file' => $file_data['saved_as'], 'title' => \Input::post('title_' . $file_id, ''))); $this->delete_file(\Input::post('file_db_' . $file_id, '')); } } else { // Save new file $file_tmp = str_replace('file_new_', '', $file_data['field']); $item_files[0] = array('id' => 0, 'data' => array('content_id' => $item->id, 'file' => $file_data['saved_as'], 'title' => \Input::post('title_new_' . $file_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1)); } } } Model_Application::bind_files($item_files); \Messages::success('Application documents successfully updated.'); \Response::redirect(\Uri::admin('current')); /** END OF FILES **/ } else { // Delete uploaded files if there is application saving error if (isset($this->_file_data)) { foreach ($this->_file_data as $file_data) { $this->delete_file($file_data['saved_as']); } } \Messages::error('<strong>There was an error while trying to update application documents</strong>'); } } if (\Input::post('video_upload', false)) { // Upload image and display errors if there are any $image = $this->upload_image('video'); if ($image['errors']) { \Messages::error('<strong>There was an error while trying to upload content image</strong>'); foreach ($image['errors'] as $error) { \Messages::error($error); } } if ($image['is_valid'] && !(\Config::get('details.video.required', false) && empty($item->videos))) { /** VIDEOS **/ // Get all video urls to update if there is no image change foreach (\Arr::filter_prefixed(\Input::post(), 'video_url_') as $video_id => $url) { $not_updated[] = $video_id; if (strpos($video_id, 'new_') === false) { $video_url = \Input::post('video_url_' . $video_id, false); if ($video_url) { // Check video $youtube = \App\Youtube::forge(); $video = $youtube->parse(\Input::post('video_url_' . $video_id, ''))->get(); if ($video) { // Update existing videos $item_videos[$video_id] = array('id' => $video_id, 'data' => array('content_id' => $item->id, 'url' => \Input::post('video_url_' . $video_id, ''), 'title' => \Input::post('video_title_' . $video_id, ''))); // Remove video ID as it is updated correctly array_pop($not_updated); // Delete image and use default one if (\Input::post('video_delete_image_' . $video_id, false)) { $item_videos[$video_id]['data']['thumbnail'] = ''; $this->delete_image(\Input::post('video_file_db_' . $video_id, ''), 'video'); } } else { \Messages::error('"' . \Input::post('video_url_' . $video_id, '') . '" is invalid video URL. Video not updated.'); } } else { \Messages::error('Video URL can\'t be empty. Video not updated.'); } } else { $video_url = \Input::post('video_url_' . $video_id, false); if ($video_url) { // Check video $youtube = \App\Youtube::forge(); $video = $youtube->parse(\Input::post('video_url_' . $video_id, ''))->get(); if ($video) { // Add new videos $item_videos[0] = array('id' => 0, 'data' => array('content_id' => $item->id, 'url' => \Input::post('video_url_' . $video_id, ''), 'title' => \Input::post('video_title_' . $video_id, ''), 'sort' => count($item->videos) + 1)); // Remove video ID as it is updated correctly array_pop($not_updated); } else { \Messages::error('"' . \Input::post('video_url_' . $video_id, '') . '" is invalid video URL. Video not updated.'); } } } } // Save images if new files are submitted if (isset($this->_image_data)) { foreach ($this->_image_data as $image_data) { if (!in_array(str_replace('video_file_', '', $image_data['field']), $not_updated)) { if (strpos($image_data['field'], 'new_') === false) { // Update existing image if (str_replace('video_file_', '', $image_data['field']) != 0) { $video_id = (int) str_replace('video_file_', '', $image_data['field']); $item_videos[$video_id]['data']['thumbnail'] = $image_data['saved_as']; $this->delete_image(\Input::post('video_file_db_' . $video_id, ''), 'video'); } } else { // Save new image $image_tmp = str_replace('video_file_new_', '', $image_data['field']); $item_videos[0]['data']['thumbnail'] = $image_data['saved_as']; } } else { // That video was not updated so we remove its image if there is one $this->delete_image($image_data['saved_as'], 'video'); } } } Model_Application::bind_videos($item_videos); \Messages::success('Application videos successfully updated.'); \Response::redirect(\Uri::admin('current')); /** END OF VIDEOS **/ } else { // Delete uploaded images if there is application saving error if (isset($this->_image_data)) { foreach ($this->_image_data as $image_data) { $this->delete_image($image_data['saved_as'], 'video'); } } \Messages::error('<strong>There was an error while trying to update application videos</strong>'); } } } \Theme::instance()->set_partial('content', $this->view_dir . 'update_files')->set('application', Model_Application::find_one_by_id($id)); }
public function action_video() { $url = \Input::post('url', false); $return['response'] = false; if ($url) { $youtube = \App\Youtube::forge(); $video = $youtube->parse($url)->get(); if (isset($video) && $video) { $return['response'] = $video; \Messages::success('Video found! Please check found data'); } else { \Messages::error('Please check video URL and try again.'); } } else { \Messages::info('Please insert video URL'); } $return['message'] = \Messages::display('left', false); echo json_encode($return); exit; }