Im very proud to announce the video section for my website with recipes. Take a look at the first video and tell me what you think about.
Gatesti bine?
Dacă îţi place să găteşti şi vrei să arăţi lumii şi prieteniilor ce capodopere faci în arta culinară, intră pe gatestebine.ro şi publicăţi reţetele.

Yahoo messenger in php
One of my articles was Yahoo Messenger Client with Action Script 3 now i will show you how to write a yahoo messenger application in php. The script flow its exactly like code from action script because its connect to the same yahoo messenger protocol. For binary working i used a zend package ( Zend_Io ). The implementation of yahoo messenger in php its very simple, use only minimal 6 base classes.
- ChallengeResponseV16 – Used to make the authentification
- Network – Used to communicate trought the socket
- Packet – Keeps human readable packet info
- PacketBody - Keeps human readable packet body info
- Protocol – Builds packets, make login and other yahoo messenger protocol implementation
- Service – Keeps constants with services provided by protocol
Try the yahoo messenger in php or download the source code
Web application versioning when using Zend Framework
This is a simple way to versioning a zend framework application using just two files, a ini file that keeps the current version and a proxy/model file wich load the current version from the ini file and test the user passed version for a new feature. The ini file is splited in three states: production, testing and development.
[production] ; 1.1.1 - ; 1.2.0 - From this we add video section ; 1.0.0 - First release of the site version = "1.0.0"; [testing : production] version = "1.0.0"; [development : production] version = "1.0.0";
The good think about this is that you can set a version for each stage of application. While application is in development mode, just set a constant for enviroement and current version will be that from development block. The class wich handle this operations is a very simple singleton class with “version” method.
define('APPLICATION_ENV', 'development');
class Proxy_Version
{
private static $_instance = null;
private $versions;
/**
* Singleton instance
* @abstract
* @return Proxy_Version
*/
public static function getInstance()
{
if (null === self::$_instance)
{
self::$_instance = new self();
}
return self::$_instance;
}
private function __construct()
{
$this->versions = new Zend_Config_Ini('version.ini', APPLICATION_ENV);
}
public static function version( $version = null )
{
self::getInstance();
$currentVersion = self::$versions->version;
$userVersion = false;//if you have stored in db the version for each user
if( $userVersion !== false )
{
$currentVersion = $userVersion;
}
if($version)
{
return version_compare($currentVersion, $version, ">=");
}
return $currentVersion;
}
}
Also if you look closer in this class you can set a user version, for example when you want to let a limited numbers of users to test the next version of the application. To be more easy to use you can apply a shortcut in a view helper and access it with $this->version().
//context of version 1.0
if($this->version("1.2"))
{
//content of version 1.2
}
//context of version 1.0
echo $this->version();
Or you can set a shortcut in a abstract zend controller action and load views depentds of version method.
//controller class
//....
public function indexAction()
{
if($this->version("1.2"))
$this->render("index_1.2.phtml");
}
//....
jQuery apear plugin
Simple jquery plugin used to trigger a function when a specific element apears on viewport, this callback is trigged one time.
This plugin is very useful when you what to preload an image when this apears on the viewport.
$('img[osrc]').apear(function(){
$(this).load(function(){
$(this).fadeIn();
});
$(this).attr('src',$(this).attr('osrc')).attr('osrc',null);
console.log('apear item');
});
In this example the image is printed with osrc attribute wich keeps the path to the image, when the apear plugin callback is trigged the osrc attribute is replaced with src attribute and add new event to loaded function to fade in the image.
Other way to use this is when you have multiple boxes ( widgets ) on the page and its not necessary to apply a javascript code to it before to apear in the viewport.
$('.widget-x').apear(initWidgetX);
Download plugin or try the Demo
Working with JSON RPC from javascript
JSON-RPC is lightweight remote procedure call protocol similar to XML-RPC. Its very simple and its used by alots of web applications at least json wich is very used in modern applications.
To communicate with server in a professional way, json-rpc is a good solution all you need to do is to create server side classes and pass it to an json rpc server class like Zend_Json_Server, read the documentation about how to create the server side.
For the client side you need to create a javascript class witch sends the request to the server and parse the response.
The json request for json-rpc is very simple has three properties in the json object: the method, params and request id.
{method : "Account.login", params : ["user","pass"], id : "194" }
And response contain the result of call, the error if it is, and the request id number.
{"result": "done", "error": null, "id": "194"}
The id of the request and response is used to match the request and reponse of the current call. For example if you send a request and also add a listener for it, when the response comes call the listener with the specific id. This id is increasing at every request.
I made a simple json-rpc implementation for javscript that handle a json-rpc protocol. Sintax of using this rpc implementation is very simple, its provide a fluent call mode with two functions “call” and “done”.
Rpc.call("Account.login", "username", "password").done( onLoginResponse );
This Rpc class depends by a public json encoder/decoder class, you can find this class here. For this work you must to change the url from ajax call and changed to your url, and thats all.
var Rpc = {
id : 0,
cid : 0,
callbacks:[],
call : function()
{
var args = [];
for(var i=0;i<arguments.length;i++)
args.push(arguments[i]);
var method;
var tosend;
this.id++;
this.cid = this.id;
if(args.length)
{
method = args.shift();
var tosend = {method : method, params : args, id : this.cid };
jQuery.ajax({
async: true,
contentType: 'application/json',
type: 'POST',
processData: false,
dataType: 'json',
url: '/api/js',
cache: false,
data: JSON.stringify(tosend),
error: function(req,stat,err){
Boxy.alert(err);
},
success: function(data){
for(i=0;i<public.Rpc.callbacks.length;i++)
{
if(public.Rpc.callbacks[i])
if(public.Rpc.callbacks[i].id == data.id)
{
var callback = public.Rpc.callbacks[i].callback;
if(callback)
{
callback.apply(null, [data.result]);
public.Rpc.callbacks.splice(i,1);
}
}
}
}
});
}
return this;
},
done : function(callback)
{
if(typeof(callback) == 'function')
this.callbacks.push( { id : this.cid, callback : callback } );
}
};
Improve Zend Framework application speed by separate static content and using Zend_Cache and Zend_View for static files
Introduction
Why doing this, the reason is simple. We dont need to process all static files in our framework, because this increase loading time of your application. The ideea is to create a separate domain for your application eg. http://s.domain.com wich will render and cache all requested files. I personally used this method and my application wich is based on Zend Framework is considerably faster. The Zend_View is used to merge multiple css or js files and pass parameters. Also compressing and obfuscation classes are used to decrease file sizes.
Create .htaccess
For beggining a .htaccess file is created for redirecting all request to render file. The files that is redirected to the render file is just js and css files, the rest of them like pictures, zip and other binary files are loaded from normal path. Also if apache deflate module is available we add filters for css,xml and javascript files to compress files.
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
RewriteEngine on RewriteRule !\.(swf|xml|jpg|png|PNG|JPG|gif|otf|ttf|htc|ico)$ render.php
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ render.php [NC,L]
Render file
This is the file called render.php wich process all requests sepcified by .htaccess file. For example if request is /css/common.css this file is loaded into Zend_View and rendered. If the request has some parameters like /css/common.css?foo=1&bar=1 the request is parsed with php function parse_str and passed to the Zend_View. Before the file is sent to output the content is compressed with specific class, for css i personally used the CSSCompressor by Stephen Clay and for javascript files JSMinPlus by Tino Zijdel. After the file is compressed the content is cached by Zend_Cache with the md5 of request like id. And finaly send the cache headers for browsers and print it to ouput.
<!?php
error_reporting(E_ALL);
ini_set('display_errors','1');
set_include_path(implode(PATH_SEPARATOR, array( dirname(__FILE__).'/library', get_include_path(), )));
require_once "Zend/Uri.php";
require_once "Zend/Cache.php";
require_once "Zend/View.php";
require_once 'functions.php';
define('CACHE_DAYS', 30);
define('USE_CACHE', false);
define('USE_COMPRESSOR', false);
$request_file = $_SERVER['REQUEST_URI'];
if($request_file == "/" || empty($request_file))
{ notFound(); }
$cache_id = md5($request_file);
$uri = Zend_Uri::factory("http://s.domain.com".$request_file);
parse_str($uri->getQuery(), $uri_params);
$file_parts = explode('.', basename($uri->getPath()));
$extension = $file_parts[ count($file_parts) - 1 ];
$file = basename($uri->getPath());
$file_path = str_replace('\\','/',dirname(__FILE__) . $uri->getPath());
$frontendOptions = array(
'lifetime' => 3600 * 24 * CACHE_DAYS, // cache lifetime of 2 hours
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => dirname(__FILE__).'/cache/' // Directory where to put the cache files
);
// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core',
'File',
$frontendOptions,
$backendOptions);
if(file_exists($file_path) && is_file($file_path))
{
switch ( $extension )
{
case "css":
header("Content-Type: text/css");
if(USE_COMPRESSOR)
require_once "CSSCompressor.php";
sendHeaders($file_path);
if( ($result = $cache->load($cache_id)) === false )
{
$result = renderView($file_path, $uri_params);
if(USE_COMPRESSOR)
$result = CSSCompressor::process($result);
$result = appendCacheInfo($result);
if(USE_CACHE)
$cache->save($result, $cache_id);
}
echo $result;
break;
case "js":
header("Content-Type: text/javascript");
if(USE_COMPRESSOR)
require_once "JSMin.php";
sendHeaders($file_path);
if( ($result = $cache->load($cache_id)) === false )
{
$result = renderView($file_path, $uri_params);
if(USE_COMPRESSOR)
$result = JSMin::minify($result);
$result = appendCacheInfo($result);
if(USE_CACHE)
$cache->save($result, $cache_id);
}
echo $result;
break;
default:
notFound();
break;
}
}
else
{
notFound();
}
This steps considerably increase the time of loading of your application. The compressing calsses make files smaller with 20%. Also the big advantage for this is you can use the css and javascript files like php. For example if you want to merge multiple common files into one file, simply use render function from Zend_View
@CHARSET "UTF-8";
<?php echo $this--->render("reset.css"); ?>
<?php echo $this--->render("grid.css"); ?>
<?php echo $this--->render("layout.css"); ?>
This method is very usefully because reduce the number of files loaded trought the network.
To make sure the files are not requested every time and the client browser do its job, we send the caching headers using the below sendHeaders function.
function sendHeaders($file)
{
$cache_days = CACHE_DAYS;
if(file_exists($file))
{
$filetime = filemtime($file);
$last_modified = date('D, d M Y H:i:s', $filetime) . ' GMT';
$expires = date('D, d M Y H:i:s', strtotime('+30 days',$filetime)) . ' GMT';
$hasid = '"' . md5($last_modified) . '"';
header("Cache-Control:max-age=".($cache_days * 24 * 60 * 60));
header("Pragma:private");
header("Last-Modified:".$last_modified);
header("Expires:".$expires);
header("Vary: Accept-Encoding");
header("Etag:".$hasid);
$PageWasUpdated = !(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) and
strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified);
$DoIDsMatch = (isset($_SERVER['HTTP_IF_NONE_MATCH']) and
@ereg($hasid, $_SERVER['HTTP_IF_NONE_MATCH']));
// Does one of the two ways apply?
if (!$PageWasUpdated or $DoIDsMatch)
{
header('HTTP/1.1 304 Not Modified');
header('Connection: close');
exit(1);
}
}
}
To work this function you must have some modules activated in your apache server. The modules are headers_module, expires_module.
Static files rendered like views
With your css and javascript files you cand do alots of things. In fact in your .css and .js files you cand write php code, for eg:
If you request: /js/account.js?logged=1 from the view file you can do somethink like this:
function onSomeButtonClick()
{
var logged = <?php echo ($this--->logged=="1") ? 'true' : 'false'; ?>;
if(logged) {
//do something
} else {
//do something
}
}
Conclusion
For my application this method is very fast and with alots of advantages and functionalities. The filesize is smaler using the compressing classes, also the apache is compress it with defalate module. With this positive points also have some issues, if you what to use the params sent to the view every time you must to disable cache.
Invisible detector made to be simple and user friendly
Today invisible-detector.net is live and is more user friendly and fast then last version. Yesterday i refused to go to club and I decided to restore design to insible-detector.net. I have made it much easier to use and much faster, the results are now directly displayed in the input where you write the id. History is quite different then others websites, this is with suggestions autocomplete. Enter and tell your opinion! Thanks!
Flash player 10.3 video problem with hardware acceleration
Working on a video player project with osmf and flex i had some strange problems. When going in fullscreen mode the screen it was black or more exactly the video it was not been sown. After one hour of testing and debugging i found the problem, the problem was that i compiled the video player with 10.3 flash player version and this works with hardware accelerated and if there is no video driver or the driver is out of date the video will not be shown only when the hardware acceleration is disabled or you update your video drivers. The solution for this is to compile with older version 10.2 or below witch is not working with video acceleration.



