Subcribe via RSS

Mischen von Query-Strings und URL-Segmenten

Juli 21st, 2009 | No Comments | Posted in Coding

CodeIgniter ist auf saubere URLs ausgelegt. Das heißt, dass Daten entweder per post durch Formulare oder per URL-Segment übergeben werden. Ein Zugriff auf das $_GET-Array ist in der Standardkonfiguration nicht vorgesehen. Dennoch kann es nötig sein eben dieses $_GET-Array zu nutzen. Eine Suchfunktion kann zum Beispiel ein Grund dafür sein. Zwar könnte der Suchstring auch mit post aus dem Formular übergeben werden, jedoch gäbe es keine Ergebnis-URLs, die z.B. vom Benutzer kopiert werden könnten. Entweder man kodiert den Suchstring mit base64 und nutzt diesen dann als URL Segment, so dass eindeutige URLs entstehen für alle Suchanfragen, allerdings ist diese URL dann natürlich nicht mehr lesbar. Will man lesbare URLs, muss man zwangsläufig auf die Get-Methode zurückgreifen.

Dazu setzt man in system/application/config/config.php den Wert von uri_protocol von AUTO auf PATH_INFO.

$config['uri_protocol']	= "PATH_INFO";

In den Controllern, in denen nun das $_GET-Array genutzt werden soll muss folgende Zeile in den Konstruktor:

parse_str($_SERVER['QUERY_STRING'],$_GET);

Damit kann dann in diesen Controllern ganz normal auf $_GET zugegriffen werden. Dennoch bleiben auch die URL-Segmente aktiviert und können weiter genutzt werden.

Tags: , ,

CodeIgniter error reporting / logging

Juli 20th, 2009 | No Comments | Posted in Coding

CodeIgniter wurde so entwickelt, dass es auf möglichst vielen Servern ohne Probleme läuft. Daher wird die Serverumgebung als unbekannt vorausgesetzt. Einstellungen wie display_error werden daher nicht beachtet. Vielmehr wird bei jedem Seitenaufruf die PHP-Funktion error_reporting aufgerufen. Wer die Einstellungen von error_reporting aber in der config.php sucht, wird vergeblich suchen. Eingestellt wird das error_reporting in der index.php im root-Verzeichnis.

Für den Test- und Entwicklungsbetrieb eignet sich

error_reporting(E_ALL);

Für den Produktivbetrieb, sollte diese Einstellung aber auf jeden Fall in

error_reporting(0);

geändert werden. Generell sollten zwar so wenig Fehler wie möglich auftreten, leider gibt es aber doch immer wieder Unvorhersehbarkeiten, die durch das Error Reporting sensible Daten aufdecken könnten.

Allerdings ist es allein mit dem Error Reporting noch nicht getan, denn Datenbankfehler werden dennoch angezeigt. Um auch diese im Produktivbetrieb auszuschalten muss in system/application/database.php

$db['default']['db_debug'] = TRUE;

in

$db['default']['db_debug'] = FALSE;

geändert werden.

Zwei einfache Handgriffe, die in jedem Fall zur Sicherheit der Applikation und des Servers beitragen und niemals vergessen werden sollten. Am besten aktiviert man, wenn man schon dabei ist in system/application/config.php das Fehler Logging. Dazu wird

$config['log_threshold'] = 0;

auf

$config['log_threshold'] = 1;

gesetzt. So werden alle aufgetretenen PHP-Fehler in system/logs/ geloggt.

Tags: , , ,

BeZoom Lighweight JQuery Zoom Plugin

Juli 20th, 2009 | 9 Comments | Posted in Coding

BeZoom is a simple and lightweight zoom plugin for the wonderful JQuery framework.

Update / Changelog

09.07.29 v0.11

  • fixed overlow:hidden bug in IE6 & 7 when container has position:absolute;
  • changed method to calculate relative mouse position to work in IE
  • chaining of mouseenter, mouseleave and mousemove didn’t work in IE
  • Plugin now works in Opera >= 9, Firefox >= 2, IE >= 7 & Chrome

Demo

To view this script in action simply hover of the following image:

Download

download BeZoom

Download BeZoom v0.11 as zip

Usage

$(document).ready(function(){
	$(".zoom").bezoom();
});

HTML

The plugins works best with images with the same proportions.


<a href="img_big.jpg" class="zoom" title="Your Title">
    <img src="img_small.jpg">
</a>

Options

It’s not neccessary to link directly to the big image. You can also you the rel-Attribute for the preview-image or any other attribute.

$(document).ready(function(){
	var options = {imgSource = 'rel'};
	$(".zoom").bezoom();
});

<a href="some_page.html" rel="img_big.jpg" class="zoom" title="Your Title">
    <img src="img_small.jpg">
</a>

Options Overview

  • Option
    Default Value
    Description
  • marginLeft
    10
    left side margin
  • identifier
    bezoom
    id that is used internally for the bezoom plugin; should not need to be changed as long as you don’t use an “bezoom”-id on your own page
  • height
    200
    height of preview-container; height of title-container doesn’t count
  • width
    200
    width of preview-container
  • titleSource
    title
    Attribute that contains the title
  • imgSource
    href
    Attribute that contains the url of the preview-image
  • bgColor
    #5398EE
    background-color of title
  • color
    #ffffff
    font-color of title
  • size
    0.8em
    font-size of title; you can also use px instead of em

Alternatives

