Thumbnail

It seems like everyone these days is texting away on their mobile phone or updating their social network status every 5 minutes. It’s no surprise that the convenience of being able to access the Internet from anywhere at any time has made sharing messages and pictures so popular. I can’t imagine going anywhere without my cell phone on the off chance that something interesting might happen and I can document it as if I were the first news reporter on the scene. This is the first article in a two-part series in which I will show you how to create a photo blog as part of your personal website which you can update from your phone simply by sending an email.

Read the original:
PHPMaster: Creating a Mobile Photo Blog, Part 1

Thumbnail

Just over two years since its move from the antiquated CVS to Subversion (SVN), PHP is once again on the move : this time, to Git . Well, eventually. The migration from CVS to SVN was a huge one and took many months.

Read more here:
PHPMaster: PHP is Moving to Git (Eventually)

547-wordpress-thumbnails

You may have noticed the “Featured Image” box when editing a post or page. It allows you to upload or select an associated image for the article. It generally appears as a thumbnail when viewing a list of posts, perhaps in a category index or search results.

Thumbnail support must be enabled within your theme. You could add it to a plug-in so it’s available to all themes but that may not be appropriate in every case. Therefore, you’ll need to open or create a ‘functions.php’ file within your theme folder (wp-content/themes/theme-name/).

To add thumbnail support for all post types, append this command somewhere after the opening <php:


add_theme_support('post-thumbnails');

Alternatively, you can enable thumbnails for just posts:


add_theme_support('post-thumbnails', array('post'));

or just pages:


add_theme_support('post-thumbnails', array('page'));

Setting Thumbnail Sizes

Default thumbnail sizes can be set in WordPress’s Settings > Media screen. However, you can also set a default height and width in functions.php, e.g.


set_post_thumbnail_size(100, 75);

This will produce thumbnails with 100px width and a 75px height (a pleasing 4:3 ratio). However, what happens when a user uploads an image with different aspect ratio — say 100 x 150? In this case, the whole image is proportionally reduced to fit the space and the resulting thumbnail is 50 x 75.

Alternatively, you can define hard-cropping by passing ‘true’ as a third argument:


set_post_thumbnail_size(100, 75, true);

This will crop the image so it matches the aspect ratio. The resulting thumbnail will always be 100 x 75, but the top and bottom or left and right edges will be removed.

WordPress Featured Image

The “Featured Image” box should now appear on your WordPress post/page edit screen. If it’s not there, check it’s enabled in “Screen Options” or review your functions.php code.

Using Thumbnails

Three main thumbnail commands can now be used within any WordPress loop. Typically, you’ll want to use them in files named index.php, category.php, archive.php, author.php, taxonomy.php or search.php:

  • has_post_thumbnail() returns ‘true’ if a thumbnail has been set
  • the_post_thumbnail() echos a string containing the thumbnail <img> tag
  • get_the_post_thumbnail() returns a string containing the thumbnail <img> tag

One of the simplest implementations is therefore:


if (has_post_thumbnail()) {
	the_post_thumbnail();
}

Or we could add a link and a default thumbnail if one isn’t available:


echo '<a href="', get_permalink(), '">';
if (has_post_thumbnail()) {
	the_post_thumbnail();
}
else {
	echo
		'<img src="',
		get_bloginfo('template_directory'), '/images/thumb-default.png',
		'" width="100" height="75" alt="thumbnail" />';
}
echo '</a>';

Advanced Thumbnail Use

Two optional arguments can be passed to the_post_thumbnail() and get_the_post_thumbnail(). The first is the size — either:

  1. a string containing the text ‘thumbnail’, ‘medium’ or ‘large’ as set in in WordPress’s Settings > Media screen, or
  2. an array with new width and height dimensions, e.g. array(120, 90)

The second is an associative array containing the src, class, alt and title.

For example:


the_post_thumbnail(
	array(120, 90),
	array(
		'src' => 'image.jpg',
		'class' => 'thumbnail',
		'alt' => 'post thumbnail',
		'title' => 'my custom title'
	)
);

results in HTML such as:


<img width="120" height="90" src="image.jpg" alt="post thumbnail" title="my custom title" />

That’s about as complex as it gets. Have fun adding thumbnail support to all your WordPress themes.

WordPress menu

