コード例 #1
0
ファイル: epg.class.php プロジェクト: saydulk/stalker_portal
 /**
  * Update EPG from one DB setting record.
  *
  * @param array $setting
  * @param bool $force
  * @return string Update result.
  */
 public function updateEpgBySetting($setting, $force = false)
 {
     $str = "From {$setting['uri']}\n";
     if (strpos($setting['uri'], 'http') === 0) {
         $etag = '';
         $headers = get_headers($setting['uri'], 1);
         if ($headers === false) {
             return "\n" . _("Source") . " " . $setting['uri'] . " " . _("unavailable") . "\n";
         }
         if (preg_match("/301 Moved Permanently/", $headers[0]) && !empty($headers['Location'])) {
             $setting['uri'] = $headers['Location'];
             return $this->updateEpgBySetting($setting, $force);
         } elseif (!preg_match("/200 OK/", $headers[0])) {
             return "\n" . _("Source") . " " . $setting['uri'] . " " . _("unavailable") . "\n";
         }
         if (!empty($headers['ETag'])) {
             $etag = $headers['ETag'];
         } else {
             if (!empty($headers['Last-Modified'])) {
                 $etag = $headers['Last-Modified'];
             } else {
                 $etag = time();
             }
         }
     } else {
         if (is_readable($setting['uri'])) {
             $etag = md5_file($setting['uri']);
         } else {
             return "\n" . _("Source") . " " . $setting['uri'] . " " . _("failed to open") . "\n";
         }
     }
     if ($setting['etag'] == $etag && !$force) {
         return _("Source") . " " . $setting['uri'] . " " . _("not changed") . "\n";
     }
     if (preg_match("/\\.gz\$/", $setting['uri'])) {
         $handle = gzopen($setting['uri'], 'r');
         if (!$handle) {
             return _("Source") . " " . $setting['uri'] . " " . _("failed to open") . "\n";
         }
         $tmpfname = tempnam("/tmp", "xmltv");
         $fp = fopen($tmpfname, "w");
         while (!gzeof($handle)) {
             $contents = gzread($handle, 1000000);
             fwrite($fp, $contents);
         }
         gzclose($handle);
         $xml = simplexml_load_file($tmpfname);
         unlink($tmpfname);
     } else {
         $xml = simplexml_load_file($setting['uri']);
     }
     $ids_arr = $this->getITVids();
     $data_arr = array();
     $start_time = microtime(1);
     $total_need_to_delete = array();
     foreach ($xml->programme as $programme) {
         $itv_id_arr = @$ids_arr[$setting['id_prefix'] . strval($programme->attributes()->channel)];
         if ($itv_id_arr) {
             $start = strtotime(strval($programme->attributes()->start));
             $stop = strtotime(strval($programme->attributes()->stop));
             $title = strval($this->getElementByLangCode($programme->title, $setting['lang_code']));
             $descr = strval($this->getElementByLangCode($programme->desc, $setting['lang_code']));
             $category = array();
             $director = array();
             $actor = array();
             if (!empty($programme->category)) {
                 foreach ($programme->category as $_category) {
                     $category[] = strval($this->getElementByLangCode($_category, $setting['lang_code']));
                 }
             }
             $category = implode(', ', $category);
             if (!empty($programme->credits->director)) {
                 foreach ($programme->credits->director as $_director) {
                     $director[] = strval($this->getElementByLangCode($_director, $setting['lang_code']));
                 }
             }
             $director = implode(', ', $director);
             if (!empty($programme->credits->actor)) {
                 foreach ($programme->credits->actor as $_actor) {
                     $actor[] = strval($this->getElementByLangCode($_actor, $setting['lang_code']));
                 }
             }
             $actor = implode(', ', $actor);
             foreach ($itv_id_arr as $itv_id) {
                 $correction_time = $this->getCorrectionTimeByChannelId($itv_id);
                 $start_ts = $start + $correction_time * 60;
                 $need_to_delete = $this->getProgramIdsForClean($start_ts, $itv_id);
                 if ($need_to_delete) {
                     $total_need_to_delete = array_merge($total_need_to_delete, $need_to_delete);
                 }
             }
             foreach ($itv_id_arr as $itv_id) {
                 $correction_time = $this->getCorrectionTimeByChannelId($itv_id);
                 $start_ts = $start + $correction_time * 60;
                 $mysql_start = date("Y-m-d H:i:s", $start_ts);
                 $stop_ts = $stop + $correction_time * 60;
                 $mysql_stop = date("Y-m-d H:i:s", $stop_ts);
                 $duration = $stop_ts - $start_ts;
                 $real_id = $itv_id . '_' . $start_ts;
                 if (isset($this->real_ids[$real_id])) {
                     continue;
                 }
                 $this->real_ids[$real_id] = true;
                 $data_arr[] = array('ch_id' => $itv_id, 'time' => $mysql_start, 'time_to' => $mysql_stop, 'duration' => $duration, 'real_id' => $real_id, 'name' => $title, 'descr' => $descr, 'category' => $category, 'director' => $director, 'actor' => $actor);
                 $this->channels_updated[$itv_id] = 1;
             }
         }
     }
     $xml = null;
     $total_need_to_delete = array_diff($total_need_to_delete, $this->new_ids);
     if (!empty($total_need_to_delete)) {
         Mysql::getInstance()->query('delete from epg where id in (' . implode(', ', array_unique($total_need_to_delete)) . ')');
         Mysql::getInstance()->query('OPTIMIZE TABLE epg');
     }
     if (!empty($data_arr)) {
         $result = $this->db->insert('epg', $data_arr);
         $real_ids = array_map(function ($item) {
             return $item['real_id'];
         }, $data_arr);
         $this->new_ids = array_merge(Mysql::getInstance()->from('epg')->in('real_id', $real_ids)->get()->all('id'), $this->new_ids);
     } else {
         $result = true;
     }
     $setting['etag'] = $etag;
     $this->setSettings($setting);
     //$str = sprintf(_("Updated %d channels from %d, %d errors"), $done, $total, $err)." \n";
     $str = "\n";
     if (!$result) {
         $str .= "<b>" . _("Errors") . ": </b> 1\n";
     }
     $str .= "<b>" . sprintf(_("Successful: %s channels"), count($this->channels_updated)) . "</b>\n";
     $str .= "<b>" . sprintf(_("Deleted: %s records"), count($total_need_to_delete)) . "</b>\n";
     $str .= "<b>" . _("Queries") . ": </b>" . Mysql::get_num_queries() . "\n";
     $str .= "<b>" . _("Exec time") . ": </b>" . round(microtime(1) - $start_time, 2) . 's';
     $this->channels_updated = array();
     return $str;
 }
