function install($theme) { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $package = $this->_getPackageFromUpload(); if (!$package) { JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_FIND_INSTALL_PACKAGE')); $this->deleteTempFiles(); return false; } if ($package['dir'] && JFolder::exists($package['dir'])) { $this->setPath('source', $package['dir']); } else { JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_INSTALL_PATH_NOT_EXISTS')); $this->deleteTempFiles(); return false; } // We need to find the installation manifest file if (!$this->_findManifest()) { JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_FIND_INFO_INSTALL_PACKAGE')); $this->deleteTempFiles(); return false; } // Files - copy files in manifest foreach ($this->_manifest->children() as $child) { if (is_a($child, 'JXMLElement') && $child->name() == 'files') { if ($this->parseFiles($child) === false) { JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_FIND_INFO_INSTALL_PACKAGE')); $this->deleteTempFiles(); return false; } } } // File - copy the xml file $copyFile = array(); $path['src'] = $this->getPath('manifest'); // XML file will be copied too $path['dest'] = JPATH_SITE . DS . 'media' . DS . 'com_phocagallery' . DS . 'images' . DS . basename($this->getPath('manifest')); $copyFile[] = $path; $this->copyFiles($copyFile, array()); $this->deleteTempFiles(); // ------------------- // Themes // ------------------- // Params - Get new themes params $paramsThemes = $this->getParamsThemes(); // ------------------- // Component // ------------------- if (isset($theme['component']) && $theme['component'] == 1) { $component = 'com_phocagallery'; $paramsC = JComponentHelper::getParams($component); foreach ($paramsThemes as $keyT => $valueT) { $paramsC->set($valueT['name'], $valueT['value']); } $data['params'] = $paramsC->toArray(); $table = JTable::getInstance('extension'); $idCom = $table->find(array('element' => $component)); $table->load($idCom); if (!$table->bind($data)) { JError::raiseWarning(500, 'Not a valid component'); return false; } // pre-save checks if (!$table->check()) { JError::raiseWarning(500, $table->getError('Check Problem')); return false; } // save the changes if (!$table->store()) { JError::raiseWarning(500, $table->getError('Store Problem')); return false; } } // ------------------- // Menu Categories // ------------------- if (isset($theme['categories']) && $theme['categories'] == 1) { $link = 'index.php?option=com_phocagallery&view=categories'; $where = array(); $where[] = 'link = ' . $db->Quote($link); $query = 'SELECT id, params FROM #__menu WHERE ' . implode(' AND ', $where); $db->setQuery($query); $itemsCat = $db->loadObjectList(); if (!empty($itemsCat)) { foreach ($itemsCat as $keyIT => $valueIT) { $query = 'SELECT m.params FROM #__menu AS m WHERE m.id = ' . (int) $valueIT->id; $db->setQuery($query); $paramsCJSON = $db->loadResult(); //$paramsCJSON = $valueIT->params; $paramsMc = new JParameter(); $paramsMc->loadJSON($paramsCJSON); foreach ($paramsThemes as $keyT => $valueT) { $paramsMc->set($valueT['name'], $valueT['value']); } $dataMc['params'] = $paramsMc->toArray(); $table =& JTable::getInstance('menu'); if (!$table->load((int) $valueIT->id)) { JError::raiseWarning(500, 'Not a valid table'); return false; } if (!$table->bind($dataMc)) { JError::raiseWarning(500, 'Not a valid table'); return false; } // pre-save checks if (!$table->check()) { JError::raiseWarning(500, $table->getError('Check Problem')); return false; } // save the changes if (!$table->store()) { JError::raiseWarning(500, $table->getError('Store Problem')); return false; } } } } // ------------------- // Menu Category // ------------------- if (isset($theme['category']) && $theme['category'] == 1) { // Select all categories to get possible menu links $query = 'SELECT c.id FROM #__phocagallery_categories AS c'; $db->setQuery($query); $categoriesId = $db->loadObjectList(); // We get id from Phoca Gallery categories and try to find menu links from these categories if (!empty($categoriesId)) { foreach ($categoriesId as $keyI => $valueI) { $link = 'index.php?option=com_phocagallery&view=category&id=' . (int) $valueI->id; //$link = 'index.php?option=com_phocagallery&view=category'; $where = array(); $where[] = 'link = ' . $db->Quote($link); $query = 'SELECT id, params FROM #__menu WHERE ' . implode(' AND ', $where); $db->setQuery($query); $itemsCat = $db->loadObjectList(); if (!empty($itemsCat)) { foreach ($itemsCat as $keyIT2 => $valueIT2) { $query = 'SELECT m.params FROM #__menu AS m WHERE m.id = ' . (int) $valueIT2->id; $db->setQuery($query); $paramsCtJSON = $db->loadResult(); //$paramsCtJSON = $valueIT2->params; $paramsMct = new JParameter(); $paramsMct->loadJSON($paramsCtJSON); foreach ($paramsThemes as $keyT => $valueT) { $paramsMct->set($valueT['name'], $valueT['value']); } $dataMct['params'] = $paramsMct->toArray(); $table =& JTable::getInstance('menu'); if (!$table->load((int) $valueIT2->id)) { JError::raiseWarning(500, 'Not a valid table'); return false; } if (!$table->bind($dataMct)) { JError::raiseWarning(500, 'Not a valid table'); return false; } // pre-save checks if (!$table->check()) { JError::raiseWarning(500, $table->getError('Check Problem')); return false; } // save the changes if (!$table->store()) { JError::raiseWarning(500, $table->getError('Store Problem')); return false; } } } } } } return true; }