Beispiel #1
0
        private string SaveImages(string content)
        {
            var originalImageSrcs = RegexUtils.GetOriginalImageSrcs(content);

            foreach (var originalImageSrc in originalImageSrcs)
            {
                if (!PageUtils.IsProtocolUrl(originalImageSrc))
                {
                    continue;
                }

                var extName = "png";
                if (StringUtils.Contains(originalImageSrc, "wx_fmt="))
                {
                    extName = originalImageSrc.Substring(originalImageSrc.LastIndexOf("=", StringComparison.Ordinal) + 1);
                }

                var materialFileName     = PathUtils.GetMaterialFileNameByExtName(extName);
                var virtualDirectoryPath = PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Image);

                var directoryPath = PathUtils.Combine(_settingsManager.WebRootPath, virtualDirectoryPath);
                var filePath      = PathUtils.Combine(directoryPath, materialFileName);

                WebClientUtils.Download(originalImageSrc, filePath);

                var imageUrl = PageUtils.Combine(virtualDirectoryPath, materialFileName);

                content = content.Replace(" data-src=", "src=");
                content = content.Replace(originalImageSrc, imageUrl);
            }
            return(content);
        }
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("PublishmentSystemID");
            returnUrl = StringUtils.ValueFromUrl(GetQueryString("returnUrl"));

            if (!IsPostBack)
            {
                //base.BreadCrumbConsole(AppManager.CMS.LeftMenu.ID_Site, "绑定微信公众帐号", AppManager.Permission.Platform_Site);


                #region 确认绑定接口没有问题
                if (!IsNet45OrNewer())
                {
                    FailMessage("请检查是否安装了.NET Framework 4.5以上版本");
                    return;
                }

                var hostUrl = PageUtils.GetHost();
                if (hostUrl.IndexOf(":") >= 0)
                {
                    var port = hostUrl.Split(new char[] { ':' })[1];
                    if (port != "80")
                    {
                        FailMessage("请检查站点是否设置为80端口");
                        return;
                    }
                }

                var testUrl = PageUtils.AddProtocolToUrl("/api/mp/url?id=1");
                var result  = string.Empty;
                WebClientUtils.Post(testUrl, string.Empty, out result);
                if (!StringUtils.EqualsIgnoreCase(result, "failed:id=1") && !StringUtils.EqualsIgnoreCase(result, "参数错误"))
                {
                    FailMessage("绑定微信公众账号需要的api有问题! 详细错误信息:" + result);
                    return;
                }


                #endregion

                var accountInfo = WeiXinManager.GetAccountInfo(PublishmentSystemID);

                EWXAccountTypeUtils.AddListItems(rblWXAccountType);
                ControlUtils.SelectListItems(rblWXAccountType, EWXAccountTypeUtils.GetValue(EWXAccountTypeUtils.GetEnumType(accountInfo.AccountType)));

                tbWhchatID.Text = accountInfo.WeChatID;

                ltlURL.Text = PageUtilityWX.API.GetMPUrl(PublishmentSystemID);

                ltlToken.Text = accountInfo.Token;

                tbAppID.Text     = accountInfo.AppID;
                tbAppSecret.Text = accountInfo.AppSecret;
            }
        }
Beispiel #3
0
        public static SeoMetaInfo GetSeoMetaInfo(string siteUrl, ECharset charset)
        {
            siteUrl = PageUtils.AddProtocolToUrl(siteUrl);
            var content = WebClientUtils.GetRemoteFileSource(siteUrl, charset);

            return(GetSeoMetaInfo(content));
        }
Beispiel #4
0
        public static Object search(Object o)
        {
            try
            {
                Hashtable param = (Hashtable)o;

                EngineEntity engine = (EngineEntity)param["engine"];

                engine.Status = "处理中";

                String searchKey = HttpUtility.UrlEncode((String)param["searchKey"], Encoding.UTF8);

                IEngine search = engine.Search;

                Dictionary <String, String> urlMap = new Dictionary <String, String>();

                Int32 timeout = Convert.ToInt32(ConfigService.get("parse.request.timeout")) * 1000;

                String html = String.Empty;

                Int32 unParseURL = 0;

                //出错50次算结束,连续5次没抓到邮箱算结束,大于设置最大邮箱数算结束
                while (!search.isEndPage(html, engine) && engine.PageCnt <= engine.MaxPageCnt && engine.ErrorCnt < 50 && unParseURL < 5)
                {
                    String url = search.getPageUrl(html, engine, searchKey);

                    try
                    {
                        html = WebClientUtils.getHTML(url, timeout);

                        if (!String.Empty.Equals(html))
                        {
                            if (search.addUrl(CommonUtils.getHTMLinkArray(url, html), engine) == 0)
                            {
                                unParseURL++;
                            }
                            else
                            {
                                unParseURL = 0;
                            }
                        }

                        engine.PageCnt = engine.PageCnt + 1;
                    }
                    catch (Exception ex)
                    {
                        engine.ErrorCnt = engine.ErrorCnt + 1;
                        search.error(engine, ex);
                        html = String.Empty;
                    }
                }

                engine.Status = "处理结束";
            }
            catch { }

            return(null);
        }
