Skip to content

Commit

Permalink
Impossible to upload some themes - issue #579
Browse files Browse the repository at this point in the history
  • Loading branch information
getdatakick committed Sep 6, 2018
1 parent 053c7d8 commit c745204
Show file tree
Hide file tree
Showing 5 changed files with 518 additions and 291 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -36,7 +36,10 @@ composer.lock
/config/settings.inc.php
/config/settings.old.php
/config/xml/*
!/config/xml/themes/
/config/xml/themes/*
!/config/xml/themes/default.xml
!/config/xml/themes/community-theme-default.xml

This comment has been minimized.

Copy link
@getdatakick

getdatakick Sep 6, 2018

Author Contributor

this commit sync default.xml and community-theme-default.xml with current version of /themes/community-theme-default/config.xml. For more info see issue #589

This comment has been minimized.

Copy link
@Traumflug

Traumflug Sep 6, 2018

Contributor

Pretty huge commit. Review would be easier if there were one commit for each task. One for the return bug, one for removal of unused code, one for this 500 throwing code, and so on. A strategy also known as "atomic commits" [1] [2]

With this huge commit a review takes a bit longer.

This comment has been minimized.

Copy link
@getdatakick

getdatakick Sep 6, 2018

Author Contributor

fair enough, I’ll try not to mix separate aspects next time.


/config/defines_custom.inc.php
/config/settings_custom.inc.php
Expand Down
147 changes: 116 additions & 31 deletions classes/Theme.php
Expand Up @@ -192,30 +192,21 @@ public static function getThemeInfo($idTheme)
$theme = new Theme((int) $idTheme);
$themeArr = [];

if (file_exists(_PS_ROOT_DIR_.'/config/xml/themes/'.$theme->directory.'.xml')) {
$configFile = _PS_ROOT_DIR_.'/config/xml/themes/'.$theme->directory.'.xml';
} elseif ($theme->name == 'community-theme-default') {
$configFile = _PS_ROOT_DIR_.'/config/xml/themes/default.xml';
} else {
$configFile = false;
}
$xmlTheme = $theme->loadConfigFile();

if ($configFile) {
if ($xmlTheme) {
$themeArr['theme_id'] = (int) $theme->id;
$xmlTheme = @simplexml_load_file($configFile);

if ($xmlTheme !== false) {
foreach ($xmlTheme->attributes() as $key => $value) {
$themeArr['theme_'.$key] = (string) $value;
}
foreach ($xmlTheme->attributes() as $key => $value) {
$themeArr['theme_'.$key] = (string) $value;
}

foreach ($xmlTheme->author->attributes() as $key => $value) {
$themeArr['author_'.$key] = (string) $value;
}
foreach ($xmlTheme->author->attributes() as $key => $value) {
$themeArr['author_'.$key] = (string) $value;
}

if ($themeArr['theme_name'] == 'community-theme-default') {
$themeArr['tc'] = Module::isEnabled('themeconfigurator');
}
if ($themeArr['theme_name'] == 'community-theme-default') {
$themeArr['tc'] = Module::isEnabled('themeconfigurator');
}
} else {
// If no xml we use data from database
Expand All @@ -241,9 +232,12 @@ public static function getNonInstalledTheme()
$notInstalledTheme = [];
foreach (glob(_PS_ALL_THEMES_DIR_.'*', GLOB_ONLYDIR) as $themeDir) {
$dir = basename($themeDir);
$configFile = _PS_ALL_THEMES_DIR_.$dir.'/config.xml';
if (!in_array($dir, $installedThemeDirectories) && @filemtime($configFile)) {
if ($xmlTheme = @simplexml_load_file($configFile)) {
if (!in_array($dir, $installedThemeDirectories)) {

This comment has been minimized.

Copy link
@getdatakick

getdatakick Sep 6, 2018

Author Contributor

Go through all subdirectories in the /themes directory, and find those themes there were not installed yet. Not-installed themes should contain Config.xml (with capital C), but we will accept lowercase version as well.

$xmlTheme = static::loadConfigFromFile(_PS_ALL_THEMES_DIR_.$dir.'/Config.xml', true);
if (! $xmlTheme) {
$xmlTheme = static::loadConfigFromFile(_PS_ALL_THEMES_DIR_.$dir.'/config.xml', true);
}
if ($xmlTheme) {
$theme = [];
foreach ($xmlTheme->attributes() as $key => $value) {
$theme[$key] = (string) $value;
Expand Down Expand Up @@ -557,17 +551,108 @@ public function toggleDefaultRightColumn()
*/
public function getConfiguration()
{
$target = _PS_ROOT_DIR_.'/themes/'.$this->name.'/Config.xml';
if (!file_exists($target)) {
$target = _PS_ROOT_DIR_.'/themes/'.$this->name.'/config.xml';
if (!file_exists($target)) {
return [];
$ob = $this->loadConfigFile();

This comment has been minimized.

Copy link
@getdatakick

getdatakick Sep 6, 2018

Author Contributor

we will load file from /config/xml/themes/<theme>.xml.

Note that originally this function loaded config.xml file from theme directory. That's totally wrong - the config file doesn't need to exists. If it exists, it usually has different format that Config.xml file from theme installation directory. In ps14 config.xml was used to advertise theme capabilities:

<?xml version="1.0" encoding="UTF-8" ?>
<theme>
	<version value="1.4">
		<ccc available="true" />
		<guest_checkout available="true" />
		<one_page_checkout available="true" />
		<store_locator available="true" />
	</version>
</theme>

Compare with Config.xml with that has installation instructions:

<?xml version="1.0" encoding="UTF-8"?>
<theme version="1.1.0" name="community-theme-default" directory="community-theme-default">
    <author name="Gytis Škema &amp; Krystian Podemski" email="info@thirtybees.com" url="https://thirtybees.com"/>
    <descriptions>
        <description iso="en">Community theme is a theme developed and maintained by the thirty bees community.</description>
    </descriptions>
    <variations>
        <variation name="community-theme-default" directory="community-theme-default" responsive="1"
                   default_left_column="1" default_right_column="0" product_per_page="12" from="1.6.1.3" to="1.6.1.6"/>
    </variations>
    <docs></docs>
    <metas>
        <meta meta_page="404" left="0" right="0"/>
        <meta meta_page="best-sales" left="1" right="0"/>
        <meta meta_page="contact" left="0" right="0"/>
        <meta meta_page="index" left="0" right="0"/>
        <meta meta_page="manufacturer" left="1" right="0"/>
        <meta meta_page="new-products" left="1" right="0"/>
        <meta meta_page="password" left="0" right="0"/>
        <meta meta_page="prices-drop" left="1" right="0"/>
        <meta meta_page="sitemap" left="1" right="0"/>
        <meta meta_page="supplier" left="0" right="0"/>
        <meta meta_page="address" left="0" right="0"/>
        <meta meta_page="addresses" left="0" right="0"/>
        <meta meta_page="authentication" left="0" right="0"/>
        <meta meta_page="cart" left="0" right="0"/>
        <meta meta_page="discount" left="0" right="0"/>
        <meta meta_page="history" left="0" right="0"/>
        <meta meta_page="identity" left="0" right="0"/>
        <meta meta_page="my-account" left="0" right="0"/>
        <meta meta_page="order-follow" left="0" right="0"/>
        <meta meta_page="order-slip" left="0" right="0"/>
        <meta meta_page="order" left="0" right="0"/>
        <meta meta_page="search" left="1" right="0"/>
        <meta meta_page="stores" left="0" right="0"/>
        <meta meta_page="order-opc" left="0" right="0"/>
        <meta meta_page="guest-tracking" left="0" right="0"/>
        <meta meta_page="order-confirmation" left="0" right="0"/>
        <meta meta_page="product" left="0" right="0"/>
        <meta meta_page="category" left="1" right="0"/>
        <meta meta_page="cms" left="0" right="0"/>
        <meta meta_page="module-cheque-payment" left="0" right="0"/>
        <meta meta_page="module-cheque-validation" left="0" right="0"/>
        <meta meta_page="module-bankwire-validation" left="0" right="0"/>
        <meta meta_page="module-bankwire-payment" left="0" right="0"/>
        <meta meta_page="module-cashondelivery-validation" left="0" right="0"/>
        <meta meta_page="products-comparison" left="0" right="0"/>
    </metas>
    <modules>
        <module action="enable" name="socialsharing"/>
        <module action="enable" name="blockbanner"/>
        <module action="enable" name="blockbestsellers"/>
        <module action="enable" name="blockcart"/>
        <module action="enable" name="blocksocial"/>
        <module action="enable" name="blockcategories"/>
        <module action="enable" name="blockcurrencies"/>
        <module action="enable" name="blockfacebook"/>
        <module action="enable" name="blocklanguages"/>
        <module action="enable" name="blocklayered"/>
        <module action="enable" name="blockcms"/>
        <module action="enable" name="blockcmsinfo"/>
        <module action="enable" name="blockcontact"/>
        <module action="enable" name="blockcontactinfos"/>
        <module action="enable" name="blockmanufacturer"/>
        <module action="enable" name="blockmyaccount"/>
        <module action="enable" name="blockmyaccountfooter"/>
        <module action="enable" name="blocknewproducts"/>
        <module action="enable" name="blocknewsletter"/>
        <module action="enable" name="blockpaymentlogo"/>
        <module action="enable" name="blocksearch"/>
        <module action="enable" name="blockspecials"/>
        <module action="enable" name="blockstore"/>
        <module action="enable" name="blocksupplier"/>
        <module action="enable" name="blocktags"/>
        <module action="enable" name="blockuserinfo"/>
        <module action="enable" name="blockviewed"/>
        <module action="enable" name="ctconfiguration"/>
        <module action="enable" name="cttopmenu"/>
        <module action="enable" name="dashactivity"/>
        <module action="enable" name="dashtrends"/>
        <module action="enable" name="dashgoals"/>
        <module action="enable" name="dashproducts"/>
        <module action="enable" name="homeslider"/>
        <module action="enable" name="homefeatured"/>
        <module action="enable" name="productpaymentlogos"/>
        <module action="enable" name="statsdata"/>
        <module action="enable" name="themeconfigurator"/>
        <module action="enable" name="blockwishlist"/>
        <module action="enable" name="productcomments"/>
        <module action="enable" name="sendtoafriend"/>
        <module action="disable" name="autoupgrade"/>
        <module action="disable" name="blockadvertising"/>
        <module action="disable" name="blockcustomerprivacy"/>
        <module action="disable" name="blocklink"/>
        <module action="disable" name="blockpermanentlinks"/>
        <module action="disable" name="blockreinsurance"/>
        <module action="disable" name="blockrss"/>
        <module action="disable" name="blocksharefb"/>
        <module action="disable" name="blocktopmenu"/>
        <module action="disable" name="crossselling"/>
        <module action="disable" name="editorial"/>
        <module action="disable" name="favoriteproducts"/>
        <module action="disable" name="ganalytics"/>
        <module action="disable" name="gsitemap"/>
        <module action="disable" name="mailalerts"/>
        <module action="disable" name="newsletter"/>
        <module action="disable" name="productscategory"/>
        <module action="disable" name="producttooltip"/>
        <module action="disable" name="trackingfront"/>
        <module action="disable" name="vatnumber"/>
        <module action="disable" name="addshoppers"/>
        <hooks>
            <hook module="socialsharing" hook="displayHeader" position="1"/>
            <hook module="socialsharing" hook="displayRightColumnProduct" position="2"/>
            <hook module="socialsharing" hook="actionObjectProductUpdateAfter" position="1"/>
            <hook module="socialsharing" hook="actionObjectProductDeleteAfter" position="1"/>
            <hook module="socialsharing" hook="displayCompareExtraInformation" position="1"/>
            <hook module="blockbanner" hook="displayHeader" position="2"/>
            <hook module="blockbanner" hook="displayBanner" position="1"/>
            <hook module="blockbanner" hook="actionObjectLanguageAddAfter" position="1"/>
            <hook module="blockbestsellers" hook="displayLeftColumn" position="1" exceptions="category"/>
            <hook module="blockbestsellers" hook="displayHeader" position="3"/>
            <hook module="blockbestsellers" hook="actionProductAdd" position="1"/>
            <hook module="blockbestsellers" hook="actionProductUpdate" position="1"/>
            <hook module="blockbestsellers" hook="actionProductDelete" position="1"/>
            <hook module="blockbestsellers" hook="actionOrderStatusPostUpdate" position="1"/>
            <hook module="blockbestsellers" hook="displayHomeTab" position="3"/>
            <hook module="blockbestsellers" hook="displayHomeTabContent" position="3"/>
            <hook module="blockcart" hook="displayHeader" position="4"/>
            <hook module="blockcart" hook="displayTop" position="2"/>
            <hook module="blockcart" hook="actionCartListOverride" position="1"/>
            <hook module="blocksocial" hook="displayHeader" position="5"/>
            <hook module="blocksocial" hook="displayFooter" position="1"/>
            <hook module="blockcategories" hook="displayLeftColumn" position="2"/>
            <hook module="blockcategories" hook="displayHeader" position="6"/>
            <!-- hook module="blockcategories" hook="displayFooter" position="3"/ -->
            <hook module="blockcategories" hook="actionCategoryAdd" position="1"/>
            <hook module="blockcategories" hook="actionCategoryUpdate" position="1"/>
            <hook module="blockcategories" hook="actionCategoryDelete" position="1"/>
            <hook module="blockcategories" hook="displayBackOfficeCategory" position="1"/>
            <hook module="blockcategories" hook="actionAdminMetaControllerUpdate_optionsBefore" position="1"/>
            <hook module="blockcategories" hook="actionAdminLanguagesControllerStatusBefore" position="1"/>
            <hook module="blockcurrencies" hook="displayHeader" position="7"/>
            <hook module="blockcurrencies" hook="displayNav" position="2"/>
            <hook module="blockfacebook" hook="displayHome" position="2"/>
            <hook module="blockfacebook" hook="displayHeader" position="8"/>
            <hook module="blocklanguages" hook="displayHeader" position="9"/>
            <hook module="blocklanguages" hook="displayNav" position="3"/>
            <hook module="blocklayered" hook="displayLeftColumn" position="3"/>
            <hook module="blocklayered" hook="displayHeader" position="10"/>
            <hook module="blocklayered" hook="actionCategoryAdd" position="2"/>
            <hook module="blocklayered" hook="actionCategoryUpdate" position="2"/>
            <hook module="blocklayered" hook="actionCategoryDelete" position="2"/>
            <hook module="blocklayered" hook="displayAttributeGroupForm" position="1"/>
            <hook module="blocklayered" hook="actionAttributeGroupSave" position="1"/>
            <hook module="blocklayered" hook="actionAttributeGroupDelete" position="1"/>
            <hook module="blocklayered" hook="displayFeatureForm" position="1"/>
            <hook module="blocklayered" hook="actionFeatureSave" position="1"/>
            <hook module="blocklayered" hook="actionFeatureDelete" position="1"/>
            <hook module="blocklayered" hook="actionProductSave" position="1"/>
            <hook module="blocklayered" hook="actionProductListOverride" position="1"/>
            <hook module="blocklayered" hook="displayAttributeGroupPostProcess" position="1"/>
            <hook module="blocklayered" hook="displayFeaturePostProcess" position="1"/>
            <hook module="blocklayered" hook="displayFeatureValueForm" position="1"/>
            <hook module="blocklayered" hook="displayFeatureValuePostProcess" position="1"/>
            <hook module="blocklayered" hook="actionFeatureValueDelete" position="1"/>
            <hook module="blocklayered" hook="actionFeatureValueSave" position="1"/>
            <hook module="blocklayered" hook="displayAttributeForm" position="1"/>
            <hook module="blocklayered" hook="actionAttributePostProcess" position="1"/>
            <hook module="blocklayered" hook="actionAttributeDelete" position="1"/>
            <hook module="blocklayered" hook="actionAttributeSave" position="1"/>
            <hook module="blockcms" hook="displayLeftColumn" position="4"/>
            <hook module="blockcms" hook="displayHeader" position="11"/>
            <hook module="blockcms" hook="displayFooter" position="3"/>
            <hook module="blockcms" hook="actionObjectCmsUpdateAfter" position="1"/>
            <hook module="blockcms" hook="actionObjectCmsDeleteAfter" position="1"/>
            <hook module="blockcms" hook="actionShopDataDuplication" position="1"/>
            <hook module="blockcms" hook="actionAdminStoresControllerUpdate_optionsAfter" position="1"/>
            <hook module="blockcmsinfo" hook="displayHome" position="3"/>
            <hook module="blockcontact" hook="displayHeader" position="12"/>
            <hook module="blockcontact" hook="displayNav" position="1"/>
            <hook module="blockcontactinfos" hook="displayHeader" position="13"/>
            <hook module="blockcontactinfos" hook="displayFooter" position="5"/>
            <hook module="blockmanufacturer" hook="displayLeftColumn" position="5" exceptions="category"/>
            <hook module="blockmanufacturer" hook="displayHeader" position="14"/>
            <hook module="blockmanufacturer" hook="actionObjectManufacturerDeleteAfter" position="1"/>
            <hook module="blockmanufacturer" hook="actionObjectManufacturerAddAfter" position="1"/>
            <hook module="blockmanufacturer" hook="actionObjectManufacturerUpdateAfter" position="1"/>
            <hook module="blockmyaccount" hook="displayLeftColumn" position="6" exceptions="category"/>
            <hook module="blockmyaccount" hook="displayHeader" position="15"/>
            <hook module="blockmyaccount" hook="actionModuleRegisterHookAfter" position="1"/>
            <hook module="blockmyaccount" hook="actionModuleUnRegisterHookAfter" position="1"/>
            <hook module="blockmyaccountfooter" hook="displayHeader" position="16"/>
            <hook module="blockmyaccountfooter" hook="displayFooter" position="4"/>
            <hook module="blockmyaccountfooter" hook="actionModuleRegisterHookAfter" position="2"/>
            <hook module="blockmyaccountfooter" hook="actionModuleUnRegisterHookAfter" position="2"/>
            <hook module="blocknewproducts" hook="displayLeftColumn" position="7"/>
            <hook module="blocknewproducts" hook="displayHeader" position="17"/>
            <hook module="blocknewproducts" hook="actionProductAdd" position="2"/>
            <hook module="blocknewproducts" hook="actionProductUpdate" position="2"/>
            <hook module="blocknewproducts" hook="actionProductDelete" position="2"/>
            <hook module="blocknewproducts" hook="displayHomeTab" position="1"/>
            <hook module="blocknewproducts" hook="displayHomeTabContent" position="1"/>
            <hook module="blocknewsletter" hook="displayHeader" position="18"/>
            <hook module="blocknewsletter" hook="displayFooter" position="2"/>
            <hook module="blocknewsletter" hook="actionCustomerAccountAdd" position="1"/>
            <hook module="blockpaymentlogo" hook="displayLeftColumn" position="8" exceptions="category"/>
            <hook module="blockpaymentlogo" hook="displayHeader" position="19"/>
            <hook module="blocksearch" hook="displayHeader" position="20"/>
            <hook module="blocksearch" hook="displayTop" position="1"/>
            <hook module="blocksearch" hook="displayMobileTopSiteMap" position="1"/>
            <hook module="blockspecials" hook="displayLeftColumn" position="9"/>
            <hook module="blockspecials" hook="displayHeader" position="21"/>
            <hook module="blockspecials" hook="actionProductAdd" position="3"/>
            <hook module="blockspecials" hook="actionProductUpdate" position="3"/>
            <hook module="blockspecials" hook="actionProductDelete" position="3"/>
            <hook module="blockstore" hook="displayLeftColumn" position="10"/>
            <hook module="blockstore" hook="displayHeader" position="22"/>
            <hook module="blocksupplier" hook="displayLeftColumn" position="11" exceptions="category"/>
            <hook module="blocksupplier" hook="displayHeader" position="23"/>
            <hook module="blocksupplier" hook="actionObjectSupplierDeleteAfter" position="1"/>
            <hook module="blocksupplier" hook="actionObjectSupplierAddAfter" position="1"/>
            <hook module="blocksupplier" hook="actionObjectSupplierUpdateAfter" position="1"/>
            <hook module="blocktags" hook="displayLeftColumn" position="12"/>
            <hook module="blocktags" hook="displayHeader" position="24"/>
            <hook module="blockuserinfo" hook="displayHeader" position="25"/>
            <hook module="blockuserinfo" hook="displayTop" position="4"/>
            <hook module="blockuserinfo" hook="displayNav" position="4"/>
            <hook module="blockviewed" hook="displayLeftColumn" position="13"/>
            <hook module="blockviewed" hook="displayHeader" position="26"/>
            <hook module="ctconfiguration" hook="displayHeader" position="35"/>
            <hook module="cttopmenu" hook="displayTop" position="3"/>
            <hook module="cttopmenu" hook="actionCategoryUpdate" position="3"/>
            <hook module="cttopmenu" hook="actionCTTopMenuCompositionChanged" position="1"/>
            <hook module="cttopmenu" hook="actionObjectProductUpdateAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectProductDeleteAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectCategoryUpdateAfter" position="1"/>
            <hook module="cttopmenu" hook="actionObjectCategoryDeleteAfter" position="1"/>
            <hook module="cttopmenu" hook="actionObjectCategoryAddAfter" position="1"/>
            <hook module="cttopmenu" hook="actionObjectCmsUpdateAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectCmsDeleteAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectCmsAddAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectCmsCategoryUpdateAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectCmsCategoryDeleteAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectCmsCategoryAddAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectSupplierDeleteAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectSupplierAddAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectSupplierUpdateAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectManufacturerDeleteAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectManufacturerAddAfter" position="2"/>
            <hook module="cttopmenu" hook="actionObjectManufacturerUpdateAfter" position="2"/>
            <hook module="cttopmenu" hook="displayHeader" position="34"/>
            <hook module="dashactivity" hook="dashboardZoneOne" position="1"/>
            <hook module="dashactivity" hook="dashboardData" position="1"/>
            <hook module="dashactivity" hook="actionObjectOrderAddAfter" position="1"/>
            <hook module="dashactivity" hook="actionObjectCustomerAddAfter" position="1"/>
            <hook module="dashactivity" hook="actionObjectCustomerMessageAddAfter" position="1"/>
            <hook module="dashactivity" hook="actionObjectCustomerThreadAddAfter" position="1"/>
            <hook module="dashactivity" hook="actionObjectOrderReturnAddAfter" position="1"/>
            <hook module="dashactivity" hook="actionAdminControllerSetMedia" position="1"/>
            <hook module="dashtrends" hook="actionOrderStatusPostUpdate" position="2"/>
            <hook module="dashtrends" hook="dashboardData" position="2"/>
            <hook module="dashtrends" hook="actionAdminControllerSetMedia" position="2"/>
            <hook module="dashtrends" hook="dashboardZoneTwo" position="1"/>
            <hook module="dashgoals" hook="dashboardData" position="3"/>
            <hook module="dashgoals" hook="actionAdminControllerSetMedia" position="3"/>
            <hook module="dashgoals" hook="dashboardZoneTwo" position="2"/>
            <hook module="dashproducts" hook="actionSearch" position="1"/>
            <hook module="dashproducts" hook="dashboardData" position="4"/>
            <hook module="dashproducts" hook="actionObjectOrderAddAfter" position="2"/>
            <hook module="dashproducts" hook="dashboardZoneTwo" position="3"/>
            <hook module="homeslider" hook="displayHeader" position="27"/>
            <hook module="homeslider" hook="displayTopColumn" position="1"/>
            <hook module="homeslider" hook="actionShopDataDuplication" position="3"/>
            <hook module="homefeatured" hook="displayHeader" position="28"/>
            <hook module="homefeatured" hook="actionProductAdd" position="4"/>
            <hook module="homefeatured" hook="actionProductUpdate" position="4"/>
            <hook module="homefeatured" hook="actionProductDelete" position="4"/>
            <hook module="homefeatured" hook="actionCategoryUpdate" position="4"/>
            <hook module="homefeatured" hook="displayHomeTab" position="2"/>
            <hook module="homefeatured" hook="displayHomeTabContent" position="2"/>
            <hook module="productpaymentlogos" hook="displayHeader" position="29"/>
            <hook module="productpaymentlogos" hook="displayProductButtons" position="2"/>
            <hook module="statsdata" hook="actionAuthentication" position="1"/>
            <hook module="statsdata" hook="displayFooter" position="6"/>
            <hook module="statsdata" hook="actionCustomerAccountAdd" position="2"/>
            <hook module="themeconfigurator" hook="displayLeftColumn" position="14"/>
            <hook module="themeconfigurator" hook="displayHome" position="1"/>
            <hook module="themeconfigurator" hook="displayHeader" position="30"/>
            <hook module="themeconfigurator" hook="displayFooter" position="7"/>
            <hook module="themeconfigurator" hook="displayBackOfficeHeader" position="1"/>
            <hook module="themeconfigurator" hook="displayTopColumn" position="2"/>
            <hook module="themeconfigurator" hook="actionObjectLanguageAddAfter" position="2"/>
            <hook module="blockwishlist" hook="displayHeader" position="31"/>
            <hook module="blockwishlist" hook="actionCartSave" position="1"/>
            <hook module="blockwishlist" hook="displayTop" position="7"/>
            <hook module="blockwishlist" hook="displayAdminCustomers" position="1"/>
            <hook module="blockwishlist" hook="displayCustomerAccount" position="1"/>
            <hook module="blockwishlist" hook="displayProductButtons" position="1"/>
            <hook module="blockwishlist" hook="displayMyAccountBlock" position="1"/>
            <hook module="blockwishlist" hook="displayProductListFunctionalButtons" position="1"/>
            <hook module="productcomments" hook="displayHeader" position="32"/>
            <hook module="productcomments" hook="displayRightColumnProduct" position="1"/>
            <hook module="productcomments" hook="displayProductTab" position="1"/>
            <hook module="productcomments" hook="displayProductTabContent" position="1"/>
            <hook module="productcomments" hook="displayProductComparison" position="1"/>
            <hook module="productcomments" hook="displayProductListReviews" position="1"/>
            <hook module="sendtoafriend" hook="displayHeader" position="33"/>
            <hook module="sendtoafriend" hook="displayLeftColumnProduct" position="1"/>
        </hooks>
    </modules>
    <images>
        <image name="cart_default" width="80" height="80" products="true" categories="false" manufacturers="false"
               suppliers="false" scenes="false"/>
        <image name="small_default" width="98" height="98" products="true" categories="false" manufacturers="true"
               suppliers="true" scenes="false"/>
        <image name="medium_default" width="125" height="125" products="true" categories="true" manufacturers="true"
               suppliers="true" scenes="false"/>
        <image name="home_default" width="250" height="250" products="true" categories="false" manufacturers="false"
               suppliers="false" scenes="false"/>
        <image name="large_default" width="458" height="458" products="true" categories="false" manufacturers="true"
               suppliers="true" scenes="false"/>
        <image name="thickbox_default" width="800" height="800" products="true" categories="false" manufacturers="false"
               suppliers="false" scenes="false"/>
        <image name="category_default" width="870" height="217" products="false" categories="true" manufacturers="false"
               suppliers="false" scenes="false"/>
        <image name="scene_default" width="870" height="270" products="false" categories="false" manufacturers="false"
               suppliers="false" scenes="true"/>
        <image name="m_scene_default" width="161" height="58" products="false" categories="false" manufacturers="false"
               suppliers="false" scenes="true"/>
    </images>
    <lazy_load>1</lazy_load>
    <high_dpi>1</high_dpi>
    <webp>1</webp>
</theme>
if ($ob) {
// convert SimpleXMLElement to array
return json_decode(json_encode($ob), true);
}
return [];
}

/**
* Get the configuration file as SimpleXMLElement
*
* @param boolean $validate - if true, configuration file will be validated
*
* @return SimpleXMLElement | false
*
* @since 1.0.7
*/
public function loadConfigFile($validate=false)
{
return static::loadConfigFromFile($this->getConfigFilePath(), $validate);
}


/**
* Get the path to configuration file
*
* @return string | false
*
* @since 1.0.7
*/
protected function getConfigFilePath()
{
$path = _PS_ROOT_DIR_.'/config/xml/themes/'.$this->directory.'.xml';
if (file_exists($path)) {
return $path;
}

if ($this->name == 'community-theme-default') {
$path = _PS_ROOT_DIR_.'/config/xml/themes/default.xml';
if (file_exists($path)) {
return $path;
}
}

return false;
}

/**
* Get the configuration file as SimpleXMLElement
*
* @param string $filePath - path to xml config file to load
* @param boolean $validate - if true, configuration file will be validated
*
* @return SimpleXMLElement | false
*
* @since 1.0.7
*/
public static function loadConfigFromFile($filePath, $validate)
{
if (file_exists($filePath)) {
$content = @simplexml_load_file($filePath);
if ($content && $validate && !static::validateConfigFile($content)) {
return false;
}
return $content;
}
return false;
}

$xmlfile = file_get_contents($target);
$ob = simplexml_load_string($xmlfile);
$json = json_encode($ob);
return json_decode($json, true);
/**
* Validate xml fields in config file
*
* @param SimpleXMLElement $xml
*
* @return boolean
*
* @since 1.0.7
*/
public static function validateConfigFile($xml)
{

This comment has been minimized.

Copy link
@getdatakick

getdatakick Sep 6, 2018

Author Contributor

moved from AdminThemesController::checkXmlFields

if (! $xml) {
return false;
}
if (!$xml['version'] || !$xml['name']) {
return false;
}
foreach ($xml->variations->variation as $val) {
if (!$val['name'] || !$val['directory'] || !$val['from'] || !$val['to']) {
return false;
}
}
foreach ($xml->modules->module as $val) {
if (!$val['action'] || !$val['name']) {
return false;
}
}
foreach ($xml->modules->hooks->hook as $val) {
if (!$val['module'] || !$val['hook'] || !$val['position']) {
return false;
}
}
return true;
}

}

0 comments on commit c745204

Please sign in to comment.