Your IP : 216.73.216.55


Current Path : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/models/
Upload File :
Current File : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/models/quickdata.php

<?php
/**
 * @name		Template Creator CK
 * @copyright	Copyright (C) since 2011. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 * @author		Cedric Keiflin - http://www.template-creator.com - http://www.joomlack.fr
 */

defined('TCK_LOADED') or die;
jimport('joomla.application.component.modellist');

use Templatecreatorck\CKFof;

class TemplateckModelQuickdata extends JModelList
{
	/**
	 * Constructor.
	 *
	 * @param   array  $config  An optional associative array of configuration settings.
	 *
	 * @see     JController
	 * @since   1.6
	 */
	public function __construct($config = array())
	{

		parent::__construct($config);
	}
	
	/**
	 * Method to install the demo data
	 *
	 * @access	public
	 * @return	true on success
	 */
	public function getModules() {
		$app = JFactory::getApplication();
		$name = $app->input->get('name', '', 'string');
		// $fileInput = new TCK_Input($_FILES);
		// $file = $fileInput->get('file', null, 'array');
		// if (!is_array($file))
			// return false;

		//Clean up filename to get rid of strange characters like spaces etc
		// $filename = TCK_File::makeSafe($file['name']);
		$modulesList = TEMPLATECREATORCK_SITE_ROOT . '/templates/' . $name . '/modules.qdtck';
		if (! file_exists($modulesList)) 
			$modulesList = TEMPLATECREATORCK_SITE_ROOT . '/templates/' . $name . '/modules.txt';
		
		if (! file_exists($modulesList)) return array();
		// check if the file exists (qstck = quick start)
		// if (TCK_File::getExt($filename) != 'qdtck' && TCK_File::getExt($filename) != 'tck3z') {
			// $msg = TCK_Text::_('CK_NOT_TCK3_AND_NOT_TCK3Z_FILE');
			// $app->redirect(TEMPLATECREATORCK_ADMIN_URL, $msg, 'error');
			// return false;
		// }

		// if (TCK_File::getExt($filename) === 'tck3z') {
			// $dest_extracted_folder = $this->extractFilesFromTck3z ($file);
			// if (! $dest_extracted_folder) {
				// return false;
			// }
			// if (file_exists($dest_extracted_folder . '/modules.txt')) {
				// $modulesList = $dest_extracted_folder . '/modules.txt';
			// } else {
				// $modulesList = $dest_extracted_folder . '/modules.qdtck';
			// }
		// } else {
			// $modulesList = $file['tmp_name'];
		// }
		
		$modules = file_get_contents($modulesList);
		$modules = unserialize($modules);

		$existingTypes = array();
		foreach ($modules as &$module) {
			$type = $module->module;
			// check if the module type is installed in the website
			if (array_key_exists($type, $existingTypes)) {
				$module->installed = $existingTypes[$type];
			} else {
				$module->installed = $this->checkIfModuleTypeExists($type);
				$existingTypes[$type] = $module->installed;
			}			
		}

		return $modules;
	}

	private function replaceRoot($text) {
		$text = str_replace("\|URIBASE\|", JUri::root(true), $text);

		return $text;
	}

	private function checkIfModuleTypeExists($type) {
		$result = CKFof::dbLoadResult("SELECT extension_id FROM #__extensions WHERE element = '" . $type . "'");

		return $result;
	}

	public function importModule($module) {
		$module->params = $this->replaceRoot($module->params);

		$module->id = 0;
		$moduleid = CKFof::dbStore('#__modules', $module);
		$assign = array('id' => 0, 'moduleid' => $moduleid, 'menuid' => 0);
		$assignment = CKFof::dbStore('#__modules_menu', $assign);

		return $moduleid;
	}
}