Beispiel #5
0
        public NameValueCollection CreateSiteByOnlineTemplateName(int siteId, bool isImportContents, bool isImportTableStyles, string onlineTemplateName, string onlineTemplateUrl, string userKeyPrefix, string administratorName)
        {
            var cacheTotalCountKey   = userKeyPrefix + CacheTotalCount;
            var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount;
            var cacheMessageKey      = userKeyPrefix + CacheMessage;

            CacheUtils.Insert(cacheTotalCountKey, "4");       //存储需要的页面总数
            CacheUtils.Insert(cacheCurrentCountKey, "0");     //存储当前的页面总数
            CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息

            //返回“运行结果”、“错误信息”及“执行JS脚本”的字符串数组
            NameValueCollection retval;

            try
            {
                CacheUtils.Insert(cacheCurrentCountKey, "1");
                CacheUtils.Insert(cacheMessageKey, "开始下载模板压缩包,可能需要几分钟,请耐心等待...");

                var filePath = PathUtility.GetSiteTemplatesPath($"T_{onlineTemplateName}.zip");
                FileUtils.DeleteFileIfExists(filePath);
                //var downloadUrl = OnlineTemplateManager.GetDownloadUrl(onlineTemplateName);
                var downloadUrl = OnlineTemplateManager.GetDownloadUrlByUrl(onlineTemplateUrl);
                WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath);

                CacheUtils.Insert(cacheCurrentCountKey, "2");
                CacheUtils.Insert(cacheMessageKey, "模板压缩包下载成功,开始解压缩,可能需要几分钟,请耐心等待...");

                var siteTemplateDir = $"T_{onlineTemplateName}";
                var directoryPath   = PathUtility.GetSiteTemplatesPath(siteTemplateDir);
                DirectoryUtils.DeleteDirectoryIfExists(directoryPath);
                ZipUtils.ExtractZip(filePath, directoryPath);

                CacheUtils.Insert(cacheCurrentCountKey, "3");              //存储当前的页面总数
                CacheUtils.Insert(cacheMessageKey, "模板压缩包解压成功,正在导入数据..."); //存储消息

                SiteTemplateManager.Instance.ImportSiteTemplateToEmptySite(siteId, siteTemplateDir, isImportContents, isImportTableStyles, administratorName);
                CreateManager.CreateByAll(siteId);

                CacheUtils.Insert(cacheCurrentCountKey, "4"); //存储当前的页面总数
                CacheUtils.Insert(cacheMessageKey, "创建成功!");  //存储消息

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                retval = AjaxManager.GetWaitingTaskNameValueCollection($"站点 <strong>{siteInfo.SiteName}<strong> 创建成功!", string.Empty,
                                                                       $"top.location.href='{PageUtils.GetMainUrl(siteId)}';");
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty);
                LogUtils.AddErrorLog(ex);
            }

            CacheUtils.Remove(cacheTotalCountKey);   //取消存储需要的页面总数
            CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数
            CacheUtils.Remove(cacheMessageKey);      //取消存储消息
            CacheUtils.ClearAll();

            return(retval);
        }
Beispiel #6
0
        //private const string NuGetPackageSource = "https://packages.nuget.org/api/v2";
        //private const string MyGetPackageSource = "https://www.myget.org/F/siteserver/api/v2";

        //public static bool FindLastPackage(string packageId, out string title, out string version, out DateTimeOffset? published, out string releaseNotes)
        //{
        //    title = string.Empty;
        //    version = string.Empty;
        //    published = null;
        //    releaseNotes = string.Empty;

        //    try
        //    {
        //        var repo =
        //            PackageRepositoryFactory.Default.CreateRepository(WebConfigUtils.AllowNightlyBuild
        //                ? MyGetPackageSource
        //                : NuGetPackageSource);

        //        var package = repo.FindPackage(packageId);

        //        title = package.Title;
        //        version = package.Version.ToString();
        //        published = package.Published;
        //        releaseNotes = package.ReleaseNotes;

        //        return true;
        //    }
        //    catch (Exception)
        //    {
        //        // ignored
        //    }

        //    return false;
        //}

        public static void DownloadPackage(string packageId, string version)
        {
            var packagesPath  = PathUtils.GetPackagesPath();
            var idWithVersion = $"{packageId}.{version}";
            var directoryPath = PathUtils.Combine(packagesPath, idWithVersion);

            if (DirectoryUtils.IsDirectoryExists(directoryPath))
            {
                if (FileUtils.IsFileExists(PathUtils.Combine(directoryPath, $"{idWithVersion}.nupkg")) && FileUtils.IsFileExists(PathUtils.Combine(directoryPath, $"{packageId}.nuspec")))
                {
                    return;
                }
            }

            if (StringUtils.EqualsIgnoreCase(packageId, PackageIdSsCms))
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                var localFilePath = PathUtils.Combine(directoryPath, idWithVersion + ".nupkg");

                WebClientUtils.SaveRemoteFileToLocal(
                    $"http://api.siteserver.cn/downloads/update/{version}", localFilePath);

                ZipUtils.UnpackFiles(localFilePath, directoryPath);
            }
            else
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                var localFilePath = PathUtils.Combine(directoryPath, idWithVersion + ".nupkg");

                WebClientUtils.SaveRemoteFileToLocal(
                    $"http://api.siteserver.cn/downloads/package/{packageId}/{version}", localFilePath);

                ZipUtils.UnpackFiles(localFilePath, directoryPath);

                //var repo = PackageRepositoryFactory.Default.CreateRepository(WebConfigUtils.IsNightlyUpdate
                //? MyGetPackageSource
                //: NuGetPackageSource);

                //var packageManager = new PackageManager(repo, packagesPath);

                ////Download and unzip the package
                //packageManager.InstallPackage(packageId, SemanticVersion.Parse(version), true, WebConfigUtils.IsNightlyUpdate);
            }

            //ZipUtils.UnpackFilesByExtension(PathUtils.Combine(directoryPath, idWithVersion + ".nupkg"),
            //    directoryPath, ".nuspec");
        }
