prepend.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. require dirname(__FILE__).'/../inc/prepend.php';
  23. # Si on a une session active
  24. if (defined('DC_SESSION_NAME') && isset($_COOKIE[DC_SESSION_NAME])) {
  25. require dirname(__FILE__).'/../inc/session.php';
  26. }
  27. require dirname(__FILE__).'/lib.mod.php';
  28. require dirname(__FILE__).'/lib.cache.php';
  29. require dirname(__FILE__).'/class.xblog.php';
  30. require dirname(__FILE__).'/class.xblogpost.php';
  31. require dirname(__FILE__).'/class.xblogcomment.php';
  32. require dirname(__FILE__).'/functions.php';
  33. $mode = dcGetMod();
  34. $year = $month = $day = NULL;
  35. $post_id = (!empty($_GET['p'])) ? $_GET['p'] : NULL;
  36. $cat_id = (!empty($_GET['cat'])) ? $_GET['cat'] : NULL;
  37. $lang = (!empty($_GET['l'])) ? $_GET['l'] : NULL;
  38. $mod_files = $mod_ts = array();
  39. if (!empty($_GET['d'])) {
  40. $year = substr($_GET['d'],0,4);
  41. if (strlen($_GET['d']) >= 7) {
  42. $month = substr($_GET['d'],5,2);
  43. if (strlen($_GET['d']) == 10) {
  44. $day = substr($_GET['d'],8,2);
  45. }
  46. }
  47. }
  48. $err_msg = $form_err = $form_msg = '';
  49. # Tableau des dates de modif
  50. $arry_last_mod = array();
  51. # Variables pour le formulaire
  52. $c_nom = $c_mail = $c_content = '';
  53. $c_site = 'http://';
  54. $preview = false;
  55. if (!empty($_COOKIE['comment_info'])) {
  56. $c_cookie = unserialize($_COOKIE['comment_info']);
  57. $c_nom = $c_cookie['c_nom'];
  58. $c_mail = $c_cookie['c_mail'];
  59. $c_site = $c_cookie['c_site'];
  60. }
  61. # Variable de conf
  62. $theme_path = $blog_dc_path.'/themes/';
  63. $theme_uri = dc_app_url.'/themes/';
  64. $img_path = dc_img_url;
  65. # Définition du thème et de la langue
  66. $__theme = dc_theme;
  67. $__lang = dc_default_lang;
  68. # Ajout des functions.php des plugins
  69. $objPlugins = new plugins(dirname(__FILE__).'/../'.DC_ECRIRE.'/tools/');
  70. foreach ($objPlugins->getFunctions() as $pfunc) {
  71. require_once $pfunc;
  72. }
  73. # Définition du template
  74. if (!is_dir($theme_path.$__theme)) {
  75. header('Content-type: text/plain');
  76. echo 'Le thème '.$__theme.' n\'existe pas';
  77. exit;
  78. }
  79. if (file_exists($theme_path.$__theme.'/template.php')) {
  80. $dc_template_file = $theme_path.$__theme.'/template.php';
  81. } else {
  82. $dc_template_file = $theme_path.'default/template.php';
  83. }
  84. # Prepend du template s'il existe
  85. if (file_exists(dirname($dc_template_file).'/prepend.php')) {
  86. require dirname($dc_template_file).'/prepend.php';
  87. }
  88. # Chargement des langues
  89. if (dc_encoding == 'UTF-8') {
  90. l10n::set(dirname(__FILE__).'/../l10n/'.$__lang.'-utf8/date');
  91. l10n::set(dirname(__FILE__).'/../l10n/'.$__lang.'-utf8/messages');
  92. } else {
  93. l10n::set(dirname(__FILE__).'/../l10n/'.$__lang.'/date');
  94. l10n::set(dirname(__FILE__).'/../l10n/'.$__lang.'/messages');
  95. }
  96. # Fichier de langue du template s'il existe
  97. if (dc_encoding == 'UTF-8') {
  98. l10n::set(dirname($dc_template_file).'/l10n/'.$__lang.'-utf8/main');
  99. } else {
  100. l10n::set(dirname($dc_template_file).'/l10n/'.$__lang.'/main');
  101. }
  102. /* Création du tableau des dates de modification de tous les fichiers
  103. inclus. On ajoute aussi le fichier UPDATE, append.php, le template,
  104. dotclear.ini et tous les fichiers de langue */
  105. $mod_files = array_merge($mod_files,get_included_files(),$GLOBALS['__l10n_files']);
  106. $mod_files[] = DC_UPDATE_FILE;
  107. $mod_files[] = $dc_template_file;
  108. $mod_files[] = $blog_dc_path.'/layout/append.php';
  109. $mod_files[] = $blog_dc_path.'/conf/dotclear.ini';
  110. # Cache HTTP
  111. if (dc_http_cache && $mode != 'search' && empty($_POST) &&
  112. defined('DC_UPDATE_FILE_W') && DC_UPDATE_FILE_W)
  113. {
  114. cache::http($mod_files,$mod_ts);
  115. }
  116. # Connexion et création du blog
  117. $con = new connection(DB_USER,DB_PASS,DB_HOST,DB_DBASE);
  118. if($con->error()) {
  119. header('Content-Type: text/plain');
  120. echo 'MySQL Error : '.$con->error();
  121. exit;
  122. }
  123. $blog = new xblog($con,DB_PREFIX,1,dc_encoding);
  124. $blog->rs_blogpost = 'xblogpost';
  125. $blog->rs_blogcomment = 'xblogcomment';
  126. $blog->setLang($lang);
  127. $blog->setURL('post',dc_blog_url.dc_format_post_url);
  128. $blog->setURL('cat',dc_blog_url.dc_format_cat_url);
  129. $blog->setURL('archive',dc_blog_url.dc_format_archive_url);
  130. $blog->setURL('day',dc_blog_url.dc_format_day_url);
  131. $blog->setDateFormat(dc_date_format,dc_time_format);
  132. $blog->setUseSmilies(dc_use_smilies);
  133. if (is_dir($theme_path.$__theme.'/smilies/')) {
  134. $blog->setSmiliesPath($theme_path.$__theme.'/smilies/',$theme_uri.$__theme.'/smilies/');
  135. } else {
  136. $blog->setSmiliesPath($theme_path.'default/smilies/',$theme_uri.'default/smilies/');
  137. }
  138. # postcon.php du template s'il existe
  139. if (file_exists(dirname($dc_template_file).'/postcon.php')) {
  140. require dirname($dc_template_file).'/postcon.php';
  141. }
  142. # postcon.php des plugins
  143. foreach ($objPlugins->getFunctions('postcon.php') as $pfunc) {
  144. require_once $pfunc;
  145. }
  146. # Catégories
  147. $rs_cat = $blog->getCat();
  148. # Mois pour les archives
  149. $arry_months = $blog->getAllDates('m','','','',$cat_id);
  150. # Les langues du blog
  151. $rs_lang = $blog->getPostLanguages();
  152. if($mode == 'home' || ($mode == 'cat' && $cat_id) || $mode == 'year')
  153. {
  154. # Dernières nouvelles
  155. $news = $blog->getLastNews(dc_nb_post_per_page,$cat_id,'post_dt DESC');
  156. if ($news->isEmpty()) {
  157. $err_msg = '<p>'.__('No entry.').'</p>';
  158. }
  159. }
  160. elseif($mode == 'day')
  161. {
  162. $news = $blog->getPostByDate($year,$month,$day,$cat_id,'post_dt DESC');
  163. if ($news->isEmpty()) {
  164. $err_msg = '<p>'.__('No entry.').'</p>';
  165. }
  166. }
  167. elseif($mode == 'month')
  168. {
  169. $news = $blog->getPostByDate($year,$month,'',$cat_id,'post_dt DESC');
  170. if ($news->isEmpty()) {
  171. $err_msg = '<p>'.__('No entry.').'</p>';
  172. }
  173. }
  174. elseif($mode == 'post' && $post_id)
  175. {
  176. $news = $blog->getPostByID($post_id);
  177. if ($news->isEmpty())
  178. {
  179. $err_msg = '<p>'.__('No entry.').'</p>';
  180. }
  181. else
  182. {
  183. # Ajout d'un commentaire
  184. if (!empty($_POST['redir']) && $news->openComment())
  185. {
  186. $c_nom = trim($_POST['c_nom']);
  187. $c_mail = trim($_POST['c_mail']);
  188. $c_site = trim($_POST['c_site']);
  189. if (trim($_POST['c_content']) == '')
  190. {
  191. $in_content = $c_content = '';
  192. }
  193. else
  194. {
  195. $c_content = $_POST['c_content'];
  196. if (dc_wiki_comments)
  197. {
  198. $objWiki = new wiki2xhtmlComment();
  199. # Options wiki
  200. $objWiki->setOpt('active_fix_word_entities',(dc_encoding != 'UTF-8'));
  201. $objWiki->setOpt('active_fr_syntax',(dc_default_lang == 'fr'));
  202. $in_content = $objWiki->transform($c_content);
  203. }
  204. else
  205. {
  206. $in_content = '<p>'.
  207. nl2br($blog->parseContent(htmlspecialchars($c_content))).'</p>';
  208. }
  209. }
  210. if (!empty($_POST['preview']))
  211. {
  212. $preview = true;
  213. }
  214. else
  215. {
  216. if ($blog->addComment($post_id,$c_nom,$c_mail,$c_site,
  217. $in_content,0,dc_time_delta,dc_comments_pub) === false)
  218. {
  219. $form_err = $blog->error(1,0);
  220. }
  221. else
  222. {
  223. if (!empty($_POST['c_remember']) || !empty($_COOKIE['comment_info']))
  224. {
  225. $c_cookie = array(
  226. 'c_nom' => $c_nom,
  227. 'c_mail' => $c_mail,
  228. 'c_site' => $c_site
  229. );
  230. $c_cookie = serialize($c_cookie);
  231. setcookie('comment_info',$c_cookie,
  232. strtotime('+3 month'),'/',
  233. $_SERVER['HTTP_HOST']);
  234. }
  235. if (dc_comment_notification && $news->f('user_email') != ''
  236. && $news->f('user_email') != $c_mail)
  237. {
  238. $n_titre = $blog->removeEntities($news->f('post_titre'));
  239. $n_mail = $news->f('user_email');
  240. $n_subject = util::mimeEncode('['.dc_blog_name.'] '.$n_titre,dc_encoding);
  241. $n_content =
  242. sprintf(__('Comment for entry %s'),$n_titre)."\n\n".
  243. sprintf(__('By: %s'),$c_nom.(($c_mail!='') ? ' <'.$c_mail.'>' : ''))."\n".
  244. sprintf(__('Website: %s'),$c_site)."\n".
  245. "\n".str_replace("\r",'',$c_content)."\n\n".
  246. "--\n".
  247. 'http://'.$_SERVER['HTTP_HOST'].$news->getPermURL();
  248. if (isset($_SERVER['REMOTE_ADDR'])) {
  249. $client_ip = $_SERVER['REMOTE_ADDR'];
  250. } else {
  251. $client_ip = "unknown";
  252. }
  253. $n_headers =
  254. 'From: '.$n_mail."\r\n".
  255. (($c_mail!='') ? 'Reply-To: '.$c_mail."\r\n" : '').
  256. 'Content-Type: text/plain; charset='.dc_encoding.";\r\n".
  257. "X-Mailer: DotClear\r\n".
  258. 'X-Blog: http://'.$_SERVER['HTTP_HOST'].dc_blog_url."\r\n".
  259. 'X-Client: '.$client_ip."\r\n";
  260. @mail($n_mail,$n_subject,$n_content,$n_headers);
  261. }
  262. $redir = $_POST['redir'].(strpos($_POST['redir'],'?') ? '&' : '?').'cos=1';
  263. header('Location: '.$redir);
  264. exit;
  265. }
  266. }
  267. }
  268. # Message si modération
  269. if (!empty($_GET['cos']) && dc_comments_pub == 0) {
  270. $form_msg = __('Your comment has been sent '.
  271. 'successfully. It will be online soon.');
  272. }
  273. $comments = $blog->getComments($post_id);
  274. $trackbacks = $comments->extractTrackbacks();
  275. $rs_prev = $blog->getNextID($news->getTS(),-1);
  276. $rs_next = $blog->getNextID($news->getTS(),1);
  277. }
  278. }
  279. elseif($mode == 'search')
  280. {
  281. # Résultat de recherche
  282. $news = $blog->searchPost($_GET['q']);
  283. if ($news->isEmpty()) {
  284. $err_msg =
  285. '<p>'.
  286. sprintf(__('Search of %s doesn\'t give any result.'),
  287. '<em>'.htmlspecialchars($_GET['q']).'</em>').
  288. '</p>';
  289. }
  290. }
  291. ?>