PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/works/trunk/class/pwfunctions.class.php

http://bitcero-modules.googlecode.com/
PHP | 192 lines | 120 code | 38 blank | 34 comment | 17 complexity | e2d66d8806b569e6f00a5409a0011578 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: pwfunctions.class.php 903 2012-01-03 07:09:43Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // Professional Works
  5. // Advanced Portfolio System
  6. // Author: BitC3R0 <i.bitcero@gmail.com>
  7. // Email: i.bitcero@gmail.com
  8. // License: GPL 2.0
  9. // --------------------------------------------------------------
  10. class PWFunctions
  11. {
  12. /**
  13. * @desc Crea el encabezado de la sección frontal
  14. */
  15. public function makeHeader(){
  16. global $xoopsModuleConfig, $xoopsTpl, $xoopsUser, $db;
  17. $xoopsTpl->assign('pw_title', $xoopsModuleConfig['title']);
  18. $xoopsTpl->assign('lang_recentsall', __('Recent works','works'));
  19. $xoopsTpl->assign('lang_featuredall', __('Featured works','works'));
  20. $recent = $xoopsModuleConfig['urlmode'] ? XOOPS_URL.'/'.trim($xoopsModuleConfig['htbase'], '/').'/recent/' : XOOPS_URL.'/modules/works/index.php?page=recent';
  21. $featured = $xoopsModuleConfig['urlmode'] ? XOOPS_URL.'/'.trim($xoopsModuleConfig['htbase'], '/').'/featured/' : XOOPS_URL.'/modules/works/index.php?page=featured';
  22. $xoopsTpl->assign('url_recent', $recent);
  23. $xoopsTpl->assign('url_featured', $featured);
  24. $xoopsTpl->assign('url_home', PW_URL);
  25. }
  26. /**
  27. * @desc Rating del trabajo
  28. * @param $rating del trabajo
  29. **/
  30. public function rating($rating){
  31. $rtn = '<div class="pwRating" style="font-weight: bold; color: #999; font-family: Verdana, arial, helvetica, sans-serif; font-size: 10px; width: 69px; text-align: center;"><div style="text-align: left;width: 69px; height: 15px; background: url('.XOOPS_URL.'/modules/works/images/starsgray.png) no-repeat;">';
  32. $rating = $rating;
  33. $percent = 10/69;
  34. $rtn .= '<div style="text-align: center; width: '.($rating>0 ? ($rating/$percent > 69 ? 69 : round($rating/$percent)) : 0).'px; height: 15px; background: url('.XOOPS_URL.'/modules/works/images/stars.png) no-repeat;">&nbsp;</div>';
  35. $rtn .= '</div>';
  36. $rtn .= "</div>";
  37. return $rtn;
  38. }
  39. /**
  40. * @desc Verifica el tipo de acceso a la información y si es necesario
  41. *la existencia del archivo htaccess
  42. **/
  43. public function accessInfo(){
  44. global $xoopsModuleConfig;
  45. if ($xoopsModuleConfig['urlmode']==0) return true;
  46. $docroot = str_replace("\\", "/", $_SERVER['DOCUMENT_ROOT']);
  47. $path = str_replace($docroot, '', XOOPS_ROOT_PATH.'/modules/works/');
  48. if (substr($path, 0, 1)!='/'){
  49. $path = '/'.$path;
  50. }
  51. $file=XOOPS_ROOT_PATH.'/modules/works/.htaccess';
  52. if (!file_exists($file)){
  53. return false;
  54. }
  55. //Determina permisos de lectura y escritura a htacces
  56. if ((!is_readable($file)))
  57. {
  58. return false;
  59. }
  60. //Verifica que información contiene htaccess y si es necesario reescribe htacces
  61. $info = file_get_contents($file);
  62. //Si acceso es por id numérico
  63. if ($xoopsModuleConfig['urlmode']){
  64. $contenido = "RewriteEngine On\nRewriteBase ".str_replace($docroot, '', PW_PATH.'/')."\nRewriteCond %{REQUEST_URI} !/[A-Z]+-\nRewriteRule ^pag/(.*)/?$ index.php?pag=$1 [L]\nRewriteRule ^recent/(.*)/?$ recent.php$1 [L]\nRewriteRule ^featured/(.*)/?$ featured.php$1 [L]\nRewriteRule ^work/(.*)/?$ work.php?id=$1 [L]\nRewriteRule ^cat/(.*)/?$ catego.php?id=$1 [L]";
  65. //Compara contenido de htaccess
  66. $pos = stripos(file_get_contents($file),$contenido);
  67. if ($pos!==false) return true;
  68. if ((!is_writable($file)))
  69. {
  70. return false;
  71. }
  72. //Copia información a archivo
  73. return file_put_contents($file,$contenido);
  74. }
  75. }
  76. /**
  77. * Get works based on given parameters
  78. */
  79. public function get_works($limit, $category=null, $public=1, $object=true, $order="created DESC"){
  80. global $xoopsModule, $xoopsModuleConfig;
  81. include_once XOOPS_ROOT_PATH.'/modules/works/class/pwwork.class.php';
  82. include_once XOOPS_ROOT_PATH.'/modules/works/class/pwcategory.class.php';
  83. include_once XOOPS_ROOT_PATH.'/modules/works/class/pwclient.class.php';
  84. $db = XoopsDatabaseFactory::getDatabaseConnection();
  85. $sql = "SELECT * FROM ".$db->prefix('pw_works')." WHERE public=$public";
  86. $sql .= $category>0 ? " AND catego='$category'" : '';
  87. $sql .= $order!='' ? " ORDER BY $order" : '';
  88. $sql.= " LIMIT 0,$limit";
  89. if ($xoopsModule && $xoopsModule->dirname()=='works'){
  90. $mc =& $xoopsModuleConfig;
  91. } else {
  92. $mc = RMUtilities::module_config('works');
  93. }
  94. $result = $db->query($sql);
  95. $works = array();
  96. while ($row = $db->fetchArray($result)){
  97. $work = new PWWork();
  98. $work->assignVars($row);
  99. $ret = array();
  100. if (!isset($categos[$work->category()])) $categos[$work->category()] = new PWCategory($work->category());
  101. if (!isset($clients[$work->client()])) $clients[$work->client()] = new PWClient($work->client());
  102. $ret = array(
  103. 'id'=>$work->id(),
  104. 'title'=>$work->title(),
  105. 'desc'=>$work->descShort(),
  106. 'catego'=>$categos[$work->category()]->name(),
  107. 'client'=>$clients[$work->client()]->name(),
  108. 'link'=>$work->link(),
  109. 'created'=>formatTimeStamp($work->created(),'s'),
  110. 'created_time'=>$work->created(),
  111. 'image'=>XOOPS_UPLOAD_URL.'/works/ths/'.$work->image(),
  112. 'rating'=>PWFunctions::rating($work->rating()),
  113. 'featured'=>$work->mark(),
  114. 'linkcat'=>$categos[$work->category()]->link(),
  115. 'metas'=>$work->get_metas()
  116. );
  117. if ($object){
  118. $w = new stdClass();
  119. foreach ($ret as $var => $value){
  120. $w->$var = $value;
  121. }
  122. $works[] = $w;
  123. } else {
  124. $works[] = $ret;
  125. }
  126. }
  127. return $works;
  128. }
  129. /**
  130. * Create toolbar
  131. */
  132. public function toolbar(){
  133. RMTemplate::get()->add_tool(__('Dashboard','admin_works'), './index.php', '../images/dashboard.png', 'dashboard');
  134. RMTemplate::get()->add_tool(__('Categories','admin_works'), './categos.php', '../images/cats16.png', 'categories');
  135. RMTemplate::get()->add_tool(__('Customer Types','admin_works'), './types.php', '../images/types.png', 'customertypes');
  136. RMTemplate::get()->add_tool(__('Customers','admin_works'), './clients.php', '../images/clients.png', 'customers');
  137. RMTemplate::get()->add_tool(__('Works','admin_works'), './works.php', '../images/works.png', 'works');
  138. }
  139. /**
  140. * Get works custom fields
  141. * @param int Work id
  142. */
  143. public function work_metas($work){
  144. if ($work<=0) return;
  145. $db = XoopsDatabaseFactory::getDatabaseConnection();
  146. $sql = "SELECT * FROM ".$db->prefix("pw_meta")." WHERE work='$work'";
  147. $result = $db->query($sql);
  148. $metas = array();
  149. while ($row = $db->fetchArray($result)){
  150. $metas[$row['name']] = $row['value'];
  151. }
  152. return $metas;
  153. }
  154. }