Monthly Archives: August 2012

Symfony2: simple JavaScript routing with Assetic and HTML5 data Attributes

Simple example HTML5 code: <div id=”gallery” data-rollover_on=”{{ asset(‘bundles/testprojecttestbundle/images/play_button_on.png’) }}” data-rollover_off=”{{ asset(‘bundles/testprojecttestbundle/images/play_button_off.png’) }}”> …</div> JavaScript (JQuery): var rollover_play_off = mainjQuery(‘div[id=”gallery”]’).attr(‘data-rollover_off’); var rollover_play_on = mainjQuery(‘div[id=”gallery”]’).attr(‘data-rollover_on’); var original_image = ‘url(‘+rollover_play_off+’)’; var second_image = ‘url(‘+rollover_play_on+’)’; Advertisements

Posted in assetic, Symfony2 | Leave a comment

Symfony2: assetic, rewriting image paths in CSS

Twig template: {% block stylesheets %} {{ parent() }} {% stylesheets filter=’cssrewrite’ output=’css/*.css’ ‘bundles/testcompanytestbundle/css/*’ %} <link href=”{{ asset_url }}” type=”text/css” rel=”stylesheet” /> {% endstylesheets %} {% endblock %} Console commands: php app/console assets:install web/ php app/console –env=prod assetic:dump CSS example … Continue reading

Posted in assets, CSS, rewrite, Symfony2 | Leave a comment

Facebook API: Like button event problem (FB.Event.subscribe(‘edge.create’…)

Original problem: FB API edge.create method not fired on Like with URL different from current page. Bug link: http://developers.connect.facebook.com/bugs/457950334238629?browse=search_502da4c4a73ed9006640326 I’ve solved the problem. You have to use the url_like table: //Facebook API – Unlike event. FB.Event.subscribe(‘edge.remove’, function(response) { console.log(‘uid’,uid); var … Continue reading

Posted in edge.create, Facebook, JavaScript, like event | Leave a comment

PHP: how to query sharing and likeing count from Facebook, Twitter, Google Plus

/** * * @param string $content_url */ public static function getFacebookShareCount( $content_url=” ) { if ($content_url == ”) return 0; $result = array(); $url = “http://api.facebook.com/restserver.php?method=links.getStats&urls=&#8221;.urlencode($content_url); $xml = file_get_contents($url); $xml = simplexml_load_string($xml); $result[‘share’] = (int)$xml->link_stat->share_count; $result[‘like’] = (int)$xml->link_stat->like_count; $result[‘comment_count’] = … Continue reading

Posted in Facebook, Google Plus, php, shared content, Twitter | Leave a comment

Symfony 1.x – simple directory name validator

/** * validate directory path * example: /path/dir1/dir2 – it is valid * path/dir2/dir2 – it is invalid */ $this->setValidator(‘proxy_folder’, new sfValidatorRegex( array( ‘pattern’ => ‘#^(/[^/]+)+$#’, ‘required’ => false ), array(‘invalid’ => ‘Invalid prefix “Folder name” field must begin /’) … Continue reading

Posted in directory name, Symfony 1.x, validator | Leave a comment