/** * Adds theme data (GUID, icon, preview image) to a style if in debug mode. (used by update & insert) * * @param string $guid Theme GUID * @param binary $icon Theme icon * @param boolean $iconRemove Whether to remove the current icon (if there is one, and we're not uploading a new one) * @param binary $previewImage Theme preview image * @param boolean $previewImageRemove Whether to remove the current preview image (if there is one, and we're not uploading a new one) */ protected function addThemeData($dostyleid, $guid, $icon, $iconRemove, $previewImage, $previewImageRemove) { $config = vB::getConfig(); if (empty($config['Misc']['debug'])) { // only modify theme information in debug mode. return; } $style = $this->library->fetchStyleByID($dostyleid); $themeImporter = new vB_Xml_Import_Theme(); $updateValues = array(); // ----- GUID ----- if (!empty($guid)) { $updateValues['guid'] = $guid; } else { $updateValues['guid'] = vB_dB_Query::VALUE_ISNULL; } // ----- Icon ----- if (!empty($icon)) { // upload it & get a filedataid $filedataid = $themeImporter->uploadThemeImageData($icon); if ($filedataid > 0 and $filedataid != $style['filedataid']) { $updateValues['filedataid'] = $filedataid; } } if ($style['filedataid'] > 0 and ($iconRemove or !empty($updateValues['filedataid']))) { // remove previous icon (if there was one and they checked 'remove' or if there was one and we just uploaded a new one) vB::getDbAssertor()->assertQuery('decrementFiledataRefcount', array('filedataid' => $style['filedataid'])); // set icon to blank if we don't have a new one if (empty($updateValues['filedataid'])) { $updateValues['filedataid'] = 0; } } // ----- Preview Image ----- if (!empty($previewImage)) { // upload it & get a previewfiledataid $previewfiledataid = $themeImporter->uploadThemeImageData($previewImage); if ($previewfiledataid > 0 and $previewfiledataid != $style['previewfiledataid']) { $updateValues['previewfiledataid'] = $previewfiledataid; } } if ($style['previewfiledataid'] > 0 and ($previewImageRemove or !empty($updateValues['previewfiledataid']))) { // remove previous preview image (if there was one and they checked 'remove' or if there was one and we just uploaded a new one) vB::getDbAssertor()->assertQuery('decrementFiledataRefcount', array('filedataid' => $style['previewfiledataid'])); // set preview image to blank if we don't have a new one if (empty($updateValues['previewfiledataid'])) { $updateValues['previewfiledataid'] = 0; } } // save if (!empty($updateValues)) { vB::getDbAssertor()->update('style', $updateValues, array('styleid' => $dostyleid)); } }