示例#1
0
 /**
  * Method to populate the data for a component object.
  *
  * @param	component_object		object	Component object passed by ref
  * @param	default_object_id		integer	Id of the component object set as the default object for the component
  * @param	template_component_name	string	Template component name used to generate search/replace pairs
  * @param	template_object_name	string	Template object name used to generate search/replace pairs
  *
  * @return	fieldsets				array	An array of fieldset objects		
  */
 protected function _populateComponentObject(&$component_object, $default_object_id, $template_component_name, $template_object_name)
 {
     // Double check that only limited punctuation is present in name as this may cause php code or sql problems
     $component_object->name = preg_replace($this->_name_regex, '', $component_object->name);
     require_once JPATH_COMPONENT . '/helpers/pluralise.php';
     if ($component_object->plural_name == '') {
         // ??? Need to add a check if language is english first	once Component Architect is made multi-lingual
         $component_object->plural_name = ComponentArchitectPluraliseHelper::pluralise($component_object->name);
     } else {
         // Double check that no punctuation is present in name as this may cause php code or sql problems
         $component_object->plural_name = preg_replace($this->_name_regex, '', $component_object->plural_name);
     }
     if ($component_object->code_name == '') {
         $component_object->code_name = str_replace(' ', '_', JString::strtolower(JString::trim($component_object->name)));
     }
     if ($component_object->plural_code_name == '') {
         $component_object->plural_code_name = str_replace(' ', '_', JString::strtolower(JString::trim($component_object->plural_name)));
     }
     if ($component_object->short_name == '') {
         $component_object->short_name = str_replace(' ', '_', JString::strtolower(JString::trim($component_object->name)));
     } else {
         // Double check that no punctuation is present in name as this may cause php code or sql problems
         $component_object->short_name = preg_replace($this->_name_regex, '', $component_object->short_name);
     }
     if ($component_object->short_plural_name == '') {
         $component_object->short_plural_name = str_replace(' ', '_', JString::strtolower(JString::trim($component_object->plural_name)));
     } else {
         // Double check that no punctuation is present in name as this may cause php code or sql problems
         $component_object->short_plural_name = preg_replace($this->_name_regex, '', $component_object->short_plural_name);
     }
     //Conditions are a generic set for the generate which may include other conditions besides Joomla! Features
     //Convert Joomla! Parts to conditions.
     $no_generate_array = array();
     // 1st pass to find all high level conditions that are set to not generate
     foreach ($component_object->joomla_parts as $name => $value) {
         // Higher levels must be set to generate otherwise all levels below will need to be set to not generate
         if (($name == 'generate_admin' or $name == 'generate_site' or $name == 'generate_plugins' or $name == 'generate_modules') and $value == '0') {
             $no_generate_array[] = $name;
         }
     }
     // 2nd pass to check each of the conditions against the no generate ones
     foreach ($component_object->joomla_parts as $name => $value) {
         // For the generate conditions in Joomla! Parts then only do so at object level if set at component level
         if ($this->_search_replace_helper->getComponentConditions($name)) {
             if ($value == '1') {
                 for ($i = 0; $i < count($no_generate_array); $i++) {
                     if (JString::strpos($name, $no_generate_array[$i]) !== false) {
                         // make sure the value is set to not generate
                         $value = '0';
                         break;
                     }
                 }
                 if ($value == '1' and (JString::strpos($name, 'generate_categories_site') !== false and in_array('generate_site', $no_generate_array) or JString::strpos($name, 'generate_site_layout') !== false and in_array('generate_site_views', $no_generate_array))) {
                     $value = '0';
                 }
             }
         } else {
             $value = '0';
         }
         $component_object->conditions[$name] = (int) $value;
     }
     //Convert Joomla! Features to conditions.
     foreach ($component_object->joomla_features as $name => $value) {
         if ($value == "") {
             $component_object->conditions[$name] = (int) $this->_search_replace_helper->getComponentConditions($name) ? $this->_search_replace_helper->getComponentConditions($name) : 0;
         } else {
             $component_object->conditions[$name] = (int) $value;
         }
     }
     if ($component_object->id == $default_object_id) {
         if (!$this->_code_template->multiple_category_objects and $this->_search_replace_helper->getComponentConditions('generate_categories') == 1) {
             $component_object->conditions['generate_categories'] = 1;
         }
         $component_object->default_object = true;
         // Search/Replace set here as in not known earlier for _getComponentSearchPairs
         // e.g. 'search' => '[%%architectcomp_default_admin_view%%]', 'replace' => 'groups'
         array_push($this->_component->search_replace_pairs, array('search' => $this->_markupText(JString::strtolower(str_replace(" ", "", $template_component_name)) . '_default_admin_view'), 'replace' => JString::strtolower(str_replace("_", "", $component_object->plural_code_name))));
         // e.g. 'search' => '[%%architectcomp_default_view%%]', 'replace' => 'groups'
         array_push($this->_component->search_replace_pairs, array('search' => $this->_markupText(JString::strtolower(str_replace(" ", "", $template_component_name)) . '_default_view'), 'replace' => JString::strtolower(str_replace("_", "", $component_object->plural_code_name))));
     } else {
         if (!$this->_code_template->multiple_category_objects) {
             $component_object->conditions['generate_categories'] = 0;
             $component_object->conditions['generate_categories_site_views_categories'] = 0;
             $component_object->conditions['generate_categories_site_views_category'] = 0;
         }
         $component_object->default_object = false;
     }
     // Initialise acronym store
     $this->_acronyms = array();
     $this->_acronyms['id'] = 'a';
     if ($this->_search_replace_helper->getComponentConditions('generate_categories') == 1) {
         $this->_acronyms['catid'] = 'c';
     }
     if ($component_object->conditions['include_access'] == 1 or $this->_search_replace_helper->getComponentConditions('include_access') == 1) {
         $this->_acronyms['access'] = 'ag';
     }
     if ($component_object->conditions['include_checkout'] == 1 or $this->_search_replace_helper->getComponentConditions('include_checkout') == 1) {
         $this->_acronyms['checked_out'] = 'uc';
     }
     if ($component_object->conditions['include_created'] == 1 or $this->_search_replace_helper->getComponentConditions('include_created') == 1) {
         $this->_acronyms['created_by'] = 'ua';
     }
     if ($component_object->conditions['include_modified'] == 1 or $this->_search_replace_helper->getComponentConditions('include_modified') == 1) {
         $this->_acronyms['modified_by'] = 'uam';
     }
     if ($component_object->conditions['generate_plugins_vote'] == 1 or $this->_search_replace_helper->getComponentConditions('generate_plugins_vote') == 1) {
         $this->_acronyms['rating'] = 'v';
     }
     $component_object->search_replace = $this->_getComponentObjectSearchPairs($template_object_name, $component_object);
     if ($this->_getFieldsets($component_object) === false) {
         return false;
     }
     if ($this->_getFields($component_object) === false) {
         return false;
     }
     return $component_object;
 }
