Ejemplo n.º 1
0
 /**
  * Method to display import event form
  * 	 
  **/
 public function import()
 {
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = JRequest::getCmd('view', $this->getName());
     $view = $this->getView($viewName, '', $viewType);
     $events = array();
     $mainframe =& JFactory::getApplication();
     $config = CFactory::getConfig();
     if (!$config->get('event_import_ical')) {
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events', false), JText::_('COM_COMMUNITY_EVENTS_IMPORT_DISABLED'), 'error');
     }
     if (JRequest::getMethod() == 'POST') {
         $type = JRequest::getVar('type', 'file');
         $valid = false;
         if ($type == 'file') {
             $file = JRequest::getVar('file', '', 'FILES');
             $valid = $file['type'] == 'text/calendar' || $file['type'] == 'application/octet-stream';
             $path = $file['tmp_name'];
             if ($valid && JFile::exists($path)) {
                 $contents = JFile::read($path);
             }
         }
         if ($type == 'url') {
             CFactory::load('helpers', 'remote');
             $file = JRequest::getVar('url', '');
             $contents = CRemoteHelper::getContent($file, true);
             preg_match('/Content-Type: (.*)/im', $contents, $matches);
             $valid = isset($matches[1]) && stripos(JString::trim($matches[1]), 'text/calendar') !== false;
         }
         CFactory::load('libraries', 'ical');
         $ical = new CICal($contents);
         if ($ical->init() && $valid) {
             $events = $ical->getItems();
         } else {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=import', false), JText::_('Unable to load .ics file'), 'error');
         }
     }
     echo $view->get(__FUNCTION__, $events);
 }
Ejemplo n.º 2
0
 /**
  * Method to display import event form
  *
  * */
 public function import()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $viewName = $jinput->get('view', $this->getName(), 'String');
     $view = $this->getView($viewName, '', $viewType);
     $events = array();
     $config = CFactory::getConfig();
     $groupId = $jinput->get->get('groupid', 0, 'Int');
     $groupLink = $groupId > 0 ? '&groupid=' . $groupId : '';
     $my = CFactory::getUser();
     if (!$config->get('event_import_ical')) {
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events' . $groupLink, false), JText::_('COM_COMMUNITY_EVENTS_IMPORT_DISABLED'), 'error');
     }
     if (!$my->canCreateEvents()) {
         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events' . $groupLink, false), JText::_('COM_COMMUNITY_EVENTS_IMPORT_DISABLED'), 'error');
     }
     if ($jinput->getMethod() == 'POST') {
         CFactory::load('libraries', 'ical');
         $type = $jinput->get('type', 'file', 'NONE');
         $valid = false;
         if ($type == 'file') {
             $fileFilter = new JInput($_FILES);
             $file = $fileFilter->get('file', '', 'array');
             $valid = $file['type'] == 'text/calendar' || $file['type'] == 'application/octet-stream';
             $path = $file['tmp_name'];
             if ($valid && JFile::exists($path)) {
                 $contents = JFile::read($path);
             }
             $icalParser = new ICal($path);
         }
         if ($type == 'url') {
             //CFactory::load( 'helpers' , 'remote' );
             $file = $jinput->get('url', '', 'STRING');
             $contents = CRemoteHelper::getContent($file, true);
             preg_match('/Content-Type: (.*)/im', $contents, $matches);
             $valid = isset($matches[1]) && stripos(JString::trim($matches[1]), 'text/calendar') !== false;
             $icalParser = new ICal($file);
         }
         $ical = new CICal($contents);
         if ($ical->init() && $valid) {
             $events = $ical->getItems();
         } else {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=import' . $groupLink, false), JText::_('Unable to load .ics file'), 'error');
         }
     }
     $data['events'] = $events;
     if (isset($icalParser)) {
         $data['icalParser'] = $icalParser;
     }
     echo $view->get(__FUNCTION__, $data);
 }