Tag Archive for page

Remove border and padding from welcome picture

/* welcome page image */
#welcome-left img {
border-bottom-style:solid;
border-bottom-width:0px;
border-left-style-ltr-source:physical;
border-left-style-rtl-source:physical;
border-left-style-value:solid;
border-left-width-ltr-source:physical;
border-left-width-rtl-source:physical;
border-left-width-value:0px;
border-right-style-ltr-source:physical;
border-right-style-rtl-source:physical;
border-right-style-value:solid;
border-right-width-ltr-source:physical;
border-right-width-rtl-source:physical;
border-right-width-value:1px;
border-top-style:solid;
border-top-width:0px;
padding-bottom:0px;
padding-left:0px;
padding-right:0px;
padding-top:0px;
}

source

JQUERY PAGE SCROLL

<script type="text/javascript">
 $(document).ready(function(){
 //back to top scroll function. Any link with a hash (#) will scroll to that id on the page
  $('a[href*=#]').click(function() {
 if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'')
 && location.hostname == this.hostname) {
   var $target = $(this.hash);
   $target = $target.length && $target
   || $('[name=' + this.hash.slice(1) +']');
   if ($target.length) {
  var targetOffset = $target.offset().top;
  $('html,body')
  .animate({scrollTop: targetOffset}, 500);
    return false;
   }
 }
  });
});
</script>

source

Asynchronous ASP.Net Pages, AJAX Helper, WebRequest Passthrough

Main Class (AsyncCall.cs), place in App_Code directory or compile as a dll and place in the bin dirctory of the site:
-------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Net;
using System.Threading;
using System.IO;
using System.Collections.Specialized;

namespace AsyncStuff
{
	public static class AsyncCall
	{
		public sealed class AsyncState
		{
			internal const string QVARNAME = "ASYNCSession";

			public readonly Page CallingPage;
			internal readonly Uri Url;
			private HttpWebRequest _request;
			private HttpWebResponse _response;
			internal readonly SpecificFunction SpecificFunction;
			public readonly object[] Parameters;
			private string _text;
			internal byte[] FormContent;

			//cascaded constructor only (private)
			private AsyncState(Page page)
			{
				this.CallingPage = page;
				this.Url = GetAsyncUrl(page.Request.Url);
			}

			//off-page url
			internal AsyncState(Uri url, Page page, SpecificFunction specificFunction)
			{
				this.CallingPage = page;
				this.Url = GetAsyncUrl(url);
				this.SpecificFunction = specificFunction;
			}

			internal AsyncState(Page page, SpecificFunction specificFunction)
				: this(page)
			{
				this.SpecificFunction = specificFunction;
			}

			internal AsyncState(Page page, SpecificFunction specificFunction, params object[] parameters)
				: this(page, specificFunction)
			{
				this.Parameters = parameters;
			}

			private Uri GetAsyncUrl(Uri uri)
			{
				string url = uri.OriginalString;
				int start = url.IndexOf("?");
				if (start < 0)
				{
					start = url.Length;
					url = url.Insert(start++, "?");
				}
				else
				{
					start++;
					url = url.Insert(start, "&");
				}

				//timestamped query variable inserted to indicate that a page is running asychronously
				url = url.Insert(start, QVARNAME + "=" + DateTime.Now.ToString("MMddyyyyHHmmssffff"));
				return new Uri(url);
			}

			public HttpWebRequest Request
			{
				get { return this._request; }
				internal set { this._request = value; }
			}

			public HttpWebResponse Response
			{
				get { return this._response; }
				internal set { this._response = value; }
			}

			public string GetResponseText()
			{
				if (this._text == null)
				{
					this._text = "";
					if (this._response != null)
						this._text = (new StreamReader(this._response.GetResponseStream())).ReadToEnd();
				}
				if (this._text == "")
					return null;

				return this._text;
			}
		}

		/// <summary>
		/// A delegate function used to create a callback for the RunPageAsynchronously() function
		/// </summary>
		/// <param name="state">The state object that will be returned from the results of the asychronous call</param>
		public delegate void SpecificFunction(AsyncState state);

