Overview

Packages

  • Folks
  • None

Classes

  • Folks
  • Folks_Activity_Form
  • Folks_Api
  • Folks_Application
  • Folks_Block_Activities
  • Folks_Block_Friends
  • Folks_Block_Know
  • Folks_Block_New
  • Folks_Block_Random
  • Folks_Block_Recent
  • Folks_Driver
  • Folks_Driver_sql
  • Folks_Friends
  • Folks_Friends_application
  • Folks_Friends_facebook
  • Folks_Friends_prefs
  • Folks_Friends_shared
  • Folks_Friends_sql
  • Folks_Login_Form
  • Folks_Notification
  • Folks_Notification_facebook
  • Folks_Notification_letter
  • Folks_Notification_mail
  • Folks_Notification_tickets
  • Folks_Search_Form
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Folks Base Class.
  4:  *
  5:  * Copyright Obala d.o.o. (www.obala.si)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author Duck <duck@obala.net>
 11:  * @package Folks
 12:  */
 13: 
 14: class Folks {
 15: 
 16:     const VFS_PATH = '.horde/folks';
 17: 
 18:     /**
 19:      * Returns published videos from user
 20:      *
 21:      * @param string $user User to check
 22:      */
 23:     static function format_date($time)
 24:     {
 25:         return strftime($GLOBALS['prefs']->getValue('date_format'), $time);
 26:     }
 27: 
 28:     /**
 29:      * Returns published videos from user
 30:      *
 31:      * @param string $user User to check
 32:      */
 33:     static function format_datetime($time)
 34:     {
 35:         return strftime($GLOBALS['prefs']->getValue('date_format'), $time)
 36:             . ' '
 37:             . (date($GLOBALS['prefs']->getValue('twentyFour') ? 'G:i' : 'g:ia', $time));
 38:     }
 39: 
 40:     /**
 41:      * Returns avaiable countries
 42:      */
 43:     static function getCountries()
 44:     {
 45:         try {
 46:            return Horde::loadConfiguration('countries.php', 'countries', 'folks');
 47:         } catch (Horde_Exception $e) {
 48:             return Horde_Nls::getCountryISO();
 49:         }
 50:     }
 51: 
 52:     /**
 53:      * Get Image path
 54:      *
 55:      * @param string $user       Image username
 56:      * @param string $view       View type
 57:      * @param boolean $full      Generate a full URL.
 58:      */
 59:     static public function getImageUrl($user, $view = 'small', $full = false)
 60:     {
 61:         if (empty($GLOBALS['conf']['images']['direct'])) {
 62:             return Horde_Util::addParameter(Horde::url('view.php', $full),
 63:                                      array('view' => $view,
 64:                                            'id' => $user),
 65:                                      null, false);
 66:         } else {
 67:             $p = hash('md5', $user);
 68:             return $GLOBALS['conf']['images']['direct'] .
 69:                    '/' . substr(str_pad($p, 2, 0, STR_PAD_LEFT), -2) . '/' . $view . '/' .
 70:                    $p . '.' . $GLOBALS['conf']['images']['image_type'];
 71:         }
 72:     }
 73: 
 74:     /**
 75:      * Return a properly formatted link depending on the global pretty url
 76:      * configuration
 77:      *
 78:      * @param string $controller       The controller to generate a URL for.
 79:      * @param array $data              The data needed to generate the URL.
 80:      * @param boolean $full            Generate a full URL.
 81:      * @param integer $append_session  0 = only if needed, 1 = always,
 82:      *                                 -1 = never.
 83:      *
 84:      * @param string  The generated URL
 85:      */
 86:     function getUrlFor($controller, $data = null, $full = false, $append_session = 0)
 87:     {
 88:         switch ($controller) {
 89:         case 'list':
 90:             if (empty($GLOBALS['conf']['urls']['pretty'])) {
 91:                 return Horde::url($data . '.php', $full, $append_session);
 92:             } else {
 93:                 return Horde::url('list/' . $data, $full, $append_session);
 94:             }
 95: 
 96:         case 'feed':
 97:             if (empty($GLOBALS['conf']['urls']['pretty'])) {
 98:                 return Horde::url('rss/' . $data . '.php', $full, $append_session);
 99:             } else {
100:                 return Horde::url('feed/' . $data, $full, $append_session);
101:             }
102: 
103:         case 'user':
104:             if (empty($GLOBALS['conf']['urls']['pretty'])) {
105:                 return Horde_Util::addParameter(Horde::url('user.php', $full, $append_session), 'user', $data);
106:             } else {
107:                 return Horde::url('user/' . $data, $full, $append_session);
108:             }
109:         }
110:     }
111: 
112:     /**
113:      * Calculate user age
114:      */
115:     static public function calcAge($birthday)
116:     {
117:         if (substr($birthday, 0, 4) == '0000') {
118:             return array('age' => '', 'sign' => '');
119:         }
120: 
121:         list($year, $month, $day) = explode('-', $birthday);
122:         $year_diff = date('Y') - $year;
123:         $month_diff = date('m') - $month;
124:         $day_diff = date('d') - $day;
125: 
126:         if ($month_diff < 0) {
127:             $year_diff--;
128:         } elseif (($month_diff == 0) && ($day_diff < 0)) {
129:             $year_diff--;
130:         }
131: 
132:         if (empty($year_diff)) {
133:             return array('age' => '', 'sign' => '');
134:         }
135: 
136:         $sign = '';
137:         switch ($month) {
138: 
139:         case 1:
140:             $sign = ($day<21) ? _("Capricorn") : _("Aquarius");
141:             break;
142: 
143:         case 2:
144:             $sign = ($day<20) ? _("Aquarius") : _("Pisces");
145:             break;
146: 
147:         case 3:
148:             $sign = ($day<21) ? _("Pisces") : _("Aries");
149:             break;
150: 
151:         case 4:
152:             $sign = ($day<21) ? _("Aries") : _("Taurus");
153:             break;
154: 
155:         case 5:
156:             $sign = ($day<22) ? _("Taurus") : _("Gemini");
157:             break;
158: 
159:         case 6:
160:             $sign = ($day<22) ? _("Gemini") : _("Cancer");
161:             break;
162: 
163:         case 7:
164:             $sign = ($day<23) ? _("Cancer") : _("Leo");
165:             break;
166: 
167:         case 8:
168:             $sign = ($day<24) ? _("Leo") : _("Virgo");
169:             break;
170: 
171:         case 9:
172:             $sign = ($day<24) ? _("Virgo") : _("Libra");
173:             break;
174: 
175:         case 10:
176:             $sign = ($day<24) ? _("Libra") : _("Scorpio");
177:             break;
178: 
179:         case 11:
180:             $sign = ($day<23) ? _("Scorpio") : _("Sagittarius");
181:             break;
182: 
183:         case 12:
184:             $sign = ($day<21) ? _("Sagittarius") : _("Capricorn");
185:             break;
186: 
187:         }
188: 
189:         return array('age' => $year_diff, 'sign' => $sign);
190:     }
191: 
192:     /**
193:      * Returns a new or the current CAPTCHA string.
194:      */
195:     static public function getCAPTCHA($new = false)
196:     {
197:         global $session;
198: 
199:         if ($new || !$session->get('folks', 'captcha')) {
200:             $captcha = '';
201:             for ($i = 0; $i < 5; ++$i) {
202:                 $captcha .= chr(rand(65, 90));
203:             }
204:             $session->set('folks', 'captcha', $captcha);
205:         }
206: 
207:         return $session->get('folks', 'captcha');
208:     }
209: 
210:     /**
211:      * Get encripted cookie login string
212:      *
213:      * @param string $string   String to encode
214:      * @param string $key   Key to encode with
215:      *
216:      * @return string  Encripted
217:      */
218:     static function encodeString($string, $key)
219:     {
220:         $key = substr(hash('md5', $key), 0, 24);
221:         $iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_ECB);
222:         $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
223:         $string = mcrypt_ecb(MCRYPT_3DES, $key, $string, MCRYPT_ENCRYPT, $iv);
224:         return base64_encode($string);
225:     }
226: 
227:     /**
228:      * Send email with attachments
229:      *
230:      * @param string $from       From address
231:      * @param string $subject    Subject of message
232:      * @param string $body       Body of message
233:      * @param array  $attaches   Path of file to attach
234:      *
235:      * @return true on succes, PEAR_Error on failure
236:      */
237:     static public function sendMail($to, $subject, $body, $attaches = array())
238:     {
239:         $mail = new Horde_Mime_Mail(array(
240:             'body' => $body,
241:             'Subject' => $subject,
242:             'To' => $to,
243:             'From' => $GLOBALS['conf']['support'],
244:             'User-Agent' => 'Folks ' . $GLOBALS['registry']->getVersion(),
245:             'X-Originating-IP' => $_SERVER['REMOTE_ADDR'],
246:             'X-Remote-Browser' => $_SERVER['HTTP_USER_AGENT']));
247: 
248:         foreach ($attaches as $file) {
249:             if (file_exists($file)) {
250:                 $mail->addAttachment($file, null, null, 'UTF-8');
251:             }
252:         }
253: 
254:         return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
255:     }
256: 
257:     /**
258:      * Fetch user email
259:      *
260:      * @param string $user       Username
261:      *
262:      * @return email on succes, PEAR_Error on failure
263:      */
264:     static public function getUserEmail($user)
265:     {
266:         // We should always realy on registration data
267:         // $prefs = Horde_Prefs::singleton($GLOBALS['conf']['prefs']['driver'], 'horde', $registry->convertUsername($user, true), '', null, false);
268:         // $prefs->retrieve();
269:         // $email = $prefs->getValue('alternate_email') ? $prefs->getValue('alternate_email') : $prefs->getValue('from_addr');
270: 
271:         // If there is no email set use the registration one
272:         if (empty($email)) {
273:             if ($GLOBALS['registry']->isAuthenticated()) {
274:                 $profile = $GLOBALS['folks_driver']->getProfile($user);
275:             } else {
276:                 $profile = $GLOBALS['folks_driver']->getRawProfile($user);
277:             }
278:             if ($profile instanceof PEAR_Error) {
279:                 return $profile;
280:             }
281: 
282:             $email = $profile['user_email'];
283:         }
284: 
285:         if (empty($email)) {
286:             return PEAR::raiseError(_("Cannot retrieve user email."));
287:         } else {
288:             return $email;
289:         }
290:     }
291: 
292:     /**
293:      * Build Folks's list of menu items.
294:      */
295:     static function getMenu()
296:     {
297:         $menu = new Horde_Menu(Horde_Menu::MASK_ALL);
298:         $menu->add(self::getUrlFor('user', $GLOBALS['registry']->getAuth()), _("My profile"), 'myaccount.png');
299:         $menu->add(self::getUrlFor('list', 'friends'), _("Friends"), 'group.png');
300:         $menu->add(Horde::url('edit/edit.php'), _("Edit profile"), 'edit.png');
301:         $menu->add(Horde::url('services.php'), _("Services"), 'horde.png');
302:         $menu->add(Horde::url('search.php'), _("Search"), 'search.png');
303:         $menu->add(self::getUrlFor('list', 'online'), _("List"), 'group.png');
304: 
305:         return $menu;
306:     }
307: }
308: 
API documentation generated by ApiGen