Esempio n. 1
0
        public ActionResult AddSnippet(string name, bool ismobile)
        {
            var handler = new ThemeHandler(MASTERdomain, ismobile);
            var dirs    = handler.GetThemeDirectory().GetDirectories("snippets");

            if (dirs.Length == 0)
            {
                return(new EmptyResult());
            }
            // try to get existing template
            // if none exist then create blank file
            var filename = string.Format("{0}.liquid", name);
            var dest     = Path.Combine(dirs[0].FullName, filename);

            // if destination file exist, then delete destination file
            if (System.IO.File.Exists(dest))
            {
                System.IO.File.Delete(dest);
            }

            System.IO.File.Create(dest).Dispose();

            var viewmodel = new LiquidFileContent(handler.GetThemeUrl(), string.Format("/snippets/{0}", filename));

            return(View("filecontent", viewmodel));
        }
Esempio n. 2
0
        public ActionResult FileContent(string path, bool ismobile)
        {
            var handler   = new ThemeHandler(MASTERdomain, ismobile);
            var root      = handler.GetThemeUrl();
            var viewmodel = new LiquidFileContent(root, path);

            return(View(viewmodel));
        }
Esempio n. 3
0
        public LiquidTemplateBase(MASTERsubdomain sd, bool isMobile)
        {
            parameters = new Hash();
            values     = new Hash();

            handler   = new ThemeHandler(sd, isMobile);
            themepath = handler.GetThemeUrl();

            AddFilterValues("asset_url", themepath);
            AddFilterValues("theme_version", isMobile? sd.theme.theme_mobile_version:sd.theme.theme_version);
        }
Esempio n. 4
0
        public ActionResult Export()
        {
            var handler = new ThemeHandler(MASTERdomain, false);

            var themedir = GeneralConstants.APP_ROOT_DIR + handler.GetThemeUrl();

            var ms = new MemoryStream();

            using (var s = new ZipOutputStream(ms))
            {
                s.SetLevel(9); // 0 - store only to 9 - means best compression
                handler.ZipFolder(themedir, themedir, s);
            }

            return(File(ms.ToArray(), "application/zip", string.Format("TradelrTheme_{0}_{1}.zip", MASTERdomain.theme.title, DateTime.UtcNow.ToShortDateString())));
        }
Esempio n. 5
0
        public ActionResult Save(ThemeChangesJSON changes)
        {
            var handler = new ThemeHandler(MASTERdomain, changes.ismobile);
            var root    = handler.GetThemeUrl();

            for (var i = 0; i < changes.names.Length; i++)
            {
                var path    = changes.names[i];
                var content = HttpUtility.UrlDecode(changes.contents[i]);
                try
                {
                    var filepath = string.Format("{0}/{1}", root, path);
                    var file     = new FileInfo(GeneralConstants.APP_ROOT_DIR + filepath);
                    using (var writer = file.CreateText())
                    {
                        writer.Write(content);
                    }
                    // invalidate cache for liquid files (usually .css and .js)
                    if (filepath.EndsWith(".liquid"))
                    {
                        var filename = Path.GetFileName(filepath);
                        var cachekey = ThemeHandler.GetCacheKey(MASTERdomain.uniqueid, filename, changes.ismobile);
                        CacheHelper.Instance.Remove(CacheItemType.liquid_assets, cachekey);
                    }
                }
                catch (Exception ex)
                {
                    Syslog.Write(ex);
                }
            }

            // update theme versions
            var version = DateTime.UtcNow.Ticks.ToString("x");

            if (changes.ismobile)
            {
                MASTERdomain.theme.theme_mobile_version = version;
            }
            else
            {
                MASTERdomain.theme.theme_version = version;
            }

            repository.Save();

            return(Json("Changes saved successfully".ToJsonOKMessage()));
        }
Esempio n. 6
0
        public ActionResult DeleteFile(string path, bool ismobile)
        {
            var handler = new ThemeHandler(MASTERdomain, ismobile);
            var file    = string.Format("{0}{1}{2}", GeneralConstants.APP_ROOT_DIR, handler.GetThemeUrl(), path);

            // prevent critical files from being deleted
            if (CriticalThemeFiles.Contains(path))
            {
                return(Json("Unable to delete critical theme files".ToJsonFail()));
            }

            try
            {
                System.IO.File.Delete(file);
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }
            return(Json("File deleted".ToJsonOKMessage()));
        }