root/trunk/lib/helper/ImageHelper.php

Revision 75, 2.4 kB (checked in by nperriault, 3 months ago)

[1.1]:

  • Companies and people modules migrated, with according form classes and templates, and functional test suite
  • Enhanced SymfoniansTestBrowser?
Line 
1 <?php
2 sfLoader::loadHelpers('I18N');
3
4 /**
5  * Return an img tag to the flag image of a given coutnry
6  *
7  * @param  string  $country_code ISO country code
8  * @param  mixed   $options
9  * @return string
10  */
11 function flag_image_tag($country_code, $options = null)
12 {
13   if (!$country_code)
14   {
15     return '';
16   }
17
18   $options = _parse_attributes($options);
19
20   if (isset($options['class']))
21   {
22     $options['class'] = trim($options['class']) . ' flag';
23   }
24   else
25   {
26     $options['class'] = 'flag';
27   }
28
29   $options['alt'] = format_country($country_code);
30   $flag_image = sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'flags'.DIRECTORY_SEPARATOR.strtolower($country_code).'.png';
31   if (!file_exists($flag_image))
32   {
33     return '';
34   }
35
36   return image_tag('flags/'.strtolower($country_code).'.png', $options);
37 }
38
39 /**
40  * Returns the application thumb web path
41  *
42  * @param  Application $application
43  * @param  mixed       $options
44  * @return string|null
45  */
46 function application_image_tag($application, $options = null)
47 {
48   return image_tag(sprintf('/%s/applications/%s',
49                            sfContext::getInstance()->getConfiguration()->getUploadDirName(),
50                            $application->getScreenshotPath()), $options);
51 }
52
53 /**
54  * Returns the company logo web path
55  *
56  * @param  Company  $company
57  * @param  mixed    $options
58  * @return string|null
59  */
60 function company_image_tag($company, $options = null)
61 {
62   return image_tag(sprintf('/%s/companies/%s',
63                            sfContext::getInstance()->getConfiguration()->getUploadDirName(),
64                            $company->getLogoPath()), $options);
65 }
66
67 /**
68  * Returns the person avatar web path. Due to image formats handling, the
69  * signature is a bit different regarding the previous *_image_tag functions.
70  *
71  * @param  sfGuardUser  $person
72  * @param  mixed        $options
73  * @return string|null
74  */
75 function person_image_tag($person, $format = 'standard', $options = null)
76 {
77   if (!$person->getAvatarPath())
78   {
79     $config = sfConfig::get('app_people_formats', array());
80
81     if (isset($config[$format]['default']))
82     {
83       return image_tag(sprintf('/images/%s', $config[$format]['default']), $options);
84     }
85   }
86
87   return image_tag(sprintf('/%s/people/%s',
88                            sfContext::getInstance()->getConfiguration()->getUploadDirName(),
89                            $person->getAvatarPath()), $options);
90 }
Note: See TracBrowser for help on using the browser.