1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: class Folks {
15:
16: const VFS_PATH = '.horde/folks';
17:
18: 19: 20: 21: 22:
23: static function format_date($time)
24: {
25: return strftime($GLOBALS['prefs']->getValue('date_format'), $time);
26: }
27:
28: 29: 30: 31: 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: 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: 54: 55: 56: 57: 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: 76: 77: 78: 79: 80: 81: 82: 83: 84: 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: 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: 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: 212: 213: 214: 215: 216: 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: 229: 230: 231: 232: 233: 234: 235: 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: 259: 260: 261: 262: 263:
264: static public function getUserEmail($user)
265: {
266:
267:
268:
269:
270:
271:
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: 294:
295: static function ()
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: