@copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html Builds Complex Joomla Components /-----------------------------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); jimport('joomla.application.component.helper'); /** * Componentbuilder Ajax Model */ class ComponentbuilderModelAjax extends JModelList { protected $app_params; public function __construct() { parent::__construct(); // get params $this->app_params = JComponentHelper::getParams('com_componentbuilder'); } // Used in joomla_component /** * Check and if a vdm notice is new (per/user) **/ public function isNew($notice) { // first get the file path $path_filename = ComponentbuilderHelper::getFilePath('user', 'notice', JFactory::getUser()->username, $fileType = '.md', JPATH_COMPONENT_ADMINISTRATOR); // check if the file is set if (($content = @file_get_contents($path_filename)) !== FALSE) { if ($notice == $content) { return false; } } return true; } /** * set That a notice has been read (per/user) **/ public function isRead($notice) { // first get the file path $path_filename = ComponentbuilderHelper::getFilePath('user', 'notice', JFactory::getUser()->username, $fileType = '.md', JPATH_COMPONENT_ADMINISTRATOR); // set as read if not already set if (($content = @file_get_contents($path_filename)) !== FALSE) { if ($notice == $content) { return true; } } return $this->saveFile($notice,$path_filename); } protected function saveFile($data,$path_filename) { if (ComponentbuilderHelper::checkString($data)) { $fp = fopen($path_filename, 'w'); fwrite($fp, $data); fclose($fp); return true; } return false; } /** * get the component details (html) **/ public function getComponentDetails($id) { // Need to find the asset id by the name of the component. $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName(array( 'id','companyname','component_version','copyright','debug_linenr', 'description','email','image','license','name', 'short_description','website','author','add_placeholders', 'system_name','mvc_versiondate'))) ->from($db->quoteName('#__componentbuilder_joomla_component')) ->where($db->quoteName('id') . ' = ' . (int) $id); $db->setQuery($query); $db->execute(); if ($db->loadRowList()) { return array( 'html' => $this->componentDetailsDisplay($db->loadObject())); } return false; } /** * set the component display **/ protected function componentDetailsDisplay($object) { // set some vars $image = (ComponentbuilderHelper::checkString($object->image)) ? 'Joomla Component Image': ''; $desc = (ComponentbuilderHelper::checkString($object->description)) ? $object->description : $object->short_description; $placeholder = ($object->add_placeholders == 1) ? ' ' . JText::_('COM_COMPONENTBUILDER_YES') . ' ' : ' ' .JText::_('COM_COMPONENTBUILDER_NO') . ' ' ; $debug = ($object->debug_linenr == 1) ? ' ' .JText::_('COM_COMPONENTBUILDER_YES') . '' : ' ' .JText::_('COM_COMPONENTBUILDER_NO') . ' ' ; $html = array(); $html[] = '

' . $object->name . ' (v' . $object->component_version . ')

'; $html[] = '

' . $desc . $image . '

'; $html[] = ''; $html[] = '

' . JText::_('COM_COMPONENTBUILDER_COMPONENT_GLOBAL_SETTINGS') . '

'; $html[] = '

'; $html[] = JText::_('COM_COMPONENTBUILDER_ADD_CUSTOM_CODE_PLACEHOLDERS') . '
' . $placeholder . '
'; $html[] = JText::_('COM_COMPONENTBUILDER_DEBUG_LINE_NUMBERS') . '
' . $debug ; $html[] = '

'; $html[] = '

' . JText::_('COM_COMPONENTBUILDER_LICENSE') . '

'; $html[] = '

' . $object->license . '

'; $html[] = '

' . JText::_('COM_COMPONENTBUILDER_COPYRIGHT') . '

'; $html[] = '

' . $object->copyright . '

'; $html[] = ' ' . JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' .$object->system_name . '

'; // now return the diplay return implode("\n", $html); } // Used in admin_view public function getImportScripts($type) { $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// Check for errors."; $script['display'][] = "\t\tif (count(\$errors = \$this->get('Errors'))){"; $script['display'][] = "\t\t\tJError::raiseError(500, implode('
', \$errors));"; $script['display'][] = "\t\t\treturn false;"; $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// 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 ('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}"; } // return the needed script if (isset($script[$type])) { return str_replace('-#-#-', '', implode("\n",$script[$type])); } return false; } public function getFieldSelectOptions($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('a.xml', 'b.name'))); $query->from($db->quoteName('#__componentbuilder_field', 'a')); $query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'b') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('b.id') . ')'); $query->where($db->quoteName('a.published') . ' = 1'); $query->where($db->quoteName('a.id') . ' = '. (int) $id); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $result = $db->loadObject(); $result->name = strtolower($result->name); if (ComponentbuilderHelper::typeField($result->name,'list')) { // load the values form params $xml = json_decode($result->xml); $xmlOptions = ComponentbuilderHelper::getBetween($xml,'option="','"'); $optionSet = ''; if (strpos($xmlOptions,',') !== false) { // mulitpal options $options = explode(',',$xmlOptions); foreach ($options as $option) { // return both value and text if (ComponentbuilderHelper::checkString($optionSet)) { // no add to option set $optionSet .= "\n".$option; } else { // no add to option set $optionSet .= $option; } } } else { // return both value and text if (ComponentbuilderHelper::checkString($optionSet)) { // no add to option set $optionSet .= "\n".$xmlOptions; } else { // no add to option set $optionSet .= $xmlOptions; } } // return found field options return $optionSet; } elseif (ComponentbuilderHelper::typeField($result->name,'text')) { return "keywords=\"\"\nlength=\"\""; } elseif (ComponentbuilderHelper::typeField($result->name,'dynamic')) { return 'dynamic_list'; } elseif (ComponentbuilderHelper::typeField($result->name)) { return 'match field type not supported. Select another!'; } else { return 'dynamic_list'; } } return false; } public function getTableColumns($tableName) { // Get a db connection. $db = JFactory::getDbo(); // get the columns $columns = $db->getTableColumns("#__".$tableName); if (ComponentbuilderHelper::checkArray($columns)) { // build the return string $tableColumns = array(); foreach ($columns as $column => $type) { $tableColumns[] = $column . ' => ' . $column; } return implode("\n",$tableColumns); } return false; } // Used in template public function getTemplateDetails($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('a.alias','a.template','b.name'))); $query->from($db->quoteName('#__componentbuilder_template', 'a')); $query->join('LEFT', $db->quoteName('#__componentbuilder_dynamic_get', 'b') . ' ON (' . $db->quoteName('b.id') . ' = ' . $db->quoteName('a.dynamic_get') . ')'); $query->where($db->quoteName('a.id') . ' != '.(int) $id); $query->where($db->quoteName('a.published') . ' = 1'); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $results = $db->loadObjectList(); $templateString = array('

Template Code Snippets

'); foreach ($results as $result) { $templateString[] = "
dynamicGet: ".$result->name."
<?php echo \$this->loadTemplate('".ComponentbuilderHelper::safeString($result->alias)."'); ?>
"; } $templateString[] = "

"; return implode("\n",$templateString); } return false; } // Used in layout public function getSnippetDetails($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('name', 'heading', 'usage', 'description', 'type', 'snippet', 'url'))); $query->from($db->quoteName('#__componentbuilder_snippet')); $query->where($db->quoteName('published') . ' = 1'); $query->where($db->quoteName('id') . ' = '. (int) $id); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $model = ComponentbuilderHelper::getModel('snippets'); $snippet = $db->loadObject(); $snippet->type = JText::_($model->selectionTranslation($snippet->type,'type')); $snippet->snippet = base64_decode($snippet->snippet); // return found snippet settings return $snippet; } return false; } public function getDynamicValues($id,$view) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('getcustom', 'gettype', 'main_source', 'view_selection', 'db_selection', 'join_view_table', 'join_db_table', 'addcalculation', 'php_calculation'))); $query->from($db->quoteName('#__componentbuilder_dynamic_get')); $query->where($db->quoteName('published') . ' = 1'); $query->where($db->quoteName('id') . ' = '. (int) $id); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $result = $db->loadObject(); // reset buket $selections = array(); $selectionsList = array(); // get the main values (name) if ($result->main_source == 1) { $selections[] = explode("\n",$result->view_selection); } elseif ($result->main_source == 2) { $selections[] = explode("\n",$result->db_selection); } elseif ($result->main_source == 3) { return '

Custom get source! You will need to transpose the variables manually.

'; } // get the joined values (name) $join_view_table = json_decode($result->join_view_table,true); unset($result->join_view_table); if (ComponentbuilderHelper::checkArray($join_view_table)) { foreach ($join_view_table as $option => $values) { foreach ($values as $nr => $value) { $result->join_view_table[$nr][$option] = $value; } } } unset($join_view_table); $join_db_table = json_decode($result->join_db_table,true); unset($result->join_db_table); if (ComponentbuilderHelper::checkArray($join_db_table)) { foreach ($join_db_table as $option => $values) { foreach ($values as $nr => $value) { $result->join_db_table[$nr][$option] = $value; } } } unset($join_db_table); // now load the joined values to the selection set if (isset($result->join_view_table) && ComponentbuilderHelper::checkArray($result->join_view_table)) { foreach ($result->join_view_table as $join_view_table) { if ($join_view_table['row_type'] == '1') { $selections[] = explode("\n",$join_view_table['selection']); } elseif ($join_view_table['row_type'] == '2') { $names = $this->setListMethodName(array($join_view_table['on_field'],$join_view_table['join_field']),$join_view_table['view_table'],$join_view_table['as'],1); $selectionsList[implode('',$names)] = explode("\n",$join_view_table['selection']); } } unset($result->join_view_table); } if (isset($result->join_db_table) && ComponentbuilderHelper::checkArray($result->join_db_table)) { foreach ($result->join_db_table as $join_db_table) { if ($join_db_table['row_type'] == '1') { $selections[] = explode("\n",$join_db_table['selection']); } elseif ($join_db_table['row_type'] == '2') { $names = $this->setListMethodName(array($join_db_table['on_field'],$join_db_table['join_field']),$join_db_table['db_table'],$join_db_table['as'],2); $selectionsList[implode('',$names)] = explode("\n",$join_db_table['selection']); } } unset($result->join_db_table); } // get the calculation reult values (name) if ($result->addcalculation == 1) { $php_calculation = base64_decode($result->php_calculation); $phpSelections = ComponentbuilderHelper::getAllBetween($php_calculation,'cal__',' '); $selections[] = array_unique($phpSelections); unset($php_calculation); unset($phpSelections); unset($result->php_calculation); } // name the main var based on view if ($view == 'template') { switch ($result->gettype) { case 1: // single $buketName = 'this->item'; break; case 2: // list $buketName = 'this->items'; break; case 3: case 4: // custom $result->getcustom = ComponentbuilderHelper::safeString($result->getcustom); if (substr($result->getcustom, 0, strlen('get')) == 'get') { $varName = substr($result->getcustom, strlen('get')); } else { $varName = $result->getcustom; } $buketName = 'this->'.$varName; break; } } elseif ($view == 'layout') { $buketName = 'displayData'; } // now build the return values if (ComponentbuilderHelper::checkArray($selections)) { $buket = array(); switch ($result->gettype) { case 1: case 3: // single $ur = '<?php echo $'.$buketName; $cf = '; ?>'; break; case 2: case 4: // list $ur = '<?php echo $item'; $cf = '; ?>'; $buket[] = '<?php foreach ($'.$buketName.' as $item): ?>
'; break; } foreach ($selections as $selection) { if (ComponentbuilderHelper::checkArray($selection)) { foreach ($selection as $value) { if (strpos($value,'AS') !== false) { list($table,$key) = explode('AS',$value); $buket[] = ''.$ur.'->'.trim($key).$cf.''; } else { $buket[] = ''.$ur.'->'.trim($value).$cf.''; } } } } if (ComponentbuilderHelper::checkArray($selectionsList)) { $buket[] = '
'; foreach ($selectionsList as $name => $selectionList) { if (ComponentbuilderHelper::checkArray($selectionList)) { $ur = '<?php echo $'.$name; $cf = '; ?>'; $buket[] = '<?php foreach ($item->'.$name.' as $'.$name.'): ?>
'; foreach ($selectionList as $value) { if (strpos($value,'AS') !== false) { list($table,$key) = explode('AS',$value); $buket[] = ''.$ur.'->'.trim($key).$cf.''; } else { $buket[] = ''.$ur.'->'.trim($value).$cf.''; } } $buket[] = '
<?php endforeach; ?>
'; } } } switch ($result->gettype) { case 2: case 4: // list $buket[] = '
<?php endforeach; ?>'; break; } return implode(' ',$buket); } } return false; } public function getLayoutDetails($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('a.alias','a.layout','b.getcustom','b.gettype','b.name'))); $query->from($db->quoteName('#__componentbuilder_layout', 'a')); $query->join('LEFT', $db->quoteName('#__componentbuilder_dynamic_get', 'b') . ' ON (' . $db->quoteName('b.id') . ' = ' . $db->quoteName('a.dynamic_get') . ')'); $query->where($db->quoteName('a.id') . ' != '.(int) $id); $query->where($db->quoteName('a.published') . ' = 1'); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $results = $db->loadObjectList(); $layoutString = array('

Layout Code Snippets

'); foreach ($results as $result) { switch ($result->gettype) { case 1: // single $layoutString[] = "
dynamicGet: ".$result->name."
<?php echo JLayoutHelper::render('".ComponentbuilderHelper::safeString($result->alias)."', \$this->item); ?>
"; break; case 2: // list $layoutString[] = "
dynamicGet: ".$result->name."
<?php echo JLayoutHelper::render('".ComponentbuilderHelper::safeString($result->alias)."', \$this->items); ?>
"; break; case 3: case 4: // custom $result->getcustom = ComponentbuilderHelper::safeString($result->getcustom); if (substr($result->getcustom, 0, strlen('get')) == 'get') { $varName = substr($result->getcustom, strlen('get')); } else { $varName = $result->getcustom; } $layoutString[] = "
dynamicGet: ".$result->name."
<?php echo JLayoutHelper::render('".ComponentbuilderHelper::safeString($result->alias)."', \$this->".$varName."); ?>
"; break; } } $layoutString[] = "

"; return implode("\n",$layoutString); } return false; } public function getDynamicFormDetails($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('a.name','a.name_code','a.filterbuilder_map'))); $query->from($db->quoteName('#__componentbuilder_dynamic_form', 'a')); $query->where($db->quoteName('a.id') . ' != '.(int) $id); $query->where($db->quoteName('a.published') . ' = 1'); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $results = $db->loadObjectList(); $string = array('

Dynamic Form Links

'); foreach ($results as $result) { $dynamicIds = array(); $result->filterbuilder_map = base64_decode($result->filterbuilder_map); if (ComponentbuilderHelper::checkString($result->filterbuilder_map) && strpos($result->filterbuilder_map, PHP_EOL) !== false) { $filters = explode(PHP_EOL, $result->filterbuilder_map); if (ComponentbuilderHelper::checkArray($filters)) { foreach ($filters as $filter) { if (strpos($filter, 'Id') !== false || strpos($filter, 'id') !== false) { list($idkey, $dump) = explode('=>', $filter); $dynamicIds[] = "&".trim($idkey)."=<?php echo \$displayData->".trim($idkey)."; ?>"; } } } } $string[] = "
dynamicForm: ".$result->name."
<a href=\"index.php?option=com_[[[component]]]&task=form." . $result->name_code . implode('',$dynamicIds) ."&ref=compiler\">" . $result->name . "</a>
"; } $string[] = "

"; return implode("\n",$string); } return false; } protected function setListMethodName($names,$table,$as,$type) { $methodNames = array(); if (ComponentbuilderHelper::checkArray($names)) { foreach ($names as $nr => $name) { if (ComponentbuilderHelper::checkString($name)) { if (strpos($name,'.') !== false) { list($dump,$var) = explode('.',$name); } else { $var = $name; } if ($nr > 0) { $methodNames[] = ComponentbuilderHelper::safeString($var,'F'); } else { $methodNames[] = ComponentbuilderHelper::safeString($var); } } } } switch ($type) { // set view name case 1: $methodNames[] = ComponentbuilderHelper::safeString($this->getViewName($table),'F'); break; // set db name case 2: $methodNames[] = ComponentbuilderHelper::safeString($table,'F'); break; } // make sure there is uniqe method names $methodNames[] = ComponentbuilderHelper::safeString($as,'U'); return $methodNames; } protected function getViewName($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('name_single'))); $query->from($db->quoteName('#__componentbuilder_admin_view')); $query->where($db->quoteName('id') . ' = '. (int) $id); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { return $db->loadResult(); } return ''; } // Used in dynamic_get public function getViewTableColumns($id,$as,$type) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); $query->select($db->quoteName(array('addfields','name_single'))); $query->from($db->quoteName('#__componentbuilder_admin_view')); $query->where($db->quoteName('published') . ' = 1'); $query->where($db->quoteName('id') . ' = '. $id); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { $result = $db->loadObject(); $description = ''; if (1 == $type) { $tableName = ComponentbuilderHelper::safeString($result->name_single).'_'; } else { $tableName = ''; } $addfields = json_decode($result->addfields,true); if (ComponentbuilderHelper::checkArray($addfields)) { $fields = array(); // get data foreach ($addfields as $option => $values) { foreach ($values as $nr => $value) { if ($option == 'field') { $value = $this->getFieldData((int) $value); if (ComponentbuilderHelper::checkArray($value)) { $field[$nr] = $value; } } elseif ($option == 'alias') { if ($value == 1) { $name[$nr] = 'alias'; } else { $name[$nr] = ''; } } } } // add the basic defaults $fields[] = $as.".id AS ".$tableName."id"; $fields[] = $as.".asset_id AS ".$tableName."asset_id"; // load data foreach ($field as $n => $f) { if (ComponentbuilderHelper::checkArray($f)) { if (ComponentbuilderHelper::checkString($name[$n])) { $f['name'] = $name[$n]; } $fields[] = $as.".".$f['name']." AS ".$tableName.$f['name']; } } // add the basic defaults $fields[] = $as.".published AS ".$tableName."published"; $fields[] = $as.".created_by AS ".$tableName."created_by"; $fields[] = $as.".modified_by AS ".$tableName."modified_by"; $fields[] = $as.".created AS ".$tableName."created"; $fields[] = $as.".modified AS ".$tableName."modified"; $fields[] = $as.".version AS ".$tableName."version"; $fields[] = $as.".hits AS ".$tableName."hits"; if (0) { $fields[] = $as.".access AS ".$tableName."access"; } $fields[] = $as.".ordering AS ".$tableName."ordering"; $viewFields = $description.implode("\n",$fields); } return $viewFields; } return false; } protected function getFieldData($id) { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Order it by the ordering field. $query->select($db->quoteName(array('a.name','a.xml'))); $query->select($db->quoteName(array('c.name'),array('type_name'))); $query->from('#__componentbuilder_field AS a'); $query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'c') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('c.id') . ')'); $query->where($db->quoteName('a.id') . ' = '. $db->quote($id)); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); if ($db->getNumRows()) { // Load the results as a list of stdClass objects (see later for more options on retrieving data). $field = $db->loadObject(); // load the values form params $field->xml = json_decode($field->xml); $field->type_name = ComponentbuilderHelper::safeString($field->type_name); $load = true; // if category then name must be catid (only one per view) if ($field->type_name == 'category') { $name = 'catid'; } // if tag is set then enable all tag options for this view (only one per view) elseif ($field->type_name == 'tag') { $name = 'tags'; } // don't add spacers or notes elseif ($field->type_name == 'spacer' || $field->type_name == 'note') { // make sure the name is unique return false; } else { $name = ComponentbuilderHelper::safeString(ComponentbuilderHelper::getBetween($field->xml,'name="','"')); } // use field core name only if not found in xml if (!ComponentbuilderHelper::checkString($name)) { $name = ComponentbuilderHelper::safeString($field->name);; } return array('name' => $name, 'type' => $field->type_name); } return false; } public function getDbTableColumns($tableName,$as,$type) { // Get a db connection. $db = JFactory::getDbo(); // get the columns $columns = $db->getTableColumns("#__".$tableName); if (ComponentbuilderHelper::checkArray($columns)) { // build the return string $tableColumns = array(); foreach ($columns as $column => $type) { $tableColumns[] = $as.".".$column . ' AS ' . $column; } return implode("\n",$tableColumns); } return false; } // Used in custom_code public function checkFunctionName($name, $id) { $nameArray = (array) $this->splitAtUpperCase($name); $name = ComponentbuilderHelper::safeString(implode(' ', $nameArray), 'cA'); if ($found = ComponentbuilderHelper::getVar('custom_code', $name, 'function_name', 'id')) { if ((int) $id !== (int) $found) { return array ( 'message' => JText::_('COM_COMPONENTBUILDER_SORRY_THIS_FUNCTION_NAME_IS_ALREADY_IN_USE'), 'status' => 'danger'); } } return array ( 'name' => $name, 'message' => JText::_('COM_COMPONENTBUILDER_GREAT_THIS_FUNCTION_NAME_WILL_WORK'), 'status' => 'success'); } protected function splitAtUpperCase($string) { return preg_split('/(?=[A-Z])/', $string, -1, PREG_SPLIT_NO_EMPTY); } public function usedin($functioName, $id, $targeting) { // get the table being targeted if ($target = $this->getTableQueryOptions($targeting)) { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName($target['select'])) ->from($db->quoteName('#__componentbuilder_' . $target['table'])); $db->setQuery($query); $db->execute(); if ($db->loadRowList()) { $bucket = array(); $hugeDataSet = $db->loadAssocList(); foreach ($hugeDataSet as $data) { foreach ($data as $key => $value) { if ('id' !== $key && $target['name'] !== $key) { if (!isset($target['not_base64'][$key])) { $value = base64_decode($value); } // check if place holder set if (strpos($value, '[CUSTOMC' . 'ODE=' . (string) $functioName . ']') !== false || strpos($value, '[CUSTOMC' . 'ODE=' . (int) $id . ']') !== false || strpos($value, '[CUSTOMC' . 'ODE=' . (string) $functioName . '+') !== false || strpos($value, '[CUSTOMC' . 'ODE=' . (int) $id . '+') !== false) { // found it so add to bucket if (!isset($bucket[$data['id']])) { $bucket[$data['id']] = array(); $bucket[$data['id']]['name'] = $data[$target['name']]; $bucket[$data['id']]['fields'] = array(); } $bucket[$data['id']]['fields'][] = $key; } } } } // check if any values found if (ComponentbuilderHelper::checkArray($bucket)) { $usedin = array(); foreach ($bucket as $editId => $values) { $usedin[] = '' . $values['name'] . ' (' . implode(', ', $values['fields']) . ')'; } $html = '
  • ' . implode('
  • ', $usedin) . '
'; return array('in' => $html, 'id' => $targeting); } } } return false; } /** * Get the table query to search for function used in * * @param string $targe The table targeted * * @return array The query options * */ protected function getTableQueryOptions($target) { $query = array(); // #__componentbuilder_joomla_component as a $query['a'] = array(); $query['a']['table'] = 'joomla_component'; $query['a']['view'] = 'joomla_components'; $query['a']['select'] = array('id', 'system_name', 'php_preflight_install','php_postflight_install', 'php_preflight_update','php_postflight_update','php_method_uninstall', 'php_helper_admin','php_admin_event','php_helper_both','php_helper_site', 'php_site_event','php_dashboard_methods','dashboard_tab'); $query['a']['not_base64'] = array('dashboard_tab' => 'json'); $query['a']['name'] = 'system_name'; // #__componentbuilder_admin_view as b $query['b'] = array(); $query['b']['table'] = 'admin_view'; $query['b']['view'] = 'admin_views'; $query['b']['select'] = array('id', 'system_name', 'javascript_view_file','javascript_view_footer','javascript_views_file', 'javascript_views_footer','php_getitem','php_save','php_postsavehook','php_getitems', 'php_getitems_after_all','php_getlistquery','php_allowedit','php_before_delete', 'php_after_delete','php_before_publish','php_after_publish','php_batchcopy', 'php_batchmove','php_document','php_model','php_controller','php_import_display', 'php_import','php_import_setdata','php_import_save','html_import_view','php_ajaxmethod'); $query['b']['not_base64'] = array(); $query['b']['name'] = 'system_name'; // #__componentbuilder_custom_admin_view as c $query['c'] = array(); $query['c']['table'] = 'custom_admin_view'; $query['c']['view'] = 'custom_admin_views'; $query['c']['select'] = array('id', 'system_name', 'default','php_view','php_jview','php_jview_display','php_document', 'js_document','css_document','css','php_model','php_controller'); $query['c']['not_base64'] = array(); $query['c']['name'] = 'system_name'; // #__componentbuilder_site_view as d $query['d'] = array(); $query['d']['table'] = 'site_view'; $query['d']['view'] = 'site_views'; $query['d']['select'] = array('id', 'system_name', 'default','php_view','php_jview','php_jview_display','php_document', 'js_document','css_document','css','php_ajaxmethod','php_model','php_controller'); $query['d']['not_base64'] = array(); $query['d']['name'] = 'system_name'; // #__componentbuilder_field as e $query['e'] = array(); $query['e']['table'] = 'field'; $query['e']['view'] = 'fields'; $query['e']['select'] = array('id', 'name', 'xml','javascript_view_footer','javascript_views_footer'); $query['e']['not_base64'] = array('xml' => 'json'); $query['e']['name'] = 'name'; // #__componentbuilder_dynamic_get as f $query['f'] = array(); $query['f']['table'] = 'dynamic_get'; $query['f']['view'] = 'dynamic_gets'; $query['f']['select'] = array('id', 'name', 'php_before_getitem','php_after_getitem','php_before_getitems','php_after_getitems', 'php_getlistquery'); $query['f']['not_base64'] = array(); $query['f']['name'] = 'name'; // #__componentbuilder_template as g $query['g'] = array(); $query['g']['table'] = 'template'; $query['g']['view'] = 'templates'; $query['g']['select'] = array('id', 'name', 'php_view','template'); $query['g']['not_base64'] = array(); $query['g']['name'] = 'name'; // #__componentbuilder_layout as h $query['h'] = array(); $query['h']['table'] = 'layout'; $query['h']['view'] = 'layouts'; $query['h']['select'] = array('id', 'name', 'php_view','layout'); $query['h']['not_base64'] = array(); $query['h']['name'] = 'name'; // return the query string to search if (isset($query[$target])) { return $query[$target]; } return false; } // Used in field public function getFieldOptions($id) { if ($field = ComponentbuilderHelper::getFieldOptions($id, 'id')) { // return found field options return $field; } return false; } }