diff options
author | Ted Trask <ttrask01@yahoo.com> | 2010-01-13 16:11:18 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2010-01-13 16:11:18 +0000 |
commit | 0eebb26c9594f1c92b13e412e6ad24857143c288 (patch) | |
tree | 40504cff2acf2d0cfe97d4bea6d4194e3225f055 /app/acf-util/skins-model.lua | |
parent | fbf9492b39641f0eef99c66b728c5d37e9bed932 (diff) | |
download | acf-core-0eebb26c9594f1c92b13e412e6ad24857143c288.tar.bz2 acf-core-0eebb26c9594f1c92b13e412e6ad24857143c288.tar.xz |
Moved skins from acf-alpine-baselayout.
Diffstat (limited to 'app/acf-util/skins-model.lua')
-rw-r--r-- | app/acf-util/skins-model.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/acf-util/skins-model.lua b/app/acf-util/skins-model.lua new file mode 100644 index 0000000..8b5a57e --- /dev/null +++ b/app/acf-util/skins-model.lua @@ -0,0 +1,49 @@ +-- acf model for displaying logfiles recusivly +module (..., package.seeall) + +require("fs") +require("format") + +local function set_skins(self, skin) + local content = "\n"..(fs.read_file(self.conf.conffile) or "") + local count + content,count = string.gsub(content, "\n%s*skin%s*=[^\n]*", "\nskin="..format.escapespecialcharacters(skin)) + if count == 0 then + content = "\nskin="..format.escapespecialcharacters(skin)..content + end + fs.write_file(self.conf.conffile, string.sub(content,2)) + local cmdoutput = "New skin selected" + return cmdoutput, errtxt +end + +local function list_skins(self) + local skinarray = {} + for i,file in ipairs(posix.dir(self.conf.wwwdir ..self.conf.skindir) or {}) do + -- Ignore files that begins with a '.' and 'cgi-bin' and only list folders + if not ((string.match(file, "^%.")) or (string.match(file, "^cgi[-]bin")) or (string.match(file, "^static")) or (posix.stat(self.conf.wwwdir .. self.conf.skindir .. file).type ~= "directory")) then + local entry = cfe({ value=file, label="Skin name" }) + local current = conf.skin + entry.inuse = (file == current) + table.insert(skinarray, entry) + end + end + return cfe({ type="list", value=skinarray, label="Skins" }) +end + + +get = function (self) + return list_skins(self) +end + +update = function (self, newskin) + -- Make sure no one can inject code into the model. + local availableskins = list_skins(self) + local cmdoutput = "Failed to set skin" + local errtxt = "Invalid selection" + for i,skin in ipairs(availableskins.value) do + if ( skin.value == newskin) then + cmdoutput, errtxt = set_skins(self, newskin) + end + end + return cfe({ value=cmdoutput, errtxt=errtxt, label="Set skin result" }) +end |