/** * This method will replace a lot of placeholders in the given text * @param string $file - a files text content * @param object $item - the component object * @param array $options - some options may be set * @return mixed */ public static function _replace($file, $item, $options = array()) { static $firstname; $date = JFactory::getDate($item->created); $categorytask = $item->params->get('uses_categories') ? JaccHelper::getcategorytask() : ""; $reltable = isset($options['reltable']) ? $options['reltable'] : ''; $extension = isset($options['extension']) ? $options['extension'] : ''; if (empty($firsttable) && isset($options['firstname'])) { $firstname = $options['firstname']; } if (isset($options['submenu']) && trim($options['submenu'])) { $options['submenu'] = "\t\t\t<submenu>\n" . $options['submenu'] . "\n\t\t\t</submenu>"; } $description = $item->description; $version = $item->version; $params = JComponentHelper::getParams('com_jacc'); $com_component = $item->name; $lcomponent = strtolower(str_replace('com_', '', $com_component)); $component = ucfirst($lcomponent); $file = str_replace("##table##", $reltable, $file); $file = str_replace("##extension##", $extension, $file); $file = str_replace("##categorytask##", $categorytask, $file); $file = str_replace("##codestart##", '<?php', $file); $file = str_replace("##codeend##", '?>', $file); $file = str_replace("##Component##", $component, $file); $file = str_replace("##description##", $description, $file); if (isset($options['defaultview']) && $options['defaultview']) { $file = str_replace("##defaultviewname##", $options['defaultview'], $file); } else { $file = str_replace("##defaultviewname##", $firstname, $file); } if (isset($options['plural']) && $options['plural']) { $file = str_replace("##plural##", $options['plural'], $file); $file = str_replace("##Plural##", ucfirst($options['plural']), $file); } $file = str_replace("##firstname##", $firstname, $file); $file = str_replace("##firstnames##", $firstname . 's', $file); $file = str_replace("##version##", $version, $file); $file = str_replace("##table##", $reltable, $file); $file = str_replace("##website##", $params->get('website'), $file); $file = str_replace("##author##", $params->get('author'), $file); $file = str_replace("##sauthor##", $params->get('sauthor'), $file); $file = str_replace("##email##", $params->get('email'), $file); $file = str_replace("##license##", $params->get('license'), $file); $file = str_replace("##component##", $lcomponent, $file); $file = str_replace("##COMPONENT##", strtoupper($lcomponent), $file); $file = str_replace("##date##", $date->format('Y-m-d'), $file); $file = str_replace("##year##", $date->format('Y'), $file); $file = str_replace("##com_component##", $com_component, $file); foreach ($options as $key => $value) { $value = (string) $value; $Ukey = ucfirst($key); $Uvalue = ucfirst($value); $file = str_replace("##" . $key . "##", $value, $file); $file = str_replace("##" . $Ukey . "##", $Uvalue, $file); } //replace category related code, if not needed if (!$item->params->get('uses_categories')) { $pattern = '/##ifdefCategoriesStart##.*##ifdefCategoriesEnd##/isU'; $file = preg_replace($pattern, '', $file); } $pattern = '/\\s+##ifdefCategories.*[Start|End]##+?/isU'; $file = preg_replace($pattern, '', $file); return $file; }
public static function _replace($file, $item, $options = array()) { $date = JFactory::getDate($item->created); $categorytask = $item->params->get('uses_categories') ? JaccHelper::getcategorytask() : ""; $reltable = isset($options['reltable']) ? $options['reltable'] : ''; if (isset($options['submenu']) && trim($options['submenu'])) { $options['submenu'] = "\t\t\t<submenu>\n" . $options['submenu'] . "\n\t\t\t</submenu>"; } $description = $item->description; $version = $item->version; $params = JComponentHelper::getParams('com_jacc'); $com_component = $item->name; $lcomponent = strtolower(str_replace('com_', '', $com_component)); $component = ucfirst($lcomponent); $file = str_replace("##table##", $reltable, $file); $file = str_replace("##categorytask##", $categorytask, $file); $file = str_replace("##codestart##", '<?php', $file); $file = str_replace("##codeend##", '?>', $file); $file = str_replace("##Component##", $component, $file); $file = str_replace("##description##", $description, $file); /** $file = str_replace("##defaultview##", $defaultview, $file); $file = str_replace("##firstname##", $firstName, $file); $file = str_replace("##Firstname##", $UFirstName, $file); **/ $file = str_replace("##version##", $version, $file); $file = str_replace("##table##", $reltable, $file); $file = str_replace("##website##", $params->get('website'), $file); $file = str_replace("##author##", $params->get('author'), $file); $file = str_replace("##sauthor##", $params->get('sauthor'), $file); $file = str_replace("##email##", $params->get('email'), $file); $file = str_replace("##license##", $params->get('license'), $file); $file = str_replace("##component##", $lcomponent, $file); $file = str_replace("##date##", $date->format('Y-m-d'), $file); $file = str_replace("##year##", $date->format('Y'), $file); $file = str_replace("##com_component##", $com_component, $file); foreach ($options as $key => $value) { $value = (string) $value; $Ukey = ucfirst($key); $Uvalue = ucfirst($value); $file = str_replace("##" . $key . "##", $value, $file); $file = str_replace("##" . $Ukey . "##", $Uvalue, $file); } /** $file = str_replace("##name##", $name, $file); $file = str_replace("##Name##", $UName, $file); $file = str_replace("##key##", $key, $file); $file = str_replace("##hident##", $hident, $file); $file = str_replace("##primary##", $primary, $file); $file = str_replace("##menuhelper##", $menuhelper, $file); $file = str_replace("##routerswitch##", $routerswitch, $file); $file = str_replace("##syslanguage##", $syslanguage, $file); **/ return $file; }