1+ // --------------------------------------------------------------------------------------------------------------------
2+ // <summary>
3+ // Includes a reference to a JavaScript.
4+ // <remarks>
5+ // This control is needed in order to let the src
6+ // attribute of the script tage be relative to the root.
7+ // </remarks>
8+ // </summary>
9+ // --------------------------------------------------------------------------------------------------------------------
10+
11+ namespace App_Code . Controls
12+ {
13+ using System . Text ;
14+ using System . Web ;
15+ using System . Web . UI ;
16+
17+ using BlogEngine . Core ;
18+
19+ /// <summary>
20+ /// Includes a reference to a JavaScript.
21+ /// <remarks>
22+ /// This control is needed in order to let the src
23+ /// attribute of the script tage be relative to the root.
24+ /// </remarks>
25+ /// </summary>
26+ public class SearchBox : Control
27+ {
28+
29+ #region Public Methods
30+
31+ /// <summary>
32+ /// Renders the control as a script tag.
33+ /// </summary>
34+ /// <param name="writer">
35+ /// The writer.
36+ /// </param>
37+ public override void RenderControl ( HtmlTextWriter writer )
38+ {
39+ writer . Write ( this . BuildHtml ( ) ) ;
40+ }
41+
42+ #endregion
43+
44+ #region Methods
45+
46+ /// <summary>
47+ /// The build html.
48+ /// </summary>
49+ private string BuildHtml ( )
50+ {
51+ var text = this . Context . Request . QueryString [ "q" ] != null
52+ ? HttpUtility . HtmlEncode ( this . Context . Request . QueryString [ "q" ] )
53+ : BlogSettings . Instance . SearchDefaultText ;
54+ var sb = new StringBuilder ( ) ;
55+ sb . AppendLine ( "<div id=\" searchbox\" >" ) ;
56+ sb . Append ( "<label for=\" searchfield\" style=\" display:none\" >Search</label>" ) ;
57+ sb . AppendFormat (
58+ "<input type=\" text\" value=\" {0}\" id=\" searchfield\" onkeypress=\" if(event.keyCode==13) return BlogEngine.search('{1}','searchfield')\" onfocus=\" BlogEngine.searchClear('{2}','searchfield')\" onblur=\" BlogEngine.searchClear('{2}','searchfield')\" />" ,
59+ text ,
60+ Utils . RelativeWebRoot ,
61+ text . Replace ( "'" , "\\ '" ) ) ;
62+ sb . AppendFormat (
63+ "<input type=\" button\" value=\" {0}\" id=\" searchbutton\" onclick=\" BlogEngine.search('{1}','searchfield');\" onkeypress=\" BlogEngine.search('{1}','searchfield');\" />" ,
64+ BlogSettings . Instance . SearchButtonText ,
65+ Utils . RelativeWebRoot ) ;
66+
67+ if ( BlogSettings . Instance . EnableCommentSearch && BlogSettings . Instance . ShowIncludeCommentsOption )
68+ {
69+ var check = this . Context . Request . QueryString [ "comment" ] != null ? "checked=\" checked\" " : string . Empty ;
70+ sb . AppendFormat ( "<div id=\" search-include-comments\" ><input type=\" checkbox\" id=\" searchcomments\" {0} />" , check ) ;
71+ if ( ! string . IsNullOrEmpty ( BlogSettings . Instance . SearchCommentLabelText ) )
72+ {
73+ sb . AppendFormat (
74+ "<label for=\" searchcomments\" >{0}</label></div>" , BlogSettings . Instance . SearchCommentLabelText ) ;
75+ }
76+ }
77+
78+ sb . AppendLine ( "</div>" ) ;
79+ return sb . ToString ( ) ;
80+ }
81+
82+ #endregion
83+ }
84+ }
0 commit comments