In my previous WordPress posts we discovered how to create a plugin, change the administration panel branding, and remove unnecessary dashboard widgets and meta boxes.

In this post, we’ll make some fundamental changes to the main administration menu. If you haven’t created an initial plugin, please read the first part. Welcome back — let’s begin…

The standard WordPress menu can be a little daunting — and third-party plugins often add further items. You can restrict user roles so clients do not see all menu items but, unless you’re using every WordPress feature, they’ll still see options which don’t apply to their site.

We’ll create a function which removes redundant links and simplifies the experience for your clients. Here’s the full code which you can copy into easy-admin.php:


// remove unnecessary menus
function remove_admin_menus() {
	global $menu, $submenu;
	// main menus removed for all users
	$restrict = explode(',', 'Links,Comments');
	// sub-menus removed for all users
	$restrictsub = explode(',', 'Categories,Post Tags');
	// main menus removed for everyone except administrators
	$restrict_user = explode(',', 'Media,Profile,Appearance,Plugins,Users,Tools,Settings');
	// sub-menus removed for everyone except administrators
	$restrictsub_user = explode(',', 'Updates,My Sites');
	// WP localization
	$f = create_function('$v,$i', 'return __($v);');
	array_walk($restrict, $f);
	if (!current_user_can('activate_plugins')) {
		array_walk($restrict_user, $f);
		$restrict = array_merge($restrict, $restrict_user);
		array_walk($restrictsub_user, $f);
		$restrictsub = array_merge($restrictsub, $restrictsub_user);
	}
	// remove menus
	end($menu);
	while (prev($menu)) {
		$k = key($menu);
		$v = explode(' ', $menu[$k][0]);
		if(in_array(is_null($v[0]) ? '' : $v[0] , $restrict)) unset($menu[$k]);
	}
	// remove sub-menus
	foreach ($submenu as $k => $p) {
		foreach($submenu[$k] as $j => $s) {
			if (in_array(is_null($s[0]) ? '' : $s[0] , $restrictsub)) unset($submenu[$k][$j]);
		}
	}
}
add_action('admin_menu', 'remove_admin_menus');

The lines at the top of this function determine which menu items are removed:

  • $restrict (line 5) contains a comma-delimited list of main menu items which will not be shown to any users — including administrators. In the example above, we’re hiding Links and Comments since they’re not used in our site.
  • $restrictsub (line 7) contains a comma-delimited list of sub-menu items which will not be shown to any user. We’ve disabled Categories and Post Tags which normally appear in the main Posts menu.
  • $restrict_user (line 9) contains a comma-delimited list of main menu items which are hidden to everyone except administrators. The example above disables everything other than the Dashboard, Pages and Posts. (Non-administrators would not normally see Appearance and Plugins, but other plugins could change that functionality).
  • $restrictsub_user (line 11) contains a comma-delimited list of sub-menu items which are hidden to everyone except administrators. We’ve disabled Updates and My Sites which normally appear within the main Dashboard menu.

simplified WordPress menu

If you don’t want any items removed for a specific value, set it to an empty array, e.g. $restrict = array();

The result is a far simpler administration menu which is free of dangerous options which could confuse your clients.

Thumbnail

Sometimes the functionality of a library or set of classes that you’re working with is 99% perfect for the job, but the last 1% requires modification of some of the core assumptions made in the code. Altering code can cause maintenance frustrations down the track and extending code can cause maintenance frustration right away, but Ruby provides us with a flexible way to modify code with less damage. In converting to Ruby I realized how strict PHP is in its class hierarchy.

View original post here:
RubySource: Confessions of a Converted PHP Developer: Animal Abuse

framework image

There’s no doubt that web frameworks have exploded in popularity over the past few years, and while it’s likely that a large part of that growth can be attributed to Ruby on Rails, the outpouring of MVC frameworks in other languages is no less impressive.

If you’re a PHP ninja, and not a die-hard Rubyist, you may be wondering what options are out there and which framework is right for you. The answer depends on a number of factors, and today we’ll review the questions you should be asking when choosing a PHP framework for your next application.

We’ll also take a look at popular PHP frameworks and what sets them apart. That way, you can make an informed decision on which framework best suits your project — or if you should even use a framework at all.


Determining Your Needs


