Пример #1
0
 function ytbupload()
 {
     JRequest::checkToken() or jexit('Invalid Token');
     jimport('joomla.client.helper');
     $app = JFactory::getApplication();
     $ftp = JClientHelper::setCredentialsFromRequest('ftp');
     $user = JFactory::getUser();
     $path = PhocaGalleryPath::getPath();
     $return = $this->input->get('return-url', null, 'base64');
     $format = $this->input->get('format', 'html', 'cmd');
     $viewBack = $this->input->get('viewback', '', 'string');
     $tab = $this->input->get('tab', 0, 'int');
     $catid = $this->input->get('id', '', 'string');
     $rating = $this->input->get('rating', '', 'string');
     $Itemid = $this->input->get('Itemid', 0, 'int');
     $limitStart = $this->input->get('limitstart', 0, 'int');
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $catid = (int) $catid;
     if ((int) $catid < 1) {
         $app->redirect($redirectUrl, JText::_('COM_PHOCAGALLERY_PLEASE_SELECT_CATEGORY'));
         return false;
     }
     $catidAlias = $catid;
     // for return
     // Set the limistart (TODO)
     if ($limitStart > 0) {
         $limitStartUrl = '&limitstart=' . $limitStart;
     } else {
         $limitStartUrl = '';
     }
     $return = JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $catidAlias . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false);
     $redirectUrl = $return;
     $model = $this->getModel('category');
     // USER RIGHT - UPLOAD - - - - - - - - - - -
     // 2, 2 means that user access will be ignored in function getUserRight for display Delete button
     $rightDisplayUpload = 0;
     $catAccess = PhocaGalleryAccess::getCategoryAccess((int) $catid);
     if (!empty($catAccess)) {
         $rightDisplayUpload = PhocaGalleryAccess::getUserRight('uploaduserid', $catAccess->uploaduserid, 2, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
     }
     // - - - - - - - - - - - - - - - - - - - - - -
     // USER RIGHT - FOLDER - - - - - - - - - - - -
     $rightFolder = '';
     if (isset($catAccess->userfolder)) {
         $rightFolder = $catAccess->userfolder;
     }
     // - - - - - - - - - - - - - - - - - - - - - -
     if ($rightDisplayUpload == 1) {
         if ($rightFolder == '') {
             $errUploadMsg = JText::_('COM_PHOCAGALLERY_USER_FOLDER_NOT_DEFINED');
             $app->redirect($redirectUrl, $errUploadMsg);
             return false;
         }
         if (!JFolder::exists($path->image_abs . $rightFolder . DS)) {
             $errUploadMsg = JText::_('COM_PHOCAGALLERY_USER_FOLDER_NOT_EXISTS');
             $app->redirect($redirectUrl, $errUploadMsg);
             return false;
         }
         // Sending and setting data for common realsingleupload function
         $this->input->set('folder', $rightFolder);
         //Set the right path for uploaded image (category folder included)
         $this->input->set('return-url', base64_encode($return));
         // set return url
         //$fileName = PhocaGalleryFileUpload::realSingleUpload(2);
         $ytbLink = $this->input->get('phocagalleryytbuploadlink', '', 'string');
         $errorYtbMsg = '';
         $ytbData = PhocaGalleryYoutube::importYtb($ytbLink, $rightFolder . DS, $errorYtbMsg);
         if ($ytbData && isset($ytbData['filename'])) {
             if (PhocaGalleryControllerCategory::save((int) $catid, $ytbData['filename'], $return, $succeeded, $errUploadMsg, false, $ytbData)) {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return true;
             } else {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return false;
             }
         } else {
             $app->redirect($redirectUrl, $errorYtbMsg);
             return false;
         }
         if ($fileName != '') {
             // Saving file name into database with relative path
             $fileName = $rightFolder . '/' . strtolower($fileName);
             if (PhocaGalleryControllerUser::save((int) $catid, $fileName, $return, $succeeded, $errUploadMsg, false)) {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return true;
             } else {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return false;
             }
         }
     } else {
         $errUploadMsg = JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION');
         $app->redirect($this->_loginurl, JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION'));
         return false;
     }
 }
Пример #2
0
 function import()
 {
     JRequest::checkToken() or die('Invalid Token');
     $app = JFactory::getApplication();
     //$post	= JRequest::get('post');
     $ytb_link = JRequest::getVar('ytb_link', '', 'post', 'string', JREQUEST_NOTRIM);
     $field = JRequest::getVar('field', '', 'post', 'string', JREQUEST_NOTRIM);
     $catid = JRequest::getVar('catid', 0, 'post', 'int');
     $folder = '';
     if ((int) $catid > 0) {
         $db = JFactory::getDBO();
         $query = 'SELECT c.userfolder' . ' FROM #__phocagallery_categories AS c' . ' WHERE c.id = ' . $db->Quote((int) $catid);
         $db->setQuery($query, 0, 1);
         $folderObj = $db->loadObject();
         if (!$db->query()) {
             $this->setError($db->getErrorMsg());
             return false;
         }
         if (isset($folderObj->userfolder) && $folderObj->userfolder != '') {
             $folder = $folderObj->userfolder . '/';
             // Save to category folder
         } else {
             $folder = '';
             // No category folder - save to root
         }
     } else {
         $errorMsg .= JText::_('COM_PHOCAGALLERY_YTB_ERROR_NO_CATEGORY');
     }
     $ytb = PhocaGalleryYoutube::importYtb($ytb_link, $folder, $errorYtbMsg);
     /*		
     		$ytb_code 	= str_replace("&feature=related","",PhocaGalleryYoutube::getCode(strip_tags($ytb_link)));
     
     		$msg = $errorMsg = '';
     		$ytb				= array();
     		$ytb['title']		= '';
     		$ytb['desc']		= '';
     		$ytb['filename']	= '';
     		$ytb['link']		= strip_tags($ytb_link);
     			
     		if(!function_exists("curl_init")){
     			$errorMsg .= JText::_('COM_PHOCAGALLERY_YTB_NOT_LOADED_CURL');
     		} else if ($ytb_code == '') {
     			$errorMsg .= JText::_('COM_PHOCAGALLERY_YTB_URL_NOT_CORRECT');
     		} else {
     			
     			$folder = '';
     			if ((int)$catid > 0) {
     				$db =JFactory::getDBO();
     				$query = 'SELECT c.userfolder'
     				.' FROM #__phocagallery_categories AS c'
     				.' WHERE c.id = '.$db->Quote((int)$catid);
     
     				$db->setQuery($query, 0, 1);
     				$folderObj = $db->loadObject();
     				
     				if (!$db->query()) {
     					$this->setError($db->getErrorMsg());
     					return false;
     				}
     				
     				if (isset($folderObj->userfolder) && $folderObj->userfolder != '') {
     					$folder = $folderObj->userfolder . '/';// Save to category folder
     				} else {
     					$folder = '';// No category folder - save to root
     				}
     			} else {
     				$errorMsg .= JText::_('COM_PHOCAGALLERY_YTB_ERROR_NO_CATEGORY');
     			}
     			
     			// Data
     			$cUrl		= curl_init("http://gdata.youtube.com/feeds/api/videos/".strip_tags($ytb_code));
                 curl_setopt($cUrl,CURLOPT_RETURNTRANSFER,1);
                 $xml		= curl_exec($cUrl);
                 curl_close($cUrl);
     			
     			$xml 	= str_replace('<media:', '<phcmedia', $xml);
     			$xml 	= str_replace('</media:', '</phcmedia', $xml);
     			
     			$data 	= JFactory::getXML($xml, false);
     
     			//Title			
     			if (isset($data->title)) {
     				$ytb['title'] = (string)$data->title;
     			}
     			
     			if ($ytb['title'] == '' && isset($data->phcmediagroup->phcmediatitle)) {
     				$ytb['title'] = (string)$data->phcmediagroup->phcmediatitle;
     			}
     			
     			if (isset($data->phcmediagroup->phcmediadescription)) {
     				$ytb['desc'] = (string)$data->phcmediagroup->phcmediadescription;
     			}
     			
     			// Thumbnail
     			if (isset($data->phcmediagroup->phcmediathumbnail[0]['url'])) {
     				$cUrl		= curl_init(strip_tags((string)$data->phcmediagroup->phcmediathumbnail[0]['url']));
     				curl_setopt($cUrl,CURLOPT_RETURNTRANSFER,1);
     				$img		= curl_exec($cUrl);
     				curl_close($cUrl);
     			}
                 	
     			if ($img != '') {
     				$cUrl		= curl_init("http://img.youtube.com/vi/".strip_tags($ytb_code)."/0.jpg");
     				curl_setopt($cUrl,CURLOPT_RETURNTRANSFER,1);
     				$img		= curl_exec($cUrl);
     				curl_close($cUrl);
     			}
     	
     			$ytb['filename']	= $folder.strip_tags($ytb_code).'.jpg';
     			
                 if (!JFile::write(JPATH_ROOT . DS . 'images' . DS . 'phocagallery' . DS . $ytb['filename'], $img)) {
     				$errorMsg .= JText::_('COM_PHOCAGALLERY_YTB_ERROR_WRITE_IMAGE');
     			}
     		}*/
     JRequest::setVar('ytb_title', $ytb['title']);
     JRequest::setVar('ytb_desc', $ytb['desc']);
     JRequest::setVar('ytb_filename', $ytb['filename']);
     JRequest::setVar('ytb_link', $ytb['link']);
     if ($errorMsg != '') {
         $msg = $errorMsg;
         $import = '';
     } else {
         $msg = JText::_('COM_PHOCAGALLERY_YTB_SUCCESS_IMPORT');
         $import = '&import=1';
         $app->getUserStateFromRequest($this->context . '.ytb_title', 'ytb_title', $ytb['title'], 'string');
         $app->getUserStateFromRequest($this->context . '.ytb_desc', 'ytb_desc', $ytb['desc'], 'string');
         $app->getUserStateFromRequest($this->context . '.ytb_filename', 'ytb_filename', $ytb['filename'], 'string');
         $app->getUserStateFromRequest($this->context . '.ytb_link', 'ytb_link', $ytb['link'], 'string');
     }
     $redirect = 'index.php?option=com_phocagallery&view=phocagalleryytb&tmpl=component&field=' . $field . '&catid=' . (int) $catid . $import;
     $this->setRedirect($redirect, $msg);
 }
Пример #3
0
 function ytbupload()
 {
     jimport('joomla.client.helper');
     $app = JFactory::getApplication();
     $ftp = JClientHelper::setCredentialsFromRequest('ftp');
     $user = JFactory::getUser();
     $path = PhocaGalleryPath::getPath();
     //$folder		= JRequest::getVar( 'folder', '', '', 'path' );
     $tab = JRequest::getVar('tab', 0, '', 'int');
     $format = JRequest::getVar('format', 'html', '', 'cmd');
     $return = JRequest::getVar('return-url', null, 'post', 'base64');
     $viewBack = JRequest::getVar('viewback', '', '', '');
     $catid = JRequest::getVar('catid', '', '', 'int');
     $Itemid = JRequest::getVar('Itemid', 0, '', 'int');
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $limitStartUrl = $this->getLimitStartUrl(0, 'subcat');
     $return = JRoute::_($this->_url . $limitStartUrl->subcat . $limitStartUrl->image, false);
     $redirectUrl = $return;
     if ((int) $catid < 1) {
         $app->redirect($redirectUrl, JText::_('COM_PHOCAGALLERY_PLEASE_SELECT_CATEGORY'));
         return false;
     }
     // Get user catid, we are not in the category, so we must find the catid
     $model = $this->getModel('user');
     $isOwnerCategory = $model->isOwnerCategory($this->_user->id, $catid);
     if (!$isOwnerCategory) {
         $app->redirect($this->_loginurl, JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION'));
         return false;
     }
     // USER RIGHT - UPLOAD - - - - - - - - - - -
     // 2, 2 means that user access will be ignored in function getUserRight for display Delete button
     $rightDisplayUpload = 0;
     $catAccess = PhocaGalleryAccess::getCategoryAccess((int) $catid);
     if (!empty($catAccess)) {
         $rightDisplayUpload = PhocaGalleryAccess::getUserRight('uploaduserid', $catAccess->uploaduserid, 2, $user->authorisedLevels(), $user->get('id', 0), 0);
     }
     // - - - - - - - - - - - - - - - - - - - - - -
     // USER RIGHT - FOLDER - - - - - - - - - - - -
     $rightFolder = '';
     if (isset($catAccess->userfolder)) {
         $rightFolder = $catAccess->userfolder;
     }
     // - - - - - - - - - - - - - - - - - - - - - -
     if ($rightDisplayUpload == 1) {
         if ($rightFolder == '') {
             $errUploadMsg = JText::_('COM_PHOCAGALLERY_USER_FOLDER_NOT_DEFINED');
             $app->redirect($redirectUrl, $errUploadMsg);
             return false;
         }
         if (!JFolder::exists($path->image_abs . $rightFolder . DS)) {
             $errUploadMsg = JText::_('COM_PHOCAGALLERY_USER_FOLDER_NOT_EXISTS');
             $app->redirect($redirectUrl, $errUploadMsg);
             return false;
         }
         // Sending and setting data for common realsingleupload function
         JRequest::setVar('folder', $rightFolder);
         //Set the right path for uploaded image (category folder included)
         JRequest::setVar('return-url', base64_encode($return));
         // set return url
         //$fileName = PhocaGalleryFileUpload::realSingleUpload(2);
         $ytbLink = JRequest::getVar('phocagalleryytbuploadlink', '', 'post', 'string', JREQUEST_NOTRIM);
         $errorYtbMsg = '';
         $ytbData = PhocaGalleryYoutube::importYtb($ytbLink, $rightFolder . DS, $errorYtbMsg);
         if ($ytbData && isset($ytbData['filename'])) {
             if (PhocaGalleryControllerUser::save((int) $catid, $ytbData['filename'], $return, $succeeded, $errUploadMsg, false, $ytbData)) {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return true;
             } else {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return false;
             }
         } else {
             $app->redirect($redirectUrl, $errorYtbMsg);
             return false;
         }
         if ($fileName != '') {
             // Saving file name into database with relative path
             $fileName = $rightFolder . '/' . strtolower($fileName);
             if (PhocaGalleryControllerUser::save((int) $catid, $fileName, $return, $succeeded, $errUploadMsg, false)) {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return true;
             } else {
                 $app->redirect($redirectUrl, $errUploadMsg);
                 return false;
             }
         }
     } else {
         $errUploadMsg = JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION');
         $app->redirect($this->_loginurl, JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION'));
         return false;
     }
 }