Beispiel #7
0
        public NameValueCollection SiteTemplateDownload(string downloadUrl, string directoryName, string userKeyPrefix)
        {
            var cacheTotalCountKey   = userKeyPrefix + CacheTotalCount;
            var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount;
            var cacheMessageKey      = userKeyPrefix + CacheMessage;

            CacheUtils.Insert(cacheTotalCountKey, "5");       //存储需要的页面总数
            CacheUtils.Insert(cacheCurrentCountKey, "0");     //存储当前的页面总数
            CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息

            //返回“运行结果”和“错误信息”的字符串数组
            NameValueCollection retval;

            try
            {
                CacheUtils.Insert(cacheCurrentCountKey, "1");
                CacheUtils.Insert(cacheMessageKey, "开始下载模板压缩包,可能需要几分钟,请耐心等待");

                var filePath = PathUtility.GetSiteTemplatesPath(directoryName + ".zip");
                FileUtils.DeleteFileIfExists(filePath);
                WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath);

                CacheUtils.Insert(cacheCurrentCountKey, "4");
                CacheUtils.Insert(cacheMessageKey, "模板压缩包下载成功,开始解压缩");

                var directoryPath = PathUtility.GetSiteTemplatesPath(directoryName);
                if (!DirectoryUtils.IsDirectoryExists(directoryPath))
                {
                    ZipUtils.UnpackFiles(filePath, directoryPath);
                }

                CacheUtils.Insert(cacheCurrentCountKey, "5");
                CacheUtils.Insert(cacheMessageKey, string.Empty);

                retval = AjaxManager.GetProgressTaskNameValueCollection("站点模板下载成功,请到站点模板管理中查看。", string.Empty);
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetProgressTaskNameValueCollection(string.Empty,
                                                                        $@"<br />下载失败!<br />{ex.Message}");
            }

            CacheUtils.Remove(cacheTotalCountKey);   //取消存储需要的页面总数
            CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数
            CacheUtils.Remove(cacheMessageKey);      //取消存储消息

            return(retval);
        }
Beispiel #8
0
        public override void error(EngineEntity entity, Exception ex)
        {
            try
            {
                if (ex.GetType() == typeof(WebException))
                {
                    WebException exception = (WebException)ex;

                    //exception.Response
                    String html = WebClientUtils.getResponseHTML((HttpWebResponse)exception.Response);

                    //得到image路径
                    String imagepath = String.Empty;
                    foreach (String url in CommonUtils.getHTMLinkArray(entity.Url, html))
                    {
                        if (url.IndexOf("/sorry/image") > -1)
                        {
                            imagepath = url;
                            break;
                        }
                    }

                    HttpWebResponse response = null;

                    try
                    {
                        response = WebClientUtils.request(imagepath, 60000);

                        captchaForm.tb_captcha.Text  = String.Empty;
                        captchaForm.pb_captcha.Image = Image.FromStream(response.GetResponseStream());
                        captchaForm.ShowDialog();
                    }
                    finally
                    {
                        if (response != null)
                        {
                            response.Close();
                        }
                    }

                    String id = imagepath.Substring(imagepath.IndexOf("id=") + 3, imagepath.IndexOf("&") - imagepath.IndexOf("id=") - 3);

                    WebClientUtils.request("http://www.google.com.hk/sorry/Captcha?id=" + id + "&captcha=" + Convert.ToString(captchaForm.Tag), 60000);
                }
            }
            catch { }
        }
Beispiel #9
0
        public NameValueCollection PluginDownload(string downloadUrl, string userKeyPrefix)
        {
            var cacheTotalCountKey   = userKeyPrefix + CacheTotalCount;
            var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount;
            var cacheMessageKey      = userKeyPrefix + CacheMessage;

            CacheUtils.Insert(cacheTotalCountKey, "5");       //存储需要的页面总数
            CacheUtils.Insert(cacheCurrentCountKey, "0");     //存储当前的页面总数
            CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息

            //返回“运行结果”和“错误信息”的字符串数组
            NameValueCollection retval;

            try
            {
                CacheUtils.Insert(cacheCurrentCountKey, "1");
                CacheUtils.Insert(cacheMessageKey, "开始下载插件压缩包,可能需要几分钟,请耐心等待");

                var fileName = PageUtils.GetFileNameFromUrl(downloadUrl);
                var filePath = PathUtils.GetPluginPath(fileName);
                FileUtils.DeleteFileIfExists(filePath);
                WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath);

                CacheUtils.Insert(cacheCurrentCountKey, "4");
                CacheUtils.Insert(cacheMessageKey, "插件压缩包下载成功,开始安装");

                ZipUtils.UnpackFiles(filePath, PathUtils.GetPluginPath(fileName.Substring(0, fileName.IndexOf(".", StringComparison.Ordinal))));

                CacheUtils.Insert(cacheCurrentCountKey, "5");
                CacheUtils.Insert(cacheMessageKey, string.Empty);

                retval = AjaxManager.GetProgressTaskNameValueCollection("插件安装成功,请刷新页面查看。", string.Empty);
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetProgressTaskNameValueCollection(string.Empty,
                                                                        $@"<br />下载失败!<br />{ex.Message}");
            }

            CacheUtils.Remove(cacheTotalCountKey);   //取消存储需要的页面总数
            CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数
            CacheUtils.Remove(cacheMessageKey);      //取消存储消息

            return(retval);
        }
        //将编辑器中图片上传至本机
        public static string SaveImage(SiteInfo siteInfo, string content)
        {
            var originalImageSrcs = RegexUtils.GetOriginalImageSrcs(content);

            foreach (var originalImageSrc in originalImageSrcs)
            {
                if (!PageUtils.IsProtocolUrl(originalImageSrc) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, PageUtils.ApplicationPath) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, siteInfo.Additional.WebUrl))
                {
                    continue;
                }
                var fileExtName = PageUtils.GetExtensionFromUrl(originalImageSrc);
                if (!EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    continue;
                }

                var fileName      = GetUploadFileName(siteInfo, originalImageSrc);
                var directoryPath = GetUploadDirectoryPath(siteInfo, fileExtName);
                var filePath      = PathUtils.Combine(directoryPath, fileName);

                try
                {
                    if (!FileUtils.IsFileExists(filePath))
                    {
                        WebClientUtils.SaveRemoteFileToLocal(originalImageSrc, filePath);
                        if (EFileSystemTypeUtils.IsImage(PathUtils.GetExtension(fileName)))
                        {
                            FileUtility.AddWaterMark(siteInfo, filePath);
                        }
                    }
                    var fileUrl = PageUtility.GetSiteUrlByPhysicalPath(siteInfo, filePath, true);
                    content = content.Replace(originalImageSrc, fileUrl);
                }
                catch
                {
                    // ignored
                }
            }
            return(content);
        }
