From 909a91844f528137f8bcd2ae86c4b79511d454d3 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 23 Apr 2018 14:47:19 +0200 Subject: [PATCH] Fixed the auto backup system, to allow JCB to be backed up automatically --- README.md | 4 +- admin/README.txt | 4 +- admin/helpers/componentbuilder.php | 1611 +++++++++-------- .../en-GB/en-GB.com_componentbuilder.ini | 2 + admin/layouts/field/data_base_fullwidth.php | 3 +- admin/models/field.php | 24 +- admin/models/fields.php | 4 +- admin/models/forms/field.js | 4 +- admin/models/forms/field.xml | 66 +- admin/sql/install.mysql.utf8.sql | 4 +- script.php | 8 +- site/componentbuilder.php | 5 +- site/helpers/componentbuilder.php | 993 +++++++++- 13 files changed, 1868 insertions(+), 864 deletions(-) diff --git a/README.md b/README.md index 74e626d04..65b2d5ef8 100644 --- a/README.md +++ b/README.md @@ -130,8 +130,8 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.7.6 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **183707** -+ *Field count*: **1024** ++ *Line count*: **184709** ++ *Field count*: **1025** + *File count*: **1201** + *Folder count*: **193** diff --git a/admin/README.txt b/admin/README.txt index 74e626d04..65b2d5ef8 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -130,8 +130,8 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.7.6 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **183707** -+ *Field count*: **1024** ++ *Line count*: **184709** ++ *Field count*: **1025** + *File count*: **1201** + *Folder count*: **193** diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index fbe7b3a3e..fc47d736c 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -39,13 +39,819 @@ abstract class ComponentbuilderHelper { // the Session keeps track of all data related to the current session of this user self::loadSession(); - } + } + /** + * Locked Libraries (we can not have these change) + **/ + public static $libraryNames = array(1 => 'No Library', 2 => 'Bootstrap v4', 3 => 'Uikit v3', 4 => 'Uikit v2', 5 => 'FooTable v2', 6 => 'FooTable v3'); + + /** + * The global params + **/ + protected static $params = false; + /** * The global updater **/ protected static $globalUpdater = array(); + /** + * The local company details + **/ + protected static $localCompany = array(); + + /** + * The snippet paths + **/ + public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/'; + public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master'; + + /** + * The packages paths + **/ + public static $jcbGithubPackagesUrl = "https://api.github.com/repos/vdm-io/JCB-Packages/git/trees/master"; + public static $jcbGithubPackageUrl = "https://github.com/vdm-io/JCB-Packages/raw/master/"; + + // not needed at this time (maybe latter) + public static $accessToken = ""; + + /** + * get the github repo file list + * + * @return array on success + * + */ + public static function getGithubRepoFileList($type, $target) + { + // get the current Packages (public) + if (!$repoData = self::get($type)) + { + if (self::urlExists($target)) + { + $repoData = self::getFileContents($target); + if (self::checkJson($repoData)) + { + $test = json_decode($repoData); + if (self::checkObject($test) && isset($test->tree) && self::checkArray($test->tree) ) + { + // remember to set it + self::set($type, $repoData); + } + // check if we have error message from github + elseif ($errorMessage = self::githubErrorHandeler(array('error' => null), $test)) + { + if (self::checkString($errorMessage['error'])) + { + JFactory::getApplication()->enqueueMessage($errorMessage['error'], 'Error'); + } + $repoData = false; + } + } + else + { + $repoData = false; + } + } + else + { + JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DOES_NOT_EXIST', $target), 'Error'); + } + } + // check if we could find packages + if (isset($repoData) && self::checkJson($repoData)) + { + $repoData = json_decode($repoData); + if (self::checkObject($repoData) && isset($repoData->tree) && self::checkArray($repoData->tree) ) + { + return $repoData->tree; + } + } + return false; + } + + /** + * get the github error messages + * + * @return array of errors on success + * + */ + protected static function githubErrorHandeler($message, &$github) + { + if (self::checkObject($github) && isset($github->message) && self::checkString($github->message)) + { + // set the message + $errorMessage = $github->message; + // add the documentation URL + if (isset($github->documentation_url) && self::checkString($github->documentation_url)) + { + $errorMessage = $errorMessage.'
'.$github->documentation_url; + } + // check the message + if (strpos($errorMessage, 'Authenticated') !== false) + { + // add little more help if it is an access token issue + $errorMessage = JText::sprintf('COM_COMPONENTBUILDER_SBR_YOU_CAN_ADD_AN_BACCESS_TOKENB_TO_GETBIBLE_GLOBAL_OPTIONS_TO_MAKE_AUTHENTICATED_REQUESTS_AN_ACCESS_TOKEN_WITH_ONLY_PUBLIC_ACCESS_WILL_DO', $errorMessage); + } + // set error notice + $message['error'] = $errorMessage; + // we have error message + return $message; + } + return false; + } + + /** + * The array of constant paths + * + * JPATH_SITE is meant to represent the root path of the JSite application, + * just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application. + * + * JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application: + * + * JPATH_BASE == JPATH_ADMINISTRATOR + * + * If you are in the site application: + * + * JPATH_BASE == JPATH_SITE + * + * If you are in the installation application: + * + * JPATH_BASE == JPATH_INSTALLATION. + * + * JPATH_ROOT is the root path for the Joomla install and does not depend upon any application. + * + * @var array + */ + public static $constantPaths = array( + // The path to the administrator folder. + 'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR, + // The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend. + 'JPATH_BASE' => JPATH_BASE, + // The path to the cache folder. + 'JPATH_CACHE' => JPATH_CACHE, + // The path to the administration folder of the current component being executed. + 'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR, + // The path to the site folder of the current component being executed. + 'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE, + // The path to the current component being executed. + 'JPATH_COMPONENT' => JPATH_COMPONENT, + // The path to folder containing the configuration.php file. + 'JPATH_CONFIGURATION' => JPATH_CONFIGURATION, + // The path to the installation folder. + 'JPATH_INSTALLATION' => JPATH_INSTALLATION, + // The path to the libraries folder. + 'JPATH_LIBRARIES' => JPATH_LIBRARIES, + // The path to the plugins folder. + 'JPATH_PLUGINS' => JPATH_PLUGINS, + // The path to the installed Joomla! site. + 'JPATH_ROOT' => JPATH_ROOT, + // The path to the installed Joomla! site. + 'JPATH_SITE' => JPATH_SITE, + // The path to the templates folder. + 'JPATH_THEMES' => JPATH_THEMES + ); + + /* + * Get the Array of Existing Validation Rule Names + * + * @return array + */ + public static function getExistingValidationRuleNames($lowercase = false) + { + // get the items + $items = self::get('_existing_validation_rules_VDM', null); + if (!$items) + { + // load the file class + jimport('joomla.filesystem.file'); + jimport('joomla.filesystem.folder'); + // set the path to the form validation rules + $path = JPATH_LIBRARIES . '/src/Form/Rule'; + // check if the path exist + if (!JFolder::exists($path)) + { + return false; + } + // we must first store the current working directory + $joomla = getcwd(); + // go to that folder + chdir($path); + // load all the files in this path + $items = JFolder::files('.', '\.php', true, true); + // change back to Joomla working directory + chdir($joomla); + // make sure we have an array + if (!self::checkArray($items)) + { + return false; + } + // remove the Rule.php from the name + $items = array_map( function ($name) { + return str_replace(array('./','Rule.php'), '', $name); + }, $items); + // store the names for next run + self::set('_existing_validation_rules_VDM', json_encode($items)); + } + // make sure it is no longer json + if (self::checkJson($items)) + { + $items = json_decode($items, true); + } + // check if the names should be all lowercase + if ($lowercase) + { + $items = array_map( function($item) { + return strtolower($item); + }, $items); + } + return $items; + } + + /** + * Get the snippet contributor details + * + * @param string $filename The file name + * @param string $type The type of file + * + * @return array On success the contributor details + * + */ + public static function getContributorDetails($filename, $type = 'snippet') + { + // start loading he contributor details + $contributor = array(); + // get the path & content + switch ($type) + { + case 'snippet': + $path = $snippetPath.$filename; + // get the file if available + $content = self::getFileContents($path); + if (self::checkJson($content)) + { + $content = json_decode($content, true); + } + break; + default: + // only allow types that are being targeted + return false; + break; + } + // see if we have content and all needed details + if (isset($content) && self::checkArray($content) + && isset($content['contributor_company']) + && isset($content['contributor_name']) + && isset($content['contributor_email']) + && isset($content['contributor_website'])) + { + // got the details from file + return array('contributor_company' => $content['contributor_company'] ,'contributor_name' => $content['contributor_name'], 'contributor_email' => $content['contributor_email'], 'contributor_website' => $content['contributor_website'], 'origin' => 'file'); + } + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_componentbuilder'); + } + // get the global company details + if (!self::checkArray(self::$localCompany)) + { + // Set the person sharing information (default VDM ;) + self::$localCompany['company'] = self::$params->get('export_company', 'Vast Development Method'); + self::$localCompany['owner'] = self::$params->get('export_owner', 'Llewellyn van der Merwe'); + self::$localCompany['email'] = self::$params->get('export_email', 'joomla@vdm.io'); + self::$localCompany['website'] = self::$params->get('export_website', 'https://www.vdm.io/'); + } + // default global + return array('contributor_company' => self::$localCompany['company'] ,'contributor_name' => self::$localCompany['owner'], 'contributor_email' => self::$localCompany['email'], 'contributor_website' => self::$localCompany['website'], 'origin' => 'global'); + } + + /** + * Get the library files + * + * @param int $id The library id to target + * + * @return array On success the array of files that belong to this library + * + */ + public static function getLibraryFiles($id) + { + // get the library files, folders, and urls + $files = array(); + // Get a db connection. + $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('b.name','a.addurls','a.addfolders','a.addfiles'))); + $query->from($db->quoteName('#__componentbuilder_library_files_folders_urls','a')); + $query->join('LEFT', $db->quoteName('#__componentbuilder_library', 'b') . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('b.id') . ')'); + $query->where($db->quoteName('a.library') . ' = ' . (int) $id); + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + // prepare the files + $result = $db->loadObject(); + // first we load the URLs + if (self::checkJson($result->addurls)) + { + // convert to array + $result->addurls = json_decode($result->addurls, true); + // set urls + if (self::checkArray($result->addurls)) + { + // build media folder path + $mediaPath = '/media/' . strtolower( preg_replace('/\s+/', '-', self::safeString($result->name, 'filename', ' ', false))); + // load the urls + foreach($result->addurls as $url) + { + if (isset($url['url']) && self::checkString($url['url'])) + { + // set the path if needed + if (isset($url['type']) && $url['type'] > 1) + { + $fileName = basename($url['url']); + // build sub path + if (strpos($fileName, '.js') !== false) + { + $path = '/js'; + } + elseif (strpos($fileName, '.css') !== false) + { + $path = '/css'; + } + else + { + $path = ''; + } + // set the path to library file + $url['path'] = $mediaPath . $path . '/' . $fileName; // we need this for later + } + // if local path is set, then use it first + if (isset($url['path'])) + { + // load document script + $files[md5($url['path'])] = '(' . JText::_('URL') . ') ' . basename($url['url']) . ' - ' . JText::_('COM_COMPONENTBUILDER_LOCAL'); + } + // check if link must be added + if (isset($url['url']) && ((isset($url['type']) && $url['type'] == 1) || (isset($url['type']) && $url['type'] == 3) || !isset($url['type']))) + { + // load url also if not building document + $files[md5($url['url'])] = '(' . JText::_('URL') . ') ' . basename($url['url']) . ' - ' . JText::_('COM_COMPONENTBUILDER_LINK'); + } + } + } + } + } + // load the local files + if (self::checkJson($result->addfiles)) + { + // convert to array + $result->addfiles = json_decode($result->addfiles, true); + // set files + if (self::checkArray($result->addfiles)) + { + foreach($result->addfiles as $file) + { + if (isset($file['file']) && isset($file['path'])) + { + $path = '/'.trim($file['path'], '/'); + // check if path has new file name (has extetion) + $pathInfo = pathinfo($path); + if (isset($pathInfo['extension']) && $pathInfo['extension']) + { + // load document script + $files[md5($path)] = '(' . JText::_('COM_COMPONENTBUILDER_FILE') . ') ' . $file['file']; + } + else + { + // load document script + $files[md5($path.'/'.trim($file['file'],'/'))] = '(' . JText::_('COM_COMPONENTBUILDER_FILE') . ') ' . $file['file']; + } + } + } + } + } + // load the files in the folder + if (self::checkJson($result->addfolders)) + { + // convert to array + $result->addfolders = json_decode($result->addfolders, true); + // set folder + if (self::checkArray($result->addfolders)) + { + // get the global settings + if (!self::checkObject(self::$params)) + { + self::$params = JComponentHelper::getParams('com_componentbuilder'); + } + // reset bucket + $bucket = array(); + // get custom folder path + $customPath = '/'.trim(self::$params->get('custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR.'/custom'), '/'); + // get all the file paths + foreach ($result->addfolders as $folder) + { + if (isset($folder['path']) && isset($folder['folder'])) + { + $_path = '/'.trim($folder['path'], '/'); + $customFolder = '/'.trim($folder['folder'], '/'); + if (isset($folder['rename']) && 1 == $folder['rename']) + { + if ($_paths = self::getAllFilePaths($customPath.$customFolder)) + { + $bucket[$_path] = $_paths; + } + } + else + { + $path = $_path.$customFolder; + if ($_paths = self::getAllFilePaths($customPath.$customFolder)) + { + $bucket[$path] = $_paths; + } + } + } + } + // now load the script + if (self::checkArray($bucket)) + { + foreach ($bucket as $root => $paths) + { + // load per path + foreach($paths as $path) + { + $files[md5($root.'/'.trim($path, '/'))] = '(' . JText::_('COM_COMPONENTBUILDER_FOLDER') . ') ' . basename($path) . ' - ' . basename($root); + } + } + } + } + } + // return files if found + if (self::checkArray($files)) + { + return $files; + } + } + return false; + } + + /** + * get all the file paths in folder and sub folders + * + * @param string $folder The local path to parse + * @param array $fileTypes The type of files to get + * + * @return void + * + */ + public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less')) + { + if (JFolder::exists($folder)) + { + // we must first store the current woking directory + $joomla = getcwd(); + // we are changing the working directory to the componet path + chdir($folder); + // get the files + foreach ($fileTypes as $type) + { + // get a list of files in the current directory tree + $files[] = JFolder::files('.', $type, true, true); + } + // change back to Joomla working directory + chdir($joomla); + // return array of files + return array_map( function($file) { return str_replace('./', '/', $file); }, (array) self::mergeArrays($files)); + } + return false; + } + + /** + * get all component IDs + */ + public static function getComponentIDs() + { + // Get a db connection. + $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('id'))); + $query->from($db->quoteName('#__componentbuilder_joomla_component')); + $query->where($db->quoteName('published') . ' >= 1'); // do not backup trash + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + return $db->loadColumn(); + } + return false; + } + + /** + * Autoloader + */ + public static function autoLoader($type = 'compiler') + { + // load the type classes + if ('smart' !== $type) + { + foreach (glob(JPATH_ADMINISTRATOR."/components/com_componentbuilder/helpers/".$type."/*.php") as $autoFile) + { + require_once $autoFile; + } + } + // load only if compiler + if ('compiler' === $type) + { + // import the Joomla librarys + jimport('joomla.filesystem.file'); + jimport('joomla.filesystem.folder'); + jimport('joomla.filesystem.archive'); + jimport('joomla.application.component.modellist'); + // include class to minify js + require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/js.php'; + } + // load only if smart + if ('smart' === $type) + { + // import the Joomla libraries + jimport('joomla.filesystem.file'); + jimport('joomla.filesystem.folder'); + jimport('joomla.filesystem.archive'); + jimport('joomla.application.component.modellist'); + } + // load this for all + jimport('joomla.application'); + } + + /** + * Remove folders with files + * + * @param string $dir The path to folder to remove + * @param boolean $ignore The folders and files to ignore and not remove + * + * @return boolean True in all is removed + * + */ + public static function removeFolder($dir, $ignore = false) + { + if (JFolder::exists($dir)) + { + $it = new RecursiveDirectoryIterator($dir); + $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + foreach ($it as $file) + { + if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue; + if ($file->isDir()) + { + $keeper = false; + if (self::checkArray($ignore)) + { + foreach ($ignore as $keep) + { + if (strpos($file->getPathname(), $dir.'/'.$keep) !== false) + { + $keeper = true; + } + } + } + if ($keeper) + { + continue; + } + JFolder::delete($file->getPathname()); + } + else + { + $keeper = false; + if (self::checkArray($ignore)) + { + foreach ($ignore as $keep) + { + if (strpos($file->getPathname(), $dir.'/'.$keep) !== false) + { + $keeper = true; + } + } + } + if ($keeper) + { + continue; + } + JFile::delete($file->getPathname()); + } + } + if (!self::checkArray($ignore)) + { + return JFolder::delete($dir); + } + return true; + } + return false; + } + + /** + * The dynamic builder of views, tables and fields + **/ + public static function dynamicBuilder(&$data, $type) + { + self::autoLoader('extrusion'); + $extruder = new Extrusion($data); + } + + public static function getFieldOptions($value, $type, $settings = array(), $xml = null) + { + // Get a db connection. + $db = JFactory::getDbo(); + + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('properties', 'short_description', 'description'))); + $query->from($db->quoteName('#__componentbuilder_fieldtype')); + $query->where($db->quoteName('published') . ' = 1'); + $query->where($db->quoteName($type) . ' = '. $value); + + // Reset the query using our newly populated query object. + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + $result = $db->loadObject(); + $properties = json_decode($result->properties,true); + $field = array( + 'subform' => array(), + 'nameListOptions' => array(), + 'php' => array(), + 'values' => " '', + 'short_description' => $result->short_description, + 'description' => $result->description); + // number pointer + $nr = 0; + // value to check since there are false and null values even 0 in the values returned + $confirmation = '8qvZHoyuFYQqpj0YQbc6F3o5DhBlmS-_-a8pmCZfOVSfANjkmV5LG8pCdAY2JNYu6cB'; + // set the headers + $field['values_description'] .= ''; + foreach ($properties as $property) + { + $example = (isset($property['example']) && self::checkString($property['example'])) ? $property['example'] : ''; + $field['values_description'] .= ''; + // check if we should load the value + $value = self::getValueFromXMLstring($xml, $property['name'], $confirmation); + // check if this is a php field + $addPHP = false; + if (strpos($property['name'], 'type_php') !== false) + { + $addPHP = true; + $phpKey = trim(preg_replace('/[0-9]+/', '', $property['name']), '_'); + // start array if not already set + if (!isset($field['php'][$phpKey])) + { + $field['php'][$phpKey] = array(); + $field['php'][$phpKey]['value'] = array(); + $field['php'][$phpKey]['desc'] = $property['description']; + } + } + // was the settings for the property passed + if(self::checkArray($settings) && isset($settings[$property['name']])) + { + // add the xml values + $field['values'] .= PHP_EOL."\t".$property['name'].'="'.$settings[$property['name']].'" '; + // add the json values + if ($addPHP) + { + $field['php'][$phpKey]['value'][] = $settings[$property['name']]; + } + else + { + $field['subform']['properties'.$nr] = array('name' => $property['name'], 'value' => $settings[$property['name']], 'desc' => $property['description']); + } + } + elseif (!$xml || $confirmation !== $value) + { + // add the xml values + $field['values'] .= PHP_EOL."\t" . $property['name'] . '="'. ($confirmation !== $value) ? $value : $example .'" '; + // add the json values + if ($addPHP) + { + $field['php'][$phpKey]['value'][] = ($confirmation !== $value) ? $value : $example; + } + else + { + $field['subform']['properties' . $nr] = array('name' => $property['name'], 'value' => ($confirmation !== $value) ? $value : $example, 'desc' => $property['description']); + } + } + // add the name List Options + if (!$addPHP) + { + $field['nameListOptions'][$property['name']] = $property['name']; + } + // increment the number + $nr++; + } + $field['values'] .= PHP_EOL."/>"; + $field['values_description'] .= '
'.JText::_('COM_COMPONENTBUILDER_PROPERTY').''.JText::_('COM_COMPONENTBUILDER_EXAMPLE').''.JText::_('COM_COMPONENTBUILDER_DESCRIPTION').'
'.$property['name'].''.$example.''.$property['description'].'
'; + // return found field options + return $field; + } + return false; + } + + public static function getValueFromXMLstring($xml, $get, $confirmation) + { + if (self::checkString($xml)) + { + return self::getBetween($xml, $get.'="', '"', $confirmation); + } + return $confirmation; + } + + + /** + * The zipper method + * + * @param string $workingDIR The directory where the items must be zipped + * @param string $filepath The path to where the zip file must be placed + * + * @return bool true On success + * + */ + public static function zip($workingDIR, &$filepath) + { + // store the current joomla working directory + $joomla = getcwd(); + + // we are changing the working directory to the component temp folder + chdir($workingDIR); + + // the full file path of the zip file + $filepath = JPath::clean($filepath); + + // delete an existing zip file (or use an exclusion parameter in JFolder::files() + JFile::delete($filepath); + + // get a list of files in the current directory tree + $files = JFolder::files('.', '', true, true); + $zipArray = array(); + // setup the zip array + foreach ($files as $file) + { + $tmp = array(); + $tmp['name'] = str_replace('./', '', $file); + $tmp['data'] = JFile::read($file); + $tmp['time'] = filemtime($file); + $zipArray[] = $tmp; + } + + // change back to joomla working directory + chdir($joomla); + + // get the zip adapter + $zip = JArchive::getAdapter('zip'); + + //create the zip file + if ($zip->create($filepath, $zipArray)) + { + return true; + } + return false; + } + + + /** + * Write a file to the server + * + * @param string $path The path and file name where to safe the data + * @param string $data The data to safe + * + * @return bool true On success + * + */ + public static function writeFile($path, $data) + { + $klaar = false; + if (self::checkString($data)) + { + // open the file + $fh = fopen($path, "w"); + if (!is_resource($fh)) + { + return $klaar; + } + // write to the file + if (fwrite($fh, $data)) + { + // has been done + $klaar = true; + } + // close file. + fclose($fh); + } + return $klaar; + } + + /* * Convert repeatable field to subform * @@ -157,60 +963,6 @@ abstract class ComponentbuilderHelper } return $object; } - - /* - * Get the Array of Existing Validation Rule Names - * - * @return array - */ - public static function getExistingValidationRuleNames($lowercase = false) - { - if (!$items = self::get('_existing_validation_rules_VDM', null)) - { - // load the file class - jimport('joomla.filesystem.file'); - jimport('joomla.filesystem.folder'); - // set the path to the form validation rules - $path = JPATH_LIBRARIES . '/src/Form/Rule'; - // check if the path exist - if (!JFolder::exists($path)) - { - return false; - } - // we must first store the current working directory - $joomla = getcwd(); - // go to that folder - chdir($path); - // load all the files in this path - $items = JFolder::files('.', '\.php', true, true); - // change back to Joomla working directory - chdir($joomla); - // make sure we have an array - if (!self::checkArray($items)) - { - return false; - } - // remove the Rule.php from the name - $items = array_map( function ($name) { - return str_replace(array('./','Rule.php'), '', $name); - }, $items); - // store the names for next run - self::set('_existing_validation_rules_VDM', json_encode($items)); - } - // make sure it is no longer json - if (self::checkJson($items)) - { - $items = json_decode($items, true); - } - // check if the names should be all lowercase - if ($lowercase) - { - $items = array_map( function($item) { - return strtolower($item); - }, $items); - } - return $items; - } public static function getDynamicScripts($type, $fieldName = false) { @@ -1018,755 +1770,6 @@ abstract class ComponentbuilderHelper } } return false; - } - - /** - * Locked Libraries (we can not have these change) - **/ - public static $libraryNames = array(1 => 'No Library', 2 => 'Bootstrap v4', 3 => 'Uikit v3', 4 => 'Uikit v2', 5 => 'FooTable v2', 6 => 'FooTable v3'); - - /** - * The global params - **/ - protected static $params = false; - - /** - * The local company details - **/ - protected static $localCompany = array(); - - /** - * The snippet paths - **/ - public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/'; - public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master'; - - /** - * The packages paths - **/ - public static $jcbGithubPackagesUrl = "https://api.github.com/repos/vdm-io/JCB-Packages/git/trees/master"; - public static $jcbGithubPackageUrl = "https://github.com/vdm-io/JCB-Packages/raw/master/"; - - // not needed at this time (maybe latter) - public static $accessToken = ""; - - /** - * get the github repo file list - * - * @return array on success - * - */ - public static function getGithubRepoFileList($type, $target) - { - // get the current Packages (public) - if (!$repoData = self::get($type)) - { - if (self::urlExists($target)) - { - $repoData = self::getFileContents($target); - if (self::checkJson($repoData)) - { - $test = json_decode($repoData); - if (self::checkObject($test) && isset($test->tree) && self::checkArray($test->tree) ) - { - // remember to set it - self::set($type, $repoData); - } - // check if we have error message from github - elseif ($errorMessage = self::githubErrorHandeler(array('error' => null), $test)) - { - if (self::checkString($errorMessage['error'])) - { - JFactory::getApplication()->enqueueMessage($errorMessage['error'], 'Error'); - } - $repoData = false; - } - } - else - { - $repoData = false; - } - } - else - { - JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DOES_NOT_EXIST', $target), 'Error'); - } - } - // check if we could find packages - if (isset($repoData) && self::checkJson($repoData)) - { - $repoData = json_decode($repoData); - if (self::checkObject($repoData) && isset($repoData->tree) && self::checkArray($repoData->tree) ) - { - return $repoData->tree; - } - } - return false; - } - - /** - * get the github error messages - * - * @return array of errors on success - * - */ - protected static function githubErrorHandeler($message, &$github) - { - if (self::checkObject($github) && isset($github->message) && self::checkString($github->message)) - { - // set the message - $errorMessage = $github->message; - // add the documentation URL - if (isset($github->documentation_url) && self::checkString($github->documentation_url)) - { - $errorMessage = $errorMessage.'
'.$github->documentation_url; - } - // check the message - if (strpos($errorMessage, 'Authenticated') !== false) - { - // add little more help if it is an access token issue - $errorMessage = JText::sprintf('COM_COMPONENTBUILDER_SBR_YOU_CAN_ADD_AN_BACCESS_TOKENB_TO_GETBIBLE_GLOBAL_OPTIONS_TO_MAKE_AUTHENTICATED_REQUESTS_AN_ACCESS_TOKEN_WITH_ONLY_PUBLIC_ACCESS_WILL_DO', $errorMessage); - } - // set error notice - $message['error'] = $errorMessage; - // we have error message - return $message; - } - return false; - } - - /** - * The array of constant paths - * - * JPATH_SITE is meant to represent the root path of the JSite application, - * just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application. - * - * JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application: - * - * JPATH_BASE == JPATH_ADMINISTRATOR - * - * If you are in the site application: - * - * JPATH_BASE == JPATH_SITE - * - * If you are in the installation application: - * - * JPATH_BASE == JPATH_INSTALLATION. - * - * JPATH_ROOT is the root path for the Joomla install and does not depend upon any application. - * - * @var array - */ - public static $constantPaths = array( - // The path to the administrator folder. - 'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR, - // The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend. - 'JPATH_BASE' => JPATH_BASE, - // The path to the cache folder. - 'JPATH_CACHE' => JPATH_CACHE, - // The path to the administration folder of the current component being executed. - 'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR, - // The path to the site folder of the current component being executed. - 'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE, - // The path to the current component being executed. - 'JPATH_COMPONENT' => JPATH_COMPONENT, - // The path to folder containing the configuration.php file. - 'JPATH_CONFIGURATION' => JPATH_CONFIGURATION, - // The path to the installation folder. - 'JPATH_INSTALLATION' => JPATH_INSTALLATION, - // The path to the libraries folder. - 'JPATH_LIBRARIES' => JPATH_LIBRARIES, - // The path to the plugins folder. - 'JPATH_PLUGINS' => JPATH_PLUGINS, - // The path to the installed Joomla! site. - 'JPATH_ROOT' => JPATH_ROOT, - // The path to the installed Joomla! site. - 'JPATH_SITE' => JPATH_SITE, - // The path to the templates folder. - 'JPATH_THEMES' => JPATH_THEMES - ); - - /** - * Get the snippet contributor details - * - * @param string $filename The file name - * @param string $type The type of file - * - * @return array On success the contributor details - * - */ - public static function getContributorDetails($filename, $type = 'snippet') - { - // start loading he contributor details - $contributor = array(); - // get the path & content - switch ($type) - { - case 'snippet': - $path = $snippetPath.$filename; - // get the file if available - $content = self::getFileContents($path); - if (self::checkJson($content)) - { - $content = json_decode($content, true); - } - break; - default: - // only allow types that are being targeted - return false; - break; - } - // see if we have content and all needed details - if (isset($content) && self::checkArray($content) - && isset($content['contributor_company']) - && isset($content['contributor_name']) - && isset($content['contributor_email']) - && isset($content['contributor_website'])) - { - // got the details from file - return array('contributor_company' => $content['contributor_company'] ,'contributor_name' => $content['contributor_name'], 'contributor_email' => $content['contributor_email'], 'contributor_website' => $content['contributor_website'], 'origin' => 'file'); - } - // get the global settings - if (!self::checkObject(self::$params)) - { - self::$params = JComponentHelper::getParams('com_componentbuilder'); - } - // get the global company details - if (!self::checkArray(self::$localCompany)) - { - // Set the person sharing information (default VDM ;) - self::$localCompany['company'] = self::$params->get('export_company', 'Vast Development Method'); - self::$localCompany['owner'] = self::$params->get('export_owner', 'Llewellyn van der Merwe'); - self::$localCompany['email'] = self::$params->get('export_email', 'joomla@vdm.io'); - self::$localCompany['website'] = self::$params->get('export_website', 'https://www.vdm.io/'); - } - // default global - return array('contributor_company' => self::$localCompany['company'] ,'contributor_name' => self::$localCompany['owner'], 'contributor_email' => self::$localCompany['email'], 'contributor_website' => self::$localCompany['website'], 'origin' => 'global'); - } - - /** - * Get the library files - * - * @param int $id The library id to target - * - * @return array On success the array of files that belong to this library - * - */ - public static function getLibraryFiles($id) - { - // get the library files, folders, and urls - $files = array(); - // Get a db connection. - $db = JFactory::getDbo(); - // Create a new query object. - $query = $db->getQuery(true); - $query->select($db->quoteName(array('b.name','a.addurls','a.addfolders','a.addfiles'))); - $query->from($db->quoteName('#__componentbuilder_library_files_folders_urls','a')); - $query->join('LEFT', $db->quoteName('#__componentbuilder_library', 'b') . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('b.id') . ')'); - $query->where($db->quoteName('a.library') . ' = ' . (int) $id); - $db->setQuery($query); - $db->execute(); - if ($db->getNumRows()) - { - // prepare the files - $result = $db->loadObject(); - // first we load the URLs - if (self::checkJson($result->addurls)) - { - // convert to array - $result->addurls = json_decode($result->addurls, true); - // set urls - if (self::checkArray($result->addurls)) - { - // build media folder path - $mediaPath = '/media/' . strtolower( preg_replace('/\s+/', '-', self::safeString($result->name, 'filename', ' ', false))); - // load the urls - foreach($result->addurls as $url) - { - if (isset($url['url']) && self::checkString($url['url'])) - { - // set the path if needed - if (isset($url['type']) && $url['type'] > 1) - { - $fileName = basename($url['url']); - // build sub path - if (strpos($fileName, '.js') !== false) - { - $path = '/js'; - } - elseif (strpos($fileName, '.css') !== false) - { - $path = '/css'; - } - else - { - $path = ''; - } - // set the path to library file - $url['path'] = $mediaPath . $path . '/' . $fileName; // we need this for later - } - // if local path is set, then use it first - if (isset($url['path'])) - { - // load document script - $files[md5($url['path'])] = '(' . JText::_('URL') . ') ' . basename($url['url']) . ' - ' . JText::_('COM_COMPONENTBUILDER_LOCAL'); - } - // check if link must be added - if (isset($url['url']) && ((isset($url['type']) && $url['type'] == 1) || (isset($url['type']) && $url['type'] == 3) || !isset($url['type']))) - { - // load url also if not building document - $files[md5($url['url'])] = '(' . JText::_('URL') . ') ' . basename($url['url']) . ' - ' . JText::_('COM_COMPONENTBUILDER_LINK'); - } - } - } - } - } - // load the local files - if (self::checkJson($result->addfiles)) - { - // convert to array - $result->addfiles = json_decode($result->addfiles, true); - // set files - if (self::checkArray($result->addfiles)) - { - foreach($result->addfiles as $file) - { - if (isset($file['file']) && isset($file['path'])) - { - $path = '/'.trim($file['path'], '/'); - // check if path has new file name (has extetion) - $pathInfo = pathinfo($path); - if (isset($pathInfo['extension']) && $pathInfo['extension']) - { - // load document script - $files[md5($path)] = '(' . JText::_('COM_COMPONENTBUILDER_FILE') . ') ' . $file['file']; - } - else - { - // load document script - $files[md5($path.'/'.trim($file['file'],'/'))] = '(' . JText::_('COM_COMPONENTBUILDER_FILE') . ') ' . $file['file']; - } - } - } - } - } - // load the files in the folder - if (self::checkJson($result->addfolders)) - { - // convert to array - $result->addfolders = json_decode($result->addfolders, true); - // set folder - if (self::checkArray($result->addfolders)) - { - // get the global settings - if (!self::checkObject(self::$params)) - { - self::$params = JComponentHelper::getParams('com_componentbuilder'); - } - // reset bucket - $bucket = array(); - // get custom folder path - $customPath = '/'.trim(self::$params->get('custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR.'/custom'), '/'); - // get all the file paths - foreach ($result->addfolders as $folder) - { - if (isset($folder['path']) && isset($folder['folder'])) - { - $_path = '/'.trim($folder['path'], '/'); - $customFolder = '/'.trim($folder['folder'], '/'); - if (isset($folder['rename']) && 1 == $folder['rename']) - { - if ($_paths = self::getAllFilePaths($customPath.$customFolder)) - { - $bucket[$_path] = $_paths; - } - } - else - { - $path = $_path.$customFolder; - if ($_paths = self::getAllFilePaths($customPath.$customFolder)) - { - $bucket[$path] = $_paths; - } - } - } - } - // now load the script - if (self::checkArray($bucket)) - { - foreach ($bucket as $root => $paths) - { - // load per path - foreach($paths as $path) - { - $files[md5($root.'/'.trim($path, '/'))] = '(' . JText::_('COM_COMPONENTBUILDER_FOLDER') . ') ' . basename($path) . ' - ' . basename($root); - } - } - } - } - } - // return files if found - if (self::checkArray($files)) - { - return $files; - } - } - return false; - } - - /** - * get all the file paths in folder and sub folders - * - * @param string $folder The local path to parse - * @param array $fileTypes The type of files to get - * - * @return void - * - */ - public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less')) - { - if (JFolder::exists($folder)) - { - // we must first store the current woking directory - $joomla = getcwd(); - // we are changing the working directory to the componet path - chdir($folder); - // get the files - foreach ($fileTypes as $type) - { - // get a list of files in the current directory tree - $files[] = JFolder::files('.', $type, true, true); - } - // change back to Joomla working directory - chdir($joomla); - // return array of files - return array_map( function($file) { return str_replace('./', '/', $file); }, (array) self::mergeArrays($files)); - } - return false; - } - - /** - * get all component IDs - */ - public static function getComponentIDs() - { - // Get a db connection. - $db = JFactory::getDbo(); - // Create a new query object. - $query = $db->getQuery(true); - $query->select($db->quoteName(array('id'))); - $query->from($db->quoteName('#__componentbuilder_joomla_component')); - $query->where($db->quoteName('published') . ' >= 1'); // do not backup trash - $db->setQuery($query); - $db->execute(); - if ($db->getNumRows()) - { - return $db->loadColumn(); - } - return false; - } - - /** - * Autoloader - */ - public static function autoLoader($type = 'compiler') - { - // load the type classes - if ('smart' !== $type) - { - foreach (glob(JPATH_ADMINISTRATOR."/components/com_componentbuilder/helpers/".$type."/*.php") as $autoFile) - { - require_once $autoFile; - } - } - // load only if compiler - if ('compiler' === $type) - { - // import the Joomla librarys - jimport('joomla.filesystem.file'); - jimport('joomla.filesystem.folder'); - jimport('joomla.filesystem.archive'); - jimport('joomla.application.component.modellist'); - // include class to minify js - require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/js.php'; - } - // load only if smart - if ('smart' === $type) - { - // import the Joomla libraries - jimport('joomla.filesystem.file'); - jimport('joomla.filesystem.folder'); - jimport('joomla.filesystem.archive'); - jimport('joomla.application.component.modellist'); - } - // load this for all - jimport('joomla.application'); - } - - /** - * Remove folders with files - * - * @param string $dir The path to folder to remove - * @param boolean $ignore The folders and files to ignore and not remove - * - * @return boolean True in all is removed - * - */ - public static function removeFolder($dir, $ignore = false) - { - if (JFolder::exists($dir)) - { - $it = new RecursiveDirectoryIterator($dir); - $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - foreach ($it as $file) - { - if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue; - if ($file->isDir()) - { - $keeper = false; - if (self::checkArray($ignore)) - { - foreach ($ignore as $keep) - { - if (strpos($file->getPathname(), $dir.'/'.$keep) !== false) - { - $keeper = true; - } - } - } - if ($keeper) - { - continue; - } - JFolder::delete($file->getPathname()); - } - else - { - $keeper = false; - if (self::checkArray($ignore)) - { - foreach ($ignore as $keep) - { - if (strpos($file->getPathname(), $dir.'/'.$keep) !== false) - { - $keeper = true; - } - } - } - if ($keeper) - { - continue; - } - JFile::delete($file->getPathname()); - } - } - if (!self::checkArray($ignore)) - { - return JFolder::delete($dir); - } - return true; - } - return false; - } - - /** - * The dynamic builder of views, tables and fields - **/ - public static function dynamicBuilder(&$data, $type) - { - self::autoLoader('extrusion'); - $extruder = new Extrusion($data); - } - - public static function getFieldOptions($value, $type, $settings = array(), $xml = null) - { - // Get a db connection. - $db = JFactory::getDbo(); - - // Create a new query object. - $query = $db->getQuery(true); - $query->select($db->quoteName(array('properties', 'short_description', 'description'))); - $query->from($db->quoteName('#__componentbuilder_fieldtype')); - $query->where($db->quoteName('published') . ' = 1'); - $query->where($db->quoteName($type) . ' = '. $value); - - // Reset the query using our newly populated query object. - $db->setQuery($query); - $db->execute(); - if ($db->getNumRows()) - { - $result = $db->loadObject(); - $properties = json_decode($result->properties,true); - $field = array( - 'subform' => array(), - 'nameListOptions' => array(), - 'php' => array(), - 'values' => " '', - 'short_description' => $result->short_description, - 'description' => $result->description); - // number pointer - $nr = 0; - // value to check since there are false and null values even 0 in the values returned - $confirmation = '8qvZHoyuFYQqpj0YQbc6F3o5DhBlmS-_-a8pmCZfOVSfANjkmV5LG8pCdAY2JNYu6cB'; - // set the headers - $field['values_description'] .= ''; - foreach ($properties as $property) - { - $example = (isset($property['example']) && self::checkString($property['example'])) ? $property['example'] : ''; - $field['values_description'] .= ''; - // check if we should load the value - $value = self::getValueFromXMLstring($xml, $property['name'], $confirmation); - // check if this is a php field - $addPHP = false; - if (strpos($property['name'], 'type_php') !== false) - { - $addPHP = true; - $phpKey = trim(preg_replace('/[0-9]+/', '', $property['name']), '_'); - // start array if not already set - if (!isset($field['php'][$phpKey])) - { - $field['php'][$phpKey] = array(); - $field['php'][$phpKey]['value'] = array(); - $field['php'][$phpKey]['desc'] = $property['description']; - } - } - // was the settings for the property passed - if(self::checkArray($settings) && isset($settings[$property['name']])) - { - // add the xml values - $field['values'] .= PHP_EOL."\t".$property['name'].'="'.$settings[$property['name']].'" '; - // add the json values - if ($addPHP) - { - $field['php'][$phpKey]['value'][] = $settings[$property['name']]; - } - else - { - $field['subform']['properties'.$nr] = array('name' => $property['name'], 'value' => $settings[$property['name']], 'desc' => $property['description']); - } - } - elseif (!$xml || $confirmation !== $value) - { - // add the xml values - $field['values'] .= PHP_EOL."\t" . $property['name'] . '="'. ($confirmation !== $value) ? $value : $example .'" '; - // add the json values - if ($addPHP) - { - $field['php'][$phpKey]['value'][] = ($confirmation !== $value) ? $value : $example; - } - else - { - $field['subform']['properties' . $nr] = array('name' => $property['name'], 'value' => ($confirmation !== $value) ? $value : $example, 'desc' => $property['description']); - } - } - // add the name List Options - if (!$addPHP) - { - $field['nameListOptions'][$property['name']] = $property['name']; - } - // increment the number - $nr++; - } - $field['values'] .= PHP_EOL."/>"; - $field['values_description'] .= '
'.JText::_('COM_COMPONENTBUILDER_PROPERTY').''.JText::_('COM_COMPONENTBUILDER_EXAMPLE').''.JText::_('COM_COMPONENTBUILDER_DESCRIPTION').'
'.$property['name'].''.$example.''.$property['description'].'
'; - // return found field options - return $field; - } - return false; - } - - public static function getValueFromXMLstring($xml, $get, $confirmation) - { - if (self::checkString($xml)) - { - return self::getBetween($xml, $get.'="', '"', $confirmation); - } - return $confirmation; - } - - - /** - * The zipper method - * - * @param string $workingDIR The directory where the items must be zipped - * @param string $filepath The path to where the zip file must be placed - * - * @return bool true On success - * - */ - public static function zip($workingDIR, &$filepath) - { - // store the current joomla working directory - $joomla = getcwd(); - - // we are changing the working directory to the component temp folder - chdir($workingDIR); - - // the full file path of the zip file - $filepath = JPath::clean($filepath); - - // delete an existing zip file (or use an exclusion parameter in JFolder::files() - JFile::delete($filepath); - - // get a list of files in the current directory tree - $files = JFolder::files('.', '', true, true); - $zipArray = array(); - // setup the zip array - foreach ($files as $file) - { - $tmp = array(); - $tmp['name'] = str_replace('./', '', $file); - $tmp['data'] = JFile::read($file); - $tmp['time'] = filemtime($file); - $zipArray[] = $tmp; - } - - // change back to joomla working directory - chdir($joomla); - - // get the zip adapter - $zip = JArchive::getAdapter('zip'); - - //create the zip file - if ($zip->create($filepath, $zipArray)) - { - return true; - } - return false; - } - - - /** - * Write a file to the server - * - * @param string $path The path and file name where to safe the data - * @param string $data The data to safe - * - * @return bool true On success - * - */ - public static function writeFile($path, $data) - { - $klaar = false; - if (self::checkString($data)) - { - // open the file - $fh = fopen($path, "w"); - if (!is_resource($fh)) - { - return $klaar; - } - // write to the file - if (fwrite($fh, $data)) - { - // has been done - $klaar = true; - } - // close file. - fclose($fh); - } - return $klaar; } /** diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index d27188ffd..a103fa9c2 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -3864,6 +3864,8 @@ COM_COMPONENTBUILDER_FIELD_NEW="A New Field" COM_COMPONENTBUILDER_FIELD_NO="No" COM_COMPONENTBUILDER_FIELD_NONE="None" COM_COMPONENTBUILDER_FIELD_NONE_SET="None Set" +COM_COMPONENTBUILDER_FIELD_NOTE_DATABASE_SETTINGS_NEEDED_DESCRIPTION="

