Skip to main content

Posts

Showing posts from 2007

Looping through IFrames using Javascript (ie. js)

I'll just paste some code here. It should be self explainatory... /****************************************************************************************** Requirements: 1. <body onLoad="wt_ad_impression()"> 2. <div id="wt_call"></div> somewhere in body 3. <input type="hidden" id="wt_name" name="wt_name" value="wt.AD" /> at Xigla Edit Banner 4. <iframe></iframe> not <iframe /> for FireFox in Ad Zone Grouping *******************************************************************************************/ var intervalId = 0; var wt_iframes = null; var iframeCount = 0; var iframeIterator = 0; function wt_ad_impression() { alert("called"); wt_iframes = document.getElementsByTagName("iframe"); iframeCount = wt_iframes.length; intervalId = setInterval(wt_collect, 200); } function wt_collect() { alert("in wt_collect"); alert(...

Change the Publishing Path for Uploaded Assets / Embedded Assets

To do this you need to use the assetfilename.asp file. Then: <% 'Place uploaded Poll Questions in the same folder as the 'DesignersPoll.asp file. Needed for Poll to work. poll_question_live_path = "/poll/poll_questions/" 'Loop through right column items to look for Poll type set right_col_list = content.createList("right_col_type") do while right_col_list.nextEntry() if right_col_list.item("right_col_type") = "poll" then 'Check if the current uploaded asset being processed matches and update publishing path if instr(right_col_list.item("poll_xml"), content.item("_cmsRemoteFileName")) > 0 then content.add "_cmsPublishPath", poll_question_live_path&content.item("_cmsRemoteFileName") exit do end if end if loop %...

Duplicate Items in the File -> New menu.

It looks like a bug, but the CMS is trying to figure out what kind of models would apply to the folder in question. To resolve this issue. 1. Goto the problematic folder. 2. Goto View -> Properties -> Access 3. Click on the New Tab 3. Uncheck All 'New Dependency' That's it. That should resolve the problem.

Meta Data in the CMS

When you goto View -> Properties -> MetaData, the form that shows up is treated sort of like a template. You can edit what type of MetaData can be entered by editing the template at /System/metadata.asp. To access the metadata content from within your asset do the following: set meta_fields = asset.getMeta(content.item("_cmsId")) meta_fields.item("title") meta_fields.item("keywords") replace(meta_fields.item("description"), vbCRLF, " ") meta_fields.item("category")

Parsing XML Documents in the CMS: 2 Methods

To start off with do this: Dim txt Dim fieldStart, fieldEnd Dim xml Dim fields Dim ltxt Dim key Dim value txt = trim(content.item("_cmsEmailBody")) ltxt = lcase(txt) fieldStart = inStr(ltxt, "<root>") fieldEnd = inStr(ltxt, "</root>") if fieldStart >= fieldEnd then content.add "_cmsError", "Invalid email format. No XML data detected." exit Sub end if ' skip the end /root fieldEnd = fieldEnd + 6 set xml = system.createXML() if not xml.loadXML(mid(txt, fieldStart, fieldEnd)) then content.add "_cmsError", "Invalid XML format." exit Sub end if Now there are two ways to parse it. Method 1: set fields = xml.selectSingleNodeAsContent("root") Method 2: set fields = xml.selectSingleNodeAsDic("root") Check to make sure we have the root node: if not isObject(fields) then content.add "_cmsError", "Invalid xml format. Missing root /root node." exit Sub end if If Method 1 ...

Http Post in .NET

string result = string.Empty; string strPost = "qf=xml&xml=" + HttpUtility.UrlEncode(xml); StreamWriter myWriter = null; HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(RequestUrl); objRequest.Method = "POST"; objRequest.ContentLength = strPost.Length; objRequest.ContentType = "application/x-www-form-urlencoded"; objRequest.KeepAlive = false; try { myWriter = new StreamWriter(objRequest.GetRequestStream()); myWriter.Write(strPost); } catch (Exception ex) { litResult.Text = ex.Message; } finally { myWriter.Close(); } HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

Parsing XML in .NET

Let's say you have XML as <root>    <item>       <name1>value1</name1>       <name2>value2</name2>       <name3>value3</name3>    </item>    <item>       <name1>value1</name1>       <name2>value2</name2>    </item> </root> To parse it we use the .NET XmlDocument class: // Create the XmlDocument object XmlDocument xmlDoc = new XmlDocument(); // Load the Xml into the object xmlDoc.Load(objResponse.GetResponseStream()); // Get the element like it was a path XmlNode errorNode = xmlDoc.SelectSingleNode("root/item/name1"); if (errorNode != null) { litResult.Text = errorNode.InnerText; return; }

Nesting a Panel within a Tabbed Panel (input.asp)