Beispiel #11
0
        public static Object run(Object o)
        {
            try
            {
                Hashtable param = o as Hashtable;

                String url = Convert.ToString(param["url"]);

                try
                {
                    String keyword = (String)param["type"];

                    parseService.changeStatus(url, Constant.ParseStatus.START);

                    //如果RUNTIME的状态为STOP,则不再解析
                    if (!Constant.RunStatus.STOP.Equals(runtimeSerivce.get(url).RunStatus))
                    {
                        String html = WebClientUtils.getHTML(url, Convert.ToInt32(ConfigService.get("parse.request.timeout")) * 1000);

                        if (!"".Equals(html))
                        {
                            spiderURL(html, url, keyword);
                            spiderMail(html, keyword, url);
                        }
                    }

                    parseService.changeStatus(url, Constant.ParseStatus.SUCCESS);
                }
                catch
                {
                    parseService.changeStatus(url, Constant.ParseStatus.EXCEPTION);
                }
            }
            catch (Exception ex) { logger.Error(ex.Message, ex); }

            return(null);
        }
Beispiel #12
0
 /// <summary>
 /// post 上传文件
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="url"></param>
 /// <param name="o"></param>
 /// <param name="files"></param>
 /// <returns></returns>
 public T PostFilesJson <T>(string url, object o, List <string> files)
 {
     return(WebClientUtils.PostFilesJson <T>(address + url, o, files));
 }
