예제 #1
0
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            Photo photo = AlbumBO.Instance.GetPhoto(targetID);
            isCanShare = true;

            userID = photo.UserID;
            User author = UserBO.Instance.GetUser(userID);
            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(author.UserID);
            string photoUrl = UrlHelper.GetPhotoUrlTag(photo.PhotoID);

            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += photoUrl;
            shareContent += "\" title=\"";
            shareContent += photo.Name;
            shareContent += "\"><img class=\"summaryimg image\" src=\"";
            shareContent += photo.ThumbSrc;
            shareContent += "\" alt=\"";
            shareContent += photo.Name;
            shareContent += "\" onload=\"imageScale(this, 200, 200)\" onerror=\"this.style.display = 'none';\" /></a>";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += photoUrl;
            shareContent += "\" title=\"";
            shareContent += photo.Name;
            shareContent += "\">";
            shareContent += photo.Name;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Name;
            shareContent += "\">";
            shareContent += author.Name;
            shareContent += "</a><br />";
            shareContent += photo.Description;
            shareContent += "</div>";


            ShareContent content = new ShareContent();
            content.Catagory = ShareType.Picture;
            content.Content = shareContent.ToString();
            content.Title = photo.Name;
            content.URL = photoUrl;

            return content;
        }
예제 #2
0
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            userID = 0;
            isCanShare = false;

            BlogArticle article = BlogBO.Instance.GetBlogArticle(targetID);

            if (article == null)
                return null;

            isCanShare = article.PrivacyType == PrivacyType.AllVisible;

            if (!isCanShare)
            {
                userID = 0;
                return null;
            }

            userID = article.UserID;

            User author = UserBO.Instance.GetUser(userID);

            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(author.UserID);
            string articleUrl = UrlHelper.GetBlogArticleUrlTag(article.ArticleID); //"$url(" + "space/" + article.UserID + "/blog/article-" + targetID + ")";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += articleUrl;
            shareContent += "\" title=\"";
            shareContent += article.Subject;
            shareContent += "\">";
            shareContent += article.Subject;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Username;
            shareContent += "\">";
            shareContent += author.Username;
            shareContent += "</a><br />";
            shareContent += StringUtil.CutString(StringUtil.ClearAngleBracket(article.Content), Consts.Share_ReviewContentLength);
            shareContent += "</div>";

            if (string.IsNullOrEmpty(article.Thumb) == false)
            {
                shareContent += "<a target=\"_blank\" href=\"" + articleUrl;
                shareContent += "\" title=\"";
                shareContent += article.Subject;
                shareContent += "\"><img class=\"summaryimg image\" src=\"";
                shareContent += article.Thumb;
                shareContent += "\" alt=\"";
                shareContent += article.Subject;
                shareContent += "\" onload=\"imageScale(this, 100, 100)\" onerror=\"this.style.display = 'none';\"  /></a>";
            }


            ShareContent content = new ShareContent();
            content.Catagory = ShareType.Blog;
            content.Content = shareContent.ToString();
            content.Title = article.Subject;
            content.URL = articleUrl;

            return content;
        }
예제 #3
0
        public ShareContent GetShareContent(int targetID, out int userID, out bool isCanShare)
        {
            userID = 0;
            isCanShare = true;

            Album album = AlbumBO.Instance.GetAlbum(targetID);
            
            if (album == null)
            {
                return null;
            }
            
            isCanShare = album.PrivacyType == PrivacyType.AllVisible;
            
            if (!isCanShare)
            {
                userID = 0;
                return null;
            }
            
            userID = album.UserID;
            
            User author = UserBO.Instance.GetUser(userID);
            StringBuffer shareContent = new StringBuffer();

            string spaceUrl = UrlHelper.GetSpaceUrlTag(album.UserID);
            string albumUrl = UrlHelper.GetAblumUrlTag(targetID);

            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += albumUrl;
            shareContent += "\" title=\"";
            shareContent += album.Name;
            shareContent += "\"><img class=\"summaryimg image\" src=\"";
            shareContent += album.CoverSrc;
            shareContent += "\" alt=\"";
            shareContent += album.Name;
            shareContent += "\" onload=\"imageScale(this, 100, 100)\" onerror=\"this.style.display = 'none';\" /></a>";

            shareContent += "<div class=\"detail\">";
            shareContent += "<b><a target=\"_blank\" href=\"";
            shareContent += albumUrl;
            shareContent += "\" title=\"";
            shareContent += album.Name;
            shareContent += "\">";
            shareContent += album.Name;
            shareContent += "</a></b><br />";
            shareContent += "<a target=\"_blank\" href=\"";
            shareContent += spaceUrl;
            shareContent += "\" title=\"";
            shareContent += author.Name;
            shareContent += "\">";
            shareContent += author.Name;
            shareContent += "</a><br />";
            shareContent += "</div>";


            ShareContent content = new ShareContent();
            content.Catagory = ShareType.Album;
            content.Content = shareContent.ToString();
            content.Title = album.Name;
            content.URL = albumUrl;

            return content;
        }