示例#2
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param	JTable	$table
  *
  * @return	void
  */
 protected function prepareTable($table)
 {
     $db = $this->getDbo();
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
     //[%%START_CUSTOM_CODE%%]
     require_once JPATH_COMPONENT . '/helpers/pluralise.php';
     $table->plural_name = htmlspecialchars_decode($table->plural_name, ENT_QUOTES);
     if (empty($table->plural_name)) {
         $name_array = explode(' ', $table->name);
         $name_array[count($name_array) - 1] = ComponentArchitectPluraliseHelper::pluralise($name_array[count($name_array) - 1]);
         $table->plural_name = implode(' ', $name_array);
     }
     $table->short_name = htmlspecialchars_decode($table->short_name, ENT_QUOTES);
     if (empty($table->short_name)) {
         $name_array = explode(' ', $table->name);
         $table->short_name = $name_array[count($name_array) - 1];
     }
     $table->short_plural_name = htmlspecialchars_decode($table->short_plural_name, ENT_QUOTES);
     if (empty($table->short_plural_name)) {
         $name_array = explode(' ', $table->plural_name);
         $table->short_plural_name = $name_array[count($name_array) - 1];
     }
     $table->code_name = str_replace('-', '_', JApplication::stringURLSafe($table->code_name));
     if (empty($table->code_name)) {
         $table->code_name = $this->generateUniqueCodeName((array) $table);
     }
     $table->plural_code_name = str_replace('-', '_', JApplication::stringURLSafe($table->plural_code_name));
     if (empty($table->plural_code_name)) {
         $table->plural_code_name = $this->generateUniqueCodeName((array) $table, 'plural_code_name');
     }
     //[%%END_CUSTOM_CODE%%]
     if (empty($table->id) or $table->id == 0) {
         // Set ordering to the last item if not set
         if (empty($table->ordering) or $table->ordering == 0) {
             $conditions_array = $this->getReorderConditions($table);
             $conditions = implode(' AND ', $conditions_array);
             $table->reorder($conditions);
         }
     }
 }