Beispiel #13
0
        public async Task PullMaterialAsync(string accessTokenOrAppId, MaterialType materialType, int groupId)
        {
            var count = await MediaApi.GetMediaCountAsync(accessTokenOrAppId);

            if (materialType == MaterialType.Message)
            {
                if (count.news_count > 0)
                {
                    var newsList = await MediaApi.GetNewsMediaListAsync(accessTokenOrAppId, 0, count.news_count);

                    newsList.item.Reverse();

                    foreach (var message in newsList.item)
                    {
                        if (await _materialMessageRepository.IsExistsAsync(message.media_id))
                        {
                            continue;
                        }

                        //var news = await MediaApi.GetForeverNewsAsync(accessTokenOrAppId, message.media_id);
                        var messageItems = new List <MaterialMessageItem>();
                        foreach (var item in message.content.news_item)
                        {
                            var imageUrl = string.Empty;
                            if (!string.IsNullOrEmpty(item.thumb_media_id) && !string.IsNullOrEmpty(item.thumb_url))
                            {
                                await using var ms = new MemoryStream();
                                await MediaApi.GetForeverMediaAsync(accessTokenOrAppId, item.thumb_media_id, ms);

                                ms.Seek(0, SeekOrigin.Begin);

                                var extName = "png";
                                if (StringUtils.Contains(item.thumb_url, "wx_fmt="))
                                {
                                    extName = item.thumb_url.Substring(item.thumb_url.LastIndexOf("=", StringComparison.Ordinal) + 1);
                                }

                                var materialFileName     = PathUtils.GetMaterialFileNameByExtName(extName);
                                var virtualDirectoryPath = PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Image);

                                var directoryPath = PathUtils.Combine(_settingsManager.WebRootPath, virtualDirectoryPath);
                                var filePath      = PathUtils.Combine(directoryPath, materialFileName);

                                await FileUtils.WriteStreamAsync(filePath, ms);

                                imageUrl = PageUtils.Combine(virtualDirectoryPath, materialFileName);
                            }
                            else if (!string.IsNullOrEmpty(item.thumb_url))
                            {
                                var extName = "png";
                                if (StringUtils.Contains(item.thumb_url, "wx_fmt="))
                                {
                                    extName = item.thumb_url.Substring(item.thumb_url.LastIndexOf("=", StringComparison.Ordinal) + 1);
                                }

                                var materialFileName     = PathUtils.GetMaterialFileNameByExtName(extName);
                                var virtualDirectoryPath = PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Image);

                                var directoryPath = PathUtils.Combine(_settingsManager.WebRootPath, virtualDirectoryPath);
                                var filePath      = PathUtils.Combine(directoryPath, materialFileName);

                                WebClientUtils.Download(item.thumb_url, filePath);

                                imageUrl = PageUtils.Combine(virtualDirectoryPath, materialFileName);
                            }

                            var commentType = CommentType.Block;
                            if (item.need_open_comment == 1)
                            {
                                commentType = item.only_fans_can_comment == 1 ? CommentType.OnlyFans : CommentType.Everyone;
                            }

                            messageItems.Add(new MaterialMessageItem
                            {
                                MessageId        = 0,
                                MaterialType     = MaterialType.Article,
                                MaterialId       = 0,
                                Taxis            = 0,
                                ThumbMediaId     = item.thumb_media_id,
                                Author           = item.author,
                                Title            = item.title,
                                ContentSourceUrl = item.content_source_url,
                                Content          = SaveImages(item.content),
                                Digest           = item.digest,
                                ShowCoverPic     = item.show_cover_pic == "1",
                                ThumbUrl         = imageUrl,
                                Url         = item.url,
                                CommentType = commentType
                            });
                        }

                        await _materialMessageRepository.InsertAsync(groupId, message.media_id, messageItems);
                    }
                }
            }
            else if (materialType == MaterialType.Image)
            {
                if (count.image_count > 0)
                {
                    var list = await MediaApi.GetOthersMediaListAsync(accessTokenOrAppId, UploadMediaFileType.image, 0, count.image_count);

                    foreach (var image in list.item)
                    {
                        if (await _materialImageRepository.IsExistsAsync(image.media_id))
                        {
                            continue;
                        }

                        await using var ms = new MemoryStream();
                        await MediaApi.GetForeverMediaAsync(accessTokenOrAppId, image.media_id, ms);

                        ms.Seek(0, SeekOrigin.Begin);

                        var extName = image.url.Substring(image.url.LastIndexOf("=", StringComparison.Ordinal) + 1);

                        var materialFileName     = PathUtils.GetMaterialFileNameByExtName(extName);
                        var virtualDirectoryPath = PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Image);

                        var directoryPath = PathUtils.Combine(_settingsManager.WebRootPath, virtualDirectoryPath);
                        var filePath      = PathUtils.Combine(directoryPath, materialFileName);

                        await FileUtils.WriteStreamAsync(filePath, ms);

                        var material = new MaterialImage
                        {
                            GroupId = groupId,
                            Title   = image.name,
                            Url     = PageUtils.Combine(virtualDirectoryPath, materialFileName),
                            MediaId = image.media_id
                        };

                        await _materialImageRepository.InsertAsync(material);
                    }
                }
            }
            else if (materialType == MaterialType.Audio)
            {
                if (count.voice_count > 0)
                {
                    var list = await MediaApi.GetOthersMediaListAsync(accessTokenOrAppId, UploadMediaFileType.voice, 0, count.voice_count);

                    foreach (var voice in list.item)
                    {
                        if (await _materialAudioRepository.IsExistsAsync(voice.media_id))
                        {
                            continue;
                        }

                        await using var ms = new MemoryStream();
                        await MediaApi.GetForeverMediaAsync(accessTokenOrAppId, voice.media_id, ms);

                        ms.Seek(0, SeekOrigin.Begin);

                        var extName = voice.url.Substring(voice.url.LastIndexOf("=", StringComparison.Ordinal) + 1);

                        var materialFileName     = PathUtils.GetMaterialFileNameByExtName(extName);
                        var virtualDirectoryPath = PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Audio);

                        var directoryPath = PathUtils.Combine(_settingsManager.WebRootPath, virtualDirectoryPath);
                        var filePath      = PathUtils.Combine(directoryPath, materialFileName);

                        await FileUtils.WriteStreamAsync(filePath, ms);

                        var audio = new MaterialAudio
                        {
                            GroupId  = groupId,
                            Title    = voice.name,
                            FileType = extName.ToUpper().Replace(".", string.Empty),
                            Url      = PageUtils.Combine(virtualDirectoryPath, materialFileName),
                            MediaId  = voice.media_id
                        };

                        await _materialAudioRepository.InsertAsync(audio);
                    }
                }
            }
            else if (materialType == MaterialType.Video)
            {
                if (count.video_count > 0)
                {
                    var list = await MediaApi.GetOthersMediaListAsync(accessTokenOrAppId, UploadMediaFileType.video, 0, count.video_count);

                    foreach (var video in list.item)
                    {
                        if (await _materialVideoRepository.IsExistsAsync(video.media_id))
                        {
                            continue;
                        }

                        await using var ms = new MemoryStream();
                        await MediaApi.GetForeverMediaAsync(accessTokenOrAppId, video.media_id, ms);

                        ms.Seek(0, SeekOrigin.Begin);

                        var extName = "mp4";

                        if (!string.IsNullOrEmpty(video.url))
                        {
                            extName = video.url.Substring(video.url.LastIndexOf("=", StringComparison.Ordinal) + 1);
                        }

                        var materialFileName     = PathUtils.GetMaterialFileNameByExtName(extName);
                        var virtualDirectoryPath = PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Video);

                        var directoryPath = PathUtils.Combine(_settingsManager.WebRootPath, virtualDirectoryPath);
                        var filePath      = PathUtils.Combine(directoryPath, materialFileName);

                        await FileUtils.WriteStreamAsync(filePath, ms);

                        var material = new MaterialVideo
                        {
                            GroupId  = groupId,
                            Title    = video.name,
                            FileType = extName.ToUpper().Replace(".", string.Empty),
                            Url      = PageUtils.Combine(virtualDirectoryPath, materialFileName),
                            MediaId  = video.media_id
                        };

                        await _materialVideoRepository.InsertAsync(material);
                    }
                }
            }
        }
