PageRenderTime 69ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_languages/www/administrator/components/com_comment/plugin/com_docman/josc_com_docman.class.php

https://github.com/DanielTichy/plagat.com
PHP | 371 lines | 216 code | 55 blank | 100 comment | 31 complexity | 02b6a69f1ef084c99d0c450cc45d124d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, AGPL-1.0, MIT
  1. <?php
  2. defined('_JEXEC') or die('Restricted access');
  3. class JOSC_com_docman extends JOSC_component {
  4. // var $_component=''; /* JOSC_component */
  5. // var $_id=0; /* JOSC_component */
  6. /* specific properties of REPLACEnewplugin if needed */
  7. // var _specific_data;
  8. function JOSC_com_docman($component,&$row,&$list)
  9. {
  10. $id = isset($row->id) ? $row->id : 0; /* document id */
  11. $this->setRowDatas($row); /* get specific properties */
  12. $this->JOSC_component($component,0,$id);
  13. }
  14. /*
  15. * Set specific properties
  16. * will be called also in admin.html.php manage comments during row loop
  17. */
  18. function setRowDatas(&$row)
  19. {
  20. /* for optimization reason, do not save row. save just needed parameters */
  21. //$this->_specific_data = isset($row->specific) ? $row->specific : '';
  22. }
  23. /*
  24. * This function is executed to check
  25. * if section/category of the row are authorized or not (exclude/include from the setting)
  26. * return : true for authorized / false for excluded
  27. * obj :
  28. * - _include_sc
  29. * - _exclude_sections
  30. * - _exclude_categories
  31. * - _exclude_contentitems
  32. *
  33. */
  34. function checkSectionCategory(&$row, &$obj)
  35. {
  36. $include = isset($obj->_include_sc) ? $obj->_include_sc : false;
  37. $sections = isset($obj->_exclude_sections) ? $obj->_exclude_sections : array();
  38. $catids = isset($obj->_exclude_categories) ? $obj->_exclude_categories : array();
  39. $contentids = isset($obj->_exclude_contentids) ? $obj->_exclude_contentids : array() ;
  40. $contentitems = isset($obj->_exclude_contentitems) ? $obj->_exclude_contentitems : array() ;
  41. /* doc id excluded ? DO NOT USE ANYMORE */
  42. if (in_array((($row->id == 0) ? -1 : $row->id), $contentids))
  43. return false;
  44. /*
  45. * Include = include only : selected Ids OR selected Sections OR Selected Categories)
  46. * Exclude = exclude selected Ids OR selected Sections OR Selected Categories
  47. */
  48. /* content ids */
  49. if (count($contentitems)>0) {
  50. $result = in_array((($row->id == 0) ? -1 : $row->id), $contentitems);
  51. if ($include && $result) return true; /* include and selected */
  52. if (!$include && $result) return false; /* exclude and selected */
  53. }
  54. /* sections (docman categories) */
  55. $result = in_array((($row->catid == 0) ? -1 : $row->catid), $sections);
  56. if ($include && $result) return true; /* include and selected */
  57. if (!$include && $result) return false; /* exclude and selected */
  58. if ($include) return false; /* was not included */
  59. if (!$include) return true; /* was not excluded */
  60. }
  61. /*
  62. * Condition to active or not the display of the post and input form
  63. * If the return is false, show readon will be executed.
  64. */
  65. function checkVisual($contentId=0)
  66. {
  67. global $option, $task;
  68. return ( $option == 'com_docman'
  69. && $task == 'doc_details'
  70. );
  71. }
  72. /*
  73. * This function will active or deactivate the show readon display
  74. */
  75. function setShowReadon( &$row, &$params, &$config )
  76. {
  77. $show_readon = $config->_show_readon;
  78. return $show_readon;
  79. }
  80. /*
  81. * construct the link to the content item
  82. * (and also direct to the comment if commentId set)
  83. */
  84. function linkToContent($contentId, $commentId='', $joscclean=false, $admin=false)
  85. {
  86. global $mainframe;
  87. $add = ( $joscclean ? "&joscclean=1" : "" ) . ( $commentId ? "&comment_id=$commentId#josc$commentId" : "" ) ;
  88. // /* COPY of docman latest module to get the itemid */
  89. // include_once( JPATH_SITE."/administrator/components/com_docman/docman.class.php");
  90. //
  91. // //DOCman core interaction API
  92. // global $_DOCMAN, $_DMUSER;
  93. // if(!is_object($_DOCMAN)) {
  94. // $_DOCMAN = new dmMainFrame();
  95. // $_DMUSER = $_DOCMAN->getUser();
  96. // }
  97. // $menuid = $_DOCMAN->getMenuId();
  98. // /* ********************* */
  99. $menuid = $this->getItemid();
  100. $url = ($admin ? "/" : "" )
  101. . "index.php?option=com_docman&task=doc_details&gid=$contentId"
  102. . ( $menuid ? "&Itemid=$menuid" : "" );
  103. // $url = DOCMAN_Utils::_rawLink('doc_details',$contentId);
  104. $url .= $add;
  105. if ($admin)
  106. $url = JURI::base().$url;
  107. $url = function_exists('sefRelToAbs') ? sefRelToAbs($url) : $url; /* does not exist in admin part */
  108. return ($url);
  109. }
  110. /*
  111. * clean the cache of the component when comments are inserted/modified...
  112. * (if cache is active)
  113. */
  114. function cleanComponentCache()
  115. {
  116. $cache =& JFactory::getCache('com_docman');
  117. $cache->clean('com_docman');
  118. }
  119. /*
  120. * copy of docman getItemid (because not available in admin part)
  121. */
  122. function getItemid( $component='com_docman')
  123. {
  124. static $ids;
  125. if( !isset($ids) ) {
  126. $ids = array();
  127. }
  128. if( !isset($ids[$component]) ) {
  129. $database = JFactory::getDBO();
  130. $query = "SELECT id FROM #__menu"
  131. ."\n WHERE link LIKE '%option=$component%'"
  132. ."\n AND type = 'component'"
  133. ."\n AND published = 1 LIMIT 1";
  134. $database->setQuery($query);
  135. $ids[$component] = $database->loadResult();
  136. }
  137. return $ids[$component];
  138. }
  139. /*----------------------------------------------------------------------------------
  140. * F U N C T I O N S F O R A D M I N P A R T
  141. *----------------------------------------------------------------------------------
  142. */
  143. /*
  144. * section option list used to display the include/exclude section list in setting
  145. * must return an array of objects (id,title)
  146. */
  147. function getSectionsIdOption()
  148. {
  149. $database = JFactory::getDBO();
  150. $sectoptions = array();
  151. $query = "SELECT id, title"
  152. . "\n FROM #__categories"
  153. . "\n WHERE published = 1"
  154. . "\n AND section = 'com_docman' "
  155. // . "\n AND access >= 0"
  156. . "\n ORDER BY ordering"
  157. ;
  158. $database->setQuery( $query );
  159. $sectoptions = $database->loadObjectList();
  160. return $sectoptions;
  161. }
  162. /*
  163. * categories option list used to display the include/exclude category list in setting
  164. * must return an array of objects (id,title)
  165. */
  166. function getCategoriesIdOption()
  167. {
  168. $database = JFactory::getDBO();
  169. $catoptions = array();
  170. return $catoptions;
  171. }
  172. /*
  173. * document list (or single) for new and edit comment
  174. * must return an array of objects (id,title)
  175. */
  176. function getObjectIdOption($id=0, $select=true)
  177. {
  178. $database = JFactory::getDBO();
  179. $content = array();
  180. $query = "SELECT id, dmname AS title"
  181. . "\n FROM #__docman "
  182. . " WHERE published=1"
  183. . ($id ? "\n AND id = $id":"")
  184. ;
  185. $database->setQuery( $query );
  186. $content = $database->loadObjectList();
  187. if (!$id && $select && count($content)>0) {
  188. array_unshift( $content, JHTML::_('select.option', '0', '-- Select Document --', 'id', 'title' ) );
  189. }
  190. return $content;
  191. }
  192. function getViewTitleField()
  193. {
  194. $title = 'dmname';
  195. return($title);
  196. }
  197. function getViewJoinQuery($alias, $contentid)
  198. {
  199. $leftjoin = "\n LEFT JOIN #__docman AS $alias ON $alias.id = $contentid ";
  200. return $leftjoin;
  201. }
  202. /*----------------------------------------------------------------------------------
  203. * F U N C T I O N S F O R MOD_COMMENTS M O D U L E
  204. *----------------------------------------------------------------------------------
  205. */
  206. function mod_commentsGetMostCommentedQuery($secids, $catids, $maxlines)
  207. {
  208. $database = JFactory::getDBO();
  209. $component = $this->_component;
  210. $limit = $maxlines>=0 ? " limit $maxlines " : "";
  211. $where = array();
  212. if ($secids)
  213. $where[] = "cat.id IN ($secids)";
  214. /*
  215. * Count comment id group by contentid
  216. * TODO: restrict according to user rights, dates and category/secitons published and dates...
  217. */
  218. $query = "SELECT COUNT(c.id) AS countid, ct.id, ct.dmname AS title "
  219. . "\n FROM `#__comment` AS c "
  220. . "\n INNER JOIN `#__docman` AS ct ON ct.id = c.contentid "
  221. . "\n INNER JOIN `#__categories` AS cat ON cat.id = ct.catid "
  222. . "\n WHERE c.published='1' "
  223. . "\n AND c.component='$component' "
  224. . "\n ". (count($where) ? (" AND ".implode(" AND ", $where)) : "")
  225. . "\n GROUP BY c.contentid"
  226. . "\n ORDER BY countid DESC"
  227. . "\n $limit"
  228. ;
  229. $database->SetQuery($query);
  230. $rows = $database->loadAssocList();
  231. return $rows;
  232. }
  233. function mod_commentsGetOthersQuery($secids, $catids, $maxlines, $orderby)
  234. {
  235. $database = JFactory::getDBO();
  236. $component = $this->_component;
  237. $limit = $maxlines>=0 ? " limit $maxlines " : "";
  238. $where = array();
  239. if ($secids)
  240. $where[] = "cat.id IN ($secids)";
  241. if ($orderby=='mostrated') {
  242. $mostrated = ", (c.voting_yes-c.voting_no)/2 AS mostrated";
  243. $where[] = "(c.voting_yes > 0 OR c.voting_no > 0)";
  244. } else {
  245. $mostrated = "";
  246. $orderby = "c.$orderby";
  247. }
  248. /*
  249. * TODO: restrict according to user rights, dates and category/secitons published and dates...
  250. */
  251. $query = "SELECT c.*, ct.dmname AS ctitle $mostrated "
  252. . "\n FROM `#__comment` AS c "
  253. . "\n INNER JOIN `#__docman` AS ct ON ct.id = c.contentid "
  254. . "\n INNER JOIN `#__categories` AS cat ON cat.id = ct.catid "
  255. . "\n WHERE c.published='1' "
  256. . "\n AND c.component='$component' "
  257. . "\n ". (count($where) ? (" AND ".implode(" AND ", $where)) : "")
  258. . "\n ORDER BY $orderby DESC "
  259. . "\n $limit"
  260. ;
  261. $database->SetQuery($query);
  262. $rows = $database->loadAssocList();
  263. return $rows;
  264. }
  265. /*
  266. * O P T I O N N A L
  267. * F O R E X P E R T M O D E O N L Y
  268. * not yet available.
  269. * do not report theses functions !
  270. */
  271. /*
  272. * section option list for the admin setting
  273. */
  274. function getExpertSectionIdOption($sections, $include)
  275. {
  276. $database = JFactory::getDBO();
  277. $where = "";
  278. if ($sections) {
  279. if ($include)
  280. $where = "\n AND id IN ($sections) ";
  281. else
  282. $where = "\n AND id NOT IN ($sections) ";
  283. }
  284. $sectoptions = array();
  285. $query = "SELECT id, title"
  286. . "\n FROM #__categories"
  287. . "\n WHERE published = 1"
  288. . "\n AND section = 'com_docman' "
  289. . $where
  290. // . "\n AND access >= 0"
  291. . "\n ORDER BY ordering"
  292. ;
  293. $database->setQuery( $query );
  294. $sectoptions = $database->loadObjectList();
  295. // add "All sections"
  296. array_unshift( $sectoptions, JHTML::_('select.option', '0', '-- All --', 'id', 'title' ) );
  297. return $sectoptions;
  298. }
  299. /*
  300. * return the id,title section object
  301. */
  302. function getExpertSectionTitle($sectionid)
  303. {
  304. $database = JFactory::getDBO();
  305. if ($sectionid==0)
  306. return '(0) All ';
  307. $query = "SELECT id, title"
  308. . "\n FROM #__categories"
  309. . "\n WHERE id=$sectionid"
  310. ;
  311. $database->setQuery( $query );
  312. $row = $database->loadObjectList();
  313. return "($sectionid) ".$row[0]->title;
  314. }
  315. }
  316. ?>