With jqzoom there is a well known alternative to BeZoom, I used some time. But jqzoom in my opinion is much to complicated and confusing. Changing something in this 1000 liner isn’t fun at all. After all jqzoom seems to be a mashup of prototip and lightview.

So I created BeZoom to suit my personal needs. It’s light and it’s easy to use.

If you are using BeZoom let me know it and I’m going to develop some more features for it. If you find any bugs I’d appreciate a short comment so I can fix it.

Tags: , ,

Dynamic SEO Title Wordpress Plugin

Juni 30th, 2009 | No Comments | Posted in Wordpress

The Dynamic SEO Title Wordpress Plugin is an effective yet easy way to boost your sites search engine rankings.

The plugin is based on the idea of Dynamic SEO.

What does the Dynamic SEO Title Wordpress Plugin plugin do?

The plugin automatically optimizes your site over time based on actual values and without guessing. It helps you to get your site as close to perfectly optimized as possible without knowing and having a final result. It adjusts your pages if required.

If there is one on-page important ranking factor that every SEO expert accepts as true, it’s the title-tag of your pages. And it’s not only a ranking factor, it’s even a factor for your click through rates in the serps, because it also appears in the listing.

When you start optimizing your page you start with keyword research. Let’s take a golfing site as the example: golfing-equipment.net What’s the best title for your page about golf clubs? Is it golf clubs, golf club, golfing clubs, golfing club or even golfing equipment? You can use a keyword tool like google.com/insights/search to find out which qould bring in most traffic. But a) this values are estimated and even more important b) you don’t know if you can rank for this phrase and where you currently would get most visitors from.
This is where the Dynamic SEO Title Wordpress Plugin comes into play: You create the page with the “best” title and the plugin adjusts it over time based on the visitors and their search queries.

Installation

  1. 1. Download the plugin
  2. 2. Extract and copy the dynamicseotitle.php file into your wp-content/plugins/ folder
  3. 3. Activate the plugin in your Admin area
  4. 4. You need something like the following code in your header:
    <title><?php wp_title(''); ?><?php if(wp_title('', false)) { ?> |
    <?php } ?><?php bloginfo('name'); ?></title>

    The important part is the wp_title, which is used as hook for the plugin.

  5. 5. DONE!

Download

Current version: 0.1
Download v0.1 as zip
Download v0.1 as rar

Even the customization of the plugin is still missing you can already use the Dynamic SEO Title Wordpress Plugin for your wordpress blog.

TODO

Customization of separator, title length, keywords to use, complete title replacement

Having some wishes for this or another Wordpress-Plugin? Please let me know in the comments!

Custom Wordpress Plugin

Need a custom Wordpress Plugin? Contact me with the form on the left!

Tags: , , , ,

Codeigniter imagettftext() Problem – Could not read font

Juni 23rd, 2009 | No Comments | Posted in Coding

Wer mit Codeigniter (1.7.1) und der PHP-Funktion imagettftext() versucht Text in ein Bild zu schreiben wird – zumindest wenn er eine XAMPP Umgebung unter Windows nutzt – auf seltsame Probleme stoßen.

Trotz korrektem Pfad zur integrierten Schrift, der texb.ttf, tritt nämlich die Fehlermeldung imagettftext: Could not read font auf. Da hilft kein experimentieren oder ändern des Pfades, es hilft nur eine neue Schriftart, denn offensichtlich ist diese Schriftart defekt oder funktioniert unter Windows nicht korrekt (unter Linux habe ich es noch nicht getestet). Massig coole Schriftarten gibt’s übrigens bei dafont. Die neue Schriftart sollte dann im dafür vorgesehenen Ordner system/fonts/ gespeichert werden.

Und hier nochmal ein kleines Snippet, das zeigt wie man dann mit der neuen Schriftart Texte in Bilder schreibt:

// Bild erzeugen, Farbe allokieren
$width = 400;
$height = 100;
$im = imagecreate($width, $height);
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 0,0,0);
 
// schreiben
$text = 'TEXT';
$font_size=60;
$angle=0;
$x=30;
$y=80;
$font_path     = './system/fonts/neue_schriftart.ttf';
imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, $text);
 
// Bild ausgeben
header("Content-type: image/png");
ImagePNG ($im);
ImageDestroy($im);

Ich habe in diesem Fall ein png erstellt. Den Code umzubauen, so dass ein gif oder jpeg erzeugt wird, sollte aber kein Problem sein.

Tags: , , , ,

Umlaute (und Pluszeichen +) in CodeIgniter URLs

Juni 8th, 2009 | No Comments | Posted in Coding

Von Hause aus ist CodeIgniter so konfiguriert, dass keine Umlaute und auch kein Pluszeichen in der URL erlaubt sind. Allerdings lässt sich das in system/application/config/config.php ändern.

Dazu ersatz man die Zeile mit permitted_uri_chars durch das folgende Snippet:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_+\-äöüß-';

Das erlaubt dann URLs auch in einem Format wie controller/methode/ö+ä/. Die Verwendung von Umlauten ist allerdings nicht unbedingt zu empfehlen. Manche Foren und Blogs enkodieren die Umlaute anders, genauso wie manche Browser. Man sollte bei der Verwendung also zumindest darauf achten auch die URLs, die mit UTF-8 enkodiert wurden (z.B. %C3%B6 für ö), entsprechend umzuleiten.

Ganz zufrieden bin ich mit dieser Lösung noch nicht, wer also bessere Ideen für eine Lösung des CodeIgniter-Umlaut-URL-Problem hat, darf diese natürlich gerne hier posten!

Tags: , , , ,