Beispiel #14
0
        protected string GetWeatherHtml(string provider)
        {
            var result = string.Empty;

            try
            {
                var group = "title";
                if (provider == yahoo)
                {
                    var    pinyinCity = TranslateUtils.ToPinYin(City);
                    string weatherUrl = $"http://weather.cn.yahoo.com/weather.html?city={pinyinCity}&s=1";
                    string regex      =
                        $@"<\!--today\s+-->\s+<div\s+class=""dt_c"">\s+<div\s+class=""tn"">{DateTime.Now.Year}-{TranslateUtils
					        .ToTwoCharString(DateTime.Now.Month)}-{TranslateUtils.ToTwoCharString(DateTime.Now.Day)}</div>\s*(?<title>[\s\S]+?)\s*</div>\s+<\!--//today\s+-->"                    ;

                    var content = WebClientUtils.GetRemoteFileSource(weatherUrl, ECharset.utf_8);

                    if (!string.IsNullOrEmpty(content))
                    {
                        content = RegexUtils.GetContent(group, regex, content);

                        var flashRegex         = @"<p>\s*(?<title>[\s\S]+?)\s*</p>";
                        var weatherStringRegex = @"<span\s+class=""ft1"">\s*(?<title>[\s\S]+?)\s*</span>";
                        var highDegreeRegex    = @"<span\s+class=""hitp"">\s*(?<title>[\s\S]+?)\s*</span>";
                        var lowDegreeRegex     = @"<span\s+class=""lotp"">\s*(?<title>[\s\S]+?)\s*</span>";

                        var flashHtml = RegexUtils.GetContent(group, flashRegex, content);
                        flashHtml = flashHtml.Replace("width=\"64\" height=\"64\"", "width=\"20\" height=\"20\"");
                        var weatherString = RegexUtils.GetContent(group, weatherStringRegex, content);
                        var highDegree    = RegexUtils.GetContent(group, highDegreeRegex, content);
                        var lowDegree     = RegexUtils.GetContent(group, lowDegreeRegex, content);

                        if (!string.IsNullOrEmpty(highDegree))
                        {
                            result = flashHtml + weatherString + $"&nbsp;{highDegree} ~ {lowDegree}";
                        }
                    }
                }
                else if (provider == sina)
                {
                    string weatherUrl = $"http://php.weather.sina.com.cn/search.php?city={PageUtils.UrlEncode(City)}";
                    var    regex      = "<td\\s+bgcolor=\\#FEFEFF\\s+height=25\\s+style=\"padding-left:20px;\"\\s+align=center>24小时</td>\\s*(?<title>[\\s\\S]+?)\\s*</tr>";

                    var content = WebClientUtils.GetRemoteFileSource(weatherUrl, ECharset.gb2312);

                    if (!string.IsNullOrEmpty(content))
                    {
                        content = RegexUtils.GetContent(group, regex, content);

                        var contentArrayList = RegexUtils.GetTagInnerContents("td", content);

                        var weatherString = (string)contentArrayList[0];
                        var highDegree    = (string)contentArrayList[1];
                        var lowDegree     = (string)contentArrayList[2];

                        if (!string.IsNullOrEmpty(highDegree))
                        {
                            result = weatherString + $"&nbsp;{highDegree} ~ {lowDegree}";
                        }
                    }
                }
            }
            catch {}

            return(result);
        }
Beispiel #15
0
        public static bool TryGetOnlineTemplates(out List <Dictionary <string, string> > list)
        {
            list = new List <Dictionary <string, string> >();

            try
            {
                var content = WebClientUtils.GetRemoteFileSource(UrlTemplatesXml, ECharset.utf_8);

                var document = XmlUtils.GetXmlDocument(content);
                var rootNode = XmlUtils.GetXmlNode(document, "//siteTemplates");
                if (rootNode.ChildNodes.Count > 0)
                {
                    foreach (XmlNode node in rootNode.ChildNodes)
                    {
                        var ie           = node.ChildNodes.GetEnumerator();
                        var title        = string.Empty;
                        var description  = string.Empty;
                        var author       = string.Empty;
                        var source       = string.Empty;
                        var lastEditDate = string.Empty;

                        while (ie.MoveNext())
                        {
                            var childNode = (XmlNode)ie.Current;
                            if (childNode == null)
                            {
                                continue;
                            }

                            var nodeName = childNode.Name;
                            if (StringUtils.EqualsIgnoreCase(nodeName, "title"))
                            {
                                title = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "description"))
                            {
                                description = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "author"))
                            {
                                author = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "source"))
                            {
                                source = childNode.InnerText;
                            }
                            else if (StringUtils.EqualsIgnoreCase(nodeName, "lastEditDate"))
                            {
                                lastEditDate = childNode.InnerText;
                            }
                        }

                        if (!string.IsNullOrEmpty(title))
                        {
                            list.Add(new Dictionary <string, string>
                            {
                                ["title"]        = StringUtils.Trim(title),
                                ["description"]  = StringUtils.Trim(description),
                                ["author"]       = StringUtils.Trim(author),
                                ["source"]       = StringUtils.Trim(source),
                                ["lastEditDate"] = StringUtils.Trim(lastEditDate)
                            });
                        }
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #16
0
 /// <summary>
 /// get 请求获取数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="url"></param>
 /// <param name="o"></param>
 /// <returns></returns>
 public T GetJson <T>(string url, object o)
 {
     return(WebClientUtils.GetParamJson <T>(address + url, o));
 }
Beispiel #17
0
        public void GatherUrls_Click(object sender, EventArgs e)
        {
            if (_isFileRule)
            {
                var gatherFileRuleInfo = DataProvider.GatherFileRuleDao.GetGatherFileRuleInfo(_gatherRuleName, PublishmentSystemId);

                var builder = new StringBuilder();
                if (gatherFileRuleInfo.IsToFile == false)
                {
                    var regexTitle          = GatherUtility.GetRegexTitle(gatherFileRuleInfo.ContentTitleStart, gatherFileRuleInfo.ContentTitleEnd);
                    var regexContentExclude = GatherUtility.GetRegexString(gatherFileRuleInfo.ContentExclude);
                    var regexContent        = GatherUtility.GetRegexContent(gatherFileRuleInfo.ContentContentStart, gatherFileRuleInfo.ContentContentEnd);

                    var contentAttributes    = TranslateUtils.StringCollectionToStringList(gatherFileRuleInfo.ContentAttributes);
                    var contentAttributesXML = TranslateUtils.ToNameValueCollection(gatherFileRuleInfo.ContentAttributesXml);

                    var attributes = GatherUtility.GetContentNameValueCollection(gatherFileRuleInfo.Charset, gatherFileRuleInfo.GatherUrl, string.Empty, regexContentExclude, gatherFileRuleInfo.ContentHtmlClearCollection, gatherFileRuleInfo.ContentHtmlClearTagCollection, regexTitle, regexContent, string.Empty, string.Empty, string.Empty, string.Empty, contentAttributes, contentAttributesXML);

                    var styleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.BackgroundContent, PublishmentSystemInfo.AuxiliaryTableForContent, null);
                    foreach (var styleInfo in styleInfoList)
                    {
                        if (string.IsNullOrEmpty(attributes[styleInfo.AttributeName.ToLower()]))
                        {
                            continue;
                        }
                        builder.Append($"{styleInfo.DisplayName}: {attributes[styleInfo.AttributeName.ToLower()]}<br><br>");
                    }
                }
                else
                {
                    try
                    {
                        var fileContent = WebClientUtils.GetRemoteFileSource(gatherFileRuleInfo.GatherUrl, gatherFileRuleInfo.Charset, string.Empty);

                        builder.Append(StringUtils.HtmlEncode(fileContent));
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, ex.Message);
                    }
                }

                Content.Text = builder.ToString();
            }
            else
            {
                var gatherUrl      = GatherUrls.SelectedValue;
                var errorBuilder   = new StringBuilder();
                var gatherRuleInfo = DataProvider.GatherRuleDao.GetGatherRuleInfo(_gatherRuleName, PublishmentSystemId);

                var regexUrlInclude = GatherUtility.GetRegexString(gatherRuleInfo.UrlInclude);
                var regexListArea   = GatherUtility.GetRegexArea(gatherRuleInfo.ListAreaStart, gatherRuleInfo.ListAreaEnd);

                var contentUrlArrayList = GatherUtility.GetContentUrls(gatherUrl, gatherRuleInfo.Charset, gatherRuleInfo.CookieString, regexListArea, regexUrlInclude, errorBuilder);

                ContentUrlRepeater.DataSource     = contentUrlArrayList;
                ContentUrlRepeater.ItemDataBound += ContentUrlRepeater_ItemDataBound;
                ContentUrlRepeater.DataBind();

                InfoMessage($"采集名称:{_gatherRuleName}&nbsp;&nbsp;内容数:{contentUrlArrayList.Count}");

                Content.Text = string.Empty;
            }
        }
