PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/altsys/include/tpls_functions.php

https://github.com/nouphet/momoxo
PHP | 150 lines | 103 code | 33 blank | 14 comment | 16 complexity | d7c16ab72b9961f577fadfe1c28e3e16 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. <?php
  2. include_once dirname(__FILE__).'/altsys_functions.php' ;
  3. function tplsadmin_import_data( $tplset , $tpl_file , $tpl_source , $lastmodified = 0 )
  4. {
  5. $db =& Database::getInstance() ;
  6. // check the file is valid template
  7. list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='default' AND tpl_file='".addslashes($tpl_file)."'" ) ) ;
  8. if( ! $count ) return false ;
  9. // check the template exists in the tplset
  10. if( $tplset != 'default' ) {
  11. list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset)."' AND tpl_file='".addslashes($tpl_file)."'" ) ) ;
  12. if( $count <= 0 ) {
  13. // copy from 'default' to the tplset
  14. $result = $db->query( "SELECT * FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='default' AND tpl_file='".addslashes($tpl_file)."'" ) ;
  15. while( $row = $db->fetchArray( $result ) ) {
  16. $db->queryF( "INSERT INTO ".$db->prefix("tplfile")." SET tpl_refid='".addslashes($row['tpl_refid'])."',tpl_module='".addslashes($row['tpl_module'])."',tpl_tplset='".addslashes($tplset)."',tpl_file='".addslashes($tpl_file)."',tpl_desc='".addslashes($row['tpl_desc'])."',tpl_type='".addslashes($row['tpl_type'])."'" ) ;
  17. $tpl_id = $db->getInsertId() ;
  18. $db->queryF( "INSERT INTO ".$db->prefix("tplsource")." SET tpl_id='$tpl_id', tpl_source=''" ) ;
  19. }
  20. }
  21. }
  22. // UPDATE just tpl_lastmodified and tpl_source
  23. $drs = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset)."' AND tpl_file='".addslashes($tpl_file)."'" ) ;
  24. while( list( $tpl_id ) = $db->fetchRow( $drs ) ) {
  25. $db->queryF( "UPDATE ".$db->prefix("tplfile")." SET tpl_lastmodified='".addslashes($lastmodified)."',tpl_lastimported=UNIX_TIMESTAMP() WHERE tpl_id='$tpl_id'" ) ;
  26. $db->queryF( "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".addslashes($tpl_source)."' WHERE tpl_id='$tpl_id'" ) ;
  27. altsys_template_touch( $tpl_id ) ;
  28. }
  29. return true ;
  30. }
  31. function tplsadmin_get_fingerprint( $lines )
  32. {
  33. $str = '' ;
  34. foreach( $lines as $line ) {
  35. if( trim( $line ) ) {
  36. $str .= md5( trim( $line ) ) ;
  37. }
  38. }
  39. return md5( $str ) ;
  40. }
  41. function tplsadmin_copy_templates_db2db( $tplset_from , $tplset_to , $whr_append = '1' )
  42. {
  43. global $db ;
  44. // get tplfile and tplsource
  45. $result = $db->query( "SELECT tpl_refid,tpl_module,'".addslashes($tplset_to)."',tpl_file,tpl_desc,tpl_lastmodified,tpl_lastimported,tpl_type,tpl_source FROM ".$db->prefix("tplfile")." NATURAL LEFT JOIN ".$db->prefix("tplsource")." WHERE tpl_tplset='".addslashes($tplset_from)."' AND ($whr_append)" ) ;
  46. while( $row = $db->fetchArray( $result ) ) {
  47. $tpl_source = array_pop( $row ) ;
  48. $drs = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_to)."' AND ($whr_append) AND tpl_file='".addslashes($row['tpl_file'])."' AND tpl_refid='".addslashes($row['tpl_refid'])."'" ) ;
  49. if( ! $db->getRowsNum( $drs ) ) {
  50. // INSERT mode
  51. $sql = "INSERT INTO ".$db->prefix("tplfile")." (tpl_refid,tpl_module,tpl_tplset,tpl_file,tpl_desc,tpl_lastmodified,tpl_lastimported,tpl_type) VALUES (" ;
  52. foreach( $row as $colval ) {
  53. $sql .= "'".addslashes($colval)."'," ;
  54. }
  55. $db->query( substr( $sql , 0 , -1 ) . ')' ) ;
  56. $tpl_id = $db->getInsertId() ;
  57. $db->query( "INSERT INTO ".$db->prefix("tplsource")." SET tpl_id='$tpl_id', tpl_source='".addslashes($tpl_source)."'" ) ;
  58. altsys_template_touch( $tpl_id ) ;
  59. } else {
  60. while( list( $tpl_id ) = $db->fetchRow( $drs ) ) {
  61. // UPDATE mode
  62. $db->query( "UPDATE ".$db->prefix("tplfile")." SET tpl_refid='".addslashes($row['tpl_refid'])."',tpl_desc='".addslashes($row['tpl_desc'])."',tpl_lastmodified='".addslashes($row['tpl_lastmodified'])."',tpl_lastimported='".addslashes($row['tpl_lastimported'])."',tpl_type='".addslashes($row['tpl_type'])."' WHERE tpl_id='$tpl_id'" ) ;
  63. $db->query( "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".addslashes($tpl_source)."' WHERE tpl_id='$tpl_id'" ) ;
  64. altsys_template_touch( $tpl_id ) ;
  65. }
  66. }
  67. }
  68. }
  69. function tplsadmin_copy_templates_f2db( $tplset_to , $whr_append = '1' )
  70. {
  71. global $db ;
  72. // get tplsource
  73. $result = $db->query( "SELECT * FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='default' AND ($whr_append)" ) ;
  74. while( $row = $db->fetchArray( $result ) ) {
  75. $basefilepath = tplsadmin_get_basefilepath( $row['tpl_module'] , $row['tpl_type'] , $row['tpl_file'] ) ;
  76. $tpl_source = rtrim( implode( "" , file( $basefilepath ) ) ) ;
  77. $lastmodified = filemtime( $basefilepath ) ;
  78. $drs = $db->query( "SELECT tpl_id FROM ".$db->prefix("tplfile")." WHERE tpl_tplset='".addslashes($tplset_to)."' AND ($whr_append) AND tpl_file='".addslashes($row['tpl_file'])."' AND tpl_refid='".addslashes($row['tpl_refid'])."'" ) ;
  79. if( ! $db->getRowsNum( $drs ) ) {
  80. // INSERT mode
  81. $sql = "INSERT INTO ".$db->prefix("tplfile")." SET tpl_refid='".addslashes($row['tpl_refid'])."',tpl_desc='".addslashes($row['tpl_desc'])."',tpl_lastmodified='".addslashes($lastmodified)."',tpl_type='".addslashes($row['tpl_type'])."',tpl_tplset='".addslashes($tplset_to)."',tpl_file='".addslashes($row['tpl_file'])."',tpl_module='".addslashes($row['tpl_module'])."'" ;
  82. $db->query( $sql ) ;
  83. $tpl_id = $db->getInsertId() ;
  84. $db->query( "INSERT INTO ".$db->prefix("tplsource")." SET tpl_id='$tpl_id', tpl_source='".addslashes($tpl_source)."'" ) ;
  85. altsys_template_touch( $tpl_id ) ;
  86. } else {
  87. while( list( $tpl_id ) = $db->fetchRow( $drs ) ) {
  88. // UPDATE mode
  89. $db->query( "UPDATE ".$db->prefix("tplfile")." SET tpl_lastmodified='".addslashes($lastmodified)."' WHERE tpl_id='$tpl_id'" ) ;
  90. $db->query( "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".addslashes($tpl_source)."' WHERE tpl_id='$tpl_id'" ) ;
  91. altsys_template_touch( $tpl_id ) ;
  92. }
  93. }
  94. }
  95. }
  96. function tplsadmin_get_basefilepath( $dirname , $type , $tpl_file )
  97. {
  98. // module instance
  99. $path = $basefilepath = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/'.($type=='block'?'blocks/':'').$tpl_file ;
  100. if( defined( 'ALTSYS_TPLSADMIN_BASEPATH' ) ) {
  101. // Special hook
  102. $path = ALTSYS_TPLSADMIN_BASEPATH.'/'.substr( $tpl_file , strlen( $dirname ) + 1 ) ;
  103. } else if( ! file_exists( $basefilepath ) && file_exists( XOOPS_ROOT_PATH.'/modules/'.$dirname.'/mytrustdirname.php' ) ) {
  104. // D3 module base
  105. include XOOPS_ROOT_PATH.'/modules/'.$dirname.'/mytrustdirname.php' ;
  106. if( ! empty( $mytrustdirname ) ) {
  107. $mid_path = $mytrustdirname == 'altsys' ? '/libs/' : '/modules/' ;
  108. $path = XOOPS_TRUST_PATH.$mid_path.$mytrustdirname.'/templates/'.($type=='block'?'blocks/':'').substr( $tpl_file , strlen( $dirname ) + 1 ) ;
  109. //new for xcck etc.other trust_module
  110. if (! file_exists( $path )){
  111. $path = XOOPS_TRUST_PATH.$mid_path.$mytrustdirname.'/templates/'.($type=='block'?'blocks/':'').$tpl_file ;
  112. }
  113. }
  114. }
  115. return $path ;
  116. }
  117. ?>