Blog Tags

Lab Eleven Blogs

A short description about your blog
Tags >> Programming

How to create a marquee text for an iPhone app

Posted by: twmeier

Tagged in: Programming , iPhone

In this blog, you will learn how to create a moving text field (also know as a marquee). Marquees are very convenient to show news, stock updates, sport scores etc..


In the .h file:
#import
@interface FirstViewController : UIViewController {

UIView *messageView;
UILabel *lblTime;
CGSize messageSize;
}
@end


In the .m file:

- (void)viewDidAppear:(BOOL)animated {    
NSString *theMessage = @"Hello, my name is Enigo Montoya. You killed my father, prepare to die";
messageSize = [theMessage sizeWithFont:[UIFont systemFontOfSize:14.0]];
messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, messageSize.width, 19)]; //x,y,width,height
[messageView setClipsToBounds:YES]; // With This you prevent the animation to be drawn outside the bounds.
[self.view addSubview:messageView];
lblTime = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, messageSize.width, 19)]; //x,y,width,height
[lblTime setBackgroundColor:[UIColor darkGrayColor]];
lblTime.font = [UIFont systemFontOfSize:14];
[lblTime setText:theMessage];
[lblTime setTextAlignment:UITextAlignmentLeft];
lblTime.frame = CGRectMake(0, 0, messageSize.width, 19); //x,y,width,height
[messageView addSubview:lblTime];
float duration = messageSize.width / 60; // This determines the speed of the moving text.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:messageView cache:YES];
lblTime.frame = CGRectMake(-messageSize.width, 0, messageSize.width, 19); //x,y,width,height
[UIView commitAnimations];
}

Thats all there is too it. Check out the comments in the code for further clues on how it works.


Joomla 1.5 Custom Breadcrumbs

Posted by: gbluma

Tagged in: Programming , PHP , Joomla , Components

Joomla seems to have everything figured out — Breadcrumb support is no exception.

Recently we were writing some custom component for a client and needed to handle the breadcrumbs in a special way that Joomla couldn't manage automatically.

As a simplified example, imagine we redirect a user to a component that isn't attached to a menu. We would expect the breadcrumbs to simply output "Home" and provide a link back to the index of the site.


Joomla 1.5 Database Functions

Posted by: twmeier

Tagged in: Programming , PHP , Joomla

Sometimes it may be hard to know how to best use Joomla's database class. Here are just a few of the most used database functions.

In Joomla 1.5, include the following line of code inside your php:

<?php
     $database  =& JFactory::getDBO();
?>

Use the $loadObject function when you want to retrieve one row from the database. For example:

$database->setQuery("SELECT * FROM jos_comprofiler WHERE id=125");
$userDetails = $database->loadObject();

You can now access the values as follows:

$userDetails->firstname
$userDetails->lastname
.....

If you want to retrieve more than one row from the database, use the loabObjectList() function. For example:

$database->setQuery("SELECT * FROM jos_comprofiler WHERE id<125");
$userDetails = $database->loadObjectList();

You will now have an array of objects. You can access the values as follows:

$userDetails[0]->firstname
$userDetails[0]->lastname
$userDetails[1]->firstname
$userDetails[1]->lastname
.....

If you want to retrieve a single value from the database, use the loadResult() function. For example:

$database->setQuery("SELECT COUNT(*) FROM jos_comprofiler");
$count= $database->loadResult();

You now have a regular php variable. In this case $count.

There are other Joomla database functions, but these three are the most common.


XMLWriter in PHP

Posted by: gbluma

Tagged in: XML , Programming , PHP

Every now and then I find myself needing to export a set of objects to XML. I usually find a quick way to write a dumb function to do it, but this is usually not the most elegant solution and rarely does it scale up to handle more complex data structures. The other option is to serialize the data into xml, but usually these methods suffer from a large performance overhead and should only be used if you can tweak the serializer to work only the right pieces of data.

I have since added XMLWriter to my toolset. Which, oddly enough, is built right into PHP (as of version 5.1.2) and based on the widely popular libxml engine. I find it to be very quick, both in performance and in ease of programming. Best of all, the code makes more sense than any of any of my own homemade tools.

Here's an example where demonstrate how to export a list of products to xml:


Changing Page Title and Meta Info in Joomla

Posted by: twmeier

Tagged in: Programming , Joomla , Components

Changing the Page Title and the Meta Tags (keywords and description) in a Joomla Component is simple (this does not apply to articles or the home page of your site).

The first step is to include the following line of code inside php tags:

global $mainframe;

Then simply use the following functions to change the Page Title, Meta Keywords and the Meta Description:

$mainframe->SetPageTitle("Some Page Title");
$mainframe->appendMetaTag( "description", "Some Description.");
$mainframe->appendMetaTag( "keywords", "keyword, keyword2");