Before you can decide on a framework for your project you should first understand its needs, its requirements, and a little about the development team working behind the scenes. There are three main questions to ask yourself before going forward:

  • What’s the primary focus of your application? Will it be an ecommerce business, a social community, a messaging platform or a directory? If you’re building an ecommerce site, for instance, you may want to choose a framework with some baked-in libraries with proven extensions for dealing with credit card processing. On the other hand, a lightweight messaging platform may need to scale very rapidly or use multiple servers and databases for load balancing and faster connectivity.
  • What will your hosting environment be? Some frameworks require additional PHP modules or software installation on the server, which may not be an option in shared hosting environments. Furthermore, a lightweight framework on which everything is self-contained and highly portable may not provide the best functionality for serious data manipulation or large information processing. For example, some frameworks work best with MySQL, while others include libraries for working with key-value and document store databases, for example.
  • What are the strengths and weaknesses of the developer(s)? It’s important to get a sense of the skills and shortcomings of the developer(s) who will actually be building and maintaining the application. Some frameworks are more user-friendly and better for beginners. While the answer to this question probably shouldn’t be a deciding factor (learning new things is good), it is definitely one to take into account given your timeline, budget and security considerations.

The Frameworks


Now that we’ve looked at some of the basic requirements of your application and the dev team behind it, let’s examine some popular PHP frameworks and see what each one has to offer.

Cake PHP

If you still need to write PHP4 compatible code, CakePHP is a great option. This PHP 4 & 5 MVC framework is one of the oldest and most popular on our list. Cake PHP has built up a reputation as a formidable and capable framework. It also has many avenues for support (groups, message boards, IRC) and excellent tutorials. CakePHP is a good framework that’s easy to get into but one that you won’t outgrow in a couple of weeks.

CakePHP’s conventions are fairly strict, however, and it’s not the most flexible framework available. This could be a plus if you want to guarantee consistency across the application regardless of the user. There are also built-in tools for unit testing, XML-RPC and feed parsing for integration with web services as well as scaffolding for rapid prototyping.

Zend Framework

The Zend Framework is for more experienced developers and those building enterprise-level applications. The framework is highly modular, meaning you can use as little or as much of the Zend code as you need. Several libraries can easily be extracted for stand-alone use. With Zend, you’re not tied to the MVC pattern (though it is certainly an option), and there is a lot of built-in support for tasks such as integration with existing web services, localization and extensive unit testing.

Zend requires PHP 5.1.4+ but has multiple configuration options and excellent documentation. It’s a framework with corporate backing and a strong community. You’ll get long-term stability and fairly quick integration of new features, not to mention security updates tested by a team of professionals. While the Zend framework may be a large overhead for small projects, if you’re building large-scale applications it is typically considered the framework of choice.

CodeIgniter

CodeIgniter is (as of v2.0) a PHP5.2+ MVC framework with a small footprint and great documentation. Often called a “beginner” framework because of its relative ease of use and short learning curve, CodeIgniter is nonetheless flexible and powerful. The framework has a large community surrounding it, so it’s fairly easy to find an existing CI library for just about anything you could dream up. If you need to do it, chances are, someone out there already has.

CodeIgniter is best suited for content sites and small-to-medium web applications. You’ll likely see a performance drop with very large numbers, but there is some built-in caching to help with that. If you’r
e new to PHP frameworks or want something that can be picked up and learned in a few hours, CodeIgniter is one of the top frameworks to consider.

Symfony

Symfony is one of the oldest PHP frameworks, and is designed for enterprise-level web applications. For all its power and performance, however, Symfony has a small footprint and is easy to configure on a variety of PHP hosting environments. Since it’s been around for so long, you’ll find a lot of tutorials and books available on framework use, a perk for new users.

Symfony uses command line generators for quick project setups and automatic code generation, which may be new to some developers. However, they allow you to get up and running with your code in very short order. If you feel intimidated by this, don’t worry. The Symfony’s web site has a large collection of tutorials, showcase applications and screencasts to get you going.

The framework has all of the advanced features you’d expect of a system designed for the development of enterprise software. For example, it offers internationalization, URL routing, test suites, a robust templating engine and a powerful plug-in API for extending Symfony’s features, or adding your own.

Kohana