		/// <summary>
		/// Run an off-page url request as an asychronous request. (Note: this is a seperate session, so don't expect session variables to persist)
		/// </summary>
		/// <param name="url">Off-page URL which contents will be retreived asychronously</param>
		/// <param name="callingPage">The current System.Web.UI.Page object which is making the asychronous call (must implement IHttpAsyncHandler or use the [%@ Page Async="true"] directive)</param>
		/// <returns>true, if the page was able to run asynchronously (a value of false may indicate the %@ Page directive is not using Async="true"</returns>
		public static bool RunAsynchronously(string url, Page callingPage)
		{
			if (callingPage is IHttpAsyncHandler)
			{
				Uri absUrl = new Uri(url, UriKind.RelativeOrAbsolute);
				if (!absUrl.IsAbsoluteUri || absUrl.OriginalString.StartsWith("file"))
				{
					string resolve = callingPage.ResolveUrl(url);
					Uri pageUrl = callingPage.Request.Url;
					string newPath = pageUrl.OriginalString.Replace(pageUrl.PathAndQuery, resolve);
					absUrl = new Uri(newPath, UriKind.Absolute);

					string filePath = callingPage.MapPath(absUrl.AbsolutePath);
					FileInfo fi = new FileInfo(filePath);
					if (!fi.Exists)
						throw new Exception("File Not Found, requestsed relative path does not exist. Check the filename for spelling errors.");
				}
				AsyncState state = new AsyncState(absUrl, callingPage, new SpecificFunction(AfterOffPage));
				callingPage.AddOnPreRenderCompleteAsync(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation), state);
				return true;
			}
			return false;
		}

		private static void AfterOffPage(AsyncState state)
		{
			if (state==null || state.Response == null || state.CallingPage==null || state.CallingPage.Response==null)
				return;

			//content rewrite (make calling page same as the page called)
			//requires IIS content rewrite pipline mode, so if exception then ignore
			try
			{
				state.CallingPage.Response.Headers.Clear();
				state.CallingPage.Response.Headers.Add(state.Response.Headers);
			}
			catch { }
			state.CallingPage.Response.ContentType = state.Response.ContentType;
			BinaryReader br = new BinaryReader(state.Response.GetResponseStream());
			int len = (int)state.Response.ContentLength;
			byte[] data = br.ReadBytes(len);
			state.CallingPage.Response.OutputStream.Write(data, 0, len);			
		
			state.CallingPage.Response.End();
		}