Set the database column for this field here. The column will have the same name as the field. Please take care to select these settings in the correct relationship. The nature of this area is to give you as much freedom/power as you would like, but with that comes responsibility.

You therefore need to insure that you know what the correct values should be. A great way to learn, is to look at the Joomla core components fields and the corresponding mySql columns.

" +COM_COMPONENTBUILDER_FIELD_NOTE_DATABASE_SETTINGS_NEEDED_LABEL="Database Settings" COM_COMPONENTBUILDER_FIELD_NOTE_FILTER_INFORMATION_DESCRIPTION="

Filter Information

diff --git a/admin/layouts/field/data_base_fullwidth.php b/admin/layouts/field/data_base_fullwidth.php index ea5f7a51b..409a39412 100644 --- a/admin/layouts/field/data_base_fullwidth.php +++ b/admin/layouts/field/data_base_fullwidth.php @@ -30,7 +30,8 @@ defined('_JEXEC') or die('Restricted access'); $form = $displayData->getForm(); $fields = $displayData->get('fields') ?: array( - 'note_no_database_settings_needed' + 'note_no_database_settings_needed', + 'note_database_settings_needed' ); ?> diff --git a/admin/models/field.php b/admin/models/field.php index 6f820e1f7..d6b1041ce 100644 --- a/admin/models/field.php +++ b/admin/models/field.php @@ -106,12 +106,6 @@ class ComponentbuilderModelField extends JModelAdmin $item->xml = json_decode($item->xml); } - if (!empty($item->javascript_view_footer)) - { - // base64 Decode javascript_view_footer. - $item->javascript_view_footer = base64_decode($item->javascript_view_footer); - } - if (!empty($item->css_views)) { // base64 Decode css_views. @@ -124,6 +118,12 @@ class ComponentbuilderModelField extends JModelAdmin $item->css_view = base64_decode($item->css_view); } + if (!empty($item->javascript_view_footer)) + { + // base64 Decode javascript_view_footer. + $item->javascript_view_footer = base64_decode($item->javascript_view_footer); + } + if (!empty($item->javascript_views_footer)) { // base64 Decode javascript_views_footer. @@ -960,12 +960,6 @@ class ComponentbuilderModelField extends JModelAdmin $data['xml'] = (string) json_encode($data['xml']); } - // Set the javascript_view_footer string to base64 string. - if (isset($data['javascript_view_footer'])) - { - $data['javascript_view_footer'] = base64_encode($data['javascript_view_footer']); - } - // Set the css_views string to base64 string. if (isset($data['css_views'])) { @@ -978,6 +972,12 @@ class ComponentbuilderModelField extends JModelAdmin $data['css_view'] = base64_encode($data['css_view']); } + // Set the javascript_view_footer string to base64 string. + if (isset($data['javascript_view_footer'])) + { + $data['javascript_view_footer'] = base64_encode($data['javascript_view_footer']); + } + // Set the javascript_views_footer string to base64 string. if (isset($data['javascript_views_footer'])) { diff --git a/admin/models/fields.php b/admin/models/fields.php index dff6955b6..b8f7f3645 100644 --- a/admin/models/fields.php +++ b/admin/models/fields.php @@ -432,12 +432,12 @@ class ComponentbuilderModelFields extends JModelList continue; } - // decode javascript_view_footer - $item->javascript_view_footer = base64_decode($item->javascript_view_footer); // decode css_views $item->css_views = base64_decode($item->css_views); // decode css_view $item->css_view = base64_decode($item->css_view); + // decode javascript_view_footer + $item->javascript_view_footer = base64_decode($item->javascript_view_footer); // decode javascript_views_footer $item->javascript_views_footer = base64_decode($item->javascript_views_footer); // unset the values we don't want exported. diff --git a/admin/models/forms/field.js b/admin/models/forms/field.js index c06aa971e..c61d5fb1b 100644 --- a/admin/models/forms/field.js +++ b/admin/models/forms/field.js @@ -801,6 +801,7 @@ function dbChecker(type){ jQuery('#jform_null_switch').removeClass('required'); // show notice jQuery('.note_no_database_settings_needed').closest('.control-group').show(); + jQuery('.note_database_settings_needed').closest('.control-group').hide(); } else { // add the datatype jQuery('#jform_datatype-lbl').closest('.control-group').show(); @@ -817,6 +818,7 @@ function dbChecker(type){ jQuery('#jform_null_switch').attr('aria-required',true); jQuery('#jform_null_switch').addClass('required'); // remove notice - jQuery('.note_no_database_settings_needed').closest('.control-group').hide(); + jQuery('.note_no_database_settings_needed').closest('.control-group').hide(); + jQuery('.note_database_settings_needed').closest('.control-group').show(); } } diff --git a/admin/models/forms/field.xml b/admin/models/forms/field.xml index e866111ab..30daa367f 100644 --- a/admin/models/forms/field.xml +++ b/admin/models/forms/field.xml @@ -219,33 +219,6 @@ description="COM_COMPONENTBUILDER_FIELD_CATID_DESCRIPTION" class="inputbox" /> - - - - - - - - COM_COMPONENTBUILDER_FIELD_NO + + COM_COMPONENTBUILDER_FIELD_OTHER - - + + + + + + @@ -394,11 +381,11 @@ message="COM_COMPONENTBUILDER_FIELD_DATALENGHT_OTHER_MESSAGE" hint="COM_COMPONENTBUILDER_FIELD_DATALENGHT_OTHER_HINT" /> - + @@ -408,6 +395,21 @@ + + + + diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index 17872419c..4ac256d64 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -730,14 +730,14 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_field` ( KEY `idx_indexes` (`indexes`), KEY `idx_null_switch` (`null_switch`), KEY `idx_catid` (`catid`), - KEY `idx_add_javascript_view_footer` (`add_javascript_view_footer`), KEY `idx_add_css_views` (`add_css_views`), KEY `idx_add_css_view` (`add_css_view`), KEY `idx_datalenght` (`datalenght`), + KEY `idx_add_javascript_views_footer` (`add_javascript_views_footer`), KEY `idx_datadefault_other` (`datadefault_other`), KEY `idx_datadefault` (`datadefault`), KEY `idx_datalenght_other` (`datalenght_other`), - KEY `idx_add_javascript_views_footer` (`add_javascript_views_footer`) + KEY `idx_add_javascript_view_footer` (`add_javascript_view_footer`) ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `#__componentbuilder_fieldtype` ( diff --git a/script.php b/script.php index 80c44f043..0f86f196e 100644 --- a/script.php +++ b/script.php @@ -3428,9 +3428,9 @@ class com_componentbuilderInstallerScript $field->type_title = 'Componentbuilder Field'; $field->type_alias = 'com_componentbuilder.field'; $field->table = '{"special": {"dbtable": "#__componentbuilder_field","key": "id","type": "Field","prefix": "componentbuilderTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}'; - $field->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "catid","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","fieldtype":"fieldtype","datatype":"datatype","indexes":"indexes","null_switch":"null_switch","store":"store","javascript_view_footer":"javascript_view_footer","add_javascript_view_footer":"add_javascript_view_footer","css_views":"css_views","add_css_views":"add_css_views","css_view":"css_view","add_css_view":"add_css_view","datalenght":"datalenght","datadefault_other":"datadefault_other","datadefault":"datadefault","datalenght_other":"datalenght_other","add_javascript_views_footer":"add_javascript_views_footer","javascript_views_footer":"javascript_views_footer","not_required":"not_required","xml":"xml"}}'; + $field->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "catid","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","fieldtype":"fieldtype","datatype":"datatype","indexes":"indexes","null_switch":"null_switch","store":"store","css_views":"css_views","add_css_views":"add_css_views","css_view":"css_view","add_css_view":"add_css_view","datalenght":"datalenght","add_javascript_views_footer":"add_javascript_views_footer","datadefault_other":"datadefault_other","datadefault":"datadefault","datalenght_other":"datalenght_other","add_javascript_view_footer":"add_javascript_view_footer","javascript_view_footer":"javascript_view_footer","javascript_views_footer":"javascript_views_footer","not_required":"not_required","xml":"xml"}}'; $field->router = 'ComponentbuilderHelperRoute::getFieldRoute'; - $field->content_history_options = '{"formFile": "administrator/components/com_componentbuilder/models/forms/field.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","not_required","xml"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","fieldtype","store","catid","add_javascript_view_footer","add_css_views","add_css_view","add_javascript_views_footer"],"displayLookup": [{"sourceColumn": "catid","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "fieldtype","targetTable": "#__componentbuilder_fieldtype","targetColumn": "id","displayColumn": "name"}]}'; + $field->content_history_options = '{"formFile": "administrator/components/com_componentbuilder/models/forms/field.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","not_required","xml"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","fieldtype","store","catid","add_css_views","add_css_view","add_javascript_views_footer","add_javascript_view_footer"],"displayLookup": [{"sourceColumn": "catid","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "fieldtype","targetTable": "#__componentbuilder_fieldtype","targetColumn": "id","displayColumn": "name"}]}'; // Set the object into the content types table. $field_Inserted = $db->insertObject('#__content_types', $field); @@ -4037,9 +4037,9 @@ class com_componentbuilderInstallerScript $field->type_title = 'Componentbuilder Field'; $field->type_alias = 'com_componentbuilder.field'; $field->table = '{"special": {"dbtable": "#__componentbuilder_field","key": "id","type": "Field","prefix": "componentbuilderTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}'; - $field->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "catid","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","fieldtype":"fieldtype","datatype":"datatype","indexes":"indexes","null_switch":"null_switch","store":"store","javascript_view_footer":"javascript_view_footer","add_javascript_view_footer":"add_javascript_view_footer","css_views":"css_views","add_css_views":"add_css_views","css_view":"css_view","add_css_view":"add_css_view","datalenght":"datalenght","datadefault_other":"datadefault_other","datadefault":"datadefault","datalenght_other":"datalenght_other","add_javascript_views_footer":"add_javascript_views_footer","javascript_views_footer":"javascript_views_footer","not_required":"not_required","xml":"xml"}}'; + $field->field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "null","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "null","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "null","core_metadesc": "null","core_catid": "catid","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","fieldtype":"fieldtype","datatype":"datatype","indexes":"indexes","null_switch":"null_switch","store":"store","css_views":"css_views","add_css_views":"add_css_views","css_view":"css_view","add_css_view":"add_css_view","datalenght":"datalenght","add_javascript_views_footer":"add_javascript_views_footer","datadefault_other":"datadefault_other","datadefault":"datadefault","datalenght_other":"datalenght_other","add_javascript_view_footer":"add_javascript_view_footer","javascript_view_footer":"javascript_view_footer","javascript_views_footer":"javascript_views_footer","not_required":"not_required","xml":"xml"}}'; $field->router = 'ComponentbuilderHelperRoute::getFieldRoute'; - $field->content_history_options = '{"formFile": "administrator/components/com_componentbuilder/models/forms/field.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","not_required","xml"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","fieldtype","store","catid","add_javascript_view_footer","add_css_views","add_css_view","add_javascript_views_footer"],"displayLookup": [{"sourceColumn": "catid","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "fieldtype","targetTable": "#__componentbuilder_fieldtype","targetColumn": "id","displayColumn": "name"}]}'; + $field->content_history_options = '{"formFile": "administrator/components/com_componentbuilder/models/forms/field.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","not_required","xml"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","fieldtype","store","catid","add_css_views","add_css_view","add_javascript_views_footer","add_javascript_view_footer"],"displayLookup": [{"sourceColumn": "catid","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "fieldtype","targetTable": "#__componentbuilder_fieldtype","targetColumn": "id","displayColumn": "name"}]}'; // Check if field type is already in content_type DB. $field_id = null; diff --git a/site/componentbuilder.php b/site/componentbuilder.php index d21ea2051..16c6e2b18 100644 --- a/site/componentbuilder.php +++ b/site/componentbuilder.php @@ -34,7 +34,10 @@ $document->addScript('components/com_componentbuilder/assets/js/site.js'); // Require helper files JLoader::register('ComponentbuilderHelper', dirname(__FILE__) . '/helpers/componentbuilder.php'); JLoader::register('ComponentbuilderEmail', JPATH_COMPONENT_ADMINISTRATOR . '/helpers/componentbuilderemail.php'); -JLoader::register('ComponentbuilderHelperRoute', dirname(__FILE__) . '/helpers/route.php'); +JLoader::register('ComponentbuilderHelperRoute', dirname(__FILE__) . '/helpers/route.php'); + +// Triger the Global Site Event +ComponentbuilderHelper::globalEvent($document); // import joomla controller library jimport('joomla.application.component.controller'); diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index 8bb1331fa..319e1f8cd 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -30,7 +30,16 @@ defined('_JEXEC') or die('Restricted access'); * Componentbuilder component helper */ abstract class ComponentbuilderHelper -{ +{ + + /** + * The Global Site Event Method. + **/ + public static function globalEvent($document) + { + // the Session keeps track of all data related to the current session of this user + self::loadSession(); + } /** * Locked Libraries (we can not have these change) @@ -42,6 +51,11 @@ abstract class ComponentbuilderHelper **/ protected static $params = false; + /** + * The global updater + **/ + protected static $globalUpdater = array(); + /** * The local company details **/ @@ -198,6 +212,62 @@ abstract class ComponentbuilderHelper 'JPATH_THEMES' => JPATH_THEMES ); + /* + * Get the Array of Existing Validation Rule Names + * + * @return array + */ + public static function getExistingValidationRuleNames($lowercase = false) + { + // get the items + $items = self::get('_existing_validation_rules_VDM', null); + if (!$items) + { + // load the file class + jimport('joomla.filesystem.file'); + jimport('joomla.filesystem.folder'); + // set the path to the form validation rules + $path = JPATH_LIBRARIES . '/src/Form/Rule'; + // check if the path exist + if (!JFolder::exists($path)) + { + return false; + } + // we must first store the current working directory + $joomla = getcwd(); + // go to that folder + chdir($path); + // load all the files in this path + $items = JFolder::files('.', '\.php', true, true); + // change back to Joomla working directory + chdir($joomla); + // make sure we have an array + if (!self::checkArray($items)) + { + return false; + } + // remove the Rule.php from the name + $items = array_map( function ($name) { + return str_replace(array('./','Rule.php'), '', $name); + }, $items); + // store the names for next run + self::set('_existing_validation_rules_VDM', json_encode($items)); + } + // make sure it is no longer json + if (self::checkJson($items)) + { + $items = json_decode($items, true); + } + // check if the names should be all lowercase + if ($lowercase) + { + $items = array_map( function($item) { + return strtolower($item); + }, $items); + } + return $items; + } + /** * Get the snippet contributor details * @@ -781,6 +851,927 @@ abstract class ComponentbuilderHelper return $klaar; } + + /* + * Convert repeatable field to subform + * + * @param array $item The array to convert + * @param string $name The main field name + * + * @return array + */ + public static function convertRepeatable($item, $name) + { + // continue only if we have an array + if (self::checkArray($item)) + { + $bucket = array(); + foreach ($item as $key => $values) + { + foreach ($values as $nr => $value) + { + if (!isset($bucket[$name . $nr]) || !self::checkArray($bucket[$name . $nr])) + { + $bucket[$name . $nr] = array(); + } + $bucket[$name . $nr][$key] = $value; + } + } + return $bucket; + } + return $item; + } + + /* + * Convert repeatable field to subform + * + * @param object $item The item to update + * @param array $searcher The fields to check and update + * @param array $updater To update the local table + * + * @return void + */ + public static function convertRepeatableFields($object, $searcher, $updater = array()) + { + // update the repeatable fields + foreach ($searcher as $key => $sleutel) + { + if (isset($object->{$key})) + { + $isJson = false; + if (self::checkJson($object->{$key})) + { + $object->{$key} = json_decode($object->{$key}, true); + $isJson = true; + } + // check if this is old values for repeatable fields + if (self::checkArray($object->{$key}) && isset($object->{$key}[$sleutel])) + { + // load it back + $object->{$key} = self::convertRepeatable($object->{$key}, $key); + // add to global updater + if ( + self::checkArray($object->{$key}) && self::checkArray($updater) && + ( + ( isset($updater['table']) && isset($updater['val']) && isset($updater['key']) ) || + ( isset($updater['unique']) && isset($updater['unique'][$key]) && isset($updater['unique'][$key]['table']) && isset($updater['unique'][$key]['val']) && isset($updater['unique'][$key]['key']) ) + ) + ) + { + $_key = null; + $_value = null; + $_table = null; + // check if we have unique id table for this repeatable/subform field + if ( isset($updater['unique']) && isset($updater['unique'][$key]) && isset($updater['unique'][$key]['table']) && isset($updater['unique'][$key]['val']) && isset($updater['unique'][$key]['key']) ) + { + $_key = $updater['unique'][$key]['key']; + $_value = $updater['unique'][$key]['val']; + $_table = $updater['unique'][$key]['table']; + } + elseif ( isset($updater['table']) && isset($updater['val']) && isset($updater['key']) ) + { + $_key = $updater['key']; + $_value = $updater['val']; + $_table = $updater['table']; + } + // continue only if values are valid + if (self::checkString($_table) && self::checkString($_key) && $_value > 0) + { + // set target table & item + $target = trim($_table) . '.' . trim($_key) . '.' . trim($_value); + if (!isset(self::$globalUpdater[$target])) + { + self::$globalUpdater[$target] = new stdClass; + self::$globalUpdater[$target]->{$_key} = (int) $_value; + } + // load the new subform values to global updater + self::$globalUpdater[$target]->{$key} = json_encode($object->{$key}); + } + } + } + // no set back to json if came in as json + if ($isJson && self::checkArray($object->{$key})) + { + $object->{$key} = json_encode($object->{$key}); + } + // remove if not json or array + elseif (!self::checkArray($object->{$key}) && !self::checkJson($object->{$key})) + { + unset($object->{$key}); + } + } + } + return $object; + } + + public static function getDynamicScripts($type, $fieldName = false) + { + // if field name is passed the convert to type + if ($fieldName) + { + $fieldNames = array( + 'php_import_display' => 'display', + 'php_import_setdata' => 'setdata', + 'php_import_save' => 'save', + 'html_import_view' => 'view', + 'php_import' => 'import', + 'php_import_ext' => 'ext', + 'php_import_headers' => 'headers' + ); + // first check if the field name is found + if (isset($fieldNames[$type])) + { + $type = $fieldNames[$type]; + } + else + { + return ''; + } + } + $script = array(); + if ('display' === $type) + { + // set the display script + $script['display'][] = "\tprotected \$headerList;"; + $script['display'][] = "\tprotected \$hasPackage = false;"; + $script['display'][] = "\tprotected \$headers;"; + $script['display'][] = "\tprotected \$hasHeader = 0;"; + $script['display'][] = "\tprotected \$dataType;"; + $script['display'][] = "\n\tpublic function display(\$tpl = null)"; + $script['display'][] = "\t{"; + $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; + $script['display'][] = "\t\t{"; + $script['display'][] = "\t\t\t// Include helper submenu"; + $script['display'][] = "\t\t\t[[[-#-#-Component]]]Helper::addSubmenu('import');"; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t\$paths = new stdClass;"; + $script['display'][] = "\t\t\$paths->first = '';"; + $script['display'][] = "\t\t\$state = \$this->get('state');"; + $script['display'][] = "\n\t\t\$this->paths = &\$paths;"; + $script['display'][] = "\t\t\$this->state = &\$state;"; + $script['display'][] = "\t\t// get global action permissions"; + $script['display'][] = "\t\t\$this->canDo = [[[-#-#-Component]]]Helper::getActions('import');"; + $script['display'][] = "\n\t\t// We don't need toolbar in the modal window."; + $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; + $script['display'][] = "\t\t{"; + $script['display'][] = "\t\t\t\$this->addToolbar();"; + $script['display'][] = "\t\t\t\$this->sidebar = JHtmlSidebar::render();"; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t// get the session object"; + $script['display'][] = "\t\t\$session = JFactory::getSession();"; + $script['display'][] = "\t\t// check if it has package"; + $script['display'][] = "\t\t\$this->hasPackage \t= \$session->get('hasPackage', false);"; + $script['display'][] = "\t\t\$this->dataType \t= \$session->get('dataType', false);"; + $script['display'][] = "\t\tif(\$this->hasPackage && \$this->dataType)"; + $script['display'][] = "\t\t{"; + $script['display'][] = "\t\t\t\$this->headerList \t= json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false),true);"; + $script['display'][] = "\t\t\t\$this->headers \t\t= [[[-#-#-Component]]]Helper::getFileHeaders(\$this->dataType);"; + $script['display'][] = "\t\t\t// clear the data type"; + $script['display'][] = "\t\t\t\$session->clear('dataType');"; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t// Check for errors."; + $script['display'][] = "\t\tif (count(\$errors = \$this->get('Errors'))){"; + $script['display'][] = "\t\t\tthrow new Exception(implode(".'"\n", $errors), 500);'; + $script['display'][] = "\t\t}"; + $script['display'][] = "\n\t\t// Display the template"; + $script['display'][] = "\t\tparent::display(\$tpl);"; + $script['display'][] = "\t}"; + } + elseif ('setdata' === $type) + { + // set the setdata script + $script['setdata'] = array(); + $script['setdata'][] = "\t/**"; + $script['setdata'][] = "\t* Set the data from the spreadsheet to the database"; + $script['setdata'][] = "\t*"; + $script['setdata'][] = "\t* @param string \$package Paths to the uploaded package file"; + $script['setdata'][] = "\t*"; + $script['setdata'][] = "\t* @return boolean false on failure"; + $script['setdata'][] = "\t*"; + $script['setdata'][] = "\t**/"; + $script['setdata'][] = "\tprotected function setData(\$package,\$table,\$target_headers)"; + $script['setdata'][] = "\t{"; + $script['setdata'][] = "\t\tif ([[[-#-#-Component]]]Helper::checkArray(\$target_headers))"; + $script['setdata'][] = "\t\t{"; + $script['setdata'][] = "\t\t\t// make sure the file is loaded\t\t"; + $script['setdata'][] = "\t\t\tJLoader::import('PHPExcel', JPATH_COMPONENT_ADMINISTRATOR . '/helpers');"; + $script['setdata'][] = "\t\t\t\$jinput = JFactory::getApplication()->input;"; + $script['setdata'][] = "\t\t\tforeach(\$target_headers as \$header)"; + $script['setdata'][] = "\t\t\t{"; + $script['setdata'][] = "\t\t\t\t\$data['target_headers'][\$header] = \$jinput->getString(\$header, null);"; + $script['setdata'][] = "\t\t\t}"; + $script['setdata'][] = "\t\t\t// set the data"; + $script['setdata'][] = "\t\t\tif(isset(\$package['dir']))"; + $script['setdata'][] = "\t\t\t{"; + $script['setdata'][] = "\t\t\t\t\$inputFileType = PHPExcel_IOFactory::identify(\$package['dir']);"; + $script['setdata'][] = "\t\t\t\t\$excelReader = PHPExcel_IOFactory::createReader(\$inputFileType);"; + $script['setdata'][] = "\t\t\t\t\$excelReader->setReadDataOnly(true);"; + $script['setdata'][] = "\t\t\t\t\$excelObj = \$excelReader->load(\$package['dir']);"; + $script['setdata'][] = "\t\t\t\t\$data['array'] = \$excelObj->getActiveSheet()->toArray(null, true,true,true);"; + $script['setdata'][] = "\t\t\t\t\$excelObj->disconnectWorksheets();"; + $script['setdata'][] = "\t\t\t\tunset(\$excelObj);"; + $script['setdata'][] = "\t\t\t\treturn \$this->save(\$data,\$table);"; + $script['setdata'][] = "\t\t\t}"; + $script['setdata'][] = "\t\t}"; + $script['setdata'][] = "\t\treturn false;"; + $script['setdata'][] = "\t}"; + } + elseif ('headers' === $type) + { + $script['headers'] = array(); + $script['headers'][] = "\t/**"; + $script['headers'][] = "\t* Method to get header."; + $script['headers'][] = "\t*"; + $script['headers'][] = "\t* @return mixed An array of data items on success, false on failure."; + $script['headers'][] = "\t*/"; + $script['headers'][] = "\tpublic function getExImPortHeaders()"; + $script['headers'][] = "\t{"; + $script['headers'][] = "\t\t// Get a db connection."; + $script['headers'][] = "\t\t\$db = JFactory::getDbo();"; + $script['headers'][] = "\t\t// get the columns"; + $script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__[[[-#-#-component]]]_[[[-#-#-view]]]\");"; + $script['headers'][] = "\t\tif ([[[-#-#-Component]]]Helper::checkArray(\$columns))"; + $script['headers'][] = "\t\t{"; + $script['headers'][] = "\t\t\t// remove the headers you don't import/export."; + $script['headers'][] = "\t\t\tunset(\$columns['asset_id']);"; + $script['headers'][] = "\t\t\tunset(\$columns['checked_out']);"; + $script['headers'][] = "\t\t\tunset(\$columns['checked_out_time']);"; + $script['headers'][] = "\t\t\t\$headers = new stdClass();"; + $script['headers'][] = "\t\t\tforeach (\$columns as \$column => \$type)"; + $script['headers'][] = "\t\t\t{"; + $script['headers'][] = "\t\t\t\t\$headers->{\$column} = \$column;"; + $script['headers'][] = "\t\t\t}"; + $script['headers'][] = "\t\t\treturn \$headers;"; + $script['headers'][] = "\t\t}"; + $script['headers'][] = "\t\treturn false;"; + $script['headers'][] = "\t}"; + } + elseif ('save' === $type) + { + $script['save'] = array(); + $script['save'][] = "\t/**"; + $script['save'][] = "\t* Save the data from the file to the database"; + $script['save'][] = "\t*"; + $script['save'][] = "\t* @param string \$package Paths to the uploaded package file"; + $script['save'][] = "\t*"; + $script['save'][] = "\t* @return boolean false on failure"; + $script['save'][] = "\t*"; + $script['save'][] = "\t**/"; + $script['save'][] = "\tprotected function save(\$data,\$table)"; + $script['save'][] = "\t{"; + $script['save'][] = "\t\t// import the data if there is any"; + $script['save'][] = "\t\tif([[[-#-#-Component]]]Helper::checkArray(\$data['array']))"; + $script['save'][] = "\t\t{"; + $script['save'][] = "\t\t\t// get user object"; + $script['save'][] = "\t\t\t\$user \t\t= JFactory::getUser();"; + $script['save'][] = "\t\t\t// remove header if it has headers"; + $script['save'][] = "\t\t\t\$id_key \t= \$data['target_headers']['id'];"; + $script['save'][] = "\t\t\t\$published_key \t= \$data['target_headers']['published'];"; + $script['save'][] = "\t\t\t\$ordering_key \t= \$data['target_headers']['ordering'];"; + $script['save'][] = "\t\t\t// get the first array set"; + $script['save'][] = "\t\t\t\$firstSet = reset(\$data['array']);"; + $script['save'][] = ""; + $script['save'][] = "\t\t\t// check if first array is a header array and remove if true"; + $script['save'][] = "\t\t\tif(\$firstSet[\$id_key] == 'id' || \$firstSet[\$published_key] == 'published' || \$firstSet[\$ordering_key] == 'ordering')"; + $script['save'][] = "\t\t\t{"; + $script['save'][] = "\t\t\t\tarray_shift(\$data['array']);"; + $script['save'][] = "\t\t\t}"; + $script['save'][] = "\t\t\t"; + $script['save'][] = "\t\t\t// make sure there is still values in array and that it was not only headers"; + $script['save'][] = "\t\t\tif([[[-#-#-Component]]]Helper::checkArray(\$data['array']) && \$user->authorise(\$table.'.import', 'com_[[[-#-#-component]]]') && \$user->authorise('core.import', 'com_[[[-#-#-component]]]'))"; + $script['save'][] = "\t\t\t{"; + $script['save'][] = "\t\t\t\t// set target."; + $script['save'][] = "\t\t\t\t\$target\t= array_flip(\$data['target_headers']);"; + $script['save'][] = "\t\t\t\t// Get a db connection."; + $script['save'][] = "\t\t\t\t\$db = JFactory::getDbo();"; + $script['save'][] = "\t\t\t\t// set some defaults"; + $script['save'][] = "\t\t\t\t\$todayDate\t\t= JFactory::getDate()->toSql();"; + $script['save'][] = "\t\t\t\t// get global action permissions"; + $script['save'][] = "\t\t\t\t\$canDo\t\t\t= [[[-#-#-Component]]]Helper::getActions(\$table);"; + $script['save'][] = "\t\t\t\t\$canEdit\t\t= \$canDo->get('core.edit');"; + $script['save'][] = "\t\t\t\t\$canState\t\t= \$canDo->get('core.edit.state');"; + $script['save'][] = "\t\t\t\t\$canCreate\t\t= \$canDo->get('core.create');"; + $script['save'][] = "\t\t\t\t\$hasAlias\t\t= \$this->getAliasesUsed(\$table);"; + $script['save'][] = "\t\t\t\t// prosses the data"; + $script['save'][] = "\t\t\t\tforeach(\$data['array'] as \$row)"; + $script['save'][] = "\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\$found = false;"; + $script['save'][] = "\t\t\t\t\tif (isset(\$row[\$id_key]) && is_numeric(\$row[\$id_key]) && \$row[\$id_key] > 0)"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t// raw items import & update!"; + $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; + $script['save'][] = "\t\t\t\t\t\t\$query"; + $script['save'][] = "\t\t\t\t\t\t\t->select('version')"; + $script['save'][] = "\t\t\t\t\t\t\t->from(\$db->quoteName('#__[[[-#-#-component]]]_'.\$table))"; + $script['save'][] = "\t\t\t\t\t\t\t->where(\$db->quoteName('id') . ' = '. \$db->quote(\$row[\$id_key]));"; + $script['save'][] = "\t\t\t\t\t\t// Reset the query using our newly populated query object."; + $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; + $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; + $script['save'][] = "\t\t\t\t\t\t\$found = \$db->getNumRows();"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t"; + $script['save'][] = "\t\t\t\t\tif(\$found && \$canEdit)"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t// update item"; + $script['save'][] = "\t\t\t\t\t\t\$id \t\t= \$row[\$id_key];"; + $script['save'][] = "\t\t\t\t\t\t\$version\t= \$db->loadResult();"; + $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; + $script['save'][] = "\t\t\t\t\t\t\$query \t\t= \$db->getQuery(true);"; + $script['save'][] = "\t\t\t\t\t\t\$fields \t= array();"; + $script['save'][] = "\t\t\t\t\t\t// Fields to update."; + $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; + $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update modified"; + $script['save'][] = "\t\t\t\t\t\t\tif ('modified_by' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update modified"; + $script['save'][] = "\t\t\t\t\t\t\tif ('modified' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update version"; + $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = (int) \$version + 1;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// verify publish authority"; + $script['save'][] = "\t\t\t\t\t\t\tif ('published' == \$target[\$key] && !\$canState)"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// set to update array"; + $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$cell;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . ' = ' . \$db->quote(\$cell);"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$fields[] = \$db->quoteName(\$target[\$key]) . \" = ''\";"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t// load the defaults"; + $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified_by') . ' = ' . \$db->quote(\$user->id);"; + $script['save'][] = "\t\t\t\t\t\t\$fields[]\t= \$db->quoteName('modified') . ' = ' . \$db->quote(\$todayDate);"; + $script['save'][] = "\t\t\t\t\t\t// Conditions for which records should be updated."; + $script['save'][] = "\t\t\t\t\t\t\$conditions = array("; + $script['save'][] = "\t\t\t\t\t\t\t\$db->quoteName('id') . ' = ' . \$id"; + $script['save'][] = "\t\t\t\t\t\t);"; + $script['save'][] = "\t\t\t\t\t\t"; + $script['save'][] = "\t\t\t\t\t\t\$query->update(\$db->quoteName('#__[[[-#-#-component]]]_'.\$table))->set(\$fields)->where(\$conditions);"; + $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; + $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\telseif (\$canCreate)"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t// insert item"; + $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; + $script['save'][] = "\t\t\t\t\t\t// reset all buckets"; + $script['save'][] = "\t\t\t\t\t\t\$columns \t= array();"; + $script['save'][] = "\t\t\t\t\t\t\$values \t= array();"; + $script['save'][] = "\t\t\t\t\t\t\$version\t= false;"; + $script['save'][] = "\t\t\t\t\t\t// Insert columns. Insert values."; + $script['save'][] = "\t\t\t\t\t\tforeach(\$row as \$key => \$cell)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t// ignore column"; + $script['save'][] = "\t\t\t\t\t\t\tif ('IGNORE' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// remove id"; + $script['save'][] = "\t\t\t\t\t\t\tif ('id' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update created"; + $script['save'][] = "\t\t\t\t\t\t\tif ('created_by' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update created"; + $script['save'][] = "\t\t\t\t\t\t\tif ('created' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\tcontinue;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// Make sure the alias is incremented"; + $script['save'][] = "\t\t\t\t\t\t\tif ('alias' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = \$this->getAlias(\$cell,\$table);"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// update version"; + $script['save'][] = "\t\t\t\t\t\t\tif ('version' == \$target[\$key])"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$cell = 1;"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$version = true;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\t// set to insert array"; + $script['save'][] = "\t\t\t\t\t\t\tif(in_array(\$key, \$data['target_headers']) && is_numeric(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$cell;"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_string(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \$db->quote(\$cell);"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t\telseif(in_array(\$key, \$data['target_headers']) && is_null(\$cell))"; + $script['save'][] = "\t\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\t// if import data is null then set empty"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$columns[] \t= \$target[\$key];"; + $script['save'][] = "\t\t\t\t\t\t\t\t\$values[] \t= \"''\";"; + $script['save'][] = "\t\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t// load the defaults"; + $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created_by';"; + $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$user->id);"; + $script['save'][] = "\t\t\t\t\t\t\$columns[] \t= 'created';"; + $script['save'][] = "\t\t\t\t\t\t\$values[] \t= \$db->quote(\$todayDate);"; + $script['save'][] = "\t\t\t\t\t\tif (!\$version)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\$columns[] \t= 'version';"; + $script['save'][] = "\t\t\t\t\t\t\t\$values[] \t= 1;"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t\t// Prepare the insert query."; + $script['save'][] = "\t\t\t\t\t\t\$query"; + $script['save'][] = "\t\t\t\t\t\t\t->insert(\$db->quoteName('#__[[[-#-#-component]]]_'.\$table))"; + $script['save'][] = "\t\t\t\t\t\t\t->columns(\$db->quoteName(\$columns))"; + $script['save'][] = "\t\t\t\t\t\t\t->values(implode(',', \$values));"; + $script['save'][] = "\t\t\t\t\t\t// Set the query using our newly populated query object and execute it."; + $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; + $script['save'][] = "\t\t\t\t\t\t\$done = \$db->execute();"; + $script['save'][] = "\t\t\t\t\t\tif (\$done)"; + $script['save'][] = "\t\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\t\t\$aId = \$db->insertid();"; + $script['save'][] = "\t\t\t\t\t\t\t// make sure the access of asset is set"; + $script['save'][] = "\t\t\t\t\t\t\t[[[-#-#-Component]]]Helper::setAsset(\$aId,\$table);"; + $script['save'][] = "\t\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t\telse"; + $script['save'][] = "\t\t\t\t\t{"; + $script['save'][] = "\t\t\t\t\t\treturn false;"; + $script['save'][] = "\t\t\t\t\t}"; + $script['save'][] = "\t\t\t\t}"; + $script['save'][] = "\t\t\t\treturn true;"; + $script['save'][] = "\t\t\t}"; + $script['save'][] = "\t\t}"; + $script['save'][] = "\t\treturn false;"; + $script['save'][] = "\t}"; + } + elseif ('view' === $type) + { + $script['view'] = array(); + $script['view'][] = ""; + $script['view'][] = ""; + $script['view'][] = "\n
"; + $script['view'][] = "
\" method=\"post\" name=\"adminForm\" id=\"adminForm\" class=\"form-horizontal form-validate\">"; + $script['view'][] = ""; + $script['view'][] = "\n\tsidebar)) : ?>"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t\tsidebar; ?>"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t"; + $script['view'][] = ""; + $script['view'][] = "\n\thasPackage && [[[-#-#-Component]]]Helper::checkArray(\$this->headerList) && [[[-#-#-Component]]]Helper::checkArray(\$this->headers)) : ?>"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\theaderList as \$name => \$title): ?>"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t\" onclick=\"Joomla.continueImport()\" />"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t"; + $script['view'][] = "\t\t 'upload')); ?>"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton()\" />    (.csv .xls .ods)"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\tstate->get('import.directory'); ?>\" />"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton3()\" />    (.csv .xls .ods)"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = ""; + $script['view'][] = "\n\t\t"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t\t\t"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\t"; + $script['view'][] = "\t\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t\t\t\" onclick=\"Joomla.submitbutton4()\" />    (.csv .xls .ods)"; + $script['view'][] = "\t\t\t\t
"; + $script['view'][] = "\t\t\t
"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t\t"; + $script['view'][] = "\t"; + $script['view'][] = "\t"; + $script['view'][] = "\t"; + $script['view'][] = ""; + $script['view'][] = "
"; + } + elseif ('import' === $type) + { + $script['import'] = array(); + $script['import'][] = "\t/**"; + $script['import'][] = "\t * Import an spreadsheet from either folder, url or upload."; + $script['import'][] = "\t *"; + $script['import'][] = "\t * @return boolean result of import"; + $script['import'][] = "\t *"; + $script['import'][] = "\t */"; + $script['import'][] = "\tpublic function import()"; + $script['import'][] = "\t{"; + $script['import'][] = "\t\t\$this->setState('action', 'import');"; + $script['import'][] = "\t\t\$app \t\t= JFactory::getApplication();"; + $script['import'][] = "\t\t\$session \t= JFactory::getSession();"; + $script['import'][] = "\t\t\$package \t= null;"; + $script['import'][] = "\t\t\$continue\t= false;"; + $script['import'][] = "\t\t// get import type"; + $script['import'][] = "\t\t\$this->getType = \$app->input->getString('gettype', NULL);"; + $script['import'][] = "\t\t// get import type"; + $script['import'][] = "\t\t\$this->dataType\t= \$session->get('dataType_VDM_IMPORTINTO', NULL);"; + $script['import'][] = "\n\t\tif (\$package === null)"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\tswitch (\$this->getType)"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t\tcase 'folder':"; + $script['import'][] = "\t\t\t\t\t// Remember the 'Import from Directory' path."; + $script['import'][] = "\t\t\t\t\t\$app->getUserStateFromRequest(\$this->_context . '.import_directory', 'import_directory');"; + $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromFolder();"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tcase 'upload':"; + $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUpload();"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tcase 'url':"; + $script['import'][] = "\t\t\t\t\t\$package = \$this->_getPackageFromUrl();"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tcase 'continue':"; + $script['import'][] = "\t\t\t\t\t\$continue \t= true;"; + $script['import'][] = "\t\t\t\t\t\$package\t= \$session->get('package', null);"; + $script['import'][] = "\t\t\t\t\t\$package\t= json_decode(\$package, true);"; + $script['import'][] = "\t\t\t\t\t// clear session"; + $script['import'][] = "\t\t\t\t\t\$session->clear('package');"; + $script['import'][] = "\t\t\t\t\t\$session->clear('dataType');"; + $script['import'][] = "\t\t\t\t\t\$session->clear('hasPackage');"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\n\t\t\t\tdefault:"; + $script['import'][] = "\t\t\t\t\t\$app->setUserState('com_[[[-#-#-component]]].message', JTe-#-#-xt::_('COM_[[[-#-#-COMPONENT]]]_IMPORT_NO_IMPORT_TYPE_FOUND'));"; + $script['import'][] = "\n\t\t\t\t\treturn false;"; + $script['import'][] = "\t\t\t\t\tbreak;"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\t// Was the package valid?"; + $script['import'][] = "\t\tif (!\$package || !\$package['type'])"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\tif (in_array(\$this->getType, array('upload', 'url')))"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t\t\$this->remove(\$package['packagename']);"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\n\t\t\t\$app->setUserState('com_[[[-#-#-component]]].message', JTe-#-#-xt::_('COM_[[[-#-#-COMPONENT]]]_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'));"; + $script['import'][] = "\t\t\treturn false;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\t"; + $script['import'][] = "\t\t// first link data to table headers"; + $script['import'][] = "\t\tif(!\$continue){"; + $script['import'][] = "\t\t\t\$package\t= json_encode(\$package);"; + $script['import'][] = "\t\t\t\$session->set('package', \$package);"; + $script['import'][] = "\t\t\t\$session->set('dataType', \$this->dataType);"; + $script['import'][] = "\t\t\t\$session->set('hasPackage', true);"; + $script['import'][] = "\t\t\treturn true;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\t// set the data"; + $script['import'][] = "\t\t\$headerList = json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false), true);"; + $script['import'][] = "\t\tif (!\$this->setData(\$package,\$this->dataType,\$headerList))"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\t// There was an error importing the package"; + $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::_('COM_[[[-#-#-COMPONENT]]]_IMPORT_ERROR');"; + $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; + $script['import'][] = "\t\t\tif (\$back)"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t\t\$app->setUserState('com_[[[-#-#-component]]].redirect_url', 'index.php?option=com_[[[-#-#-component]]]&view='.\$back);"; + $script['import'][] = "\t\t\t\t\$session->clear('backto_VDM_IMPORT');"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\t\t\t\$result = false;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\t\telse"; + $script['import'][] = "\t\t{"; + $script['import'][] = "\t\t\t// Package imported sucessfully"; + $script['import'][] = "\t\t\t\$msg = JTe-#-#-xt::sprintf('COM_[[[-#-#-COMPONENT]]]_IMPORT_SUCCESS', \$package['packagename']);"; + $script['import'][] = "\t\t\t\$back = \$session->get('backto_VDM_IMPORT', NULL);"; + $script['import'][] = "\t\t\tif (\$back)"; + $script['import'][] = "\t\t\t{"; + $script['import'][] = "\t\t\t \$app->setUserState('com_[[[-#-#-component]]].redirect_url', 'index.php?option=com_[[[-#-#-component]]]&view='.\$back);"; + $script['import'][] = "\t\t\t \$session->clear('backto_VDM_IMPORT');"; + $script['import'][] = "\t\t\t}"; + $script['import'][] = "\t\t\t\$result = true;"; + $script['import'][] = "\t\t}"; + $script['import'][] = "\n\t\t// Set some model state values"; + $script['import'][] = "\t\t\$app->enqueueMessage(\$msg);"; + $script['import'][] = "\n\t\t// remove file after import"; + $script['import'][] = "\t\t\$this->remove(\$package['packagename']);"; + $script['import'][] = "\t\t\$session->clear(\$this->getType.'_VDM_IMPORTHEADERS');"; + $script['import'][] = "\t\treturn \$result;"; + $script['import'][] = "\t}"; + } + elseif ('ext' === $type) + { + $script['ext'][] = "\t/**"; + $script['ext'][] = "\t * Check the extension"; + $script['ext'][] = "\t *"; + $script['ext'][] = "\t * @param string \$file Name of the uploaded file"; + $script['ext'][] = "\t *"; + $script['ext'][] = "\t * @return boolean True on success"; + $script['ext'][] = "\t *"; + $script['ext'][] = "\t */"; + $script['ext'][] = "\tprotected function checkExtension(\$file)"; + $script['ext'][] = "\t{"; + $script['ext'][] = "\t\t// check the extention"; + $script['ext'][] = "\t\tswitch(strtolower(pathinfo(\$file, PATHINFO_EXTENSION)))"; + $script['ext'][] = "\t\t{"; + $script['ext'][] = "\t\t\tcase 'xls':"; + $script['ext'][] = "\t\t\tcase 'ods':"; + $script['ext'][] = "\t\t\tcase 'csv':"; + $script['ext'][] = "\t\t\treturn true;"; + $script['ext'][] = "\t\t\tbreak;"; + $script['ext'][] = "\t\t}"; + $script['ext'][] = "\t\treturn false;"; + $script['ext'][] = "\t}"; + } + elseif ('routerparse' === $type) + { + $script['routerparse'][] = "\t\t\t\t// default script in switch for this view"; + $script['routerparse'][] = "\t\t\t\t\$vars['view'] = '[[[-#-#-sview]]]';"; + $script['routerparse'][] = "\t\t\t\tif (is_numeric(\$segments[\$count-1]))"; + $script['routerparse'][] = "\t\t\t\t{"; + $script['routerparse'][] = "\t\t\t\t\t\$vars['id'] = (int) \$segments[\$count-1];"; + $script['routerparse'][] = "\t\t\t\t}"; + $script['routerparse'][] = "\t\t\t\telseif (\$segments[\$count-1])"; + $script['routerparse'][] = "\t\t\t\t{"; + $script['routerparse'][] = "\t\t\t\t\t\$id = \$this->getVar('[[[-#-#-sview]]]', \$segments[\$count-1], 'alias', 'id');"; + $script['routerparse'][] = "\t\t\t\t\tif(\$id)"; + $script['routerparse'][] = "\t\t\t\t\t{"; + $script['routerparse'][] = "\t\t\t\t\t\t\$vars['id'] = \$id;"; + $script['routerparse'][] = "\t\t\t\t\t}"; + $script['routerparse'][] = "\t\t\t\t}"; + } + // return the needed script + if (isset($script[$type])) + { + return str_replace('-#-#-', '', implode("\n",$script[$type])); + } + return false; + } + + /** + * Run Global Updater if any are set + * + * @return void + * + */ + public static function runGlobalUpdater() + { + // check if any updates are set to run + if (self::checkArray(self::$globalUpdater)) + { + // get the database object + $db = JFactory::getDbo(); + foreach (self::$globalUpdater as $tableKeyID => $object) + { + // get the table + $table = explode('.', $tableKeyID); + // update the item + $db->updateObject('#__componentbuilder_' . (string) $table[0] , $object, (string) $table[1]); + } + // rest updater + self::$globalUpdater = array(); + } + } + + /** + * Copy Any Item (only use for direct database copying) + * + * @param int $id The item to copy + * @param string $table The table and model to copy from and with + * @param array $config The values that should change + * + * @return boolean True if success + * + */ + public static function copyItem($id, $type, $config = array()) + { + // only continue if we have an id + if ((int) $id > 0) + { + // get the model + $model = self::getModel($type); + $app = \JFactory::getApplication(); + // get item + if ($item = $model->getItem($id)) + { + // update values that should change + if (self::checkArray($config)) + { + foreach($config as $key => $value) + { + if (isset($item->{$key})) + { + $item->{$key} = $value; + } + } + } + // clone the object + $data = array(); + foreach ($item as $key => $value) + { + $data[$key] = $value; + } + // reset some values + $data['id'] = 0; + $data['version'] = 1; + if (isset($data['tags'])) + { + $data['tags'] = null; + } + if (isset($data['associations'])) + { + $data['associations'] = array(); + } + // remove some unneeded values + unset($data['params']); + unset($data['asset_id']); + unset($data['checked_out']); + unset($data['checked_out_time']); + // Attempt to save the data. + if ($model->save($data)) + { + return true; + } + } + } + return false; + } + /** * the basic localkey **/