Example #1
0
<?php

/**
 * @package JEM
 * @subpackage JEM - Module-Basic
 * @copyright (C) 2013-2015 joomlaeventmanager.net
 * @copyright (C) 2005-2009 Christoph Lukes
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */
defined('_JEXEC') or die;
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_jem/models', 'JemModel');
require_once JPATH_SITE . '/components/com_jem/helpers/helper.php';
// perform cleanup if it wasn't done today (archive, trash)
JEMHelper::cleanup();
/**
 * Module-Basic
 */
abstract class modJEMHelper
{
    /**
     * Method to get the events
     *
     * @access public
     * @return array
     */
    public static function getList(&$params)
    {
        mb_internal_encoding('UTF-8');
        // Retrieve Eventslist model for the data
        $model = JModelLegacy::getInstance('Eventslist', 'JemModel', array('ignore_request' => true));
        // Set params for the model
Example #2
0
	/**
	 * Imports data from an old Eventlist installation
	 */
	public function eventlistImport()
	{
		$model = $this->getModel('import');
		$size = 5000;

		// Handling the different names for all classes and db table names (possibly substrings)
		// EL 1.0.2 doesn't have tables attachments and cats_event_descriptions
		// EL 1.1 has both tables but events doesn't contain field catsid
		// also the recurrence fields are different
		// And EL 1.1 runs on J! 1.5 only - which has different access level ids (fixed (0, 1, 2) instead of (1, 2, 3, ...))
		$tables = new stdClass();
		// Note: 'attachments' MUST be last entry!
		$tables->eltables  = array("categories", "events", "cats_event_relations", "groupmembers", "groups", "register", "venues", "attachments");
		$tables->jemtables = array("categories", "events", "cats_event_relations", "groupmembers", "groups", "register", "venues", "attachments");

		$app = JFactory::getApplication();
		$jinput = $app->input;
		$step = $jinput->get('step', 0, 'INT');
		$current = $jinput->get->get('current', 0, 'INT');
		$total = $jinput->get->get('total', 0, 'INT');
		$table = $jinput->get->get('table', 0, 'INT');
		$prefix = $app->getUserStateFromRequest('com_jem.import.elimport.prefix', 'prefix', '#__', 'cmd');
		$copyImages = $app->getUserStateFromRequest('com_jem.import.elimport.copyImages', 'copyImages', 0, 'int');
		$copyAttachments = $app->getUserStateFromRequest('com_jem.import.elimport.copyAttachments', 'copyAttachments', 0, 'int');
		$fromJ15 = $app->getUserStateFromRequest('com_jem.import.elimport.fromJ15', 'fromJ15', '0', 'int'); // import from Joomla! 1.5 site?

		$link = 'index.php?option=com_jem&view=import';
		$msg = JText::_('COM_JEM_IMPORT_EL_IMPORT_WORK_IN_PROGRESS')." ";

		if ($jinput->get('startToken', 0, 'INT') || ($step == 1)) {
			// Are the JEM tables empty at start? If no, stop import
			if ($model->getExistingJemData()) {
				$this->setRedirect($link);
				return;
			}
		}

		if ($step <= 1) {
			$app->setUserState('com_jem.import.elimport.copyImages', '0');
			$app->setUserState('com_jem.import.elimport.copyAttachments', '0');
			$app->setUserState('com_jem.import.elimport.fromJ15', '0');

			if ($step == 1) {
				$attachments = $model->getEventlistTableCount("eventlist_attachments") !== null;
				$app->setUserState('com_jem.import.elimport.attachmentsPossible', $attachments);
			}

			parent::display();
			return;
		} elseif ($step == 2) {
			// Special handling of cats_event_relations table which only exists on EL 1.1
			if (($tables->eltables[$table] == 'cats_event_relations')) {
				$tot = $model->getEventlistTableCount("eventlist_".$tables->eltables[$table]);
				if (!empty($tot)) {
					$total = $tot;
				} else {
					$tables->eltables[$table] = 'events';
				}
			}

			// Get number of rows if it is still 0 or we have moved to the next table
			if ($total == 0 || $current == 0) {
				$total = $model->getEventlistTableCount("eventlist_".$tables->eltables[$table]);
			}

			// If $total is null, the table does not exist, so we skip import for this table.
			if ($total == null) {
				// This helps to prevent special cases in the following code
				$total = 0;
			} else {
				// The real work is done here:
				// Loading from EL tables, changing data, storing in JEM tables
				$data = $model->getEventlistData("eventlist_".$tables->eltables[$table], $current, $size);
				$data = $model->transformEventlistData($tables->jemtables[$table], $data, $fromJ15);
				$model->storeJemData("jem_".$tables->jemtables[$table], $data);
			}

			// Proceed with next bunch of data
			$current += $size;

			// Current table is imported completely, proceed with next table
			if ($current > $total) {
				$table++;
				$current = 0;
			}

			// Check if table import is complete
			if ($current <= $total && $table < count($tables->eltables)) {
				// Don't add default prefix to link because of special character #
				if ($prefix == "#__") {
					$prefix = "";
				}

				$link .= '&step='.$step.'&table='.$table.'&current='.$current.'&total='.$total;
				//todo: we say "importing..." so we must show table of next step - but we don't know their entry count ($total).
				$msg .= JText::sprintf('COM_JEM_IMPORT_EL_IMPORT_WORKING_STEP_COPY_DB', $tables->jemtables[$table], $current, '?');
			} else {
				$step++;
				$link .= '&step='.$step;
				$msg .= JText::_('COM_JEM_IMPORT_EL_IMPORT_WORKING_STEP_REBUILD');
			}
		} elseif ($step == 3) {
			// We have to rebuild the hierarchy of the categories due to the plain database insertion
			JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.'/tables');
			$categoryTable = JTable::getInstance('Category', 'JemTable');
			$categoryTable->rebuild();
			$step++;
			$link .= '&step='.$step;
			if ($copyImages) {
				$msg .= JText::_('COM_JEM_IMPORT_EL_IMPORT_WORKING_STEP_COPY_IMAGES');
			} else {
				$msg .= JText::_('COM_JEM_IMPORT_EL_IMPORT_WORKING_STEP_COPY_IMAGES_SKIPPED');
			}
		} elseif ($step == 4) {
			// Copy EL images to JEM image destination?
			if ($copyImages) {
				$model->copyImages();
			}
			$step++;
			$link .= '&step='.$step;
			if ($copyAttachments) {
				$msg .= JText::_('COM_JEM_IMPORT_EL_IMPORT_WORKING_STEP_COPY_ATTACHMENTS');
		} else {
				$msg .= JText::_('COM_JEM_IMPORT_EL_IMPORT_WORKING_STEP_COPY_ATTACHMENTS_SKIPPED');
			}
		} elseif ($step == 5) {
			// Copy EL images to JEM image destination?
			if ($copyAttachments) {
				$model->copyAttachments();
			}
			$step++;
			$link .= '&step='.$step;
			$msg = JText::_('COM_JEM_IMPORT_EL_IMPORT_FINISHED');
		} else {
			// cleanup stored fields for users importing multiple time ;-)
			$app->setUserState('com_jem.import.elimport.prefix', null);
			$app->setUserState('com_jem.import.elimport.copyImages', null);
			$app->setUserState('com_jem.import.elimport.copyAttachments', null);
			$app->setUserState('com_jem.import.elimport.fromJ15', null);
			$app->setUserState('com_jem.import.elimport.attachmentsPossible', null);

			// perform forced cleanup (archive, delete, recurrence)
			JEMHelper::cleanup(true);

			$msg = JText::_('COM_JEM_IMPORT_EL_IMPORT_FINISHED');
		}

		$app->enqueueMessage($msg);
		$this->setRedirect($link);
	}
Example #3
0
	/**
	 * Triggerarchive + Recurrences
	 *
	 * @access public
	 * @return void
	 *
	 */
	function triggerarchive()
	{
		JEMHelper::cleanup(1);

		$link = 'index.php?option=com_jem&view=housekeeping';
		$msg = JText::_('COM_JEM_HOUSEKEEPING_AUTOARCHIVE_DONE');

		$this->setRedirect($link, $msg);
	}
Example #4
0
	/**
	 * Method to save the form data.
	 *
	 * @param $data array
	 */
	public function save($data)
	{
		// Variables
		$date        = JFactory::getDate();
		$app         = JFactory::getApplication();
		$jinput      = $app->input;
		$jemsettings = JEMHelper::config();
		$fileFilter  = new JInput($_FILES);
		$table       = $this->getTable();

		// Check if we're in the front or back
		$backend = (bool)$app->isAdmin();
		$new     = (bool)empty($data['id']);

		// Variables
		$cats             = $jinput->get('cid', array(), 'array');
		$recurrencenumber = $jinput->get('recurrence_number', '', 'int');
		$recurrencebyday  = $jinput->get('recurrence_byday', '', 'string');
		$metakeywords     = $jinput->get('meta_keywords', '', '');
		$metadescription  = $jinput->get('meta_description', '', '');
		$task             = $jinput->get('task', '', 'cmd');

		// event maybe first of recurrence set -> dissolve complete set
		if (JemHelper::dissolve_recurrence($data['id'])) {
			$this->cleanCache();
		}

		if ($data['dates'] == null || $data['recurrence_type'] == '0')
		{
			$data['recurrence_number']		= '';
			$data['recurrence_byday']		= '';
			$data['recurrence_counter'] 	= '';
			$data['recurrence_type']		= '';
			$data['recurrence_limit']		= '';
			$data['recurrence_limit_date']	= '';
			$data['recurrence_first_id']	= '';
		} else {
			if (!$new) {
				// edited event maybe part of a recurrence set
				// -> drop event from set
				$data['recurrence_first_id']	= '';
				$data['recurrence_counter'] 	= '';
			}

			$data['recurrence_number']		= $recurrencenumber;
			$data['recurrence_byday']		= $recurrencebyday;
		}

		$data['meta_keywords'] 		= $metakeywords;
		$data['meta_description']	= $metadescription;

		// Store IP of author only.
		if ($new) {
			$author_ip = $jinput->get('author_ip', '', 'string');
			$data['author_ip'] = $author_ip;
		}

		// Store as copy - reset creation date, modification fields, hit counter, version
		if ($task == 'save2copy') {
			unset($data['created']);
			unset($data['modified']);
			unset($data['modified_by']);
			unset($data['version']);
			unset($data['hits']);
		}

		// Save the event
		$saved = parent::save($data);

		if ($saved) {
			// At this point we do have an id.
			$pk = $this->getState($this->getName() . '.id');

			if (isset($data['featured'])) {
				$this->featured($pk, $data['featured']);
			}

			// attachments, new ones first
			$attachments 				= array();
			$attachments 				= $fileFilter->get('attach', array(), 'array');
			$attachments['customname']	= $jinput->post->get('attach-name', array(), 'array');
			$attachments['description'] = $jinput->post->get('attach-desc', array(), 'array');
			$attachments['access'] 		= $jinput->post->get('attach-access', array(), 'array');
			JEMAttachment::postUpload($attachments, 'event' . $pk);

			// and update old ones
			$old				= array();
			$old['id'] 			= $jinput->post->get('attached-id', array(), 'array');
			$old['name'] 		= $jinput->post->get('attached-name', array(), 'array');
			$old['description'] = $jinput->post->get('attached-desc', array(), 'array');
			$old['access'] 		= $jinput->post->get('attached-access', array(), 'array');

			foreach ($old['id'] as $k => $id) {
				$attach 				= array();
				$attach['id'] 			= $id;
				$attach['name'] 		= $old['name'][$k];
				$attach['description'] 	= $old['description'][$k];
				$attach['access'] 		= $old['access'][$k];
				JEMAttachment::update($attach);
			}

			// Store cats
			$saved |= $this->_storeCategoriesSelected($pk, $cats, !$backend, $new);

			// check for recurrence
			// when filled it will perform the cleanup function
			$table->load($pk);
			if (($table->recurrence_number > 0) && ($table->dates != null)) {
				JEMHelper::cleanup(2); // 2 = force on save, needs special attention
			}
		}

		return $saved;
	}