		/// <summary>
		/// Run the current page request as an asychronous request. (Note: this is a seperate session, so don't expect session variables to persist)
		/// </summary>
		/// <param name="callingPage">The current System.Web.UI.Page object to be processed (must implement IHttpAsyncHandler or use the [%@ Page Async="true"] directive)</param>
		/// <param name="specificFunction">A parameterless function to call on the async request page</param>
		/// <returns>true, if the page was able to run asynchronously (a value of false may indicate the %@ Page directive is not using Async="true"</returns>
		public static bool RunAsynchronously(Page callingPage, SpecificFunction specificFunction)
		{
			if ((callingPage is IHttpAsyncHandler) && !IsRunningAsync(callingPage))
			{
				AsyncState state = new AsyncState(callingPage, specificFunction);
				callingPage.AddOnPreRenderCompleteAsync(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation), state);
				return true;
			}
			return false;
		}

		/// <summary>
		/// Run the current page request as an asychronous request. (Note: this is a seperate session, so don't expect session variables to persist)
		/// </summary>
		/// <param name="callingPage">The current System.Web.UI.Page object to be processed (must implement IHttpAsyncHandler or use the [%@ Page Async="true"] directive)</param>
		/// <param name="specificFunction">A function to call on the async request page</param>
		/// <param name="parameters">The parameters to pass to the specific function</param>
		/// <returns>true, if the page was able to run asynchronously (a value of false may indicate the %@ Page directive is not using Async="true"</returns>
		public static bool RunAsynchronously(Page callingPage, SpecificFunction specificFunction, params object[] parameters)
		{
			if ((callingPage is IHttpAsyncHandler) && !IsRunningAsync(callingPage))
			{
				AsyncState state = new AsyncState(callingPage, specificFunction, parameters);
				callingPage.AddOnPreRenderCompleteAsync(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation), state);
				return true;
			}
			return false;
		}

		/// <summary>
		/// Tests to see if the page is in is asynchronous cycle of an asynchronous request made from the RunPageAsynchronously function
		/// </summary>
		/// <param name="page">The page to check for sychronicity</param>
		/// <returns>true if in the asychronous cycle</returns>
		public static bool IsRunningAsync(Page page)
		{
			return (page.Request.QueryString[AsyncState.QVARNAME] != null);
		}

		private static IAsyncResult BeginAsyncOperation(object sender, EventArgs e, AsyncCallback cb, object stateObj)
		{
			if (stateObj is AsyncState)
			{
				AsyncState state = (AsyncState)stateObj;
				state.Request = (HttpWebRequest)HttpWebRequest.Create(state.Url);
				
				//copy relevant header information
				state.Request.Accept = GetTextList<string>(state.CallingPage.Request.AcceptTypes, ", ", true);
				state.Request.AllowAutoRedirect = true;
				state.Request.AllowWriteStreamBuffering = true;
				state.Request.ContentType = state.CallingPage.Request.ContentType + "; " + state.CallingPage.Request.ContentEncoding.WebName;
				state.Request.Method = state.CallingPage.Request.RequestType;
				state.Request.Referer = state.CallingPage.Request.UrlReferrer.OriginalString;
				
				//copy cookies
				if (state.CallingPage.Request.Cookies.Count > 0)
				{
					state.Request.CookieContainer = new CookieContainer();
					List<string> excludedCookies = new List<string> { "ASP.NET_SessionId" };
					foreach (string key in state.CallingPage.Request.Cookies.Keys)
					{
						if (!excludedCookies.Contains(key, StringComparer.CurrentCultureIgnoreCase))
						{
							HttpCookie cookie = state.CallingPage.Request.Cookies[key];
							Cookie copy = new Cookie(cookie.Name, cookie.Value, state.Url.AbsolutePath, state.Url.Host);
							state.Request.CookieContainer.Add(copy);
						}
					}
				}
				
				//copy form variables
				if (state.CallingPage.Request.Form.Count > 0 && state.Request.Method.Equals("POST", StringComparison.CurrentCultureIgnoreCase))
				{
					string pairs = GetTextDictionary(state.CallingPage.Request.Form, "=", "&", true);					
					state.FormContent = state.CallingPage.Request.ContentEncoding.GetBytes(pairs);
					state.Request.ContentLength = state.FormContent.Length;
					state.Request.BeginGetRequestStream(EndRequestStreamCallback, state);
				}

				return state.Request.BeginGetResponse(cb, stateObj);
			}
			return null;
		}

		private static void EndRequestStreamCallback(IAsyncResult ar)
		{
			if (ar.AsyncState is AsyncState)
			{
				AsyncState state = (AsyncState)ar.AsyncState;				
				BinaryWriter sw = new BinaryWriter(state.Request.EndGetRequestStream(ar));
				sw.Write(state.FormContent, 0, state.FormContent.Length);
				sw.Close();
			}
		}

		private static void EndAsyncOperation(IAsyncResult ar)
		{
			if (ar.AsyncState is AsyncState)
			{
				AsyncState state = (AsyncState)ar.AsyncState;
				if (state.Request != null)
				{
					try { state.Response = (HttpWebResponse)state.Request.EndGetResponse(ar); }
					catch (Exception ex) { throw new Exception("WebRequest Error. Remember that asynchronous calls are made from the server and not the client, so any routing done on the client (say...to a testing server) will not be in effect with this request.", ex); };

					if (state.SpecificFunction != null)
					{
						object target = state.SpecificFunction.Target;
						if (target == null)
							target = state.CallingPage;
						try { state.SpecificFunction.Method.Invoke(target, new object[] { state }); }
						catch (Exception ex) { throw new Exception("An error occured in the SpecificFunction supplied, the debug thread is not attached to the function invoked, therefore further debug information is unavailable.", ex); }
					}
				}
			}
		}

		private static string GetTextList<I>(IEnumerable<I> list, string separator, bool urlEncode)
		{			
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			int index = 0;
			foreach (I item in list)
			{
				if (index > 0)
					sb.Append(separator);				
				if (urlEncode)				
					sb.Append(HttpUtility.UrlPathEncode(item.ToString()));
				else
					sb.Append(item.ToString());
				index++;
			}
			string ret = sb.ToString();
			sb.Length = 0; //destroy memory
			return ret;
		}

		private static string GetTextDictionary<K, V>(IDictionary<K, V> dictionary, string equality, string separator, bool urlEncode)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			int index = 0;
			foreach (K key in dictionary.Keys)
			{
				V value = dictionary[key];
				if (index > 0)
					sb.Append(separator);
				if (urlEncode)
					sb.Append(HttpUtility.UrlPathEncode(key.ToString()));
				else
					sb.Append(key.ToString());
				sb.Append(equality);
				if (urlEncode)
					sb.Append(HttpUtility.UrlPathEncode(value.ToString()));
				else
					sb.Append(value.ToString());

				index++;
			}
			string ret = sb.ToString();
			sb.Length = 0; //destroy memory
			return ret;
		}

		private static string GetTextDictionary(NameValueCollection dictionary, string equality, string separator, bool urlEncode)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			int index = 0;
			foreach (string key in dictionary.Keys)
			{
				string value = dictionary[key];
				if (index > 0)
					sb.Append(separator);
				if (urlEncode)
					sb.Append(HttpUtility.UrlPathEncode(key.ToString()));
				else
					sb.Append(key.ToString());
				sb.Append(equality);
				if (urlEncode)
					sb.Append(HttpUtility.UrlPathEncode(value.ToString()));
				else
					sb.Append(value.ToString());
				index++;
			}
			string ret = sb.ToString();
			sb.Length = 0; //destroy memory
			return ret;
		}



	}
}

