Web Development

...now browsing by category

 

Drupal 6 Social Networking

Saturday, April 18th, 2009
Drupal 6 Social Networking is one of the lastest publications addressing the use of the popular open source content management framework.

Drupal 6 Social Networking is one of the lastest publications addressing the use of the popular open source content management framework.

I’ve fought it for a long enough time, but I’m finally taming my dislike of Drupal.  I’ll admit - its mostly because I’m now using it for what it is - a framework and not as a content management system.  Now I seem to be growing as a Drupler.  Fast-foward to a few weeks back: I was browsing about Amazon and came across Drupal 6 Social Networking.  After reading the entire book in a few days, I felt it deserved a review.

Drupal 6 Social Networking is written to reach a wide audience - from programmers to content administrators, no matter the level of experience.  It is authored by Michael Peacock of Peacock-Carter, a web developer from Newcastle, UK.

The book is broken down into 10 chapters, ranging from an introduction to drupal and social networks, installing drupal, using the framework to create the functionality desired, and even into web site promotion.

The highlights of this book is that is an easy read and is written for those that are not exactly sure of what certain features relate to in the system.  For example, have you ever wondered what the full use of Taxonomy is in Drupal?  Peacock has a casual writing style that gets directly to the point, accompanying his writing with on-point visual examples to add visual detail to his writing.

If you are new to the Drupal framework, this book will guide you from installation to project setup.  If you are seasoned with the framework, but not exactly sure how to make the best of specific modules to get the performance / functionality you need, this book will enlighten you with which module to use and why to use it.

Overall, this is a worthy purchase that gets directly to what the title states - drupal 6 and social networking.  This mean, you guessed it, Michael directly focuses on how drupal can be used to build a social network and he doesn’t slide off topic in doing so.

For those interested:

5-for-1 Deal from SitePoint - profits going to victims of Australian bushfires

Thursday, February 12th, 2009


SitePoint Special Sale

Just thought I’d pass this awesome offer along to those that read the blog.

SitePoint is offering a deal to get 5 of their books in PDF format for only $29.99.

The beauty of it is that the proceeds are going to be donated to the victims of the Australian bushfires.

I’ve read a few of the books and some are hit or miss.  I definitely recommend:

Check it out, its for a good cause!

jQuery turns 3 with the release of jQuery 1.3

Friday, January 16th, 2009

jQuery
January 14th, 2006 brought to the development world what would soon become one of the most influential javascript frameworks.  jQuery, the write less, do more framework, has since taken on a life of its own and is now used by many web sites today, from Google, to Dell, and even Virginia Tech.

Happy Birthday jQuery!

Quickie - Import Database to MYSQL via SSH/Linux

Friday, December 12th, 2008

Here is a quickie for importing an sql file to mysql on linux….

mysql -u -p dbname < sqlfile

Example

> mysql -u root -p wordpress_db < "/home/webster/backup.sql"
> Enter Password:

And there you have it…

MYSQL Backup Quickie

Saturday, November 22nd, 2008

Okay, due to timing I will be adding very quick tutorials/notes for myself.  Selfish I know, but it could prove to be of use to starters as well.

If you have your SSH handy + access to working with your database, run the following command to backup your database.

mysqldump -username -password databaseName > nameoffile.sql

So, for example - if you have a root account with the password Password and a database named MyDB and you wanted to call the backup MyDBBackup.sql and save the file into your /home/username directory.

mysqldump -root -p MyDB > /home/username/MyDBBackup.sql

Simple Javascript to Combat Spam

Monday, August 25th, 2008

Before you read any further, take into context this isn’t going to fully help you in terms of lessening your spam. However, it is a neat trick and will help some, or at least deter some spamming bots from picking your e-mail address and using it for spam.

While at work today I was performing some maintenance on a project that was handed to me and I noticed a tiny bit of javascript used to print an e-mail address, but by doing so kept it seperate and not connected.

<script type="text/javascript">
    emailE=('roberthash@' + 'yahoo.com')
    document.write('<A href="mailto:' + emailE + '">' + emailE + '</a>')
</script>

What you see first is that a variable is assigned two values that are added together. By splitting the e-mail into two pieces (in theory), this will assist in deterring spam bots searching for a valid e-mail address.

emailE=('roberthash@' + 'yahoo.com')

From there we utilize the document.write() function to print this text to the browser window.

document.write('<A href="mailto:' + emailE + '">' + emailE + '</a>')

Another beautiful part is that if Javascript is not installed, this means there won’t be an e-mail address showcased. However, this could be a pain if you have someone trying to find your e-mail address that has a legit reason to contact you - but doesn’t have Javascript.

As usual, it is a method to be used at your own risk or if you feel it is indeed the solution for your project.

With further research, I have found the origination of this code, which can be found at http://www.joemaller.com/js-mailer.shtml.

As you can see - it is a very simple approach that even a novice programmer can understand. Who says you can’t learn new tricks?

Populating TextBox with Date via C#

Friday, August 22nd, 2008

I have found through my web application development experience that it can be quite the pain if someone messes up a date. This is a huge headache for reporting purposes.

Methods to get around this can be one of many things. Validation for example simply forces the user to put in a date before they can submit information. Who is to say they are putting in the right date anyway? The ASP.NET calendar control is nice, as it gives a calendar and allows the user to pick a date. One method that I have found to work quite nicely for data that is entered for a day is to have the date set automatically.

What would be a scenario for this? The ideal setting is to track a date when an action is committed. Examples include form submission (no-brainer), requests, updates, etc.

For example, let’s say we have the following form:

<form runat="server">
  <asp:Textbox ID="dateBox" runat="server"></asp:TextBox>
</form>

Now, using the code behind file, we can write a simple line of code to send today’s date straight to the dateBox ASP Textbox upon the loading of the form.