コード例 #2
0
ファイル: load.php プロジェクト: kamekun/WrapperPHP
<?php

$start_time = microtime(1);
// no cache
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
require_once "init.php";
set_error_handler(array($debug = Debug::getInstance(), 'parsePHPError'));
print "generated in: " . round(microtime(1) - $start_time, 3) . "s; query counter: " . Mysql::get_num_queries() . "; cache hits: " . Mysql::get_cache_hits() . "; cache miss: " . Mysql::get_cache_misses() . "; " . $debug->getErrorStr();
コード例 #3
0
ファイル: tasks.php プロジェクト: Eugen1985/stalker_portal
        echo "<td><b>#</b></td>";
        echo "<td><b>" . _('Movie') . "</b></td>";
        echo "<td><b>" . _('Date') . "</b></td>";
        echo "<td><b>" . _('Opening date') . "</b></td>";
        echo "<td>&nbsp;</td>";
        echo "</tr>";
        $num = 0;
        while ($arr = $tasks->next()) {
            $num++;
            echo "<tr>";
            echo "<td>" . $num . "</td>";
            //echo "<td><a href='msgs.php?task={$arr['id']}'>".get_media_name_by_id($arr['media_id'])."</a></td>";
            echo "<td>" . $arr['name'] . "</td>";
            echo "<td>" . $arr['login'] . "</td>";
            echo "<td>" . $arr['start_time'] . "</td>";
            echo '<td><a href="reject_task.php?id=' . $arr['id'] . '&send_to=' . $arr['media_id'] . '">' . _('reject') . '</a></td>';
            echo "</tr>";
        }
        echo "</table>";
    }
    echo "<br>";
    echo "<br>";
    echo "<br>";
}
?>
</td>
</tr>
</table>
<?php 
echo 'queries: ' . Mysql::get_num_queries() . '<br>';
echo 'generated in: ' . round(microtime(1) - $start_time, 3) . 's';