예제 #4
0
        /// <summary>
        /// 如果是整数的天 或者 小时 或者 分钟 将转换成对应的单位: 如:"3天"
        /// 0返回 "无限期"
        /// </summary>
        /// <param name="seconds"></param>
        /// <returns></returns>
        public static string FormatSecond(long seconds, TimeUnit timeUnit)
        {

            if (seconds == 0)
                return Lang.Common_Indefinitely;

            int secondOfDay = 24 * 3600;
            int secondOfHour = 3600;
            int secondOfMinute = 60;

            StringBuffer buffer = new StringBuffer();
            if (seconds > secondOfDay)
            {
                int day = (int)(seconds / secondOfDay);
                buffer += day + Lang.Common_Day;
                seconds -= day * secondOfDay;
            }

            if (timeUnit == TimeUnit.Day && buffer.Length > 0) return buffer.ToString();

            if (seconds > secondOfHour)
            {
                int hour;
                hour = (int)seconds / secondOfHour;
                buffer += hour + Lang.Common_Hour;
                seconds -= hour * secondOfHour;
            }

            if (timeUnit == TimeUnit.Hour && buffer.Length > 0) return buffer.ToString();

            if (seconds > secondOfMinute)
            {
                int minute;
                minute = (int)seconds / secondOfMinute;
                buffer += minute + Lang.Common_Minute;
                seconds -= minute * secondOfMinute;
            }

            if (timeUnit == TimeUnit.Minute && buffer.Length > 0) return buffer.ToString();

            if (seconds > 0)
                buffer += seconds + Lang.Common_Second;

            return buffer.ToString();
        }
예제 #5
0
		private void GenerateAjaxPanelAspxCode(TemplateElement node, ScopeData scopeData)
		{
			TemplateElement attributeList = node.ChildNodes[0];

			string autoID = NewAjaxPanelID();

			string id = null;
			string tag = null;
			string onUpdate = null;
			string idOnly = "false";
			string ajaxOnly = "false";
			Hashtable others = new Hashtable(2);

			foreach (TemplateElement item in attributeList.ChildNodes)
			{
				string name = item.Items[TemplateElement.KEY_NAME] as string;

				name = name.ToLower();

				switch (name)
				{
					case "id":
                        StringBuffer sb = new StringBuffer();

						GenerateDoubleQuteStringAspxCode(sb, item, scopeData);

                        id = sb.ToString();
						break;

					case "tag":
						tag = item.SourceTemplate.Substring(item.Index, item.Length);
						break;

					case "idonly":
						idOnly = "true";
						break;

					case "ajaxonly":
						ajaxOnly = "true";
						break;

					case "onupdate":
						StringBuffer jscode = new StringBuffer();

						GenerateAspxCode(jscode, item, scopeData);

						onUpdate = jscode.ToString();
						break;

					default:
						StringBuffer code = new StringBuffer();

						GenerateAspxCode(code, item, scopeData);

						others.Add(name, code.ToString());
						break;
				}
			}

			if (id == null)
				id = "\"" + autoID + "\"";

			if (tag == null)
				tag = "div";

			m_CodeBody += "<" + tag + " id=\"<%=" + id + "%>\"";

			if (others.Count > 0)
			{
				foreach (DictionaryEntry item in others)
				{
					m_CodeBody += " " + item.Key + "=\"" + item.Value + "\"";
				}
			}

			m_CodeBody += ">";

            m_CodeBody += "<%\r\nusing(MaxLabs.WebEngine.AjaxPanel " + autoID + " = new MaxLabs.WebEngine.AjaxPanel(" + id + ", " + idOnly + ", " + ajaxOnly + ", this.AjaxPanelContext, this.HtmlTextWriter)){%>";

            m_CodeBody += "<%\r\nHtmlTextWriter " + autoID + "__w = __w; if(__w.InnerWriter is AjaxPanelWriter == false) __w = " + autoID + ".Writer; %>";
			
			GenerateAspxCode(node, scopeData);

            m_CodeBody += "<%\r\n__w = " + autoID + "__w; }%>";

			m_CodeBody += "</" + tag + ">";

			if (onUpdate != null)
			{
                m_CodeBody += "<script type=\"text/javascript\">var __<%=" + id + "%>__ = document.getElementById('<%=" + id + "%>'); __<%=" + id + "%>__.onUpdate = function(panel){ " + onUpdate + " }</script>";
			}
		}
