PageRenderTime 28ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/dtransport/trunk/item.php

http://bitcero-modules.googlecode.com/
PHP | 288 lines | 214 code | 46 blank | 28 comment | 17 complexity | 44e13902ded7a60e7f69aa5bb992743b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: item.php 1068 2012-09-19 01:50:37Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // D-Transport
  5. // Manage files for download in XOOPS
  6. // Author: Eduardo Cortés <i.bitcero@gmail.com>
  7. // Email: i.bitcero@gmail.com
  8. // License: GPL 2.0
  9. // --------------------------------------------------------------
  10. if ($id==''){
  11. header('location: '.DT_URL);
  12. die();
  13. }
  14. $item = new DTSoftware($id);
  15. if($item->getVar('approved')){
  16. $canview = true;
  17. } else {
  18. $canview = $xoopsUser->isAdmin() || ($xoopsUser->uid()==$item->getVar('uid'));
  19. }
  20. if ($item->isNew() || !$canview){
  21. redirect_header(DT_URL, 2, __('Specified item does not exists!','dtransport'));
  22. die();
  23. }
  24. if($item->getVar('delete'))
  25. redirect_header(DT_URL, 2, __('This item is not available for download at this moment!','dtransport'));
  26. // Download default file
  27. if($action=='download'){
  28. $file = $item->file();
  29. if(!$file)
  30. redirect_header($item->permalink(), 0, __('Internal Error! Please try again later','dtransport'));
  31. header("location: ".$file->permalink());
  32. die();
  33. }
  34. $xoopsOption['template_main'] = 'dtrans_item.html';
  35. $xoopsOption['module_subpage'] = 'item';
  36. include 'header.php';
  37. $xoopsTpl->assign('dtrans_option','details');
  38. $dtfunc->makeHeader();
  39. $candownload = $item->canDownload($xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS);
  40. // Enlaces del elemento
  41. $data = array();
  42. $data['link'] = $item->permalink();
  43. $data['screens'] = $item->permalink(0, 'screens');
  44. $data['download'] = $candownload ? $item->permalink(0, 'download') : '';
  45. $data['features'] = $item->permalink(0, 'features');
  46. $data['logs'] = $item->permalink(0, 'logs');
  47. // Datos generales
  48. $data['name'] = $item->getVar('name');
  49. $data['version'] = $item->getVar('version');
  50. // Imagen por defecto
  51. $img = new RMImage();
  52. $img->load_from_params($item->getVar('image'));
  53. $data['image'] = $img->url();
  54. $data['thumbnail'] = $img->get_smallest();
  55. $data['rating'] = @number_format($item->getVar('rating')/$item->getVar('votes'), 1);
  56. $data['votes'] = $item->getVar('votes');
  57. // Licencias
  58. $data['licenses'] = array();
  59. foreach ($item->licences(true) as $lic){
  60. $data['licenses'][] = array(
  61. 'url' => $lic->link(),
  62. 'name' => $lic->name(),
  63. 'link' => $lic->permalink()
  64. );
  65. }
  66. // Plataformas
  67. $data['platforms'] = array();
  68. foreach ($item->platforms(true) as $os){
  69. $data['platforms'][] = array(
  70. 'name' => $os->name(),
  71. 'link' => $os->permalink()
  72. );
  73. }
  74. $tf = new RMTimeFormatter(0, '%T% %d%, %Y%'); // Time formatter
  75. $data['created'] = $tf->format($item->getVar('created'));
  76. $data['update'] = $item->getVar('created')>0 ? $tf->format($item->getVar('modified')) : '';
  77. $data['author'] = array(
  78. 'name' => $item->getVar('author_name'),
  79. 'url' => $item->getVar('author_url'),
  80. 'email' => $item->getVar('author_email'),
  81. 'contact' => $item->getVar('author_contact'),
  82. );
  83. $data['langs'] = $item->getVar('langs');
  84. $data['downs'] = $item->getVar('hits');
  85. $data['version'] = $item->getVar('version');
  86. $data['updated'] = $item->getVar('modified')>$item->getVar('created') && $item->getVar('modified')>(time()-($mc['update']*86400));
  87. $data['new'] = !$data['updated'] && $item->getVar('created')>(time()-($mc['new']*86400));
  88. $data['description'] = $item->getVar('desc');
  89. $data['shortdesc'] = $item->getVar('shortdesc');
  90. $data['siterate'] = $dtfunc->ratingStars($item->getVar('siterate'));
  91. $fg = $item->fileGroups(true);
  92. $data['filegroups'] = array();
  93. foreach($fg as $g){
  94. $files = $g->files(true);
  95. $data['filegroups'][$g->id()]['name'] = $g->name();
  96. foreach($files as $file){
  97. $data['filegroups'][$g->id()]['files'][] = array(
  98. 'file' => $file->file(),
  99. 'size' => $rmu->formatBytesSize($file->size()),
  100. 'date' => $tf->format($file->date()),
  101. 'title' => $file->title(),
  102. 'remote' => $file->remote(),
  103. 'hits' => $file->hits(),
  104. 'link' => $file->permalink()
  105. );
  106. }
  107. }
  108. // Imágenes de la Descarga
  109. $imgs = $item->screens(true);
  110. $xoopsTpl->assign('screens_count', $item->getVar('screens'));
  111. $data['screens'] = array();
  112. foreach ($imgs as $img){
  113. $data['screens'][] = array(
  114. 'id'=>$img->id(),
  115. 'title'=>$img->title(),
  116. 'image'=>$img->url(),
  117. 'ths' => $img->url('ths')
  118. );
  119. }
  120. unset($imgs,$img);
  121. //Etiquetas
  122. $tags = $item->tags(false);
  123. $relatedTags = array();
  124. $data['tags'] = array();
  125. foreach ($tags as $tag){
  126. $otag=new DTTag();
  127. $otag->assignVars($tag);
  128. $data['tags'][] = array(
  129. 'id' => $tag['id_tag'],
  130. 'name' => $tag['tag'],
  131. 'link' => $otag->permalink()
  132. );
  133. $relatedTags[] = $tag['id_tag'];
  134. }
  135. unset($tags,$otag,$tag);
  136. // Categories
  137. $cats = $item->categories(true);
  138. $data['categories'] = array();
  139. foreach($cats as $ocat){
  140. $data['categories'][] = array(
  141. 'id' => $ocat->id(),
  142. 'name' => $ocat->name(),
  143. 'link' => $ocat->permalink()
  144. );
  145. }
  146. unset($ocat,$cats,$cat);
  147. // Características
  148. $chars = $item->features(true);
  149. $data['features'] = array();
  150. foreach ($chars as $feature){
  151. $updated = $feature->modified()>$feature->created() && $feature->modified()>(time()-($mc['update']*86400));
  152. $new = !$updated && $feature->created()>(time() - ($mc['new']*86400));
  153. $data['features'][] = array(
  154. 'id'=>$feature->id(),
  155. 'title'=>$feature->title(),
  156. 'updated'=>$updated,
  157. 'nameid'=>$feature->nameid(),
  158. 'content' => $feature->content(),
  159. 'link' => $feature->permalink(),
  160. 'metas' => $dtfunc->get_metas('feat', $feature->id())
  161. );
  162. }
  163. unset($chars, $feature);
  164. // Logs
  165. $logs = $item->logs(true);
  166. $data['logs'] = array();
  167. foreach ($logs as $log){
  168. $data['logs'][] = array(
  169. 'id'=>$log->id(),
  170. 'title'=>$log->title(),
  171. 'content' => $log->log(),
  172. 'date'=>formatTimestamp($log->date(),'s')
  173. );
  174. }
  175. unset($logs, $log);
  176. $data['metas'] = $dtfunc->get_metas('down', $item->id());
  177. $data['approved'] = $item->getVar('approved');
  178. $xoopsTpl->assign('item', $data);
  179. // Usuario
  180. $dtUser = new XoopsUser($item->getVar('uid'));
  181. $xoopsTpl->assign('dtUser', array('id'=>$dtUser->uid(),'uname'=>$dtUser->uname(),'avatar'=>$dtUser->getVar('user_avatar')));
  182. if($mc['daydownload']){
  183. $xoopsTpl->assign('daily_items', $dtfunc->get_items(0, 'daily', $mc['limit_daydownload']));
  184. $xoopsTpl->assign('daily_width', floor(100/($mc['limit_daydownload'])));
  185. $xoopsTpl->assign('lang_daydown', __('<strong>Day</strong> Downloads','dtransport'));
  186. }
  187. // Desargas relacionadas
  188. if($mc['active_relatsoft']){
  189. $xoopsTpl->assign('lang_related',__('<strong>Related</strong> Downloads','dtransport'));
  190. $xoopsTpl->assign('related_items', $dtfunc->items_by($relatedTags, 'tags', $item->id(), 'RAND()', 0, $mc['limit_relatsoft']));
  191. }
  192. if(!$item->getVar('approved')){
  193. $xoopsTpl->assign('lang_noapproved', __('This item has not been approved yet! You can view this information but other users can not.','dtransport'));
  194. }
  195. // Lenguaje
  196. $xoopsTpl->assign('lang_new', __('New','dtransport'));
  197. $xoopsTpl->assign('lang_updated', __('Updated','dtransport'));
  198. $xoopsTpl->assign('lang_author', __('Author:','dtransport'));
  199. $xoopsTpl->assign('lang_version', __('Version:','dtransport'));
  200. $xoopsTpl->assign('lang_createdon', __('Created on:','dtransport'));
  201. $xoopsTpl->assign('lang_updatedon', __('Updated on:','dtransport'));
  202. $xoopsTpl->assign('lang_langs', __('Languages:','dtransport'));
  203. $xoopsTpl->assign('lang_platforms', __('Supported platforms:','dtransport'));
  204. $xoopsTpl->assign('lang_license',__('License:','dtransport'));
  205. $xoopsTpl->assign('lang_siterate', sprintf(__('%s rate','dtransport'), $xoopsConfig['sitename']));
  206. $xoopsTpl->assign('lang_rateuser', __('Users rating', 'dtransport'));
  207. $xoopsTpl->assign('lang_votes', __('%u votes', 'dtransport'));
  208. $xoopsTpl->assign('lang_downnow', __('Download Now!','dtransport'));
  209. $xoopsTpl->assign('lang_download', __('Download','dtransport'));
  210. $xoopsTpl->assign('lang_screenshots', __('Screenshots','dtransport'));
  211. $xoopsTpl->assign('lang_tags',__('Tags:','dtransport'));
  212. $xoopsTpl->assign('lang_published',__('Published on:','dtransport'));
  213. $xoopsTpl->assign('lang_downopts',__('Download Options','dtransport'));
  214. $xoopsTpl->assign('lang_details',__('Details','dtransport'));
  215. $xoopsTpl->assign('lang_logs', __('Logs','dtransport'));
  216. $xoopsTpl->assign('lang_features', __('Features','dtransport'));
  217. $xoopsTpl->assign('lang_choose', __('You can choose between next download options if you prefer another file type or another location.','dtransport'));
  218. // Download options labels
  219. $xoopsTpl->assign('lang_title', __('Title','dtransport'));
  220. $xoopsTpl->assign('lang_size', __('Size','dtransport'));
  221. $xoopsTpl->assign('lang_hits', __('Hits','dtransport'));
  222. $xoopsTpl->assign('xoops_pagetitle', $item->getVar('name').($item->getVar('version')!='' ? " ".$item->getVar('version') : '')." &raquo; ".$xoopsModule->name());
  223. // Ubicación Actual
  224. //$location = "<strong>"._MS_DT_YOUREHERE."</strong> <a href='".DT_URL."'>".$xoopsModule->name()."</a> &raquo; ";
  225. $location .= " &raquo; <strong>".$item->getVar('name')."</strong>";
  226. $xoopsTpl->assign('dt_location', $location);
  227. $tpl->add_xoops_style('main.css','dtransport');
  228. $tpl->add_local_script('main.js','dtransport');
  229. $metas = $data['metas'];
  230. $rmf->add_keywords_description(isset($metas['description']) ? $metas['description'] : $item->getVar('shortdesc'), isset($metas['keywords']) ? $metas['keywords'] : '');
  231. // Lightbox plugins
  232. if($rmf->plugin_installed("lightbox")){
  233. $lightbox = RMLightbox::get();
  234. $lightbox->add_element("a.item-images");
  235. $lightbox->add_element("#dt-item-features a");
  236. $lightbox->render();
  237. }
  238. // Comments
  239. $rmf->get_comments('dtransport','item='.$item->id(), 'module', 0, null, true);
  240. // Comments form
  241. RMFunctions::comments_form('dtransport', 'item='.$item->id(), 'module', DT_PATH.'/class/dtransportcontroller.php');
  242. include 'footer.php';