bibliography.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpBIB
  5. // | $Id: bibliography.php,v 2.0 2005/07/22 08:58:54 dfolio Exp $
  6. // | Creation Date : Tue Apr 28 2005
  7. // | LastUpdate $Date: 2005/07/22 08:58:54 $
  8. // +------------------------------------------------------------------------+
  9. // | Copyright (c) 2003-2005 David FOLIO, Antre Team
  10. // | Email dfolio@free.fr
  11. // | Web http://dfolio.free.fr
  12. // +------------------------------------------------------------------------+
  13. // | This source file is subject to BSD License, that is available
  14. // | at http://opensource.org/licenses/bsd-license.php
  15. // | or http://dfolio.free.fr/license.txt
  16. // +------------------------------------------------------------------------+
  17. //
  18. /** Bibliography management
  19. *
  20. * This script provide several method to render bibliography, usually build
  21. * from the {@link BibtexParser}.
  22. *
  23. *
  24. * This script is provided "as is" for free. No support is available. I am
  25. * not responsible for any loss due to the use of this program.
  26. * You may modify the program for your own purpose. If you think your
  27. * modification may benefit others, please send me a copy to:
  28. * {@link mailto:dfolio@free.fr dfolio@free.fr}.
  29. * Thank you!
  30. *
  31. * If you think it is helpful, please kindly add a link pointing to:
  32. * {@link http://dfolio.free.fr}
  33. *
  34. * @version $Revision: 2.0 $
  35. * @author David FOLIO <dfolio@free.fr>
  36. * @copyright Copyright &copy; 2003-2005, Antre Team
  37. * @license http://dfolio.free.fr/license.txt
  38. *
  39. * @package phpBIB
  40. */
  41. /** Needs phpbib constants*/
  42. include_once(dirname(__FILE__).'/constants.php');
  43. /** Need the {@link BibtexParser "bibtex parser"} */
  44. require_once(dirname(__FILE__).'/bibtexParser.php');
  45. /** Class Bibliography: bibliography management
  46. *
  47. *
  48. * @author David FOLIO
  49. * @version 1.1
  50. * @package phpBIB
  51. */
  52. class Bibliography{
  53. /** The bibliography data
  54. *
  55. * This is an array which contains bibliography entry, usually build with
  56. * {@link BibtexParser}
  57. * @var Array
  58. */
  59. var $biblio;
  60. /**
  61. * Provide cited entry
  62. */
  63. var $arrCited;
  64. /** define if cache is enabled
  65. * @var Boolean
  66. * @access private
  67. */
  68. var $_useCache;
  69. /** The constructor
  70. * @param $bibfiles a list of bibTeX file to load
  71. * @param $useCache (dis)enable the cache management
  72. */
  73. function Bibliography($bibfiles=null,$useCache=false){
  74. $this->arrCited=array();
  75. $this->biblio=array();
  76. $this->_useCache=$useCache;
  77. if (!empty($bibfiles)) {
  78. $bibTeX=new BibTexParser($bibfiles,$this->_useCache);
  79. //$bibTeX->load($bibfiles,$useCache);
  80. $this->biblio=$bibTeX->getBibData();
  81. $bibTeX->destroy($this->_useCache);
  82. unset($bibTeX);
  83. }
  84. $this->initLang();
  85. }
  86. /** Define the biblio data entry
  87. * @param Array the biblio data entry, which is build from BibtexParser
  88. * @see {@link BibtexParser}
  89. */
  90. function setBiblio($biblio){
  91. if (!is_array($biblio)){
  92. trigger_error("Bibliography::setBiblio > Bad parameter biblio=".
  93. print_r($biblio,true).
  94. " which must be an array of biblio data entry\n",
  95. E_USER_ERROR);
  96. return false;
  97. }
  98. $this->biblio=$biblio;
  99. }
  100. /** Get the biblio data entry
  101. * @return Array the biblio data entry array
  102. */
  103. function getBiblio(){return $this->biblio;}
  104. /** Delete the current biblio.
  105. * If there the cache is enable, also remove the biblio from the cache.
  106. *
  107. * @param Boolean (dis)enable the cache management
  108. */
  109. function destroy($useCache=false){
  110. if ($useCache&&isset($_SESSION["PHPBIB_BIBLIO"])) unset($_SESSION["PHPBIB_BIBLIO"]);
  111. unset($this->biblio);
  112. //$this=NULL;
  113. return true;
  114. }
  115. /* Some usefull function to access to some fields ---------------------------- */
  116. /** Get author
  117. *
  118. * Get author fields for the bikey value. If no author fields are found then
  119. * the function return <var>FALSE</var>.
  120. * @param (String) a bikey value
  121. * @return (Mixed)
  122. * @todo ameliorer la generation des author en eliminant les 'and' inutiles...
  123. */
  124. function getAuthor($bibkey){
  125. if (isset($this->biblio["author"][$bibkey])){
  126. $authors=$this->biblio["author"][$bibkey];
  127. $str='';$list=array();
  128. if (!empty($authors)&&is_string($authors)){
  129. $ltmp=explode(' and ',$authors);
  130. foreach($ltmp as $anAuthor){
  131. $anAuthor=(trim($anAuthor));
  132. if (!array_key_exists($anAuthor,$list))
  133. $list[$anAuthor]='<a href="'.Bibliography::href('',array('bibAuthor'=>$anAuthor)).
  134. '" title="'.__('Author').': '.$anAuthor.'">'.$anAuthor."</a>";
  135. }
  136. ksort($list);$str=implode(", ", $list);
  137. if(($pos=strrpos($str,','))!==false){
  138. $str =substr($str,0,$pos).' '.__(' and ').' '.substr($str,$pos+1);
  139. }
  140. }
  141. return " ".BIB_AUTHOR_START.$str.". ".BIB_AUTHOR_END." ";
  142. }elseif (isset($this->biblio["editor"][$bibkey]))
  143. return " ".BIB_AUTHOR_START.$this->biblio["editor"][$bibkey].". ".BIB_AUTHOR_END." ";
  144. else return false;
  145. }
  146. /** Get title
  147. *
  148. * Get title fields for the bikey value. If no title fields are found then
  149. * the function return <var>FALSE</var>.
  150. * @param (String) a bikey value
  151. * @return (Mixed)
  152. */
  153. function getTitle($bibkey){
  154. if (isset($this->biblio["title"][$bibkey])) return BIB_TITLE_START.trim($this->biblio["title"][$bibkey])."".BIB_TITLE_END;
  155. else return false;
  156. }
  157. /** Get Date
  158. *
  159. * Get date field for the bikey value.
  160. * To build the date, the year field is required, and the month field is
  161. * optional. If the month fields is available
  162. * If no year fields are found then the function return <var>FALSE</var>.
  163. * @param (String) a bikey value
  164. * @return (Mixed)
  165. */
  166. function getDate($bibkey){
  167. if (isset($this->biblio["year"][$bibkey])){
  168. $date=(isset($this->biblio["month"][$bibkey])?$this->biblio["month"][$bibkey] :"")." ".$this->biblio["year"][$bibkey];
  169. return " ".BIB_DATE_START.
  170. ((strtotime($date)!=-1) ? __(date(" F ",strtotime($date))):$date).
  171. $this->biblio["year"][$bibkey].". ".BIB_DATE_END;
  172. }
  173. return false;
  174. }
  175. /** Get abstract
  176. *
  177. * Get abstract field for the bikey value.
  178. * @param (String) a bikey value
  179. * @return (String)
  180. */
  181. function getAbstract($bibkey){
  182. return (isset($this->biblio["abstract"][$bibkey])?
  183. BIB_ABSTRACT_START.'<strong>'.__("Abstract").':</strong> '.$this->biblio["abstract"][$bibkey].BIB_ABSTRACT_END."\n":"");
  184. }
  185. /** Get keywords
  186. *
  187. * Get keywords field for the bikey value.
  188. * @param (String) a bikey value
  189. * @return (String)
  190. */
  191. function getKeywords($bibkey){
  192. if (!isset($this->biblio["keywords"][$bibkey])) return "";
  193. $keywords=$this->biblio["keywords"][$bibkey];
  194. $list=array();
  195. if (!empty($keywords)&& is_string($keywords)){
  196. $ltmp=explode(',',$keywords);
  197. foreach($ltmp as $akeyword){
  198. $akeyword=strtoupper(trim($akeyword));
  199. if (!array_key_exists($akeyword,$list))
  200. $list[$akeyword]='<a href="'.Bibliography::href('',array('bibKeyword'=>$akeyword)).'" title="'.$akeyword.'">'.$akeyword."</a>";
  201. }
  202. ksort($list);
  203. return BIB_KEYWORDS_START.'<strong>'.__("Keyword(s)").':</strong> '.
  204. ' '.implode(", ", $list).".".BIB_KEYWORDS_END."\n";
  205. }
  206. return '';
  207. }
  208. function getWeb($bibkey){
  209. $str=(isset($this->biblio["url"][$bibkey])?
  210. __('Available at:')." ".str_replace('%s',$this->biblio["url"][$bibkey] ,BIB_URL_PATERN)
  211. .(isset($this->biblio["lastchecked"][$bibkey])? ' ('.__('last seen')." ".$this->biblio["lastchecked"][$bibkey].')' :"")
  212. :"");
  213. if (strlen($str)>1) return BIB_WEB_START.$str.BIB_WEB_END."\n";
  214. return '';
  215. }
  216. function getAnnote($bibkey){
  217. return (isset($this->biblio["annote"][$bibkey])?
  218. BIB_ANNOTE_START.$this->biblio["annote"][$bibkey].BIB_ANNOTE_END."\n"
  219. :"");
  220. }
  221. function getBookInfo($bibkey){
  222. $str= (isset($this->biblio["isbn"][$bibkey])?
  223. BIB_ISBN_START.'ISBN: '.$this->biblio["isbn"][$bibkey].BIB_ISBN_END.""
  224. :"");
  225. $str=(isset($this->biblio["issn"][$bibkey])?
  226. ((strlen($str)>1)?trim($str).', ':'').BIB_ISBN_START.'ISSN: '.$this->biblio["issn"][$bibkey].BIB_ISBN_END.""
  227. :"");
  228. if (strlen($str)>1) return trim($str).'.';
  229. return '';
  230. }
  231. function getIcons($bibkey){
  232. return BIB_ICONS_START
  233. .'<a href="'.Bibliography::href('',array('bibKey'=>$bibkey)).'" title="View bibTeX of '.$bibkey.'">'
  234. .str_replace('%s',$bibkey,BIB_ICONS_IMG_PATERN).'</a>'
  235. .(isset($this->biblio["doi"][$bibkey])? " &nbsp;".str_replace('%s',$this->biblio["doi"][$bibkey],BIB_DOI_PATERN) :'')
  236. .BIB_ICONS_END;
  237. }
  238. /* Some usefull function to build some entry --------------------------------- */
  239. /**#@+
  240. * If required fields are not set then the function return <var>FALSE</var>.
  241. *
  242. */
  243. /** Design @article category
  244. *
  245. * Desin an article from a journal or magazine.
  246. * - Required fields: author, title, journal, year.
  247. * - Optional fields: volume, number, pages, month.
  248. * @param (String) a bikey value
  249. * @return (Mixed)
  250. **/
  251. function buildArticle($bibkey){
  252. if (!isset($this->biblio["author"][$bibkey])||!isset($this->biblio["title"][$bibkey])||
  253. !isset($this->biblio["journal"][$bibkey])||!isset($this->biblio["year"][$bibkey]))
  254. return false;
  255. return " ".$this->getAuthor($bibkey)
  256. .$this->getTitle($bibkey)
  257. .BIB_JOURNAL_START.$this->biblio["journal"][$bibkey].BIB_JOURNAL_END
  258. .trim(isset($this->biblio["volume"][$bibkey])? ", Vol. ".$this->biblio["volume"][$bibkey] :"")
  259. .trim(isset($this->biblio["number"][$bibkey])? "(".$this->biblio["number"][$bibkey].")" :"")
  260. .trim(isset($this->biblio["pages"][$bibkey])? "&nbsp;: p.&nbsp;".$this->biblio["pages"][$bibkey] :"").". "
  261. .$this->getDate($bibkey)
  262. .$this->getBookInfo($bibkey)
  263. .$this->getWeb($bibkey)
  264. ."";
  265. }
  266. /** Design @book category
  267. *
  268. * Design a book with an explicit publisher.
  269. * - Required fields: author or editor, title, publisher, year.
  270. * - Optional fields: volume, number, series, address, edition, month.
  271. * @param (String) a bikey value
  272. * @return (Mixed)
  273. */
  274. function buildBook($bibkey){
  275. if (!isset($this->biblio["author"][$bibkey])&&!isset($this->biblio["editor"][$bibkey])) return "<!-- NO AUHTOR OR EDITOR -->";
  276. if (!isset($this->biblio["title"][$bibkey])||!isset($this->biblio["publisher"][$bibkey])) return false;
  277. return " ".$this->getAuthor($bibkey)
  278. .$this->getTitle($bibkey)
  279. .BIB_PUBLISHER_START.$this->biblio["publisher"][$bibkey].BIB_PUBLISHER_END
  280. .trim(isset($this->biblio["edition"][$bibkey])?", ".$this->biblio["edition"][$bibkey] :"")
  281. .trim(isset($this->biblio["series"][$bibkey])?", ".$this->biblio["series"][$bibkey] :"")
  282. .trim(isset($this->biblio["volume"][$bibkey])? ", Vol. ".$this->biblio["volume"][$bibkey] :"")
  283. .trim(isset($this->biblio["number"][$bibkey])? "(".$this->biblio["number"][$bibkey].")" :"")
  284. .trim(isset($this->biblio["pages"][$bibkey])? "&nbsp;: p.&nbsp;".$this->biblio["pages"][$bibkey] :"").". "
  285. .(isset($this->biblio["address"][$bibkey])?BIB_ADDRESS_START.$this->biblio["address"][$bibkey].". ".BIB_ADDRESS_END :"")
  286. .$this->getDate($bibkey)
  287. .$this->getBookInfo($bibkey)
  288. .$this->getWeb($bibkey)
  289. ."";
  290. }
  291. /** Design @book category
  292. *
  293. * Design a book with an explicit publisher.
  294. * - Required fields: title.
  295. * - Optional fields: author, howpublished, address, month, year, note.
  296. * @param (String) a bikey value
  297. * @return (Mixed)
  298. */
  299. /* function buildBookLet($bibkey){
  300. if (!isset($this->biblio["title"][$bibkey])) return false;
  301. return " ".$this->getAuthor($bibkey)
  302. .$this->getTitle($bibkey)
  303. .(isset($this->biblio["edition"][$bibkey])?", ".$this->biblio["edition"][$bibkey] :" ")
  304. .(isset($this->biblio["series"][$bibkey])?", ".$this->biblio["series"][$bibkey] :" ")
  305. .(isset($this->biblio["volume"][$bibkey])? ", Vol. ".$this->biblio["volume"][$bibkey] :"")
  306. .(isset($this->biblio["number"][$bibkey])? "(".$this->biblio["number"][$bibkey].")" :"")
  307. .(isset($this->biblio["pages"][$bibkey])? "&nbsp;: p.&nbsp;".$this->biblio["pages"][$bibkey] :"").". "
  308. .(isset($this->biblio["address"][$bibkey])?BIB_ADDRESS_START.$this->biblio["address"][$bibkey].". ".BIB_ADDRESS_END :" ")
  309. .$this->getDate($bibkey)
  310. ."";
  311. }*/
  312. /** Design @inproceedings category
  313. *
  314. * Design an article in a conference proceedings.
  315. * - Required fields: author, title, booktitle, year.
  316. * - Optional fields: editor, volume or number, series, pages, address, month, organization, publisher.
  317. * @param (String) a bikey value
  318. * @return (Mixed)
  319. */
  320. function buildInProceedings($bibkey){
  321. if (!isset($this->biblio["author"][$bibkey])||!isset($this->biblio["title"][$bibkey])||
  322. !isset($this->biblio["booktitle"][$bibkey])||!isset($this->biblio["year"][$bibkey]))
  323. return false;
  324. return " ".$this->getAuthor($bibkey)
  325. .$this->getTitle($bibkey)
  326. .BIB_BOOKTITLE_START.$this->biblio["booktitle"][$bibkey].BIB_BOOKTITLE_END
  327. .trim(isset($this->biblio["publisher"][$bibkey])? ", ".$this->biblio["publisher"][$bibkey] :"")
  328. .trim(isset($this->biblio["editor"][$bibkey])?", ".$this->biblio["editor"][$bibkey] :"")
  329. .trim(isset($this->biblio["series"][$bibkey])?", ".$this->biblio["series"][$bibkey] :"")
  330. .trim(isset($this->biblio["volume"][$bibkey])?", Vol. ".$this->biblio["volume"][$bibkey] :"")
  331. .trim(isset($this->biblio["number"][$bibkey])?"(".$this->biblio["number"][$bibkey].")" :"")
  332. .trim(isset($this->biblio["pages"][$bibkey])?"&nbsp;: p.&nbsp;".$this->biblio["pages"][$bibkey] :"").". "
  333. .(isset($this->biblio["organization"][$bibkey])?$this->biblio["organization"][$bibkey] :"")
  334. .(isset($this->biblio["address"][$bibkey])?BIB_ADDRESS_START.$this->biblio["address"][$bibkey].". ".BIB_ADDRESS_END :" ")
  335. .$this->getDate($bibkey)
  336. .$this->getBookInfo($bibkey)
  337. .$this->getWeb($bibkey)
  338. ."";
  339. }
  340. /** Design thesis like category
  341. *
  342. * Design a PhD or Master's thesis.
  343. * - Required fields: author, title, school, year.
  344. * - Optional fields: type, address, month.
  345. * @param (String) a bikey value
  346. * @return (Mixed)
  347. */
  348. function buildThesis($bibkey){
  349. if (!isset($this->biblio["author"][$bibkey])||!isset($this->biblio["title"][$bibkey])||
  350. !isset($this->biblio["school"][$bibkey])||!isset($this->biblio["year"][$bibkey]))
  351. return false;
  352. return " ".$this->getAuthor($bibkey)
  353. .$this->getTitle($bibkey)
  354. .BIB_SCHOOL_START
  355. .(isset($this->biblio["type"][$bibkey])? $this->biblio["type"][$bibkey].", " :" ")
  356. .$this->biblio["school"][$bibkey].BIB_SCHOOL_END
  357. .(isset($this->biblio["address"][$bibkey])?" ".BIB_ADDRESS_START.$this->biblio["address"][$bibkey].". ".BIB_ADDRESS_END :" ")
  358. .$this->getDate($bibkey)
  359. .$this->getWeb($bibkey)
  360. ."";
  361. }
  362. /** Design report category
  363. *
  364. * A report published or some audiovisual/film material.
  365. * - Required fields: author, title, institution, year.
  366. * - Optional fields: type, number, address, month.
  367. * @param (String) a bikey value
  368. * @return (Mixed)
  369. */
  370. function buildReport($bibkey){
  371. if (!isset($this->biblio["author"][$bibkey])||!isset($this->biblio["title"][$bibkey])||
  372. !isset($this->biblio["institution"][$bibkey])||!isset($this->biblio["year"][$bibkey]))
  373. return false;
  374. return " ".$this->getAuthor($bibkey)
  375. .trim(isset($this->biblio["type"][$bibkey])? " ".$this->biblio["type"][$bibkey].":" :" ")
  376. .trim(isset($this->biblio["number"][$bibkey])?" ".$this->biblio["number"][$bibkey].":" :"")
  377. .$this->getTitle($bibkey)
  378. .BIB_INSTITUTION_START.$this->biblio["institution"][$bibkey].BIB_INSTITUTION_END
  379. .(isset($this->biblio["address"][$bibkey])?BIB_ADDRESS_START.$this->biblio["address"][$bibkey].". ".BIB_ADDRESS_END :"")
  380. .$this->getDate($bibkey)
  381. .$this->getWeb($bibkey)
  382. ."";
  383. }
  384. /** Design @misc category
  385. *
  386. * Desin a misc entry
  387. * - Optional fields: author, title, howpublished, address, year, month.
  388. * @param (String) a bikey value
  389. * @return (Mixed)
  390. **/
  391. function buildMisc($bibkey){
  392. return " ".$this->getAuthor($bibkey)
  393. .$this->getTitle($bibkey)
  394. .(isset($this->biblio["howpublished"][$bibkey])? " ".$this->biblio["howpublished"][$bibkey] :"")
  395. .(isset($this->biblio["address"][$bibkey])?", ".BIB_ADDRESS_START.$this->biblio["address"][$bibkey].". ".BIB_ADDRESS_END :" ")
  396. .$this->getDate($bibkey)
  397. .$this->getBookInfo($bibkey)
  398. .$this->getWeb($bibkey)
  399. ."";
  400. }
  401. /**#@-*/
  402. /** Translate bibitem to string
  403. *
  404. * This is the main function to render a bibitem. It's check the category field
  405. * (which must be set, otherwise the function return <var>FALSE</var>) in
  406. * order to design the the bibitem.
  407. *
  408. * You can add your own category. In this case you have to design the
  409. * corresponding "build" function, as proposed above.
  410. *
  411. * @param (String) a bikey value
  412. * @param (Array) the array in which to search
  413. * @return (Mixed)
  414. */
  415. function item2str($bibkey){
  416. if (!isset($this->biblio["category"][$bibkey])) return false;
  417. $item_start="";$item_end=$this->getAnnote($bibkey);
  418. switch($this->biblio["category"][$bibkey]){
  419. case "UNPUBLISHED":
  420. default:
  421. return "<!--not designed-->\n";
  422. case "ARTICLE":
  423. return $item_start.$this->buildArticle($bibkey).$item_end;
  424. case "INBOOK":
  425. if (!(isset($this->biblio["pages"][$bibkey])||isset($this->biblio["chapter"][$bibkey]))) return false;
  426. if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("InBook");
  427. case "BOOKLET":
  428. if (!isset($this->biblio["author"][$bibkey]))$this->biblio["author"][$bibkey]=" ";
  429. if (!isset($this->biblio["editor"][$bibkey]))$this->biblio["editor"][$bibkey]=" ";
  430. if (!isset($this->biblio["publisher"][$bibkey]))$this->biblio["publisher"][$bibkey]=" ";
  431. if (!isset($this->biblio["year"][$bibkey]))$this->biblio["year"][$bibkey]=" ";
  432. if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("Booklet");
  433. case "BOOK":
  434. if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("Book");
  435. return $item_start.$this->buildBook($bibkey).$item_end;
  436. case "PROCEEDINGS":if (!isset($this->biblio["booktitle"][$bibkey]))$this->biblio["booktitle"][$bibkey]=__("Proceeding");
  437. case "INCOLLECTION":if (!isset($this->biblio["publisher"][$bibkey])) return false;
  438. case "CONFERENCE":
  439. case "INPROCEEDINGS":
  440. return $item_start.$this->buildInProceedings($bibkey).$item_end;
  441. case "MASTERSTHESIS":if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("Master thesis");
  442. case "PHDTHESIS":if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("PhD thesis");
  443. return $item_start.$this->buildThesis($bibkey).$item_end;
  444. case "MANUAL":
  445. if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("Manual");
  446. if (!isset($this->biblio["author"][$bibkey]))$this->biblio["author"][$bibkey]="";
  447. if (!isset($this->biblio["title"][$bibkey]))$this->biblio["title"][$bibkey]="";
  448. if (!isset($this->biblio["institution"][$bibkey]))$this->biblio["institution"][$bibkey]="";
  449. if (!isset($this->biblio["year"][$bibkey]))$this->biblio["year"][$bibkey]="";
  450. case "AUDIOVISUAL": if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("Audiovisal");
  451. case "TECHREPORT": if (!isset($this->biblio["type"][$bibkey]))$this->biblio["type"][$bibkey]=__("Technical report");
  452. return $item_start.$this->buildReport($bibkey).$item_end;
  453. case "WEBPAGE":
  454. case "MISC":
  455. return $item_start.$this->buildMisc($bibkey).$item_end;
  456. }
  457. }
  458. /** Translate bibitem to bibTeX
  459. *
  460. * This function (re)build the bibitem entry into bibtex format, in order to
  461. * be included in your HTML page.
  462. * @param (String) a bikey value
  463. * @param (Array) the array in which to search
  464. * @return (Mixed)
  465. */
  466. function item2bib($bibkey){
  467. if (!isset($this->biblio["category"][$bibkey])) return false;
  468. $html=BIB_BIBENTRY_START.'<strong>'.__("BibTeX Reference").':</strong> <div class="bibTeX">@'.$this->biblio["category"][$bibkey].'{'.$bibkey.",<br/>\n";
  469. foreach($this->biblio as $field=>$fval){
  470. if(($field==="category")||(!isset($fval[$bibkey]))||empty($fval[$bibkey])) continue;
  471. $html.= "\t&nbsp;&nbsp;".$field.' = {'.$fval[$bibkey]."},<br/> \n";
  472. }
  473. return $html."};\n</div>".BIB_BIBENTRY_END."\n";
  474. }
  475. /** Generic build view
  476. * @param (String) the view must be one of used field (eg keyword, authors, category...).
  477. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  478. * @param (Boolean) if <var>TRUE</var> include subitem (abstract,
  479. * keywords,...)
  480. * @param String a view filter function
  481. * @param Mixed the filter argument
  482. * @return (Mixed)
  483. * @sa stringViewFilter(), authorViewFilter()
  484. * @access private
  485. */
  486. function _buildView($view="", $showBib=false, $showSubItem=false,$usekSort=false,
  487. $filter_func="stringViewFilter", $filter=""){
  488. if (!isset($this->biblio[$view])) {
  489. if (BIB_PARSE_DEBUG) echo "<!-- no view:$view -->\n";
  490. return false;
  491. }
  492. if ($usekSort) ksort($this->biblio[$view]);
  493. //if (BIB_PARSE_DEBUG) echo "<!-- VIEW $view:( $filter_func)$filter:$pattern -->\n";
  494. $html='';
  495. //if (BIB_PARSE_DEBUG) $html.= "\n<!-- [$view] -->\n";
  496. $list=array();$i=0;
  497. foreach($this->biblio[$view] as $bibkey=>$item){
  498. if(in_array($bibkey,$list)){continue;}
  499. if (!empty($filter_func)&&( $filter_func!=="")){
  500. if (!call_user_func(array(get_class($this),$filter_func),$filter,strtoupper(trim($this->biblio[$view][$bibkey])))) {
  501. continue;}
  502. }
  503. $i++;
  504. //if (BIB_PARSE_DEBUG) $html.= "\n<!-- [$i] $bibkey -->\n";
  505. $list[]=$bibkey;
  506. $item_start=sprintf(BIB_BIBITEM_START,$bibkey);
  507. $item_start.=BIB_BIBKEY_START.$bibkey.$this->getIcons($bibkey).BIB_BIBKEY_END;
  508. $item_end=" ".BIB_BIBITEM_END."\n";
  509. $html.= $item_start.$this->item2str($bibkey).$item_end;
  510. if ($showBib||$showSubItem) $html.=BIB_SUBITEM_START;
  511. if ($showSubItem) $html.="\n".$this->getAbstract($bibkey).$this->getKeywords($bibkey)."";
  512. if ($showBib) $html.= $this->item2bib($bibkey);
  513. if ($showBib||$showSubItem) $html.=BIB_SUBITEM_END."\n";
  514. }
  515. return $html."\n";
  516. }
  517. /**Dump the bibliography
  518. *
  519. * This is the main function to build the bibliography view
  520. * @param (String) define the sorting method (if not empty).
  521. * If it's set must be one of {@link BIB_SORT_LIST}.
  522. * If it's empty don't sort the bibliography.
  523. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  524. * @param (Boolean) if <var>TRUE</var> include subitem (abstract,
  525. * keywords,...)
  526. * @return (Mixed)
  527. */
  528. function dump($sort="", $showBib=false, $showSubItem=false){
  529. if (!empty($sort)){
  530. if (strpos(BIB_SORT_LIST,$sort)===false) $sort="author";
  531. if (strpos($sort,"author")!==false){
  532. if ($sort{0}=='r'){
  533. $sort=substr($sort,1);
  534. if(krsort($this->biblio[$sort])===false) echo "can't sort by $sort";
  535. }else if(ksort($this->biblio[$sort])===false) echo "can't sort by $sort";
  536. }else{
  537. if ($sort{0}=='r'){
  538. $sort=substr($sort,1);
  539. if(arsort($this->biblio[$sort])===false) echo "can't sort by $sort";
  540. }else if(asort($this->biblio[$sort])===false) echo "can't sort by $sort";
  541. }
  542. }else $sort="author";
  543. return BIB_VIEW_START
  544. ."<!-- buildView($sort,$showBib, $showSubItem ...)-->"
  545. .$this->_buildView($sort,$showBib, $showSubItem,false, "", "")
  546. ."\n".BIB_VIEW_END." \n";
  547. }
  548. /* Some usefull function to build view --------------------------------------- */
  549. /**Build bibkeys view
  550. * @param (String) the category.
  551. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  552. * @param (Boolean) if <var>TRUE</var> include subitem (abstract, keywords,...)
  553. * @return (Mixed)
  554. */
  555. function bibkeysView(&$bibkeys, $showBib=false, $showSubItem=false,$usekSort=false){
  556. if (is_string($bibkeys)){
  557. $bibkeysStr=$bibkeys;$bibkeys=array();
  558. $bibkeysStr=str_replace(' ','',trim($bibkeysStr));
  559. if (strpos($bibkeysStr,',')!=false) $bibkeys=explode(',',$bibkeysStr);
  560. else $bibkeys[]=$bibkeysStr;
  561. }/* else is an array!*/
  562. if ($usekSort) ksort($bibkeys);
  563. $html='';
  564. $list=array();$i=0;
  565. foreach($bibkeys as $bibkey){
  566. if(in_array($bibkey,$list)){continue;}
  567. $i++;$list[]=$bibkey;
  568. $item_start=sprintf(BIB_BIBITEM_START,$bibkey);
  569. $item_start.=BIB_BIBKEY_START.$bibkey.$this->getIcons($bibkey).BIB_BIBKEY_END;
  570. $item_end=" ".BIB_BIBITEM_END."\n";
  571. $html.= $item_start.$this->item2str($bibkey).$item_end;
  572. if ($showBib||$showSubItem) $html.=BIB_SUBITEM_START;
  573. if ($showSubItem) $html.="\n".$this->getAbstract($bibkey).$this->getKeywords($bibkey)."";
  574. if ($showBib) $html.= $this->item2bib($bibkey);
  575. if ($showBib||$showSubItem) $html.=BIB_SUBITEM_END."\n";
  576. }
  577. return BIB_VIEW_START.$html.BIB_VIEW_END."\n";
  578. }
  579. /**Build year view
  580. /**Build category view
  581. * @param (String) the category.
  582. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  583. * @param (Boolean) if <var>TRUE</var> include subitem (abstract, keywords,...)
  584. * @return (Mixed)
  585. */
  586. function categoryView($category="", $showBib=false, $showSubItem=false){
  587. if (!isset($this->biblio["category"])) return false;
  588. return BIB_VIEW_START
  589. .$this->_buildView("category", $showBib, $showSubItem,true,"stringViewFilter", $category)
  590. ."\n".BIB_VIEW_END."\n";
  591. }
  592. /**Build year view
  593. * @param (String) the category.
  594. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  595. * @param (Boolean) if <var>TRUE</var> include subitem (abstract, keywords,...)
  596. * @return (Mixed)
  597. */
  598. function yearView($year="", $showBib=false, $showSubItem=false){
  599. if (!isset($this->biblio["year"])) return false;
  600. return BIB_VIEW_START
  601. .$this->_buildView("year",$showBib, $showSubItem,true,"stringViewFilter", $year)
  602. ."\n".BIB_VIEW_END."\n";
  603. }
  604. /**Build keywords view
  605. * @param (String) the keyword.
  606. * If it's empty build the complete bibliography.
  607. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  608. * @param (Boolean) if <var>TRUE</var> include subitem (abstract, keywords,...)
  609. * @return (Mixed)
  610. */
  611. function keywordView($keyword="", $showBib=false, $showSubItem=false){
  612. if (!isset($this->biblio["keywords"])) return false;
  613. return BIB_VIEW_START
  614. .$this->_buildView( "keywords",$showBib, $showSubItem,true,"stringViewFilter", $keyword)
  615. ."\n".BIB_VIEW_END."\n";
  616. }
  617. /**Build author view
  618. * @param (String) the author.
  619. * @param (Boolean) if <var>TRUE</var> include the corresponding bibTeX
  620. * @param (Boolean) if <var>TRUE</var> include subitem (abstract, keywords,...)
  621. * @return (Mixed)
  622. */
  623. function authorView($author="", $showBib=false, $showSubItem=false){
  624. if (!isset($this->biblio["author"])) return false;
  625. if (strpos($author,' OR ')!==false){
  626. $author=explode(' OR ',$author);
  627. }
  628. return BIB_VIEW_START
  629. .$this->_buildView("author",$showBib, $showSubItem,true,"authorViewFilter", $author)
  630. ."\n".BIB_VIEW_END."\n";
  631. }
  632. /* Some usefull function to build some "list" -------------------------------- */
  633. /** A simple string view filter.
  634. * @param String the filter argument
  635. * @param String the value to parse
  636. * @return TRUE if the $filter is found in the $val, false otherwise
  637. */
  638. function stringViewFilter($filter,$val){
  639. if(!empty($filter)&&(is_string($filter))&&(strpos($val,strtoupper(trim($filter)))!==false)) {return true;}
  640. return false;
  641. }
  642. /** The author view filter.
  643. * @param Mixed the filter argument
  644. * @param String the value to parse
  645. * @return TRUE if the $filter is found in the $val, false otherwise
  646. */
  647. function authorViewFilter($filter,$val){
  648. if(empty($val))return false;
  649. $authors=array();
  650. if (is_string($filter)){
  651. $filter=strtoupper(trim($filter));
  652. if (strpos($filter,' OR ')!==false) $authors=explode(' OR ',$filter);
  653. else $authors[]=$filter;
  654. }else $authors=$filter;
  655. if (count($authors)<2){
  656. foreach($authors as $k=>$author){
  657. if (empty($author)) continue;
  658. //if (BIB_PARSE_DEBUG)
  659. if (strpos($author,' AND ')!==false){
  660. $authorsAND=explode(' AND ',$filter);
  661. foreach($authorsAND as $an){if (strpos($val,$an)===false) return false;}
  662. return true;
  663. }elseif(strpos($val,$author)!==false) {return true;}
  664. }
  665. } else
  666. if(preg_match('/('.implode('|',$authors).')/i',$val)) {return true;}
  667. return false;
  668. }
  669. /* Some usefull function to build some "list" -------------------------------- */
  670. /**Build categories list
  671. *
  672. * This function build categroy list of the bibliography.
  673. * @return String
  674. */
  675. function categoriesList(){
  676. if (!isset($this->biblio["category"])) return false;
  677. $list=array();
  678. foreach($this->biblio["category"] as $bibkey=>$category){
  679. if (!array_key_exists($category,$list))
  680. $list[$category]='<li><a href="'.Bibliography::href('',array('bibCategory'=>$category)).'" title="'.__('Category').': '.$category.'">'.$category."</a></li>";
  681. }
  682. ksort($list);
  683. return BIB_CATEGORIES_LIST_START.implode("\n", $list).BIB_CATEGORIES_LIST_END."<br/>\n";
  684. }
  685. /**Build years list
  686. *
  687. * This function build categroy list of the bibliography.
  688. * @return String
  689. */
  690. function yearsList(){
  691. if (!isset($this->biblio["year"])) return false;
  692. $list=array();
  693. foreach($this->biblio["year"] as $bibkey=>$year){
  694. if (!array_key_exists($year,$list))
  695. $list[$year]='<li><a href="'.Bibliography::href('',array('bibYear'=>$year)).
  696. '" title="'.__('Year').': '.$year.'">'.$year."</a></li>";
  697. }
  698. ksort($list);
  699. return BIB_YEARS_LIST_START.implode("\n", $list).BIB_YEARS_LIST_END."<br/>\n";
  700. }
  701. /**Build keywords list
  702. *
  703. * This function build the keywords list of the bibliography.
  704. * @return String
  705. */
  706. function keywordsList(){
  707. if (!isset($this->biblio["keywords"])) return false;
  708. $list=array();
  709. foreach($this->biblio["keywords"] as $bibkey=>$keywords){
  710. $ltmp=explode(',',$keywords);
  711. foreach($ltmp as $akeyword){
  712. $akeyword=strtoupper(trim($akeyword));
  713. if (!array_key_exists($akeyword,$list))
  714. $list[$akeyword]='<li><a href="'.Bibliography::href('',array('bibKeyword'=>$akeyword)).'" title="'.$akeyword.'">'.$akeyword."</a></li>";
  715. }
  716. }
  717. ksort($list);
  718. //echo "\n\n<!-- ";print_r($list);echo " -->\n\n";
  719. return BIB_KEYWORDS_LIST_START.implode("\n", $list).BIB_KEYWORDS_LIST_END."<br/>\n";
  720. }
  721. /**Build authors list
  722. *
  723. * This function build author list of the bibliography.
  724. * @return String
  725. */
  726. function authorsList($letter=false){
  727. if (is_string($letter)) $letter=strtoupper($letter);
  728. if (!isset($this->biblio["author"])) return false;
  729. $list=array();
  730. if ($letter===true){
  731. foreach($this->biblio["author"] as $bibkey=>$authors){
  732. $ltmp=explode(' and ',$authors);
  733. foreach($ltmp as $anAuthor){
  734. $anAuthor=(trim($anAuthor));$ai=Bibliography::getAuthorInitial($anAuthor);
  735. if (!array_key_exists($ai,$list)){
  736. $list[$ai]='<li><a href="'.Bibliography::href('',array('bibAuthor'=>$ai)).
  737. '" title="'.__('Author').': '.$ai.'">'.$ai."</a></li>";
  738. }
  739. }
  740. }
  741. }else{
  742. foreach($this->biblio["author"] as $bibkey=>$authors){
  743. $ltmp=explode(' and ',$authors);
  744. foreach($ltmp as $anAuthor){
  745. $anAuthor=(trim($anAuthor));$ai=Bibliography::getAuthorInitial($anAuthor);
  746. if (!array_key_exists($anAuthor,$list) &&($letter&&($ai==$letter)||!$letter)){
  747. $list[$anAuthor]='<li><a href="'.Bibliography::href('',array('bibAuthor'=>$anAuthor)).
  748. '" title="'.__('Author').': '.$anAuthor.'">'.$anAuthor."</a></li>";
  749. }
  750. }
  751. }
  752. }
  753. uksort($list,array("Bibliography","authorcmp"));
  754. return BIB_AUTHORS_LIST_START.implode("\n", $list).BIB_AUTHORS_LIST_END."<br/>\n";
  755. }
  756. /**Build sort list
  757. *
  758. * This function build the know sort list of the bibliography.
  759. * @param (String) define the separator to use between different 'sort'
  760. * category.
  761. * @return (String) HTML code
  762. */
  763. function sortList($sepList=""){
  764. $html="";
  765. $sort_list=explode(',',BIB_SORT_LIST);
  766. foreach($sort_list as $asort){
  767. $label=__("sort by").' '.$asort;
  768. if ($asort{0}=='r') $label.=' ('.__("reverse").')';
  769. $html.='<a href="'.Bibliography::href('',array("sort"=>$asort)).'" title="'.$label.'" > '.$label."</a>".$sepList;
  770. }
  771. return $html;
  772. }
  773. /*
  774. function searchSubject($subject){
  775. $list=array();
  776. $subjects=strtoupper(implode(' ',$subject));
  777. if (isset($this->biblio["bibkey"])){
  778. }
  779. }
  780. */
  781. /** Build URI
  782. *
  783. * This function build an internal (to the package) href URI.
  784. * @param (String) base URL (index page)
  785. * @param (Array) an array of query string, such as:
  786. * <code>array("query"=>"val",...)</code>
  787. * For empty query just set an empty val.
  788. * @param (Array) a list of query to remove
  789. * @return (String) the href string...
  790. */
  791. function href($url="",$arr_queries=null,$removes=null){
  792. if (empty($url)) $url=BIB_INDEX;
  793. $queries="";
  794. if (empty($arr_queries)||!is_array($arr_queries))$arr_queries=array();
  795. if (empty($removes)&&(!is_bool($removes)))
  796. $removes=array("bibAuthor",'bibCategory','bibYear','bibKeyword','bibKey','biblio',
  797. 'bibkey','bibCite','bibref','bibRef');
  798. $qstr=(empty($_SERVER["QUERY_STRING"])) ? "": $_SERVER["QUERY_STRING"];
  799. // are there some query string defined?
  800. if (($p=strpos($url,'?'))!==false){
  801. $qstr=substr($url,$p+1).'&'.$qstr;
  802. $url=substr($url,0,$p);
  803. }
  804. if (!empty($qstr)&&($removes!==true)){
  805. $qt=explode('&', urldecode($qstr));
  806. foreach($qt as $q){
  807. if (strpos($q,'=')!==false){list($qa,$qv)=explode('=',$q);
  808. }else{$qa=$q;$qv="";}
  809. if (in_array($qa,$removes)&&!in_array($qa,array_keys($arr_queries))) continue;
  810. if (!isset($arr_queries[$qa])) $arr_queries[$qa]=$qv;
  811. }
  812. }
  813. foreach($arr_queries as $qa => $qv){
  814. /*if ((is_array($removes)&& @in_array($qa,$removes))) unset($arr_queries[$qa]);
  815. else*/
  816. if (empty($qv)) $queries .= "&$qa";
  817. else $queries .= "&$qa=".($qv);
  818. }
  819. if ($queries[0]=='&')$queries[0]='?';
  820. return $url . htmlspecialchars($queries);
  821. }
  822. /** Build a bibkey URI
  823. *
  824. * This function provide a usefull way to build a bibliography key entry.
  825. * Becarefull, this function does not check if the corresponding
  826. * <var>$ref</var> is defined in the bibliography!
  827. * @param (String) a bibkeyt reference
  828. * @param (String) index where are located the reference page, and where the
  829. * 'bibKey' are binded
  830. * @return (String) anchor HTML markup
  831. */
  832. function bibkey($ref,$index=BIB_INDEX){
  833. return '<a class="ref" href="'.Bibliography::href($index, array('bibKey'=>$ref)).'" title="'.__("cite").' '.$ref.' ">'.$ref."</a>";
  834. }
  835. /** Build a citation.
  836. *
  837. * This function provide a usefull way to cite a bibliography entry.
  838. * Becarefull, this function does not check if the corresponding
  839. * <var>$ref</var> is defined in the bibliography!
  840. * @param (String) a bibkeyt reference
  841. * @param (String) index where are located the reference page, and where the
  842. * 'bibKey' are binded
  843. * @return (String) anchor HTML markup
  844. */
  845. function cite($ref,$index=""){
  846. if (empty($index)) $index=$_SERVER["PHP_SELF"];
  847. if (!in_array($ref,$this->arrCited))$this->arrCited[]=$ref;
  848. return '<a class="ref" href="#'.$ref.'" title="'.__("cite").' '.$ref.' ">'.$ref."</a>";
  849. //$this->bibkey($ref,$index);
  850. }
  851. function getCited(){
  852. $cited="\n<dl>\n";
  853. foreach($this->arrCited as $ref){
  854. $cited.=" <dt class=\"bibkey\" id=\"$ref\">$ref</dt>".
  855. "<dd>".$this->item2str($ref)."</dd>\n";
  856. }
  857. return $cited."</dl>\n";
  858. }
  859. /** Initialize language support
  860. *
  861. * This function load all language file defined in <var>'./lang/'.$lang</var>.
  862. * All file with '.php' is this directory was considered as a laqnguage file.
  863. * @param (String) a two letter country iso639 code (such as 'en', 'fr'...) which
  864. * must be a directory available in './lang' diretory.
  865. * @return (Boolean) <var>$TRUE</var> if success
  866. */
  867. function initLang($lang=""){
  868. if (empty($lang)){
  869. $checkLang=array("language","Lang",'user_lang','user_langage');
  870. foreach ($checkLang as $aLang){
  871. if (isset($_REQUEST[$aLang])) {$lang=$_REQUEST[$aLang];break;}
  872. elseif (isset($_SESSION[$aLang])) {$lang=$_SESSION[$aLang];break;}
  873. elseif (isset($GLOBALS[$aLang])) {$lang=$GLOBALS[$aLang];break;}
  874. $aLang=strtoupper($aLang);
  875. if (isset($_REQUEST[$aLang])) {$lang=$_REQUEST[$aLang];break;}
  876. elseif (isset($_SESSION[$aLang])) {$lang=$_SESSION[$aLang];break;}
  877. elseif (isset($GLOBALS[$aLang])) {$lang=$GLOBALS[$aLang];break;}
  878. }
  879. if (empty($lang)) $lang=BIB_DEFAULT_LANG;
  880. }
  881. $dir=dirname(__FILE__).'/lang/'.$lang;
  882. if (!is_dir($dir)){
  883. trigger_error("[".__CLASS__."::initLang] $dir is not a directory \n",E_USER_WARNING);
  884. return false;
  885. }
  886. if (function_exists("glob")){
  887. $files = glob("$dir/*.php");/*print_r($files);*/
  888. foreach ((array)$files as $filename) {if (is_readable($filename)) include $filename;}
  889. return $lang;
  890. }else{
  891. if ($dh = opendir($dir)){
  892. while(($file = readdir($dh))!== false) {
  893. if (strpos($file,'.php')!==false) include $dir.'/'.$file;
  894. }
  895. closedir($dh);
  896. return $lang;
  897. }
  898. }
  899. return false;
  900. }
  901. /** Authors comparison
  902. *
  903. * This function provide an author comparison for sort criteriurm.
  904. *
  905. * Note that this comparison is case sensitive.
  906. * @param (String) first author
  907. * @param (String) second author
  908. * @return (Int)
  909. * - < 0 if a is less than b,
  910. * - > 0 if a is greater than b,
  911. * - 0 if they are equal.
  912. */
  913. function authorcmp ($a, $b) {
  914. $ai=Bibliography::getAuthorInitial($a);
  915. $bi=Bibliography::getAuthorInitial($b);
  916. if ($ai!==$bi) return ($ai<$bi) ? -1 : +1;
  917. $posA=strrpos($a,'.'); $posB=strrpos($b,'.');
  918. if (($posA===false)&&($posB===false)){
  919. return strcmp($a,$b);
  920. }elseif(($posA===false)&&($posB!==false)){
  921. return strcmp($a,substr($b,$posB+1));
  922. }elseif(($posA!==false)&&($posB===false)){
  923. return strcmp(substr($a,$posA+1),$b);
  924. }else{
  925. return strcmp(substr($a,$posA+1),substr($b,$posB+1));
  926. }
  927. //return strcmp($a,$b);//inutile...
  928. }
  929. /** Try to guess author initial
  930. *
  931. * This method parse an author name to guess its 'first letter' initial.
  932. * @param (String) author to parse
  933. * @return (String) the initial (first letter name) or false if the given
  934. * parameter is not a string...
  935. */
  936. function getAuthorInitial($author,$isFirst=true){
  937. if (!is_string($author)) {
  938. if (BIB_PARSE_DEBUG) echo "$author not a string ";
  939. return false;
  940. }
  941. if (($posA=strrpos($author,'.'))!==false){
  942. $author=trim(substr($author,$posA+1));
  943. return Bibliography::getAuthorInitial($author,false);
  944. } elseif (($posA=strrpos($author,' '))!==false){
  945. $arr=explode(' ', $author);
  946. foreach($arr as $ka=>$a){$a=trim($a);
  947. if (($isFirst&&$ka<1)|| (strlen($a)<2)) continue; //||in_array($a,array("Le","De",... )
  948. return $a[0];
  949. }
  950. }
  951. return strtoupper($author[0]);
  952. }
  953. } /*end of Bibliography class*/
  954. /** Build a citation.
  955. *
  956. * This is just a link to {@link Bibliography::cite()} method
  957. * @param (String) a bibkey reference
  958. * @param (String) index where are located the reference page, and where the
  959. * 'bibKey' are binded
  960. * @return (String) anchor HTML markup
  961. */
  962. function cite($ref,$index=BIB_INDEX){
  963. return Bibliography::bibkey($ref,$index);
  964. }
  965. if (!function_exists("__")){
  966. /** Internationalisation function
  967. * @param (String) the string to translate
  968. * @return (String)
  969. */
  970. function __($str){
  971. return (!empty($GLOBALS['__l10n'][$str])) ? $GLOBALS['__l10n'][$str] : $str;
  972. }
  973. }
  974. ?>