Ejemplo n.º 1
0
 /**
  * process one file uploaded by handx weblog
  *
  * @param string the file to process
  */
 public static function process_handx_weblog($file)
 {
     global $context;
     // load parameters for uploads
     Safe::load('parameters/agents.include.php');
     if (!$context['uploads_nick_name']) {
         Logger::remember('agents/upload.php: no parameters, skipping ' . $file);
         return;
     }
     // read the input queue
     if (!($content = trim(Safe::file_get_contents($context['path_to_root'] . $file)))) {
         return;
     }
     // save in the output queue
     if ($handle = Safe::fopen($context['path_to_root'] . $file . '.bak', 'ab')) {
         fwrite($handle, $content);
         fclose($handle);
         // delete the input queue
         Safe::unlink($context['path_to_root'] . $file);
     }
     // date is derived from file name
     $name = basename($file);
     $year = substr($name, 0, 4);
     $month = substr($name, 4, 2);
     $day = substr($name, 6, 2);
     // split entries using the default separator value
     $separator = "/<table width=100%><tr><td class='time'>(.+?)<\\/td><\\/tr><\\/table>/";
     $entries = preg_split($separator, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
     // no time information
     if (@count($entries) == 1) {
         // make a stamp
         $stamp = gmstrftime('%Y-%m-%d %H:%M:%S', mktime(0, 0, 0, $month, $day, $year));
         // process this entry
         Uploads::process_handx_entry(trim($entries[0]), $stamp);
         // pairs of time and content strings
     } elseif (@count($entries) > 1) {
         // process all pairs
         for ($index = 0; $index < count($entries); $index++) {
             // the time as extracted by preg_split()
             $stamp = '';
             if (preg_match('/(\\d{1,2}):(\\d{1,2}) (am|pm)/', $entries[$index], $matches)) {
                 $index++;
                 // make a stamp
                 $hour = $matches[1];
                 $minutes = $matches[2];
                 if ($matches[3] == 'pm') {
                     $hour += 12;
                 }
                 $stamp = gmstrftime('%Y-%m-%d %H:%M:%S', mktime($hour, $minutes, 0, $month, $day, $year));
             }
             // the entry itself
             $entry = $entries[$index];
             // process this entry
             Uploads::process_handx_entry(trim($entry), $stamp);
         }
     }
 }