Cool PHP Tools http://www.coolphptools.com News from Cool PHP Tools Sat, 11 Apr 2026 04:Apr:th 100 Neighbor Webmaster CMS v1.0 en Updated All Code http://www.coolphptools.com/news/detail/updated-all-code Thu, 09 Jun 2016 12:Jun:th 160 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/updated-all-code Long overdue, I have brought all my projects here up to date. 

  • Codeigniter / Smarty integration now works with CodeIgniter 3 and Smarty 3.
  • Color Extract sample code works in PHP5
  • Dynamic CSS - fixed many glitches and added some enhancements.

I also redid my entire website with the latest version of my CMS and using Bootstrap. Please let me know if you encounter any issues.

 

]]>
Smarty 3.x Missing Template Variable error http://www.coolphptools.com/news/detail/Smarty_3_x_Missing_Template_Variable_error Thu, 05 May 2011 23:May:th 124 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/Smarty_3_x_Missing_Template_Variable_error In the Smarty 3.0 release, for some odd reason the developer decided undefined variables in the template are errors. In Smarty 2.x undefined variables were treated as empty strings. This made a lot more sense to me. The whole reason I use Smarty is so I don't have to sweat details like this. 

I decided to find where in the code the error was coming from and make it work like it used to. My solution (and it may not be optimal as I didn't dig that deeply) is as follows:

1) Edit smarty/libs/sysplugins/smarty_internal_data.php and change the getVariable() function to:

    /**
     * gets the object of a Smarty variable
     * 
     * @param string $variable the name of the Smarty variable
     * @param object $_ptr optional pointer to data object
     * @param boolean $search_parents search also in parent data
     * @return object the object of the variable
     */
    public function getVariable($_variable, $_ptr = null, $search_parents = true, $error_enable = true)
    {
        if ($_ptr === null) {
            $_ptr = $this;
        } while ($_ptr !== null) {
            if (isset($_ptr->tpl_vars[$_variable])) {
                // found it, return it
                return $_ptr->tpl_vars[$_variable];
            } 
            // not found, try at parent
            if ($search_parents) {
                $_ptr = $_ptr->parent;
            } else {
                $_ptr = null;
            } 
        } 
        if (isset(Smarty::$global_tpl_vars[$_variable])) {
            // found it, return it
            return Smarty::$global_tpl_vars[$_variable];
        } 
        if ($this->smarty->error_unassigned && $error_enable) {
            throw new SmartyException('Undefined Smarty variable "' . $_variable . '"');
        } else {
			if (! $this->smarty->error_unassigned) {
            	return new Smarty_variable(null, false);
			} else {
        		if ($error_enable) {
					// force a notice
					$x = $$_variable;
        		}
            	return new Undefined_Smarty_Variable;
        	} 
        } 
    }

2) Now in your code, before calling the template, add this line:

  $smarty->error_unassigned = false; 

This assumes your instance of Smarty is called $smarty. The beauty of this method is that you don't have to turn off ALL error messages just to suppress the missing var message.

]]>
Error 324 (ERR_EMPTY_RESPONSE) http://www.coolphptools.com/news/detail/Error_324_ERR_EMPTY_RESPONSE Wed, 12 Jan 2011 16:Jan:th 11 [email protected] http://www.coolphptools.com/news/detail/Error_324_ERR_EMPTY_RESPONSE I just upgraded my server since I needed to rebuild my PHP/Apache to include a missing library. CPanel makes this easy, however they allow only a few versions of PHP to choose from. The earliest available was still after my current version. I decided to go ahead anyway. Everything worked fine for all my web sites except one. That web site was running Moodle 1.9. When I went to that web site I got the mystersious "Error 324 (ERR_EMPTY_RESPONSE)" error.

Six hours later (might be a slight exaggeration) I finally found the problem. The culprit was the following line in lib/setup.php:

  raise_memory_limit('96M');    // We should never NEED this much but just in case...

 

After commenting out this line everything was fine. Hopefully this will help anyone with a similar problem. 

 

 

 

]]>
CSS Variables Are Really Really Bad... Really? http://www.coolphptools.com/news/detail/css-variables-are-really-really-bad Fri, 15 Jul 2016 00:Jul:th 196 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/css-variables-are-really-really-bad Ok, by this point you may realize that I actually think CSS variables are useful. Now I have the daunting task of convincing you that there are valid reasons to support variables and that doesn't include turning CSS into a programming language.

I first want to clear up the difference between parameters and variables. A parameter is passed along with the request for a CSS file and can subsequently be referenced using the $_GET array (assuming you are using PHP). Variables are defined either in the CSS file or pulled in from the PHP environment variables. CSS files could potentially behave differently based on a value within a user's $_SESSION. This is a bad idea, and I will explain a little later.

