/** * Adds a Flexiskin defined by data via request parameter * @return String encoded result JSON string */ public function addFlexiskin() { $aData = FormatJson::decode($this->getMain()->getVal('data', "")); $oData = $aData[0]; if (is_null($oData->template)) { return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-templatenotexists')->plain())); } if (empty($oData->template)) { $oData->template = 'default'; } $sId = str_replace(" ", "_", strtolower($oData->name)); $sFlexiskinPath = BsFileSystemHelper::getDataDirectory('flexiskin' . DS . md5($sId)); if (is_dir($sFlexiskinPath)) { return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-skinexists')->plain())); } //PW(27.11.2013) TODO: add check template really exists before add if (empty($oData->name)) { //PW(27.11.2013) TODO: add msg return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-nameempty')->plain())); } if ($oData->template != 'default') { $oConfig = $this->getConfigFromId($oData->template); if (!$oConfig->isGood()) { return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-templatenotexists')->plain())); } $oConf = FormatJson::decode($oConfig->getValue()); $oConf[0]->name = $oData->name; $oConf[0]->desc = $oData->desc; $sConfigFile = FormatJson::encode($oConf); } else { $sConfigFile = Flexiskin::generateConfigFile($oData); } $oStatus = BsFileSystemHelper::saveToDataDirectory('conf.json', $sConfigFile, "flexiskin" . DS . md5($sId)); if (!$oStatus->isGood()) { return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-fail-add-skin', $this->getErrorMessage($oStatus))->plain())); } if ($oData->template != 'default') { $oStatus = BsFileSystemHelper::copyFile('variables.less', "flexiskin" . DS . $oData->template, "flexiskin" . DS . md5($sId)); $oStatus = BsFileSystemHelper::copyFolder("images", "flexiskin" . DS . $oData->template, "flexiskin" . DS . md5($sId)); } else { $oStatus = BsFileSystemHelper::saveToDataDirectory('variables.less', Flexiskin::generateStyleFile($sConfigFile), "flexiskin" . DS . md5($sId)); } $oStatus = BsFileSystemHelper::saveToDataDirectory('screen.less', Flexiskin::generateScreenFile(), "flexiskin" . DS . md5($sId)); $oStatus = BsFileSystemHelper::saveToDataDirectory('screen.tmp.less', Flexiskin::generateScreenFile(true), "flexiskin" . DS . md5($sId)); //tbd: check 1st, 2nd and 3rd status if (!$oStatus->isGood()) { return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-fail-add-skin', $this->getErrorMessage($oStatus))->plain())); } BsFileSystemHelper::ensureDataDirectory("flexiskin" . DS . md5($sId) . DS . "images"); return FormatJson::encode(array('success' => true)); }
/** * Replaces the BlueSpiceSkin screen.less file with the one specified by the parameters * @global string $wgResourceModules * @param string $sFlexiskinId * @param int $bIsTemp * @return boolean true of replaced correctly, otherwise false */ public function addCssFile($sFlexiskinId, $bIsTemp = false) { global $wgResourceModules; $oStatus = BsFileSystemHelper::ensureDataDirectory("flexiskin/" . $sFlexiskinId); if (!$oStatus->isGood()) { return false; } $sFilePath = BsFileSystemHelper::getDataPath("flexiskin/" . $sFlexiskinId); $sFilePath .= "/screen" . ($bIsTemp ? '.tmp' : '') . ".less"; if (!isset($wgResourceModules['skins.bluespiceskin']) || !isset($wgResourceModules['skins.bluespiceskin']['styles'])) { return false; } foreach ($wgResourceModules['skins.bluespiceskin']['styles'] as $iIndex => $sStylePath) { //check if element ends with "screen.less" if (strpos($sStylePath, "screen.less", strlen($sStylePath) - strlen("screen.less")) === false) { continue; } $wgResourceModules['skins.bluespiceskin']['styles'][$iIndex] = ".." . $sFilePath; return true; } return false; }