oh hai.

Joomla Jobline Component Strip Slashes

Posted: May 1st, 2008 | Author: Nick | Filed under: joomla, php | Tags: , , , | No Comments »

If you have magic_quotes_gpc set to on in php and would like to keep it on but jobline is not removing the slashes on display or edit in the backend then edit the following files to fix it.

/administrator/components/com_jobline/admin.jobline.php
Look for the editJobPosting function and just before the last line in this function which is HTML_jobline_admin::editJobPosting( $row, $lists, $cur_template, $returnpage ); add the following lines of code.

$row->description = stripslashes($row->description);
$row->qualifications = stripslashes($row->qualifications);
$row->applyinfo = stripslashes($row->applyinfo);
 
That just fixes editing in the backend, now for the front end view. Go find this file...
/components/com_jobline/jobline.php
and look for this function viewJobPosting and add the same lines as above which are
$row->description = stripslashes($row->description);
$row->qualifications = stripslashes($row->qualifications);
$row->applyinfo = stripslashes($row->applyinfo);

right before this line
HTML_jobline::show( $row );

Hope this helps, it takes a little while to find so I thought I would save someone else the time. Enjoy


Turning off PHP safe mode with Plesk

Posted: April 20th, 2008 | Author: Nick | Filed under: php | Tags: , , | No Comments »

While working on an application that creates it’s own directories on the fly and then inserts images in them I came across some safe mode errors. Basically what they were is that I was creating a folder with the script which would then set the user to be ‘apache’ and then when the script went to write in it again and it didn’t actually own that folder, apache died.

I found some other more complicated solutions on the net where you have to edit the php.ini file and one where you edit the vhosts file. I figured there had to be a way to do it through Plesk and I finally found it so I figured I would share it so that no one else has to deal with it.

This is what the error looks like:

Warning: mkdir() [function.mkdir]: SAFE MODE Restriction in effect. The script whose uid is 10004 is not allowed to access /var/www/vhosts/xxx/xxx/xxxx owned by uid 48 in /var/www/vhosts/xxx/xxx/xxx/upload.php on line 98

So go into plesk and follow these steps…

  • Click Domains over on the left
  • Choose the domain you are wanting to disable safe mode on
  • Under the hosting section choose setup
  • Scroll down and under services find the one that says ‘PHP support’
  • Leave that box checked but uncheck the one to the right of it that says ‘(PHP ’safe_mode’ on )’
  • Click ok and you are done.

Hope this helps.


PHP to Ruby on Rails Translations

Posted: April 20th, 2008 | Author: Nick | Filed under: php, ruby | Tags: , , , | No Comments »

I used to develop primarily in PHP and dabbled into ASP but then I learned about Ruby and the Rails framework and now I cringe when I need to develop something new that isn’t in Ruby. There are a ton of tutorials on Rails so if you aren’t familiar or want to learn just do some googling. My intention with this post is to compare the differences in chunks of common code between php and ruby. Items such as for loops, array manipulation in ruby, various string functions in ruby and php, etc. I obviously won’t write everything so if you think of something that would be handy to know then leave a comment with it in there. Yes I realize PHP has frameworks that add some of the handy features that Rails does.

Create Array:
Ruby:

myArray = ["dog","cat","mouse"]

PHP:

$myArray = array("dog","cat","mouse")

*With Ruby there’s no need to specify that it’s an array, it knows from the brackets. Also notice that PHP uses parentheses and Ruby uses brackets.

Using element of array by position

Ruby:

myArray[1] = "cat"

PHP:

$myArray(1) = "cat"

First Elements:

Ruby:

myArray.first = "dog"

PHP:

first($myArray) = "dog"

Ruby:

myArray.first(2) = ["dog","cat"]

PHP:

for ($i=0; $i < 1; $i++ ){$first2elements .= myArray($i);}

* If there is a better way to do this in PHP let me know if it doesn’t involved a loop.

Print out elements of Array

Ruby:

 myArray.inspect

PHP:

printr($myArray)

Comments

Ruby:

# COMMENT

*Ruby doesn’t have multiline comments at the moment, just get a good editor that has a shortcut for it such as Textmate or vim with the vim NERDCommenter plugin.

PHP:

// SINGLE LINE COMMENT
/* MULTILINE COMMENT */

View embed Tags
Ruby:

< %=%>

PHP: (Short version), (Long Version)

< ?php= ?>
< ?= ?>

*Both languages support putting an equal sign after the opening to print out what is in the tag. In Ruby if something isn’t meant to be printed out such as the opening loop tag then it will get mad at you since there’s nothing to print in that portion.

A quick note on Ruby before I go into the string section. You can call quite a few methods on arrays and strings that permanately change the current object you are working on. The Exclamation point is what tells Ruby to keep the changes you made to it or if you leave it off it remains the same when you call it again. For instance you can do…

String Manipulation

Ruby:

s = "hello world"

PHP:

$s = "hello world"
s.capitalize => "Hello World"
ucwords($s) = "Hello World"
s.capitalize! = "Hello World" *This keeps the string Capitalized
s.capitalize = "Hello World"

*The string is capitalized but only for this call on the capitalize method, if you want you can store it in a new variable to keep the capitalization.

Other good things to know about Ruby

Form Validation
Ruby:

validates_presence_of :animal_name #This goes in the definition of the model such as 'animals', going into detail about how models work is beyond the scope of this tutorial. Other handy ones you can use in rails are...
validates_acceptance_of #Good to use this for checkboxes.
validates_format_of #Can use regular expressions to validate fields such as email address.
validates_length_of :animal_name, :maximum = 20 #A max of 20 characters is aloud
validates_length_of :animal_name, :within= 5..20 #Needs to be within 5 to 20 characters
validates_numericality_of :feet #Makes sure that the user specifies a number for amount of feet
validates_presence_of :animal_name #Make sure animal name isn't blank
validates_uniqueness_of :animal_name #Make sure you only have one entry for 'dog' as an animal name

PHP: There are several PHP frameworks that have different ways of doing similar validation techniques try, CakePHP is a very popular one.

Link Creation

< %= link_to "link name" "/direction/for/link" %>
< %= javascript_include_tag "myJSFile" %>
< %= stylesheet_link_tag "myCSSFile" %>

A great resource for PHP to rails/ruby translations is http://railsforphp.com