Page Example (AsyncPage.aspx):
-------------------------------------------------------------------------------
<%@ Page Async="true" Language="C#" AutoEventWireup="true" CodeFile="AsyncPage.aspx.cs" Inherits="AsyncPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" >http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></a>

<html xmlns="<a href="http://www.w3.org/1999/xhtml">" >http://www.w3.org/1999/xhtml"></a>
<head runat="server">
    <title></title>
    <script type="text/javascript">
    	function AJAXCall(url, callBack, postData) {
    		//setup the callback
    		var out = callBack;
    		if (!out) {
    			out = function(text) { return; }
    		}

    		//setup the request
    		var request = null;
    		if (window.XMLHttpRequest)
    			request = new XMLHttpRequest();
    		else if (window.ActiveXObject)
    			request = new ActiveXObject("Microsoft.XMLHTTP");
    		else
    			return false;

    		//true for async..
    		request.open("POST", url, true);

    		//setup the handle of the request when the status changes
    		request.onreadystatechange = function() {
    			if (request && request.readyState == 4) {
    				//if (request.status == 200)
    				out(request.responseText);

    			}
    		}
    		//setup the request headers
    		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    		//send the request
    		if (postData)
    			request.send(postData);
    		else
    			request.send("");
    	}

    	function callback(data) {
    		alert('got here: ' + data);
    	}

    	function button1() {
    		AJAXCall("AsyncPage.aspx?LongFunction=1", callback, "testing=1");
    	}   	

    	function button2() {
    		AJAXCall("AsyncPage.aspx?ShortFunction=1", callback, "testing=1");
    	}

    	function button3() {
    		AJAXCall("AsyncPage.aspx?UrlFunction=1", callback, "testing=1");
    	}

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
		<asp:Label ID="lbl1" runat="server" />
		<input type="button" id="testbutton1" value="TestLong" onclick="javascript:button1();" style="width:100px;Height:25px;" />
		<input type="button" id="testbutton2" value="TestShort" onclick="javascript:button2();" style="width:100px;Height:25px;" />
		<input type="button" id="testbutton3" value="TestUrl" onclick="javascript:button3();" style="width:100px;Height:25px;" />
    </div>
    </form>
