';";
$addModule[] = "\t\t\t\t\tbreak;";
$addModule[] = "\t\t\t\tcase 'array':";
$addModule[] = "\t\t\t\tcase 'Array':";
$addModule[] = "\t\t\t\t\treturn \$this->setModules[\$position];";
$addModule[] = "\t\t\t\t\tbreak;";
$addModule[] = "\t\t\t\tdefault:";
$addModule[] = "\t\t\t\t\treturn implode(' ', \$this->setModules[\$position]);";
$addModule[] = "\t\t\t\t\tbreak;";
$addModule[] = "\t\t\t\t";
$addModule[] = "\t\t\t}";
$addModule[] = "\t\t}";
$addModule[] = "\t\treturn false;";
$addModule[] = "\t}";
$this->fileContentDynamic[$view['settings']->code]['###'.$TARGET.'_GET_MODULE_JIMPORT###'] = "\njimport('joomla.application.module.helper');";
return implode("\n",$addModule);
}
$this->fileContentDynamic[$view['settings']->code]['###'.$TARGET.'_GET_MODULE_JIMPORT###'] = '';
return '';
}
protected function setCustomGetForm($view)
{
return '';
}
protected function setDocumentCustomPHP($view)
{
if ($view['settings']->add_php_document == 1)
{
$view['settings']->php_document = (array) explode("\n",$view['settings']->php_document);
if (ComponentbuilderHelper::checkArray($view['settings']->php_document))
{
return str_replace(array_keys($this->placeholders),array_values($this->placeholders),"\n\t\t".implode("\n\t\t",$view['settings']->php_document));
}
}
return '';
}
protected function setCustomButtons($view)
{
// ensure correct target is set
$TARGET = ComponentbuilderHelper::safeString($this->target,'U');
// set the custom buttons ###CUSTOM_BUTTONS_CONTROLLER###
$this->fileContentDynamic[$view['settings']->code]['###'.$TARGET.'_CUSTOM_BUTTONS_CONTROLLER###'] = '';
// set the custom buttons ###CUSTOM_BUTTONS_METHOD###
$this->fileContentDynamic[$view['settings']->code]['###'.$TARGET.'_CUSTOM_BUTTONS_METHOD###'] = '';
// if site add buttons to view
if ($this->target == 'site')
{
// set the custom buttons ###SITE_TOP_BUTTON###
$this->fileContentDynamic[$view['settings']->code]['###SITE_TOP_BUTTON###'] = '';
// set the custom buttons ###SITE_BOTTOM_BUTTON###
$this->fileContentDynamic[$view['settings']->code]['###SITE_BOTTOM_BUTTON###'] = '';
// load into place
switch ($view['settings']->button_position)
{
case 1:
// set buttons to top right of the view
$this->fileContentDynamic[$view['settings']->code]['###SITE_TOP_BUTTON###'] = '
toolbar->render(); ?>
';
break;
case 2:
// set buttons to top left of the view
$this->fileContentDynamic[$view['settings']->code]['###SITE_TOP_BUTTON###'] = 'toolbar->render(); ?>';
break;
case 3:
// set buttons to buttom right of the view
$this->fileContentDynamic[$view['settings']->code]['###SITE_BOTTOM_BUTTON###'] = '
toolbar->render(); ?>
';
break;
case 4:
// set buttons to buttom left of the view
$this->fileContentDynamic[$view['settings']->code]['###SITE_BOTTOM_BUTTON###'] = 'toolbar->render(); ?>';
break;
case 5:
// set buttons to buttom left of the view
$this->placeholders['[[[SITE_TOOLBAR]]]'] = 'toolbar->render(); ?>';
break;
}
}
// check if custom button should be added
if (isset($view['settings']->add_custom_button) && $view['settings']->add_custom_button == 1)
{
if (ComponentbuilderHelper::checkArray($view['settings']->custom_buttons))
{
$buttons = array();
foreach ($view['settings']->custom_buttons as $custom_button)
{
if ($custom_button['target'] != 2 || $this->target == 'site')
{
// Load to lang
$keyLang = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($custom_button['name'],'U');
$keyCode = ComponentbuilderHelper::safeString($custom_button['name']);
$this->langContent[$this->lang][$keyLang] = trim($custom_button['name']);
// add cpanel button
$buttons[] = "\t\tif (\$this->canDo->get('".$view['settings']->code.".".$keyCode."'))";
$buttons[] = "\t\t{";
$buttons[] = "\t\t\t//".$this->setLine(__LINE__)." add ".$custom_button['name']." button.";
$buttons[] = "\t\t\tJToolBarHelper::custom('".$view['settings']->code.".".$custom_button['method']."', '".$custom_button['icomoon']."', '', '".$keyLang."', false);";
$buttons[] = "\t\t}";
}
}
if (ComponentbuilderHelper::checkArray($buttons))
{
if (ComponentbuilderHelper::checkString($view['settings']->php_controller))
{
// set the custom buttons ###CUSTOM_BUTTONS_CONTROLLER###
$this->fileContentDynamic[$view['settings']->code]['###'.$TARGET.'_CUSTOM_BUTTONS_CONTROLLER###'] =
"\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$view['settings']->php_controller);
if ('site' == $this->target)
{
// add the controller for this view
// build the file
$target = array($this->target => $view['settings']->code);
$this->buildDynamique($target,'custom_form');
###GET_FORM_CUSTOM###
}
}
if (ComponentbuilderHelper::checkString($view['settings']->php_model))
{
// set the custom buttons ###CUSTOM_BUTTONS_METHOD###
$this->fileContentDynamic[$view['settings']->code]['###'.$TARGET.'_CUSTOM_BUTTONS_METHOD###'] =
"\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$view['settings']->php_model);
}
return "\n".implode("\n",$buttons);
}
}
}
return '';
}
protected function setCustomCSS($view)
{
if ($view['settings']->add_css == 1)
{
if (ComponentbuilderHelper::checkString($view['settings']->css))
{
return str_replace(array_keys($this->placeholders),array_values($this->placeholders),$view['settings']->css);
}
}
return '';
}
protected function setDocumentCustomCSS($view)
{
if ($view['settings']->add_css_document == 1)
{
$view['settings']->css_document = (array) explode("\n",$view['settings']->css_document);
if (ComponentbuilderHelper::checkArray($view['settings']->css_document))
{
$script = "\n\t\t//".$this->setLine(__LINE__)." Set the Custom CSS script to view\n\t\t".'$this->document->addStyleDeclaration("';
$cssDocument = str_replace('"', '\"', implode("\n\t\t\t",$view['settings']->css_document));
return $script.str_replace(array_keys($this->placeholders),array_values($this->placeholders),"\n\t\t\t".$cssDocument)."\n\t\t".'");';
}
}
return '';
}
protected function setDocumentCustomJS($view)
{
if ($view['settings']->add_js_document == 1)
{
$view['settings']->js_document = (array) explode("\n",$view['settings']->js_document);
if (ComponentbuilderHelper::checkArray($view['settings']->js_document))
{
$script = "\n\t\t//".$this->setLine(__LINE__)." Set the Custom JS script to view\n\t\t".'$this->document->addScriptDeclaration("';
$jsDocument = str_replace('"', '\"', implode("\n\t\t\t",$view['settings']->js_document));
return $script.str_replace(array_keys($this->placeholders),array_values($this->placeholders),"\n\t\t\t".$jsDocument)."\n\t\t".'");';
}
}
return '';
}
protected function setFootableScriptsLoader($view)
{
if (isset($this->footableScripts[$this->target][$view['settings']->code]) && $this->footableScripts[$this->target][$view['settings']->code])
{
return $this->setFootableScripts(false,'$this->document');
}
return '';
}
protected function setDocumentMetadata($view)
{
if ($view['settings']->main_get->gettype == 1 && $view['metadata'] == 1)
{
return $this->setMetadataItem();
}
elseif ($view['metadata'] == 1)
{
// lets check if we have a custom get method that has the same name as the view
// if we do then it posibly can be that the metadata is loaded via that method
// and we can load the full metadata structure with its vars
if (isset($view['settings']->custom_get) && ComponentbuilderHelper::checkArray($view['settings']->custom_get))
{
$found = false;
$searchFor = 'get'.$view['settings']->Code;
foreach ($view['settings']->custom_get as $custom_get)
{
if ($searchFor == $custom_get->getcustom)
{
$found = true;
break;
}
}
// now lets see
if ($found)
{
return $this->setMetadataItem($view['settings']->code);
}
else
{
return $this->setMetadataList();
}
}
else
{
return $this->setMetadataList();
}
}
return '';
}
protected function setMetadataItem($item = 'item')
{
$meta = array();
$meta[] = "\n\t\t//".$this->setLine(__LINE__)." load the meta description";
$meta[] = "\t\tif (isset(\$this->".$item."->metadesc) && \$this->".$item."->metadesc)";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setDescription(\$this->".$item."->metadesc);";
$meta[] = "\t\t}";
$meta[] = "\t\telseif (\$this->params->get('menu-meta_description'))";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setDescription(\$this->params->get('menu-meta_description'));";
$meta[] = "\t\t}";
$meta[] = "\t\t//".$this->setLine(__LINE__)." load the key words if set";
$meta[] = "\t\tif (isset(\$this->".$item."->metakey) && \$this->".$item."->metakey)";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetadata('keywords', \$this->".$item."->metakey);";
$meta[] = "\t\t}";
$meta[] = "\t\telseif (\$this->params->get('menu-meta_keywords'))";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetadata('keywords', \$this->params->get('menu-meta_keywords'));";
$meta[] = "\t\t}";
$meta[] = "\t\t//".$this->setLine(__LINE__)." check the robot params";
$meta[] = "\t\tif (isset(\$this->".$item."->robots) && \$this->".$item."->robots)";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetadata('robots', \$this->".$item."->robots);";
$meta[] = "\t\t}";
$meta[] = "\t\telseif (\$this->params->get('robots'))";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetadata('robots', \$this->params->get('robots'));";
$meta[] = "\t\t}";
$meta[] = "\t\t//".$this->setLine(__LINE__)." check if autor is to be set";
$meta[] = "\t\tif (isset(\$this->".$item."->created_by) && \$this->params->get('MetaAuthor') == '1')";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetaData('author', \$this->".$item."->created_by);";
$meta[] = "\t\t}";
$meta[] = "\t\t//".$this->setLine(__LINE__)." check if metadata is available";
$meta[] = "\t\tif (isset(\$this->".$item."->metadata) && \$this->".$item."->metadata)";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$mdata = json_decode(\$this->".$item."->metadata,true);";
$meta[] = "\t\t\tforeach (\$mdata as \$k => \$v)";
$meta[] = "\t\t\t{";
$meta[] = "\t\t\t\tif (\$v)";
$meta[] = "\t\t\t\t{";
$meta[] = "\t\t\t\t\t\$this->document->setMetadata(\$k, \$v);";
$meta[] = "\t\t\t\t}";
$meta[] = "\t\t\t}";
$meta[] = "\t\t}";
return implode("\n",$meta);
}
protected function setMetadataList()
{
$meta = array();
$meta[] = "\n\t\t//".$this->setLine(__LINE__)." load the meta description";
$meta[] = "\t\tif (\$this->params->get('menu-meta_description'))";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setDescription(\$this->params->get('menu-meta_description'));";
$meta[] = "\t\t}";
$meta[] = "\t\t//".$this->setLine(__LINE__)." load the key words if set";
$meta[] = "\t\tif (\$this->params->get('menu-meta_keywords'))";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetadata('keywords', \$this->params->get('menu-meta_keywords'));";
$meta[] = "\t\t}";
$meta[] = "\t\t//".$this->setLine(__LINE__)." check the robot params";
$meta[] = "\t\tif (\$this->params->get('robots'))";
$meta[] = "\t\t{";
$meta[] = "\t\t\t\$this->document->setMetadata('robots', \$this->params->get('robots'));";
$meta[] = "\t\t}";
return implode("\n",$meta);
}
protected function setGoogleChartLoader($view)
{
if (isset($this->googleChart[$this->target][$view['settings']->code]) && $this->googleChart[$this->target][$view['settings']->code])
{
$chart = array();
$chart[] = "\n\n\t\t//".$this->setLine(__LINE__)." add the google chart builder class.";
$chart[] = "\t\trequire_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/chartbuilder.php';";
$chart[] = "\t\t//".$this->setLine(__LINE__)." load the google chart js.";
$chart[] = "\t\t\$this->document->addScript(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/js/google.jsapi.js');";
$chart[] = "\t\t\$this->document->addScript('https://canvg.googlecode.com/svn/trunk/rgbcolor.js');";
$chart[] = "\t\t\$this->document->addScript('https://canvg.googlecode.com/svn/trunk/canvg.js');";
return implode("\n",$chart);
}
return '';
}
protected function setUikitLoader($view)
{
// reset buktes
$setter = '';
$loader['css'] = array();
$loader['js'] = array();
// allways load these in
$setter .= "\n\n\t\t//".$this->setLine(__LINE__)." always make sure jquery is loaded.";
$setter .= "\n\t\tJHtml::_('jquery.framework');";
$setter .= "\n\t\t//".$this->setLine(__LINE__)." Load the header checker class.";
$setter .= "\n\t\trequire_once( JPATH_COMPONENT_SITE.'/helpers/headercheck.php' );";
$setter .= "\n\t\t//".$this->setLine(__LINE__)." Initialize the header checker.";
$setter .= "\n\t\t\$HeaderCheck = new HeaderCheck;";
// load the defaults needed
if ($this->uikit)
{
$setter .= "\n\n\t\t//".$this->setLine(__LINE__)." Load uikit options.";
$setter .= "\n\t\t\$uikit = \$this->params->get('uikit_load');";
$setter .= "\n\t\t//".$this->setLine(__LINE__)." Set script size.";
$setter .= "\n\t\t\$size = \$this->params->get('uikit_min');";
$setter .= "\n\t\t//".$this->setLine(__LINE__)." Set css style.";
$setter .= "\n\t\t\$style = \$this->params->get('uikit_style');";
$setter .= "\n\n\t\t//".$this->setLine(__LINE__)." The uikit css.";
$setter .= "\n\t\tif ((!\$HeaderCheck->css_loaded('uikit.min') || \$uikit == 1) && \$uikit != 2 && \$uikit != 3)";
$setter .= "\n\t\t{";
$setter .= "\n\t\t\t\$this->document->addStyleSheet(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/uikit/css/uikit'.\$style.\$size.'.css');";
$setter .= "\n\t\t}";
$setter .= "\n\t\t//".$this->setLine(__LINE__)." The uikit js.";
$setter .= "\n\t\tif ((!\$HeaderCheck->js_loaded('uikit.min') || \$uikit == 1) && \$uikit != 2 && \$uikit != 3)";
$setter .= "\n\t\t{";
$setter .= "\n\t\t\t\$this->document->addScript(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/uikit/js/uikit'.\$size.'.js');";
$setter .= "\n\t\t}";
}
// load the components need
if ($this->uikit && isset($this->uikitComp[$view['settings']->code]) && ComponentbuilderHelper::checkArray($this->uikitComp[$view['settings']->code]))
{
$setter .= "\n\n\t\t//".$this->setLine(__LINE__)." Load the script to find all uikit components needed.";
$setter .= "\n\t\tif (\$uikit != 2)";
$setter .= "\n\t\t{";
$setter .= "\n\t\t\t//".$this->setLine(__LINE__)." Set the default uikit components in this view.";
$setter .= "\n\t\t\t\$uikitComp = array();";
foreach ($this->uikitComp[$view['settings']->code] as $class)
{
$setter .= "\n\t\t\t\$uikitComp[] = '".$class."';";
}
// check content for more needed components
if (isset($this->siteFieldData['uikit'][$view['settings']->code]) && ComponentbuilderHelper::checkArray($this->siteFieldData['uikit'][$view['settings']->code]))
{
$setter .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Get field uikit components needed in this view.";
$setter .= "\n\t\t\t\$uikitFieldComp = \$this->get('UikitComp');";
$setter .= "\n\t\t\tif (isset(\$uikitFieldComp) && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$uikitFieldComp))";
$setter .= "\n\t\t\t{";
$setter .= "\n\t\t\t\tif (isset(\$uikitComp) && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$uikitComp))";
$setter .= "\n\t\t\t\t{";
$setter .= "\n\t\t\t\t\t\$uikitComp = array_merge(\$uikitComp, \$uikitFieldComp);";
$setter .= "\n\t\t\t\t\t\$uikitComp = array_unique(\$uikitComp);";
$setter .= "\n\t\t\t\t}";
$setter .= "\n\t\t\t\telse";
$setter .= "\n\t\t\t\t{";
$setter .= "\n\t\t\t\t\t\$uikitComp = \$uikitFieldComp;";
$setter .= "\n\t\t\t\t}";
$setter .= "\n\t\t\t}";
}
$setter .= "\n\t\t}";
$setter .= "\n\n\t\t//".$this->setLine(__LINE__)." Load the needed uikit components in this view.";
$setter .= "\n\t\tif (\$uikit != 2 && isset(\$uikitComp) && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$uikitComp))";
$setter .= "\n\t\t{";
$setter .= "\n\t\t\t//".$this->setLine(__LINE__)." load just in case.";
$setter .= "\n\t\t\tjimport('joomla.filesystem.file');";
$setter .= "\n\t\t\t//".$this->setLine(__LINE__)." loading...";
$setter .= "\n\t\t\tforeach (\$uikitComp as \$class)";
$setter .= "\n\t\t\t{";
$setter .= "\n\t\t\t\tforeach (".$this->fileContentStatic['###Component###']."Helper::\$uk_components[\$class] as \$name)";
$setter .= "\n\t\t\t\t{";
$setter .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." check if the CSS file exists.";
$setter .= "\n\t\t\t\t\tif (JFile::exists(JPATH_ROOT.'/media/com_".$this->fileContentStatic['###component###']."/uikit/css/components/'.\$name.\$style.\$size.'.css'))";
$setter .= "\n\t\t\t\t\t{";
$setter .= "\n\t\t\t\t\t\t//".$this->setLine(__LINE__)." load the css.";
$setter .= "\n\t\t\t\t\t\t\$this->document->addStyleSheet(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/uikit/css/components/'.\$name.\$style.\$size.'.css');";
$setter .= "\n\t\t\t\t\t}";
$setter .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." check if the JavaScript file exists.";
$setter .= "\n\t\t\t\t\tif (JFile::exists(JPATH_ROOT.'/media/com_".$this->fileContentStatic['###component###']."/uikit/js/components/'.\$name.\$size.'.js'))";
$setter .= "\n\t\t\t\t\t{";
$setter .= "\n\t\t\t\t\t\t//".$this->setLine(__LINE__)." load the js.";
$setter .= "\n\t\t\t\t\t\t\$this->document->addScript(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/uikit/js/components/'.\$name.\$size.'.js');";
$setter .= "\n\t\t\t\t\t}";
$setter .= "\n\t\t\t\t}";
$setter .= "\n\t\t\t}";
$setter .= "\n\t\t}";
}
elseif ($this->uikit && ComponentbuilderHelper::checkArray($this->siteFieldData['uikit'][$view['settings']->code]))
{
$setter .= "\n\n\t\t//".$this->setLine(__LINE__)." Load the needed uikit components in this view.";
$setter .= "\n\t\t\$uikitComp = \$this->get('UikitComp');";
$setter .= "\n\t\tif (\$uikit != 2 && isset(\$uikitComp) && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$uikitComp))";
$setter .= "\n\t\t{";
$setter .= "\n\t\t\t//".$this->setLine(__LINE__)." load just in case.";
$setter .= "\n\t\t\tjimport('joomla.filesystem.file');";
$setter .= "\n\t\t\t//".$this->setLine(__LINE__)." loading...";
$setter .= "\n\t\t\tforeach (\$uikitComp as \$class)";
$setter .= "\n\t\t\t{";
$setter .= "\n\t\t\t\tforeach (".$this->fileContentStatic['###Component###']."Helper::\$uk_components[\$class] as \$name)";
$setter .= "\n\t\t\t\t{";
$setter .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." check if the CSS file exists.";
$setter .= "\n\t\t\t\t\tif (JFile::exists(JPATH_ROOT.'/media/com_".$this->fileContentStatic['###component###']."/uikit/css/components/'.\$name.\$style.\$size.'.css'))";
$setter .= "\n\t\t\t\t\t{";
$setter .= "\n\t\t\t\t\t\t//".$this->setLine(__LINE__)." load the css.";
$setter .= "\n\t\t\t\t\t\t\$this->document->addStyleSheet(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/uikit/css/components/'.\$name.\$style.\$size.'.css');";
$setter .= "\n\t\t\t\t\t}";
$setter .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." check if the JavaScript file exists.";
$setter .= "\n\t\t\t\t\tif (JFile::exists(JPATH_ROOT.'/media/com_".$this->fileContentStatic['###component###']."/uikit/js/components/'.\$name.\$size.'.js'))";
$setter .= "\n\t\t\t\t\t{";
$setter .= "\n\t\t\t\t\t\t//".$this->setLine(__LINE__)." load the js.";
$setter .= "\n\t\t\t\t\t\t\$this->document->addScript(JURI::root(true) .'/media/com_".$this->fileContentStatic['###component###']."/uikit/js/components/'.\$name.\$size.'.js');";
$setter .= "\n\t\t\t\t\t}";
$setter .= "\n\t\t\t\t}";
$setter .= "\n\t\t\t}";
$setter .= "\n\t\t}";
}
return $setter;
}
protected function setCustomViewExtraDisplayMethods(&$view)
{
if ($view['settings']->add_php_jview == 1)
{
return str_replace(array_keys($this->placeholders),array_values($this->placeholders),"\n\n".$view['settings']->php_jview);
}
return '';
}
protected function setCustomViewBody(&$view)
{
if (ComponentbuilderHelper::checkString($view['settings']->default))
{
if ($view['settings']->main_get->gettype == 2 && $view['settings']->main_get->pagination == 1)
{
// build body
$body = array();
// add limit box
if (strpos($view['settings']->default, '[[[LIMITBOX]]]') !== false)
{
$this->placeholders['[[[LIMITBOX]]]'] = 'pagination->getLimitBox(); ?>';
}
$body[] = str_replace(array_keys($this->placeholders),array_values($this->placeholders),$view['settings']->default);
$body[] = "\n".'items) && '.$this->fileContentStatic['###component###'].'Helper::checkArray($this->items) && count($this->items) > 4): ?>';
$body[] = '';
$body[] = '';
return implode("\n",$body);
}
else
{
return "\n". str_replace(array_keys($this->placeholders),array_values($this->placeholders),$view['settings']->default);
}
}
return '';
}
protected function setCustomViewCodeBody(&$view)
{
if ($view['settings']->add_php_view == 1)
{
$view['settings']->php_view = (array) explode("\n",$view['settings']->php_view);
if (ComponentbuilderHelper::checkArray($view['settings']->php_view))
{
return str_replace(array_keys($this->placeholders),array_values($this->placeholders),"\n\n".implode("\n",$view['settings']->php_view));
}
}
return '';
}
protected function setCustomViewTemplateBody(&$view)
{
if (isset($this->templateData[$this->target][$view['settings']->code]) && ComponentbuilderHelper::checkArray($this->templateData[$this->target][$view['settings']->code]))
{
foreach ($this->templateData[$this->target][$view['settings']->code] as $template => $data)
{
// build the file
$target = array($this->target => $view['settings']->code);
$this->buildDynamique($target,'template',$template);
// set the file data
$TARGET = ComponentbuilderHelper::safeString($this->target,'U');
// ###SITE_TEMPLATE_BODY### <<>>
$this->fileContentDynamic[$view['settings']->code.'_'.$template]['###'.$TARGET.'_TEMPLATE_BODY###'] = "\n" . str_replace(array_keys($this->placeholders),array_values($this->placeholders),$data['html']);
// ###SITE_TEMPLATE_CODE_BODY### <<>>
$this->fileContentDynamic[$view['settings']->code.'_'.$template]['###'.$TARGET.'_TEMPLATE_CODE_BODY###'] = $this->setCustomViewTemplateCode($data['php_view']);
}
}
}
protected function setCustomViewTemplateCode(&$php)
{
if (ComponentbuilderHelper::checkString($php))
{
$php_view = (array) explode("\n",$php);
if (ComponentbuilderHelper::checkArray($php_view))
{
$php_view = "\n\n".implode("\n",$php_view);
return str_replace(array_keys($this->placeholders),array_values($this->placeholders),$php_view);
}
}
return '';
}
protected function setCustomViewLayouts()
{
if (isset($this->layoutData[$this->target]) && ComponentbuilderHelper::checkArray($this->layoutData[$this->target]))
{
foreach ($this->layoutData[$this->target] as $layout => $data)
{
// build the file
$target = array($this->target => $layout);
$this->buildDynamique($target,'layout');
// set the file data
$TARGET = ComponentbuilderHelper::safeString($this->target,'U');
// ###SITE_LAYOUT_CODE### <<>>
$php_view = (array) explode("\n",$data['php_view']);
if (ComponentbuilderHelper::checkArray($php_view))
{
$php_view = "\n\n".implode("\n",$php_view);
$this->fileContentDynamic[$layout]['###'.$TARGET.'_LAYOUT_CODE###'] = str_replace(array_keys($this->placeholders),array_values($this->placeholders),$php_view);
}
else
{
$this->fileContentDynamic[$layout]['###'.$TARGET.'_LAYOUT_CODE###'] = '';
}
// ###SITE_LAYOUT_BODY### <<>>
$this->fileContentDynamic[$layout]['###'.$TARGET.'_LAYOUT_BODY###'] = "\n" . str_replace(array_keys($this->placeholders),array_values($this->placeholders),$data['html']);
}
}
}
protected function getReplacementNames()
{
foreach ($this->newFiles as $type => $files)
{
foreach ($files as $view => $file)
{
if (isset($file['path']) && ComponentbuilderHelper::checkArray($file))
{
if (JFile::exists($file['path']))
{
$string = file_get_contents($file['path']);
$buket['static'][] = $this->getInbetweenStrings($string);
}
}
elseif (ComponentbuilderHelper::checkArray($file))
{
foreach ($file as $nr => $doc)
{
if (ComponentbuilderHelper::checkArray($doc))
{
if (JFile::exists($doc['path']))
{
$string = file_get_contents($doc['path']);
$buket[$view][] = $this->getInbetweenStrings($string);
}
}
}
}
}
}
foreach ($buket as $type => $array)
{
foreach ($array as $replacments)
{
$replacments = array_unique($replacments);
foreach ($replacments as $replacment)
{
if ($type != 'static')
{
//var_dump($replacment); echo "\n";
$echos[$replacment] = "###".$replacment."### ";
}
elseif ($type == 'static')
{
//var_dump($replacment); echo "\n";
$echos[$replacment] = "###".$replacment."### ";
}
}
}
}
foreach ($echos as $echo)
{
echo $echo.' ';
}
}
protected function updateFiles()
{
if (isset($this->newFiles['static']) && ComponentbuilderHelper::checkArray($this->newFiles['static']) && isset($this->newFiles['dynamic']) && ComponentbuilderHelper::checkArray($this->newFiles['dynamic']))
{
// get the bom file
$bom = JFile::read($this->bomPath);
// first we do the static files
foreach ($this->newFiles['static'] as $static)
{
if (JFile::exists($static['path']))
{
$this->fileContentStatic['###FILENAME###'] = $static['name'];
$php = '';
if (ComponentbuilderHelper::checkFileType($static['name'],'php'))
{
$php = "fileContentStatic),array_values($this->fileContentStatic),$php.$bom.$code);
// add to zip array
$this->writeFile($static['path'],$answer);
}
else
{
$answer = str_replace(array_keys($this->fileContentStatic),array_values($this->fileContentStatic),$string);
// add to zip array
$this->writeFile($static['path'],$answer);
}
$this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL );
}
}
// now we do the dynamic files
foreach ($this->newFiles['dynamic'] as $view => $files)
{
if (isset($this->fileContentDynamic[$view]) && ComponentbuilderHelper::checkArray($this->fileContentDynamic[$view]))
{
foreach ($files as $file)
{
if ($file['view'] == $view)
{
if (JFile::exists($file['path']))
{
$this->fileContentStatic['###FILENAME###'] = $file['name'];
$php = '';
if (ComponentbuilderHelper::checkFileType($file['name'],'php'))
{
$php = "fileContentStatic),array_values($this->fileContentStatic),$php.$bom.$code);
$answer = str_replace(array_keys($this->fileContentDynamic[$view]),array_values($this->fileContentDynamic[$view]),$answer);
// add to zip array
$this->writeFile($file['path'],$answer);
}
else
{
$answer = str_replace(array_keys($this->fileContentStatic),array_values($this->fileContentStatic),$string);
$answer = str_replace(array_keys($this->fileContentDynamic[$view]),array_values($this->fileContentDynamic[$view]),$answer);
// add to zip array
$this->writeFile($file['path'],$answer);
}
$this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL );
}
}
}
}
}
// do a final run to update the readme file
foreach ($this->newFiles['static'] as $static)
{
if ($this->componentData->addreadme && 'README.md' == $static['name'] && JFile::exists($static['path']))
{
$this->buildReadMe($static['path']);
break;
}
}
// move the update server to host
if ($this->componentData->add_update_server && isset($this->updateServerFileName) && $this->add2SalesServer)
{
$xml_update_server_path = $this->componentPath.'/'.$this->updateServerFileName.'.xml';
// make sure we have the correct file
if (JFile::exists($xml_update_server_path) && isset($this->componentData->update_server_ftp))
{
// Get the basic encription.
$basickey = ComponentbuilderHelper::getCryptKey('basic');
// Get the encription object.
$basic = new FOFEncryptAes($basickey, 128);
if (!empty($this->componentData->update_server_ftp) && $basickey && !is_numeric($this->componentData->update_server_ftp) && $this->componentData->update_server_ftp === base64_encode(base64_decode($this->componentData->update_server_ftp, true)))
{
// basic decript data update_server_ftp.
$this->componentData->update_server_ftp = rtrim($basic->decryptString($this->componentData->update_server_ftp), "\0");
}
// now move the file
$this->moveFileToFtpServer($xml_update_server_path,$this->componentData->update_server_ftp);
}
}
return true;
}
return false;
}
protected function moveFileToFtpServer($localPath, $clientInput, $remote = null, $removeLocal = true)
{
// get the ftp opbject
$ftp = $this->getFTP($clientInput);
// chack if we are conected
if ($ftp instanceof JClientFtp && $ftp->isConnected())
{
// move the file
if ($ftp->store($localPath,$remote))
{
// if moved then remove the file from repository
if ($removeLocal)
{
JFile::delete($localPath);
}
}
// at the end close the conection
$ftp->quit();
}
}
protected function getFTP($clientInput)
{
$signature = md5($clientInput);
if (isset($this->FTP[$signature]) && $this->FTP[$signature] instanceof JClientFtp)
{
return $this->FTP[$signature];
}
else
{
// make sure we have a string and it is not default or empty
if (ComponentbuilderHelper::checkString($clientInput))
{
// turn into vars
parse_str($clientInput);
// set options
if (isset($options) && ComponentbuilderHelper::checkArray($options))
{
foreach ($options as $option => $value)
{
if ('timeout' == $option)
{
$options[$option] = (int) $value;
}
if ('type' == $option)
{
$options[$option] = (string) $value;
}
}
}
else
{
$options = array();
}
// get ftp object
if (isset($host) && $host != 'HOSTNAME' && isset($port) && $port != 'PORT_INT' && isset($username) && $username != 'user@name.com' && isset($password) && $password != 'password')
{
// load for reuse
$this->FTP[$signature] = JClientFtp::getInstance($host, $port, $options, $username, $password);
return $this->FTP[$signature];
}
}
}
return false;
}
protected function buildReadMe($path)
{
// setup the unrealistic numbers
$folders = $this->folderCount * 5;
$files = $this->fileCount * 5;
$lines = $this->lineCount * 10;
$seconds = $folders + $files + $lines;
$totalHours = round($seconds / 3600);
$totalDays = round($totalHours / 8);
// setup the more realistic numbers
$debugging = $seconds / 4;
$planning = $seconds / 7;
$mapping = $seconds / 10;
$office = $seconds / 6;
$seconds = $folders + $files + $lines + $debugging + $planning + $mapping + $office;
$actualTotalHours = round($seconds / 3600);
$actualTotalDays = round($actualTotalHours / 8);
$debuggingHours = round($debugging / 3600);
$planningHours = round($planning / 3600);
$mappingHours = round($mapping / 3600);
$officeHours = round($office / 3600);
// the actual time spent
$actualHoursSpent = $actualTotalHours - $totalHours;
$actualDaysSpent = $actualTotalDays - $totalDays;
// calculate the projects actual time frame of completion
$projectWeekTime = round($actualTotalDays / 5,1);
$projectMonthTime = round($actualTotalDays / 24,1);
// set some defaults
$this->fileContentStatic['###LINE_COUNT###'] = $this->lineCount;
$this->fileContentStatic['###FILE_COUNT###'] = $this->fileCount;
$this->fileContentStatic['###FOLDER_COUNT###'] = $this->folderCount;
$this->fileContentStatic['###folders###'] = $folders;
$this->fileContentStatic['###files###'] = $files;
$this->fileContentStatic['###lines###'] = $lines;
$this->fileContentStatic['###seconds###'] = $seconds;
$this->fileContentStatic['###totalHours###'] = $totalHours;
$this->fileContentStatic['###totalDays###'] = $totalDays;
$this->fileContentStatic['###debugging###'] = $debugging;
$this->fileContentStatic['###planning###'] = $planning;
$this->fileContentStatic['###mapping###'] = $mapping;
$this->fileContentStatic['###office###'] = $office;
$this->fileContentStatic['###actualTotalHours###'] = $actualTotalHours;
$this->fileContentStatic['###actualTotalDays###'] = $actualTotalDays;
$this->fileContentStatic['###debuggingHours###'] = $debuggingHours;
$this->fileContentStatic['###planningHours###'] = $planningHours;
$this->fileContentStatic['###mappingHours###'] = $mappingHours;
$this->fileContentStatic['###officeHours###'] = $officeHours;
$this->fileContentStatic['###actualHoursSpent###'] = $actualHoursSpent;
$this->fileContentStatic['###actualDaysSpent###'] = $actualDaysSpent;
$this->fileContentStatic['###projectWeekTime###'] = $projectWeekTime;
$this->fileContentStatic['###projectMonthTime###'] = $projectMonthTime;
// get the file
$string = JFile::read($path);
// update the file
$answer = str_replace(array_keys($this->fileContentStatic),array_values($this->fileContentStatic),$string);
// add to zip array
$this->writeFile($path,$answer);
}
protected function zipComponent()
{
// before we zip the component we first need to move it to the git folder if set
if (ComponentbuilderHelper::checkString($this->gitPath))
{
// set the git path
$this->gitPath = $this->gitPath.'/com_'.$this->componentData->sales_name.'__joomla_'.$this->joomlaVersion;
// remove old data
$this->removeFolder($this->gitPath,true);
// set the new data
JFolder::copy($this->componentPath, $this->gitPath, '', true);
}
// the name of the zip file to create
$this->filepath = $this->tempPath.'/'.$this->componentFolderName.'.zip';
// store the current joomla working directory
$joomla = getcwd();
// we are changing the working directory to the componet temp folder
chdir($this->componentPath);
// the full file path of the zip file
$this->filepath = JPath::clean($this->filepath);
// delete an existing zip file (or use an exclusion parameter in JFolder::files()
JFile::delete($this->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($this->filepath, $zipArray))
{
// now move to backup if zip was made and backup is requered
if ($this->backupPath)
{
JFile::copy($this->filepath, $this->backupPath);
}
// move to sales server host
if ($this->componentData->add_sales_server)
{
// make sure we have the correct file
if (isset($this->componentData->sales_server_ftp))
{
// Get the basic encription.
$basickey = ComponentbuilderHelper::getCryptKey('basic');
// Get the encription object.
$basic = new FOFEncryptAes($basickey, 128);
if (!empty($this->componentData->sales_server_ftp) && $basickey && !is_numeric($this->componentData->sales_server_ftp) && $this->componentData->sales_server_ftp === base64_encode(base64_decode($this->componentData->sales_server_ftp, true)))
{
// basic decript data update_server_ftp.
$this->componentData->sales_server_ftp = rtrim($basic->decryptString($this->componentData->sales_server_ftp), "\0");
}
// now move the file
$this->moveFileToFtpServer($this->filepath, $this->componentData->sales_server_ftp, $this->componentSalesName.'.zip',false);
}
}
// remove the component folder since we are done
if ($this->removeFolder($this->componentPath))
{
return true;
}
}
return false;
}
protected function removeFolder($dir, $git = 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())
{
if ($git && strpos($file->getPathname(), $dir.'/.git') !== false) continue;
JFolder::delete($file->getPathname());
}
else
{
if ($git && strpos($file->getPathname(), $dir.'/.git') !== false) continue;
JFile::delete($file->getPathname());
}
}
if (!$git && JFolder::delete($dir))
{
return true;
}
}
return false;
}
protected function writeFile($path,$data)
{
$fh = fopen($path, "w");
if (!is_resource($fh))
{
return false;
}
if (fwrite($fh, $data))
{
// close file.
fclose($fh);
return true;
}
// close file.
fclose($fh);
return false;
}
protected function setMethodGetItem($view)
{
$script = '';
// go from json to array
if(isset($this->jsonItemBuilder[$view]) && ComponentbuilderHelper::checkArray($this->jsonItemBuilder[$view]))
{
foreach ($this->jsonItemBuilder[$view] as $jsonItem)
{
$script .= "\n\n\t\t\tif (!empty(\$item->".$jsonItem."))";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Convert the ".$jsonItem." field to an array.";
$script .= "\n\t\t\t\t\$".$jsonItem." = new Registry;";
$script .= "\n\t\t\t\t\$".$jsonItem."->loadString(\$item->".$jsonItem.");";
$script .= "\n\t\t\t\t\$item->".$jsonItem." = \$".$jsonItem."->toArray();";
$script .= "\n\t\t\t}";
}
}
// go from json to string
if (isset($this->jsonStringBuilder[$view]) && ComponentbuilderHelper::checkArray($this->jsonStringBuilder[$view]))
{
$makeArray = '';
foreach ($this->jsonStringBuilder[$view] as $jsonString)
{
$script .= "\n\n\t\t\tif (!empty(\$item->".$jsonString."))";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." JSON Decode ".$jsonString.".";
if (strpos($jsonString, 'group') !== false)
{
$makeArray = ',true';
}
$script .= "\n\t\t\t\t\$item->".$jsonString." = json_decode(\$item->".$jsonString.$makeArray.");";
$script .= "\n\t\t\t}";
}
}
// go from base64 to string
if (isset($this->base64Builder[$view]) && ComponentbuilderHelper::checkArray($this->base64Builder[$view]))
{
foreach ($this->base64Builder[$view] as $baseString)
{
$script .= "\n\n\t\t\tif (!empty(\$item->".$baseString."))"; // TODO && base64_encode(base64_decode(\$item->".$baseString.", true)) === \$item->".$baseString.")";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." base64 Decode ".$baseString.".";
$script .= "\n\t\t\t\t\$item->".$baseString." = base64_decode(\$item->".$baseString.");";
$script .= "\n\t\t\t}";
}
}
// decryption
if ((isset($this->basicEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->basicEncryptionBuilder[$view])) || (isset($this->advancedEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->advancedEncryptionBuilder[$view])))
{
$Component = $this->fileContentStatic['###Component###'];
if (isset($this->basicEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->basicEncryptionBuilder[$view]))
{
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Get the basic encription.";
$script .= "\n\t\t\t\$basickey = ".$Component."Helper::getCryptKey('basic');";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Get the encription object.";
$script .= "\n\t\t\t\$basic = new FOFEncryptAes(\$basickey, 128);";
foreach ($this->basicEncryptionBuilder[$view] as $baseString)
{
$script .= "\n\n\t\t\tif (!empty(\$item->".$baseString.") && \$basickey && !is_numeric(\$item->".$baseString.") && \$item->".$baseString." === base64_encode(base64_decode(\$item->".$baseString.", true)))";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." basic decript data ".$baseString.".";
$script .= "\n\t\t\t\t\$item->".$baseString." = rtrim(\$basic->decryptString(\$item->".$baseString."), ".'"\0"'.");";
$script .= "\n\t\t\t}";
}
}
if (isset($this->advancedEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->advancedEncryptionBuilder[$view]))
{
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Get the advanced encription key.";
$script .= "\n\t\t\t\$advancedkey = ".$Component."Helper::getCryptKey('advanced');";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Get the encription object.";
$script .= "\n\t\t\t\$advanced = new FOFEncryptAes(\$advancedkey, 256);";
foreach ($this->advancedEncryptionBuilder[$view] as $baseString)
{
$script .= "\n\n\t\t\tif (!empty(\$item->".$baseString.") && \$advancedkey && !is_numeric(\$item->".$baseString.") && \$item->".$baseString." === base64_encode(base64_decode(\$item->".$baseString.", true)))";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." advanced decript data ".$baseString.".";
$script .= "\n\t\t\t\t\$item->".$baseString." = rtrim(\$advanced->decryptString(\$item->".$baseString."), ".'"\0"'.");";
$script .= "\n\t\t\t}";
}
}
}
// add custom php to getitem method
if (isset($this->customScriptBuilder['php_getitem'][$view]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_getitem'][$view]))
{
$script .= "\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_getitem'][$view]);
}
return $script;
}
protected function setCheckboxSave($view)
{
$script = '';
if(isset($this->checkboxBuilder[$view]) && ComponentbuilderHelper::checkArray($this->checkboxBuilder[$view]))
{
foreach ($this->checkboxBuilder[$view] as $checkbox)
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Set the empty ".$checkbox." item to data";
$script .= "\n\t\tif (!isset(\$data['".$checkbox."']))";
$script .= "\n\t\t{";
$script .= "\n\t\t\t\$data['".$checkbox."'] = '';";
$script .= "\n\t\t}";
}
}
return $script;
}
protected function setMethodItemSave($view)
{
$script = '';
// turn array into JSON string
if(isset($this->jsonItemBuilder[$view]) && ComponentbuilderHelper::checkArray($this->jsonItemBuilder[$view]))
{
foreach ($this->jsonItemBuilder[$view] as $jsonItem)
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Set the ".$jsonItem." items to data.";
$script .= "\n\t\tif (isset(\$data['".$jsonItem."']) && is_array(\$data['".$jsonItem."']))";
$script .= "\n\t\t{";
$script .= "\n\t\t\t\$".$jsonItem." = new JRegistry;";
$script .= "\n\t\t\t\$".$jsonItem."->loadArray(\$data['".$jsonItem."']);";
$script .= "\n\t\t\t\$data['".$jsonItem."'] = (string) \$".$jsonItem.";";
$script .= "\n\t\t}";
$script .= "\n\t\telseif (!isset(\$data['".$jsonItem."']))";
$script .= "\n\t\t{";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Set the empty ".$jsonItem." to data";
$script .= "\n\t\t\t\$data['".$jsonItem."'] = '';";
$script .= "\n\t\t}";
}
}
// turn string into json string
if(isset($this->jsonStringBuilder[$view]) && ComponentbuilderHelper::checkArray($this->jsonStringBuilder[$view]))
{
foreach ($this->jsonStringBuilder[$view] as $jsonString)
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Set the ".$jsonString." string to JSON string.";
$script .= "\n\t\tif (isset(\$data['".$jsonString."']))";
$script .= "\n\t\t{";
$script .= "\n\t\t\t\$data['".$jsonString."'] = (string) json_encode(\$data['".$jsonString."']);";
$script .= "\n\t\t}";
}
}
// turn string into base 64 string
if(isset($this->base64Builder[$view]) && ComponentbuilderHelper::checkArray($this->base64Builder[$view]))
{
foreach ($this->base64Builder[$view] as $baseString)
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Set the ".$baseString." string to base64 string.";
$script .= "\n\t\tif (isset(\$data['".$baseString."']))";
$script .= "\n\t\t{";
$script .= "\n\t\t\t\$data['".$baseString."'] = base64_encode(\$data['".$baseString."']);";
$script .= "\n\t\t}";
}
}
// turn string into encrypted string
if((isset($this->basicEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->basicEncryptionBuilder[$view])) || (isset($this->advancedEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->advancedEncryptionBuilder[$view])))
{
$Component = $this->fileContentStatic['###Component###'];
if(isset($this->basicEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->basicEncryptionBuilder[$view]))
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Get the basic encription key.";
$script .= "\n\t\t\$basickey = ".$Component."Helper::getCryptKey('basic');";
$script .= "\n\t\t//".$this->setLine(__LINE__)." Get the encription object";
$script .= "\n\t\t\$basic = new FOFEncryptAes(\$basickey, 128);";
foreach ($this->basicEncryptionBuilder[$view] as $baseString)
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Encript data ".$baseString.".";
$script .= "\n\t\tif (isset(\$data['".$baseString."']) && \$basickey)";
$script .= "\n\t\t{";
$script .= "\n\t\t\t\$data['".$baseString."'] = \$basic->encryptString(\$data['".$baseString."']);";
$script .= "\n\t\t}";
}
}
if(isset($this->advancedEncryptionBuilder[$view]) && ComponentbuilderHelper::checkArray($this->advancedEncryptionBuilder[$view]))
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Get the advanced encription key.";
$script .= "\n\t\t\$advancedkey = ".$Component."Helper::getCryptKey('advanced');";
$script .= "\n\t\t//".$this->setLine(__LINE__)." Get the encription object";
$script .= "\n\t\t\$advanced = new FOFEncryptAes(\$advancedkey, 256);";
foreach ($this->advancedEncryptionBuilder[$view] as $baseString)
{
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Encript data ".$baseString.".";
$script .= "\n\t\tif (isset(\$data['".$baseString."']) && \$advancedkey)";
$script .= "\n\t\t{";
$script .= "\n\t\t\t\$data['".$baseString."'] = \$advanced->encryptString(\$data['".$baseString."']);";
$script .= "\n\t\t}";
}
}
}
// add custom PHP to the save method
if(isset($this->customScriptBuilder['php_save'][$view]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_save'][$view]))
{
$script .= "\n\n" . str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_save'][$view]);
}
return $script;
}
protected function setJmodelAdminBeforeDelete($view)
{
// add custom PHP to the delete Method
if(isset($this->customScriptBuilder['php_before_delete'][$view]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_before_delete'][$view]))
{
return "\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_before_delete'][$view]);
}
return "";
}
protected function setJmodelAdminAfterDelete($view)
{
// add custom PHP to the delete Method
if(isset($this->customScriptBuilder['php_after_delete'][$view]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_after_delete'][$view]))
{
return "\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_after_delete'][$view]);
}
return "";
}
protected function setPostSaveHook($view)
{
// add custom PHP to the post save hook Method
if(isset($this->customScriptBuilder['php_postsavehook'][$view]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_postsavehook'][$view]))
{
return "\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_postsavehook'][$view])."\n\n\t\treturn;";
}
return "\n\t\treturn;";
}
protected function setJtableConstructor($view)
{
// reset
$oserver = "";
// set component name
$component = $this->fileContentStatic['###component###'];
// add the tags observer
if (isset($this->tagsBuilder[$view]) && ComponentbuilderHelper::checkString($this->tagsBuilder[$view]))
{
$oserver .= "\n\n\t\t//".$this->setLine(__LINE__)." Adding Tag Options";
$oserver .= "\n\t\tJTableObserverTags::createObserver(\$this, array('typeAlias' => 'com_".$component.".".$view."'));";
}
// add the history/version observer
if (isset($this->historyBuilder[$view]) && ComponentbuilderHelper::checkString($this->historyBuilder[$view]))
{
$oserver .= "\n\n\t\t//".$this->setLine(__LINE__)." Adding History Options";
$oserver .= "\n\t\tJTableObserverContenthistory::createObserver(\$this, array('typeAlias' => 'com_".$component.".".$view."'));";
}
return $oserver;
}
protected function setJtableAliasCategory($view)
{
// only add Observers if both title, alias and category is availabe in view
if (array_key_exists($view, $this->catCodeBuilder))
{
$code = $this->catCodeBuilder[$view]['code'];
return ", '".$code."' => \$this->".$code;
}
return '';
}
protected function setUninstallScript()
{
// reset script
$script = '';
if (isset($this->uninstallScriptBuilder) && ComponentbuilderHelper::checkArray($this->uninstallScriptBuilder))
{
$component = $this->fileContentStatic['###component###'];
// start loading the data to delet
$script .= "\n\t\t//".$this->setLine(__LINE__)." Get Application object";
$script .= "\n\t\t\$app = JFactory::getApplication();";
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Get The Database object";
$script .= "\n\t\t\$db = JFactory::getDbo();";
foreach ($this->uninstallScriptBuilder as $viewName => $typeAlias)
{
// set a var value
$view = ComponentbuilderHelper::safeString($viewName);
// First check if data is till in table
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t//".$this->setLine(__LINE__)." Select id from content type table";
$script .= "\n\t\t\$query->select(\$db->quoteName('type_id'));";
$script .= "\n\t\t\$query->from(\$db->quoteName('#__content_types'));";
$script .= "\n\t\t//".$this->setLine(__LINE__)." Where ".$viewName." alias is found";
$script .= "\n\t\t\$query->where( \$db->quoteName('type_alias') . ' = '. \$db->quote('".$typeAlias."') );";
$script .= "\n\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t//".$this->setLine(__LINE__)." Execute query to see if alias is found";
$script .= "\n\t\t\$db->execute();";
$script .= "\n\t\t\$".$view."_found = \$db->getNumRows();";
$script .= "\n\t\t//".$this->setLine(__LINE__)." Now check if there were any rows";
$script .= "\n\t\tif (\$".$view."_found)";
$script .= "\n\t\t{";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Since there are load the needed ".$view." type ids";
$script .= "\n\t\t\t\$".$view."_ids = \$db->loadColumn();";
// Now remove the actual type entry
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Remove ".$viewName." from the content type table";
$script .= "\n\t\t\t\$".$view."_condition = array( \$db->quoteName('type_alias') . ' = '. \$db->quote('".$typeAlias."') );";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\t\$query->delete(\$db->quoteName('#__content_types'));";
$script .= "\n\t\t\t\$query->where(\$".$view."_condition);";
$script .= "\n\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Execute the query to remove ".$viewName." items";
$script .= "\n\t\t\t\$".$view."_done = \$db->execute();";
$script .= "\n\t\t\tif (\$".$view."_done);";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." If succesfully remove ".$viewName." add queued success message.";
// TODO lang is not translated
$script .= "\n\t\t\t\t\$app->enqueueMessage(JText::_('The (".$typeAlias.") type alias was removed from the #__content_type table'));";
$script .= "\n\t\t\t}";
// Now remove the related items from contentitem tag map table
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Remove ".$viewName." items from the contentitem tag map table";
$script .= "\n\t\t\t\$".$view."_condition = array( \$db->quoteName('type_alias') . ' = '. \$db->quote('".$typeAlias."') );";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\t\$query->delete(\$db->quoteName('#__contentitem_tag_map'));";
$script .= "\n\t\t\t\$query->where(\$".$view."_condition);";
$script .= "\n\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Execute the query to remove ".$viewName." items";
$script .= "\n\t\t\t\$".$view."_done = \$db->execute();";
$script .= "\n\t\t\tif (\$".$view."_done);";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." If succesfully remove ".$viewName." add queued success message.";
// TODO lang is not translated
$script .= "\n\t\t\t\t\$app->enqueueMessage(JText::_('The (".$typeAlias.") type alias was removed from the #__contentitem_tag_map table'));";
$script .= "\n\t\t\t}";
// Now remove the related items from ucm content table
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Remove ".$viewName." items from the ucm content table";
$script .= "\n\t\t\t\$".$view."_condition = array( \$db->quoteName('core_type_alias') . ' = ' . \$db->quote('".$typeAlias."') );";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\t\$query->delete(\$db->quoteName('#__ucm_content'));";
$script .= "\n\t\t\t\$query->where(\$".$view."_condition);";
$script .= "\n\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Execute the query to remove ".$viewName." items";
$script .= "\n\t\t\t\$".$view."_done = \$db->execute();";
$script .= "\n\t\t\tif (\$".$view."_done);";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." If succesfully remove ".$viewName." add queued success message.";
// TODO lang is not translated
$script .= "\n\t\t\t\t\$app->enqueueMessage(JText::_('The (".$typeAlias.") type alias was removed from the #__ucm_content table'));";
$script .= "\n\t\t\t}";
// setup the foreach loop of ids
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Make sure that all the ".$viewName." items are cleared from DB";
$script .= "\n\t\t\tforeach (\$".$view."_ids as \$".$view."_id)";
$script .= "\n\t\t\t{";
// Now remove the related items from ucm base table
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Remove ".$viewName." items from the ucm base table";
$script .= "\n\t\t\t\t\$".$view."_condition = array( \$db->quoteName('ucm_type_id') . ' = ' . \$".$view."_id);";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\t\t\$query->delete(\$db->quoteName('#__ucm_base'));";
$script .= "\n\t\t\t\t\$query->where(\$".$view."_condition);";
$script .= "\n\t\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Execute the query to remove ".$viewName." items";
$script .= "\n\t\t\t\t\$db->execute();";
// Now remove the related items from ucm history table
$script .= "\n\n\t\t\t\t//".$this->setLine(__LINE__)." Remove ".$viewName." items from the ucm history table";
$script .= "\n\t\t\t\t\$".$view."_condition = array( \$db->quoteName('ucm_type_id') . ' = ' . \$".$view."_id);";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\t\t\$query->delete(\$db->quoteName('#__ucm_history'));";
$script .= "\n\t\t\t\t\$query->where(\$".$view."_condition);";
$script .= "\n\t\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Execute the query to remove ".$viewName." items";
$script .= "\n\t\t\t\t\$db->execute();";
$script .= "\n\t\t\t}";
$script .= "\n\t\t}";
}
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." If All related items was removed queued success message.";
// TODO lang is not translated
$script .= "\n\t\t\$app->enqueueMessage(JText::_('All related items was removed from the #__ucm_base table'));";
$script .= "\n\t\t\$app->enqueueMessage(JText::_('All related items was removed from the #__ucm_history table'));";
// finaly remove the assets from the assets table
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Remove ".$component." assets from the assets table";
$script .= "\n\t\t\$".$component."_condition = array( \$db->quoteName('name') . ' LIKE ' . \$db->quote('com_".$component."%') );";
$script .= "\n\n\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$script .= "\n\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\$query->delete(\$db->quoteName('#__assets'));";
$script .= "\n\t\t\$query->where(\$".$component."_condition);";
$script .= "\n\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\$".$view."_done = \$db->execute();";
$script .= "\n\t\tif (\$".$view."_done);";
$script .= "\n\t\t{";
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." If succesfully remove ".$component." add queued success message.";
// TODO lang is not translated
$script .= "\n\t\t\t\$app->enqueueMessage(JText::_('All related items was removed from the #__assets table'));";
$script .= "\n\t\t}";
// done
$script .= "\n";
}
return $script;
}
protected function setComponentToContentTypes($action)
{
$script = '';
if (isset($this->componentData->admin_views) && ComponentbuilderHelper::checkArray($this->componentData->admin_views))
{
// set component name
$component = $this->fileContentStatic['###component###'];
// reset
$dbStuff = array();
// start loading the content type data
foreach ($this->componentData->admin_views as $viewData)
{
// set main keys
$view = ComponentbuilderHelper::safeString($viewData['settings']->name_single);
// set list view keys
$views = ComponentbuilderHelper::safeString($viewData['settings']->name_list);
// get this views content type data
$dbStuff[$view] = $this->getContentType($view, $component);
// get the correct views name
$checkViews = (isset($this->catCodeBuilder[$view]['views']) && ComponentbuilderHelper::checkString($this->catCodeBuilder[$view]['views'])) ? $this->catCodeBuilder[$view]['views'] : $views;
if (ComponentbuilderHelper::checkArray($dbStuff[$view]) && array_key_exists($view, $this->catCodeBuilder) && ($checkViews == $views))
{
$dbStuff[$view.' catagory'] = $this->getCategoryContentType($view, $views, $component);
}
elseif(!isset($dbStuff[$view]) || !ComponentbuilderHelper::checkArray($dbStuff[$view]))
{
// remove if not array
unset($dbStuff[$view]);
}
}
// build the db insert query
if (ComponentbuilderHelper::checkArray($dbStuff))
{
$taabb = '';
if ($action == 'update')
{
$taabb = "\t";
}
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Get The Database object";
$script .= "\n\t\t\t\$db = JFactory::getDbo();";
foreach ($dbStuff as $name => $tables)
{
if (ComponentbuilderHelper::checkArray($tables))
{
$code = ComponentbuilderHelper::safeString($name);
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Create the ".$name." content type object.";
$script .= "\n\t\t\t\$".$code." = new stdClass();";
foreach ($tables as $table => $data)
{
$script .= "\n\t\t\t\$".$code."->".$table." = '".$data."';";
}
if ($action == 'update')
{
// we first load script to check if data exist
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Check if ".$name." type is already in content_type DB.";
$script .= "\n\t\t\t\$".$code."_id = null;";
$script .= "\n\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\t\t\t\$query->select(\$db->quoteName(array('type_id')));";
$script .= "\n\t\t\t\$query->from(\$db->quoteName('#__content_types'));";
$script .= "\n\t\t\t\$query->where(\$db->quoteName('type_alias') . ' LIKE '. \$db->quote($".$code."->type_alias));";
$script .= "\n\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t\$db->execute();";
}
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Set the object into the content types table.";
if ($action == 'update')
{
$script .= "\n\t\t\tif (\$db->getNumRows())";
$script .= "\n\t\t\t{";
$script .= "\n\t\t\t\t\$".$code."->type_id = \$db->loadResult();";
$script .= "\n\t\t\t\t\$".$code."_Updated = \$db->updateObject('#__content_types', \$".$code.", 'type_id');";
$script .= "\n\t\t\t}";
$script .= "\n\t\t\telse";
$script .= "\n\t\t\t{";
}
$script .= "\n\t\t\t".$taabb."\$".$code."_Inserted = \$db->insertObject('#__content_types', \$".$code.");";
if ($action == 'update')
{
$script .= "\n\t\t\t}";
}
}
}
$script .= "\n\n";
}
}
return $script;
}
protected function setInstallScript()
{
// reset script
$script = $this->setComponentToContentTypes('install');
if (isset($this->paramsBuilder) && ComponentbuilderHelper::checkString($this->paramsBuilder))
{
if (ComponentbuilderHelper::checkString($script))
{
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Install the global extenstion params.";
}
else
{
$script .= "\n\t\t\t//".$this->setLine(__LINE__)." Install the global extenstion params.";
$script .= "\n\t\t\t\$db = JFactory::getDbo();";
}
$script .= "\n\t\t\t\$query = \$db->getQuery(true);";
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Field to update.";
$script .= "\n\t\t\t\$fields = array(";
$script .= "\n\t\t\t\t\$db->quoteName('params') . ' = ' . \$db->quote('{".$this->paramsBuilder."}'),";
$script .= "\n\t\t\t);";
$script .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Condition.";
$script .= "\n\t\t\t\$conditions = array(";
$script .= "\n\t\t\t\t\$db->quoteName('element') . ' = ' . \$db->quote('com_".$component."')";
$script .= "\n\t\t\t);";
$script .= "\n\n\t\t\t\$query->update(\$db->quoteName('#__extensions'))->set(\$fields)->where(\$conditions);";
$script .= "\n\t\t\t\$db->setQuery(\$query);";
$script .= "\n\t\t\t\$allDone = \$db->execute();";
}
if (ComponentbuilderHelper::checkString($script))
{
$script .= "\n\t\t\t".'echo \'';
$script .= "\n\t\t\t\t".'';
$script .= "\n\t\t\t\t".'\';';
return $script;
}
return "\n\t\t\t//".$this->setLine(__LINE__)." noting to install.";
}
protected function setUpdateScript()
{
// reset script
$script = $this->setComponentToContentTypes('update');
if (isset($this->componentData->admin_views) && ComponentbuilderHelper::checkArray($this->componentData->admin_views))
{
$script .= "\n\t\t\t".'echo \'';
$script .= "\n\t\t\t\t".'';
$script .= "\n\t\t\t\t".'';
$script .= "\n\t\t\t\t
Upgrade to Version ".$this->fileContentStatic['###VERSION###']." Was Successful! Let us know if anything is not working as expected.
';";
}
if (ComponentbuilderHelper::checkString($script))
{
return $script;
}
return "\n\t\t\t//".$this->setLine(__LINE__)." noting to update.";
}
protected function getContentType($view, $component)
{
// add if history is to be kept or if tags is added
if ((isset($this->historyBuilder[$view]) && ComponentbuilderHelper::checkString($this->historyBuilder[$view])) || (isset($this->tagsBuilder[$view]) && ComponentbuilderHelper::checkString($this->tagsBuilder[$view])))
{
// reset array
$array = array();
// set needed defaults
$alias = (array_key_exists($view, $this->aliasBuilder)) ? $this->aliasBuilder[$view] : 'null';
$title = (array_key_exists($view, $this->titleBuilder)) ? $this->titleBuilder[$view] : 'null';
$category = (array_key_exists($view, $this->catCodeBuilder)) ? $this->catCodeBuilder[$view]['code'] : 'null';
$categoryHistory = (array_key_exists($view, $this->catCodeBuilder)) ?
'{"sourceColumn": "'.$category.'","targetTable": "#__categories","targetColumn": "id","displayColumn": "title"},': '';
$Component = ComponentbuilderHelper::safeString($component, 'F');
$View = ComponentbuilderHelper::safeString($view, 'F');
$maintext = (isset($this->maintextBuilder[$view]) && ComponentbuilderHelper::checkString($this->maintextBuilder[$view])) ? $this->maintextBuilder[$view] : 'null';
$hiddenFields = (isset($this->hiddenFieldsBuilder[$view]) && ComponentbuilderHelper::checkString($this->hiddenFieldsBuilder[$view])) ? $this->hiddenFieldsBuilder[$view]: '';
$dynamicfields = (isset($this->dynamicfieldsBuilder[$view]) && ComponentbuilderHelper::checkString($this->dynamicfieldsBuilder[$view])) ? $this->dynamicfieldsBuilder[$view] : '';
$intFields = (isset($this->intFieldsBuilder[$view]) && ComponentbuilderHelper::checkString($this->intFieldsBuilder[$view])) ? $this->intFieldsBuilder[$view] : '';
$customfieldlinks = (isset($this->customFieldLinksBuilder[$view]) && ComponentbuilderHelper::checkString($this->customFieldLinksBuilder[$view])) ? $this->customFieldLinksBuilder[$view] : '';
// build uninstall script for content types
$this->uninstallScriptBuilder[$View] = 'com_'.$component.'.'.$view;
// check if this view has metadata
if (isset($this->metadataBuilder[$view]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$view]))
{
$core_metadata = 'metadata';
$core_metakey = 'metakey';
$core_metadesc = 'metadesc';
}
else
{
$core_metadata = 'null';
$core_metakey = 'null';
$core_metadesc = 'null';
}
// check if view has access
if (isset($this->accessBuilder[$view]) && ComponentbuilderHelper::checkString($this->accessBuilder[$view]))
{
$core_access = 'access';
$accessHistory = ',{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"}';
}
else
{
$core_access = 'null';
$accessHistory = '';
}
// set the title
$array['type_title'] = $Component.' '.$View;
// set the alias
$array['type_alias'] = 'com_'.$component.'.'.$view;
// set the table
$array['table'] = '{"special": {"dbtable": "#__'.$component.'_'.$view.'","key": "id","type": "'.$View.'","prefix": "'.$component.'Table","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}';
// set field map
$array['field_mappings'] = '{"common": {"core_content_item_id": "id","core_title": "'.$title.'","core_state": "published","core_alias": "'.$alias.'","core_created_time": "created","core_modified_time": "modified","core_body": "'.$maintext.'","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "'.$core_access.'","core_params": "params","core_featured": "null","core_metadata": "'.$core_metadata.'","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "'.$core_metakey.'","core_metadesc": "'.$core_metadesc.'","core_catid": "'.$category.'","core_xreference": "null","asset_id": "asset_id"},"special": {'.$dynamicfields.'}}';
// set the router class method
$array['router'] = $Component.'HelperRoute::get'.$View.'Route';
// set content history
$array['content_history_options'] = '{"formFile": "administrator/components/com_'.$component.'/models/forms/'.$view.'.xml","hideFields": ["asset_id","checked_out","checked_out_time","version"'.$hiddenFields.'],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering"'.$intFields.'],"displayLookup": ['.$categoryHistory.'{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}'.$accessHistory.',{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}'.$customfieldlinks.']}';
return $array;
}
return false;
}
protected function getCategoryContentType($view, $views, $component)
{
$category = $this->catCodeBuilder[$view]['code'];
$Component = ComponentbuilderHelper::safeString($component, 'F');
$View = ComponentbuilderHelper::safeString($view, 'F');
// build uninstall script for content types
$this->uninstallScriptBuilder[$View.' '.$category] = 'com_'.$component.'.'.$views.'.category';
// set the title
$array['type_title'] = $Component.' '.$View.' '.ComponentbuilderHelper::safeString($category, 'F');
// set the alias
$array['type_alias'] = 'com_'.$component.'.'.$views.'.category';
// set the table
$array['table'] = '{"special":{"dbtable":"#__categories","key":"id","type":"Category","prefix":"JTable","config":"array()"},"common":{"dbtable":"#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}';
// set field map
$array['field_mappings'] = '{"common":{"core_content_item_id":"id","core_title":"title","core_state":"published","core_alias":"alias","core_created_time":"created_time","core_modified_time":"modified_time","core_body":"description", "core_hits":"hits","core_publish_up":"null","core_publish_down":"null","core_access":"access", "core_params":"params", "core_featured":"null", "core_metadata":"metadata", "core_language":"language", "core_images":"null", "core_urls":"null", "core_version":"version", "core_ordering":"null", "core_metakey":"metakey", "core_metadesc":"metadesc", "core_catid":"parent_id", "core_xreference":"null", "asset_id":"asset_id"}, "special":{"parent_id":"parent_id","lft":"lft","rgt":"rgt","level":"level","path":"path","extension":"extension","note":"note"}}';
// set the router class method
$array['router'] = $Component.'HelperRoute::getCategoryRoute';
// set content history
$array['content_history_options'] = '{"formFile":"administrator\/components\/com_categories\/models\/forms\/category.xml", "hideFields":["asset_id","checked_out","checked_out_time","version","lft","rgt","level","path","extension"], "ignoreChanges":["modified_user_id", "modified_time", "checked_out", "checked_out_time", "version", "hits", "path"],"convertToInt":["publish_up", "publish_down"], "displayLookup":[{"sourceColumn":"created_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"access","targetTable":"#__viewlevels","targetColumn":"id","displayColumn":"title"},{"sourceColumn":"modified_user_id","targetTable":"#__users","targetColumn":"id","displayColumn":"name"},{"sourceColumn":"parent_id","targetTable":"#__categories","targetColumn":"id","displayColumn":"title"}]}';
return $array;
}
protected function setRouterHelp($viewName_single, $viewName_list, $front = false)
{
// add if tags is added, also for all front item views
if (((isset($this->tagsBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->tagsBuilder[$viewName_single])) || $front) && (!in_array($viewName_single,$this->setRouterHelpDone)))
{
// insure we load a view only once
$this->setRouterHelpDone[] = $viewName_single;
// build view route helper
$View = ComponentbuilderHelper::safeString($viewName_single, 'F');
$routeHelper = array();
$routeHelper[] = "\n\n\t/**";
$routeHelper[] = "\t* @param int The route of the ".$View;
$routeHelper[] = "\t*/";
if ('category' == $viewName_single || 'categories' == $viewName_single)
{
$routeHelper[] = "\tpublic static function get".$View."Route(\$id = 0)";
}
else
{
$routeHelper[] = "\tpublic static function get".$View."Route(\$id = 0, \$catid = 0)";
}
$routeHelper[] = "\t{";
$routeHelper[] = "\t\tif (\$id > 0)";
$routeHelper[] = "\t\t{";
$routeHelper[] = "\t\t\t//".$this->setLine(__LINE__)." Initialize the needel array.";
$routeHelper[] = "\t\t\t\$needles = array(";
$routeHelper[] = "\t\t\t\t'".$viewName_single."' => array((int) \$id)";
$routeHelper[] = "\t\t\t);";
$routeHelper[] = "\t\t\t//".$this->setLine(__LINE__)." Create the link";
$routeHelper[] = "\t\t\t\$link = 'index.php?option=com_".$this->fileContentStatic['###component###']."&view=".$viewName_single."&id='. \$id;";
$routeHelper[] = "\t\t}";
$routeHelper[] = "\t\telse";
$routeHelper[] = "\t\t{";
$routeHelper[] = "\t\t\t//".$this->setLine(__LINE__)." Initialize the needel array.";
$routeHelper[] = "\t\t\t\$needles = array();";
$routeHelper[] = "\t\t\t//".$this->setLine(__LINE__)."Create the link but don't add the id.";
$routeHelper[] = "\t\t\t\$link = 'index.php?option=com_".$this->fileContentStatic['###component###']."&view=".$viewName_single."';";
$routeHelper[] = "\t\t}";
if ('category' != $viewName_single && 'categories' != $viewName_single)
{
$routeHelper[] = "\t\tif (\$catid > 1)";
$routeHelper[] = "\t\t{";
$routeHelper[] = "\t\t\t\$categories = JCategories::getInstance('".$this->fileContentStatic['###component###'].".".$viewName_list."');";
$routeHelper[] = "\t\t\t\$category = \$categories->get(\$catid);";
$routeHelper[] = "\t\t\tif (\$category)";
$routeHelper[] = "\t\t\t{";
$routeHelper[] = "\t\t\t\t\$needles['category'] = array_reverse(\$category->getPath());";
$routeHelper[] = "\t\t\t\t\$needles['categories'] = \$needles['category'];";
$routeHelper[] = "\t\t\t\t\$link .= '&catid='.\$catid;";
$routeHelper[] = "\t\t\t}";
$routeHelper[] = "\t\t}";
}
if (isset($this->hasMenuGlobal[$viewName_single]))
{
$routeHelper[] = "\n\t\tif (\$item = self::_findItem(\$needles, '".$viewName_single."'))";
}
else
{
$routeHelper[] = "\n\t\tif (\$item = self::_findItem(\$needles))";
}
$routeHelper[] = "\t\t{";
$routeHelper[] = "\t\t\t\$link .= '&Itemid='.\$item;";
$routeHelper[] = "\t\t}";
$routeHelper[] = "\n\t\treturn \$link;";
$routeHelper[] = "\t}";
return implode("\n",$routeHelper);
}
return '';
}
protected function routerParseSwitch($view)
{
// add if tags is added, also for all front item views
if (1)
{
// build view route switch
$routerSwitch = array();
$routerSwitch[] = "\n\t\t\tcase '".$view."':";
$routerSwitch[] = "\t\t\t\t\$vars['view'] = '".$view."';";
$routerSwitch[] = "\t\t\t\tif (is_numeric(\$segments[\$count-1]))";
$routerSwitch[] = "\t\t\t\t{";
$routerSwitch[] = "\t\t\t\t\t\$vars['id'] = (int) \$segments[\$count-1];";
$routerSwitch[] = "\t\t\t\t}";
$routerSwitch[] = "\t\t\t\telse";
$routerSwitch[] = "\t\t\t\t{";
$routerSwitch[] = "\t\t\t\t\t\$id = \$this->getVar('".$view."', \$segments[\$count-1], 'alias', 'id');";
$routerSwitch[] = "\t\t\t\t\tif(\$id)";
$routerSwitch[] = "\t\t\t\t\t{";
$routerSwitch[] = "\t\t\t\t\t\t\$vars['id'] = \$id;";
$routerSwitch[] = "\t\t\t\t\t}";
$routerSwitch[] = "\t\t\t\t}";
$routerSwitch[] = "\t\t\t\tbreak;";
return implode("\n",$routerSwitch);
}
elseif (0)
{
// build view route switch
$routerSwitch = array();
$routerSwitch[] = "\n\t\t\tcase '".$view."':";
$routerSwitch[] = "\t\t\t\t\$vars['view'] = '".$view."';";
$routerSwitch[] = "\t\t\t\tbreak;";
return implode("\n",$routerSwitch);
}
return '';
}
protected function routerBuildViews($view)
{
if (isset($this->fileContentStatic['###ROUTER_BUILD_VIEWS###']) && ComponentbuilderHelper::checkString($this->fileContentStatic['###ROUTER_BUILD_VIEWS###']))
{
return " || \$view == '".$view."'";
}
else
{
return "\$view == '".$view."'";
}
}
protected function setBatchMove($viewName_single)
{
// set needed defaults
$title = false;
$alias = false;
$category = false;
$batchmove = array();
$VIEW = ComponentbuilderHelper::safeString($viewName_single, 'U');
// component helper name
$Helper = $this->fileContentStatic['###Component###'].'Helper';
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
// only load category if set in this view
if (array_key_exists($viewName_single, $this->catCodeBuilder))
{
$category = $this->catCodeBuilder[$viewName_single]['code'];
}
// only load alias if set in this view
if (array_key_exists($viewName_single, $this->aliasBuilder))
{
$alias = $this->aliasBuilder[$viewName_single];
}
// only load title if set in this view
if (array_key_exists($viewName_single, $this->titleBuilder))
{
$title = $this->titleBuilder[$viewName_single];
}
// prepare custom script
if (isset($this->customScriptBuilder['php_batchmove'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_batchmove'][$viewName_single]))
{
$customScript = "\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_batchmove'][$viewName_single]);
}
else
{
$customScript = '';
}
$batchmove[] = "\n\t/**";
$batchmove[] = "\t * Batch move items to a new category";
$batchmove[] = "\t *";
$batchmove[] = "\t * @param integer \$value The new category ID.";
$batchmove[] = "\t * @param array \$pks An array of row IDs.";
$batchmove[] = "\t * @param array \$contexts An array of item contexts.";
$batchmove[] = "\t *";
$batchmove[] = "\t * @return boolean True if successful, false otherwise and internal error is set.";
$batchmove[] = "\t *";
$batchmove[] = "\t * @since\t12.2";
$batchmove[] = "\t */";
$batchmove[] = "\tprotected function batchMove(\$values, \$pks, \$contexts)";
$batchmove[] = "\t{";
$batchmove[] = "\t\tif (empty(\$this->batchSet))";
$batchmove[] = "\t\t{";
$batchmove[] = "\t\t\t//".$this->setLine(__LINE__)." Set some needed variables.";
$batchmove[] = "\t\t\t\$this->user = JFactory::getUser();";
$batchmove[] = "\t\t\t\$this->table = \$this->getTable();";
$batchmove[] = "\t\t\t\$this->tableClassName = get_class(\$this->table);";
$batchmove[] = "\t\t\t\$this->contentType = new JUcmType;";
$batchmove[] = "\t\t\t\$this->type = \$this->contentType->getTypeByTable(\$this->tableClassName);";
$batchmove[] = "\t\t\t\$this->canDo = ".$Helper."::getActions('".$viewName_single."');";
$batchmove[] = "\t\t}";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit']]))
{
$batchmove[] = "\n\t\tif (!\$this->canDo->get('".$core['core.edit']."') && !\$this->canDo->get('".$core['core.batch']."'))";
}
else
{
$batchmove[] = "\n\t\tif (!\$this->canDo->get('core.edit') && !\$this->canDo->get('core.batch'))";
}
$batchmove[] = "\t\t{";
$batchmove[] = "\t\t\t\$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));";
$batchmove[] = "\t\t\treturn false;";
$batchmove[] = "\t\t}".$customScript;
$batchmove[] = "\n\t\t//".$this->setLine(__LINE__)." make sure published only updates if user has the permission.";
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder['global'][$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit.state']]))
{
$batchmove[] = "\t\tif (isset(\$values['published']) && !\$this->canDo->get('".$core['core.edit.state']."'))";
}
else
{
$batchmove[] = "\t\tif (isset(\$values['published']) && !\$this->canDo->get('core.edit.state'))";
}
$batchmove[] = "\t\t{";
$batchmove[] = "\t\t\tunset(\$values['published']);";
$batchmove[] = "\t\t}";
$batchmove[] = "\t\t//".$this->setLine(__LINE__)." remove move_copy from array";
$batchmove[] = "\t\tunset(\$values['move_copy']);";
if ($category)
{
$batchmove[] = "\n\t\tif (isset(\$values['category']) && (int) \$values['category'] > 0 && !static::checkCategoryId(\$values['category']))";
$batchmove[] = "\t\t{";
$batchmove[] = "\t\t\treturn false;";
$batchmove[] = "\t\t}";
$batchmove[] = "\t\telseif (isset(\$values['category']) && (int) \$values['category'] > 0)";
$batchmove[] = "\t\t{";
$batchmove[] = "\t\t\t//".$this->setLine(__LINE__)." move the category value to correct field name";
$batchmove[] = "\t\t\t\$values['".$category."'] = \$values['category'];";
$batchmove[] = "\t\t\tunset(\$values['category']);";
$batchmove[] = "\t\t}";
$batchmove[] = "\t\telseif (isset(\$values['category']))";
$batchmove[] = "\t\t{";
$batchmove[] = "\t\t\tunset(\$values['category']);";
$batchmove[] = "\t\t}\n";
}
$batchmove[] = "\n\t\t//".$this->setLine(__LINE__)." Parent exists so we proceed";
$batchmove[] = "\t\tforeach (\$pks as \$pk)";
$batchmove[] = "\t\t{";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder[$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit']]))
{
$batchmove[] = "\t\t\tif (!\$this->user->authorise('".$core['core.edit']."', \$contexts[\$pk]))";
}
else
{
$batchmove[] = "\t\t\tif (!\$this->user->authorise('core.edit', \$contexts[\$pk]))";
}
$batchmove[] = "\t\t\t{";
$batchmove[] = "\t\t\t\t\$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));";
$batchmove[] = "\n\t\t\t\treturn false;";
$batchmove[] = "\t\t\t}";
$batchmove[] = "\n\t\t\t//".$this->setLine(__LINE__)." Check that the row actually exists";
$batchmove[] = "\t\t\tif (!\$this->table->load(\$pk))";
$batchmove[] = "\t\t\t{";
$batchmove[] = "\t\t\t\tif (\$error = \$this->table->getError())";
$batchmove[] = "\t\t\t\t{";
$batchmove[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Fatal error";
$batchmove[] = "\t\t\t\t\t\$this->setError(\$error);";
$batchmove[] = "\n\t\t\t\t\treturn false;";
$batchmove[] = "\t\t\t\t}";
$batchmove[] = "\t\t\t\telse";
$batchmove[] = "\t\t\t\t{";
$batchmove[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Not fatal error";
$batchmove[] = "\t\t\t\t\t\$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', \$pk));";
$batchmove[] = "\t\t\t\t\tcontinue;";
$batchmove[] = "\t\t\t\t}";
$batchmove[] = "\t\t\t}";
$batchmove[] = "\n\t\t\t//".$this->setLine(__LINE__)." insert all set values.";
$batchmove[] = "\t\t\tif (".$Helper."::checkArray(\$values))";
$batchmove[] = "\t\t\t{";
$batchmove[] = "\t\t\t\tforeach (\$values as \$key => \$value)";
$batchmove[] = "\t\t\t\t{";
$batchmove[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Do special action for access.";
$batchmove[] = "\t\t\t\t\tif ('access' == \$key && strlen(\$value) > 0)";
$batchmove[] = "\t\t\t\t\t{";
$batchmove[] = "\t\t\t\t\t\t\$this->table->\$key = \$value;";
$batchmove[] = "\t\t\t\t\t}";
$batchmove[] = "\t\t\t\t\telseif (strlen(\$value) > 0 && isset(\$this->table->\$key))";
$batchmove[] = "\t\t\t\t\t{";
$batchmove[] = "\t\t\t\t\t\t\$this->table->\$key = \$value;";
$batchmove[] = "\t\t\t\t\t}";
$batchmove[] = "\t\t\t\t}";
$batchmove[] = "\t\t\t}\n";
$batchmove[] = "\n\t\t\t//".$this->setLine(__LINE__)." Check the row.";
$batchmove[] = "\t\t\tif (!\$this->table->check())";
$batchmove[] = "\t\t\t{";
$batchmove[] = "\t\t\t\t\$this->setError(\$this->table->getError());";
$batchmove[] = "\n\t\t\t\treturn false;";
$batchmove[] = "\t\t\t}";
$batchmove[] = "\n\t\t\tif (!empty(\$this->type))";
$batchmove[] = "\t\t\t{";
$batchmove[] = "\t\t\t\t\$this->createTagsHelper(\$this->tagsObserver, \$this->type, \$pk, \$this->typeAlias, \$this->table);";
$batchmove[] = "\t\t\t}";
$batchmove[] = "\n\t\t\t//".$this->setLine(__LINE__)." Store the row.";
$batchmove[] = "\t\t\tif (!\$this->table->store())";
$batchmove[] = "\t\t\t{";
$batchmove[] = "\t\t\t\t\$this->setError(\$this->table->getError());";
$batchmove[] = "\n\t\t\t\treturn false;";
$batchmove[] = "\t\t\t}";
$batchmove[] = "\t\t}";
$batchmove[] = "\n\t\t//".$this->setLine(__LINE__)." Clean the cache";
$batchmove[] = "\t\t\$this->cleanCache();";
$batchmove[] = "\n\t\treturn true;";
$batchmove[] = "\t}";
return "\n".implode("\n",$batchmove);
}
protected function setBatchCopy($viewName_single)
{
// set needed defaults
$title = false;
$alias = false;
$category = false;
$batchcopy = array();
$VIEW = ComponentbuilderHelper::safeString($viewName_single, 'U');
// component helper name
$Helper = $this->fileContentStatic['###Component###'].'Helper';
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
// only load category if set in this view
if (array_key_exists($viewName_single, $this->catCodeBuilder))
{
$category = $this->catCodeBuilder[$viewName_single]['code'];
}
// only load alias if set in this view
if (array_key_exists($viewName_single, $this->aliasBuilder))
{
$alias = $this->aliasBuilder[$viewName_single];
}
// only load title if set in this view
if (array_key_exists($viewName_single, $this->titleBuilder))
{
$title = $this->titleBuilder[$viewName_single];
}
// prepare custom script
if (isset($this->customScriptBuilder['php_batchcopy'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_batchcopy'][$viewName_single]))
{
$customScript = "\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_batchcopy'][$viewName_single]);
}
else
{
$customScript = '';
}
$batchcopy[] = "\n\t/**";
$batchcopy[] = "\t * Batch copy items to a new category or current.";
$batchcopy[] = "\t *";
$batchcopy[] = "\t * @param integer \$values The new values.";
$batchcopy[] = "\t * @param array \$pks An array of row IDs.";
$batchcopy[] = "\t * @param array \$contexts An array of item contexts.";
$batchcopy[] = "\t *";
$batchcopy[] = "\t * @return mixed An array of new IDs on success, boolean false on failure.";
$batchcopy[] = "\t *";
$batchcopy[] = "\t * @since\t12.2";
$batchcopy[] = "\t */";
$batchcopy[] = "\tprotected function batchCopy(\$values, \$pks, \$contexts)";
$batchcopy[] = "\t{";
$batchcopy[] = "\t\tif (empty(\$this->batchSet))";
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\t//".$this->setLine(__LINE__)." Set some needed variables.";
$batchcopy[] = "\t\t\t\$this->user = JFactory::getUser();";
$batchcopy[] = "\t\t\t\$this->table = \$this->getTable();";
$batchcopy[] = "\t\t\t\$this->tableClassName = get_class(\$this->table);";
$batchcopy[] = "\t\t\t\$this->contentType = new JUcmType;";
$batchcopy[] = "\t\t\t\$this->type = \$this->contentType->getTypeByTable(\$this->tableClassName);";
$batchcopy[] = "\t\t\t\$this->canDo = ".$Helper."::getActions('".$viewName_single."');";
$batchcopy[] = "\t\t}";
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.create']]))
{
$batchcopy[] = "\n\t\tif (!\$this->canDo->get('".$core['core.create']."') && !\$this->canDo->get('".$core['core.batch']."'))";
}
else
{
$batchcopy[] = "\n\t\tif (!\$this->canDo->get('core.create') || !\$this->canDo->get('core.batch'))";
}
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\treturn false;";
$batchcopy[] = "\t\t}".$customScript;
$batchcopy[] = "\n\t\t//".$this->setLine(__LINE__)." get list of uniqe fields";
$batchcopy[] = "\t\t\$uniqeFields = \$this->getUniqeFields();";
$batchcopy[] = "\t\t//".$this->setLine(__LINE__)." remove move_copy from array";
$batchcopy[] = "\t\tunset(\$values['move_copy']);";
$batchcopy[] = "\n\t\t//".$this->setLine(__LINE__)." make sure published is set";
$batchcopy[] = "\t\tif (!isset(\$values['published']))";
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\t\$values['published'] = 0;";
$batchcopy[] = "\t\t}";
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder['global'][$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit.state']]))
{
$batchcopy[] = "\t\telseif (isset(\$values['published']) && !\$this->canDo->get('".$core['core.edit.state']."'))";
}
else
{
$batchcopy[] = "\t\telseif (isset(\$values['published']) && !\$this->canDo->get('core.edit.state'))";
}
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\t\t\$values['published'] = 0;";
$batchcopy[] = "\t\t}";
if ($category)
{
$batchcopy[] = "\n\t\tif (isset(\$values['category']) && (int) \$values['category'] > 0 && !static::checkCategoryId(\$values['category']))";
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\treturn false;";
$batchcopy[] = "\t\t}";
$batchcopy[] = "\t\telseif (isset(\$values['category']) && (int) \$values['category'] > 0)";
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\t//".$this->setLine(__LINE__)." move the category value to correct field name";
$batchcopy[] = "\t\t\t\$values['".$category."'] = \$values['category'];";
$batchcopy[] = "\t\t\tunset(\$values['category']);";
$batchcopy[] = "\t\t}";
$batchcopy[] = "\t\telseif (isset(\$values['category']))";
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\tunset(\$values['category']);";
$batchcopy[] = "\t\t}";
}
$batchcopy[] = "\n\t\t\$newIds = array();";
$batchcopy[] = "\n\t\t//".$this->setLine(__LINE__)." Parent exists so let's proceed";
$batchcopy[] = "\t\twhile (!empty(\$pks))";
$batchcopy[] = "\t\t{";
$batchcopy[] = "\t\t\t//".$this->setLine(__LINE__)." Pop the first ID off the stack";
$batchcopy[] = "\t\t\t\$pk = array_shift(\$pks);";
$batchcopy[] = "\n\t\t\t\$this->table->reset();";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." only allow copy if user may edit this item.";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder[$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit']]))
{
$batchcopy[] = "\n\t\t\tif (!\$this->user->authorise('".$core['core.edit']."', \$contexts[\$pk]))";
}
else
{
$batchcopy[] = "\n\t\t\tif (!\$this->user->authorise('core.edit', \$contexts[\$pk]))";
}
$batchcopy[] = "\n\t\t\t{";
$batchcopy[] = "\n\t\t\t\t//".$this->setLine(__LINE__)." Not fatal error";
$batchcopy[] = "\n\t\t\t\t\$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', \$pk));";
$batchcopy[] = "\n\t\t\t\tcontinue;";
$batchcopy[] = "\n\t\t\t}";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." Check that the row actually exists";
$batchcopy[] = "\t\t\tif (!\$this->table->load(\$pk))";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tif (\$error = \$this->table->getError())";
$batchcopy[] = "\t\t\t\t{";
$batchcopy[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Fatal error";
$batchcopy[] = "\t\t\t\t\t\$this->setError(\$error);";
$batchcopy[] = "\n\t\t\t\t\treturn false;";
$batchcopy[] = "\t\t\t\t}";
$batchcopy[] = "\t\t\t\telse";
$batchcopy[] = "\t\t\t\t{";
$batchcopy[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Not fatal error";
$batchcopy[] = "\t\t\t\t\t\$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', \$pk));";
$batchcopy[] = "\t\t\t\t\tcontinue;";
$batchcopy[] = "\t\t\t\t}";
$batchcopy[] = "\t\t\t}";
if ($category && $alias == 'alias' && $title == 'title')
{
$batchcopy[] = "\n\t\t\tif (isset(\$values['".$category."']))";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tstatic::generateTitle((int) \$values['".$category."'], \$this->table);";
$batchcopy[] = "\t\t\t}";
$batchcopy[] = "\t\t\telse";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tstatic::generateTitle((int) \$this->table->".$category.", \$this->table);";
$batchcopy[] = "\t\t\t}";
}
elseif ($category && $alias && $title)
{
$batchcopy[] = "\n\t\t\tif (isset(\$values['".$category."']))";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tlist(\$this->table->".$title.", \$this->table->".$alias.") = \$this->generateNewTitle(\$values['".$category."'], \$this->table->".$alias.", \$this->table->".$title.");";
$batchcopy[] = "\t\t\t}";
$batchcopy[] = "\t\t\telse";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tlist(\$this->table->".$title.", \$this->table->".$alias.") = \$this->generateNewTitle(\$this->table->".$category.", \$this->table->".$alias.", \$this->table->".$title.");";
$batchcopy[] = "\t\t\t}";
}
elseif (!$category && $alias && $title)
{
$batchcopy[] = "\n\t\t\tlist(\$this->table->".$title.", \$this->table->".$alias.") = \$this->_generateNewTitle(\$this->table->".$alias.", \$this->table->".$title.");";
}
elseif (!$category && !$alias && $title && $title != 'user')
{
$batchcopy[] = "\n\t\t\t\$this->table->".$title." = \$this->generateUniqe('".$title."',\$this->table->".$title.");";
}
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." insert all set values";
$batchcopy[] = "\t\t\tif (".$Helper."::checkArray(\$values))";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tforeach (\$values as \$key => \$value)";
$batchcopy[] = "\t\t\t\t{";
$batchcopy[] = "\t\t\t\t\tif (strlen(\$value) > 0 && isset(\$this->table->\$key))";
$batchcopy[] = "\t\t\t\t\t{";
$batchcopy[] = "\t\t\t\t\t\t\$this->table->\$key = \$value;";
$batchcopy[] = "\t\t\t\t\t}";
$batchcopy[] = "\t\t\t\t}";
$batchcopy[] = "\t\t\t}\n";
$batchcopy[] = "\t\t\t//".$this->setLine(__LINE__)." update all uniqe fields";
$batchcopy[] = "\t\t\tif (".$Helper."::checkArray(\$uniqeFields))";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\tforeach (\$uniqeFields as \$uniqeField)";
$batchcopy[] = "\t\t\t\t{";
$batchcopy[] = "\t\t\t\t\t\$this->table->\$uniqeField = \$this->generateUniqe(\$uniqeField,\$this->table->\$uniqeField);";
$batchcopy[] = "\t\t\t\t}";
$batchcopy[] = "\t\t\t}";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." Reset the ID because we are making a copy";
$batchcopy[] = "\t\t\t\$this->table->id = 0;";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." TODO: Deal with ordering?";
$batchcopy[] = "\t\t\t//".$this->setLine(__LINE__)." \$this->table->ordering\t= 1;";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." Check the row.";
$batchcopy[] = "\t\t\tif (!\$this->table->check())";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\t\$this->setError(\$this->table->getError());";
$batchcopy[] = "\n\t\t\t\treturn false;";
$batchcopy[] = "\t\t\t}";
$batchcopy[] = "\n\t\t\tif (!empty(\$this->type))";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\t\$this->createTagsHelper(\$this->tagsObserver, \$this->type, \$pk, \$this->typeAlias, \$this->table);";
$batchcopy[] = "\t\t\t}";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." Store the row.";
$batchcopy[] = "\t\t\tif (!\$this->table->store())";
$batchcopy[] = "\t\t\t{";
$batchcopy[] = "\t\t\t\t\$this->setError(\$this->table->getError());";
$batchcopy[] = "\n\t\t\t\treturn false;";
$batchcopy[] = "\t\t\t}";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." Get the new item ID";
$batchcopy[] = "\t\t\t\$newId = \$this->table->get('id');";
$batchcopy[] = "\n\t\t\t//".$this->setLine(__LINE__)." Add the new ID to the array";
$batchcopy[] = "\t\t\t\$newIds[\$pk] = \$newId;";
$batchcopy[] = "\t\t}";
$batchcopy[] = "\n\t\t//".$this->setLine(__LINE__)." Clean the cache";
$batchcopy[] = "\t\t\$this->cleanCache();";
$batchcopy[] = "\n\t\treturn \$newIds;";
$batchcopy[] = "\t}";
return "\n".implode("\n",$batchcopy);
}
protected function setAliasTitleFix($viewName_single)
{
$fixUniqe = array();
// only load this if these two items are set
if (array_key_exists($viewName_single, $this->aliasBuilder) && array_key_exists($viewName_single, $this->titleBuilder))
{
// set needed defaults
$setCategory = false;
$alias = $this->aliasBuilder[$viewName_single];
$title = $this->titleBuilder[$viewName_single];
$VIEW = ComponentbuilderHelper::safeString($viewName_single, 'U');
if (array_key_exists($viewName_single, $this->catCodeBuilder))
{
$category = $this->catCodeBuilder[$viewName_single]['code'];
$setCategory = true;
}
// start building the fix
$fixUniqe[] = "\n\t\t//".$this->setLine(__LINE__)." Alter the ".$title." for save as copy";
$fixUniqe[] = "\t\tif (\$input->get('task') == 'save2copy')";
$fixUniqe[] = "\t\t{";
$fixUniqe[] = "\t\t\t\$origTable = clone \$this->getTable();";
$fixUniqe[] = "\t\t\t\$origTable->load(\$input->getInt('id'));";
$fixUniqe[] = "\n\t\t\tif (\$data['".$title."'] == \$origTable->".$title.")";
$fixUniqe[] = "\t\t\t{";
if ($setCategory)
{
$fixUniqe[] = "\t\t\t\tlist(\$".$title.", \$".$alias.") = \$this->generateNewTitle(\$data['".$category."'], \$data['".$alias."'], \$data['".$title."']);";
}
else
{
$fixUniqe[] = "\t\t\t\tlist(\$".$title.", \$".$alias.") = \$this->_generateNewTitle(\$data['".$alias."'], \$data['".$title."']);";
}
$fixUniqe[] = "\t\t\t\t\$data['".$title."'] = \$".$title.";";
$fixUniqe[] = "\t\t\t\t\$data['".$alias."'] = \$".$alias.";";
$fixUniqe[] = "\t\t\t}";
$fixUniqe[] = "\t\t\telse";
$fixUniqe[] = "\t\t\t{";
$fixUniqe[] = "\t\t\t\tif (\$data['".$alias."'] == \$origTable->".$alias.")";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\t\$data['".$alias."'] = '';";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\t\t\t}";
$fixUniqe[] = "\n\t\t\t\$data['published'] = 0;";
$fixUniqe[] = "\t\t}";
$fixUniqe[] = "\n\t\t//".$this->setLine(__LINE__)." Automatic handling of ".$alias." for empty fields";
$fixUniqe[] = "\t\tif (in_array(\$input->get('task'), array('apply', 'save', 'save2new')) && (int) \$input->get('id') == 0)";
$fixUniqe[] = "\t\t{";
$fixUniqe[] = "\t\t\tif (\$data['".$alias."'] == null)";
$fixUniqe[] = "\t\t\t{";
$fixUniqe[] = "\t\t\t\tif (JFactory::getConfig()->get('unicodeslugs') == 1)";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\t\$data['".$alias."'] = JFilterOutput::stringURLUnicodeSlug(\$data['".$title."']);";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\t\t\t\telse";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\t\$data['".$alias."'] = JFilterOutput::stringURLSafe(\$data['".$title."']);";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\n\t\t\t\t\$table = JTable::getInstance('".$viewName_single."', '".$this->fileContentStatic['###component###']."Table');";
if ($setCategory)
{
$fixUniqe[] = "\n\t\t\t\tif (\$table->load(array('".$alias."' => \$data['".$alias."'], '".$category."' => \$data['".$category."'])) && (\$table->id != \$data['id'] || \$data['id'] == 0))";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\t\$msg = JText::_('COM_".$this->fileContentStatic['###COMPONENT###']."_".$VIEW."_SAVE_WARNING');";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\n\t\t\t\tlist(\$".$title.", \$".$alias.") = \$this->generateNewTitle(\$data['".$category."'], \$data['".$alias."'], \$data['".$title."']);";
}
else
{
$fixUniqe[] = "\n\t\t\t\tif (\$table->load(array('".$alias."' => \$data['".$alias."'])) && (\$table->id != \$data['id'] || \$data['id'] == 0))";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\t\$msg = JText::_('COM_".$this->fileContentStatic['###COMPONENT###']."_".$VIEW."_SAVE_WARNING');";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\n\t\t\t\tlist(\$".$title.", \$".$alias.") = \$this->_generateNewTitle(\$data['".$alias."'], \$data['".$title."']);";
}
$fixUniqe[] = "\t\t\t\t\$data['".$alias."'] = \$".$alias.";";
$fixUniqe[] = "\n\t\t\t\tif (isset(\$msg))";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\tJFactory::getApplication()->enqueueMessage(\$msg, 'warning');";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\t\t\t}";
$fixUniqe[] = "\t\t}";
}
// handel other uniqe fields
$fixUniqe[] = "\n\t\t//".$this->setLine(__LINE__)." Alter the uniqe field for save as copy";
$fixUniqe[] = "\t\tif (\$input->get('task') == 'save2copy')";
$fixUniqe[] = "\t\t{";
$fixUniqe[] = "\t\t\t//".$this->setLine(__LINE__)." Automatic handling of other uniqe fields";
$fixUniqe[] = "\t\t\t\$uniqeFields = \$this->getUniqeFields();";
$fixUniqe[] = "\t\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkArray(\$uniqeFields))";
$fixUniqe[] = "\t\t\t{";
$fixUniqe[] = "\t\t\t\tforeach (\$uniqeFields as \$uniqeField)";
$fixUniqe[] = "\t\t\t\t{";
$fixUniqe[] = "\t\t\t\t\t\$data[\$uniqeField] = \$this->generateUniqe(\$uniqeField,\$data[\$uniqeField]);";
$fixUniqe[] = "\t\t\t\t}";
$fixUniqe[] = "\t\t\t}";
$fixUniqe[] = "\t\t}";
return "\n".implode("\n",$fixUniqe);
}
protected function setGenerateNewTitle($viewName_single)
{
// if category is added to this view then do nothing
if (array_key_exists($viewName_single, $this->aliasBuilder) && array_key_exists($viewName_single, $this->titleBuilder))
{
$newFunction = array();
$newFunction[] = "\n\n\t/**";
$newFunction[] = "\t* Method to change the title & alias.";
$newFunction[] = "\t*";
$newFunction[] = "\t* @param string \$alias The alias.";
$newFunction[] = "\t* @param string \$title The title.";
$newFunction[] = "\t*";
$newFunction[] = "\t* @return array Contains the modified title and alias.";
$newFunction[] = "\t*";
$newFunction[] = "\t*/";
$newFunction[] = "\tprotected function _generateNewTitle(\$alias, \$title)";
$newFunction[] = "\t{";
$newFunction[] = "\n\t\t//".$this->setLine(__LINE__)." Alter the title & alias";
$newFunction[] = "\t\t\$table = \$this->getTable();";
$newFunction[] = "\n\t\twhile (\$table->load(array('alias' => \$alias)))";
$newFunction[] = "\t\t{";
$newFunction[] = "\t\t\t\$title = JString::increment(\$title);";
$newFunction[] = "\t\t\t\$alias = JString::increment(\$alias, 'dash');";
$newFunction[] = "\t\t}";
$newFunction[] = "\n\t\treturn array(\$title, \$alias);";
$newFunction[] = "\t}";
return implode("\n",$newFunction);
}
elseif (array_key_exists($viewName_single, $this->titleBuilder))
{
$newFunction = array();
$newFunction[] = "\n\n\t/**";
$newFunction[] = "\t* Method to change the title & alias.";
$newFunction[] = "\t*";
$newFunction[] = "\t* @param string \$title The title.";
$newFunction[] = "\t*";
$newFunction[] = "\t* @return array Contains the modified title and alias.";
$newFunction[] = "\t*";
$newFunction[] = "\t*/";
$newFunction[] = "\tprotected function _generateNewTitle(\$title)";
$newFunction[] = "\t{";
$newFunction[] = "\n\t\t//".$this->setLine(__LINE__)." Alter the title";
$newFunction[] = "\t\t\$table = \$this->getTable();";
$newFunction[] = "\n\t\twhile (\$table->load(array('title' => \$title)))";
$newFunction[] = "\t\t{";
$newFunction[] = "\t\t\t\$title = JString::increment(\$title);";
$newFunction[] = "\t\t}";
$newFunction[] = "\n\t\treturn \$title;";
$newFunction[] = "\t}";
return implode("\n",$newFunction);
}
return '';
}
protected function setInstall()
{
if (isset($this->queryBuilder) && ComponentbuilderHelper::checkArray($this->queryBuilder))
{
// set the main db prefix
$component = $this->fileContentStatic['###component###'];
// start building the db
$db = '';
foreach ($this->queryBuilder as $view => $fields)
{
// build the uninstall array
$this->uninstallBuilder[] = "DROP TABLE IF EXISTS `#__".$component."_".$view."`;";
// setup the tables
$db .= "CREATE TABLE IF NOT EXISTS `#__".$component."_".$view."` (";
$db .= "\n\t`id` int(11) NOT NULL AUTO_INCREMENT,";
$db .= "\n\t`asset_id` INT(255) UNSIGNED NOT NULL DEFAULT '0',";
ksort($fields);
foreach ($fields as $field => $data)
{
// set default
$default = $data['default'];
if ( $default == 'Other' )
{
$default = $data['other'];
}
if ($default == 'DATETIME' || $default == 'CURRENT_TIMESTAMP')
{
$default = $default.' '.$data['null_switch'];
}
elseif ($default == 0 || $default)
{
$default = $data['null_switch']." DEFAULT '".$default."'";
}
elseif ($data['null_switch'] == 'NULL')
{
$default = "DEFAULT NULL";
}
else
{
$default = $data['null_switch']." DEFAULT ''";
}
// set the lenght
$lenght = '';
if (isset($data['lenght']) && $data['lenght'] > 0)
{
$lenght = '('.$data['lenght'].')';
}
// set the field to db
$db .= "\n\t`".$field."` ".$data['type'].$lenght." ".$default.",";
}
$db .= "\n\t`params` TEXT NOT NULL DEFAULT '',";
$db .= "\n\t`published` tinyint(1) NOT NULL DEFAULT '1',";
$db .= "\n\t`created_by` int(11) NOT NULL DEFAULT '0',";
$db .= "\n\t`modified_by` int(11) NOT NULL DEFAULT '0',";
$db .= "\n\t`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',";
$db .= "\n\t`modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',";
$db .= "\n\t`checked_out` int(11) NOT NULL,";
$db .= "\n\t`checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',";
$db .= "\n\t`version` int(11) NOT NULL DEFAULT '1',";
$db .= "\n\t`hits` int(11) NOT NULL DEFAULT '0',";
// check if view has access
if (isset($this->accessBuilder[$view]) && ComponentbuilderHelper::checkString($this->accessBuilder[$view]))
{
$db .= "\n\t`access` int(11) DEFAULT NULL,";
}
$db .= "\n\t`ordering` int(11) NOT NULL DEFAULT '0',";
// check if metadata is added to this view
if (isset($this->metadataBuilder[$view]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$view]))
{
$db .= "\n\t`metakey` TEXT NOT NULL DEFAULT '',";
$db .= "\n\t`metadesc` TEXT NOT NULL DEFAULT '',";
$db .= "\n\t`metadata` TEXT NOT NULL DEFAULT '',";
}
$db .= "\n\tPRIMARY KEY (`id`)";
if (isset($this->dbUniqueKeys[$view]) && ComponentbuilderHelper::checkArray($this->dbUniqueKeys[$view]))
{
foreach ($this->dbUniqueKeys[$view] as $nr => $key)
{
$db .= ",\n\tUNIQUE KEY `idx_".$key."` (`".$key."`)";
}
}
// check if view has access
if (isset($this->accessBuilder[$view]) && ComponentbuilderHelper::checkString($this->accessBuilder[$view]))
{
$db .= ",\n\tKEY `idx_access` (`access`)";
}
$db .= ",\n\tKEY `idx_checkout` (`checked_out`)";
$db .= ",\n\tKEY `idx_createdby` (`created_by`)";
$db .= ",\n\tKEY `idx_modifiedby` (`modified_by`)";
$db .= ",\n\tKEY `idx_state` (`published`)";
if (isset($this->dbKeys[$view]) && ComponentbuilderHelper::checkArray($this->dbKeys[$view]))
{
foreach ($this->dbKeys[$view] as $nr => $key)
{
$db .= ",\n\tKEY `idx_".$key."` (`".$key."`)";
}
}
$db .= "\n) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;\n\n";
}
// add custom sql dump to the file
if (isset($this->customScriptBuilder['sql']) && ComponentbuilderHelper::checkArray($this->customScriptBuilder['sql']))
{
foreach ($this->customScriptBuilder['sql'] as $for => $customSql)
{
$placeholders = array('[[[component]]]' => $component, '[[[view]]]' => $for);
$db .= "\n\n".str_replace(array_keys($placeholders),array_values($placeholders),$customSql);
}
}
return $db;
}
return '';
}
protected function setUninstall()
{
if (isset($this->queryBuilder) && ComponentbuilderHelper::checkArray($this->queryBuilder))
{
$bd = '';
foreach ($this->uninstallBuilder as $line)
{
$bd .= $line."\n";
}
return $bd;
}
return '';
}
protected function setLangAdmin()
{
// add final list of needed lang strings
$this->langContent['adminsys'][$this->langPrefix] = ComponentbuilderHelper::safeString($this->componentData->name,'W');
$this->langContent['adminsys'][$this->langPrefix.'_CONFIGURATION'] = ComponentbuilderHelper::safeString($this->componentData->name,'W').' Configuration';
$this->langContent[$this->lang][$this->langPrefix] = ComponentbuilderHelper::safeString($this->componentData->name,'W');
$this->langContent['admin'][$this->langPrefix.'_BACK'] = 'Back';
$this->langContent['admin'][$this->langPrefix.'_DASH'] = 'Dashboard';
$this->langContent['admin'][$this->langPrefix.'_VERSION'] = 'Version';
$this->langContent['admin'][$this->langPrefix.'_DATE'] = 'Date';
$this->langContent['admin'][$this->langPrefix.'_AUTHOR'] = 'Author';
$this->langContent['admin'][$this->langPrefix.'_WEBSITE'] = 'Website';
$this->langContent['admin'][$this->langPrefix.'_LICENSE'] = 'License';
$this->langContent['admin'][$this->langPrefix.'_CONTRIBUTORS'] = 'Contributors';
$this->langContent['admin'][$this->langPrefix.'_CONTRIBUTOR'] = 'Contributor';
$this->langContent['admin'][$this->langPrefix.'_DASHBOARD'] = ComponentbuilderHelper::safeString($this->componentData->name,'W').' Dashboard';
$this->langContent['admin'][$this->langPrefix.'_SAVE_SUCCESS'] = "Great! Item successfully saved.";
$this->langContent['admin'][$this->langPrefix.'_SAVE_WARNING'] = "The value already existed so please select another.";
$this->langContent['admin'][$this->langPrefix.'_HELP_MANAGER'] = "Help";
$this->langContent['admin'][$this->langPrefix.'_NEW'] = "New";
$this->langContent['admin'][$this->langPrefix.'_KEEP_ORIGINAL_STATE'] = "- Keep Original State -";
$this->langContent['admin'][$this->langPrefix.'_KEEP_ORIGINAL_ACCESS'] = "- Keep Original Access -";
$this->langContent['admin'][$this->langPrefix.'_KEEP_ORIGINAL_CATEGORY'] = "- Keep Original Category -";
if ($this->componentData->add_license && $this->componentData->license_type == 3)
{
$this->langContent['admin']['NIE_REG_NIE'] = "
Lincense not set for ".$this->componentData->name.".
Notify your administrator! The lincense can be obtained from ".$this->componentData->companyname.".
";
}
// add the langug files needed to import and export data
if ($this->addEximport)
{
$this->langContent['admin'][$this->langPrefix.'_EXPORT_FAILED'] = "Export Failed";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_FAILED'] = "Import Failed";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_TITLE'] = "Data Importer";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_NO_IMPORT_TYPE_FOUND'] = "Import type not found.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_UNABLE_TO_FIND_IMPORT_PACKAGE'] = "Package to import not found.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_ERROR'] = "Import error.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_SUCCESS'] = "Great! Import successful.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_WARNIMPORTFILE'] = "Warning, import file error.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_NO_FILE_SELECTED'] = "No import file selected.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_PLEASE_SELECT_A_FILE'] = "Please select a file to import.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_PLEASE_SELECT_ALL_COLUMNS'] = "Please link all columns.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_PLEASE_SELECT_A_DIRECTORY'] = "Please enter the file directory.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_WARNIMPORTUPLOADERROR'] = "Warning, import upload error.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_PLEASE_ENTER_A_PACKAGE_DIRECTORY'] = "Please enter the file directory.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE'] = "Path does not have a valid file.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_DOES_NOT_HAVE_A_VALID_FILE_TYPE'] = "Does not have a valid file type.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_ENTER_A_URL'] = "Please enter a url.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_MSG_INVALID_URL'] = "Invalid url.";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_CONTINUE'] = "Continue";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_FROM_UPLOAD'] = "Upload";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_SELECT_FILE'] = "Select File";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_UPLOAD_BOTTON'] = "Upload File";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_FROM_DIRECTORY'] = "Directory";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_SELECT_FILE_DIRECTORY'] = "Set the path to file";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_GET_BOTTON'] = "Get File";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_FROM_URL'] = "URL";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_SELECT_FILE_URL'] = "Enter file URL";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_UPDATE_DATA'] = "Import Data";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_FORMATS_ACCEPTED'] = "formats accepted";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_LINK_FILE_TO_TABLE_COLUMNS'] = "Link File to Table Columns";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_TABLE_COLUMNS'] = "Table Columns";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_FILE_COLUMNS'] = "File Columns";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_PLEASE_SELECT_COLUMN'] = "-- Please Select Column --";
$this->langContent['admin'][$this->langPrefix.'_IMPORT_IGNORE_COLUMN'] = "-- Ignore This Column --";
$this->langContent['admin'][$this->langPrefix.'_NO_ACCESS_GRANTED'] = "No Access Granted!";
}
// check if the both array is set
if (isset($this->langContent['both']) && ComponentbuilderHelper::checkArray($this->langContent['both']))
{
foreach ($this->langContent['both'] as $keylang => $langval)
{
$this->langContent['admin'][$keylang] = $langval;
}
}
if (isset($this->langContent['admin']) && ComponentbuilderHelper::checkArray($this->langContent['admin']))
{
ksort($this->langContent['admin']);
foreach ($this->langContent['admin'] as $key => $value)
{
if (strlen($key) > 0)
{
if (!isset($lang))
{
$lang = '';
}
$lang .= $key.'="'.$value.'"'."\n";
}
}
return $lang;
}
return '';
}
protected function setLangSite()
{
// add final list of needed lang strings
$this->langContent['site'][$this->langPrefix] = ComponentbuilderHelper::safeString($this->componentData->name,'W');
// some more defaults
$this->langContent['site']['JTOOLBAR_APPLY'] = "Save";
$this->langContent['site']['JTOOLBAR_SAVE_AS_COPY'] = "Save as Copy";
$this->langContent['site']['JTOOLBAR_SAVE'] = "Save & Close";
$this->langContent['site']['JTOOLBAR_SAVE_AND_NEW'] = "Save & New";
$this->langContent['site']['JTOOLBAR_CANCEL'] = "Cancel";
$this->langContent['site']['JTOOLBAR_CLOSE'] = "Close";
$this->langContent['site']['JTOOLBAR_HELP'] = "Help";
$this->langContent['site']['JGLOBAL_FIELD_ID_LABEL'] = "ID";
$this->langContent['site']['JGLOBAL_FIELD_ID_DESC'] = "Record number in the database.";
$this->langContent['site']['JGLOBAL_FIELD_MODIFIED_LABEL'] = "Modified Date";
$this->langContent['site']['COM_CONTENT_FIELD_MODIFIED_DESC'] = "The last date this item was modified.";
$this->langContent['site']['JGLOBAL_FIELD_MODIFIED_BY_LABEL'] = "Modified By";
$this->langContent['site']['JGLOBAL_FIELD_MODIFIED_BY_DESC'] = "The user who did the last modification.";
// check if the both array is set
if (isset($this->langContent['both']) && ComponentbuilderHelper::checkArray($this->langContent['both']))
{
foreach ($this->langContent[$this->lang] as $keylang => $langval)
{
$this->langContent['site'][$keylang] = $langval;
}
}
if (isset($this->langContent['site']) && ComponentbuilderHelper::checkArray($this->langContent['site']))
{
ksort($this->langContent['site']);
foreach ($this->langContent['site'] as $key => $value)
{
if (strlen($key) > 0)
{
if (!isset($lang))
{
$lang = '';
}
$lang .= $key.'="'.$value.'"'."\n";
}
}
return $lang;
}
return '';
}
protected function setLangSiteSys()
{
// add final list of needed lang strings
$this->langContent['sitesys'][$this->langPrefix] = ComponentbuilderHelper::safeString($this->componentData->name,'W');
if (isset($this->langContent['sitesys']) && ComponentbuilderHelper::checkArray($this->langContent['sitesys']))
{
ksort($this->langContent['sitesys']);
foreach ($this->langContent['sitesys'] as $key => $value)
{
if (strlen($key) > 0)
{
if (!isset($lang))
{
$lang = '';
}
$lang .= $key.'="'.$value.'"'."\n";
}
}
return $lang;
}
return '';
}
protected function setLangAdminSys()
{
if (isset($this->langContent['adminsys']) && ComponentbuilderHelper::checkArray($this->langContent['adminsys']))
{
ksort($this->langContent['adminsys']);
foreach ($this->langContent['adminsys'] as $key => $value)
{
if (strlen($key) > 0)
{
if (!isset($lang))
{
$lang = '';
}
$lang .= $key.'="'.$value.'"'."\n";
}
}
return $lang;
}
return '';
}
protected function setCustomAdminViewListLink($view,$viewName_list)
{
if (isset($this->componentData->custom_admin_views) && ComponentbuilderHelper::checkArray($this->componentData->custom_admin_views))
{
foreach ($this->componentData->custom_admin_views as $custom_admin_view)
{
if (ComponentbuilderHelper::checkArray($custom_admin_view['adminviews']))
{
foreach ($custom_admin_view['adminviews'] as $adminview)
{
if ($view['adminview'] == $adminview)
{
// set the needed keys
$setId = false;
if (ComponentbuilderHelper::checkArray($custom_admin_view['settings']->main_get->filter))
{
foreach ($custom_admin_view['settings']->main_get->filter as $filter)
{
if ($filter['filter_type'] == 1 || '$id' == $filter['state_key'])
{
$setId = true;
}
}
}
// set the needed array values
$set = array(
'icon' => $custom_admin_view['icomoon'],
'link' => $custom_admin_view['settings']->code,
'NAME' => $custom_admin_view['settings']->CODE,
'name' => $custom_admin_view['settings']->name);
// only load to list if it has id filter
if ($setId)
{
// now load it to the global object for items list
$this->customAdminViewListLink[$viewName_list][] = $set;
// add to set id for list view if needed
$this->customAdminViewListId[$custom_admin_view['settings']->code] = true;
}
else
{
// now load it to the global object for tool bar
$this->customAdminDynamicButtons[$viewName_list][] = $set;
}
}
}
}
}
}
}
protected function setListBody($viewName_single,$viewName_list)
{
if (isset($this->listBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->listBuilder[$viewName_list]))
{
// component helper name
$Helper = $this->fileContentStatic['###Component###'].'Helper';
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
// make sure the custom links are only added once
$firstTimeBeingAdded = true;
// add the default
$body = "items as \$i => \$item): ?>";
$body .= "\n\tuser->authorise('core.manage', 'com_checkin') || \$item->checked_out == \$this->user->id || \$item->checked_out == 0;";
$body .= "\n\t\t\$userChkOut = JFactory::getUser(\$item->checked_out);";
$body .= "\n\t\t\$canDo = ".$Helper."::getActions('".$viewName_single."',\$item,'".$viewName_list."');";
$body .= "\n\t?>";
$body .= "\n\t".'
";
$add = false;
}
else
{
// start building the links
$link = '&id=id; ?>';
// check if custom links should be added to this list views
if (isset($this->customAdminViewListLink[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customAdminViewListLink[$viewName_list]) && $firstTimeBeingAdded)
{
// make sure the custom links are only added once
$firstTimeBeingAdded = false;
// start building the links
$customAdminView = "\n\t\t\t".'
';
}
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit']]))
{
// set permissions.
$accessCheck = "\$canDo->get('".$core['core.edit']."')";
}
else
{
// set permissions.
$accessCheck = "\$canDo->get('core.edit')";
}
// triger the checked out script to be added
$checkoutTriger = true;
}
if ($add)
{
// set as linked
$body .= "\n\t\t".'
";
$body .= "\n";
// return the build
return $body;
}
return '';
}
protected function setListHead($viewName_single,$viewName_list)
{
if (isset($this->listBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->listBuilder[$viewName_list]))
{
// main lang prefix
$langView = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($viewName_single,'U');
// set status lang
$statusLangName = $langView.'_STATUS';
// set id lang
$idLangName = $langView.'_ID';
// add to lang array
if (!isset($this->langContent[$this->lang][$statusLangName]))
{
$this->langContent[$this->lang][$statusLangName] = 'Status';
}
// add to lang array
if (!isset($this->langContent[$this->lang][$idLangName ]))
{
$this->langContent[$this->lang][$idLangName] = 'Id';
}
// set default
$head = '
";
return $head;
}
return '';
}
protected function setListColnr($viewName_list)
{
if (isset($this->listColnrBuilder[$viewName_list]))
{
return $this->listColnrBuilder[$viewName_list];
}
return '';
}
protected function setEditBody(&$view)
{
// set view name
$viewName_single = ComponentbuilderHelper::safeString($view['settings']->name_single);
// alignment
$alignmentNames = array(1 => 'left', 2 => 'right', 3 => 'fullwidth', 4 => 'above', 5 => 'under', 6 => 'leftside', 7 => 'rightside');
// main lang prefix
$langView = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($viewName_single,'U');
if (isset($this->layoutBuilder[$viewName_single]) && ComponentbuilderHelper::checkArray($this->layoutBuilder[$viewName_single]))
{
// set the linked view tabs
$linkedTab = array();
$keys = array();
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
if (isset($this->linkedAdminViews[$viewName_single]) && ComponentbuilderHelper::checkArray($this->linkedAdminViews[$viewName_single]))
{
foreach ($this->linkedAdminViews[$viewName_single] as $linkedView)
{
$tabName = $view['settings']->tabs[(int) $linkedView['tab']];
$this->tabCounter[$viewName_single][$linkedView['tab']] = $tabName;
$linkedTab[$linkedView['adminview']] = $linkedView['tab'];
if (ComponentbuilderHelper::checkString($linkedView['key']) && ComponentbuilderHelper::checkString($linkedView['parentkey']))
{
$keys[$linkedView['adminview']] = array( 'key' => $linkedView['key'], 'parentKey' => $linkedView['parentkey']);
}
else
{
$keys[$linkedView['adminview']] = array( 'key' => null, 'parentKey' => null);
}
if (isset($linkedView['addnew']))
{
$keys[$linkedView['adminview']]['addNewButton'] = (int) $linkedView['addnew'];
}
else
{
$keys[$linkedView['adminview']]['addNewButton'] = 0;
}
}
}
// start tab set
$bucket = array();
$leftside = '';
$rightside = '';
$footer = '';
$header = '';
$mainwidth = 12;
$sidewidth = 0;
ksort($this->tabCounter[$viewName_single]);
foreach ($this->tabCounter[$viewName_single] as $tabNr => $tabName)
{
$tabWidth = 12;
$lrCounter = 0;
// set tab lang
$tabLangName = $langView.'_'.ComponentbuilderHelper::safeString($tabName,'U');
// set tab code name
$tabCodeName = ComponentbuilderHelper::safeString($tabName);
// add to lang array
if (!isset($this->langContent[$this->lang][$tabLangName]))
{
$this->langContent[$this->lang][$tabLangName] = $tabName;
}
// check if linked view belongs to this tab
$buildLayout = true;
$linkedViewId = '';
if (ComponentbuilderHelper::checkArray($linkedTab))
{
$linkedViewId = array_search($tabNr,$linkedTab);
if ($linkedViewId)
{
// don't build
$buildLayout = false;
}
}
if ($buildLayout)
{
// sort to make sure it loads left first
$alignments = $this->layoutBuilder[$viewName_single][$tabName];
ksort($alignments);
foreach ($alignments as $alignment => $names)
{
// set layout code name
$layoutCodeName = $tabCodeName.'_'.$alignmentNames[$alignment];
// reset each time
$items = '';
$itemCounter = 0;
ksort($names);
foreach ($names as $nr => $name)
{
if ($itemCounter == 0)
{
$items .= "'".$name."'";
}
else
{
$items .= ",\n\t'".$name."'";
}
$itemCounter++;
}
switch($alignment)
{
case 1: // left
case 2: // right
// count
$lrCounter++;
// set as items layout
$this->setLayout($viewName_single,$layoutCodeName,$items,'layoutitems');
// set the lang to tab
$bucket[$tabCodeName]['lang'] = $tabLangName;
// load the body
if (!isset($bucket[$tabCodeName][(int) $alignment]))
{
$bucket[$tabCodeName][(int) $alignment] = '';
}
$bucket[$tabCodeName][(int) $alignment] .= "";
break;
case 3: // fullwidth
// set as items layout
$this->setLayout($viewName_single,$layoutCodeName,$items,'layoutfull');
// set the lang to tab
$bucket[$tabCodeName]['lang'] = $tabLangName;
// load the body
if (!isset($bucket[$tabCodeName][(int) $alignment]))
{
$bucket[$tabCodeName][(int) $alignment] = '';
}
$bucket[$tabCodeName][(int) $alignment] .= "";
break;
case 4: // above
// set as title layout
$this->setLayout($viewName_single, $layoutCodeName, $items, 'layouttitle');
// load to header
$header .= "\n\t";
break;
case 5: // under
// set as title layout
$this->setLayout($viewName_single, $layoutCodeName, $items, 'layouttitle');
// load to footer
$footer .= "\n\n\n";
break;
case 6: // left side
$tabWidth = $tabWidth - 2;
// set as items layout
$this->setLayout($viewName_single, $layoutCodeName, $items, 'layoutitems');
// load the body
$leftside .= "\n\t";
break;
case 7: // right side
$tabWidth = $tabWidth - 2;
// set as items layout
$this->setLayout($viewName_single, $layoutCodeName, $items, 'layoutitems');
// load the body
$rightside .= "\n\t";
break;
}
}
}
else
{
// set layout code name
$layoutCodeName = $tabCodeName.'_fullwidth';
// set identifiers
$linkedViewIdentifier[$linkedViewId] = $tabCodeName;
//set function name
$codeName = ComponentbuilderHelper::safeString(ComponentbuilderHelper::randomkey(3).$tabCodeName);
// set as items layout
$this->setLayout($viewName_single,$layoutCodeName,$codeName,'layoutlinkedview');
// set the lang to tab
$bucket[$tabCodeName]['lang'] = $tabLangName;
// set all the linked view stuff
$this->secondRunAdmin['setLinkedView'][] = array(
'viewId' => $linkedViewId,
'viewName_single' => $viewName_single,
'codeName' => $codeName,
'layoutCodeName' => $layoutCodeName,
'key' => $keys[$linkedViewId]['key'],
'parentKey' => $keys[$linkedViewId]['parentKey'],
'addNewButon' => $keys[$linkedViewId]['addNewButton']);
// load the body
if (!isset($bucket[$tabCodeName][3]))
{
$bucket[$tabCodeName][3] = '';
}
$bucket[$tabCodeName][3] .= "";
}
// width calculator :)
if ($tabWidth == 8)
{
$mainwidth = 8;
$sidewidth = 2;
}
elseif ($tabWidth == 10 && $mainwidth != 8)
{
$mainwidth = 9;
$sidewidth = 3;
}
$bucket[$tabCodeName]['lr'] = $lrCounter;
}
// tab counter
$tabCounter = 0;
// check if width is still 12
$span = '';
if ($mainwidth != 12)
{
$span = ' span'.$mainwidth;
}
// start building body
$body = '
';
// now build the template
foreach ($bucket as $tabCodeName => $posions)
{
// check main if both left and right is set
$lrCounter = $posions['lr'];
// get lang string
$tabLangName = $posions['lang'];
// build main center
$main = '';
$mainbottom = '';
foreach ($posions as $posion => $string)
{
if ($lrCounter == 2)
{
switch($posion)
{
case 1: // left
case 2: // right
$main .= "\n\t\t\t".'
';
break;
}
}
// set acctive tab
if ($tabCounter == 0)
{
$body .= "\n\n\t '".$tabCodeName."')); ?>";
}
// if this is a linked view set permissions
$closeIT = false;
if(in_array($tabCodeName,$linkedViewIdentifier))
{
// get view name
$linkedViewId = array_search($tabCodeName,$linkedViewIdentifier);
$linkedViewData = $this->getAdminViewData($linkedViewId);
$linkedCodeName = ComponentbuilderHelper::safeString($linkedViewData->name_single);
// setup correct core target
$coreLoadLinked = false;
if (isset($this->permissionCore[$linkedCodeName]))
{
$coreLinked = $this->permissionCore[$linkedCodeName];
$coreLoadLinked = true;
}
// check if the item has permissions.
if ($coreLoadLinked && isset($coreLinked['core.access']) && isset($this->permissionBuilder['global'][$coreLinked['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$coreLinked['core.access']]) && in_array($linkedCodeName,$this->permissionBuilder['global'][$coreLinked['core.access']]))
{
$body .= "\n\n\tcanDo->get('".$coreLinked['core.access']."')) : ?>";
$closeIT = true;
}
else
{
$body .= "\n";
}
// insure clear
unset($coreLoadLinked,$coreLinked,$linkedViewData);
}
else
{
$body .= "\n";
}
// start tab
$body .= "\n\t";
// add the main
$body .= "\n\t\t".'
';
$body .= $main;
$body .= "\n\t\t
";
if (strlen($mainbottom) > 0)
{
// add the main bottom
$body .= "\n\t\t".'
';
$body .= $mainbottom;
$body .= "\n\t\t
";
}
$body .= "\n\t";
if($closeIT)
{
$body .= "\n\t";
}
// set counter
$tabCounter++;
}
// set default publishing tab lang
$tabLangName = $langView.'_PUBLISHING';
// add to lang array
if (!isset($this->langContent[$this->lang][$tabLangName]))
{
$this->langContent[$this->lang][$tabLangName] = 'Publishing';
}
// check if access is added to this view
if (isset($this->accessBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->accessBuilder[$viewName_single]))
{
$addAccess = ",\n\t'access'";
}
else
{
$addAccess = "";
}
// check if metadata is added to this view
if (isset($this->metadataBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$viewName_single]))
{
// set default publishing tab code name
$tabCodeNameLeft = 'publishing';
$tabCodeNameRight = 'metadata';
// the default publishing tiems
$items = "'created',\n\t'created_by',\n\t'modified',\n\t'modified_by',\n\t'published',\n\t'ordering'".$addAccess.",\n\t'version',\n\t'hits',\n\t'id'";
// set the publishing layout
$this->setLayout($viewName_single, $tabCodeNameLeft, $items, 'layoutpublished');
$this->setLayout($viewName_single, $tabCodeNameRight, false, 'layoutmetadata');
}
else
{
// set default publishing tab code name
$tabCodeNameLeft = 'publishing';
$tabCodeNameRight = 'publlshing';
// the default publishing tiems
$items_one = "'created',\n\t'created_by',\n\t'modified',\n\t'modified_by'";
$items_two = "'published',\n\t'ordering'".$addAccess.",\n\t'version',\n\t'hits',\n\t'id'";
// set the publishing layout
$this->setLayout($viewName_single, $tabCodeNameLeft, $items_one, 'layoutpublished');
$this->setLayout($viewName_single, $tabCodeNameRight, $items_two, 'layoutpublished');
}
// check if the item has permissions.
$publishingPer = array();
$allToBeChekced = array('core.delete','core.edit.created_by','core.edit.state','core.edit.created');
foreach ($allToBeChekced as $core_permission)
{
if ($coreLoad && isset($core[$core_permission]) && isset($this->permissionBuilder['global'][$core[$core_permission]]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core[$core_permission]]) && in_array($viewName_single,$this->permissionBuilder['global'][$core[$core_permission]]))
{
// set permissions.
$publishingPer[] = "\$this->canDo->get('".$core[$core_permission]."')";
}
else
{
// set permissions.
$publishingPer[] = "\$this->canDo->get('".$core_permission."')";
}
}
$body .= "\n\n\t";
// set the default publishing tab
$body .= "\n\t";
$body .= "\n\t\t".'
';
$body .= "\n\t\t\t".'
';
$body .= "\n\t\t\t\t";
$body .= "\n\t\t\t
";
$body .= "\n\t\t\t".'
';
$body .= "\n\t\t\t\t";
$body .= "\n\t\t\t
";
$body .= "\n\t\t
";
$body .= "\n\t";
$body .= "\n\t";
// make sure we dont load it to a view with the name component
if ($viewName_single != 'component')
{
// set permissions tab lang
$tabLangName = $langView.'_PERMISSION';
// set permissions tab code name
$tabCodeName = 'permissions';
// add to lang array
if (!isset($this->langContent[$this->lang][$tabLangName]))
{
$this->langContent[$this->lang][$tabLangName] = 'Permissions';
}
// set the permissions tab
$body .= "\n\n\tcanDo->get('core.admin')) : ?>";
$body .= "\n\t";
$body .= "\n\t\t".'
';
$body .= "\n\t\t\t".'
';
$body .= "\n\t\t\t\t".'";
$body .= "\n\t\t\t
";
$body .= "\n\t\t
";
$body .= "\n\t";
$body .= "\n\t";
}
// end the tab set
$body .= "\n\n\t";
$body .= "\n\n\t
";
$add = false;
}
else
{
$link = '&id=id; ?>&ref='.$refview.'&refid=';
// check if custom links should be added to this list views
if (isset($this->customAdminViewListLink[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customAdminViewListLink[$viewName_list]) && $firstTimeBeingAdded)
{
// make sure the custom links are only added once
$firstTimeBeingAdded = false;
// start building the links
$customAdminView = "\n\t\t\t".'
';
}
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit']]))
{
// set permissions.
$accessCheck = "\$canDo->get('".$core['core.edit']."')";
}
else
{
// set permissions.
$accessCheck = "\$canDo->get('core.edit')";
}
// triger the checked out script to be added
$checkoutTriger = true;
}
if ($add)
{
// set as linked
$body .= "\n\t\t".'
';
$head .= "\n";
// main lang prefix
$langView = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($viewName_single,'U');
// set status lang
$statusLangName = $langView.'_STATUS';
// set id lang
$idLangName = $langView.'_ID';
// make sure only first link is used as togeler
$firstLink = true;
// add to lang array
if (!isset($this->langContent[$this->lang][$statusLangName]))
{
$this->langContent[$this->lang][$statusLangName] = 'Status';
}
// add to lang array
if (!isset($this->langContent[$this->lang][$idLangName ]))
{
$this->langContent[$this->lang][$idLangName] = 'Id';
}
$head .= "\n\t
";
// set controller for data hiding options
$controller = 1;
// build the dynamic fields
foreach ($this->listBuilder[$viewName_list] as $item)
{
$setin = 'data-hide="phone"';
if ($controller > 3)
{
$setin = 'data-hide="phone,tablet"';
}
if ($controller > 6)
{
$setin = 'data-hide="all"';
}
if ($item['link'] && $firstLink)
{
$setin = 'data-toggle="true"';
$firstLink = false;
}
$head .= "\n\t\t
";
$head .= "\n\t\t\t";
$head .= "\n\t\t
";
$controller++;
}
// set default
$head .= "\n\t\t".'
';
$head .= "\n\t\t\t";
$head .= "\n\t\t
";
$head .= "\n\t\t".'
';
$head .= "\n\t\t\t";
$head .= "\n\t\t
";
$head .= "\n\t
";
$head .= "\n";
return $head;
}
return '';
}
protected function setListQueryLinked($viewName_single, $viewName_list, $functionName, $key, $_key, $parentKey, $parent_key, $globalKey)
{
// check if this view has category added
if (isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list]))
{
$categoryCodeName = $this->categoryBuilder[$viewName_list]['code'];
$addCategory = true;
}
else
{
$addCategory = false;
}
$query = "\n\n\t/**";
$query .= "\n\t* Method to get list data.";
$query .= "\n\t*";
$query .= "\n\t* @return mixed An array of data items on success, false on failure.";
$query .= "\n\t*/";
$query .= "\n\tpublic function get".$functionName."()";
$query .= "\n\t{";
// setup the query
$query .= "\n\t\t//".$this->setLine(__LINE__)." Get the user object.";
$query .= "\n\t\t\$user = JFactory::getUser();";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$query .= "\n\t\t\$db = JFactory::getDBO();";
$query .= "\n\t\t\$query = \$db->getQuery(true);";
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Select some fields";
$query .= "\n\t\t\$query->select('a.*');";
// add the category
if ($addCategory)
{
$query .= "\n\t\t\$query->select(\$db->quoteName('c.title','category_title'));";
}
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." From the ".$this->fileContentStatic['###component###']."_".$viewName_single." table";
$query .= "\n\t\t\$query->from(\$db->quoteName('#__".$this->fileContentStatic['###component###']."_".$viewName_single."', 'a'));";
// add the category
if ($addCategory)
{
$query .= "\n\t\t\$query->join('LEFT', \$db->quoteName('#__categories', 'c') . ' ON (' . \$db->quoteName('a.".$categoryCodeName."') . ' = ' . \$db->quoteName('c.id') . ')');";
}
// add custom filtering php
if (isset($this->customScriptBuilder['php_getlistquery'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_getlistquery'][$viewName_single]))
{
$query .= "\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_getlistquery'][$viewName_single]);
}
// add the custom fields query
$query .= $this->setCustomQuery($viewName_list, $viewName_single);
if ($key && strpos($key,'-R>') === false && strpos($key,'-A>') === false && strpos($parentKey,'-R>') === false && strpos($parentKey,'-A>') === false)
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Filter by ".$globalKey." global.";
$query .= "\n\t\t\$".$globalKey." = \$this->".$globalKey.";";
$query .= "\n\t\tif (is_numeric(\$".$globalKey." ))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('a.".$key." = ' . (int) \$".$globalKey." );";
$query .= "\n\t\t}";
$query .= "\n\t\telseif (is_string(\$".$globalKey."))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('a.".$key." = ' . \$db->quote(\$".$globalKey."));";
$query .= "\n\t\t}";
$query .= "\n\t\telse";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('a.".$key." = -5');";
$query .= "\n\t\t}";
}
if (isset($this->accessBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->accessBuilder[$viewName_single]))
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Join over the asset groups.";
$query .= "\n\t\t\$query->select('ag.title AS access_level');";
$query .= "\n\t\t\$query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Filter by access level.";
$query .= "\n\t\tif (\$access = \$this->getState('filter.access'))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('a.access = ' . (int) \$access);";
$query .= "\n\t\t}";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Implement View Level Access";
$query .= "\n\t\tif (!\$user->authorise('core.options', 'com_".$this->fileContentStatic['###component###']."'))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$groups = implode(',', \$user->getAuthorisedViewLevels());";
$query .= "\n\t\t\t\$query->where('a.access IN (' . \$groups . ')');";
$query .= "\n\t\t}";
}
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Order the results by ordering";
$query .= "\n\t\t\$query->order('a.ordering ASC');";
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Load the items";
$query .= "\n\t\t\$db->setQuery(\$query);";
$query .= "\n\t\t\$db->execute();";
$query .= "\n\t\tif (\$db->getNumRows())";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$items = \$db->loadObjectList();";
// ###STORE_METHOD_FIX### <<>>
$query .= $this->setGetItemsMethodStringFix($viewName_single,$this->fileContentStatic['###Component###'],"\t");
// ###SELECTIONTRANSLATIONFIX### <<>>
$query .= $this->setSelectionTranslationFix($viewName_list,$this->fileContentStatic['###Component###'],"\t");
// filter by child repetable field values
if ($key && strpos($key,'-R>') !== false && strpos($key,'-A>') === false)
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Filter by ".$globalKey." Repetable Field";
$query .= "\n\t\t\$".$globalKey." = \$this->".$globalKey.";";
}
// filter by child array field values
if ($key && strpos($key,'-R>') === false && strpos($key,'-A>') !== false)
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Filter by ".$globalKey." Array Field";
$query .= "\n\t\t\$".$globalKey." = \$this->".$globalKey.";";
}
// filter by parent repetable field values
if ($key && strpos($parentKey,'-R>') !== false && strpos($parentKey,'-A>') === false)
{
list($bin,$target) = explode('-R>',$parentKey);
$query .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Filter by ".$_key." Repetable Field";
$query .= "\n\t\t\t\$".$globalKey." = json_decode(\$this->".$globalKey.",true);";
$query .= "\n\t\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkArray(\$items) && isset(\$".$globalKey.") && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$".$globalKey."))";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\tforeach (\$items as \$nr => &\$item)";
$query .= "\n\t\t\t\t{";
$query .= "\n\t\t\t\t\tif (\$item->".$_key." && isset(\$".$globalKey."['".$target."']) && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$".$globalKey."['".$target."']))";
$query .= "\n\t\t\t\t\t{";
$query .= "\n\t\t\t\t\t\tif (!in_array(\$item->".$_key.",\$".$globalKey."['".$target."']))";
$query .= "\n\t\t\t\t\t\t{";
$query .= "\n\t\t\t\t\t\t\tunset(\$items[\$nr]);";
$query .= "\n\t\t\t\t\t\t\tcontinue;";
$query .= "\n\t\t\t\t\t\t}";
$query .= "\n\t\t\t\t\t}";
$query .= "\n\t\t\t\t}";
$query .= "\n\t\t\t}";
$query .= "\n\t\t\telse";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\treturn false;";
$query .= "\n\t\t\t}";
}
// filter by parent array field values
if ($key && strpos($parentKey,'-R>') === false && strpos($parentKey,'-A>') !== false)
{
$query .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Filter by ".$globalKey." Array Field";
$query .= "\n\t\t\t\$".$globalKey." = \$this->".$globalKey.";";
$query .= "\n\t\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkArray(\$items) && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$".$globalKey."))";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\tforeach (\$items as \$nr => &\$item)";
$query .= "\n\t\t\t\t{";
list($bin,$target) = explode('-A>',$parentKey);
if (ComponentbuilderHelper::checkString($target))
{
$query .= "\n\t\t\t\t\tif (\$item->".$_key." && ".$this->fileContentStatic['###Component###']."Helper::checkArray(\$".$globalKey."['".$target."']))";
$query .= "\n\t\t\t\t\t{";
$query .= "\n\t\t\t\t\t\tif (!in_array(\$item->".$_key.",\$".$globalKey."['".$target."']))";
}
else
{
$query .= "\n\t\t\t\t\tif (\$item->".$_key.")";
$query .= "\n\t\t\t\t\t{";
$query .= "\n\t\t\t\t\t\tif (!in_array(\$item->".$_key.",\$".$globalKey."))";
}
$query .= "\n\t\t\t\t\t\t{";
$query .= "\n\t\t\t\t\t\t\tunset(\$items[\$nr]);";
$query .= "\n\t\t\t\t\t\t\tcontinue;";
$query .= "\n\t\t\t\t\t\t}";
$query .= "\n\t\t\t\t\t}";
$query .= "\n\t\t\t\t}";
$query .= "\n\t\t\t}";
$query .= "\n\t\t\telse";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\treturn false;";
$query .= "\n\t\t\t}";
}
$query .= "\n\t\t\treturn \$items;";
$query .= "\n\t\t}";
$query .= "\n\t\treturn false;";
$query .= "\n\t}";
// ###SELECTIONTRANSLATIONFIXFUNC###<<>>
$query .= $this->setSelectionTranslationFixFunc($viewName_list,$this->fileContentStatic['###Component###']);
// fixe mothod name clash
$query = str_replace('selectionTranslation(','selectionTranslation'.$functionName.'(',$query);
return $query;
}
protected function setCustomAdminDynamicButton($viewName_list)
{
$buttons = '';
if (isset($this->customAdminDynamicButtons[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customAdminDynamicButtons[$viewName_list]))
{
$buttons = array();
foreach ($this->customAdminDynamicButtons[$viewName_list] as $custom_button)
{
// Load to lang
$keyLang = $this->langPrefix.'_'.$custom_button['NAME'];
$this->langContent[$this->lang][$keyLang] = ComponentbuilderHelper::safeString($custom_button['name'],'Ww');
// add cpanel button
$buttons[] = "\t\tif (\$this->canDo->get('".$custom_button['link'].".access'))";
$buttons[] = "\t\t{";
$buttons[] = "\t\t\t//".$this->setLine(__LINE__)." add ".$custom_button['name']." button.";
$buttons[] = "\t\t\tJToolBarHelper::custom('".$viewName_list.".redirectTo".ComponentbuilderHelper::safeString($custom_button['link'],'F')."', '".$custom_button['icon']."', '', '".$keyLang."', true);";
$buttons[] = "\t\t}";
}
if (ComponentbuilderHelper::checkArray($buttons))
{
return implode("\n",$buttons);
}
}
return $buttons;
}
protected function setCustomAdminDynamicButtonController($viewName_list)
{
$method = '';
if (isset($this->customAdminDynamicButtons[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customAdminDynamicButtons[$viewName_list]))
{
$method = array();
foreach ($this->customAdminDynamicButtons[$viewName_list] as $custom_button)
{
// add the custom redirect method
$method[] = "\n\n\tpublic function redirectTo".ComponentbuilderHelper::safeString($custom_button['link'],'F')."()";
$method[] = "\t{";
$method[] = "\t\t//".$this->setLine(__LINE__)." Check for request forgeries";
$method[] = "\t\tJSession::checkToken() or die(JText::_('JINVALID_TOKEN'));";
$method[] = "\t\t//".$this->setLine(__LINE__)." check if export is allowed for this user.";
$method[] = "\t\t\$user = JFactory::getUser();";
$method[] = "\t\tif (\$user->authorise('".$custom_button['link'].".access', 'com_".$this->fileContentStatic['###component###']."'))";
$method[] = "\t\t{";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." Get the input";
$method[] = "\t\t\t\$input = JFactory::getApplication()->input;";
$method[] = "\t\t\t\$pks = \$input->post->get('cid', array(), 'array');";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." Sanitize the input";
$method[] = "\t\t\tJArrayHelper::toInteger(\$pks);";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." convert to string";
$method[] = "\t\t\t\$ids = implode('_', \$pks);";
$method[] = "\t\t\t\$this->setRedirect(JRoute::_('index.php?option=com_".$this->fileContentStatic['###component###']."&view=".$custom_button['link']."&cid='.\$ids, false));";
$method[] = "\t\t\treturn;";
$method[] = "\t\t}";
$method[] = "\t\t//".$this->setLine(__LINE__)." Redirect to the list screen with error.";
$method[] = "\t\t\$message = JText::_('".$this->langPrefix."_ACCESS_TO_".$custom_button['NAME']."_FAILED');";
$method[] = "\t\t\$this->setRedirect(JRoute::_('index.php?option=com_".$this->fileContentStatic['###component###']."&view=".$viewName_list."', false), \$message, 'error');";
$method[] = "\t\treturn;";
$method[] = "\t}";
// add to lang array
$lankey = $this->langPrefix."_ACCESS_TO_".$custom_button['NAME']."_FAILED";
if (!isset($this->langContent[$this->lang][$lankey]))
{
$this->langContent[$this->lang][$lankey] = 'Access to '.$custom_button['link'].' was denied.';
}
}
return implode("\n",$method);
}
return $method;
}
protected function setModelExportMethod($viewName_single, $viewName_list)
{
$query = '';
if ($this->eximportView[$viewName_list])
{
$query = "\n\n\t/**";
$query .= "\n\t* Method to get list export data.";
$query .= "\n\t*";
$query .= "\n\t* @return mixed An array of data items on success, false on failure.";
$query .= "\n\t*/";
$query .= "\n\tpublic function getExportData(\$pks)";
$query .= "\n\t{";
$query .= "\n\t\t//".$this->setLine(__LINE__)." setup the query";
$query .= "\n\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkArray(\$pks))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t//".$this->setLine(__LINE__)." Get the user object.";
$query .= "\n\t\t\t\$user = JFactory::getUser();";
$query .= "\n\t\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$query .= "\n\t\t\t\$db = JFactory::getDBO();";
$query .= "\n\t\t\t\$query = \$db->getQuery(true);";
$query .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Select some fields";
$query .= "\n\t\t\t\$query->select('a.*');";
$query .= "\n\n\t\t\t//".$this->setLine(__LINE__)." From the ".$this->fileContentStatic['###component###']."_".$viewName_single." table";
$query .= "\n\t\t\t\$query->from(\$db->quoteName('#__".$this->fileContentStatic['###component###']."_".$viewName_single."', 'a'));";
$query .= "\n\t\t\t\$query->where('a.id IN (' . implode(',',\$pks) . ')');";
// add custom filtering php
if (isset($this->customScriptBuilder['php_getlistquery'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_getlistquery'][$viewName_single]))
{
$query .= "\n\n\t".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_getlistquery'][$viewName_single]);
}
if (isset($this->accessBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->accessBuilder[$viewName_single]))
{
$query .= "\n\t\t\t//".$this->setLine(__LINE__)." Implement View Level Access";
$query .= "\n\t\t\tif (!\$user->authorise('core.options', 'com_".$this->fileContentStatic['###component###']."'))";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\t\$groups = implode(',', \$user->getAuthorisedViewLevels());";
$query .= "\n\t\t\t\t\$query->where('a.access IN (' . \$groups . ')');";
$query .= "\n\t\t\t}";
}
$query .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Order the results by ordering";
$query .= "\n\t\t\t\$query->order('a.ordering ASC');";
$query .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Load the items";
$query .= "\n\t\t\t\$db->setQuery(\$query);";
$query .= "\n\t\t\t\$db->execute();";
$query .= "\n\t\t\tif (\$db->getNumRows())";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\t\$items = \$db->loadObjectList();";
$query .= $this->setGetItemsMethodStringFix($viewName_single,$this->fileContentStatic['###Component###'],"\t\t",true);
$query .= "\n\t\t\t\treturn \$items;";
$query .= "\n\t\t\t}";
$query .= "\n\t\t}";
$query .= "\n\t\treturn false;";
$query .= "\n\t}";
$query .= "\n\n\t/**";
$query .= "\n\t* Method to get header.";
$query .= "\n\t*";
$query .= "\n\t* @return mixed An array of data items on success, false on failure.";
$query .= "\n\t*/";
$query .= "\n\tpublic function getExImPortHeaders()";
$query .= "\n\t{";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Get a db connection.";
$query .= "\n\t\t\$db = JFactory::getDbo();";
$query .= "\n\t\t//".$this->setLine(__LINE__)." get the columns";
$query .= "\n\t\t\$columns = \$db->getTableColumns(".'"#__'.$this->fileContentStatic['###component###'].'_'.$viewName_single.'");';
$query .= "\n\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkArray(\$columns))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t//".$this->setLine(__LINE__)." remove the headers you don't import/export.";
$query .= "\n\t\t\tunset(\$columns['asset_id']);";
$query .= "\n\t\t\tunset(\$columns['checked_out']);";
$query .= "\n\t\t\tunset(\$columns['checked_out_time']);";
$query .= "\n\t\t\t\$headers = new stdClass();";
$query .= "\n\t\t\tforeach (\$columns as \$column => \$type)";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\t\$headers->{\$column} = \$column;";
$query .= "\n\t\t\t}";
$query .= "\n\t\t\treturn \$headers;";
$query .= "\n\t\t}";
$query .= "\n\t\treturn false;";
$query .= "\n\t}";
}
return $query;
}
protected function setControllerEximportMethod($viewName_single, $viewName_list)
{
$method = '';
if (isset($this->eximportView[$viewName_list]) && $this->eximportView[$viewName_list])
{
$method = array();
// add the export method
$method[] = "\n\n\tpublic function exportData()";
$method[] = "\t{";
$method[] = "\t\t//".$this->setLine(__LINE__)." Check for request forgeries";
$method[] = "\t\tJSession::checkToken() or die(JText::_('JINVALID_TOKEN'));";
$method[] = "\t\t//".$this->setLine(__LINE__)." check if export is allowed for this user.";
$method[] = "\t\t\$user = JFactory::getUser();";
$method[] = "\t\tif (\$user->authorise('".$viewName_single.".export', 'com_".$this->fileContentStatic['###component###']."') && \$user->authorise('core.export', 'com_".$this->fileContentStatic['###component###']."'))";
$method[] = "\t\t{";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." Get the input";
$method[] = "\t\t\t\$input = JFactory::getApplication()->input;";
$method[] = "\t\t\t\$pks = \$input->post->get('cid', array(), 'array');";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." Sanitize the input";
$method[] = "\t\t\tJArrayHelper::toInteger(\$pks);";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." Get the model";
$method[] = "\t\t\t\$model = \$this->getModel('".ComponentbuilderHelper::safeString($viewName_list,'F')."');";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." get the data to export";
$method[] = "\t\t\t\$data = \$model->getExportData(\$pks);";
$method[] = "\t\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkArray(\$data))";
$method[] = "\t\t\t{";
$method[] = "\t\t\t\t//".$this->setLine(__LINE__)." now set the data to the spreadsheet";
$method[] = "\t\t\t\t\$date = JFactory::getDate();";
$method[] = "\t\t\t\t".$this->fileContentStatic['###Component###']."Helper::xls(\$data,'".ComponentbuilderHelper::safeString($viewName_list,'F')."_'.\$date->format('jS_F_Y'),'".ComponentbuilderHelper::safeString($viewName_list,'Ww')." exported ('.\$date->format('jS F, Y').')','".ComponentbuilderHelper::safeString($viewName_list,'w')."');";
$method[] = "\t\t\t}";
$method[] = "\t\t}";
$method[] = "\t\t//".$this->setLine(__LINE__)." Redirect to the list screen with error.";
$method[] = "\t\t\$message = JText::_('".$this->langPrefix."_EXPORT_FAILED');";
$method[] = "\t\t\$this->setRedirect(JRoute::_('index.php?option=com_".$this->fileContentStatic['###component###']."&view=".$viewName_list."', false), \$message, 'error');";
$method[] = "\t\treturn;";
$method[] = "\t}";
// add the import method
$method[] = "\n\n\tpublic function importData()";
$method[] = "\t{";
$method[] = "\t\t//".$this->setLine(__LINE__)." Check for request forgeries";
$method[] = "\t\tJSession::checkToken() or die(JText::_('JINVALID_TOKEN'));";
$method[] = "\t\t//".$this->setLine(__LINE__)." check if import is allowed for this user.";
$method[] = "\t\t\$user = JFactory::getUser();";
$method[] = "\t\tif (\$user->authorise('".$viewName_single.".import', 'com_".$this->fileContentStatic['###component###']."') && \$user->authorise('core.import', 'com_".$this->fileContentStatic['###component###']."'))";
$method[] = "\t\t{";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." Get the import model";
$method[] = "\t\t\t\$model = \$this->getModel('".ComponentbuilderHelper::safeString($viewName_list,'F')."');";
$method[] = "\t\t\t//".$this->setLine(__LINE__)." get the headers to import";
$method[] = "\t\t\t\$headers = \$model->getExImPortHeaders();";
$method[] = "\t\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkObject(\$headers))";
$method[] = "\t\t\t{";
$method[] = "\t\t\t\t//".$this->setLine(__LINE__)." Load headers to session.";
$method[] = "\t\t\t\t\$session = JFactory::getSession();";
$method[] = "\t\t\t\t\$headers = json_encode(\$headers);";
$method[] = "\t\t\t\t\$session->set('".$viewName_single."_VDM_IMPORTHEADERS', \$headers);";
$method[] = "\t\t\t\t\$session->set('backto_VDM_IMPORT', '".$viewName_list."');";
$method[] = "\t\t\t\t\$session->set('dataType_VDM_IMPORTINTO', '".$viewName_single."');";
$method[] = "\t\t\t\t//".$this->setLine(__LINE__)." Redirect to import view.";
// add to lang array
$selectImportFileNote = $this->langPrefix."_IMPORT_SELECT_FILE_FOR_".ComponentbuilderHelper::safeString($viewName_list,'U');
if (!isset($this->langContent[$this->lang][$selectImportFileNote]))
{
$this->langContent[$this->lang][$selectImportFileNote] = 'Select the file to import data to '.$viewName_list.'.';
}
$method[] = "\t\t\t\t\$message = JText::_('".$selectImportFileNote."');";
$method[] = "\t\t\t\t\$this->setRedirect(JRoute::_('index.php?option=com_".$this->fileContentStatic['###component###']."&view=import', false), \$message);";
$method[] = "\t\t\t\treturn;";
$method[] = "\t\t\t}";
$method[] = "\t\t}";
$method[] = "\t\t//".$this->setLine(__LINE__)." Redirect to the list screen with error.";
$method[] = "\t\t\$message = JText::_('".$this->langPrefix."_IMPORT_FAILED');";
$method[] = "\t\t\$this->setRedirect(JRoute::_('index.php?option=com_".$this->fileContentStatic['###component###']."&view=".$viewName_list."', false), \$message, 'error');";
$method[] = "\t\treturn;";
$method[] = "\t}";
return implode("\n",$method);
}
return $method;
}
protected function setExportButton($viewName_single, $viewName_list)
{
$button = '';
if (isset($this->eximportView[$viewName_list]) && $this->eximportView[$viewName_list])
{
// main lang prefix
$langExport = $this->langPrefix.'_'.ComponentbuilderHelper::safeString('Export Data','U');
// add to lang array
if (!isset($this->langContent[$this->lang][$langExport]))
{
$this->langContent[$this->lang][$langExport] = 'Export Data';
}
$button = array();
$button[] = "\n\n\t\t\tif (\$this->canDo->get('core.export') && \$this->canDo->get('".$viewName_single.".export'))";
$button[] = "\t\t\t{";
$button[] = "\t\t\t\tJToolBarHelper::custom('".$viewName_list.".exportData', 'download', '', '".$langExport."', true);";
$button[] = "\t\t\t}";
return implode("\n",$button);
}
return $button;
}
protected function setImportButton($viewName_single, $viewName_list)
{
$button = '';
if (isset($this->eximportView[$viewName_list]) && $this->eximportView[$viewName_list])
{
// main lang prefix
$langImport = $this->langPrefix.'_'.ComponentbuilderHelper::safeString('Import Data','U');
// add to lang array
if (!isset($this->langContent[$this->lang][$langImport]))
{
$this->langContent[$this->lang][$langImport] = 'Import Data';
}
$button = array();
$button[] = "\n\n\t\tif (\$this->canDo->get('core.import') && \$this->canDo->get('".$viewName_single.".import'))";
$button[] = "\t\t{";
$button[] = "\t\t\tJToolBarHelper::custom('".$viewName_list.".importData', 'upload', '', '".$langImport."', false);";
$button[] = "\t\t}";
return implode("\n",$button);
}
return $button;
}
protected function setListQuery($viewName_single, $viewName_list)
{
// check if this view has category added
if (isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list]))
{
$categoryCodeName = $this->categoryBuilder[$viewName_list]['code'];
$addCategory = true;
}
else
{
$addCategory = false;
}
// setup the query
$query = "//".$this->setLine(__LINE__)." Get the user object.";
$query .= "\n\t\t\$user = JFactory::getUser();";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$query .= "\n\t\t\$db = JFactory::getDBO();";
$query .= "\n\t\t\$query = \$db->getQuery(true);";
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Select some fields";
$query .= "\n\t\t\$query->select('a.*');";
// add the category
if ($addCategory)
{
$query .= "\n\t\t\$query->select(\$db->quoteName('c.title','category_title'));";
}
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." From the ".$this->fileContentStatic['###component###']."_item table";
$query .= "\n\t\t\$query->from(\$db->quoteName('#__".$this->fileContentStatic['###component###']."_".$viewName_single."', 'a'));";
// add the category
if ($addCategory)
{
$query .= "\n\t\t\$query->join('LEFT', \$db->quoteName('#__categories', 'c') . ' ON (' . \$db->quoteName('a.".$categoryCodeName."') . ' = ' . \$db->quoteName('c.id') . ')');";
}
// add custom filtering php
if (isset($this->customScriptBuilder['php_getlistquery'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_getlistquery'][$viewName_single]))
{
$query .= "\n\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_getlistquery'][$viewName_single]);
}
// add the custom fields query
$query .= $this->setCustomQuery($viewName_list, $viewName_single);
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Filter by published state";
$query .= "\n\t\t\$published = \$this->getState('filter.published');";
$query .= "\n\t\tif (is_numeric(\$published))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('a.published = ' . (int) \$published);";
$query .= "\n\t\t}";
$query .= "\n\t\telseif (\$published === '')";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('(a.published = 0 OR a.published = 1)');";
$query .= "\n\t\t}";
if (isset($this->accessBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->accessBuilder[$viewName_single]))
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Join over the asset groups.";
$query .= "\n\t\t\$query->select('ag.title AS access_level');";
$query .= "\n\t\t\$query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Filter by access level.";
$query .= "\n\t\tif (\$access = \$this->getState('filter.access'))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->where('a.access = ' . (int) \$access);";
$query .= "\n\t\t}";
$query .= "\n\t\t//".$this->setLine(__LINE__)." Implement View Level Access";
$query .= "\n\t\tif (!\$user->authorise('core.options', 'com_".$this->fileContentStatic['###component###']."'))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$groups = implode(',', \$user->getAuthorisedViewLevels());";
$query .= "\n\t\t\t\$query->where('a.access IN (' . \$groups . ')');";
$query .= "\n\t\t}";
}
// set the search query
$query .= $this->setSearchQuery($viewName_list);
// set other filters
$query .= $this->setFilterQuery($viewName_list);
// add the category
if ($addCategory)
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Filter by a single or group of categories.";
$query .= "\n\t\t\$baselevel = 1;";
$query .= "\n\t\t\$categoryId = \$this->getState('filter.category_id');";
$query .= "\n";
$query .= "\n\t\tif (is_numeric(\$categoryId))";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$cat_tbl = JTable::getInstance('Category', 'JTable');";
$query .= "\n\t\t\t\$cat_tbl->load(\$categoryId);";
$query .= "\n\t\t\t\$rgt = \$cat_tbl->rgt;";
$query .= "\n\t\t\t\$lft = \$cat_tbl->lft;";
$query .= "\n\t\t\t\$baselevel = (int) \$cat_tbl->level;";
$query .= "\n\t\t\t\$query->where('c.lft >= ' . (int) \$lft)";
$query .= "\n\t\t\t\t->where('c.rgt <= ' . (int) \$rgt);";
$query .= "\n\t\t}";
$query .= "\n\t\telseif (is_array(\$categoryId))";
$query .= "\n\t\t{";
$query .= "\n\t\t\tJArrayHelper::toInteger(\$categoryId);";
$query .= "\n\t\t\t\$categoryId = implode(',', \$categoryId);";
$query .= "\n\t\t\t\$query->where('a.category IN (' . \$categoryId . ')');";
$query .= "\n\t\t}";
$query .= "\n";
}
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." Add the list ordering clause.";
$query .= "\n\t\t\$orderCol = \$this->state->get('list.ordering', 'a.id');";
$query .= "\n\t\t\$orderDirn = \$this->state->get('list.direction', 'asc'); ";
$query .= "\n\t\tif (\$orderCol != '')";
$query .= "\n\t\t{";
$query .= "\n\t\t\t\$query->order(\$db->escape(\$orderCol . ' ' . \$orderDirn));";
$query .= "\n\t\t}";
$query .= "\n";
$query .= "\n\t\treturn \$query;";
return $query;
}
protected function setSearchQuery($viewName_list)
{
if (isset($this->searchBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->searchBuilder[$viewName_list]))
{
// setup the searh options
$search = "'(";
foreach ($this->searchBuilder[$viewName_list] as $nr => $array)
{
// array( 'type' => $typeName, 'code' => $name, 'custom' => $custom, 'list' => $field['list']);
if ($nr == 0)
{
$search .= "a.".$array['code']." LIKE '.\$search.'";
if (ComponentbuilderHelper::checkArray($array['custom']) && 1 == $array['list'])
{
$search .= " OR ".$array['custom']['db'].".".$array['custom']['text']." LIKE '.\$search.'";
}
}
else
{
$search .= " OR a.".$array['code']." LIKE '.\$search.'";
if (ComponentbuilderHelper::checkArray($array['custom']) && 1 == $array['list'])
{
$search .= " OR ".$array['custom']['db'].".".$array['custom']['text']." LIKE '.\$search.'";
}
}
}
$search .= ")'";
// now setup query
$query = "\n\t\t//".$this->setLine(__LINE__)." Filter by search.";
$query .= "\n\t\t\$search = \$this->getState('filter.search');";
$query .= "\n\t\tif (!empty(\$search))";
$query .= "\n\t\t{";
$query .= "\n\t\t\tif (stripos(\$search, 'id:') === 0)";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\t\$query->where('a.id = ' . (int) substr(\$search, 3));";
$query .= "\n\t\t\t}";
$query .= "\n\t\t\telse";
$query .= "\n\t\t\t{";
$query .= "\n\t\t\t\t\$search = \$db->quote('%' . \$db->escape(\$search, true) . '%');";
$query .= "\n\t\t\t\t\$query->where(".$search.");";
$query .= "\n\t\t\t}";
$query .= "\n\t\t}";
$query .= "\n";
return $query;
}
return '';
}
protected function setCustomQuery($viewName_list, $viewName_single)
{
if (isset($this->customBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customBuilder[$viewName_list]))
{
$query = "";
foreach ($this->customBuilder[$viewName_list] as $filter)
{
if (isset($this->customBuilderList[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customBuilderList[$viewName_list]) && in_array($filter['code'],$this->customBuilderList[$viewName_list]))
{
$query .= "\n\n\t\t//".$this->setLine(__LINE__)." From the ".ComponentbuilderHelper::safeString(ComponentbuilderHelper::safeString($filter['custom']['table'],'w'))." table.";
$query .= "\n\t\t\$query->select(\$db->quoteName('".$filter['custom']['db'].".".$filter['custom']['text']."','".$filter['code']."_".$filter['custom']['text']."'));";
$query .= "\n\t\t\$query->join('LEFT', \$db->quoteName('".$filter['custom']['table']."', '".$filter['custom']['db']."') . ' ON (' . \$db->quoteName('a.".$filter['code']."') . ' = ' . \$db->quoteName('".$filter['custom']['db'].".".$filter['custom']['id']."') . ')');";
}
// build the field type file
$this->setCustomFieldTypeFile($filter, $viewName_list, $viewName_single);
}
return $query;
}
}
protected function setCustomFieldTypeFile($data, $viewName_list, $viewName_single)
{
// make sure it is not already been build
if (!isset($this->fileContentDynamic['customfield_'.$data['type']]) || !ComponentbuilderHelper::checkArray($this->fileContentDynamic['customfield_'.$data['type']]))
{
// first build the custom field type file
$target = array('admin' => 'customfield');
$this->buildDynamique($target,'field'.$data['custom']['extends'],$data['custom']['type']);
// set tab and break replacements
$tabBreak = array(
'\t' => "\t",
'\n' => "\n"
);
// make field dynamic
$replace = array(
'###TABLE###' => $data['custom']['table'],
'###ID###' => $data['custom']['id'],
'###TEXT###' => $data['custom']['text'],
'###CODE_TEXT###' => $data['code'].'_'.$data['custom']['text'],
'###CODE###' => $data['code'],
'###component###' => $this->fileContentStatic['###component###'],
'###Component###' => $this->fileContentStatic['###Component###'],
'###view_type###' => $viewName_single.'_'.$data['type'],
'###type###' => $data['type'],
'###view###' => $viewName_single,
'###views###' => $viewName_list
);
// now load the php script
if (isset($data['custom']['php']) && ComponentbuilderHelper::checkArray($data['custom']['php']))
{
// make sure the ar is reset
$phpCode = '';
foreach ($data['custom']['php'] as $line => $code)
{
if (ComponentbuilderHelper::checkString($code))
{
if ($line == 1)
{
$phpCode .= str_replace(array_keys($tabBreak),array_values($tabBreak),$code);
}
else
{
$phpCode .= "\n\t\t".str_replace(array_keys($tabBreak),array_values($tabBreak),$code);
}
}
}
// replace the placholders
$phpCode = str_replace(array_keys($replace),array_values($replace),$phpCode);
}
else
{
$phpCode = 'return null;';
}
if (!ComponentbuilderHelper::checkString($phpCode))
{
$phpCode = 'return null;';
}
if ($data['custom']['extends'] == 'user')
{
// now load the php xclude script
if (ComponentbuilderHelper::checkArray($data['custom']['phpx']))
{
// make sure the ar is reset
$phpxCode = '';
foreach ($data['custom']['phpx'] as $line => $code)
{
if (ComponentbuilderHelper::checkString($code))
{
if ($line == 1)
{
$phpxCode .= str_replace(array_keys($tabBreak),array_values($tabBreak),$code);
}
else
{
$phpxCode .= "\n\t\t".str_replace(array_keys($tabBreak),array_values($tabBreak),$code);
}
}
}
// replace the placholders
$phpxCode = str_replace(array_keys($replace),array_values($replace),$phpxCode);
}
else
{
$phpxCode = 'return null;';
}
if (!ComponentbuilderHelper::checkString($phpxCode))
{
$phpxCode = 'return null;';
}
// temp holder for name
$tempName = $data['custom']['label'].' Group';
// set lang
$groupLangName = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($tempName,'U');
// add to lang array
$this->langContent[$this->lang][$groupLangName] = ComponentbuilderHelper::safeString($tempName,'W');
// build the Group Control
$this->setGroupControl[$data['type']] = $groupLangName;
// ###JFORM_GETGROUPS_PHP### <<>>
$this->fileContentDynamic['customfield_'.$data['type']]['###JFORM_GETGROUPS_PHP###'] = $phpCode;
// ###JFORM_GETEXCLUDED_PHP### <<>>
$this->fileContentDynamic['customfield_'.$data['type']]['###JFORM_GETEXCLUDED_PHP###'] = $phpxCode;
}
else
{
// ###JFORM_GETOPTIONS_PHP### <<>>
$this->fileContentDynamic['customfield_'.$data['type']]['###JFORM_GETOPTIONS_PHP###'] = $phpCode;
}
// ###Type### <<>>
$this->fileContentDynamic['customfield_'.$data['type']]['###Type###'] = ComponentbuilderHelper::safeString($data['custom']['type'],'F');
// ###type### <<>>
$this->fileContentDynamic['customfield_'.$data['type']]['###type###'] = $data['custom']['type'];
// ###type### <<>>
$this->fileContentDynamic['customfield_'.$data['type']]['###ADD_BUTTON###'] = $this->setAddButttonToListField($data['custom']['view']);
}
}
protected function setAddButttonToListField($targetView)
{
$addButton = array();
$addButton[] = "\n\t/**";
$addButton[] = "\t * Override to add new button";
$addButton[] = "\t *";
$addButton[] = "\t * @return string The field input markup.";
$addButton[] = "\t *";
$addButton[] = "\t * @since 3.2";
$addButton[] = "\t */";
$addButton[] = "\tprotected function getInput()";
$addButton[] = "\t{";
$addButton[] = "\t\t//".$this->setLine(__LINE__)." see if we should add buttons";
$addButton[] = "\t\t\$setButton = \$this->getAttribute('button');";
$addButton[] = "\t\t//".$this->setLine(__LINE__)." get html";
$addButton[] = "\t\t\$html = parent::getInput();";
$addButton[] = "\t\t//".$this->setLine(__LINE__)." if true set button";
$addButton[] = "\t\tif (\$setButton === 'true')";
$addButton[] = "\t\t{";
$addButton[] = "\t\t\t\$user = JFactory::getUser();";
$addButton[] = "\t\t\t//".$this->setLine(__LINE__)." only add if user allowed to create " . $targetView;
// get core permissions
$coreLoad = false;
if (isset($this->permissionCore[$targetView]))
{
$core = $this->permissionCore[$targetView];
$coreLoad = true;
}
// check if the item has permissions.
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($targetView,$this->permissionBuilder['global'][$core['core.create']]))
{
$addButton[] = "\t\t\tif (\$user->authorise('".$core['core.create']."', 'com_".$this->fileContentStatic['###component###']."'))";
}
else
{
$addButton[] = "\t\t\tif (\$user->authorise('core.create', 'com_".$this->fileContentStatic['###component###']."'))";
}
$addButton[] = "\t\t\t{";
$addButton[] = "\t\t\t\t//".$this->setLine(__LINE__)." get the input from url";
$addButton[] = "\t\t\t\t\$jinput = JFactory::getApplication()->input;";
$addButton[] = "\t\t\t\t//".$this->setLine(__LINE__)." get the view name & id";
$addButton[] = "\t\t\t\t\$values = \$jinput->getArray(array(";
$addButton[] = "\t\t\t\t\t'id' => 'int',";
$addButton[] = "\t\t\t\t\t'view' => 'word'";
$addButton[] = "\t\t\t\t));";
$addButton[] = "\t\t\t\t//".$this->setLine(__LINE__)." check if new item";
$addButton[] = "\t\t\t\t\$ref = '';";
$addButton[] = "\t\t\t\tif (!is_null(\$values['id']) && strlen(\$values['view']))";
$addButton[] = "\t\t\t\t{";
$addButton[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." only load referal if not new item.";
$addButton[] = "\t\t\t\t\t\$ref = '&ref=' . \$values['view'] . '&refid=' . \$values['id'];";
$addButton[] = "\t\t\t\t}";
$addButton[] = "\t\t\t\t//".$this->setLine(__LINE__)." build the button";
$addButton[] = "\t\t\t\t\$button = 'fileContentStatic['###component###'] . "&view=" . $targetView . "&layout=edit'.\$ref.'\" >";
$addButton[] = "\t\t\t\t\t' . JText::_('COM_".$this->fileContentStatic['###COMPONENT###']."_NEW') . '';";
$addButton[] = "\t\t\t\t//".$this->setLine(__LINE__)." return the button attached to input field";
$addButton[] = "\t\t\t\treturn \$html . \$button;";
$addButton[] = "\t\t\t}";
$addButton[] = "\t\t}";
$addButton[] = "\t\treturn \$html;";
$addButton[] = "\t}";
return implode("\n",$addButton);
}
protected function setFilterQuery($viewName_list)
{
if (isset($this->filterBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->filterBuilder[$viewName_list]))
{
$filterQuery = "";
foreach ($this->filterBuilder[$viewName_list] as $filter)
{
if ($filter['type'] != 'category' && ComponentbuilderHelper::checkArray($filter['custom']))
{
$filterQuery .= "\n\t\t//".$this->setLine(__LINE__)." Filter by ".$filter['code'].".";
$filterQuery .= "\n\t\tif (\$".$filter['code']." = \$this->getState('filter.".$filter['code']."'))";
$filterQuery .= "\n\t\t{";
$filterQuery .= "\n\t\t\t\$query->where('a.".$filter['code']." = ' . \$db->quote(\$db->escape(\$".$filter['code'].", true)));";
$filterQuery .= "\n\t\t}";
}
elseif ($filter['type'] != 'category')
{
$filterQuery .= "\n\t\t//".$this->setLine(__LINE__)." Filter by ".ucwords($filter['code']).".";
$filterQuery .= "\n\t\tif (\$".$filter['code']." = \$this->getState('filter.".$filter['code']."'))";
$filterQuery .= "\n\t\t{";
$filterQuery .= "\n\t\t\t\$query->where('a.".$filter['code']." = ' . \$db->quote(\$db->escape(\$".$filter['code'].", true)));";
$filterQuery .= "\n\t\t}";
}
}
return $filterQuery;
}
return '';
}
protected function buildTheViewScript($viewArray, $component)
{
// set the view name
$viewName = ComponentbuilderHelper::safeString($viewArray['settings']->name_single);
// setup the str_replace values
$placeholders = array('[[[component]]]' => $component, '[[[view]]]' => $viewName);
// add conditions to this view
if (isset($viewArray['settings']->conditions) && ComponentbuilderHelper::checkArray($viewArray['settings']->conditions))
{
// reset defaults
$getValue = array();
$ifValue = array();
$targetControls = array();
$functions = array();
foreach ($viewArray['settings']->conditions as $condition)
{
if (isset($condition['match_name']) && ComponentbuilderHelper::checkString($condition['match_name']))
{
$uniqueVar = ComponentbuilderHelper::randomkey(7);
$matchName = $condition['match_name'].'_'.$uniqueVar;
$targetBehavior = ($condition['target_behavior'] == 1) ? 'show' : 'hide';
$targetDefault = ($condition['target_behavior'] == 1) ? 'hide' : 'show';
// make sure only one relation is set
$firstTime = true;
// set the realtation if any
if ($condition['target_relation'] && $firstTime)
{
// chain to other items of the same target
$relations = $this->getTargetRelationScript($viewArray['settings']->conditions,$condition,$viewName);
if (ComponentbuilderHelper::checkArray($relations))
{
// set behavior and default array
$behaviors[$matchName] = $targetBehavior;
$defaults[$matchName] = $targetDefault;
// set the type buket
$typeBuket[$matchName] = $condition['match_type'];
// set function array
$functions[$uniqueVar][0] = $matchName;
$matchNames[$matchName] = $condition['match_name'];
// get the select value
$getValue[$matchName] = $this->getValueScript($condition['match_type'],$condition['match_name'],$uniqueVar);
// get the options
$options = $this->getOptionsScript($condition['match_type'],$condition['match_options']);
// set the if values
$ifValue[$matchName] = $this->ifValueScript($matchName,$condition['match_behavior'],$condition['match_type'],$options);
// set the target controls
$targetControls[$matchName] = $this->setTargetControlsScript($condition['target_field'],$targetBehavior,$targetDefault,$uniqueVar,$viewName);
$firstTime = false;
foreach($relations as $relation)
{
if (ComponentbuilderHelper::checkString($relation['match_name']))
{
$relationName = $relation['match_name'].'_'.$uniqueVar;
// set the type buket
$typeBuket[$relationName] = $relation['match_type'];
// set function array
$functions[$uniqueVar][] = $relationName;
$matchNames[$relationName] = $relation['match_name'];
// get the relation option
$relationOptions = $this->getOptionsScript($relation['match_type'],$relation['match_options']);
$getValue[$relationName] = $this->getValueScript($relation['match_type'],$relation['match_name'],$uniqueVar);
$ifValue[$relationName] = $this->ifValueScript($relationName,$relation['match_behavior'],$relation['match_type'],$relationOptions);
}
}
}
}
else
{
// set behavior and default array
$behaviors[$matchName] = $targetBehavior;
$defaults[$matchName] = $targetDefault;
// set the type buket
$typeBuket[$matchName] = $condition['match_type'];
// set function array
$functions[$uniqueVar][0] = $matchName;
$matchNames[$matchName] = $condition['match_name'];
// get the select value
$getValue[$matchName] = $this->getValueScript($condition['match_type'],$condition['match_name'],$uniqueVar);
// get the options
$options = $this->getOptionsScript($condition['match_type'],$condition['match_options']);
// set the if values
$ifValue[$matchName] = $this->ifValueScript($matchName,$condition['match_behavior'],$condition['match_type'],$options);
// set the target controls
$targetControls[$matchName] = $this->setTargetControlsScript($condition['target_field'],$targetBehavior,$targetDefault,$uniqueVar,$viewName);
}
}
}
// reset buckets
$initial = '';
$func = '';
$validation = '';
$isSet = '';
$listener = '';
if (ComponentbuilderHelper::checkArray($functions))
{
// now build the initial script
$initial .= "// Initial Script\njQuery(document).ready(function()";
$initial .= "\n{";
foreach ($functions as $function => $matchKeys)
{
$func_call = $this->buildFunctionCall($function,$matchKeys,$getValue);
$initial .= $func_call['code'];
}
$initial .= "});\n";
// for modal fields
$modal = '';
// now build the listener scripts
foreach ($functions as $l_function => $l_matchKeys)
{
$funcCall = '';
foreach ($l_matchKeys as $l_matchKey)
{
$name = $matchNames[$l_matchKey];
$matchTypeKey = $typeBuket[$l_matchKey];
$funcCall = $this->buildFunctionCall($l_function,$l_matchKeys,$getValue);
if (isset($this->setScriptUserSwitch) && ComponentbuilderHelper::checkArray($this->setScriptUserSwitch) && in_array($matchTypeKey,$this->setScriptUserSwitch))
{
$modal .= $funcCall['code'];
}
elseif(isset($this->setScriptMediaSwitch) && ComponentbuilderHelper::checkArray($this->setScriptMediaSwitch) && in_array($matchTypeKey,$this->setScriptMediaSwitch))
{
$modal .= $funcCall['code'];
}
else
{
$listener .= "\n// #jform_".$name." listeners for ".$l_matchKey." function";
$listener .= "\njQuery('#jform_".$name."').on('keyup',function()";
$listener .= "\n{";
$listener .= $funcCall['code'];
$listener .= "\n});";
$listener .= "\njQuery('#adminForm').on('change', '#jform_".$name."',function (e)";
$listener .= "\n{";
$listener .= "\n\te.preventDefault();";
$listener .= $funcCall['code'];
$listener .= "\n});\n";
}
}
}
if (ComponentbuilderHelper::checkString($modal))
{
$listener .= "\nwindow.SqueezeBox.initialize({";
$listener .= "\n\tonClose:function(){";
$listener .= $modal;
$listener .= "\n\t}";
$listener .= "\n});\n";
}
// now build the function
$func = '';
$head = '';
foreach ($functions as $f_function => $f_matchKeys)
{
$map = '';
// does this function require an array
$addArray = false;
$func_ = $this->buildFunctionCall($f_function,$f_matchKeys,$getValue);
// set array switch
if ($func_['array'])
{
$addArray = true;
}
$func .= "\n// the ".$f_function." function";
$func .= "\nfunction ".$f_function."(";
$fucounter = 0;
foreach ($f_matchKeys as $fu_matchKey)
{
if (ComponentbuilderHelper::checkString($fu_matchKey))
{
if ($fucounter == 0)
{
$func .= $fu_matchKey;
}
else
{
$func .= ','.$fu_matchKey;
}
$fucounter++;
}
}
$func .= ")";
$func .= "\n{";
if ($addArray)
{
foreach ($f_matchKeys as $a_matchKey)
{
$name = $matchNames[$a_matchKey];
$func .= "\n\tif (isSet(".$a_matchKey.") && ".$a_matchKey.".constructor !== Array)\n\t{\n\t\tvar temp_".$f_function." = ".$a_matchKey.";\n\t\tvar ".$a_matchKey." = [];\n\t\t".$a_matchKey.".push(temp_".$f_function.");\n\t}";
$func .= "\n\telse if (!isSet(".$a_matchKey."))\n\t{";
$func .= "\n\t\tvar ".$a_matchKey." = [];";
$func .= "\n\t}";
$func .= "\n\tvar ".$name." = ".$a_matchKey.".some(".$a_matchKey."_SomeFunc);\n";
// setup the map function
$map .= "\n// the ".$f_function." Some function";
$map .= "\nfunction ".$a_matchKey."_SomeFunc(".$a_matchKey.")";
$map .= "\n{";
$map .= "\n\t//".$this->setLine(__LINE__)." set the function logic";
$map .= "\n\tif (";
$if = $ifValue[$a_matchKey];
if (ComponentbuilderHelper::checkString($if))
{
$map .= $if;
}
$map .= ")";
$map .= "\n\t{";
$map .= "\n\t\treturn true;";
$map .= "\n\t}\n\treturn false;";
$map .= "\n}\n";
}
$func .= "\n\n\t//".$this->setLine(__LINE__)." set this function logic";
$func .= "\n\tif (";
// set if counter
$aifcounter = 0;
foreach ($f_matchKeys as $af_matchKey)
{
$name = $matchNames[$af_matchKey];
if ($aifcounter == 0)
{
$func .= $name;
}
else
{
$func .= ' && '.$name;
}
$aifcounter++;
}
$func .= ")\n\t{";
}
else
{
$func .= "\n\t//".$this->setLine(__LINE__)." set the function logic";
$func .= "\n\tif (";
// set if counter
$ifcounter = 0;
foreach ($f_matchKeys as $f_matchKey)
{
$if = $ifValue[$f_matchKey];
if (ComponentbuilderHelper::checkString($if))
{
if ($ifcounter == 0)
{
$func .= $if;
}
else
{
$func .= ' && '.$if;
}
$ifcounter++;
}
}
$func .= ")\n\t{";
}
// get the controles
$controls = $targetControls[$f_matchKeys[0]];
// get target behavior and default
$targetBehavior = $behaviors[$f_matchKeys[0]];
$targetDefault = $defaults[$f_matchKeys[0]];
// load the target behavior
foreach($controls as $target => $action)
{
$func .= $action['behavior'];
if (ComponentbuilderHelper::checkString($action['hide']))
{
$func .= $action[$targetBehavior];
$head .= $action['requiredVar'];
}
}
$func .= "\n\t}\n\telse\n\t{";
foreach($controls as $target => $action)
{
$func .= $action['default'];
if (ComponentbuilderHelper::checkString($action['hide']))
{
$func .= $action[$targetDefault];
}
}
$func .= "\n\t}\n}\n".$map;
}
// add the needed validation to file
if (isset($this->validationFixBuilder[$viewName]) && ComponentbuilderHelper::checkArray($this->validationFixBuilder[$viewName]))
{
$validation .= "\n// update required fields";
$validation .= "\nfunction updateFieldRequired(name,status)";
$validation .= "\n{";
$validation .= "\n\tvar not_required = jQuery('#jform_not_required').val();";
$validation .= "\n\n\tif(status == 1)";
$validation .= "\n\t{";
$validation .= "\n\t\tif (isSet(not_required) && not_required != 0)";
$validation .= "\n\t\t{";
$validation .= "\n\t\t\tnot_required = not_required+','+name;";
$validation .= "\n\t\t}";
$validation .= "\n\t\telse";
$validation .= "\n\t\t{";
$validation .= "\n\t\t\tnot_required = ','+name;";
$validation .= "\n\t\t}";
$validation .= "\n\t}";
$validation .= "\n\telse";
$validation .= "\n\t{";
$validation .= "\n\t\tif (isSet(not_required) && not_required != 0)";
$validation .= "\n\t\t{";
$validation .= "\n\t\t\tnot_required = not_required.replace(','+name,'');";
$validation .= "\n\t\t}";
$validation .= "\n\t}";
$validation .= "\n\n\tjQuery('#jform_not_required').val(not_required);";
$validation .= "\n}\n";
}
// set the isSet function
$isSet = "\n// the isSet function";
$isSet .= "\nfunction isSet(val)";
$isSet .= "\n{";
$isSet .= "\n\tif ((val != undefined) && (val != null) && 0 !== val.length){";
$isSet .= "\n\t\treturn true;";
$isSet .= "\n\t}";
$isSet .= "\n\treturn false;";
$isSet .= "\n}";
}
// load to this buket
$fileScript = $initial.$func.$validation.$isSet;
$footerScript = $listener;
}
// add custom script to file
if (isset($this->customScriptBuilder['view_file'][$viewName]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['view_file'][$viewName]))
{
if (!isset($fileScript))
{
$fileScript = '';
}
$fileScript .= "\n\n".str_replace(array_keys($placeholders),array_values($placeholders),$this->customScriptBuilder['view_file'][$viewName]);
}
// add custom script to footer
if (isset($this->customScriptBuilder['view_footer'][$viewName]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['view_footer'][$viewName]))
{
$customFooterScript = "\n\n".str_replace(array_keys($placeholders),array_values($placeholders),$this->customScriptBuilder['view_footer'][$viewName]);
if (strpos($customFooterScript,'params->get('minify') && isset($fileScript) && ComponentbuilderHelper::checkString($fileScript))
{
// minify the fielScript javscript
$minifier = new JS;
$minifier->add($fileScript);
$fileScript = $minifier->minify();
}
// minfy the script
if ($this->params->get('minify') && isset($footerScript) && ComponentbuilderHelper::checkString($footerScript))
{
// minify the footerScript javscript
$minifier = new JS;
$minifier->add($footerScript);
$footerScript = $minifier->minify();
}
// make sure there is script to add
if (isset($fileScript) && ComponentbuilderHelper::checkString($fileScript))
{
// add the head script if set
if (isset($head) && ComponentbuilderHelper::checkString($head))
{
$fileScript = "// Some Global Values\n".$head."\n".$fileScript;
}
// load the script
$this->editBodyViewScriptBuilder[$viewName]['fileScript'] = $fileScript;
}
// make sure to add custom footer script if php was found in it, since we canot minfy it with php
if (isset($customFooterScript) && ComponentbuilderHelper::checkString($customFooterScript))
{
if (!isset($footerScript))
{
$footerScript = '';
}
$footerScript .= $customFooterScript;
}
// make sure there is script to add
if (isset($footerScript) && ComponentbuilderHelper::checkString($footerScript))
{
// add the needed script tags
$footerScript = "\n\n".'";
$this->editBodyViewScriptBuilder[$viewName]['footerScript'] = $footerScript;
}
}
protected function buildFunctionCall($function,$matchKeys,$getValue)
{
$initial = '';
$funcsets = array();
$array = false;
foreach ($matchKeys as $matchKey)
{
$value = $getValue[$matchKey];
if ($value['isArray'])
{
$initial .= "\n\t".$value['get'];
$funcsets[] = $matchKey;
$array = true;
}
else
{
$initial .= "\n\t".$value['get'];
$funcsets[] = $matchKey;
}
}
// make sure that the function is loaded only once
if (ComponentbuilderHelper::checkArray($funcsets))
{
$initial .= "\n\t".$function."(";
$initial .= implode(',',$funcsets);
$initial .= ");\n";
}
return array('code' => $initial, 'array' => $array);
}
protected function getTargetRelationScript($relations,$condition,$view)
{
// reset the buket
$buket = array();
// convert to name array
foreach ($condition['target_field'] as $targetField)
{
if (ComponentbuilderHelper::checkArray($targetField))
{
$currentTargets[] = $targetField['name'];
}
}
// start the search
foreach($relations as $relation)
{
// reset found
$found = false;
if ($relation['match_field'] != $condition['match_field'])
{
if (ComponentbuilderHelper::checkArray($relation['target_field']))
{
foreach($relation['target_field'] as $target)
{
if (ComponentbuilderHelper::checkArray($target) && $this->checkRelationControl($target['name'],$relation['match_name'],$condition['match_name'],$view))
{
if (in_array($target['name'],$currentTargets))
{
$this->targetRelationControl[$view][$target['name']] = array($relation['match_name'],$condition['match_name']);
$found = true;
break;
}
}
}
if ($found)
{
$buket[] = $relation;
}
}
}
}
return $buket;
}
protected function checkRelationControl($targetName,$relationMatchName,$conditionMatchName,$view)
{
if(isset($this->targetRelationControl[$view]) && ComponentbuilderHelper::checkArray($this->targetRelationControl[$view]))
{
if(isset($this->targetRelationControl[$view][$targetName]) && ComponentbuilderHelper::checkArray($this->targetRelationControl[$view][$targetName]))
{
if (!in_array($relationMatchName,$this->targetRelationControl[$view][$targetName]) || !in_array($conditionMatchName,$this->targetRelationControl[$view][$targetName]))
{
return true;
}
}
else
{
return true;
}
}
elseif (!isset($this->targetRelationControl[$view]) || !ComponentbuilderHelper::checkArray($this->targetRelationControl[$view]))
{
return true;
}
return false;
}
protected function setTargetControlsScript($targets,$targetBehavior,$targetDefault,$uniqueVar,$viewName)
{
$bucket = array();
if (ComponentbuilderHelper::checkArray($targets) && !in_array($uniqueVar,$this->targetControlsScriptChecker))
{
foreach($targets as $target)
{
if (ComponentbuilderHelper::checkArray($target))
{
// set the required var
if($target['required'] == 'yes')
{
$unique = $uniqueVar.ComponentbuilderHelper::randomkey(3);
$bucket[$target['name']]['requiredVar'] = "jform_".$unique."_required = false;\n";
}
else
{
$bucket[$target['name']]['requiredVar'] = '';
}
// set target type
$targetTypeSufix = "";
if ($this->defaultField($target['type'], 'spacer'))
{
// target a class if this is a note or spacer
$targetType = ".";
}
elseif ($target['type'] == 'editor')
{
// target the label if editor field
$targetType = "#jform_";
// since the id is not alway accessable we use the lable TODO (not best way)
$targetTypeSufix = "-lbl";
}
else
{
// target an id if this is a field
$targetType = "#jform_";
}
// set the target behavior
$bucket[$target['name']]['behavior'] = "\n\t\tjQuery('".$targetType.$target['name'].$targetTypeSufix."').closest('.control-group').".$targetBehavior."();";
// set the target default
$bucket[$target['name']]['default'] = "\n\t\tjQuery('".$targetType.$target['name'].$targetTypeSufix."').closest('.control-group').".$targetDefault."();";
// the hide required function
if($target['required'] == 'yes')
{
$hide = "\n\t\tif (!jform_".$unique."_required)";
$hide .= "\n\t\t{";
$hide .= "\n\t\t\tupdateFieldRequired('".$target['name']."',1);";
$hide .= "\n\t\t\tjQuery('#jform_".$target['name']."').removeAttr('required');";
$hide .= "\n\t\t\tjQuery('#jform_".$target['name']."').removeAttr('aria-required');";
$hide .= "\n\t\t\tjQuery('#jform_".$target['name']."').removeClass('required');";
$hide .= "\n\t\t\tjform_".$unique."_required = true;";
$hide .= "\n\t\t}";
$bucket[$target['name']]['hide'] = $hide;
// the show required function
$show = "\n\t\tif (jform_".$unique."_required)";
$show .= "\n\t\t{";
$show .= "\n\t\t\tupdateFieldRequired('".$target['name']."',0);";
$show .= "\n\t\t\tjQuery('#jform_".$target['name']."').prop('required','required');";
$show .= "\n\t\t\tjQuery('#jform_".$target['name']."').attr('aria-required',true);";
$show .= "\n\t\t\tjQuery('#jform_".$target['name']."').addClass('required');";
$show .= "\n\t\t\tjform_".$unique."_required = false;";
$show .= "\n\t\t}\n";
$bucket[$target['name']]['show'] = $show;
// make sure that the axaj and other needed things for this view is loaded
$this->validationFixBuilder[$viewName][] = $target['name'];
}
else
{
$bucket[$target['name']]['hide'] = '';
$bucket[$target['name']]['show'] = '';
}
}
}
$this->targetControlsScriptChecker[] = $uniqueVar;
}
return $bucket;
}
protected function ifValueScript($value,$behavior,$type,$options)
{
// reset string
$string = '';
switch ($behavior)
{
case 1: // Is
// only 4 list/radio/checkboxes
if(ComponentbuilderHelper::typeField($type, 'list') || ComponentbuilderHelper::typeField($type, 'dynamic') || !ComponentbuilderHelper::typeField($type))
{
if (ComponentbuilderHelper::checkArray($options))
{
foreach ($options as $option)
{
if (!is_numeric($option))
{
if($option != 'true' && $option != 'false')
{
$option = "'".$option."'";
}
}
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' || '.$value.' == '.$option;
}
else
{
$string .= $value.' == '.$option;
}
}
}
else
{
$string .= 'isSet('.$value.')';
}
}
break;
case 2: // Is Not
// only 4 list/radio/checkboxes
if(ComponentbuilderHelper::typeField($type, 'list') || ComponentbuilderHelper::typeField($type, 'dynamic') || !ComponentbuilderHelper::typeField($type))
{
if (ComponentbuilderHelper::checkArray($options))
{
foreach ($options as $option)
{
if (!is_numeric($option))
{
if($option != 'true' && $option != 'false')
{
$option = "'".$option."'";
}
}
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' || '.$value.' != '.$option;
}
else
{
$string .= $value.' != '.$option;
}
}
}
else
{
$string .= '!isSet('.$value.')';
}
}
break;
case 3: // Any Selection
// only 4 list/radio/checkboxes/dynamic_list
if(ComponentbuilderHelper::typeField($type, 'list') || ComponentbuilderHelper::typeField($type, 'dynamic') || !ComponentbuilderHelper::typeField($type))
{
if (ComponentbuilderHelper::checkArray($options))
{
foreach ($options as $option)
{
if (!is_numeric($option))
{
if($option != 'true' && $option != 'false')
{
$option = "'".$option."'";
}
}
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' || '.$value.' == '.$option;
}
else
{
$string .= $value.' == '.$option;
}
}
}
else
{
$userFix = '';
if (isset($this->setScriptUserSwitch) && ComponentbuilderHelper::checkArray($this->setScriptUserSwitch) && in_array($type,$this->setScriptUserSwitch))
{
// TODO this needs a closer look, a bit buggy
$userFix = " && ".$value." != 'Select a User.'";
}
//echo '
'; var_dump($type);exit;
$string .= 'isSet('.$value.')'.$userFix;
}
}
break;
case 4: // Active (not empty)
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
$string .= 'isSet('.$value.')';
}
break;
case 5: // Unactive (empty)
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
$string .= '!isSet('.$value.')';
}
break;
case 6: // Key Word All (case-sensitive)
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options['keywords']))
{
foreach ($options['keywords'] as $keyword)
{
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' && '.$value.'.indexOf("'.$keyword.'") >= 0';
}
else
{
$string .= $value.'.indexOf("'.$keyword.'") >= 0';
}
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.' == "error"';
}
}
break;
case 7: // Key Word Any (case-sensitive)
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options['keywords']))
{
foreach ($options['keywords'] as $keyword)
{
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' || '.$value.'.indexOf("'.$keyword.'") >= 0';
}
else
{
$string .= $value.'.indexOf("'.$keyword.'") >= 0';
}
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.' == "error"';
}
}
break;
case 8: // Key Word All (case-insensitive)
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options['keywords']))
{
foreach ($options['keywords'] as $keyword)
{
$keyword = ComponentbuilderHelper::safeString($keyword, 'w');
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' && '.$value.'.toLowerCase().indexOf("'.$keyword.'") >= 0';
}
else
{
$string .= $value.'.toLowerCase().indexOf("'.$keyword.'") >= 0';
}
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.' == "error"';
}
}
break;
case 9: // Key Word Any (case-insensitive)
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options['keywords']))
{
foreach ($options['keywords'] as $keyword)
{
$keyword = ComponentbuilderHelper::safeString($keyword, 'w');
if(ComponentbuilderHelper::checkString($string))
{
$string .= ' || '.$value.'.toLowerCase().indexOf("'.$keyword.'") >= 0';
}
else
{
$string .= $value.'.toLowerCase().indexOf("'.$keyword.'") >= 0';
}
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.' == "error"';
}
}
break;
case 10: // Min Length
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options))
{
if ($options['length'])
{
$string .= $value.'.length >= '.(int) $options['length'];
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.'.length >= 5';
}
}
break;
case 11: // Max Length
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options))
{
if ($options['length'])
{
$string .= $value.'.length <= '.(int) $options['length'];
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.'.length <= 5';
}
}
break;
case 12: // Exact Length
// only 4 text_field
if(ComponentbuilderHelper::typeField($type, 'text'))
{
if (ComponentbuilderHelper::checkArray($options))
{
if ($options['length'])
{
$string .= $value.'.length == '.(int) $options['length'];
}
}
if(!ComponentbuilderHelper::checkString($string))
{
$string .= $value.'.length == 5';
}
}
break;
}
if(!ComponentbuilderHelper::checkString($string))
{
$string = 0;
}
return $string;
}
protected function getOptionsScript($type,$options)
{
$buket = array();
if(ComponentbuilderHelper::checkString($options))
{
if(ComponentbuilderHelper::typeField($type, 'list') || ComponentbuilderHelper::typeField($type, 'dynamic') || !ComponentbuilderHelper::typeField($type))
{
$optionsArray = explode(PHP_EOL, $options);
if (!ComponentbuilderHelper::checkArray($optionsArray))
{
$optionsArray[] = $optionsArray;
}
foreach($optionsArray as $option)
{
if (strpos($option,'|') !== false)
{
list($option) = explode('|', $option);
}
if ($option != 'dynamic_list')
{
// add option to return buket
$buket[] = $option;
}
}
}
elseif(ComponentbuilderHelper::typeField($type, 'text'))
{
// check to get the key words if set
$keywords = ComponentbuilderHelper::getBetween($options,'keywords="','"');
if (ComponentbuilderHelper::checkString($keywords))
{
if (strpos($keywords,',') !== false)
{
$keywords = explode(',', $keywords);
foreach($keywords as $keyword)
{
$buket['keywords'][] = trim($keyword);
}
}
else
{
$buket['keywords'][] = trim($keywords);
}
}
// check to ket string length if set
$length = ComponentbuilderHelper::getBetween($options,'length="','"');
if (ComponentbuilderHelper::checkString($length))
{
$buket['length'] = $length;
} else {
$buket['length'] = false;
}
}
}
return $buket;
}
protected function getValueScript($type,$name,$unique)
{
$select = '';
$isArray = false;
$keyName = $name.'_'.$unique;
if ($type == 'checkboxes')
{
$select = "var ".$keyName." = [];\n\tjQuery('#jform_".$name." input[type=checkbox]').each(function()\n\t{\n\t\tif (jQuery(this).is(':checked'))\n\t\t{\n\t\t\t".$keyName.".push(jQuery(this).prop('value'));\n\t\t}\n\t});";
$isArray = true;
}
elseif($type == 'checkbox')
{
$select = 'var '.$keyName.' = jQuery("#jform_'.$name.'").prop(\'checked\');';
}
elseif ($type == 'radio')
{
$select = 'var '.$keyName.' = jQuery("#jform_'.$name.' input[type=\'radio\']:checked").val();';
}
elseif ($type == 'list' || ComponentbuilderHelper::typeField($type, 'dynamic') || !ComponentbuilderHelper::typeField($type))
{
$select = 'var '.$keyName.' = jQuery("#jform_'.$name.'").val();';
$isArray = true;
}
elseif(ComponentbuilderHelper::typeField($type, 'text'))
{
$select = 'var '.$keyName.' = jQuery("#jform_'.$name.'").val();';
}
return array( 'get' => $select, 'isArray' => $isArray);
}
protected function clearValueScript($type,$name,$unique)
{
$clear = '';
$isArray = false;
$keyName = $name.'_'.$unique;
if($type == 'text' || $type == 'password' || $type == 'textarea')
{
$clear = "jQuery('#jform_".$name."').value = '';";
}
elseif($type == 'radio')
{
$clear = "jQuery('#jform_".$name."').checked = false;";
}
elseif($type == 'checkboxes' || $type == 'checkbox' || $type == 'checkbox')
{
$clear = "jQuery('#jform_".$name."').selectedIndex = -1;";
}
return $clear;
}
protected function setViewScript($view)
{
if (isset($this->editBodyViewScriptBuilder[$view]) && isset($this->editBodyViewScriptBuilder[$view]['fileScript']))
{
return $this->editBodyViewScriptBuilder[$view]['fileScript'];
}
return '';
}
protected function setEditBodyScript($view)
{
if (isset($this->editBodyViewScriptBuilder[$view]) && isset($this->editBodyViewScriptBuilder[$view]['footerScript']))
{
return $this->editBodyViewScriptBuilder[$view]['footerScript'];
}
return '';
}
protected function setValidationFix($view,$Component)
{
$fix = '';
if (isset($this->validationFixBuilder[$view]) && ComponentbuilderHelper::checkArray($this->validationFixBuilder[$view]))
{
$fix .= "\n\n\t/**";
$fix .= "\n\t* Method to validate the form data.";
$fix .= "\n\t*";
$fix .= "\n\t* @param JForm \$form The form to validate against.";
$fix .= "\n\t* @param array \$data The data to validate.";
$fix .= "\n\t* @param string \$group The name of the field group to validate.";
$fix .= "\n\t*";
$fix .= "\n\t* @return mixed Array of filtered data if valid, false otherwise.";
$fix .= "\n\t*";
$fix .= "\n\t* @see JFormRule";
$fix .= "\n\t* @see JFilterInput";
$fix .= "\n\t* @since 12.2";
$fix .= "\n\t*/";
$fix .= "\n\tpublic function validate(\$form, \$data, \$group = null)";
$fix .= "\n\t{";
$fix .= "\n\t\t//".$this->setLine(__LINE__)." check if the not_required field is set";
$fix .= "\n\t\tif (".$Component."Helper::checkString(\$data['not_required']))";
$fix .= "\n\t\t{";
$fix .= "\n\t\t\t\$requiredFields = (array) explode(',',(string) \$data['not_required']);";
$fix .= "\n\t\t\t\$requiredFields = array_unique(\$requiredFields);";
$fix .= "\n\t\t\t//".$this->setLine(__LINE__)." now change the required field attributes value";
$fix .= "\n\t\t\tforeach (\$requiredFields as \$requiredField)";
$fix .= "\n\t\t\t{";
$fix .= "\n\t\t\t\t//".$this->setLine(__LINE__)." make sure there is a string value";
$fix .= "\n\t\t\t\tif (".$Component."Helper::checkString(\$requiredField))";
$fix .= "\n\t\t\t\t{";
$fix .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." change to false";
$fix .= "\n\t\t\t\t\t\$form->setFieldAttribute(\$requiredField, 'required', 'false');";
$fix .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." also clear the data set";
$fix .= "\n\t\t\t\t\t\$data[\$requiredField] = '';";
$fix .= "\n\t\t\t\t}";
$fix .= "\n\t\t\t}";
$fix .= "\n\t\t}";
$fix .= "\n\t\treturn parent::validate(\$form, \$data, \$group);";
$fix .= "\n\t}";
}
return $fix;
}
protected function setAjaxToke($view)
{
$fix = '';
if (isset($this->customScriptBuilder['token'][$view]) && $this->customScriptBuilder['token'][$view])
{
$fix .= "\n\t\t//".$this->setLine(__LINE__)." Add Ajax Token";
$fix .= "\n\t\t\$document->addScriptDeclaration(\"var token = '\".JSession::getFormToken().\"';\");";
}
return $fix;
}
protected function setRegisterAjaxTask($target)
{
$tasks = '';
if (isset($this->customScriptBuilder[$target]['ajax_controller']) && ComponentbuilderHelper::checkArray($this->customScriptBuilder[$target]['ajax_controller']))
{
$taskArray = array();
foreach ($this->customScriptBuilder[$target]['ajax_controller'] as $view)
{
foreach ($view as $task)
{
$taskArray[$task['task_name']] = $task['task_name'];
}
}
if (ComponentbuilderHelper::checkArray($taskArray))
{
foreach ($taskArray as $name)
{
$tasks .= "\n\t\t\$this->registerTask('".$name."', 'ajax');";
}
}
}
return $tasks;
}
protected function setAjaxInputReturn($target)
{
$cases = '';
if (isset($this->customScriptBuilder[$target]['ajax_controller']) && ComponentbuilderHelper::checkArray($this->customScriptBuilder[$target]['ajax_controller']))
{
$input = array();
$valueArray = array();
$getModel = array();
foreach ($this->customScriptBuilder[$target]['ajax_controller'] as $view)
{
foreach ($view as $task)
{
$input[$task['task_name']][] = "\n\t\t\t\t\t\t\$".$task['value_name']."Value = \$jinput->get('".$task['value_name']."', ".$task['input_default'].", '".$task['input_filter']."');";
$valueArray[$task['task_name']][] = "\$".$task['value_name']."Value";
$getModel[$task['task_name']] = "\n\t\t\t\t\t\t\t\$result = \$this->getModel('ajax')->".$task['method_name']."([[[valueArray]]]);";
// see user check is needed
if (!isset($task['user_check']) || 1 == $task['user_check'])
{
// add it since this means it was not set, and in the old method we assumed it was inplace
// or it is set and 1 means we still want it inplace
$userCheck[$task['task_name']] = ' && $user->id != 0';
}
else
{
$userCheck[$task['task_name']] = '';
}
}
}
if (ComponentbuilderHelper::checkArray($getModel))
{
foreach ($getModel as $task => $getMethod)
{
$cases .= "\n\t\t\t\tcase '".$task."':";
$cases .= "\n\t\t\t\t\ttry";
$cases .= "\n\t\t\t\t\t{";
foreach ($input[$task] as $string)
{
$cases .= $string;
}
// set the values
$values = implode(', ',$valueArray[$task]);
$ifvalues = implode(' && ',$valueArray[$task]);
// set the values to method
$getMethod = str_replace('[[[valueArray]]]',$values,$getMethod);
$cases .= "\n\t\t\t\t\t\tif(".$ifvalues.$userCheck[$task].")";
$cases .= "\n\t\t\t\t\t\t{";
$cases .= $getMethod;
$cases .= "\n\t\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\t\telse";
$cases .= "\n\t\t\t\t\t\t{";
$cases .= "\n\t\t\t\t\t\t\t\$result = false;";
$cases .= "\n\t\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\t\tif(array_key_exists('callback',\$_GET))";
$cases .= "\n\t\t\t\t\t\t{";
$cases .= "\n\t\t\t\t\t\t\techo \$_GET['callback'] . \"(\".json_encode(\$result).\");\";";
$cases .= "\n\t\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\t\telse";
$cases .= "\n\t\t\t\t\t\t{";
$cases .= "\n\t\t\t\t\t\t\techo \"(\".json_encode(\$result).\");\";";
$cases .= "\n\t\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\tcatch(Exception \$e)";
$cases .= "\n\t\t\t\t\t{";
$cases .= "\n\t\t\t\t\t\tif(array_key_exists('callback',\$_GET))";
$cases .= "\n\t\t\t\t\t\t{";
$cases .= "\n\t\t\t\t\t\t\techo \$_GET['callback'].\"(\".json_encode(\$e).\");\";";
$cases .= "\n\t\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\t\telse";
$cases .= "\n\t\t\t\t\t\t{";
$cases .= "\n\t\t\t\t\t\t\techo \"(\".json_encode(\$e).\");\";";
$cases .= "\n\t\t\t\t\t\t}";
$cases .= "\n\t\t\t\t\t}";
$cases .= "\n\t\t\t\tbreak;";
}
}
}
return $cases;
}
protected function setAjaxModelMethods($target)
{
$methods = '';
if (isset($this->customScriptBuilder[$target]['ajax_model']) && ComponentbuilderHelper::checkArray($this->customScriptBuilder[$target]['ajax_model']))
{
foreach ($this->customScriptBuilder[$target]['ajax_model'] as $view => $method)
{
$methods .= "\n\n\t//".$this->setLine(__LINE__)." Used in ".$view."\n";
$methods .= str_replace(array_keys($this->placeholders),array_values($this->placeholders),$method);
}
}
return $methods;
}
protected function setFilterFunctions($viewName_single,$viewName_list)
{
if (isset($this->filterBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->filterBuilder[$viewName_list]))
{
$function = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
foreach ($this->filterBuilder[$viewName_list] as $filter)
{
if ($filter['type'] != 'category' && ComponentbuilderHelper::checkArray($filter['custom']) && $filter['custom']['extends'] == 'user')
{
$function[] = "\n\tprotected function getThe".$filter['function'].ComponentbuilderHelper::safeString($filter['custom']['text'],'F')."Selections()";
$function[] = "\t{";
$function[] = "\t\t//".$this->setLine(__LINE__)." Get a db connection.";
$function[] = "\t\t\$db = JFactory::getDbo();";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$function[] = "\t\t\$query = \$db->getQuery(true);";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Select the text.";
$function[] = "\t\t\$query->select(\$db->quoteName(array('a.".$filter['custom']['id']."','a.".$filter['custom']['text']."')));";
$function[] = "\t\t\$query->from(\$db->quoteName('".$filter['custom']['table']."', 'a'));";
$function[] = "\t\t//".$this->setLine(__LINE__)." get the targeted groups";
$function[] = "\t\t\$groups= JComponentHelper::getParams('com_".$component."')->get('".$filter['type']."');";
$function[] = "\t\tif (count(\$groups) > 0)";
$function[] = "\t\t{";
$function[] = "\t\t\t\$query->join('LEFT', \$db->quoteName('#__user_usergroup_map', 'group') . ' ON (' . \$db->quoteName('group.user_id') . ' = ' . \$db->quoteName('a.id') . ')');";
$function[] = "\t\t\t\$query->where('group.group_id IN (' . implode(',', \$groups) . ')');";
$function[] = "\t\t}";
$function[] = "\t\t\$query->order('a.".$filter['custom']['text']." ASC');";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Reset the query using our newly populated query object.";
$function[] = "\t\t\$db->setQuery(\$query);";
$function[] = "\n\t\t\$results = \$db->loadObjectList();";
$function[] = "\t\tif (\$results)";
$function[] = "\t\t{";
$function[] = "\t\t\t\$filter = array();";
$function[] = "\t\t\t\$batch = array();";
$function[] = "\t\t\tforeach (\$results as \$result)";
$function[] = "\t\t\t{";
$function[] = "\t\t\t\t\$filter[] = JHtml::_('select.option', \$result->".$filter['custom']['id'].", \$result->".$filter['custom']['text'].");";
$function[] = "\t\t\t}";
$function[] = "\t\t\treturn \$filter;";
$function[] = "\t\t}";
$function[] = "\t\treturn false;";
$function[] = "\t}";
/* else
{
$function[] = "\n\tprotected function getThe".$filter['function'].ComponentbuilderHelper::safeString($filter['custom']['text'],'F')."Selections()";
$function[] = "\t{";
$function[] = "\t\t//".$this->setLine(__LINE__)." Get a db connection.";
$function[] = "\t\t\$db = JFactory::getDbo();";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Select the text.";
$function[] = "\t\t\$query = \$db->getQuery(true);";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Select the text.";
$function[] = "\t\t\$query->select(\$db->quoteName(array('".$filter['custom']['id']."','".$filter['custom']['text']."')));";
$function[] = "\t\t\$query->from(\$db->quoteName('".$filter['custom']['table']."'));";
$function[] = "\t\t\$query->where(\$db->quoteName('published') . ' = 1');";
$function[] = "\t\t\$query->order(\$db->quoteName('".$filter['custom']['text']."') . ' ASC');";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Reset the query using our newly populated query object.";
$function[] = "\t\t\$db->setQuery(\$query);";
$function[] = "\n\t\t\$results = \$db->loadObjectList();";
$function[] = "\n\t\tif (\$results)";
$function[] = "\t\t{";
$function[] = "\t\t\t\$filter = array();";
$function[] = "\t\t\t\$batch = array();";
$function[] = "\t\t\tforeach (\$results as \$result)";
$function[] = "\t\t\t{";
if ($filter['custom']['text'] == 'user')
{
$function[] = "\t\t\t\t\$filter[] = JHtml::_('select.option', \$result->".$filter['custom']['text'].", JFactory::getUser(\$result->".$filter['custom']['text'].")->name);";
$function[] = "\t\t\t\t\$batch[] = JHtml::_('select.option', \$result->".$filter['custom']['id'].", JFactory::getUser(\$result->".$filter['custom']['text'].")->name);";
}
else
{
$function[] = "\t\t\t\t\$filter[] = JHtml::_('select.option', \$result->".$filter['custom']['text'].", \$result->".$filter['custom']['text'].");";
$function[] = "\t\t\t\t\$batch[] = JHtml::_('select.option', \$result->".$filter['custom']['id'].", \$result->".$filter['custom']['text'].");";
}
$function[] = "\t\t\t}";
$function[] = "\t\t\treturn array('filter' => \$filter, 'batch' => \$batch);";
$function[] = "\t\t}";
$function[] = "\t\treturn false;";
$function[] = "\t}";
}*/
}
elseif ($filter['type'] != 'category' && !ComponentbuilderHelper::checkArray($filter['custom']))
{
$translation = false;
if (isset($this->selectionTranslationFixBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->selectionTranslationFixBuilder[$viewName_list])
&& array_key_exists($filter['code'],$this->selectionTranslationFixBuilder[$viewName_list]))
{
$translation = true;
}
$function[] = "\n\tprotected function getThe".$filter['function']."Selections()";
$function[] = "\t{";
$function[] = "\t\t//".$this->setLine(__LINE__)." Get a db connection.";
$function[] = "\t\t\$db = JFactory::getDbo();";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Create a new query object.";
$function[] = "\t\t\$query = \$db->getQuery(true);";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Select the text.";
$function[] = "\t\t\$query->select(\$db->quoteName('".$filter['code']."'));";
$function[] = "\t\t\$query->from(\$db->quoteName('#__".$component."_".$filter['database']."'));";
$function[] = "\t\t\$query->order(\$db->quoteName('".$filter['code']."') . ' ASC');";
$function[] = "\n\t\t//".$this->setLine(__LINE__)." Reset the query using our newly populated query object.";
$function[] = "\t\t\$db->setQuery(\$query);";
$function[] = "\n\t\t\$results = \$db->loadColumn();";
$function[] = "\n\t\tif (\$results)";
$function[] = "\t\t{";
// check if translated vlaue is used
if ($translation)
{
$function[] = "\t\t\t//".$this->setLine(__LINE__)." get model";
$function[] = "\t\t\t\$model = \$this->getModel();";
}
$function[] = "\t\t\t\$results = array_unique(\$results);";
$function[] = "\t\t\t\$filter = array();";
$function[] = "\t\t\tforeach (\$results as \$".$filter['code'].")";
$function[] = "\t\t\t{";
// check if translated vlaue is used
if ($translation)
{
$function[] = "\t\t\t\t//".$this->setLine(__LINE__)." Translate the ".$filter['code']." selection";
$function[] = "\t\t\t\t\$text = \$model->selectionTranslation(\$".$filter['code'].",'".$filter['code']."');";
$function[] = "\t\t\t\t//".$this->setLine(__LINE__)." Now add the ".$filter['code']." and its text to the options array";
$function[] = "\t\t\t\t\$filter[] = JHtml::_('select.option', \$".$filter['code'].", JText::_(\$text));";
}
else
{
$function[] = "\t\t\t\t//".$this->setLine(__LINE__)." Now add the ".$filter['code']." and its text to the options array";
$function[] = "\t\t\t\t\$filter[] = JHtml::_('select.option', \$".$filter['code'].", \$".$filter['code'].");";
}
$function[] = "\t\t\t}";
$function[] = "\t\t\treturn \$filter;";
$function[] = "\t\t}";
$function[] = "\t\treturn false;";
$function[] = "\t}";
}
}
if (ComponentbuilderHelper::checkArray($function))
{
// return the function
return "\n".implode("\n",$function);
}
}
return '';
}
protected function setUniqueFields($view)
{
$fields = array();
$fields[] = "\n\n\t/**";
$fields[] = "\t * Method to get the unique fields of this table.";
$fields[] = "\t *";
$fields[] = "\t * @return mixed An array of field names, boolean false if none is set.";
$fields[] = "\t *";
$fields[] = "\t * @since 3.0";
$fields[] = "\t */";
$fields[] = "\tprotected function getUniqeFields()";
$fields[] = "\t{";
if (isset($this->dbUniqueKeys[$view]) && ComponentbuilderHelper::checkArray($this->dbUniqueKeys[$view]))
{
$fields[] = "\t\treturn array('".implode("','",$this->dbUniqueKeys[$view])."');";
}
else
{
$fields[] = "\t\treturn false;";
}
$fields[] = "\t}";
// return the unique fields
return implode("\n",$fields);
}
protected function setOtherFilter($view)
{
if (isset($this->filterBuilder[$view]) && ComponentbuilderHelper::checkArray($this->filterBuilder[$view]))
{
$otherFilter = array();
foreach ($this->filterBuilder[$view] as $filter)
{
if ($filter['type'] != 'category' && ComponentbuilderHelper::checkArray($filter['custom']) && $filter['custom']['extends'] !== 'user')
{
$CodeName = ComponentbuilderHelper::safeString($filter['code'].' '.$filter['custom']['text'],'W');
$codeName = $filter['code'].ComponentbuilderHelper::safeString($filter['custom']['text'],'F');
$type = ComponentbuilderHelper::safeString($filter['custom']['type'],'F');
$otherFilter[] = "\n\t\t//".$this->setLine(__LINE__)." Set ".$CodeName." Selection";
$otherFilter[] = "\t\t\$this->".$codeName."Options = JFormHelper::loadFieldType('".$type."')->getOptions();";
$otherFilter[] = "\t\tif (\$this->".$codeName."Options)";
$otherFilter[] = "\t\t{";
$otherFilter[] = "\t\t\t//".$this->setLine(__LINE__)." ".$CodeName." Filter";
$otherFilter[] = "\t\t\tJHtmlSidebar::addFilter(";
$otherFilter[] = "\t\t\t\t'- Select '.JText::_('".$filter['lang']."').' -',";
$otherFilter[] = "\t\t\t\t'filter_".$filter['code']."',";
$otherFilter[] = "\t\t\t\tJHtml::_('select.options', \$this->".$codeName."Options, 'value', 'text', \$this->state->get('filter.".$filter['code']."'))";
$otherFilter[] = "\t\t\t);";
$otherFilter[] = "\n\t\t\tif (\$this->canBatch && \$this->canCreate && \$this->canEdit)";
$otherFilter[] = "\t\t\t{";
$otherFilter[] = "\t\t\t\t//".$this->setLine(__LINE__)." ".$CodeName." Batch Selection";
$otherFilter[] = "\t\t\t\tJHtmlBatch_::addListSelection(";
$otherFilter[] = "\t\t\t\t\t'- Keep Original '.JText::_('".$filter['lang']."').' -',";
$otherFilter[] = "\t\t\t\t\t'batch[".$filter['code']."]',";
$otherFilter[] = "\t\t\t\t\tJHtml::_('select.options', \$this->".$codeName."Options, 'value', 'text')";
$otherFilter[] = "\t\t\t\t);";
$otherFilter[] = "\t\t\t}";
$otherFilter[] = "\t\t}";
}
elseif ($filter['type'] != 'category')
{
$Codename = ComponentbuilderHelper::safeString($filter['code'],'W');
if (isset($filter['custom']) && ComponentbuilderHelper::checkArray($filter['custom']) && $filter['custom']['extends'] === 'user')
{
$functionName = "\$this->getThe".$filter['function'].ComponentbuilderHelper::safeString($filter['custom']['text'],'F')."Selections();";
}
else
{
$functionName = "\$this->getThe".$filter['function']."Selections();";
}
$otherFilter[] = "\n\t\t//".$this->setLine(__LINE__)." Set ".$Codename." Selection";
$otherFilter[] = "\t\t\$this->".$filter['code']."Options = ".$functionName;
$otherFilter[] = "\t\tif (\$this->".$filter['code']."Options)";
$otherFilter[] = "\t\t{";
$otherFilter[] = "\t\t\t//".$this->setLine(__LINE__)." ".$Codename." Filter";
$otherFilter[] = "\t\t\tJHtmlSidebar::addFilter(";
$otherFilter[] = "\t\t\t\t'- Select '.JText::_('".$filter['lang']."').' -',";
$otherFilter[] = "\t\t\t\t'filter_".$filter['code']."',";
$otherFilter[] = "\t\t\t\tJHtml::_('select.options', \$this->".$filter['code']."Options, 'value', 'text', \$this->state->get('filter.".$filter['code']."'))";
$otherFilter[] = "\t\t\t);";
$otherFilter[] = "\n\t\t\tif (\$this->canBatch && \$this->canCreate && \$this->canEdit)";
$otherFilter[] = "\t\t\t{";
$otherFilter[] = "\t\t\t\t//".$this->setLine(__LINE__)." ".$Codename." Batch Selection";
$otherFilter[] = "\t\t\t\tJHtmlBatch_::addListSelection(";
$otherFilter[] = "\t\t\t\t\t'- Keep Original '.JText::_('".$filter['lang']."').' -',";
$otherFilter[] = "\t\t\t\t\t'batch[".$filter['code']."]',";
$otherFilter[] = "\t\t\t\t\tJHtml::_('select.options', \$this->".$filter['code']."Options, 'value', 'text')";
$otherFilter[] = "\t\t\t\t);";
$otherFilter[] = "\t\t\t}";
$otherFilter[] = "\t\t}";
}
}
if (ComponentbuilderHelper::checkArray($otherFilter))
{
// return the filter
return "\n".implode("\n",$otherFilter);
}
}
return '';
}
protected function setCategoryFilter($viewName_list)
{
if (isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list]))
{
// check if category has another name
if (isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
}
else
{
$otherViews = $viewName_list;
}
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
$COMONENT = ComponentbuilderHelper::safeString($this->componentData->name_code,'U');
// set filter
$filter = array();
$filter[] = "\n\n\t\t//".$this->setLine(__LINE__)." Category Filter.";
$filter[] = "\t\tJHtmlSidebar::addFilter(";
$filter[] = "\t\t\tJText::_('JOPTION_SELECT_CATEGORY'),";
$filter[] = "\t\t\t'filter_category_id',";
$filter[] = "\t\t\tJHtml::_('select.options', JHtml::_('category.options', 'com_".$component.".".$otherViews."'), 'value', 'text', \$this->state->get('filter.category_id'))";
$filter[] = "\t\t);";
$filter[] = "\n\t\tif (\$this->canBatch && \$this->canCreate && \$this->canEdit)";
$filter[] = "\t\t{";
$filter[] = "\t\t\t//".$this->setLine(__LINE__)." Category Batch selection.";
$filter[] = "\t\t\tJHtmlBatch_::addListSelection(";
$filter[] = "\t\t\t\tJText::_('COM_".$COMONENT."_KEEP_ORIGINAL_CATEGORY'),";
$filter[] = "\t\t\t\t'batch[category]',";
$filter[] = "\t\t\t\tJHtml::_('select.options', JHtml::_('category.options', 'com_".$component.".".$otherViews."'), 'value', 'text')";
$filter[] = "\t\t\t);";
$filter[] = "\t\t}";
// return the filter
return implode("\n",$filter);
}
return '';
}
protected function setRouterCategoryViews($viewName_single,$viewName_list)
{
if(isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list])){
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// check if category has another name
if (isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
$otherView = $this->catOtherName[$viewName_list]['view'];
}
else
{
$otherViews = $viewName_list;
$otherView = $viewName_single;
}
// return category view string
if (isset($this->fileContentStatic['###ROUTER_CATEGORY_VIEWS###']) && ComponentbuilderHelper::checkString($this->fileContentStatic['###ROUTER_CATEGORY_VIEWS###']))
{
return ",\n\t\t\t".'"com_'.$component.'.'.$otherViews.'" => "'.$otherView.'"';
}
else
{
return "\n\t\t\t".'"com_'.$component.'.'.$otherViews.'" => "'.$otherView.'"';
}
}
return '';
}
protected function setJcontrollerAllowAdd($viewName_single,$viewName_list)
{
$allow = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
// check if item has category
if(isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list])){
// check if category has another name
if ($coreLoad && isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
$otherView = $this->catOtherName[$viewName_list]['view'];
}
else
{
$otherViews = $viewName_list;
$otherView = $viewName_single;
}
// setup the category script
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." get the user object";
$allow[] = "\t\t\$user = JFactory::getUser();";
// check if the item has permissions.
if ($coreLoad && isset($core['core.access']) && isset($this->permissionBuilder['global'][$core['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.access']]) && in_array($otherView,$this->permissionBuilder['global'][$core['core.access']]))
{
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Access check.";
$allow[] = "\t\t\$access = \$user->authorise('".$core['core.access']."', 'com_".$component."');";
$allow[] = "\t\tif (!\$access)";
$allow[] = "\t\t{";
$allow[] = "\t\t\treturn false;";
$allow[] = "\t\t}";
}
$allow[] = "\t\t\$categoryId = JArrayHelper::getValue(\$data, 'catid', \$this->input->getInt('filter_category_id'), 'int');";
$allow[] = "\t\t\$allow = null;";
$allow[] = "\n\t\tif (\$categoryId)";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." If the category has been passed in the URL check it.";
$allow[] = "\t\t\t\$allow = \$user->authorise('core.create', \$this->option . '.".$otherViews.".category.' . \$categoryId);";
$allow[] = "\t\t}";
$allow[] = "\n\t\tif (\$allow === null)";
$allow[] = "\t\t{";
// check if the item has permissions.
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.create']]))
{
// setup the default script
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\t\treturn \$user->authorise('".$core['core.create']."', \$this->option);";
}
else
{
// setup the default script
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\t\treturn parent::allowAdd(\$data);";
}
$allow[] = "\t\t}";
$allow[] = "\t\telse";
$allow[] = "\t\t{";
$allow[] = "\t\t\treturn \$allow;";
$allow[] = "\t\t}";
}
else
{
// check if the item has permissions.
if ($coreLoad && isset($core['core.access']) && isset($this->permissionBuilder['global'][$core['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.access']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.access']]))
{
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Access check.";
$allow[] = "\t\t\$access = JFactory::getUser()->authorise('".$core['core.access']."', 'com_".$component."');";
$allow[] = "\t\tif (!\$access)";
$allow[] = "\t\t{";
$allow[] = "\t\t\treturn false;";
$allow[] = "\t\t}";
}
// check if the item has permissions.
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.create']]))
{
// setup the default script
$allow[] = "\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\treturn JFactory::getUser()->authorise('".$core['core.create']."', \$this->option);";
}
else
{
// setup the default script
$allow[] = "\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\treturn parent::allowAdd(\$data);";
}
}
return implode("\n",$allow);
}
protected function setJcontrollerAllowEdit($viewName_single,$viewName_list)
{
$allow = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// prepare custom permission script
if (isset($this->customScriptBuilder['php_allowedit'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_allowedit'][$viewName_single]))
{
$customAllow = str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_allowedit'][$viewName_single]);
}
else
{
$customAllow = '';
}
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
if(isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list])){
// check if category has another name
if ($coreLoad && isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
$otherView = $this->catOtherName[$viewName_list]['view'];
}
else
{
$otherViews = $viewName_list;
$otherView = $viewName_single;
}
// setup the category script
$allow[] = "\t\t//".$this->setLine(__LINE__)." get user object.";
$allow[] = "\t\t\$user\t\t= JFactory::getUser();";
$allow[] = "\t\t//".$this->setLine(__LINE__)." get record id.";
$allow[] = "\t\t\$recordId\t= (int) isset(\$data[\$key]) ? \$data[\$key] : 0;";
// load custom permission script
$allow[] = $customAllow;
// check if the item has permissions.
if ($coreLoad && isset($core['core.access']) && isset($this->permissionBuilder['global'][$core['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.access']]) && in_array($otherView,$this->permissionBuilder['global'][$core['core.access']]))
{
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Access check.";
$allow[] = "\t\t\$access = (\$user->authorise('".$core['core.access']."', 'com_".$component.".".$otherView.".' . (int) \$recordId) && \$user->authorise('".$core['core.access']."', 'com_".$component."'));";
$allow[] = "\t\tif (!\$access)";
$allow[] = "\t\t{";
$allow[] = "\t\t\treturn false;";
$allow[] = "\t\t}";
}
$allow[] = "\n\t\tif (\$recordId)";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder[$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit']]) && in_array($otherView,$this->permissionBuilder[$core['core.edit']]))
{
$allow[] = "\t\t\t\$permission = \$user->authorise('".$core['core.edit']."', 'com_".$component.".".$otherView.".' . (int) \$recordId);";
}
else
{
$allow[] = "\t\t\t\$permission = \$user->authorise('core.edit', 'com_".$component.".".$otherView.".' . (int) \$recordId);";
}
$allow[] = "\t\t\tif (!\$permission && !is_null(\$permission))";
$allow[] = "\t\t\t{";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.own']) && isset($this->permissionBuilder[$core['core.edit.own']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.own']]) && in_array($otherView,$this->permissionBuilder[$core['core.edit.own']]))
{
$allow[] = "\t\t\t\tif (\$user->authorise('".$core['core.edit.own']."', 'com_".$component.".".$otherView.".' . \$recordId))";
}
else
{
$allow[] = "\t\t\t\tif (\$user->authorise('core.edit.own', 'com_".$component.".".$otherView.".' . \$recordId))";
}
$allow[] = "\t\t\t\t{";
$allow[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Fallback on edit.own. Now test the owner is the user.";
$allow[] = "\t\t\t\t\t\$ownerId = (int) isset(\$data['created_by']) ? \$data['created_by'] : 0;";
$allow[] = "\t\t\t\t\tif (empty(\$ownerId))";
$allow[] = "\t\t\t\t\t{";
$allow[] = "\t\t\t\t\t\t//".$this->setLine(__LINE__)." Need to do a lookup from the model.";
$allow[] = "\t\t\t\t\t\t\$record = \$this->getModel()->getItem(\$recordId);";
$allow[] = "\n\t\t\t\t\t\tif (empty(\$record))";
$allow[] = "\t\t\t\t\t\t{";
$allow[] = "\t\t\t\t\t\t\treturn false;";
$allow[] = "\t\t\t\t\t\t}";
$allow[] = "\t\t\t\t\t\t\$ownerId = \$record->created_by;";
$allow[] = "\t\t\t\t\t}";
$allow[] = "\n\t\t\t\t\t//".$this->setLine(__LINE__)." If the owner matches 'me' then do the test.";
$allow[] = "\t\t\t\t\tif (\$ownerId == \$user->id)";
$allow[] = "\t\t\t\t\t{";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.own']) && isset($this->permissionBuilder['global'][$core['core.edit.own']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit.own']]) && in_array($otherView,$this->permissionBuilder['global'][$core['core.edit.own']]))
{
$allow[] = "\t\t\t\t\t\tif (\$user->authorise('".$core['core.edit.own']."', 'com_".$component."'))";
}
else
{
$allow[] = "\t\t\t\t\t\tif (\$user->authorise('core.edit.own', 'com_".$component."'))";
}
$allow[] = "\t\t\t\t\t\t{";
$allow[] = "\t\t\t\t\t\t\treturn true;";
$allow[] = "\t\t\t\t\t\t}";
$allow[] = "\t\t\t\t\t}";
$allow[] = "\t\t\t\t}";
$allow[] = "\t\t\t\treturn false;";
$allow[] = "\t\t\t}";
$allow[] = "\n\t\t\t\$categoryId = (int) isset(\$data['catid']) ? \$data['catid']: \$this->getModel()->getItem(\$recordId)->catid;";
$allow[] = "\n\t\t\tif (\$categoryId)";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\t//".$this->setLine(__LINE__)." The category has been set. Check the category permissions.";
$allow[] = "\t\t\t\t\$catpermission = \$user->authorise('core.edit', \$this->option . '.".$otherViews.".category.' . \$categoryId);";
$allow[] = "\t\t\t\tif (!\$catpermission && !is_null(\$catpermission))";
$allow[] = "\t\t\t\t{";
$allow[] = "\t\t\t\t\treturn false;";
$allow[] = "\t\t\t\t}";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($otherView,$this->permissionBuilder['global'][$core['core.edit']]))
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." Since there is no permission, revert to the component permissions.";
$allow[] = "\t\treturn \$user->authorise('".$core['core.edit']."', \$this->option);";
}
else
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." Since there is no permission, revert to the component permissions.";
$allow[] = "\t\treturn parent::allowEdit(\$data, \$key);";
}
}
else
{
// setup the category script
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." get user object.";
$allow[] = "\t\t\$user\t\t= JFactory::getUser();";
$allow[] = "\t\t//".$this->setLine(__LINE__)." get record id.";
$allow[] = "\t\t\$recordId\t= (int) isset(\$data[\$key]) ? \$data[\$key] : 0;";
// load custom permission script
$allow[] = $customAllow;
// check if the item has permissions.
if ($coreLoad && isset($core['core.access']) && isset($this->permissionBuilder[$core['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.access']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.access']]))
{
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Access check.";
$allow[] = "\t\t\$access = (\$user->authorise('".$core['core.access']."', 'com_".$component.".".$viewName_single.".' . (int) \$recordId) && \$user->authorise('".$core['core.access']."', 'com_".$component."'));";
$allow[] = "\t\tif (!\$access)";
$allow[] = "\t\t{";
$allow[] = "\t\t\treturn false;";
$allow[] = "\t\t}";
}
$allow[] = "\n\t\tif (\$recordId)";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder[$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit']]))
{
$allow[] = "\t\t\t\$permission = \$user->authorise('".$core['core.edit']."', 'com_".$component.".".$viewName_single.".' . (int) \$recordId);";
}
else
{
$allow[] = "\t\t\t\$permission = \$user->authorise('core.edit', 'com_".$component.".".$viewName_single.".' . (int) \$recordId);";
}
$allow[] = "\t\t\tif (!\$permission && !is_null(\$permission))";
$allow[] = "\t\t\t{";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.own']) && isset($this->permissionBuilder[$core['core.edit.own']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.own']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.own']]))
{
$allow[] = "\t\t\t\tif (\$user->authorise('".$core['core.edit.own']."', 'com_".$component.".".$viewName_single.".' . \$recordId))";
}
else
{
$allow[] = "\t\t\t\tif (\$user->authorise('core.edit.own', 'com_".$component.".".$viewName_single.".' . \$recordId))";
}
$allow[] = "\t\t\t\t{";
$allow[] = "\t\t\t\t\t//".$this->setLine(__LINE__)." Now test the owner is the user.";
$allow[] = "\t\t\t\t\t\$ownerId = (int) isset(\$data['created_by']) ? \$data['created_by'] : 0;";
$allow[] = "\t\t\t\t\tif (empty(\$ownerId))";
$allow[] = "\t\t\t\t\t{";
$allow[] = "\t\t\t\t\t\t//".$this->setLine(__LINE__)." Need to do a lookup from the model.";
$allow[] = "\t\t\t\t\t\t\$record = \$this->getModel()->getItem(\$recordId);";
$allow[] = "\n\t\t\t\t\t\tif (empty(\$record))";
$allow[] = "\t\t\t\t\t\t{";
$allow[] = "\t\t\t\t\t\t\treturn false;";
$allow[] = "\t\t\t\t\t\t}";
$allow[] = "\t\t\t\t\t\t\$ownerId = \$record->created_by;";
$allow[] = "\t\t\t\t\t}";
$allow[] = "\n\t\t\t\t\t//".$this->setLine(__LINE__)." If the owner matches 'me' then allow.";
$allow[] = "\t\t\t\t\tif (\$ownerId == \$user->id)";
$allow[] = "\t\t\t\t\t{";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.own']) && isset($this->permissionBuilder['global'][$core['core.edit.own']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit.own']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit.own']]))
{
$allow[] = "\t\t\t\t\t\tif (\$user->authorise('".$core['core.edit.own']."', 'com_".$component."'))";
}
else
{
$allow[] = "\t\t\t\t\t\tif (\$user->authorise('core.edit.own', 'com_".$component."'))";
}
$allow[] = "\t\t\t\t\t\t{";
$allow[] = "\t\t\t\t\t\t\treturn true;";
$allow[] = "\t\t\t\t\t\t}";
$allow[] = "\t\t\t\t\t}";
$allow[] = "\t\t\t\t}";
$allow[] = "\t\t\t\treturn false;";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit']]))
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." Since there is no permission, revert to the component permissions.";
$allow[] = "\t\treturn \$user->authorise('".$core['core.edit']."', \$this->option);";
}
else
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." Since there is no permission, revert to the component permissions.";
$allow[] = "\t\treturn parent::allowEdit(\$data, \$key);";
}
}
return implode("\n",$allow);
}
protected function setJmodelAdminGetForm($viewName_single,$viewName_list)
{
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// allways load these
$allow = array();
$allow[] = "\t\t//".$this->setLine(__LINE__)." Get the form.";
$allow[] = "\t\t\$form = \$this->loadForm('com_".$component.".".$viewName_single."', '".$viewName_single."', array('control' => 'jform', 'load_data' => \$loadData));";
$allow[] = "\n\t\tif (empty(\$form))";
$allow[] = "\t\t{";
$allow[] = "\t\t\treturn false;";
$allow[] = "\t\t}";
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
if(isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list])){
// check if category has another name
if ($coreLoad && isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
$otherView = $this->catOtherName[$viewName_list]['view'];
}
else
{
$otherViews = $viewName_list;
$otherView = $viewName_single;
}
// setup the category script
$allow[] = "\n\t\t\$jinput = JFactory::getApplication()->input;";
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." The front end calls this model and uses a_id to avoid id clashes so we need to check for that first.";
$allow[] = "\t\tif (\$jinput->get('a_id'))";
$allow[] = "\t\t{";
$allow[] = "\t\t\t\$id = \$jinput->get('a_id', 0, 'INT');";
$allow[] = "\t\t}";
$allow[] = "\t\t//".$this->setLine(__LINE__)." The back end uses id so we use that the rest of the time and set it to 0 by default.";
$allow[] = "\t\telse";
$allow[] = "\t\t{";
$allow[] = "\t\t\t\$id = \$jinput->get('id', 0, 'INT');";
$allow[] = "\t\t}";
$allow[] = "\t\t//".$this->setLine(__LINE__)." Determine correct permissions to check.";
$allow[] = "\t\tif (\$this->getState('".$viewName_single.".id'))";
$allow[] = "\t\t{";
$allow[] = "\t\t\t\$id = \$this->getState('".$viewName_single.".id');";
$allow[] = "\n\t\t\t\$catid = 0;";
$allow[] = "\t\t\tif (isset(\$this->getItem(\$id)->catid))";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\t//".$this->setLine(__LINE__)." set catagory id";
$allow[] = "\t\t\t\t\$catid = \$this->getItem(\$id)->catid;";
$allow[] = "\n\t\t\t\t//".$this->setLine(__LINE__)." Existing record. Can only edit in selected categories.";
$allow[] = "\t\t\t\t\$form->setFieldAttribute('catid', 'action', 'core.edit');";
$allow[] = "\n\t\t\t\t//".$this->setLine(__LINE__)." Existing record. Can only edit own items in selected categories.";
$allow[] = "\t\t\t\t\$form->setFieldAttribute('catid', 'action', 'core.edit.own');";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
$allow[] = "\t\telse";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." New record. Can only create in selected categories.";
$allow[] = "\t\t\t\$form->setFieldAttribute('catid', 'action', 'core.create');";
$allow[] = "\t\t}";
$allow[] = "\n\t\t\$user = JFactory::getUser();";
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Check for existing item.";
$allow[] = "\t\t//".$this->setLine(__LINE__)." Modify the form based on Edit State access controls.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder[$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.state']]))
{
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('".$core['core.edit.state']."', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (isset(\$catid) && \$catid != 0 && !\$user->authorise('core.edit.state', 'com_".$component.".".$viewName_list.".category.' . (int) \$catid))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('".$core['core.edit.state']."', 'com_".$component."')))";
}
else
{
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('core.edit.state', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (isset(\$catid) && \$catid != 0 && !\$user->authorise('core.edit.state', 'com_".$component.".".$viewName_list.".category.' . (int) \$catid))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('core.edit.state', 'com_".$component."')))";
}
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('ordering', 'disabled', 'true');";
$allow[] = "\t\t\t\$form->setFieldAttribute('published', 'disabled', 'true');";
$allow[] = "\n\t\t\t//".$this->setLine(__LINE__)." Disable fields while saving.";
$allow[] = "\t\t\t\$form->setFieldAttribute('ordering', 'filter', 'unset');";
$allow[] = "\t\t\t\$form->setFieldAttribute('published', 'filter', 'unset');";
$allow[] = "\t\t}";
}
else
{
$allow[] = "\n\t\t\$jinput = JFactory::getApplication()->input;";
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." The front end calls this model and uses a_id to avoid id clashes so we need to check for that first.";
$allow[] = "\t\tif (\$jinput->get('a_id'))";
$allow[] = "\t\t{";
$allow[] = "\t\t\t\$id = \$jinput->get('a_id', 0, 'INT');";
$allow[] = "\t\t}";
$allow[] = "\t\t//".$this->setLine(__LINE__)." The back end uses id so we use that the rest of the time and set it to 0 by default.";
$allow[] = "\t\telse";
$allow[] = "\t\t{";
$allow[] = "\t\t\t\$id = \$jinput->get('id', 0, 'INT');";
$allow[] = "\t\t}";
$allow[] = "\n\t\t\$user = JFactory::getUser();";
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Check for existing item.";
$allow[] = "\t\t//".$this->setLine(__LINE__)." Modify the form based on Edit State access controls.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder[$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.state']]))
{
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('".$core['core.edit.state']."', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('".$core['core.edit.state']."', 'com_".$component."')))";
}
else
{
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('core.edit.state', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('core.edit.state', 'com_".$component."')))";
}
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('ordering', 'disabled', 'true');";
$allow[] = "\t\t\t\$form->setFieldAttribute('published', 'disabled', 'true');";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields while saving.";
$allow[] = "\t\t\t\$form->setFieldAttribute('ordering', 'filter', 'unset');";
$allow[] = "\t\t\t\$form->setFieldAttribute('published', 'filter', 'unset');";
$allow[] = "\t\t}";
}
$allow[] = "\t\t//".$this->setLine(__LINE__)." Modify the form based on Edit Creaded By access controls.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.created_by']) && isset($this->permissionBuilder[$core['core.edit.created_by']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.created_by']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.created_by']]))
{
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('".$core['core.edit.created_by']."', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('".$core['core.edit.created_by']."', 'com_".$component."')))";
}
else
{
$allow[] = "\t\tif (!\$user->authorise('core.edit.created_by', 'com_".$component."'))";
}
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('created_by', 'disabled', 'true');";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('created_by', 'readonly', 'true');";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields while saving.";
$allow[] = "\t\t\t\$form->setFieldAttribute('created_by', 'filter', 'unset');";
$allow[] = "\t\t}";
$allow[] = "\t\t//".$this->setLine(__LINE__)." Modify the form based on Edit Creaded Date access controls.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.created']) && isset($this->permissionBuilder[$core['core.edit.created']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.created']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.created']]))
{
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('".$core['core.edit.created']."', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('".$core['core.edit.created']."', 'com_".$component."')))";
}
else
{
$allow[] = "\t\tif (!\$user->authorise('core.edit.created', 'com_".$component."'))";
}
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('created', 'disabled', 'true');";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields while saving.";
$allow[] = "\t\t\t\$form->setFieldAttribute('created', 'filter', 'unset');";
$allow[] = "\t\t}";
// handel the fields permissions
if (isset($this->permissionFields[$viewName_single]) && ComponentbuilderHelper::checkArray($this->permissionFields[$viewName_single]))
{
foreach ($this->permissionFields[$viewName_single] as $fieldName => $fieldType)
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." Modify the form based on Edit ".ComponentbuilderHelper::safeString($fieldName, 'W')." access controls.";
$allow[] = "\t\tif (\$id != 0 && (!\$user->authorise('".$viewName_single.".edit.".$fieldName."', 'com_".$component.".".$viewName_single.".' . (int) \$id))";
$allow[] = "\t\t\t|| (\$id == 0 && !\$user->authorise('".$viewName_single.".edit.".$fieldName."', 'com_".$component."')))";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('".$fieldName."', 'disabled', 'true');";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable fields for display.";
$allow[] = "\t\t\t\$form->setFieldAttribute('".$fieldName."', 'readonly', 'true');";
if ('radio' == $fieldType || 'repeatable' == $fieldType)
{
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." Disable radio button for display.";
$allow[] = "\t\t\t\$class = \$form->getFieldAttribute('".$fieldName."', 'class', '');";
$allow[] = "\t\t\t\$form->setFieldAttribute('".$fieldName."', 'class', \$class.' disabled no-click');";
}
$allow[] = "\t\t\tif (!\$form->getValue('".$fieldName."'))";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\t//".$this->setLine(__LINE__)." Disable fields while saving.";
$allow[] = "\t\t\t\t\$form->setFieldAttribute('".$fieldName."', 'filter', 'unset');";
$allow[] = "\t\t\t\t//".$this->setLine(__LINE__)." Disable fields while saving.";
$allow[] = "\t\t\t\t\$form->setFieldAttribute('".$fieldName."', 'required', 'false');";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
}
}
// setup the default script
$allow[] = "\n\t\treturn \$form;";
return implode("\n",$allow);
}
protected function setJmodelAdminAllowEdit($viewName_single,$viewName_list)
{
$allow = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// prepare custom permission script
if (isset($this->customScriptBuilder['php_allowedit'][$viewName_single]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_allowedit'][$viewName_single]))
{
$customAllow = "\t\t\$recordId\t= (int) isset(\$data[\$key]) ? \$data[\$key] : 0;\n".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_allowedit'][$viewName_single]);
}
else
{
$customAllow = '';
}
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder[$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit']]))
{
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Check specific edit permission then general edit permission.";
$allow[] = "\t\t\$user = JFactory::getUser();";
// load custom permission script
$allow[] = $customAllow;
$allow[] = "\t\treturn \$user->authorise('".$core['core.edit']."', 'com_".$component.".".$viewName_single.".'. ((int) isset(\$data[\$key]) ? \$data[\$key] : 0)) or \$user->authorise('".$core['core.edit']."', 'com_".$component."');";
}
else
{
$allow[] = "\n\t\t//".$this->setLine(__LINE__)." Check specific edit permission then general edit permission.";
if (ComponentbuilderHelper::checkString($customAllow))
{
$allow[] = "\t\t\$user = JFactory::getUser();";
}
// load custom permission script
$allow[] = $customAllow;
$allow[] = "\t\treturn JFactory::getUser()->authorise('core.edit', 'com_".$component.".".$viewName_single.".'. ((int) isset(\$data[\$key]) ? \$data[\$key] : 0)) or parent::allowEdit(\$data, \$key);";
}
return implode("\n",$allow);
}
protected function setJmodelAdminCanDelete($viewName_single,$viewName_list)
{
$allow = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
if(isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list])){
// check if category has another name
if ($coreLoad && isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
$otherView = $this->catOtherName[$viewName_list]['view'];
}
else
{
$otherViews = $viewName_list;
$otherView = $viewName_single;
}
// setup the category script
$allow[] = "\n\t\tif (!empty(\$record->id))";
$allow[] = "\t\t{";
$allow[] = "\t\t\tif (\$record->published != -2)";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\treturn;";
$allow[] = "\t\t\t}";
$allow[] = "\n\t\t\t\$user = JFactory::getUser();";
$allow[] = "\t\t\t\$allow = \$user->authorise('core.delete', 'com_".$component.".".$otherViews.".category.' . (int) \$record->catid);";
// check if the item has permissions.
if ($coreLoad && isset($this->permissionBuilder[$core['core.delete']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.delete']]) && in_array($otherView,$this->permissionBuilder[$core['core.delete']]))
{
$allow[] = "\n\t\t\tif (\$allow)";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
$allow[] = "\t\t\t\treturn \$user->authorise('".$core['core.delete']."', 'com_".$component.".".$otherView.".' . (int) \$record->id);";
$allow[] = "\t\t\t}";
}
else
{
$allow[] = "\n\t\t\tif (\$allow)";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
$allow[] = "\t\t\t\treturn \$user->authorise('core.delete', 'com_".$component.".".$otherView.".' . (int) \$record->id);";
$allow[] = "\t\t\t}";
}
$allow[] = "\t\t\treturn \$allow;";
$allow[] = "\t\t}";
$allow[] = "\t\treturn false;";
}
else
{
// setup the default script
$allow[] = "\n\t\tif (!empty(\$record->id))";
$allow[] = "\t\t{";
$allow[] = "\t\t\tif (\$record->published != -2)";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\treturn;";
$allow[] = "\t\t\t}";
// check if the item has permissions.
if ($coreLoad && isset($this->permissionBuilder[$core['core.delete']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.delete']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.delete']]))
{
$allow[] = "\n\t\t\t\$user = JFactory::getUser();";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
$allow[] = "\t\t\treturn \$user->authorise('".$core['core.delete']."', 'com_".$component.".".$viewName_single.".' . (int) \$record->id);";
}
else
{
$allow[] = "\n\t\t\t\$user = JFactory::getUser();";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
$allow[] = "\t\t\treturn \$user->authorise('core.delete', 'com_".$component.".".$viewName_single.".' . (int) \$record->id);";
}
$allow[] = "\t\t}";
$allow[] = "\t\treturn false;";
}
return implode("\n",$allow);
}
protected function setJmodelAdminCanEditState($viewName_single,$viewName_list)
{
$allow = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
if(isset($this->categoryBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->categoryBuilder[$viewName_list])){
// check if category has another name
if (isset($this->catOtherName[$viewName_list]) && ComponentbuilderHelper::checkArray($this->catOtherName[$viewName_list]))
{
$otherViews = $this->catOtherName[$viewName_list]['views'];
$otherView = $this->catOtherName[$viewName_list]['view'];
}
else
{
$otherViews = $viewName_list;
$otherView = $viewName_single;
}
$allow[] = "\n\t\t\$user = JFactory::getUser();";
$allow[] = "\t\t\$recordId\t= (!empty(\$record->id)) ? \$record->id : 0;";
$allow[] = "\n\t\tif (\$recordId)";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder[$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.state']]))
{
$allow[] = "\t\t\t\$permission = \$user->authorise('".$core['core.edit.state']."', 'com_".$component.".".$viewName_single.".' . (int) \$recordId);";
}
else
{
$allow[] = "\t\t\t\$permission = \$user->authorise('core.edit.state', 'com_".$component.".".$viewName_single.".' . (int) \$recordId);";
}
$allow[] = "\t\t\tif (!\$permission && !is_null(\$permission))";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\treturn false;";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
// setup the category script
$allow[] = "\t\t//".$this->setLine(__LINE__)." Check against the category.";
$allow[] = "\t\tif (!empty(\$record->catid))";
$allow[] = "\t\t{";
$allow[] = "\t\t\t\$catpermission = \$user->authorise('core.edit.state', 'com_".$component.".".$otherViews.".category.' . (int) \$record->catid);";
$allow[] = "\t\t\tif (!\$catpermission && !is_null(\$catpermission))";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\treturn false;";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder[$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.state']]))
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\treturn \$user->authorise('".$core['core.edit.state']."', 'com_".$component."');";
}
else
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\treturn parent::canEditState(\$record);";
}
}
else
{
// setup the default script
$allow[] = "\n\t\t\$user = JFactory::getUser();";
$allow[] = "\t\t\$recordId\t= (!empty(\$record->id)) ? \$record->id : 0;";
$allow[] = "\n\t\tif (\$recordId)";
$allow[] = "\t\t{";
$allow[] = "\t\t\t//".$this->setLine(__LINE__)." The record has been set. Check the record permissions.";
// check if the item has permissions.
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder[$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder[$core['core.edit.state']]))
{
$allow[] = "\t\t\t\$permission = \$user->authorise('".$core['core.edit.state']."', 'com_".$component.".".$viewName_single.".' . (int) \$recordId);";
}
else
{
$allow[] = "\t\t\t\$permission = \$user->authorise('core.edit.state', 'com_".$component.".".$viewName_single.".' . (int) \$recordId);";
}
$allow[] = "\t\t\tif (!\$permission && !is_null(\$permission))";
$allow[] = "\t\t\t{";
$allow[] = "\t\t\t\treturn false;";
$allow[] = "\t\t\t}";
$allow[] = "\t\t}";
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder['global'][$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit.state']]))
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\treturn \$user->authorise('".$core['core.edit.state']."', 'com_".$component."');";
}
else
{
$allow[] = "\t\t//".$this->setLine(__LINE__)." In the absense of better information, revert to the component permissions.";
$allow[] = "\t\treturn parent::canEditState(\$record);";
}
}
return implode("\n",$allow);
}
protected function setJviewListCanDo($viewName_single,$viewName_list)
{
$allow = array();
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName_single]))
{
$core = $this->permissionCore[$viewName_single];
$coreLoad = true;
}
// check if the item has permissions for edit.
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit']]))
{
$allow[] = "\n\t\t\$this->canEdit\t\t= \$this->canDo->get('".$core['core.edit']."');";
}
else
{
$allow[] = "\n\t\t\$this->canEdit\t\t= \$this->canDo->get('core.edit');";
}
// check if the item has permissions for edit state.
if ($coreLoad && isset($core['core.edit.state']) && isset($this->permissionBuilder['global'][$core['core.edit.state']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit.state']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.edit.state']]))
{
$allow[] = "\t\t\$this->canState\t\t= \$this->canDo->get('".$core['core.edit.state']."');";
}
else
{
$allow[] = "\t\t\$this->canState\t\t= \$this->canDo->get('core.edit.state');";
}
// check if the item has permissions for create.
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.create']]))
{
$allow[] = "\t\t\$this->canCreate\t= \$this->canDo->get('".$core['core.create']."');";
}
else
{
$allow[] = "\t\t\$this->canCreate\t= \$this->canDo->get('core.create');";
}
// check if the item has permissions for delete.
if ($coreLoad && isset($core['core.delete']) && isset($this->permissionBuilder['global'][$core['core.delete']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.delete']]) && in_array($viewName_single,$this->permissionBuilder['global'][$core['core.delete']]))
{
$allow[] = "\t\t\$this->canDelete\t= \$this->canDo->get('".$core['core.delete']."');";
}
else
{
$allow[] = "\t\t\$this->canDelete\t= \$this->canDo->get('core.delete');";
}
// check if the item has permissions for batch.
if ($coreLoad && isset($core['core.batch']) && isset($this->permissionBuilder['global']['global'][$core['core.batch']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global']['global'][$core['core.batch']]) && in_array($viewName_single,$this->permissionBuilder['global']['global'][$core['core.delete']]))
{
$allow[] = "\t\t\$this->canBatch\t= (\$this->canDo->get('".$core['core.batch']."') && \$this->canDo->get('core.batch'));";
}
else
{
$allow[] = "\t\t\$this->canBatch\t= \$this->canDo->get('core.batch');";
}
return implode("\n",$allow);
}
protected function setFieldSetAccessControl($view)
{
$access = '';
if ($view != 'component')
{
// set component name
$component = ComponentbuilderHelper::safeString($this->componentData->name_code);
// set label
$label = 'Permissions in relation to this '.$view;
// set the access fieldset
$access = "";
$access .= "\n\t".'
';
}
// return access field set
return $access;
}
protected function setFilterFields($view)
{
// keep track of all fields already added
$donelist = array('id','search','published','access','created_by','modified_by');
// default filter fields
$fields = "'a.id','id'";
$fields .= ",\n\t\t\t\t'a.published','published'";
if (isset($this->accessBuilder[$view]) && ComponentbuilderHelper::checkString($this->accessBuilder[$view]))
{
$fields .= ",\n\t\t\t\t'a.access','access'";
}
$fields .= ",\n\t\t\t\t'a.ordering','ordering'";
$fields .= ",\n\t\t\t\t'a.created_by','created_by'";
$fields .= ",\n\t\t\t\t'a.modified_by','modified_by'";
// add the rest of the set filters
if (isset($this->sortBuilder[$view]) && ComponentbuilderHelper::checkArray($this->sortBuilder[$view]))
{
foreach ($this->sortBuilder[$view] as $filter)
{
if (!in_array($filter['code'],$donelist))
{
if ($filter['type'] == 'category')
{
$fields .= ",\n\t\t\t\t'c.title','category_title'";
$fields .= ",\n\t\t\t\t'c.id', 'category_id'";
if ($filter['code'] != 'category')
{
$fields .= ",\n\t\t\t\t'a.".$filter['code']."', '".$filter['code']."'";
}
}
else
{
// check if custom field is set
/*if (ComponentbuilderHelper::checkArray($filter['custom']))
{
$fields .= ",\n\t\t\t\t'".$filter['custom']['db'].".".$filter['custom']['text']."','".$filter['code']."_".$filter['custom']['text']."'";
}*/
$fields .= ",\n\t\t\t\t'a.".$filter['code']."','".$filter['code']."'";
}
$donelist[] = $filter['code'];
}
}
}
// add the rest of the set filters
if (isset($this->filterBuilder[$view]) && ComponentbuilderHelper::checkArray($this->filterBuilder[$view]))
{
foreach ($this->filterBuilder[$view] as $filter)
{
if (!in_array($filter['code'],$donelist))
{
if ($filter['type'] == 'category')
{
$fields .= ",\n\t\t\t\t'c.title','category_title'";
$fields .= ",\n\t\t\t\t'c.id', 'category_id'";
if ($filter['code'] != 'category')
{
$fields .= ",\n\t\t\t\t'a.".$filter['code']."', '".$filter['code']."'";
}
}
else
{
// check if custom field is set
/*if (ComponentbuilderHelper::checkArray($filter['custom']))
{
$fields .= ",\n\t\t\t\t'".$filter['custom']['db'].".".$filter['custom']['text']."','".$filter['code']."_".$filter['custom']['text']."'";
}*/
$fields .= ",\n\t\t\t\t'a.".$filter['code']."','".$filter['code']."'";
}
$donelist[] = $filter['code'];
}
}
}
return $fields;
}
protected function setStoredId($view)
{
// keep track of all fields already added
$donelist = array('id','search','published','access','created_by','modified_by');
// set the defaults first
$stored = "//".$this->setLine(__LINE__)." Compile the store id.";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.id');";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.search');";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.published');";
if (isset($this->accessBuilder[$view]) && ComponentbuilderHelper::checkString($this->accessBuilder[$view]))
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.access');";
}
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.ordering');";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.created_by');";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.modified_by');";
// add the rest of the set filters
if (isset($this->sortBuilder[$view]) && ComponentbuilderHelper::checkArray($this->sortBuilder[$view]))
{
foreach ($this->sortBuilder[$view] as $filter)
{
if (!in_array($filter['code'],$donelist))
{
if ($filter['type'] == 'category')
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.category');";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.category_id');";
if ($filter['code'] != 'category')
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.".$filter['code']."');";
}
}
else
{
// check if custom field is set
/*if (ComponentbuilderHelper::checkArray($filter['custom']))
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.".$filter['code']."_".$filter['custom']['text']."');";
}*/
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.".$filter['code']."');";
}
$donelist[] = $filter['code'];
}
}
}
// add the rest of the set filters
if (isset($this->filterBuilder[$view]) && ComponentbuilderHelper::checkArray($this->filterBuilder[$view]))
{
foreach ($this->filterBuilder[$view] as $filter)
{
if (!in_array($filter['code'],$donelist))
{
if ($filter['type'] == 'category')
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.category');";
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.category_id');";
if ($filter['code'] != 'category')
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.".$filter['code']."');";
}
}
else
{
// check if custom field is set
/*if (ComponentbuilderHelper::checkArray($filter['custom']))
{
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.".$filter['code']."_".$filter['custom']['text']."');";
}*/
$stored .= "\n\t\t\$id .= ':' . \$this->getState('filter.".$filter['code']."');";
}
$donelist[] = $filter['code'];
}
}
}
return $stored;
}
protected function setAddToolBar($view)
{
// set view name
$viewName = ComponentbuilderHelper::safeString($view['settings']->name_single);
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$viewName]))
{
$core = $this->permissionCore[$viewName];
$coreLoad = true;
}
// check type
if ($view['settings']->type == 2)
{
// set lang strings
$viewNameLang_readonly = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($view['settings']->name_single.' readonly','U');
// load to lang
$this->langContent[$this->lang][$viewNameLang_readonly] = $view['settings']->name_single.' :: Readonly';
// build toolbar
$toolBar = "JFactory::getApplication()->input->set('hidemainmenu', true);";
$toolBar .= "\n\t\tJToolBarHelper::title(JText::_('".$viewNameLang_readonly."'), '".$viewName."');";
$toolBar .= "\n\t\tJToolBarHelper::cancel('".$viewName.".cancel', 'JTOOLBAR_CLOSE');";
}
else
{
// set lang strings
$viewNameLang_new = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($view['settings']->name_single.' New','U');
$viewNameLang_edit = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($view['settings']->name_single.' Edit','U');
// load to lang
$this->langContent[$this->lang][$viewNameLang_new] = 'A New '.$view['settings']->name_single;
$this->langContent[$this->lang][$viewNameLang_edit] = 'Editing the '.$view['settings']->name_single;
// build toolbar
$toolBar = "JFactory::getApplication()->input->set('hidemainmenu', true);";
$toolBar .= "\n\t\t\$user = JFactory::getUser();";
$toolBar .= "\n\t\t\$userId = \$user->id;";
$toolBar .= "\n\t\t\$isNew = \$this->item->id == 0;";
$toolBar .= "\n\n\t\tJToolbarHelper::title( JText::_(\$isNew ? '".$viewNameLang_new."' : '".$viewNameLang_edit."'), 'pencil-2 article-add');";
$toolBar .= "\n\t\t//".$this->setLine(__LINE__)." Built the actions for new and existing records.";
$toolBar .= "\n\t\tif (\$this->refid || \$this->ref)";
$toolBar .= "\n\t\t{";
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName,$this->permissionBuilder['global'][$core['core.create']]))
{
$toolBar .= "\n\t\t\tif (\$this->canDo->get('".$core['core.create']."') && \$isNew)";
}
else
{
$toolBar .= "\n\t\t\tif (\$this->canDo->get('core.create') && \$isNew)";
}
$toolBar .= "\n\t\t\t{";
$toolBar .= "\n\t\t\t\t//".$this->setLine(__LINE__)." We can create the record.";
$toolBar .= "\n\t\t\t\tJToolBarHelper::save('".$viewName.".save', 'JTOOLBAR_SAVE');";
$toolBar .= "\n\t\t\t}";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName,$this->permissionBuilder['global'][$core['core.edit']]))
{
$toolBar .= "\n\t\t\telseif (\$this->canDo->get('".$core['core.edit']."'))";
}
else
{
$toolBar .= "\n\t\t\telseif (\$this->canDo->get('core.edit'))";
}
$toolBar .= "\n\t\t\t{";
$toolBar .= "\n\t\t\t\t//".$this->setLine(__LINE__)." We can save the record.";
$toolBar .= "\n\t\t\t\tJToolBarHelper::save('".$viewName.".save', 'JTOOLBAR_SAVE');";
$toolBar .= "\n\t\t\t}";
$toolBar .= "\n\t\t\tif (\$isNew)";
$toolBar .= "\n\t\t\t{";
$toolBar .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Do not creat but cancel.";
$toolBar .= "\n\t\t\t\tJToolBarHelper::cancel('".$viewName.".cancel', 'JTOOLBAR_CANCEL');";
$toolBar .= "\n\t\t\t}";
$toolBar .= "\n\t\t\telse";
$toolBar .= "\n\t\t\t{";
$toolBar .= "\n\t\t\t\t//".$this->setLine(__LINE__)." We can close it.";
$toolBar .= "\n\t\t\t\tJToolBarHelper::cancel('".$viewName.".cancel', 'JTOOLBAR_CLOSE');";
$toolBar .= "\n\t\t\t}";
$toolBar .= "\n\t\t}";
$toolBar .= "\n\t\telse";
$toolBar .= "\n\t\t{";
$toolBar .= "\n\t\t\tif (\$isNew)";
$toolBar .= "\n\t\t\t{";
$toolBar .= "\n\t\t\t\t//".$this->setLine(__LINE__)." For new records, check the create permission.";
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName,$this->permissionBuilder['global'][$core['core.create']]))
{
$toolBar .= "\n\t\t\t\tif (\$this->canDo->get('".$core['core.create']."'))";
}
else
{
$toolBar .= "\n\t\t\t\tif (\$this->canDo->get('core.create'))";
}
$toolBar .= "\n\t\t\t\t{";
$toolBar .= "\n\t\t\t\t\tJToolBarHelper::apply('".$viewName.".apply', 'JTOOLBAR_APPLY');";
$toolBar .= "\n\t\t\t\t\tJToolBarHelper::save('".$viewName.".save', 'JTOOLBAR_SAVE');";
$toolBar .= "\n\t\t\t\t\tJToolBarHelper::custom('".$viewName.".save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);";
$toolBar .= "\n\t\t\t\t};";
$toolBar .= "\n\t\t\t\tJToolBarHelper::cancel('".$viewName.".cancel', 'JTOOLBAR_CANCEL');";
$toolBar .= "\n\t\t\t}";
$toolBar .= "\n\t\t\telse";
$toolBar .= "\n\t\t\t{";
if ($coreLoad && isset($core['core.edit']) && isset($this->permissionBuilder['global'][$core['core.edit']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.edit']]) && in_array($viewName,$this->permissionBuilder['global'][$core['core.edit']]))
{
$toolBar .= "\n\t\t\t\tif (\$this->canDo->get('".$core['core.edit']."'))";
}
else
{
$toolBar .= "\n\t\t\t\tif (\$this->canDo->get('core.edit'))";
}
$toolBar .= "\n\t\t\t\t{";
$toolBar .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." We can save the new record";
$toolBar .= "\n\t\t\t\t\tJToolBarHelper::apply('".$viewName.".apply', 'JTOOLBAR_APPLY');";
$toolBar .= "\n\t\t\t\t\tJToolBarHelper::save('".$viewName.".save', 'JTOOLBAR_SAVE');";
$toolBar .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." We can save this record, but check the create permission to see";
$toolBar .= "\n\t\t\t\t\t//".$this->setLine(__LINE__)." if we can return to make a new one.";
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName,$this->permissionBuilder['global'][$core['core.create']]))
{
$toolBar .= "\n\t\t\t\t\tif (\$this->canDo->get('".$core['core.create']."'))";
}
else
{
$toolBar .= "\n\t\t\t\t\tif (\$this->canDo->get('core.create'))";
}
$toolBar .= "\n\t\t\t\t\t{";
$toolBar .= "\n\t\t\t\t\t\tJToolBarHelper::custom('".$viewName.".save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);";
$toolBar .= "\n\t\t\t\t\t}";
$toolBar .= "\n\t\t\t\t}";
if ($coreLoad && isset($this->historyBuilder[$viewName]) && ComponentbuilderHelper::checkString($this->historyBuilder[$viewName]))
{
$toolBar .= "\n\t\t\t\t\$canVersion = (\$this->canDo->get('core.version') && \$this->canDo->get('".$core['core.version']."'));";
$toolBar .= "\n\t\t\t\tif (\$this->state->params->get('save_history', 1) && \$this->canDo->get('".$core['core.edit']."') && \$canVersion)";
$toolBar .= "\n\t\t\t\t{";
$toolBar .= "\n\t\t\t\t\tJToolbarHelper::versions('com_".$this->fileContentStatic['###component###'].".".$viewName."', \$this->item->id);";
$toolBar .= "\n\t\t\t\t}";
}
if ($coreLoad && isset($core['core.create']) && isset($this->permissionBuilder['global'][$core['core.create']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder['global'][$core['core.create']]) && in_array($viewName,$this->permissionBuilder['global'][$core['core.create']]))
{
$toolBar .= "\n\t\t\t\tif (\$this->canDo->get('".$core['core.create']."'))";
}
else
{
$toolBar .= "\n\t\t\t\tif (\$this->canDo->get('core.create'))";
}
$toolBar .= "\n\t\t\t\t{";
$toolBar .= "\n\t\t\t\t\tJToolBarHelper::custom('".$viewName.".save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);";
$toolBar .= "\n\t\t\t\t}";
$toolBar .= "\n\t\t\t\tJToolBarHelper::cancel('".$viewName.".cancel', 'JTOOLBAR_CLOSE');";
$toolBar .= "\n\t\t\t}";
$toolBar .= "\n\t\t}";
$toolBar .= "\n\t\tJToolbarHelper::divider();";
$toolBar .= "\n\t\t//".$this->setLine(__LINE__)." set help url for this view if found";
$toolBar .= "\n\t\t\$help_url = ".$this->fileContentStatic['###Component###']."Helper::getHelpUrl('".$viewName."');";
$toolBar .= "\n\t\tif (".$this->fileContentStatic['###Component###']."Helper::checkString(\$help_url))";
$toolBar .= "\n\t\t{";
$toolBar .= "\n\t\t\tJToolbarHelper::help('".$this->langPrefix."_HELP_MANAGER', false, \$help_url);";
$toolBar .= "\n\t\t}";
}
return $toolBar;
}
protected function setPopulateState($view)
{
// rest buket
$state = '';
// keep track of all fields already added
$donelist = array();
// add the rest of the set filters
if (isset($this->sortBuilder[$view]) && ComponentbuilderHelper::checkArray($this->sortBuilder[$view]))
{
foreach ($this->sortBuilder[$view] as $filter)
{
if (!in_array($filter['code'],$donelist))
{
if ($filter['type'] == 'category')
{
if (strlen($state) == 0)
{
$spacer = "";
}
else
{
$spacer = "\n\n\t\t";
}
$state .= $spacer."\$category = \$app->getUserStateFromRequest(\$this->context . '.filter.category', 'filter_category');";
$state .= "\n\t\t\$this->setState('filter.category', \$category);";
$state .= "\n\n\t\t\$categoryId = \$this->getUserStateFromRequest(\$this->context . '.filter.category_id', 'filter_category_id');";
$state .= "\n\t\t\$this->setState('filter.category_id', \$categoryId);";
if ($filter['code'] != 'category')
{
$state .= "\n\n\t\t\$".$filter['code']." = \$app->getUserStateFromRequest(\$this->context . '.filter.".$filter['code']."', 'filter_".$filter['code']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['code']."', \$".$filter['code'].");";
}
}
else
{
if (strlen($state) == 0)
{
$spacer = "";
}
else
{
$spacer = "\n\n\t\t";
}
// check if custom field is set
/*if (ComponentbuilderHelper::checkArray($filter['custom']))
{
$state .= $spacer."\$".$filter['code']."_".$filter['custom']['text']." = \$this->getUserStateFromRequest(\$this->context . '.filter.".$filter['code']."_".$filter['custom']['text']."', 'filter_".$filter['code']."_".$filter['custom']['text']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['code']."_".$filter['custom']['text']."', \$".$filter['code']."_".$filter['custom']['text'].");";
$spacer = "\n\n\t\t";
}*/
$state .= $spacer."\$".$filter['code']." = \$this->getUserStateFromRequest(\$this->context . '.filter.".$filter['code']."', 'filter_".$filter['code']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['code']."', \$".$filter['code'].");";
}
$donelist[] = $filter['code'];
}
}
}
// add the rest of the set filters
if (isset($this->filterBuilder[$view]) && ComponentbuilderHelper::checkArray($this->filterBuilder[$view]))
{
foreach ($this->filterBuilder[$view] as $filter)
{
if (!in_array($filter['code'],$donelist))
{
if ($filter['type'] == 'category')
{
if (strlen($state) == 0)
{
$spacer = "";
}
else
{
$spacer = "\n\n\t\t";
}
$state .= $spacer."\$category = \$app->getUserStateFromRequest(\$this->context . '.filter.category', 'filter_category');";
$state .= "\n\t\t\$this->setState('filter.category', \$category);";
$state .= "\n\n\t\t\$categoryId = \$this->getUserStateFromRequest(\$this->context . '.filter.category_id', 'filter_category_id');";
$state .= "\n\t\t\$this->setState('filter.category_id', \$categoryId);";
if ($filter['code'] != 'category')
{
$state .= "\n\n\t\t\$".$filter['code']." = \$app->getUserStateFromRequest(\$this->context . '.filter.".$filter['code']."', 'filter_".$filter['code']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['code']."', \$".$filter['code'].");";
}
}
else
{
if (strlen($state) == 0)
{
$spacer = "";
}
else
{
$spacer = "\n\n\t\t";
}
// check if custom field is set
/*if (ComponentbuilderHelper::checkArray($filter['custom']))
{
$state .= $spacer."\$".$filter['custom']['text']." = \$this->getUserStateFromRequest(\$this->context . '.filter.".$filter['custom']['text']."', 'filter_".$filter['custom']['text']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['custom']['text']."', \$".$filter['custom']['text'].");";
$state .= "\n\t\t\$".$filter['code']."_".$filter['custom']['text']." = \$this->getUserStateFromRequest(\$this->context . '.filter.".$filter['code']."_".$filter['custom']['text']."', 'filter_".$filter['code']."_".$filter['custom']['text']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['code']."_".$filter['custom']['text']."', \$".$filter['code']."_".$filter['custom']['text'].");";
$spacer = "\n\n\t\t";
}*/
$state .= $spacer."\$".$filter['code']." = \$this->getUserStateFromRequest(\$this->context . '.filter.".$filter['code']."', 'filter_".$filter['code']."');";
$state .= "\n\t\t\$this->setState('filter.".$filter['code']."', \$".$filter['code'].");";
}
$donelist[] = $filter['code'];
}
}
}
return $state;
}
protected function setSortFields($view)
{
// set the default first
$fields = "return array(";
$fields .= "\n\t\t\t'a.sorting' => JText::_('JGRID_HEADING_ORDERING')";
$fields .= ",\n\t\t\t'a.published' => JText::_('JSTATUS')";
// add the rest of the set filters
if (isset($this->sortBuilder[$view]) && ComponentbuilderHelper::checkArray($this->sortBuilder[$view]))
{
foreach ($this->sortBuilder[$view] as $filter)
{
if ($filter['type'] == 'category')
{
$fields .= ",\n\t\t\t'c.category_title' => JText::_('".$filter['lang']."')";
}
elseif (ComponentbuilderHelper::checkArray($filter['custom']))
{
$fields .= ",\n\t\t\t'".$filter['custom']['db'].".".$filter['custom']['text']."' => JText::_('".$filter['lang']."')";
}
else
{
$fields .= ",\n\t\t\t'a.".$filter['code']."' => JText::_('".$filter['lang']."')";
}
}
}
$fields .= ",\n\t\t\t'a.id' => JText::_('JGRID_HEADING_ID')";
$fields .= "\n\t\t);";
// return fields
return $fields;
}
protected function setCheckinCall()
{
$call = "\n\t\t//".$this->setLine(__LINE__)." check in items";
$call .= "\n\t\t\$this->checkInNow();\n";
return $call;
}
protected function setAutoCheckin($view,$component)
{
$checkin = "\n\n\t/**";
$checkin .= "\n\t* Build an SQL query to checkin all items left checked out longer then a set time.";
$checkin .= "\n\t*";
$checkin .= "\n\t* @return a bool";
$checkin .= "\n\t*";
$checkin .= "\n\t*/";
$checkin .= "\n\tprotected function checkInNow()";
$checkin .= "\n\t{";
$checkin .= "\n\t\t//".$this->setLine(__LINE__)." Get set check in time";
$checkin .= "\n\t\t\$time = JComponentHelper::getParams('com_".$component."')->get('check_in');";
$checkin .= "\n\t\t";
$checkin .= "\n\t\tif (\$time)";
$checkin .= "\n\t\t{";
$checkin .= "\n\n\t\t\t//".$this->setLine(__LINE__)." Get a db connection.";
$checkin .= "\n\t\t\t\$db = JFactory::getDbo();";
$checkin .= "\n\t\t\t//".$this->setLine(__LINE__)." reset query";
$checkin .= "\n\t\t\t\$query = \$db->getQuery(true);";
$checkin .= "\n\t\t\t\$query->select('*');";
$checkin .= "\n\t\t\t\$query->from(\$db->quoteName('#__".$component."_".$view."'));";
$checkin .= "\n\t\t\t\$db->setQuery(\$query);";
$checkin .= "\n\t\t\t\$db->execute();";
$checkin .= "\n\t\t\tif (\$db->getNumRows())";
$checkin .= "\n\t\t\t{";
$checkin .= "\n\t\t\t\t//".$this->setLine(__LINE__)." Get Yesterdays date";
$checkin .= "\n\t\t\t\t\$date = JFactory::getDate()->modify(\$time)->toSql();";
$checkin .= "\n\t\t\t\t//".$this->setLine(__LINE__)." reset query";
$checkin .= "\n\t\t\t\t\$query = \$db->getQuery(true);";
$checkin .= "\n\n\t\t\t\t//".$this->setLine(__LINE__)." Fields to update.";
$checkin .= "\n\t\t\t\t\$fields = array(";
$checkin .= "\n\t\t\t\t\t\$db->quoteName('checked_out_time') . '=\'0000-00-00 00:00:00\'',";
$checkin .= "\n\t\t\t\t\t\$db->quoteName('checked_out') . '=0'";
$checkin .= "\n\t\t\t\t);";
$checkin .= "\n\n\t\t\t\t//".$this->setLine(__LINE__)." Conditions for which records should be updated.";
$checkin .= "\n\t\t\t\t\$conditions = array(";
$checkin .= "\n\t\t\t\t\t\$db->quoteName('checked_out') . '!=0', ";
$checkin .= "\n\t\t\t\t\t\$db->quoteName('checked_out_time') . '<\''.\$date.'\''";
$checkin .= "\n\t\t\t\t);";
$checkin .= "\n\n\t\t\t\t//".$this->setLine(__LINE__)." Check table";
$checkin .= "\n\t\t\t\t\$query->update(\$db->quoteName('#__".$component."_".$view."'))->set(\$fields)->where(\$conditions); ";
$checkin .= "\n\n\t\t\t\t\$db->setQuery(\$query);";
$checkin .= "\n\n\t\t\t\t\$db->execute();";
$checkin .= "\n\t\t\t}";
$checkin .= "\n\t\t}";
$checkin .= "\n\n\t\treturn false;";
$checkin .= "\n\t}";
return $checkin;
}
protected function setGetItemsMethodStringFix($view,$Component,$tab = '',$export = false)
{
// add the fix if this view has the need for it
$fix = '';
// encription switches
$basicCrypt = false;
$advancedCrypt = false;
// setup correct core target
$coreLoad = false;
if (isset($this->permissionCore[$view]))
{
$core = $this->permissionCore[$view];
$coreLoad = true;
}
$component = ComponentbuilderHelper::safeString($Component);
// check if the item has permissions.
if ($coreLoad && isset($core['core.access']) && isset($this->permissionBuilder[$core['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.access']]) && in_array($view,$this->permissionBuilder[$core['core.access']]))
{
$fix .= "\n\n\t".$tab."\t//".$this->setLine(__LINE__)." set values to display correctly.";
$fix .= "\n\t".$tab."\tif (".$Component."Helper::checkArray(\$items))";
$fix .= "\n\t".$tab."\t{";
$fix .= "\n\t".$tab."\t\t//".$this->setLine(__LINE__)." get user object.";
$fix .= "\n\t".$tab."\t\t\$user = JFactory::getUser();";
$fix .= "\n\t".$tab."\t\tforeach (\$items as \$nr => &\$item)";
$fix .= "\n\t".$tab."\t\t{";
$fix .= "\n\t".$tab."\t\t\t\$access = (\$user->authorise('".$core['core.access']."', 'com_".$component.".".$view.".' . (int) \$item->id) && \$user->authorise('".$core['core.access']."', 'com_".$component."'));";
$fix .= "\n\t".$tab."\t\t\tif (!\$access)";
$fix .= "\n\t".$tab."\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\tunset(\$items[\$nr]);";
$fix .= "\n\t".$tab."\t\t\t\tcontinue;";
$fix .= "\n\t".$tab."\t\t\t}\n";
}
if (!$export)
{
$methodName = 'getItemsMethodListStringFixBuilder';
}
else
{
$methodName = 'getItemsMethodEximportStringFixBuilder';
}
if (isset($this->{$methodName}[$view]) && ComponentbuilderHelper::checkArray($this->{$methodName}[$view]))
{
if (!ComponentbuilderHelper::checkString($fix))
{
$fix .= "\n\n\t".$tab."\t//".$this->setLine(__LINE__)." set values to display correctly.";
$fix .= "\n\t".$tab."\tif (".$Component."Helper::checkArray(\$items))";
$fix .= "\n\t".$tab."\t{";
$fix .= "\n\t".$tab."\t\tforeach (\$items as \$nr => &\$item)";
$fix .= "\n\t".$tab."\t\t{";
}
foreach ($this->{$methodName}[$view] as $item)
{
switch ($item['method'])
{
case 1:
// JSON_STRING_ENCODE
$decode = 'json_decode';
$suffix_decode = ', true';
break;
case 2:
// BASE_SIXTY_FOUR
$decode = 'base64_decode';
$suffix_decode = '';
break;
case 3:
// BASIC_ENCRYPTION_LOCALKEY
$decode = '$basic->decryptString';
$basicCrypt = true;
$suffix_decode = '';
break;
case 4:
// ADVANCE_ENCRYPTION_VDMKEY
$decode = '$advanced->decryptString';
$advancedCrypt = true;
$suffix_decode = '';
break;
default:
// JSON_ARRAY_ENCODE
$decode = 'json_decode';
$suffix_decode = ', true';
break;
}
if ($item['type'] == 'usergroup' && !$export)
{
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." decode ".$item['name'];
$fix .= "\n\t".$tab."\t\t\t\$".$item['name']."Array = ".$decode."(\$item->".$item['name'].$suffix_decode.");";
$fix .= "\n\t".$tab."\t\t\tif (".$Component."Helper::checkArray(\$".$item['name']."Array))";
$fix .= "\n\t".$tab."\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\$".$item['name']."Names = '';";
$fix .= "\n\t".$tab."\t\t\t\t\$counter = 0;";
$fix .= "\n\t".$tab."\t\t\t\tforeach (\$".$item['name']."Array as \$".$item['name'].")";
$fix .= "\n\t".$tab."\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\tif (\$counter == 0)";
$fix .= "\n\t".$tab."\t\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\t\t\$".$item['name']."Names .= ".$Component."Helper::getGroupName(\$".$item['name'].");";
$fix .= "\n\t".$tab."\t\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t\telse";
$fix .= "\n\t".$tab."\t\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\t\t\$".$item['name']."Names .= ', '.".$Component."Helper::getGroupName(\$".$item['name'].");";
$fix .= "\n\t".$tab."\t\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t\t\$counter++;";
$fix .= "\n\t".$tab."\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t\$item->".$item['name']." = \$".$item['name']."Names;";
$fix .= "\n\t".$tab."\t\t\t}";
}
/*elseif ($item['type'] == 'usergroup' && $export)
{
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." decode ".$item['name'];
$fix .= "\n\t".$tab."\t\t\t\$".$item['name']."Array = ".$decode."(\$item->".$item['name'].$suffix_decode.");";
$fix .= "\n\t".$tab."\t\t\tif (".$Component."Helper::checkArray(\$".$item['name']."Array))";
$fix .= "\n\t".$tab."\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\$item->".$item['name']." = implode('|',\$".$item['name']."Array);";
$fix .= "\n\t".$tab."\t\t\t}";
}*/
elseif ($item['translation'] && !$export)
{
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." convert ".$item['name'];
$fix .= "\n\t".$tab."\t\t\t\$".$item['name']."Array = ".$decode."(\$item->".$item['name'].$suffix_decode.");";
$fix .= "\n\t".$tab."\t\t\tif (".$Component."Helper::checkArray(\$".$item['name']."Array))";
$fix .= "\n\t".$tab."\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\$".$item['name']."Names = '';";
$fix .= "\n\t".$tab."\t\t\t\t\$counter = 0;";
$fix .= "\n\t".$tab."\t\t\t\tforeach (\$".$item['name']."Array as \$".$item['name'].")";
$fix .= "\n\t".$tab."\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\tif (\$counter == 0)";
$fix .= "\n\t".$tab."\t\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\t\t\$".$item['name']."Names .= JText::_(\$this->selectionTranslation(\$".$item['name'].", '".$item['name']."'));";
$fix .= "\n\t".$tab."\t\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t\telse";
$fix .= "\n\t".$tab."\t\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\t\t\$".$item['name']."Names .= ', '.JText::_(\$this->selectionTranslation(\$".$item['name'].", '".$item['name']."'));";
$fix .= "\n\t".$tab."\t\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t\t\$counter++;";
$fix .= "\n\t".$tab."\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t\$item->".$item['name']." = \$".$item['name']."Names;";
$fix .= "\n\t".$tab."\t\t\t}";
}
else
{
if ($item['method'] == 2 || $item['method'] == 3 || $item['method'] == 4)
{
$taber = '';
if ($item['method'] == 3)
{
$taber = "\t";
$fix .= "\n\t".$tab."\t\t\tif (\$basickey && !is_numeric(\$item->".$item['name'].") && \$item->".$item['name']." === base64_encode(base64_decode(\$item->".$item['name'].", true)))";
$fix .= "\n\t".$tab."\t\t\t{";
}
if ($item['method'] == 4)
{
$taber = "\t";
$fix .= "\n\t".$tab."\t\t\tif (\$advancedkey && !is_numeric(\$item->".$item['name'].") && \$item->".$item['name']." === base64_encode(base64_decode(\$item->".$item['name'].", true)))";
$fix .= "\n\t".$tab."\t\t\t{";
}
if ($item['method'] == 3 || $item['method'] == 4)
{
$fix .= "\n\t".$tab."\t\t\t\t//".$this->setLine(__LINE__)." decrypt ".$item['name'];
}
else
{
$fix .= "\n\t".$tab.$taber."\t\t\t//".$this->setLine(__LINE__)." decode ".$item['name'];
}
$fix .= "\n\t".$tab.$taber."\t\t\t\$item->".$item['name']." = ".$decode."(\$item->".$item['name'].");";
if ($item['method'] == 3 || $item['method'] == 4)
{
$fix .= "\n\t".$tab."\t\t\t}";
}
}
else
{
if ($export && $item['type'] == 'repeatable')
{
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." decode repeatable ".$item['name'];
$fix .= "\n\t".$tab."\t\t\t\$".$item['name']."Array = ".$decode."(\$item->".$item['name'].$suffix_decode.");";
$fix .= "\n\t".$tab."\t\t\tif (".$Component."Helper::checkArray(\$".$item['name']."Array))";
$fix .= "\n\t".$tab."\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\$bucket".$item['name']." = array();";
$fix .= "\n\t".$tab."\t\t\t\tforeach (\$".$item['name']."Array as \$".$item['name']."FieldName => \$".$item['name'].")";
$fix .= "\n\t".$tab."\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\tif (".$Component."Helper::checkArray(\$".$item['name']."))";
$fix .= "\n\t".$tab."\t\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\t\t\$bucket".$item['name']."[] = \$".$item['name']."FieldName . '<||VDM||>' . implode('<|VDM|>',\$".$item['name'].");";
$fix .= "\n\t".$tab."\t\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t\t//".$this->setLine(__LINE__)." make sure the bucket has values.";
$fix .= "\n\t".$tab."\t\t\t\tif (".$Component."Helper::checkArray(\$bucket".$item['name']."))";
$fix .= "\n\t".$tab."\t\t\t\t{";
$fix .= "\n\t".$tab."\t\t\t\t\t//".$this->setLine(__LINE__)." clear the repeatable field.";
$fix .= "\n\t".$tab."\t\t\t\t\tunset(\$item->".$item['name'].");";
$fix .= "\n\t".$tab."\t\t\t\t\t//".$this->setLine(__LINE__)." set repeatable field for export.";
$fix .= "\n\t".$tab."\t\t\t\t\t\$item->".$item['name']." = implode('<|||VDM|||>',\$bucket".$item['name'].");";
$fix .= "\n\t".$tab."\t\t\t\t\t//".$this->setLine(__LINE__)." unset the bucket.";
$fix .= "\n\t".$tab."\t\t\t\t\tunset(\$bucket".$item['name'].");";
$fix .= "\n\t".$tab."\t\t\t\t}";
$fix .= "\n\t".$tab."\t\t\t}";
}
else
{
if (!$export)
{
// TODO we must add options for multi custom selection.
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." convert ".$item['name'];
$fix .= "\n\t".$tab."\t\t\t\$item->".$item['name']." = ".$Component."Helper::jsonToString(\$item->".$item['name'].");";
}
}
}
}
}
}
// close the foreach if needed
if (!ComponentbuilderHelper::checkString($fix) && $export)
{
$fix .= "\n\n\t".$tab."\t//".$this->setLine(__LINE__)." set values to display correctly.";
$fix .= "\n\t".$tab."\tif (".$Component."Helper::checkArray(\$items))";
$fix .= "\n\t".$tab."\t{";
$fix .= "\n\t".$tab."\t\tforeach (\$items as \$nr => &\$item)";
$fix .= "\n\t".$tab."\t\t{";
}
// close the foreach if needed
if (ComponentbuilderHelper::checkString($fix))
{
// remove these values if export
if ($export)
{
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." unset the values we don't want exported.";
$fix .= "\n\t".$tab."\t\t\tunset(\$item->asset_id);";
$fix .= "\n\t".$tab."\t\t\tunset(\$item->checked_out);";
$fix .= "\n\t".$tab."\t\t\tunset(\$item->checked_out_time);";
}
$fix .= "\n\t".$tab."\t\t}";
$fix .= "\n\t".$tab."\t}";
if ($export)
{
$fix .= "\n\t".$tab."\t//".$this->setLine(__LINE__)." Add headers to items array.";
$fix .= "\n\t".$tab."\t\$headers = \$this->getExImPortHeaders();";
$fix .= "\n\t".$tab."\tif (".$Component."Helper::checkObject(\$headers))";
$fix .= "\n\t".$tab."\t{";
$fix .= "\n\t".$tab."\t\tarray_unshift(\$items,\$headers);";
$fix .= "\n\t".$tab."\t}";
}
}
// add custom php to getitems method
if (isset($this->customScriptBuilder['php_getitems'][$view]) && ComponentbuilderHelper::checkString($this->customScriptBuilder['php_getitems'][$view]))
{
$fix .= "\n\n".$tab."".str_replace(array_keys($this->placeholders),array_values($this->placeholders),$this->customScriptBuilder['php_getitems'][$view]);
}
if ($basicCrypt)
{
$script = "\n\n\t".$tab."\t//".$this->setLine(__LINE__)." Get the basic encription key.";
$script .= "\n\t".$tab."\t\$basickey = ".$Component."Helper::getCryptKey('basic');";
$script .= "\n\t".$tab."\t//".$this->setLine(__LINE__)." Get the encription object.";
$script .= "\n\t".$tab."\t\$basic = new FOFEncryptAes(\$basickey, 128);";
// add the encryption script
$fix = $script . $fix;
}
if ($advancedCrypt)
{
$script = "\n\n\t".$tab."\t//".$this->setLine(__LINE__)." Get the advanced encription key.";
$script .= "\n\t".$tab."\t\$advancedkey = ".$Component."Helper::getCryptKey('advanced');";
$script .= "\n\t".$tab."\t//".$this->setLine(__LINE__)." Get the encription object.";
$script .= "\n\t".$tab."\t\$advanced = new FOFEncryptAes(\$advancedkey, 256);";
// add the encryption script
$fix = $script . $fix;
}
return $fix;
}
protected function setSelectionTranslationFix($views,$Component,$tab = '')
{
// add the fix if this view has the need for it
$fix = '';
if (isset($this->selectionTranslationFixBuilder[$views]) && ComponentbuilderHelper::checkArray($this->selectionTranslationFixBuilder[$views]))
{
$fix .= "\n\n\t".$tab."\t//".$this->setLine(__LINE__)." set selection value to a translatable value";
$fix .= "\n\t".$tab."\tif (".$Component."Helper::checkArray(\$items))";
$fix .= "\n\t".$tab."\t{";
$fix .= "\n\t".$tab."\t\tforeach (\$items as \$nr => &\$item)";
$fix .= "\n\t".$tab."\t\t{";
foreach ($this->selectionTranslationFixBuilder[$views] as $name => $values)
{
$fix .= "\n\t".$tab."\t\t\t//".$this->setLine(__LINE__)." convert ".$name;
$fix .= "\n\t".$tab."\t\t\t\$item->".$name." = \$this->selectionTranslation(\$item->".$name.", '".$name."');";
}
$fix .= "\n\t".$tab."\t\t}";
$fix .= "\n\t".$tab."\t}\n";
}
return $fix;
}
protected function setSelectionTranslationFixFunc($views,$Component)
{
// add the fix if this view has the need for it
$fix = '';
if (isset( $this->selectionTranslationFixBuilder[$views]) && ComponentbuilderHelper::checkArray($this->selectionTranslationFixBuilder[$views]))
{
$fix .= "\n\n\t/**";
$fix .= "\n\t* Method to convert selection values to translatable string.";
$fix .= "\n\t*";
$fix .= "\n\t* @return translatable string";
$fix .= "\n\t*/";
$fix .= "\n\tpublic function selectionTranslation(\$value,\$name)";
$fix .= "\n\t{";
foreach ($this->selectionTranslationFixBuilder[$views] as $name => $values)
{
if (ComponentbuilderHelper::checkArray($values))
{
$fix .= "\n\t\t//".$this->setLine(__LINE__)." Array of ".$name." language strings";
$fix .= "\n\t\tif (\$name == '".$name."')";
$fix .= "\n\t\t{";
$fix .= "\n\t\t\t\$".$name."Array = array(";
$counter = 0;
foreach ($values as $value => $translang)
{
// only add quotes to strings
if (ComponentbuilderHelper::checkString($value))
{
$key = "'".$value."'";
}
else
{
if ($value == '')
{
$value = 0;
}
$key = $value;
}
if ($counter == 0)
{
$fix .= "\n\t\t\t\t".$key." => '".$translang."'";
}
else
{
$fix .= ",\n\t\t\t\t".$key." => '".$translang."'";
}
$counter++;
}
$fix .= "\n\t\t\t);";
$fix .= "\n\t\t\t//".$this->setLine(__LINE__)." Now check if value is found in this array";
$fix .= "\n\t\t\tif (isset(\$".$name."Array[\$value]) && ".$Component."Helper::checkString(\$".$name."Array[\$value]))";
$fix .= "\n\t\t\t{";
$fix .= "\n\t\t\t\treturn \$".$name."Array[\$value];";
$fix .= "\n\t\t\t}";
$fix .= "\n\t\t}";
}
}
$fix .= "\n\t\treturn \$value;";
$fix .= "\n\t}";
}
return $fix;
}
protected function setFieldSet($view,$component)
{
// setup the fieldset of this view
if (isset($view['settings']->fields) && ComponentbuilderHelper::checkArray($view['settings']->fields))
{
// setup the list view and single view name
$listViewName = ComponentbuilderHelper::safeString($view['settings']->name_list);
$viewName = ComponentbuilderHelper::safeString($view['settings']->name_single);
// add metadata to the view
if ($view['metadata'])
{
$this->metadataBuilder[$viewName] = $viewName;
}
// add access to the view
if ($view['access'])
{
$this->accessBuilder[$viewName] = $viewName;
}
// set the read only
$readOnly = "";
if ($view['settings']->type == 2)
{
$readOnly = "\n\t\t\t".'readonly="true"'."\n\t\t\t".'disabled="true"';
}
// main lang prefix
$langView = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($view['settings']->name_single,'U');
$langViews = $this->langPrefix.'_'.ComponentbuilderHelper::safeString($view['settings']->name_list,'U');
// set default lang
$this->langContent[$this->lang][$langView] = $view['settings']->name_single;
$this->langContent[$this->lang][$langViews] = $view['settings']->name_list;
// set the singel name
$viewSingleName = ComponentbuilderHelper::safeString($view['settings']->name_single,'W');
// set global item strings
$this->langContent[$this->lang][$langViews.'_N_ITEMS_ARCHIVED'] = "%s ".$view['settings']->name_list." archived.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_ARCHIVED_1'] = "%s ".$view['settings']->name_single." archived.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_CHECKED_IN_0'] = "No ".$view['settings']->name_single." successfully checked in.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_CHECKED_IN_1'] = "%d ".$view['settings']->name_single." successfully checked in.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_CHECKED_IN_MORE'] = "%d ".$view['settings']->name_list." successfully checked in.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_DELETED'] = "%s ".$view['settings']->name_list." deleted.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_DELETED_1'] = "%s ".$view['settings']->name_single." deleted.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_FEATURED'] = "%s ".$view['settings']->name_list." featured.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_FEATURED_1'] = "%s ".$view['settings']->name_single." featured.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_PUBLISHED'] = "%s ".$view['settings']->name_list." published.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_PUBLISHED_1'] = "%s ".$view['settings']->name_single." published.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_TRASHED'] = "%s ".$view['settings']->name_list." trashed.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_TRASHED_1'] = "%s ".$view['settings']->name_single." trashed.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_UNFEATURED'] = "%s ".$view['settings']->name_list." unfeatured.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_UNFEATURED_1'] = "%s ".$view['settings']->name_single." unfeatured.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_UNPUBLISHED'] = "%s ".$view['settings']->name_list." unpublished.";
$this->langContent[$this->lang][$langViews.'_N_ITEMS_UNPUBLISHED_1'] = "%s ".$view['settings']->name_single." unpublished.";
$this->langContent[$this->lang][$langViews.'_BATCH_OPTIONS'] = "Batch process the selected ".$view['settings']->name_list;
$this->langContent[$this->lang][$langViews.'_BATCH_TIP'] = "All changes will be applied to all selected ".$view['settings']->name_list;
// set some basic defaults
$this->langContent[$this->lang][$langView.'_ERROR_UNIQUE_ALIAS'] = "Another ".$view['settings']->name_single." has the same alias.";
$this->langContent[$this->lang][$langView.'_CREATED_DATE_LABEL'] = "Created date";
$this->langContent[$this->lang][$langView.'_CREATED_DATE_DESC'] = "The date ".$view['settings']->name_single." was created.";
$this->langContent[$this->lang][$langView.'_CREATED_BY_LABEL'] = "Created by";
$this->langContent[$this->lang][$langView.'_CREATED_BY_DESC'] = "The user that created the ".$view['settings']->name_single.".";
$this->langContent[$this->lang][$langView.'_ORDERING_LABEL'] = "Ordering";
$this->langContent[$this->lang][$langView.'_VERSION_LABEL'] = "Revision";
$this->langContent[$this->lang][$langView.'_VERSION_DESC'] = "A count of the number of times this ".$view['settings']->name_single." has been revised.";
$this->langContent[$this->lang][$langView.'_SAVE_WARNING'] = "Alias already existed so a number was added at the end. You can re-edit the ".$view['settings']->name_single." to customise the alias.";
// set the defautl fields
$fieldSet = '";
// check if metadata is added to this view
if (isset($this->metadataBuilder[$viewName]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$viewName]))
{
$fieldSet .= "\n\n\t";
$fieldSet .= "\n\t';
$fieldSet .= "\n\t\t".'