Beispiel #18
0
 /// <summary>
 /// post url 传参
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="url"></param>
 /// <param name="o"></param>
 /// <returns></returns>
 public T PostUrlJson <T>(string url, object o)
 {
     return(WebClientUtils.PostUrlJson <T>(address + url, o));
 }
        public async Task <ActionResult <IntResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasAppPermissionsAsync(MenuUtils.AppPermissions.SettingsSitesAdd))
            {
                return(Unauthorized());
            }

            if (!request.Root)
            {
                if (_pathManager.IsSystemDirectory(request.SiteDir))
                {
                    return(this.Error("文件夹名称不能为系统文件夹名称,请更改文件夹名称!"));
                }
                if (!DirectoryUtils.IsDirectoryNameCompliant(request.SiteDir))
                {
                    return(this.Error("文件夹名称不符合系统要求,请更改文件夹名称!"));
                }
                var sitePath = await _pathManager.GetSitePathAsync(request.ParentId);

                var directories = DirectoryUtils.GetDirectoryNames(sitePath);
                if (ListUtils.ContainsIgnoreCase(directories, request.SiteDir))
                {
                    return(this.Error("已存在相同的文件夹,请更改文件夹名称!"));
                }
                var list = await _siteRepository.GetSiteDirsAsync(request.ParentId);

                if (ListUtils.ContainsIgnoreCase(list, request.SiteDir))
                {
                    return(this.Error("已存在相同的站点文件夹,请更改文件夹名称!"));
                }
            }

            var channelInfo = new Channel();

            channelInfo.ChannelName          = channelInfo.IndexName = "首页";
            channelInfo.ParentId             = 0;
            channelInfo.ContentModelPluginId = string.Empty;

            var tableName = string.Empty;

            if (StringUtils.EqualsIgnoreCase(request.SiteType, Types.SiteTypes.Web) || StringUtils.EqualsIgnoreCase(request.SiteType, Types.SiteTypes.Wx))
            {
                if (request.TableRule == TableRule.Choose)
                {
                    tableName = request.TableChoose;
                }
                else if (request.TableRule == TableRule.HandWrite)
                {
                    tableName = request.TableHandWrite;

                    if (!await _settingsManager.Database.IsTableExistsAsync(tableName))
                    {
                        await _contentRepository.CreateContentTableAsync(tableName, _contentRepository.GetTableColumns(tableName));
                    }
                    else
                    {
                        await _settingsManager.Database.AlterTableAsync(tableName, _contentRepository.GetTableColumns(tableName));
                    }
                }
            }

            var adminId = _authManager.AdminId;

            var siteId = await _siteRepository.InsertSiteAsync(channelInfo, new Site
            {
                SiteName  = request.SiteName,
                SiteType  = request.SiteType,
                SiteDir   = request.SiteDir,
                TableName = tableName,
                ParentId  = request.ParentId,
                Root      = request.Root
            }, adminId);

            if (string.IsNullOrEmpty(tableName))
            {
                tableName = await _contentRepository.CreateNewContentTableAsync();

                await _siteRepository.UpdateTableNameAsync(siteId, tableName);
            }

            if (await _authManager.IsSiteAdminAsync() && !await _authManager.IsSuperAdminAsync())
            {
                var siteIdList = await _authManager.GetSiteIdsAsync() ?? new List <int>();

                siteIdList.Add(siteId);
                var adminInfo = await _administratorRepository.GetByUserIdAsync(adminId);

                await _administratorRepository.UpdateSiteIdsAsync(adminInfo, siteIdList);
            }

            var caching = new CacheUtils(_cacheManager);
            var site    = await _siteRepository.GetAsync(siteId);

            caching.SetProcess(request.Guid, "任务初始化...");

            if (request.CreateType == "local")
            {
                var manager = new SiteTemplateManager(_pathManager, _databaseManager, caching);
                await manager.ImportSiteTemplateToEmptySiteAsync(site, request.LocalDirectoryName, request.IsImportContents, request.IsImportTableStyles, adminId, request.Guid);

                caching.SetProcess(request.Guid, "生成站点页面...");
                await _createManager.CreateByAllAsync(site.Id);

                caching.SetProcess(request.Guid, "清除系统缓存...");
                _cacheManager.Clear();
            }
            else if (request.CreateType == "cloud")
            {
                caching.SetProcess(request.Guid, "开始下载模板压缩包,可能需要几分钟,请耐心等待...");

                var filePath = _pathManager.GetSiteTemplatesPath($"T_{request.CloudThemeName}.zip");
                FileUtils.DeleteFileIfExists(filePath);
                var downloadUrl = CloudUtils.Dl.GetThemesDownloadUrl(request.CloudThemeUserName, request.CloudThemeName);
                WebClientUtils.Download(downloadUrl, filePath);

                caching.SetProcess(request.Guid, "模板压缩包下载成功,开始解压缩,可能需要几分钟,请耐心等待...");

                var siteTemplateDir = $"T_{request.CloudThemeName}";
                var directoryPath   = _pathManager.GetSiteTemplatesPath(siteTemplateDir);
                DirectoryUtils.DeleteDirectoryIfExists(directoryPath);
                _pathManager.ExtractZip(filePath, directoryPath);

                caching.SetProcess(request.Guid, "模板压缩包解压成功,正在导入数据...");

                var manager = new SiteTemplateManager(_pathManager, _databaseManager, caching);
                await manager.ImportSiteTemplateToEmptySiteAsync(site, siteTemplateDir, request.IsImportContents, request.IsImportTableStyles, adminId, request.Guid);

                caching.SetProcess(request.Guid, "生成站点页面...");
                await _createManager.CreateByAllAsync(site.Id);

                caching.SetProcess(request.Guid, "清除系统缓存...");
                _cacheManager.Clear();
            }

            return(new IntResult
            {
                Value = siteId
            });
        }
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            if (Body.IsQueryExists("Delete"))
            {
                var siteTemplateDir = Body.GetQueryString("SiteTemplateDir");

                try
                {
                    SiteTemplateManager.Instance.DeleteSiteTemplate(siteTemplateDir);

                    Body.AddAdminLog("删除站点模板", $"站点模板:{siteTemplateDir}");

                    SuccessDeleteMessage();
                }
                catch (Exception ex)
                {
                    FailDeleteMessage(ex);
                }
            }

            _directoryNameLowerList = SiteTemplateManager.Instance.GetDirectoryNameLowerList();

            if (!Page.IsPostBack)
            {
                BreadCrumbSys(AppManager.Sys.LeftMenu.Site, "在线模板下载", AppManager.Sys.Permission.SysSite);

                try
                {
                    var list = new List <Dictionary <string, string> > ();

                    var content = WebClientUtils.GetRemoteFileSource(StringUtils.Constants.UrlMoban, ECharset.utf_8);

                    var document = XmlUtils.GetXmlDocument(content);
                    var rootNode = XmlUtils.GetXmlNode(document, "//siteTemplates");
                    if (rootNode.ChildNodes.Count > 0)
                    {
                        foreach (XmlNode node in rootNode.ChildNodes)
                        {
                            var ie           = node.ChildNodes.GetEnumerator();
                            var templateName = string.Empty;
                            var templateType = string.Empty;
                            var size         = string.Empty;
                            var author       = string.Empty;
                            var uploadDate   = string.Empty;
                            var pageUrl      = string.Empty;
                            var demoUrl      = string.Empty;
                            var downloadUrl  = string.Empty;

                            while (ie.MoveNext())
                            {
                                var childNode = (XmlNode)ie.Current;
                                var nodeName  = childNode.Name;
                                if (StringUtils.EqualsIgnoreCase(nodeName, "templateName"))
                                {
                                    templateName = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "templateType"))
                                {
                                    templateType = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "size"))
                                {
                                    size = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "author"))
                                {
                                    author = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "uploadDate"))
                                {
                                    uploadDate = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "pageUrl"))
                                {
                                    pageUrl = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "demoUrl"))
                                {
                                    demoUrl = childNode.InnerText;
                                }
                                else if (StringUtils.EqualsIgnoreCase(nodeName, "downloadUrl"))
                                {
                                    downloadUrl = childNode.InnerText;
                                }
                            }

                            var directorName = PageUtils.GetFileNameFromUrl(downloadUrl);
                            directorName = directorName.Replace(".zip", string.Empty);

                            list.Add(new Dictionary <string, string>
                            {
                                ["templateName"]  = templateName,
                                ["templateType"]  = templateType,
                                ["size"]          = size,
                                ["author"]        = author,
                                ["uploadDate"]    = uploadDate,
                                ["pageUrl"]       = pageUrl,
                                ["demoUrl"]       = demoUrl,
                                ["downloadUrl"]   = downloadUrl,
                                ["directoryName"] = directorName
                            });
                        }
                    }

                    dgContents.DataSource     = list;
                    dgContents.ItemDataBound += dgContents_ItemDataBound;
                    dgContents.DataBind();
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "在线模板获取失败:页面地址无法访问!");
                }
            }
        }