Since this code is php, it should all be inside php tags like it is below:


global $mainframe;

$mainframe->SetPageTitle("Some Page Title");
$mainframe->appendMetaTag( "description", "Some Description.");
$mainframe->appendMetaTag( "keywords", "keyword, keyword2");

?>

That is all there is too it. You will notice that your Meta Description and Keywords will be appended to your global Meta Description and Keywords, which can be found in the "Global Configurations" in the backend of Joomla.


Parsing an XML string retrieved using AJAX

Posted by: twmeier

Tagged in: XML , Programming , PHP , Javascript , Ajax

While working on an AJAX function this week, I found the need to parse an XML string using JavaScript and PHP. The following JavaScript was used to retrieve an XML string from a PHP file:

function someJavascriptFunction() {
      xmlHttp=GetXmlHttpObject();    
      url = "/components/com_component/ajax/ajax.php?task=someTask";    
      url += "&cc_number="+document.getElementById('cc_number').value;
      xmlHttp.open("GET",url,true);    
      xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState == 4)  {       
           xmlDoc=loadXMLString(xmlHttp.responseText);
           var response = xmlDoc.getElementsByTagName("response")[0].childNodes[0].nodeValue;
           document.getElementById("someID").innerHTML = response;
     }
     xmlHttp.send(null);
}

function GetXmlHttpObject()    {
      var xmlHttp=null;
      try {
           // Firefox, Opera 8.0+, Safari
           xmlHttp=new XMLHttpRequest();
      }
      catch (e) {
           //Internet Explorer
           try {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
           }
           catch (e) {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
           }
      }
      return xmlHttp;
}

As you can see from the code above, the XML field I was interested in was the "response" field. The XML string that was created and passed using xmlHttp.responseText from the PHP file looked similar to this:

<authorizationResponse>
      <message>Some Message</message>
      <response>Some Message</response>
....
</authorizationResponse>

Not only did I need to parse the XML from the  responseText in javascript, but I also need to parse it inside the PHP function that the JavaScript function called. The XML above was retrieved from a payment gateway in the PHP function using CURL and naned $xmlString.

The only field I needed in the PHP file was the "message" field, and to retrieve it, (or any other field), I did the following in the PHP file:

$xml = new SimpleXMLElement($xmlString);
$message = $xml->authorizationResponse->message;

Don't forget you still need to echo out the entire XML string in your PHP file order to be used by your JavaScript function:

echo $xmlString;


Writing a Joomla 1.5 Content Plugin

Posted by: gbluma

Tagged in: Programming , Plugins , PHP , Joomla

This article will show you how to build a quick plugin to replace some text in an article before it get's displayed to the user.

Intro

Lately I've been writing a number of content plugins for Joomla. They're pretty simple, but basically it allows you to transform the content at a number of points in Joomla's process of editing, saving, and displaying of that content. In theory you could use it to do anything but it's common to replace text and/or add special content into the articles.

I used to frown on these types of plugins because it's better to just get the data right in the first place. But sometimes controlling the input just isn't possible or perhaps you need to keep the article in a certain format but display it in another format.


Joomla 1.5 Custom Parameter Type (WYSIWYG)

Posted by: gbluma

Tagged in: Programming , Joomla

joomlaJoomla has made module development a piece of cake. If you want a section of your module to display a poll or banner it's really easy. Likewise Joomla has made it easy to edit the content in those modules with module parameters.

... But one thing you haven't been able to do is edit those parameters in a WYSIWYG textarea... until now...


Joomla HTTPS Redirect Plugin (Beta)

Posted by: gbluma

Tagged in: Programming , Joomla

The HTTPS Redirect Plugin redirects a visitor to the same page under HTTPS.

When a user requests a url over HTTP (e.g. http://example.com/secure/stuff/ ) Joomla will handle the redirection to the appropriate HTTPS page (e.g. https://example.com/secure/stuff/ )


There are times when you may not want the ability to edit a Virtuemart product from the front end. This may be due to a poorly designed template that just doesn't work well with this feature.

To remove the edit button from the product detail page, you will need to open the following file:

/administrator/components/com_virtuemart/html/shop.product_details.php


<< Start < Prev 1 2 Next > End >>

Latest Blogs

Fix Bad Credit With These Helpful Tips
Feb 26th 2013 by: Administrator

Will iPhone Apps Run On iPad?
Jan 29th 2010 by: Trevor M.

How to create a marquee text for an iPhone app
Jan 21st 2010 by: Trevor M.

How to Submit Additional Images in Virtuemart
Aug 7th 2009 by: Trevor M.

Using an Image as a Submit Button in HTML
Jul 31st 2009 by: Trevor M.

Read all blogs