/htdocs/scieloOrg/php/wpPosts.php

https://github.com/robertatakenaka/Web · PHP · 440 lines · 371 code · 53 blank · 16 comment · 21 complexity · 12bfe61a3e8655881edc5eadac0fad68 MD5 · raw file

  1. <?php
  2. ini_set("display_errors","1");
  3. error_reporting(E_ALL ^E_NOTICE);
  4. $lang = isset($_REQUEST['lang'])?($_REQUEST['lang']):"";
  5. $pid = isset($_REQUEST['pid'])?($_REQUEST['pid']):"";
  6. $defFile = parse_ini_file(dirname(__FILE__)."/../../scielo.def.php");
  7. require_once(dirname(__FILE__)."/../../applications/scielo-org/users/functions.php");
  8. require_once(dirname(__FILE__)."/../../applications/scielo-org/users/langs.php");
  9. require_once(dirname(__FILE__)."/../../classDefFile.php");
  10. require_once(dirname(__FILE__)."/../../applications/scielo-org/classes/services/ArticleServices.php");
  11. require_once(dirname(__FILE__)."/../../applications/scielo-org/classes/wpPosts.php");
  12. require_once(dirname(__FILE__)."/../../applications/scielo-org/classes/wpBlog.php");
  13. require_once(dirname(__FILE__)."/../../applications/scielo-org/sso/header.php");
  14. $applServer = $defFile["SERVER_SCIELO"];
  15. $applServerOrg = $defFile["SCIELO_REGIONAL_DOMAIN"];
  16. $wordpress = $defFile["DB_WORDPRESS"];
  17. $databasePath = $defFile["PATH_DATABASE"];
  18. $flagLog = $defFile["ENABLE_SERVICES_LOG"];
  19. $blogLastComment = $_REQUEST['commentID'];
  20. $show_login = $defFile["show_login"];
  21. $login_error = $_REQUEST["error"];
  22. //getting metadatas from PID
  23. $articleService = new ArticleService($applServer);
  24. $articleService->setParams($pid);
  25. $article = $articleService->getArticle();
  26. $ArticleDAO = new articleDAO();
  27. $BlogDAO = new wpBlogDAO();
  28. $PostsDAO = new wpPostsDAO();
  29. $insertDate = date('Y-m-d h:i:s');
  30. $acron = $_REQUEST["acron"];
  31. $guidUrl = "http://".$wordpress."/".$acron."/".substr($insertDate,0,4)."/".substr($insertDate,5,2)."/".substr($insertDate,8,2)."/".$article->getPID()."/";
  32. $guiSubmit = "http://".$wordpress."/".$acron."/wp-comments-post.php";
  33. $Post = new wpPosts();
  34. $Post->setPostName($article->getPID());
  35. $Post->setPostGuid($guidUrl);
  36. $Post->setPostDate($insertDate);
  37. $title = $article->getTitle();
  38. /************************************************
  39. * Transformando e assegurando que o Title seja cadastrado em English
  40. ************************************************/
  41. $posTitleEn = strpos($article->getTitle(),'"en"');
  42. $titleEn = substr($title, $posTitleEn);
  43. $title = ereg_replace("<[^>]*>", "",$titleEn);
  44. $title = str_replace('"en">',"",$title);
  45. $title = str_replace("]]>","",$title);
  46. $Post->setPostTitle($title);
  47. /************************************************/
  48. $Post->setPostAuth("1");
  49. $Post->setPostDateGmt($insertDate);
  50. /************************************************
  51. * Abstract cadastrado nas duas linguagens
  52. ************************************************/
  53. $abstract = $article->getAbstractXML();
  54. $posAbstractpt = strpos($article->getAbstractXML(),'"pt\"');
  55. if($posAbstractpt){
  56. $abstractpt = substr($abstract, $posAbstractpt);
  57. $abstract = str_replace('"pt\"><![CDATA[',"",$abstractpt);
  58. $abstract = str_replace(']]></ABSTRACT>',"",$abstract);
  59. }else{
  60. $posAbstracten = strpos($article->getAbstractXML(),'"en\"');
  61. $abstracten = substr($abstract, $posAbstracten);
  62. $abstract = str_replace('"en\"><![CDATA[',"",$abstracten);
  63. $abstract = str_replace(']]></ABSTRACT>',"",$abstract);
  64. }
  65. $Post->setPostContent($abstract);
  66. /************************************************/
  67. $Post->setPostCategory("0");
  68. $Post->setPostStatus("publish");
  69. $Post->setPingStatus("open");
  70. $Post->setPostModified($insertDate);
  71. $Post->setPostModifiedGmt($insertDate);
  72. $Post->setPostParent("0");
  73. $Post->setMenuOrder("0");
  74. $Post->setCommentCount("0");
  75. $Post->setCommentStatus("1");
  76. $blogId = $BlogDAO->getBlogIdByName($acron);
  77. $blogTable = "wp_".$blogId."_posts";
  78. if($ArticleDAO->getArticleByPID($article->getPID())){//se o artigo existe
  79. if($ArticleDAO->getWpPostByID($article->getPID())){//se existe o id do blog
  80. $postDate = $ArticleDAO->getPostDate($article->getPID());
  81. //redefinindo a url
  82. $guidUrl = "http://".$wordpress."/".$acron."/".substr($postDate,0,4)."/".substr($postDate,5,2)."/".substr($postDate,8,2)."/".$article->getPID()."/";
  83. }else{
  84. if ($blogId != 0){
  85. //verifica se blog da revista j� existe.
  86. $addedPostId = $PostsDAO->addPost($Post,$blogId);
  87. $article->setWpPostID($addedPostId);
  88. $article->setWpURL($guidUrl);
  89. $article->setWpPostDate($insertDate);
  90. //Pesquisa o ID do Blog
  91. $ArticleDAO->updatePosts($article,$blogId);
  92. }
  93. }
  94. }else{
  95. if ($blogId != 0){ //verifica se blog da revista j� existe.
  96. //Adiciona o post
  97. $addedPostId = $PostsDAO->addPost($Post,$blogId);
  98. $article->setWpPostID($addedPostId);
  99. $article->setWpURL($guidUrl);
  100. $article->setWpPostDate($insertDate);
  101. //Pesquisa o ID do Blog
  102. $ArticleDAO->AddArticle($article);
  103. }
  104. }
  105. ?>
  106. <!DOCTYPE html
  107. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  108. <html>
  109. <head>
  110. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  111. <script language="javascript" src="../js/validate.js"></script>
  112. <link rel="stylesheet" href="/applications/scielo-org/css/public/style-<?=$lang?>.css" type="text/css" media="screen"/>
  113. </head>
  114. <body>
  115. <div class="container">
  116. <div class="level2">
  117. <div class="bar">
  118. </div>
  119. <div class="top">
  120. <div id="parent">
  121. <img src="/img/<?=$lang?>/scielobre.gif" alt="SciELO - Scientific Electronic Library Online"/>
  122. </div>
  123. <div id="identification">
  124. <h1>
  125. <span>
  126. SciELO - Scientific Electronic Library Online
  127. </span>
  128. </h1>
  129. </div>
  130. </div>
  131. <div class="middle">
  132. <div id="collection">
  133. <h3>
  134. <span>
  135. <?=COMMENTS_ARTICLE?>
  136. </span>
  137. <?
  138. if($_COOKIE["userID"] && $_COOKIE["userID"]!=-2 && $blogId!=0){
  139. ?>
  140. <span class="addSpanAnchor">
  141. <A HREF="#add" class="addCommentAnchor"><?=COMMENTS_ADD?></A>
  142. </span>
  143. <?
  144. }
  145. ?>
  146. <?if($blogId!=0){?>
  147. <span>
  148. <a class="rssComments" target="_blank" title=<?="RSS Feed".$title ?> href=<?=$guidUrl."feed/"?>><img src=<?='"http://'.$_SERVER["SERVER_NAME"].'/img/feed.gif"'?>> </a>
  149. </span>
  150. <?}?>
  151. </h3>
  152. <div class="content">
  153. <form action="<?php echo $guiSubmit?>" method="post" id="commentform" onSubmit="return validaSubmit()" >
  154. <TABLE border="0" cellpadding="0" cellspacing="2" width="700" align="center">
  155. <TR>
  156. <TD colspan="2">
  157. <h3><span style="font-weight:100;font-size: 70%; background:none;">
  158. <?php
  159. include(dirname(__FILE__)."/displayReference.php");
  160. ?>
  161. <br/><br/>
  162. </span></h3>
  163. </TD>
  164. </TR>
  165. <TR>
  166. <TD colspan="2">
  167. <?php
  168. if($blogId!=0){
  169. $serviceUrl = $guidUrl."feed/";
  170. $xmlFile = file_get_contents($serviceUrl);
  171. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  172. $xml .='<root>';
  173. $xml .='<vars><lang>'.$lang.'</lang><applserver>'. $wordpress .'</applserver><service_log>'.$flagLog.'</service_log></vars>';
  174. $xml .= str_replace('<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->','',$xmlFile);
  175. $xml .='</root>';
  176. if(isset($_REQUEST['debug']))
  177. {
  178. echo '<textarea cols="100" rows="50">';
  179. echo $xml;
  180. echo '</textarea>';
  181. exit;
  182. }
  183. $xsl = $defFile["PATH_XSL"]."comments.xsl";
  184. $transformer = new XSLTransformer();
  185. $transformer->setXslBaseUri($defFile["PATH_XSL"]);
  186. $transformer->setXml($xml);
  187. $transformer->setXslFile($xsl);
  188. $transformer->transform();
  189. $output = $transformer->getOutput();
  190. $output = str_replace('&amp;','&',$output);
  191. $output = str_replace('&slt;','<',$output);
  192. $output = str_replace('&gt;','>',$output);
  193. $output = str_replace('&quot;','"',$output);
  194. $output = str_replace('<p>',' ',$output);
  195. $output = str_replace('</p>',' ',$output);
  196. echo $output;
  197. }
  198. ?>
  199. </TD>
  200. </TR>
  201. <TR>
  202. <TD colspan="2" >
  203. <?
  204. //Verificando se o User esta logado e se o blog existe
  205. if($_COOKIE["userID"] && $_COOKIE["userID"]!=-2 && $blogId!=0){?>
  206. <h3>
  207. <span class="addComments">
  208. <A NAME="add"></A>
  209. <?
  210. $quotes = array("(",")");
  211. $comments = str_replace($quotes,"",COMMENTS_ADD);
  212. echo $comments;
  213. ?>
  214. </span>
  215. </h3>
  216. <?
  217. if(isset($blogLastComment)){?>
  218. <ol class="commentlist">
  219. <li class="liComments">
  220. <div class="divComments">
  221. <?php
  222. $lastComment = $PostsDAO->getLastComment($blogId,$blogLastComment);
  223. echo COMMNETS_MESSAGE_INFO_1;
  224. echo $lastComment[0]['comment_author'];
  225. echo COMMNETS_MESSAGE_INFO_2;
  226. ?>
  227. <div class="divCommentText">
  228. <?=$lastComment[0]['comment_content'];?>
  229. </div>
  230. </div>
  231. </li>
  232. </ol>
  233. <?}
  234. if(isset($_REQUEST['erro'])){
  235. if($_REQUEST['erro']==1){?>
  236. <ol class="commentlist">
  237. <li class="liComments">
  238. <div class="divComments">
  239. <?=COMMNETS_MESSAGE_ERRO_1?>
  240. </div>
  241. </li>
  242. </ol>
  243. <?}elseif($_REQUEST['erro']==2){?>
  244. <ol class="commentlist">
  245. <li class="liComments">
  246. <div class="divComments">
  247. <?=COMMNETS_MESSAGE_ERRO_2?>
  248. </div>
  249. </li>
  250. </ol>
  251. <?}
  252. }?>
  253. <input type="hidden" name="blogId" value="<?=$blogId?>"/>
  254. <input type="hidden" name="comment_post_ID" value="<?php echo $ArticleDAO->getWpPostByIDValue($article->getPID());?>" />
  255. <input type="hidden" name="userID" value="<?=$_COOKIE['userID']?>"/>
  256. <input type="hidden" name="PID" value="<?=$article->getPID()?>"/>
  257. <input type="hidden" name="acron" value="<?=$acron?>"/>
  258. <input type="hidden" name="origem" value=<?='"http://'.$_SERVER["SERVER_NAME"].'/scieloOrg/php/wpPosts.php?pid='.$pid."&lang=".$lang."&acron=".$acron.'"'?>/>
  259. <!-- <? echo "blogId=".$blogId."postId=".$ArticleDAO->getWpPostByIDValue($article->getPID())."userId=".$_COOKIE['userID']; ?> -->
  260. <TR>
  261. <TD align="right" width="0" valign="top">
  262. </TD>
  263. <TD>
  264. </TD>
  265. </TR>
  266. <TR>
  267. <TD height="15">
  268. </TD>
  269. </TR>
  270. <TR>
  271. <TD align="right" width="0">
  272. <span>
  273. <?=COMMENTS_USER_AUTHOR?>
  274. </span>
  275. </TD>
  276. <TD>
  277. <input type="text" name="author" id="author" value="<?=$_COOKIE["firstName"]?>" size="22" tabindex="1" />
  278. </TD>
  279. </TR>
  280. <TR>
  281. <TD align="right">
  282. <span>
  283. <?=COMMNETS_USER_EMAIL?>
  284. </span>
  285. </TD>
  286. <TD>
  287. <input type="text" name="email" id="email" value="<?=$_COOKIE["email"]?>" size="30" tabindex="2" />
  288. </TD>
  289. </TR>
  290. <TR>
  291. <TD align="right" valign="top">
  292. <?=COMMNETS_USER_COMMENT?>
  293. </TD>
  294. <TD>
  295. <textarea name="comment" id="comment" cols="70%" rows="10" onblur="me_checkLim(this);" onkeydown="me_checkLim(this);" tabindex="3"></textarea>
  296. <div style="margin-left: 20%;"><?=CHAR_LIMIT?><span id="carRest">1024</span></div>
  297. </TD>
  298. </TR>
  299. <TR>
  300. <TD height="10" align="right">
  301. </TD>
  302. <TD height="10" align="left">
  303. <input name="submit" type="submit" id="submit" class="submit" tabindex="5" value="<?=COMMNETS_USER_BUTTON?>" />
  304. </TD>
  305. </TR>
  306. <TR>
  307. <TD >
  308. </TD>
  309. <TD >
  310. <?=REQUIRED_FIELD_TEXT?>
  311. </TD>
  312. </tr>
  313. <TR>
  314. <TD >
  315. </TD>
  316. <TD >
  317. <?}elseif($blogId==0){
  318. echo COMMNETS_DONT_BLOG;
  319. }
  320. elseif($show_login==0){
  321. }
  322. else{?>
  323. </TD>
  324. </tr>
  325. </TABLE>
  326. </form>
  327. <strong>
  328. <div style="font-size: 10pt; font-family:Arial,Verdana;color:#990000;">
  329. <?
  330. //echo COMMNETS_MESSAGE_BLOG_INI.'<a href="http://'.$defFile["SCIELO_REGIONAL_DOMAIN"].'//applications/scielo-org/sso/loginScielo.php?lang='.$lang.'">login</a>'.COMMNETS_MESSAGE_BLOG_FIM;
  331. echo COMMNETS_MESSAGE_BLOG_INI.'login'.COMMNETS_MESSAGE_BLOG_FIM;
  332. ?>
  333. </div>
  334. </strong>
  335. <div class="intro">
  336. <div class="loginBlog">
  337. <form name="login" method="get" action=<?='"http://'.$applServerOrg.'//applications/scielo-org/sso/loginScielo.php"'?>>
  338. <table width="100%" cellpadding="0" cellspacing="0" border="0">
  339. <tr>
  340. <th><?=FIELD_LOGIN?></th>
  341. <td><input type="text" name="login" size="25"/>
  342. <?
  343. if($login_error)
  344. echo '<span class="tfvHighlight" >'. LOGIN_ERROR . '</span>';
  345. ?>
  346. </td>
  347. </tr>
  348. <tr>
  349. <th><?=FIELD_PASSWORD?></th>
  350. <td><input type="password" name="password" size="25"/></td>
  351. </tr>
  352. <tr>
  353. <th>&nbsp;</th>
  354. <td><input type="submit" class="submit" value="<?=BUTTON_LOGIN?>"/></td>
  355. </tr>
  356. <tr>
  357. <th>&nbsp;</th>
  358. <td>
  359. <a href=<?='"http://'.$applServerOrg.'/applications/scielo-org/users/forgot.php"'?> target="_blank"><?=FORGOT_PASSWORD?></a>
  360. <br/>
  361. <a href=<?='"http://'.$applServerOrg.'/applications/scielo-org/users/userData.php"'?> target="_blank"><?=REGISTER?></a>
  362. </td>
  363. </tr>
  364. </table>
  365. <input type="hidden" name="acao" value="login"/>
  366. <input type="hidden" name="origem" value=<?='"http://'.$_SERVER["SERVER_NAME"].'/scieloOrg/php/wpPosts.php?pid='.$pid."&lang=".$lang."&acron=".$acron.'"'?>/>
  367. <input type="hidden" name="otherLocation" value="true"/>
  368. </form>
  369. </div>
  370. </div>
  371. <?}?>
  372. </div>
  373. </div>
  374. </div>
  375. </div>
  376. </div>
  377. <?
  378. if($defFile['LOG']['ACTIVATE_LOG'] == '1') {
  379. ?>
  380. <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
  381. <script type="text/javascript">
  382. _uacct = "UA-604844-1";
  383. urchinTracker();
  384. </script>
  385. <?}?>
  386. </BODY>
  387. </HTML>