<?php
// vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
// $Id$
function tribune_colissimo_info() {
return t('Donne l\'état d\'un colis colissimo.');
}
function tribune_colissimo_filter(&$post) {
'info' => variable_get('tribune_colissimo_name', "Colissimo"),
);
if (variable_get('tribune_colissimo_authentified', FALSE)) {
$answer['login'] = $answer['info'];
}
if (preg_match(':^/'. t
('colissimo') .'(.*)$:', $post['message'], $matches)) {
$args = $matches[1];
$response = _tribune_colissimo_status($args);
if ($response['error']) {
$answer['message'] = $response['error'];
} else {
$answer['message'] = $response['text'];
}
$answer['message'] = tribune_filters_print_clock($post) ." ". $answer['message'];
}
}
function _tribune_colissimo_status($id) {
$url = "http://www.coliposte.net/ec/suivi_ec.jsp?colispart=". urlencode($id);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = iconv("ISO-8859-1", "UTF-8", $result);
'<td.*>(.*)</td>.*'.
'<td.*>(.*)</td>.*'.
'<td.*>(.*)</td>.*'.
'<td.*>(.*)</td>.*'.
'</tr>:Um', $result, $matches, PREG_SET_ORDER);
$status = "";
foreach ($matches as $match) {
$centre = trim($match[4]);
if (preg_match(':(.*)\W*\((.*)\).*:Um', $centre, $array)) {
}
$status .= t
("<b>!date</b> - <i>!centre</i> !desc ", array('!date' => $date, '!desc' => $desc, '!centre' => $centre));
}
return array('error' => FALSE, 'text' => $status);
}
function tribune_colissimo_settings() {
$form['tribune_colissimo_name'] = array(
'#type' => "textfield",
'#title' => t("Display name"),
'#default_value' => variable_get('tribune_colissimo_name', "Colissimo"),
);
$form['tribune_colissimo_authentified'] = array(
'#type' => "checkbox",
'#title' => t("Appear to be authentified"),
'#default_value' => variable_get('tribune_colissimo_authentified', FALSE),
'#description' => t("Whether this filter will appear to be 'anonymous' or 'authentified'. Since the filter does not correspond to a real user, posting as authentified may result in 'nickname collisions'."),
);
return system_settings_form($form);
}