In my dynamic CSS library, parameters become variables within the CSS file. The subtle difference has to do with browser caching. This is a common argument against using CSS variables since the browser has no knowledge of a variable's value and may return a cached version of the CSS file where the values were different than they are now. By using parameters, the values are part of the request itself and caching includes them. In other words:

 

returns a different browser cached version than: 

 

 

even though the css file (myfile.css) is the same. This is because the browser is smart enough to include the passed parameters when caching files. This answers the reason why you shouldn't use $_SESSION variables directly in your CSS file to control the output of your CSS since the browser does not take them into consideration when caching. How could it? The session is managed on the server while the browser is on your local client (PC, Mac, Iphone, ...).

 

]]>
New Version of the Dynamic CSS library http://www.coolphptools.com/news/detail/New_Version_of_the_Dynamic_CSS_library Mon, 16 Feb 2009 19:Feb:th 46 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/New_Version_of_the_Dynamic_CSS_library  I have a new version of my CSS filter library. Here are the highlights of what has changed:

  • Fixed a bug when applying the alpha filter for IE5.5 and IE6
  • Added code to generate the indexed image (.gif/.png8) when it doesn't exist for browsers that don't support .png images
  • Allow conditional statements to be separated using semicolons (the statements used to be required to be on a line by themselves).

To clarify the last bullet, I will give an example of the old syntax (which still works):

    body
    {
        color: #000;
        if ($_GET[‘theme’] == ‘blue’)
            background‐color: #03C;
        else
            background‐color: #CCC;
        endif
    }

 Now can be written on a single line:

    body {
        color: #000;
        if ($_GET[‘theme’] == ‘blue’); background‐color: #03C; else; background‐color: #CCC; endif;
    }

You can download the latest version here.

]]>
Color Extract Utility http://www.coolphptools.com/news/detail/color-extract-utility Wed, 03 Sep 2008 14:Sep:rd 246 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/color-extract-utility I came across a useful class on phpclasses.org. It extracts colors from an image file. I enhanced it a little and created an online test area where you can try it out. You can see it and download it here.

Credit must be given to Csongor Zalatnai of Hungary for creating the original class.

]]>
New version of Dynamic CSS library http://www.coolphptools.com/news/detail/new-version-of-dynamic-css-library Tue, 13 May 2008 01:May:th 133 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/new-version-of-dynamic-css-library This version has an updated User Manual. It also:

  • Fixes a silent failure when an included css file did not exist.
  • Allows overriding of the state variables using parameters on the CSS Url.
  • Fixed a bug where @include statements ignored the if block they were in.

You can download version 1.1 here.

]]>
Will Code for Food http://www.coolphptools.com/news/detail/will-code-for-food Tue, 27 Jan 2009 01:Jan:th 26 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/will-code-for-food Just for the record, I love open source. Like most good programmers I have a bit of a lazy streak. If someone has already coded what I need, or at least close to what I need, I will use it. I don't want to reinvent the wheel.

The other nice thing about open source is, well, you get the source. Being a hands on type of programmer I get suspicious of "black box" solutions. I always suspect there is some programming bug lurking in there waiting to rise up and bite me. When my program isn't working is it because I did something wrong or am I hitting one of those nasty bugs in a vendor's package? I have done my share of "alpha testing" of a vendor's supposedly "production" code. Of course the burden of proof is always on you. Create your simple test case showing the bug and wait on the tech support hotline listening to Kenny G for hours only to end up talking to someone who just joined the company a week ago. I would much rather have all the code in front of me to dive in and fix whatever problem arises.

Ok, so now you are probably thinking "What's the problem"? The basic issue is that Open Source projects are also free. Believe me I love free. I am addicted to free. And therein lies the problem. There is so much Open Source code out there - and a lot of it really good quality, that people think all code should be free. The idea that I may want to charge for my time programming puts me into the greedy money grubbing capatilist ranks of Bill Gates. To see an extreme example of this sentiment, watch the movie "Antitrust" where an evil Tim Robbins resorts to murder to protect his investment in code. The message from the movie is "all code should be free"! So instead, many programmers decide to give away their code and add a "donate" button in hopes someone will realize the time and effort they put into developing the code and will compensate them for their time. Forget the fact you have bills to pay and mouths to feed.

This article is more of an expression of my frustration at how devalued programming skills have become. I guess this may be payback for the years of excessive fees paid to average or below average consultants. I have no great solution to this issue. I see some open soure projects have been adopting different approaches like "free for the basic functionality and then pay for either services or additional functionality". Time will tell approach works best. 

 

]]>
Welcome to my technical site http://www.coolphptools.com/news/detail/welcome Tue, 29 Apr 2008 02:Apr:th 119 Kepler Gelotte [email protected] http://www.coolphptools.com/news/detail/welcome Just created this web site. Hopefully more will be added in the near future.

]]>