예제 #6
0
        public void GenerateAspxCode(string skinID, TemplateFile templateFile, string[] templateImports)
        {
            string template = templateFile.GetFullTemplate(skinID);

            string checkString = ReadCheckString(templateFile);
            string newCheckString = GetNewCheckString(template);

            if (checkString != newCheckString)
            {
                #region 需要重新解析模板    

                m_Document = TemplateElement.CreateDocument(template, templateFile);

                m_CodeHead = new StringBuffer();
                m_CodeBody = new StringBuffer(template.Length);

                GenerateAspxCodeHead1(templateFile);

                GenerateAspxCode(m_Document, new ScopeData(null));

                GenerateAspxCodeHead2(templateFile, templateImports, skinID);

                string aspxCode = string.Concat("<%--", newCheckString, "--%>\r\n", m_CodeHead.ToString(), m_CodeBody.ToString());

                try
                {
                    using (StreamWriter writer = new StreamWriter(templateFile.ParsedFilePath, false, Encoding.UTF8))
                    {
                        writer.Write(aspxCode);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.CreateErrorLog(ex, templateFile.FileName + "写入文件时出错");
                }

                LogHelper.CreateDebugLog(templateFile.FileName + "发生了重新解析,并写入磁盘");

                #endregion
            }

            TryBuildTempWebConfig();
        }
예제 #7
0
		private void GenerateFunctionAspxCode(StringBuffer codeBody, TemplateElement function, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type funcReturnType = null;

			string thisVarName = null;
			string thisFuncName = null;

			string name = (string)function.Items[TemplateElement.KEY_NAME];

			if (StringUtil.EqualsIgnoreCase(name, "url"))
			{
				GenerateUrlFunctionAspxCode(codeBody, function, scopeData);
				returnType = typeof(string);
			}
			else if (StringUtil.EqualsIgnoreCase(name, "parent"))
			{
				bool onlyOneParam = true;
				TemplateElement funcParam = null;

				foreach (TemplateElement param in function.ChildNodes[0].ChildNodes)
				{
					if (param.Type == TemplateElementTypes.Literal)
						continue;

                    if (funcParam != null)
					{
						onlyOneParam = false;
						break;
					}

					funcParam = param;
				}

				if (onlyOneParam)
				{
					if (funcParam.Type == TemplateElementTypes.Variable)
						GenerateVariableAspxCode(codeBody, funcParam, out returnType, scopeData.Previous);
					else if (funcParam.Type == TemplateElementTypes.Function)
                        GenerateFunctionAspxCode(codeBody, funcParam, out returnType, scopeData.Previous);
				}
			}
            else if (StringUtil.EqualsIgnoreCase(name, "this"))
            {
                bool onlyOneParam = true;
                TemplateElement funcParam = null;

                foreach (TemplateElement param in function.ChildNodes[0].ChildNodes)
                {
                    if (param.Type == TemplateElementTypes.Literal)
                        continue;

                    if (funcParam != null)
                    {
                        onlyOneParam = false;
                        break;
                    }

                    funcParam = param;
                }

                if (onlyOneParam)
                {
                    if (funcParam.Type == TemplateElementTypes.Variable)
                        GenerateVariableAspxCode(codeBody, funcParam, out returnType, scopeData.Last);
                    else if (funcParam.Type == TemplateElementTypes.Function)
                        GenerateFunctionAspxCode(codeBody, funcParam, out returnType, scopeData.Last);
                }
            }
            else if (StringUtil.EqualsIgnoreCase(name, "out"))
            {
                funcReturnType = typeof(string);

                StringBuffer newCodeBody = new StringBuffer();

                GenerateOutFunctionAspxCode(newCodeBody, function, scopeData);

                if (function.ChildNodes.Count > 1)
                    GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], funcReturnType, out returnType, scopeData);

                if (returnType == null)
                    returnType = funcReturnType;

                codeBody += newCodeBody.ToString();
            }
            else if (scopeData.SearchThisVariableMethod(name, out funcReturnType, out thisVarName, out thisFuncName))
            {
                StringBuffer newCodeBody = new StringBuffer();

                newCodeBody += thisVarName + "." + thisFuncName + "(";

                GenerateAspxCode(newCodeBody, function.ChildNodes[0], scopeData);

                newCodeBody += ")";

                if (function.ChildNodes.Count > 1)
                    GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], funcReturnType, out returnType, scopeData);

                if (returnType == null)
                    returnType = funcReturnType;

                codeBody += newCodeBody.ToString();
            }
            else
            {
                MethodInfo method = SearchMethodForFunction(name);

                if (method != null)
                {
                    StringBuffer newCodeBody = new StringBuffer();

                    string instanceName = DeclaringVariable(method.DeclaringType);

                    newCodeBody += instanceName + "." + method.Name + "(";

                    GenerateAspxCode(newCodeBody, function.ChildNodes[0], scopeData);

                    newCodeBody += ")";

                    if (function.ChildNodes.Count > 1)
                        GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], method.ReturnType, out returnType, scopeData);

                    if (returnType == null)
                        returnType = method.ReturnType;

                    codeBody += newCodeBody.ToString();
                }
            }
		}
