Categories
Joomla!

SEF URLs cause access problems in Joomla!

Frank Summers reports a solution for a problem which causes pages to become inaccessible on a Joomla! site when Search Engine Friendly URLs are turned on.

It seems to have something to do with permissions on the Joomla! install directory, with a workaround via the $line_site variable in configuration.php.

Further information is available through Frank's link above and at Joomla.org.

Categories
CSS PHP WordPress

Changing the font of code blocks with geshi syntax highlighter

By default, geshi-derived syntax highlighters use a serif font to display code blocks.  Many people find serif fonts less clear than the visually simpler sans-serif fonts.

A good choice is Lucida Console.  Consolas is even better because it has a slashed zero, which is easier to distinguish from the capital letter "O", though not as many computers have Consolas installed. To account for this, list the fonts in order of preference, the browser will use the first one that it can display.

To change the default font for code blocks, find the geshi code folder (usually under plugins), open geshi.php and look for the following code:

1
2
3
4
5
    /**
     * The overall style for this code block
     * @var string
     */
    var $overall_style = 'font-family:monospace;';

And modify is as seen here. Note that two word font names must be quoted, and the quote marks may need to be escaped, as seen below;

1
2
3
4
5
    /**
     * The overall style for this code block
     * @var string
     */
    var $overall_style = 'font-family:Consolas, \'Lucida Console\', monospace;';
Categories
Database MySQL

Adding a UNIQUE constraint to a database column

Sometimes we may need to make a column unique in a database table.  For instance we can't have two employees with the same employees with the same employee number or pension plan id.

To prevent this, run a query like the following to place a constraint on the attribute or attributes;

ALTER TABLE Employee ADD UNIQUE (EmpID, PensionID)

There are many other uses of the ALTER command that will help us modify our existing tables.  See this article for more useful applications of the ALTER command.

Categories
Database MySQL

Pulling database values in multiple formats

When we pull a value from MySQL or another database, there's nothing stopping us from pulling the same value in different ways within the same query.

For instance, say we want to pull dates in their raw format, which is suitable for sorting but may not be the most useful formatting for display.  We might find a format like "Jan-13-2009 · Wed" more useful for display purposes, though it's useless for sorting on.

We could massage the data in PHP to alter the date format, but it would be much faster and more efficient to let the database server deal with that.  You'll also have cleaner PHP code if you deliver attributes from your database server ready to use.

Here's an example of a query that pulls all values (the asterisk) followed by additional formats of two dates.  Note that the additional formats are manipulations of data which have already been pulled in their raw format by the asterisk in the select statement.  Note also that I've adopted the convention of  prepending "fmt_" to these derived attributes.

1
2
3
4
5
SELECT
  *,
  DATE_FORMAT(date_received,'%Y-%b-%d · %a') AS fmt_date_received,
  DATE_FORMAT(date_dispatched,'%Y-%b-%d · %a') AS fmt_date_dispatched,
FROM packages

You're now free to use date_received and fmt_date_received independently throughout your code.

Categories
Uncategorized

Going directly to a specific page in a PDF file

When accessing a PDF file through a web browser, it's possible to go to a specific page by adding a parameter to the URL.

www.mysite.ca/docs/mydoc.pdf#page=100

This is great for bookmarking a specific page in a PDF.  Unfortunately, it doesn't seem to work for accessing a PDF from the command line.

Keep in mind that the counter goes from the cover page, so to reach page 100 you may to increase the number to account for the cover page, table of contents, and other content wihch comes before the page labelled "page 1".

Now isn't that handy?