Author: pmacadden Date: 2010-05-26 16:02:17 +0200 (Wed, 26 May 2010) New Revision: 29631
Added: plugins/pmGravatarPlugin/trunk/LICENSE plugins/pmGravatarPlugin/trunk/README plugins/pmGravatarPlugin/trunk/lib/ plugins/pmGravatarPlugin/trunk/lib/helper/ plugins/pmGravatarPlugin/trunk/lib/helper/GravatarHelper.php plugins/pmGravatarPlugin/trunk/package.xml Log: pmGravatarPlugin added. Added: plugins/pmGravatarPlugin/trunk/LICENSE =================================================================== --- plugins/pmGravatarPlugin/trunk/LICENSE (rev 0) +++ plugins/pmGravatarPlugin/trunk/LICENSE 2010-05-26 14:02:17 UTC (rev 29631) @@ -0,0 +1,7 @@ +Copyright (c) Patricio Mac Adden + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Added: plugins/pmGravatarPlugin/trunk/README =================================================================== --- plugins/pmGravatarPlugin/trunk/README (rev 0) +++ plugins/pmGravatarPlugin/trunk/README 2010-05-26 14:02:17 UTC (rev 29631) @@ -0,0 +1,38 @@ +pmGravatarPlugin +================ + +With this plugin you can use [gravatar](http://gravatar.com) images in your application. + +Installation +------------ + + * Install the plugin + + $ ./symfony plugin:install pmGravatarPlugin + + * Clear you cache + + $ symfony cc + +Example usage +------------- + + [php] + <?php use_helper('Gravatar') ?> + + <?php echo gravatar('[email protected]') ?> + + +Gravatar helper functions +------------------------- + + * gravatar: draws a gravatar + * gravatar_url: returns the gravatar url from a given email. Returns a + default image if email does not have an image + +functions options +----------------- + + * size: a value between 1 and 512 + * rating: 'g', 'pg', 'r', 'x' + * default image: one of gravatar's default images Added: plugins/pmGravatarPlugin/trunk/lib/helper/GravatarHelper.php =================================================================== --- plugins/pmGravatarPlugin/trunk/lib/helper/GravatarHelper.php (rev 0) +++ plugins/pmGravatarPlugin/trunk/lib/helper/GravatarHelper.php 2010-05-26 14:02:17 UTC (rev 29631) @@ -0,0 +1,72 @@ +<?php + +/** + * Builds a gravatar url. + * + * @param string $email The user email. + * @param integer $size The gravatar size. + * @param string $rating The gravatar rating. + * @param string $default The default image to use if the email does not have + * a gravatar image. + * + * @return string The gravatar image url. + */ +function _build_url($email, $size, $rating, $default) +{ + $url = 'http://www.gravatar.com/avatar/'; + + $email_hash = md5(trim(strtolower($email))); + + $url .= $email_hash; + + $params_added = false; + if ($size >= 1 && $size <= 512) + { + $url .= "?s=$size"; + $params_added = true; + } + + if ($rating == 'g' || $rating == 'pg' || $rating == 'r' || $rating == 'x') + { + $url .= ($params_added?'&':'?')."r=$rating"; + } + + if (!is_null(($default))) + { + $url .= ($params_added?'&':'?')."d=$default"; + } + + return $url; +} + +/** + * Builds a gravatar url. + * + * @param string $email The user email. + * @param integer $size The gravatar size. + * @param string $rating The gravatar rating. + * @param string $default The default image to use if the email does not have + * a gravatar image. + * + * @return string The gravatar image url. + */ +function gravatar_url($email, $size = 80, $rating = 'g', $default = null) +{ + return _build_url($email, $size, $rating, $default); +} + +/** + * Builds an <img> tag using a gravatar image. + * + * @param string $email The user email. + * @param integer $size The gravatar size. + * @param string $rating The gravatar rating. + * @param string $default The default image to use if the email does not have + * a gravatar image. + * + * @return string The gravatar image url. + */ +function gravatar($email, $size = 80, $rating = 'g', $default = null) +{ + return image_tag(gravatar_url($email, $size, $rating, $default)); +} Added: plugins/pmGravatarPlugin/trunk/package.xml =================================================================== --- plugins/pmGravatarPlugin/trunk/package.xml (rev 0) +++ plugins/pmGravatarPlugin/trunk/package.xml 2010-05-26 14:02:17 UTC (rev 29631) @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package packagerversion="1.0.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> + <name>pmGravatarPlugin</name> + <channel>plugins.symfony-project.org</channel> + <summary>With this plugin you can use gravatar images in your application.</summary> + <description>With this plugin you can use gravatar images in your application.</description> + <lead> + <name>Patricio Mac Adden</name> + <user>pmacadden</user> + <email>[email protected]</email> + <active>yes</active> + </lead> + <date>2010-05-26</date> + <version> + <release>1.0.0</release> + <api>1.0.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.symfony-project.com/license">MIT license</license> + <notes>-</notes> + <contents> + <dir name="/"> + <file role="data" name="README"/> + <file role="data" name="LICENSE"/> + <dir name="lib"> + <dir name="helper"> + <file role="data" name="GravatarHelper.php"/> + </dir> + </dir> + </dir> + </contents> + <dependencies> + <required> + <php> + <min>5.0.0</min> + </php> + <pearinstaller> + <min>1.4.1</min> + </pearinstaller> + <package> + <name>symfony</name> + <channel>pear.symfony-project.com</channel> + <min>1.3.0</min> + <max>1.5.0</max> + <exclude>1.5.0</exclude> + </package> + </required> + </dependencies> + + <phprelease></phprelease> + <changelog></changelog> +</package> -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
