Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_rss.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * RSS syndication on a folder (search, folders, report....)
9  *
10  * @author Anakeen 2003
11  * @version $Id: freedom_rss.php,v 1.11 2009/01/14 13:09:53 jerome Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/freedom_util.php");
20 include_once ("FDL/Lib.Dir.php");
21 
22 function freedom_rss(&$action)
23 {
24 
25  $id = GetHttpVars("id", 0);
26  $dhtml = (GetHttpVars("dh", 1) == 1 ? true : false);
27  $action->lay->set("html", $dhtml);
28  $lim = GetHttpVars("lim", 100);
29  $order = GetHttpVars("order");
30 
31  $dbaccess = $action->GetParam("FREEDOM_DB");
32 
33  header('Content-type: text/xml; charset=utf-8');
34  $action->lay->setEncoding("utf-8");
35 
36  $baseurl = $action->getparam("CORE_EXTERNURL");
37 
38  if (!$action->auth) $addauth = '&authtype=basic';
39  else $addauth = '';
40 
41  $standurl = __xmlentities($action->GetParam("CORE_STANDURL"));
42  $action->lay->set("standurl", $standurl);
43  $action->lay->set("server", substr($baseurl, 0, strrpos($baseurl, '/')));
44 
45  $cssf = getparam("CORE_STANDURL") . "$addauth&app=CORE&action=CORE_CSS&session=" . $action->session->id . "&layout=FDL:RSS.CSS";
46  $action->lay->set("rsscss", $cssf);
47 
48  setlocale(LC_TIME, "C");
49  $rsslink = $baseurl . __xmlentities("?sole=Y$addauth&app=FDL&action=FDL_CARD&latest=Y&id=" . $id);
50  $action->lay->set("rsslink", $rsslink);
51  $action->lay->set("copy", "Copyright 2006 Anakeen");
52  $action->lay->set("lang", substr(getParam("CORE_LANG") , 0, 2));
53  $action->lay->set("datepub", strftime("%a, %d %b %Y %H:%M:%S %z", time()));
54  $action->lay->set("ttl", 60);
55  $action->lay->set("category", "Dynacase documents");
56  $action->lay->set("generator", "Dynacase version " . $action->parent->getParam("VERSION"));
57 
59  $action->lay->set("lastbuild", strftime("%a, %d %b %Y %H:%M:%S %z", $doc->revdate));
60  // Check right for doc access
61  if ($doc->defDoctype == 'S') $aclctrl = "execute";
62  else $aclctrl = "open";
63  if (($err = $doc->Control($aclctrl)) != "") {
64  $action->log->error($err);
65  return;
66  }
67  $action->lay->set("icon", $doc->getIcon());
68  if ($doc->doctype != 'S' && $doc->doctype != 'D') {
69 
70  $ldoc = array(
72  );
73  } else {
74 
75  $filter = array();
76  $famid = "";
77  $report = ($doc->fromid == getIdFromName($dbaccess, "REPORT") ? true : false);
78  $items = array();
79  if (!$order) {
80  if ($doc->getValue("REP_IDSORT")) {
81  $order = $doc->getValue("REP_IDSORT");
82  $order.= " " . $doc->getValue("REP_ORDERSORT");
83  } else $order = "revdate desc";
84  }
85  $ldoc = getChildDoc($dbaccess, $doc->id, 0, $lim, $filter, $action->user->id, "TABLE", $famid, false, $order);
86  }
87  if ($report) {
88  $tmpdoc = createDoc($dbaccess, getIdFromName($dbaccess, "REPORT") , false);
89  $fdoc = createDoc($dbaccess, $doc->getValue("SE_FAMID") , false);
90  $lattr = $fdoc->GetNormalAttributes();
91  $tcol1 = array();
92  foreach ($lattr as $k => $v) {
93  $tcol1[$v->id] = array(
94  "colid" => $v->id,
95  "collabel" => $v->getLabel() ,
96  "rightfornumber" => ($v->type == "money") ? "right" : "left"
97  );
98  }
99  $tinternals = $tmpdoc->_getInternals();
100  foreach ($tinternals as $k => $v) {
101  $tcol1[$k] = array(
102  "colid" => $k,
103  "collabel" => $v,
104  "rightfornumber" => "left"
105  );
106  }
107  $tcolshown = array();
108  $tcols = $doc->getTValue("REP_IDCOLS");
109  foreach ($tcols as $k => $v) {
110  $tcolshown[$v] = $tcol1[$v];
111  }
112  }
113  // $action->lay->set("rssname", $doc->getTitle()." -".count($ldoc)."-");
114  $action->lay->set("rssname", __xmlentities($doc->getTitle()));
115 
116  $lines = array();
117  foreach ($ldoc as $kdoc => $vdoc) {
118  $zdoc = getDocObject($dbaccess, $vdoc);
119  $descr = '';
120 
121  $items[$zdoc->id] = array(
122  "title" => "",
123  "link" => $baseurl . __xmlentities("?sole=Y$addauth&app=FDL&action=FDL_CARD&id=" . $zdoc->id) ,
124  "descr" => "",
125  "revdate" => strftime("%a, %d %b %Y %H:%M:%S %z", $zdoc->revdate) ,
126  "id" => $zdoc->id,
127  "category" => $zdoc->fromname,
128  "author" => __xmlentities(getMailAddr($zdoc->owner, true)) ,
129  "rssname" => __xmlentities($doc->getTitle()),
130  "rsslink" => $rsslink,
131  "report" => $report,
132  );
133  if ($report) {
134  $lines = array();
135  $i = 0;
136  foreach ($tcolshown as $kc => $vc) {
137  if ($zdoc->getValue($kc) == "") $lines[] = array(
138  "attr" => $vc["collabel"],
139  "val" => ""
140  );
141  else {
142  switch ($kc) {
143  case "revdate":
144  $cval = strftime("%x %T", $vdoc[$kc]);
145  break;
146 
147  case "state":
148  $cval = _($vdoc[$kc]);
149  break;
150 
151  default:
152  $cval = $zdoc->getHtmlValue($lattr[$kc], $zdoc->getValue($kc) , "", false);
153  if ($lattr[$kc]->type == "image") $cval = "<img width=\"30px\" src=\"$cval\">";
154  }
155  if ($i == 0) {
156  $items[$zdoc->id]["title"] = __xmlentities(html_entity_decode($cval, ENT_NOQUOTES, 'UTF-8'));
157  $i++;
158  } else {
159  $cval = __xmlentities($cval);
160  $lines[] = array(
161  "attr" => $vc["collabel"],
162  "val" => ($cval)
163  );
164  }
165  }
166  }
167  $action->lay->setBlockData("lines" . $zdoc->id, $lines);
168  } else {
169  $items[$zdoc->id]["descr"] = ($dhtml ? __xmlentities(($zdoc->viewdoc("FDL:VIEWTHUMBCARD"))) : "...");
170  $items[$zdoc->id]["title"] = __xmlentities($zdoc->getTitle());
171  }
172  }
173  $action->lay->setBlockData("Items", $items);
174  $action->lay->set("report", $report);
175 }
176 
177 function __xmlentities($string)
178 {
179  return preg_replace(array(
180  '/&/',
181  '/"/',
182  "/'/",
183  '/</',
184  '/>/'
185  ) , array(
186  '&amp;',
187  '&quot;',
188  '&apos;',
189  '&lt;',
190  '&gt;',
191  '&apos;'
192  ) , $string);
193 }
194 ?>
← centre documentaire © anakeen - published under CC License - Dynacase