예제 #8
0
		private void GenerateVariableAspxCode(StringBuffer codeBody, TemplateElement variable, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type varType = null;
			string varName = null;
			string paramName = null;
			string name = (string)variable.Items[TemplateElement.KEY_NAME];

            if (scopeData.SearchScopeVariable(name, out varType, out varName))
			{
				StringBuffer newCodeBody = new StringBuffer();

				newCodeBody += varName;

				if (variable.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], varType, out returnType, scopeData);

				if (returnType == null)
					returnType = varType;

				codeBody += newCodeBody.ToString();
			}
			else if (scopeData.SearchThisVariableProperty(name, out varType, out varName, out paramName))
			{
				StringBuffer newCodeBody = new StringBuffer();

				newCodeBody += varName + "." + paramName;

				if (variable.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], varType, out returnType, scopeData);

				if (returnType == null)
					returnType = varType;

				codeBody += newCodeBody.ToString();
			}
			else
			{
				MemberInfo member = SearchMemberForVariable(name);

                if (member != null)
                {
                    string instanceName = DeclaringVariable(member.DeclaringType);

                    StringBuffer newCodeBody = new StringBuffer();

                    newCodeBody += instanceName + "." + member.Name;

                    Type memberType;

                    if (member.MemberType == MemberTypes.Property)
                        memberType = ((PropertyInfo)member).PropertyType;
                    else
                        memberType = ((FieldInfo)member).FieldType;

                    if (variable.ChildNodes.Count > 0)
                        GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], memberType, out returnType, scopeData);

                    if (returnType == null)
                        returnType = memberType;

                    codeBody += newCodeBody.ToString();
                }
                else
                {

                    throw new TemplateVariableNotExistsException(name, variable.TemplateFile.FilePath, variable.SourceTemplate, variable.Index);
                    //codeBody += name;
                    //LogHelper.CreateErrorLog(new TemplateVariableNotExistsException(name, variable.TemplateFile.FilePath, variable.SourceTemplate, variable.Index));

                    //if (returnType == null)
                    //    returnType = typeof(string);
                }
			}
		}
예제 #9
0
		public static string GetUrlForAction(string urlInfo, string query)
		{
            if (string.IsNullOrEmpty(query))
                return GetUrlForAction(urlInfo);

            int indexOfQuery = urlInfo.IndexOf('?');

            if (indexOfQuery >= 0)
            {

                #region 处理原来有参数同时也要追加参数的情况

                NameValueCollection q2 = HttpUtility.ParseQueryString(query);

                StringBuffer newUrl = new StringBuffer();

                if (AllSettings.Current.FriendlyUrlSettings.UrlFormat == UrlFormat.Query)
                    newUrl += Globals.AppRoot + "/default.aspx?";

                else
                    newUrl += Globals.AppRoot + "/";

                string query1 = string.Empty;

                if (indexOfQuery >= 0)
                {
                    newUrl += urlInfo.Substring(0, indexOfQuery);

                    query1 = urlInfo.Substring(indexOfQuery + 1);
                }
                else
                    newUrl += urlInfo;

                switch (AllSettings.Current.FriendlyUrlSettings.UrlFormat)
                {
                    //case MaxLabs.bbsMax.Enums.UrlFormat.Folder:
                    //    newUrl += "/";
                    //    break;

                    case MaxLabs.bbsMax.Enums.UrlFormat.Aspx:
                        newUrl += ".aspx";
                        break;

                    case MaxLabs.bbsMax.Enums.UrlFormat.Html:
                        newUrl += ".html";
                        break;
                }


                NameValueCollection q1 = HttpUtility.ParseQueryString(query1);

                if (q2 != null)
                {
                    for (int i = 0; i < q2.Count; i++)
                    {
                        string value = q2[i];

                        q1[q2.GetKey(i)] = value;
                    }
                }

                StringBuilder newQuery = new StringBuilder("?");

                for (int i = 0; i < q1.Count; i++)
                {
                    newQuery.Append(HttpUtility.UrlEncode(q1.GetKey(i))).Append("=").Append(HttpUtility.UrlEncode(q1[i])).Append("&");
                }

                newQuery.Remove(newQuery.Length - 1, 1);

                newUrl += newQuery;

                #endregion

                return newUrl.ToString();
            }
            else
            {
                return string.Concat(GetUrlForAction(urlInfo), "?", query);
            }

		}