Kohana began as a fork of CodeIgniter, though it’s much more than a simple branch off. Like CI, Kohana strives to be a lightweight, easy-to-use framework that performs well for small-to-medium web applications and custom content management systems.

Unlike CodeIgniter, Kohana requires PHP 5.3. The developers have taken advantage of this by including some advanced functionality not present in Codeigniter. The 5.3 requirement also means less code can accomplish some of the same tasks with less concern over backwards comparability. While Kohana’s documentation is a little lacking, it tends to implement features more cleanly. The community is active, so getting help shouldn’t be an issue.

Yii

Yii is a highly modular, high-performance PHP5 framework designed specifically for developing web applications. Yii uses a lot of command line generators and tools to get you up and running quickly; therefore, it’s best used by people that aren’t intimidated by a terminal window. All those generators mean more commands to memorize, but once you do, you’ll find that they greatly decrease the time it takes to set up and configure your application.

It’s easy to extend Yii and add in your favorite third-party libraries. Yii also supports templating, themes and widgets, and includes tools for testing, libraries for internationalization and web service integration. Yii’s performance is good and the automatic code generation makes it a great framework for rapid development. The framework is well-documented, but since so much of the work is done at the command line, it can be intimidating to some users.


Image courtesy of Flickr, baldiri

More About: dev & design, framework, php, php framework, web, Web Development

For more Dev & Design coverage:

It started with a tweet Saturday morning, sounding an alarm of a security breach in the popular microblogging platform Tumblr. “OMG… The Tumbeasts are spitting out passwords!,” it warned.

That tweet spread like wildfire, notifying the world of a coding error that opened a security hole with the potential of revealing users’ passwords, server IP addresses, API keys and personal information.

Fortunately, Tumblr reacted, fixing the problem and then issuing this official message about 5 to 6 hours after the flaw was discovered:

“A human error caused some sensitive server configuration information to be exposed this morning. Our technicians took immediate measures to protect from any issues that may come as a result.

We’re triple checking everything and bringing in outside auditors to confirm, but we have no reason to believe that anything was compromised. We’re certain that none of your personal information (passwords, etc.) was exposed, and your blog is backed up and safe as always. This was an embarrassing error, but something we were prepared for.

The fact that this occurred at all is still unacceptable, and we’ll be seriously evaluating and adjusting our processes to ensure an error like this can never happen again.

Please let us know if you have absolutely any questions.”

What caused the error? That’s still under intense discussion at The Hacker News and elsewhere in the hacker community, but many think the culprit was a errant piece of PHP code. Obviously, spelling counts.

Let us know in the comments if you think those who discovered the security flaw were more eager to broadcast its existence than notify the Tumbler coders who might have been in a position to quickly fix it.

More About: Breach, flaw, php, security, tumblr

For more Dev & Design coverage:




The Web Development Series is supported by Rackspace, the better way to do hosting. Learn more about Rackspace’s hosting solutions here.

This year brought quite a few headlines of note to the developer world. While we each have our favorites, from new releases of classic tools to astounding announcements from tech companies, here, in no particular order, are a few stories that stood out to us this year.

In the comments, we’d love to know what stories stood out most to you this year, partly to indulge our sense of gratuitous end-of-year nostalgia and partly to help us hone our coverage for 2011, when we hope to bring you more fascinating web dev news than ever before.

What were your favorite dev-related headlines of 2010?


1. The Release of Rails 3.0


Early in February, the Ruby on Rails core team took the wraps off Rails 3.0, a long-awaited release of the popular Ruby framework.

Rails creator David Heinemeier Hansson wrote on the Rails blog, “We’ve had more than 250 people help with the release and we’ve been through almost 4,000 commits since 2.3 to get here. Yet still the new version feels lighter, more agile, and easier to understand.

“It’s a great day to be a Rails developer.”


2. Salesforce’s Acquisition of Heroku


Earlier this month, Salesforce bought Heroku for a staggering $212 million, giving another token of legitimacy to the growing Ruby community as well as to cloud-based programming tools.

Salesforce CEO Marc Benioff said at the time, “The next era of cloud computing is social, mobile and real-time… Ruby is the language of Cloud 2, and Heroku is the leading Ruby application platform-as-a-service for Cloud 2 that is fueling this growing community. We think this acquisition will uniquely position Salesforce.com as the cornerstone for the next generation of app developers.”