With an aspx file, in the code-behind we can add an attribute to the Page_Load method to autopopulate a date (or set any value - same premise). Below we will set it within an IF statement for when the page posts back:

protected void Page_Load(object sender, EventArgs e)
{
  if (!Page.IsPostBack)
{
  // This will happen upon a postback
  dateBox.Text =DateTime.Today.ToString("MM/dd/yyyy");
}

Or you can set the value in outside of the PostBack IF statement:

  dateBox.Text = DateTime.Today.ToString("MM/dd/yyyy");

As you can see, that simple line of code will send today’s date straight to the textbox without the user having to enter it. We have included it in the page load portion to see that it fires upon, as you guessed it, the loading of the page/form. To break it down further, we can add some pretty neat attributes to the code to produce other effects:

If we want to add tomorrow’s date, we can use .AddDays(+1)

  DateTime.Today.AddDays(+1).ToString("MM/dd/yyyy");

If we want to add yesterday, we can use .AddDays(-1)

  DateTime.Today.AddDays(-1).ToString("MM/dd/yyyy");

Want to populate a year? You can use the same premise. As Nico VanHaaster has pointed out, you can call the AddYears() method to combat leap year occurances:

  DateTime.Today.AddYears(-1).ToString("MM/dd/yyyy");

As one can see, it’s a very simple approach to solving a problem with user’s entering a date and becoming frustrated if they have to do this more than once (such as they enter this data after each task on a given day).

Happy Programming!

Png Fix for IE 6.0

Friday, August 22nd, 2008

For those of us that enjoy using PNG graphics in our layouts, it is common knowledge that Internet Explorer is a point of frustration in the entire process.

Fortunately javascript can be utilized to assist in this matter. Be sure to use the defer type.

<html>
<head>
<!--[if lt IE 7.]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->
</head>
<body>

For an example of the javascript one could use to show the PNG format in IE6, check out the link below:

Populate DropDown List with MySQL and PHP

Friday, August 22nd, 2008

Drop-down lists have long been a form designer’s friend in terms of packing a lot of choices into a single area. The maintenance of these however can become tedius over time if you must continually update the list.

In the static Web 1.0 days, we would have coded each option in the list. Fortunately through the use of a server-side language and a database we can make this a lot more efficient.

In this example I will showcase how to do this in PHP. For those that use ASP.NET, I’m pretty sure you are accustomed to the drag-n-drop capabilities of Visual Studio, where you simply drag-n-drop and set your connection settings accordingly.

In PHP however, it is a little more work. In the following I will have assumed you already have a table named states created with 3 columns (I used state_id, state, state_abbr - *If you haven’t created the table, Kim Briggs has a wonderful sql example at http://kimbriggs.com/computers/computer-notes/mysql-notes/mysql-create-state-table.file .*

I will also assume that you have already connected to the database in your file.

We will begin first by creating a variable which will hold our SQL query. From there we will create a variable that will hold the result.

<?
$query="SELECT * FROM state";
$result = mysql_query ($query);

Then we shall begin the drop down list:

echo "<select name='state' value=''>State</option>";

And we will use a while statement to create an array to cycle through the results printing HTML options for each item. As you will see, we will be binding the columns to the values that we want to print on the page.

while($myfetch=mysql_fetch_array($result)){
echo "<option value=$myfetch[state_id]>$myfetch[state_abbr]</option>";
}

From there we will close the list and the PHP file.:

echo "</select>";
?>

And for the code in its complete form:

 <?
  //Create SQL Query
  $query="SELECT * FROM state";
  // Variable for results
  $result = mysql_query ($query);
  // Begin select tag
  echo "<select name=state value=''>State</option>";
  //Return each result
  while($myfetch=mysql_fetch_array($result))
  {
     echo "<option value=$myfetch[state_id]>$myfetch[state_abbr]</option>";
  }
  //End select
  echo "</select>";
?>

Easy enough huh? Do note that with the query, we can control how the results are printed (IE alphabetical, by id, etc.). This can be used for a variety of fields, from states to categories.

Dynamically Populating a DropDownList with C#

Wednesday, August 20th, 2008

Okay, out of fairness I thought I would post the same tutorial for my favorite dynamic duo - ASP.NET and C#. We will assume we are using the same database name or table name. We will work with a asp:DropDownList control such as:


<asp:DropDownList id="state" runat="server"></asp:DropDownList>

We will create a method called StateDropDown:

private void StateDropDown()
{
}

From there we will define our connection settings - typically what we have set in the web.config file.

SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySettings"].ConnectionString);

From there, much like the PHP example, we will create an SQL query that will scope the database table to populate the dropdown. We will assume i’m connecting to a database named info and a table named state.

string Sql = "SELECT * FROM info..state";

Now for the fun of C# - creating a dataset, filling the dataset, then applying that dataset to your asp:dropdown control.

SqlDataAdapter sqlAdapter = new SqlDataAdapter(Sql, Con);
DataSet ds = new DataSet();
sqlDA.Fill(ds);
state.DataSource = ds.Tables[0];
state.DataTextField = "state_abbr";
state.DataValueField = "state_id";
state.DataBind();
}

And now for the unmolested code:

private void StateDropDown()
{
//Define your connection
SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySettings"].ConnectionString);
//Create your SQL query/string
string Sql = "SELECT * FROM info..state";
SqlDataAdapter sqlAdapter = new SqlDataAdapter(Sql, Con);
DataSet ds = new DataSet();
sqlDA.Fill(ds);
//Define which control will accept this dataset
state.DataSource = ds.Tables[0];
state.DataTextField = "state_abbr";
state.DataValueField = "state_id";
//Bind the dataset to the control
state.DataBind();
}