PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/textpattern/lib/txplib_update.php

https://bitbucket.org/Manfre/xpattern
PHP | 126 lines | 102 code | 10 blank | 14 comment | 25 complexity | 0b1d92ed32f1ffefb5ccc04845263a6e MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. $HeadURL: http://textpattern.googlecode.com/svn/development/4.0/textpattern/lib/txplib_update.php $
  4. $LastChangedRevision: 2812 $
  5. */
  6. //-------------------------------------------------------------
  7. function install_language_from_file($lang)
  8. {
  9. $lang_file = txpath.'/lang/'.$lang.'.txt';
  10. # first attempt with local file
  11. if (is_file($lang_file) && is_readable($lang_file))
  12. {
  13. $lang_file = txpath.'/lang/'.$lang.'.txt';
  14. if (!is_file($lang_file) || !is_readable($lang_file)) return;
  15. $file = @fopen($lang_file, "r");
  16. if ($file) {
  17. $lastmod = @filemtime($lang_file);
  18. $lastmod = date('YmdHis',$lastmod);
  19. $data = array();
  20. $event = '';
  21. while (!feof($file)) {
  22. $line = fgets($file, 4096);
  23. # any line starting with #, not followed by @ is a simple comment
  24. if($line[0]=='#' && $line[1]!='@' && $line[1]!='#') continue;
  25. # if available use the lastmod time from the file
  26. if (strpos($line,'#@version') === 0)
  27. { # Looks like: "#@version id;unixtimestamp"
  28. @list($fversion,$ftime) = explode(';',trim(substr($line,strpos($line,' ',1))));
  29. $lastmod = date("YmdHis",min($ftime, time()));
  30. }
  31. # each language section should be prefixed by #@
  32. if($line[0]=='#' && $line[1]=='@')
  33. {
  34. if (!empty($data)){
  35. foreach ($data as $name => $value)
  36. {
  37. $value = addslashes($value);
  38. $exists = mysql_query('SELECT name, lastmod FROM `'.PFX."txp_lang` WHERE `lang`='".$lang."' AND `name`='$name' AND `event`='$event'");
  39. if ($exists) $exists = mysql_fetch_row($exists);
  40. if ($exists[1])
  41. {
  42. mysql_query("UPDATE `".PFX."txp_lang` SET `lastmod`='$lastmod', `data`='$value' WHERE `lang`='".$lang."' AND `name`='$name' AND `event`='$event'");
  43. echo mysql_error();
  44. } else
  45. mysql_query("INSERT DELAYED INTO `".PFX."txp_lang` SET `lang`='".$lang."', `name`='$name', `lastmod`='$lastmod', `event`='$event', `data`='$value'");
  46. echo mysql_error();
  47. }
  48. }
  49. # reset
  50. $data = array();
  51. $event = substr($line,2, (strlen($line)-2));
  52. $event = rtrim($event);
  53. continue;
  54. }
  55. @list($name,$val) = explode(' => ',trim($line));
  56. $data[$name] = $val;
  57. }
  58. # remember to add the last one
  59. if (!empty($data)){
  60. foreach ($data as $name => $value)
  61. {
  62. mysql_query("INSERT DELAYED INTO `".PFX."txp_lang` SET `lang`='".$lang."', `name`='$name', `lastmod`='$lastmod', `event`='$event', `data`='$value'");
  63. }
  64. }
  65. mysql_query("DELETE FROM `".PFX."txp_lang` WHERE `lang`='".$lang."' AND `lastmod`>$lastmod");
  66. @fclose($filename);
  67. #delete empty fields if any
  68. mysql_query("DELETE FROM `".PFX."txp_lang` WHERE `data`=''");
  69. mysql_query("FLUSH TABLE `".PFX."txp_lang`");
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. //-------------------------------------------------------------
  76. # check for updates through xml-rpc
  77. function checkUpdates()
  78. {
  79. require_once txpath.'/lib/IXRClass.php';
  80. $client = new IXR_Client('http://rpc.textpattern.com');
  81. $uid = safe_field('val','txp_prefs',"name='blog_uid'");
  82. if (!$client->query('tups.getTXPVersion',$uid))
  83. {
  84. return gTxt('problem_connecting_rpc_server');
  85. }else{
  86. $msg = array();
  87. $response = $client->getResponse();
  88. if (is_array($response))
  89. {
  90. ksort($response);
  91. $version = safe_field('val','txp_prefs',"name='version'");
  92. $lversion = explode('.',$version);
  93. $branch = substr($version,0,3);
  94. foreach ($response as $key => $val)
  95. {
  96. $rversion = explode('.',$val);
  97. if ($key == 'txp_current_version_'.$branch)
  98. {
  99. if (isset($lversion[2]) && isset($rversion[2]) && (intval($rversion[2])>intval($lversion[2])))
  100. {
  101. $msg[]= gTxt('updated_branch_version_available');
  102. }else{
  103. $msg[]= gTxt('your_branch_is_updated');
  104. }
  105. }else{
  106. if (intval($rversion[0])>intval($lversion[0]) || intval($rversion[1])>intval($lversion[1]))
  107. {
  108. $msg[]= gTxt('new_textpattern_version_available').': '.$val;
  109. }
  110. }
  111. }
  112. return $msg;
  113. }
  114. }
  115. }
  116. ?>