</body>
</html>

Code Behind (AsyncPage.aspx.cs):
-------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Threading;
using AsyncStuff;

public partial class AsyncPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {		
		if (AsyncCall.IsRunningAsync(Page))			
			CalledAsync(); //function is run when a page calls itself asychronously

		//a query variable triggers this page to run a different async function (use AJAX Call to this same url with this query variable)
		//these are single-run checked already, so you don't have to worry about running them more than once
		if (Request.QueryString["LongFunction"] != null)		
			AsyncCall.RunAsynchronously(Page, AfterLong, "Long call");

		if (Request.QueryString["ShortFunction"] != null)
			AsyncCall.RunAsynchronously(Page, AfterShort);

		if (Request.QueryString["UrlFunction"] != null)
			AsyncCall.RunAsynchronously("/AsyncTest.aspx?test=1", Page);
				
		//Normal Page load		
		lbl1.Text = "Just sitting here";
    }

	//this stuff called on the async thread
	protected void CalledAsync()
	{
		//stuff done during async
		
		if (Request.QueryString["LongFunction"]!=null)
		{
			//crunch some numbers to waste some time
			for(int i = 1; i<565535; i++)
			{
				decimal num = (decimal)DateTime.Now.Millisecond * (decimal)(new Random(DateTime.Now.Millisecond)).NextDouble();
				num += num;
			}
			Response.Write("Success");
		}
		else if (Request.QueryString["ShortFunction"] != null)
		{
			Response.Write("Short Call Was Run");
		}

		Response.End(); //do not show regular page contents
	}

	//this stuff called on the page thread after the async call returns
	protected void AfterLong(AsyncCall.AsyncState state)
	{
		//this is an example of using the response stream directly, you can use state.GetResponseText() to accomplish this same thing
		StreamReader sr = new StreamReader(state.Response.GetResponseStream());
		string pageContent = sr.ReadToEnd();
		if (pageContent.Contains("Success"))		
			Response.Write(state.Parameters[0].ToString());
		else		
			Response.Write("Failure");

		Response.End();
	}

	//this stuff called on the page thread after the async call returns
	protected void AfterShort(AsyncCall.AsyncState state)	
	{		
		string text = state.GetResponseText();
		if (text!=null)
			Response.Write(text);
		Response.End();
	}
}

source

Get current page url

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "<a href="://";" >://";</a>
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>
You can now get the current page URL using the line:

<?php
  echo curPageURL();
?>
Sometimes it is needed to get the page name only. The following example shows how to do it: 

<?php
function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

echo "The current page name is ".curPageName();
?>

source

Display a Page’s Parent Page Name – Concrete5

<?php
$page = Page::getByID($c->getCollectionParentID());
print $page->getCollectionName();
?>

source

Suppress certain page header – Crystal Reports

(PageNumber MOD 2) = 0

source

Display Page Date – Concrete5

<?php echo $c->getCollectionDatePublic("F j, Y") ?>

source

URL Parameter to Page Include

<?php
header("Content-type: text/html;charset=utf-8");
if(!isset($description))
{
$description = 'Default description for your site';
}

if(!isset($title))
{
$title = 'Default page title for your site';
}

?>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<?php
if (isset($_GET['page']) && $_GET['page'] != "") {
$page = $_GET['page'];
if (file_exists('sections/'.$page.'.php')) {
@include ('sections/'.$page.'.php');
} elseif (!file_exists('sections/'.$page.'.php')) {
echo '404 error.'; //A quick and simple means to produce a 404 page through template.
}
} else {
@include ('sections/landing.php');
}
?>
</body>
</html>

source

Exclude WordPress Categories on Secondary Front Pages

<?php if ( is_home() ) {
query_posts("paged=$paged&cat=-3");
}
while (have_posts()) : the_post(); ?>

source

Display Page Type Handle – Concrete5

<?php echo $c->getCollectionTypeHandle() ?>

source