If you are going to put a panel within the first tab of the Tabbed panel there are no special requirements you need to take. However, if you put the panel within the second tab, it needs to be hidden from view initially. To do this: <% input.startTabbedPanel "Tab 1, Tab 2, Tab 3" %> <% input nextTabbedPanel %> <% set list = content.createList("some_value") %> <% list.setParam "panel_stylesheet", "visibility: hidden; display: none;" %> <% do while list.nextPanel() %> <table> <tr><td>somestuff</td></tr> </table> <% loop %> <% input.nextTabbedPanel %> <% input.endTabbedPanel %> That's it. NOTE: that for the panel_stylesheet line the css needs to have ; at the end or this won't work.

Deleting / Cleaning up Content Fields another Method

Sometimes content.getTable() doesn't work in the post_input.asp file the reason being is that content.getTable() pulls its data from the input.asp file where as asset.getContent() pulls data from the database. So here's the method for deleting old data that could be stuck in the database... set content_fields = asset.getContent(content.item("_cmsId")).getTable() for each itm in content_fields if itm = "somestring or you can do a Regex match here" then asset.deleteContentField(content.item("_cmsId"), itm) end if next

document.getElementByName()

<input type="text" name="somename" value="somevalue1" /> <input type="text" name="somename" value="somevalue2" /> <input type="text" name="somename" value="somevalue3" /> <script type="text/javascript"> var x = document.getElementByName('somename'); // document.getElementByName() returns an array where //x[0].value == "somevalue1"; //x[1].value == "somevalue2" </script> Note: getElementByName() only works for form elemnts if you need other elements a workaround would be to use var element = getElementByTagName() and assign a class to each element then you could look for that class using if element[index].className == "somename".

Referencing Embedded Uploads In Another Asset

This breaks the methodology of embedded uploads in that embedded uploads are only supposed to be used by the asset it is embedded in. If you want many assets to be able to use an upload, you should store that upload in say the /Asset/ Directory. However, there is a way around this, but this is based on one assumption. That embedded uploads get stored in the same directory on the live site as the asset itself. Given this, you can do the following. fileName = list.item("the_upload") // This will return the path and filename to the CMS where the upload is stored. // ie. '/Myhorse/01/02/abc.gif' liveSitePath = asset.getLink(list.item("_cmsId")) // This will return the path and filname to the live site where the asset is stored // With the assumption that uploads get saved in the same directory, just do a // little string manipulation and you got it.

Abstracting Out Content Into a Layout