3. Facebook’s Release of HipHop for PHP


In February, Facebook rolled out HipHop, an internal open-source project intended to speed up PHP for large-scale applications.

HipHop isn’t quite a compiler. “Rather,” wrote Facebook engineer Haiping Zhao, “it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it.”

The project was the culmination of two years of work by a small team of engineers; in the end, it got a thumbs-up from PHP creator Rasmus Lerdorf, who said, “I think it is a cool project and it will certainly be a good option for some sites.”


4. The Rise of Node.js


Node.js has been around for a couple years, but 2010 was the year awareness and use of the JavaScript framework really blew up.

Commits have grown, as have the number of committers. Traffic to the project website has steadily climbed through the year, and downloads for Node.js from GitHub have predictably grown, as well.

As the organizers of the annual Node Knockout wrote, “It’s at the bleeding edge of a technology stack that allows developers to blur the lines between software, the web and the new like never before.”


5. Microsoft’s Release of Visual Studio 2010


The latest version of Microsoft’s Visual Studio, a big release by any standards, launched this year to impressive reviews from all corners of the web. InfoWorld said the release “marks a major advance in functionality and ease,” and The Register wrote, “It is hard not to be impressed by Microsoft’s tool suite.”

The IDE was overhauled, completely rewritten from the ground up. Support for Silverlight was added, and Microsoft also took this opportunity to release F#, a new programming language developed by Microsoft Research.


6. Facebook’s Release of the Open Graph API


Facebook and social app developers have long wrestled with Facebook integration for third parties. In the spring at its f8 developer conference, Facebook rolled out a brand new model for tapping into the social web, and it did so to unprecedented fanfare.

Dubbed the Open Graph, Facebook’s changes brought instant gratification and familiarity for Facebook users as they surfed the web — and they brought a fast and easy way for devs to integrate with the social network, as easy as a single line of HTML in many cases.


7. The Android/Java/Oracle Saga


What a year it’s been for Java! Not only is the language a key part in the programming stack of the fastest-growing mobile OS out there; it’s also the star of a big, potentially spendy lawsuit between two of the giants of the tech industry.

Sun, which developed the language in-house back in the dark ages, was acquired by Oracle. That deal became official in January, and Oracle wasted no time in getting litigious with Google over that company’s use of Java in the Android platform and the Dalvik virtual machine that stands in for the JVM on mobile OSes.

The lawsuit began in August with Oracle claiming that Google “knowingly, directly and repeatedly infringed Oracle’s Java-related intellectual property.”

Google quickly countered that it was shocked — shocked! — that Oracle would make such claims over an open-source technology. It followed with the assertions that Oracle’s patents are unenforceable and that if there had been “any use in the Android platform of any protected elements” of Java, Google itself “is not liable” due to the fact that such violations would have been committed by third parties and without Google’s knowledge.

We’ll continue to keep an eye on the lawsuit and on Java’s role in the Android platform throughout 2011.


8. Apple Declares War on Flash


Tensions between Apple and Adobe ran high this year, beginning in January when the iPad launched without support for Flash. Then in February, Apple co-founder Steve Jobs told employees why: “No one will be using Flash. The world is moving to HTML5.”

These were the words that launched a thousand blog posts. Throughout the spring, the two companies waged a war of words — and one sweet antitrust inquiry with the Department of Justice over Apple’s banning of Flash for iPhone app devs.

Steve Jobs dropped the bomb of the year in a passive-aggressive missive on Flash in which the Apple co-founder stated that Adobe’s programming technology is “no longer necessary” and waxed hypocritical about open technologies.

But while he may have been passive aggressive and hypocritical, he also may have been right. With HTML5 making a strong showing early in its lifetime, it was only a matter of time before a public figure of Jobs’s stature would make a statement or two about the death of Flash.

Of course, this tension has made for a convenient cozying-up between Google and Adobe along the way.


What Are Your Picks?


Again, let us know in the comments what your favorite stories of 2010 were — and Happy New Year from the geeks at Mashable!

With special thanks to our Twitter friends who made suggestions for this list: Jordan Runnin, Leon Gersing and Jeremy Bray.

More About: 2010, developers, heroku, hiphop, java, News, node.js, php, programming, rails, ruby, visual studio, Web Development, web development series

For more Dev & Design coverage: