class.blogroll.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. class blogroll
  23. {
  24. var $con;
  25. var $blog;
  26. var $table;
  27. function blogroll(&$blog,$prefix)
  28. {
  29. $this->con = $blog->con;
  30. $this->blog = $blog;
  31. $this->table = $prefix.'link';
  32. }
  33. function addLink($label,$href,$title='',$lang='')
  34. {
  35. $strReq = 'SELECT MAX(position) '.
  36. 'FROM '.$this->table;
  37. if (($rs = $this->con->select($strReq)) === false) {
  38. return false;
  39. }
  40. $position = $rs->f(0);
  41. $insReq = 'INSERT INTO '.$this->table.' '.
  42. '(label, href, title, lang, position) VALUES '.
  43. '(\''.$this->con->escapeStr($label).'\', '.
  44. '\''.$this->con->escapeStr($href).'\', '.
  45. '\''.$this->con->escapeStr($title).'\', '.
  46. '\''.$this->con->escapeStr($lang).'\', '.
  47. '\''.(integer) $position.'\')';
  48. if ($this->con->execute($insReq) === false) {
  49. return false;
  50. }
  51. $this->blog->triggerMassUpd();
  52. return true;
  53. }
  54. function updLink($link_id,$label,$href,$title='',$lang='', $rel='')
  55. {
  56. $updReq = 'UPDATE '.$this->table.' SET '.
  57. 'label = \''.$this->con->escapeStr($label).'\','.
  58. 'href = \''.$this->con->escapeStr($href).'\','.
  59. 'title = \''.$this->con->escapeStr($title).'\','.
  60. 'lang = \'' . $this->con->escapeStr($lang).'\','.
  61. 'rel = \'' . $this->con->escapeStr($rel).'\''.
  62. 'WHERE link_id = '.$link_id;
  63. if ($this->con->execute($updReq) === false) {
  64. return false;
  65. }
  66. $this->blog->triggerMassUpd();
  67. return true;
  68. }
  69. # Suppression (lien ou catégorie)
  70. function delEntry($link_id)
  71. {
  72. $delReq = 'DELETE FROM '.$this->table.' '.
  73. 'WHERE link_id = '.$link_id;
  74. if ($this->con->execute($delReq) === false) {
  75. return false;
  76. }
  77. $this->blog->triggerMassUpd();
  78. return true;
  79. }
  80. # Création de catégorie
  81. function addCat($title)
  82. {
  83. return $this->addLink('','',$title,'');
  84. }
  85. # Modification de catégories
  86. function updCat($id,$title)
  87. {
  88. return $this->updLink($id,'','',$title,'');
  89. }
  90. # Ordonner les entrées
  91. function ordEntries($ord)
  92. {
  93. if (!is_array($ord)) {
  94. return false;
  95. }
  96. foreach ($ord as $k => $v)
  97. {
  98. $updReq = 'UPDATE '.$this->table.' SET '.
  99. 'position = '.(integer) $v.' '.
  100. 'WHERE link_id = '.(integer) $k;
  101. if (!$this->con->execute($updReq)) {
  102. return false;
  103. }
  104. }
  105. $this->blog->triggerMassUpd();
  106. return true;
  107. }
  108. }
  109. ?>