Heres a pattern that abstracts out common code to a single file and publishes out to the live site as an include file. Think snippet of html that gets included in the big file. 1. Create a layout file in any Template, layout.asp (clone out output would work great) 2. Create a filename.asp that checks for the layout and changes publishing path accordingly. This is so this particular layout has different name from output.asp if content.("_cmsLayout") = "layout.asp" then content.add "_cmsPublishPath", replace(content.item("_cmsPublishPath"), "old_val", "new_val" end if 3. In the template we wish to include this code do this if content.isPublishing then asset.setParam "_cmsLayout", "layout.asp" <!--#include virtual="<% asset.getLink("path to asset that uses template with layout.asp file") %>" --> 'when the asset that asset.getLink() is referring to is published, one is publi...

Making references to Assets work even if the Asset has not been published yet

In the CMS, from within the current asset if you have a link to another asset and the other asset has not been published yet. The current asset will have the link disabled when published. In some cases even content will not be displayed as well. To prevent this from happening you can use this trick: asset.setPram "filter_status", "*" href = asset.getLink("path or id") Now the href will be enabled regardless of whether the asset being reffered to has been published or not.

ExactTarget Setup

There's alot of stuff to do!! 1. Assets that will be published to ExactTarget will use the http_insert.asp and http_update.asp templates. 2. Configure HTTP Export, Package and Workflow to Publish out to the ExactTarget Server Url To Configure the HTTP Export: 1. Goto System -> Configure -> Export -> HTTP 2. Enter an abitrary name. 3. Enter URL http://www.exacttarget.com/api/integrate.asp 4. Method = Post 5. Encoding = XML fields http_insert.asp & http_update.asp uses the same code. Essentially a system.include(http_insert.asp) in the http_update.asp should do the trick: Here is the code for http_insert.asp: <% system.setdependency(false) %><% system.startCapture() %> belvoir belv0!r email add HTMLPaste &![CDATA[ ]]> qf=xml&xml= For a good example of this, MyHorse or MEHC uses this in their Newsletters.

Pagination using Dropdown List or Links for Sorting Generating Multiple Pages From a Single Asset. ie. Dynamic Sorting / Filtering

This is something that is very complicated at the moment. Essentially, what we want to do is create a dynamic sort or filter by xyz. This is handled by the CMS as a generation of multiple static pages for each sort or filter selection. The work will be done in the output.asp file and filename.asp template file. Within the output.asp, the trick is to generate links to each of the individual static pages using: asset.setParam "args", "querystringfield=abc&otherfield=abc" 'create a link back to the same page with the querystring fields attatched to it asset.getLink(content.item("_cmsId") You can then access the querystring fields by using: content.item("querystringfield") content.item("otherfield") the querystring fields get added to the content. On load? (Question that is currently unanswered) Within the filename.asp file, to generate multiple static pages: 'first check if the querystring fields are set if content.item("q...

Checking / Creating New Folders from an SMTP Import

To check if a folder exists in the CMS already you have to create a folder list. There is no direct commands to do this. dim folderExists folderExists = false set folderlist = asset.getFolderList("/path/") 'loop through folder list do while folderlist.nextEntry() if folderlist.item("_cmsLabel") = "foldername" folderExists = true exit do end if loop To create a folder in the CMS, first make a Model that only contains a folder. Then do the following: if folderExists = false then 'create folder set dict = system.createDictionary() fId = asset.create(folderName, "/Site/Global/Picture of the Week/", "/System/Models/Directory Builder", dict) end if The parameters for the asset.create("label", "Path", "Model to use", content or dictionary)

Passing values from Javascript to Asp.Net

The trick to passing data from Javascript and Asp.Net is to use hidden inputs in the html. The hidden inputs should have the runat="server" attribute. For example: <input type="hidden" runat="server" id="hiddenfield" value="" /> Then in the Javascript, whatever value you are trying to pull from Asp.Net, set the hidden field using: document.getElementById("hiddenfield").value = "whatever value you want to set" And in the Asp.net form, you can just access the hiddenfield by using its id. string x = hiddenfield.value.text Thats all there is to it. You might need to check the syntax of it first as this is just all from my head.

Handling / Resizing Multiple / Single Image Uploads

Upload.asp gets called everytime someone uploads somthing into an input template. For a single image upload we can do the following inside the input.asp: <tr> <td>Image</td> <td> <span name="pic_span" id="pic_span"> <% if content.item("image_name") "" then %> <img src=" " /> <% end if %> </span> <% input.setParam "span_label", "pic_span" %> <% input.setParam "show_browse", "link" %> <% input.setParam "show_upload", "attatch" %> <% input.showAcquireImage "image_name", content.item("image_name") %> </td> </tr> If there are multiple images change the above so that all content.items becomes the list object. When createing the list use the image_name as the iterator. Then in the upload.asp: if content.item(...

Creating Multiple Files From a Single Template

Sometimes you need to create multiple files from a single template. For instance, when you have a drop down list that displays certain items depending on what is selected, the CMS handles this by creating multiple files (i.e. different versions of the same page populated with different static content). Since the content is managed by the CMS it would be redundant to have the same information hosted on the clients database server and also the CMS is not capable of generating dynamic pages that pull information from the CMS database itself. I believe the CMS database is closed off to external programs / scripts. So moving along, you create multiple Files by using the filename.asp template file. At this moment I am uncertain how many times or what events trigger the code in the filename.asp to fire. I am aware that you can create a file for every link in the template. One of the things that seems to link the output.asp file and filename.asp is the use of asset.setParam "args"...

The Storage of Content / Uploads Within the CMS

Prior to publishing out an asset to either a live site or a stage site, assets store information within a database or on CrownPeak's local web server. Essentially, an asset only holds Key / Value pairs within the database and any documents or images that were uploaded from an input form gets stored on the CrownPeak's local web server (i.e. A0 - A8). Usually the keys are user defined within the input template and can be viewed by selecting an asset and going to View -> Properties -> Content. Viewing the content, there are several things that probably should be pointed out. Upload#user_defined_name:1 is probably a key in the database. The word Upload in the key specifies that the value for this key is probably a location to CrownPeaks local web server (i.e. the path to where the upload is stored.) When an upload is published out it gets copied from the local web server to the clients server.

Creating an Asset via Email i.e. SMTP Import

In order to create an SMTP Import, you first need to configure it within the CMS. Goto: System -> Configure -> Import -> SMTP Create the import: File -> New Email Import Set it up with these settings: Document User = CrownPeak Admin Folder = Folder to create the asset in. Model = Model that will be used to create the asset Send Errors = Specifies what to do if errors occur. It will give you a token that you need to use in the subject line of your email. It is also possible to use it in the body of the email but I have never tried it. Seems the subject line is more suited for this. Next you need to setup the smtp_import.asp template file: If this asset doesn't depend on the input being recieved, then you can just execute the following a couple of times to populate the asset: content.add "fieldname", "value" However if the asset does depend on the input being recieved perhaps to create an asset in a certain directory depending on the input, you can sto...

Asp.Net C# Sending Email

This entry will describe how to send email using Asp.Net and C#. There will be a couple examples maybe jumbled together, but it will cover these topics: 1. Sending Text Email 2. Sending HTML Email 3. Sending Attatchments First off, specify/import the library you need... Using System.Net.Mail; (CodeBehind) or (Inline) Next create the mail object.... MailMessage mail = new MailMessage(); Then set the mail object fields... (Your usual... To, From, Subject, Body) mail.From = new MailAddress("someone@gmail.com"); mail.To.Add("someone@gmail.com"); mail.Bcc.Add("someone@gmail.com"); mail.Subject = "The Subject Line"; mail.Body = "The Body String"; For HTML email setting a single field will do... mail.IsBodyHtml = true; If you want to add attatchments, do the following... the first argument is a stream and the second is a string for the filename. mail.Attatchments.Add(new Attatchment(FileUpload.PostedFile.InputStream, "filename"); No...