function create_atom($file_path, $mode, $id, $title, $topics) { global $bb_cfg; $dir = dirname($file_path); if (!file_exists($dir)) { if (!bb_mkdir($dir)) { return false; } } foreach ($topics as $topic) { $last_time = $topic['topic_last_post_time']; if ($topic['topic_last_post_edit_time']) { $last_time = $topic['topic_last_post_edit_time']; } $date = bb_date($last_time, 'Y-m-d', 0); $time = bb_date($last_time, 'H:i:s', 0); break; } $atom = ""; $atom .= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; $atom .= "<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:base=\"http://" . $bb_cfg['server_name'] . $bb_cfg['script_path'] . "\">\n"; $atom .= "<title>{$title}</title>\n"; $atom .= "<updated>" . $date . "T{$time}+00:00</updated>\n"; $atom .= "<id>tag:rto.feed,2000:/{$mode}/{$id}</id>\n"; $atom .= "<link href=\"http://" . $bb_cfg['server_name'] . $bb_cfg['script_path'] . "\" />\n"; foreach ($topics as $topic) { $topic_id = $topic['topic_id']; $tor_size = ''; if (isset($topic['tor_size'])) { $tor_size = str_replace(' ', ' ', ' [' . humn_size($topic['tor_size']) . ']'); } $topic_title = $topic['topic_title']; $orig_word = array(); $replacement_word = array(); obtain_word_list($orig_word, $replacement_word); if (count($orig_word)) { $topic_title = preg_replace($orig_word, $replacement_word, $topic_title); } $topic_title = wbr($topic_title); $author_name = $topic['first_username'] ? wbr($topic['first_username']) : 'Гость'; $last_time = $topic['topic_last_post_time']; if ($topic['topic_last_post_edit_time']) { $last_time = $topic['topic_last_post_edit_time']; } $date = bb_date($last_time, 'Y-m-d', 0); $time = bb_date($last_time, 'H:i:s', 0); $updated = ''; $checktime = TIMENOW - 604800; // неделя (week) if ($topic['topic_first_post_edit_time'] && $topic['topic_first_post_edit_time'] > $checktime) { $updated = '[Обновлено] '; } $atom .= "<entry>\n"; $atom .= "\t<title type=\"html\"><![CDATA[{$updated}{$topic_title}{$tor_size}]]></title>\n"; $atom .= "\t<author>\n"; $atom .= "\t\t<name>{$author_name}</name>\n"; $atom .= "\t</author>\n"; $atom .= "\t<updated>" . $date . "T{$time}+00:00</updated>\n"; $atom .= "\t<id>tag:rto.feed," . $date . ":/t/{$topic_id}</id>\n"; $atom .= "\t<link href=\"viewtopic.php?t={$topic_id}\" />\n"; $atom .= "</entry>\n"; } $atom .= "</feed>"; @unlink($file_path); $fp = fopen($file_path, "w"); fwrite($fp, $atom); fclose($fp); return true; }
function _move($file_path) { $dir = dirname($file_path); if (!file_exists($dir)) { if (!bb_mkdir($dir)) { $this->errors[] = "Cannot create dir: {$dir}"; return false; } } if (!@rename($this->file['tmp_name'], $file_path)) { if (!@copy($this->file['tmp_name'], $file_path)) { $this->errors[] = 'Cannot copy tmp file'; return false; } @unlink($this->file['tmp_name']); } @chmod($file_path, 0664); return file_exists($file_path); }
function file_write($str, $file, $max_size = LOG_MAX_SIZE, $lock = true, $replace_content = false) { $bytes_written = false; if ($max_size && @filesize($file) >= $max_size) { $old_name = $file; $ext = ''; if (preg_match('#^(.+)(\\.[^\\/]+)$#', $file, $matches)) { $old_name = $matches[1]; $ext = $matches[2]; } $new_name = $old_name . '_[old]_' . date('Y-m-d_H-i-s_') . getmypid() . $ext; clearstatcache(); if (@file_exists($file) && @filesize($file) >= $max_size && !@file_exists($new_name)) { @rename($file, $new_name); } } if (!($fp = @fopen($file, 'ab'))) { if ($dir_created = bb_mkdir(dirname($file))) { $fp = @fopen($file, 'ab'); } } if ($fp) { if ($lock) { @flock($fp, LOCK_EX); } if ($replace_content) { @ftruncate($fp, 0); @fseek($fp, 0, SEEK_SET); } $bytes_written = @fwrite($fp, $str); @fclose($fp); } return $bytes_written; }