PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/public/sspdir/app/controllers/install_controller.php

https://github.com/matejudo/prospekta
PHP | 520 lines | 470 code | 25 blank | 25 comment | 52 complexity | bbe93b01edead47e2a3ef1e0b2e20232 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. class InstallController extends AppController
  3. {
  4. var $name = 'Install';
  5. var $uses = array();
  6. var $helpers = array('Html', 'Javascript', 'Director');
  7. var $components = array('Director', 'Pigeon', 'Cookie', 'Session');
  8. function beforeFilter() {
  9. if ($this->Session->read('Language')) {
  10. Configure::write('Config.language', $this->Session->read('Language'));
  11. }
  12. $this->pageTitle = __("Installing", true);
  13. $this->set('config_path', ROOT . DS . 'config');
  14. $this->set('controller', $this);
  15. $this->layout = 'simple';
  16. }
  17. ////
  18. // Install landing page
  19. ////
  20. function index() {
  21. $lang_folder = new Folder(ROOT . DS . 'locale');
  22. $langs = $lang_folder->ls(true, false);
  23. $actual = array();
  24. foreach ($langs[0] as $l) {
  25. if (($l != 'eng' && $l != 'SAMPLE') && file_exists(ROOT . DS . 'locale' . DS . $l . DS . 'welcome.po')) {
  26. $actual[] = $l;
  27. }
  28. }
  29. if (empty($actual)) {
  30. $this->Session->write('Language', 'eng');
  31. $this->redirect('/install/license');
  32. exit;
  33. }
  34. $this->set('langs', $actual);
  35. }
  36. function lang($l) {
  37. $this->Session->write('Language', $l);
  38. $this->redirect('/install/license');
  39. exit;
  40. }
  41. ////
  42. // Install license
  43. ////
  44. function license() {}
  45. ////
  46. // Activation
  47. ////
  48. function activate() {
  49. $this->Session->write('activation', null);
  50. }
  51. ////
  52. // Perform server check
  53. ////
  54. function test() {
  55. if ($this->data) {
  56. $php = version_compare(PHP_VERSION, '4.3.7', 'ge');
  57. extension_loaded('mysql') ? $mysql = true : $mysql = extension_loaded('mysqli');
  58. if (ini_get('safe_mode') == false || ini_get('safe_mode') == '' || strtolower(ini_get('safe_mode')) == 'off') {
  59. $no_safe_mode = true;
  60. } else {
  61. $no_safe_mode = false;
  62. }
  63. if ($php && $mysql && $no_safe_mode) {
  64. $this->set('success', true);
  65. } else {
  66. $this->set('success', false);
  67. $this->set('php', $php);
  68. $this->set('mysql', $mysql);
  69. $this->set('no_safe_mode', $no_safe_mode);
  70. }
  71. } else {
  72. $this->redirect('/install');
  73. exit;
  74. }
  75. }
  76. ////
  77. // Enter database details and create config file
  78. ////
  79. function database() {
  80. $this->set('db_select_error', false);
  81. $this->set('connection_error', false);
  82. $this->set('conf_exists', false);
  83. $filename = ROOT . DS . 'config' . DS . 'conf.php';
  84. if ($this->data) {
  85. if (file_exists($filename)) {
  86. $this->set('conf_exists', true);
  87. } else {
  88. $details = $this->data['db'];
  89. $server = trim($details['server']);
  90. $name = trim($details['name']);
  91. $user = trim($details['user']);
  92. $pass = trim($details['pass']);
  93. $prefix = trim($details['prefix']);
  94. if (strpos($server, ':') !== false) {
  95. $bits = explode(':', $server);
  96. $server = $bits[0];
  97. $extra = "ini_set('mysql.default_socket', '{$bits[1]}');";
  98. ini_set('mysql.default_socket', $bits[1]);
  99. }
  100. $link = @mysql_connect($server, $user, $pass);
  101. if (!$link) {
  102. $this->set('connection_error', true);
  103. $this->set('mysql_error', mysql_error());
  104. } elseif (@!mysql_select_db($details['name'])) {
  105. $this->set('db_select_error', true);
  106. $this->set('mysql_error', mysql_error());
  107. } else {
  108. $fill = "<?php\n\n\t";
  109. $fill .= '$host = \''. $server ."';\n\t";
  110. $fill .= '$db = \''. $name ."';\n\t";
  111. $fill .= '$user = \''. $user ."';\n\t";
  112. $fill .= '$pass = \''. $pass ."';\n\n\t";
  113. $fill .= '$pre = \''. $prefix ."';\n\n";
  114. if (isset($extra)) {
  115. $fill .= "\t$extra\n\n";
  116. }
  117. $fill .= '?>';
  118. $handle = fopen($filename, 'w+');
  119. if (fwrite($handle, $fill) == false) {
  120. $this->set('write_error', true);
  121. } else {
  122. $this->redirect('/install/register');
  123. exit;
  124. }
  125. }
  126. }
  127. } else {
  128. if (file_exists($filename)) {
  129. $this->set('conf_exists', true);
  130. }
  131. }
  132. }
  133. ////
  134. // Create the first user
  135. ////
  136. function register() {}
  137. ////
  138. // Install it already!
  139. ////
  140. function finish() {
  141. if ($this->data) {
  142. mysql_connect(DIR_DB_HOST, DIR_DB_USER, DIR_DB_PASSWORD);
  143. mysql_select_db(DIR_DB);
  144. $atbl = DIR_DB_PRE . 'albums';
  145. $itbl = DIR_DB_PRE . 'images';
  146. $dtbl = DIR_DB_PRE . 'dynamic';
  147. $dltbl = DIR_DB_PRE . 'dynamic_links';
  148. $stbl = DIR_DB_PRE . 'slideshows';
  149. $utbl = DIR_DB_PRE . 'usrs';
  150. $acctbl = DIR_DB_PRE . 'account';
  151. $this->set('error', '');
  152. $queries = array(
  153. "CREATE TABLE $atbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(100), description BLOB, path VARCHAR(50), tn TINYINT(1) NOT NULL DEFAULT '0', aTn VARCHAR(150), active TINYINT(1) NOT NULL DEFAULT '0', audioFile VARCHAR(100) DEFAULT NULL, audioCap VARCHAR(200) DEFAULT NULL, displayOrder INT(4) DEFAULT '999', target TINYINT(1) NOT NULL DEFAULT '0', images_count INT NOT NULL DEFAULT 0, sort_type VARCHAR(255) NOT NULL DEFAULT 'manual', title_template VARCHAR(255), link_template TEXT, caption_template TEXT, modified DATETIME DEFAULT NULL, created DATETIME DEFAULT NULL, updated_by INT(11), created_by INT(11))",
  154. "CREATE TABLE $itbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), aid INT, title VARCHAR(255), src VARCHAR(255), caption TEXT, link TEXT, active TINYINT(1) NOT NULL DEFAULT '1', seq INT(4) NOT NULL DEFAULT '999', pause INT(4) NOT NULL DEFAULT '0', target TINYINT(1) NOT NULL DEFAULT '0', modified DATETIME DEFAULT NULL, created DATETIME DEFAULT NULL, updated_by INT(11), created_by INT(11), anchor VARCHAR(255) DEFAULT NULL)",
  155. "CREATE TABLE $utbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), usr VARCHAR(50), pwd VARCHAR(50), email VARCHAR(255), perms INT(2) NOT NULL DEFAULT '1', modified DATETIME DEFAULT NULL, created DATETIME DEFAULT NULL, news TINYINT(1) DEFAULT 0, help TINYINT(1) DEFAULT 0)",
  156. "CREATE TABLE $dtbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(100), description TEXT, modified DATETIME DEFAULT NULL, created DATETIME DEFAULT NULL, main TINYINT(1) DEFAULT 0, sort_type VARCHAR(255) NOT NULL DEFAULT 'manual', updated_by INT(11), created_by INT(11))",
  157. "CREATE TABLE $dltbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), did INT, aid INT, display INT DEFAULT '800')",
  158. "CREATE TABLE $stbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(255), url VARCHAR(255))",
  159. "INSERT INTO $utbl (id, usr, email, pwd, perms, created, modified) VALUES (NULL, '" . $this->data['User']['usr'] . "', '" . $this->data['User']['email'] . "', '" . $this->data['User']['pwd'] . "', 4, NOW(), NOW())",
  160. "CREATE TABLE $acctbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), externals TINYINT(1), internals TINYINT(1), version VARCHAR(255), activation_key VARCHAR(255), last_check DATETIME, theme VARCHAR(255) DEFAULT '/app/webroot/styles/default/default.css', lang VARCHAR(255) DEFAULT 'eng')",
  161. "INSERT INTO $acctbl (id, externals, internals, version, activation_key, last_check, lang) VALUES (NULL, 1, 1, '" . DIR_VERSION . "', '" . $this->Session->read('activation') . "', '" . date('Y-m-d H:i:s', strtotime('+2 weeks')) . "', NULL)",
  162. "INSERT INTO $dtbl(name, description, main, created, modified) VALUES('All albums', 'This gallery contains all published albums.', 1, NOW(), NOW())"
  163. );
  164. foreach($queries as $query) {
  165. if (!mysql_query($query)) {
  166. $this->set('error', mysql_error());
  167. $this->render();
  168. exit;
  169. }
  170. }
  171. $this->_clean(CACHE . DS . 'models');
  172. } else {
  173. $this->redirect('/install');
  174. }
  175. }
  176. ////
  177. // Perform upgrade
  178. ////
  179. function upgrade($step = 1) {
  180. define('CUR_USER_ID', $this->Session->read('User.id'));
  181. // Make sure they have the appropriate version of PHP, as 1.0.8+ now requires 4.3.2+
  182. if (version_compare(PHP_VERSION, '4.3.7', '>=')) {
  183. if (function_exists('set_time_limit')) {
  184. set_time_limit(0);
  185. }
  186. $this->set('error', false);
  187. $this->set('step', $step);
  188. if ($step != 1) {
  189. mysql_connect(DIR_DB_HOST, DIR_DB_USER, DIR_DB_PASSWORD);
  190. mysql_select_db(DIR_DB);
  191. $version = DIR_VERSION;
  192. $atbl = DIR_DB_PRE . 'albums';
  193. $itbl = DIR_DB_PRE . 'images';
  194. $dtbl = DIR_DB_PRE . 'dynamic';
  195. $dltbl = DIR_DB_PRE . 'dynamic_links';
  196. $stbl = DIR_DB_PRE . 'slideshows';
  197. $utbl = DIR_DB_PRE . 'usrs';
  198. $acctbl = DIR_DB_PRE . 'account';
  199. }
  200. switch($step) {
  201. case(2):
  202. @mysql_query("CREATE TABLE $acctbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), externals TINYINT(1), internals TINYINT(1), process_specs VARCHAR(255), thumb_specs VARCHAR(255), version VARCHAR(255)) ");
  203. $check = mysql_query("SELECT * FROM $acctbl");
  204. if (mysql_num_rows($check) == 0):
  205. @mysql_query("INSERT INTO $acctbl VALUES (NULL, 1, 1, '', '', '$version')");
  206. endif;
  207. // 1.0.0
  208. @mysql_query("ALTER TABLE $atbl CHANGE displayOrder displayOrder INT(4) NOT NULL DEFAULT '999'");
  209. @mysql_query("ALTER TABLE $itbl CHANGE seq seq INT(4) NOT NULL DEFAULT '999'");
  210. @mysql_query("ALTER TABLE $itbl ADD pause INT(4) NOT NULL DEFAULT '0'");
  211. @mysql_query("ALTER TABLE $itbl ADD title VARCHAR(255)");
  212. @mysql_query("ALTER TABLE $itbl ADD target TINYINT(1) NOT NULL DEFAULT '0'");
  213. @mysql_query("ALTER TABLE $utbl ADD perms TINYINT(1) NOT NULL DEFAULT '1'");
  214. @mysql_query("CREATE TABLE $stbl(id INT AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(255), url VARCHAR(255))");
  215. @mysql_query("UPDATE $utbl SET perms = 4 WHERE id = {$_SESSION['loginID']}");
  216. // 1.0.3
  217. @mysql_query("ALTER TABLE $atbl ADD show_headers INT(1) NOT NULL DEFAULT '1'");
  218. @mysql_query("ALTER TABLE $atbl ADD process_specs VARCHAR(255)");
  219. @mysql_query("ALTER TABLE $atbl ADD thumb_specs VARCHAR(255)");
  220. @mysql_query("UPDATE $atbl SET show_headers = 1");
  221. @mysql_query("ALTER TABLE $itbl CHANGE src src VARCHAR(255)");
  222. // 1.0.5
  223. @mysql_query("UPDATE $atbl SET thumb_specs = CONCAT(thumb_specs, 'x0') WHERE thumb_specs IS NOT NULL AND thumb_specs <> ''");
  224. // 1.0.6
  225. @mysql_query("UPDATE $atbl SET process_specs = CONCAT(process_specs, 'x0') WHERE thumb_specs IS NOT NULL AND thumb_specs <> ''");
  226. // 1.0.7
  227. @mysql_query("ALTER TABLE $atbl ADD updated_on TIMESTAMP");
  228. @mysql_query("ALTER TABLE $atbl ADD created_on TIMESTAMP");
  229. @mysql_query("UPDATE $atbl SET created_on = NOW() WHERE created_on IS NULL OR created_on = '' OR created_on = '0000-00-00 00:00'");
  230. @mysql_query("ALTER TABLE $itbl ADD updated_on TIMESTAMP");
  231. @mysql_query("ALTER TABLE $itbl ADD created_on TIMESTAMP");
  232. @mysql_query("UPDATE $itbl SET created_on = NOW() WHERE created_on IS NULL OR created_on = '' or created_on = '0000-00-00 00:00'");
  233. // 1.0.8
  234. @mysql_query("ALTER TABLE $utbl CHANGE perms perms INT(2) NOT NULL DEFAULT 1");
  235. @mysql_query("ALTER TABLE $atbl ADD images_count INT NOT NULL DEFAULT 0");
  236. @mysql_query("ALTER TABLE $atbl ADD sort_type VARCHAR(255) NOT NULL DEFAULT 'manual'");
  237. // 1.0.9
  238. @mysql_query("ALTER TABLE $atbl ADD title_template VARCHAR(255)");
  239. @mysql_query("ALTER TABLE $atbl ADD link_template INT(2)");
  240. @mysql_query("ALTER TABLE $atbl ADD caption_template TEXT");
  241. @mysql_query("ALTER TABLE $utbl ADD email VARCHAR(255)");
  242. // 1.1
  243. @mysql_query("ALTER TABLE $dtbl ADD description TEXT");
  244. @mysql_query("ALTER TABLE $dtbl ADD modified TIMESTAMP");
  245. @mysql_query("ALTER TABLE $dtbl ADD created TIMESTAMP");
  246. @mysql_query("UPDATE $dtbl SET modified = NOW(), created = NOW() WHERE created_on IS NULL OR created_on = '' or created_on = '0000-00-00 00:00'");
  247. @mysql_query("ALTER TABLE $dtbl ADD main TINYINT(1) DEFAULT 0");
  248. @mysql_query("UPDATE $dtbl SET `main` = 0 WHERE `main` <> 1");
  249. $test = mysql_query("SELECT * FROM $dtbl WHERE `main` = 1");
  250. if (mysql_num_rows($test) != 1) {
  251. @mysql_query("INSERT INTO $dtbl(name, description, main, created, modified) VALUES('All albums', 'This gallery contains all published albums.', 1, NOW(), NOW())");
  252. $new_id = mysql_insert_id();
  253. $inner_r = mysql_query("SELECT id, displayOrder FROM $atbl WHERE active = 1");
  254. if (mysql_num_rows($inner_r) > 0) {
  255. while ($r = mysql_fetch_array($inner_r)) {
  256. mysql_query("INSERT INTO $dltbl(did, aid, display) VALUES($new_id, {$r['id']}, {$r['displayOrder']})");
  257. }
  258. }
  259. }
  260. @mysql_query("ALTER TABLE $atbl ADD created_by INT(11)");
  261. @mysql_query("ALTER TABLE $atbl ADD updated_by INT(11)");
  262. @mysql_query("ALTER TABLE $itbl ADD created_by INT(11)");
  263. @mysql_query("ALTER TABLE $itbl ADD updated_by INT(11)");
  264. @mysql_query("ALTER TABLE $dtbl ADD created_by INT(11)");
  265. @mysql_query("ALTER TABLE $dtbl ADD updated_by INT(11)");
  266. $res = mysql_query("SELECT * FROM $utbl ORDER BY perms DESC LIMIT 1");
  267. if (mysql_num_rows($res) != 0) {
  268. $u = mysql_fetch_row($res); $id = $u[0];
  269. @mysql_query("UPDATE $atbl SET created_by = $id, updated_by = $id WHERE created_by IS NULL");
  270. @mysql_query("UPDATE $dtbl SET created_by = $id, updated_by = $id WHERE created_by IS NULL");
  271. @mysql_query("UPDATE $itbl SET created_by = $id, updated_by = $id WHERE created_by IS NULL");
  272. }
  273. @mysql_query("ALTER TABLE $atbl CHANGE created_on created TIMESTAMP");
  274. @mysql_query("ALTER TABLE $itbl CHANGE created_on created TIMESTAMP");
  275. @mysql_query("ALTER TABLE $dtbl CHANGE created_on created TIMESTAMP");
  276. @mysql_query("ALTER TABLE $atbl CHANGE updated_on modified TIMESTAMP");
  277. @mysql_query("ALTER TABLE $itbl CHANGE updated_on modified TIMESTAMP");
  278. @mysql_query("ALTER TABLE $dtbl CHANGE updated_on modified TIMESTAMP");
  279. @mysql_query("ALTER TABLE $atbl DROP created_on");
  280. @mysql_query("ALTER TABLE $itbl DROP created_on");
  281. @mysql_query("ALTER TABLE $dtbl DROP created_on");
  282. @mysql_query("ALTER TABLE $atbl DROP updated_on");
  283. @mysql_query("ALTER TABLE $itbl DROP updated_on");
  284. @mysql_query("ALTER TABLE $dtbl DROP updated_on");
  285. @mysql_query("ALTER TABLE $dtbl CHANGE main main TINYINT(1) DEFAULT 0");
  286. @mysql_query("ALTER TABLE $acctbl ADD activation_key VARCHAR(255)");
  287. @mysql_query("ALTER TABLE $acctbl ADD last_check DATETIME");
  288. if (@mysql_query("ALTER TABLE $acctbl ADD theme VARCHAR(255) default '/app/webroot/styles/default/default.css'")) {
  289. @mysql_query("UPDATE $acctbl SET theme = '/app/webroot/styles/default/default.css' WHERE theme IS NULL or theme =''");
  290. }
  291. if (@mysql_query("ALTER TABLE $acctbl ADD lang VARCHAR(255) default 'eng'")) {
  292. @mysql_query("UPDATE $acctbl SET lang = 'eng'");
  293. }
  294. @mysql_query("UPDATE $acctbl SET lang = 'eng' WHERE lang = 'en'");
  295. // New link templates
  296. @mysql_query("ALTER TABLE $atbl CHANGE link_template link_template TEXT");
  297. $full = DIR_HOST . '/popup.php?src=[full_hr_url]&w=[img_w]&h=[img_h]&title=[img_src]';
  298. $template = mysql_real_escape_string("javascript:if (window.NewWindow) { NewWindow.close(); }; NewWindow=window.open('$full','myWindow','width=[img_w],height=[img_h],toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,titlebar=no');NewWindow.focus(); void(0);");
  299. @mysql_query("UPDATE $atbl SET link_template = '{$template}__~~__0' WHERE link_template = '3'");
  300. $template = '[full_hr_url]';
  301. @mysql_query("UPDATE $atbl SET link_template = '{$template}__~~__1' WHERE link_template = '2'");
  302. @mysql_query("UPDATE $atbl SET link_template = '{$template}__~~__0' WHERE link_template = '1'");
  303. @mysql_query("UPDATE $itbl SET link = REPLACE(link, '/hr/', '/lg/')");
  304. if (@mysql_query("ALTER TABLE $dtbl ADD sort_type VARCHAR(255) NOT NULL DEFAULT 'manual'")) {
  305. @mysql_query("UPDATE $atbl SET sort_type = 'manual");
  306. }
  307. if (@mysql_query("ALTER TABLE $utbl ADD created TIMESTAMP")) {
  308. @mysql_query("ALTER TABLE $utbl ADD modified TIMESTAMP");
  309. $res = mysql_query("SELECT created FROM $atbl ORDER BY created LIMIT 1");
  310. if (mysql_num_rows($res) == 1) {
  311. $u = mysql_fetch_row($res);
  312. @mysql_query("UPDATE $utbl SET created = '$u[0]', modified = '$u[0]'");
  313. } else {
  314. @mysql_query("UPDATE $utbl SET created = NOW(), modified = NOW()");
  315. }
  316. }
  317. @mysql_query("ALTER TABLE $atbl CHANGE created created DATETIME DEFAULT NULL");
  318. @mysql_query("ALTER TABLE $itbl CHANGE created created DATETIME DEFAULT NULL");
  319. @mysql_query("ALTER TABLE $dtbl CHANGE created created DATETIME DEFAULT NULL");
  320. @mysql_query("ALTER TABLE $atbl CHANGE modified modified DATETIME DEFAULT NULL");
  321. @mysql_query("ALTER TABLE $itbl CHANGE modified modified DATETIME DEFAULT NULL");
  322. @mysql_query("ALTER TABLE $dtbl CHANGE modified modified DATETIME DEFAULT NULL");
  323. @mysql_query("ALTER TABLE $utbl CHANGE created created DATETIME DEFAULT NULL");
  324. @mysql_query("ALTER TABLE $utbl CHANGE modified modified DATETIME DEFAULT NULL");
  325. @mysql_query("ALTER TABLE $utbl DROP avatar");
  326. @mysql_query("ALTER TABLE $atbl DROP process_specs");
  327. @mysql_query("ALTER TABLE $atbl DROP thumb_specs");
  328. @mysql_query("ALTER TABLE $acctbl DROP process_specs");
  329. @mysql_query("ALTER TABLE $acctbl DROP thumb_specs");
  330. @mysql_query("ALTER TABLE $utbl ADD news TINYINT(1) DEFAULT 1");
  331. @mysql_query("ALTER TABLE $utbl ADD help TINYINT(1) DEFAULT 1");
  332. @mysql_query("UPDATE $utbl SET news = 1, help = 1 WHERE news IS NULL");
  333. if (@mysql_query("ALTER TABLE $itbl ADD anchor VARCHAR(255) DEFAULT NULL")) {
  334. $targets = glob(ALBUMS . DS . '*' . DS . 'cache' . DS . '*');
  335. foreach ($targets as $t) {
  336. @unlink($t);
  337. }
  338. }
  339. @mysql_query("DELETE FROM $dtbl WHERE name = '' OR name IS NULL");
  340. @mysql_query("DELETE FROM $itbl WHERE aid IS NULL");
  341. break;
  342. case(3):
  343. // Move stuff around
  344. $targets = glob(ALBUMS . DS . '*');
  345. foreach ($targets as $t) {
  346. if (basename($t) != 'imports' && basename($t) != 'avatars') {
  347. $hr = $t . DS . 'hr';
  348. $lg = $t . DS . 'lg';
  349. $tn = $t . DS . 'tn';
  350. $dir = $t . DS . 'director';
  351. $cache = $t . DS . 'cache';
  352. if (is_dir($t . DS . 'hr')) {
  353. foreach (glob($hr . DS . '*') as $h) {
  354. rename($h, $lg . DS . basename($h));
  355. }
  356. $this->Director->rmdirr($hr);
  357. }
  358. $this->Director->rmdirr($tn);
  359. $this->Director->rmdirr($dir);
  360. new Folder($cache, true);
  361. }
  362. }
  363. // Custom thumbs
  364. $targets = glob(THUMBS . DS . 'album-*');
  365. if (!empty($targets)) {
  366. loadModel('Image');
  367. $this->Image =& new Image();
  368. foreach ($targets as $t) {
  369. $file = basename($t);
  370. preg_match('/^album-([0-9]+)\..*/', $file, $matches);
  371. $id = $matches[1];
  372. $album = $this->Image->Album->read(null, $id);
  373. rename($t, ALBUMS . DS . $album['Album']['path'] . DS . 'lg' . DS . $file);
  374. $this->Image->create();
  375. $data['Image']['aid'] = $id;
  376. $data['Image']['src'] = $file;
  377. $data['Image']['created_by'] = $data['Image']['updated_by'] = CUR_USER_ID;
  378. $data['Image']['active'] = 0;
  379. $this->Image->save($data);
  380. }
  381. }
  382. $this->Director->rmdirr(THUMBS);
  383. // Clear cache if not upgraded to 1.1.4 yet
  384. $check = mysql_fetch_row(mysql_query("SELECT version FROM $acctbl LIMIT 1"));
  385. $version = $check[0];
  386. if (strlen($version) == 3) {
  387. $version .= '.0';
  388. }
  389. if (version_compare($version, '1.1.4', '<')) {
  390. $clear = glob(ALBUMS . DS . '*' . DS . 'cache' . DS . '*');
  391. if (!empty($clear)) {
  392. foreach($clear as $crusty) {
  393. @unlink($crusty);
  394. }
  395. }
  396. }
  397. break;
  398. case(4):
  399. // Strip abs path from album thumbs
  400. $results = mysql_query("SELECT * FROM $atbl WHERE aTn <> '' AND aTn IS NOT NULL");
  401. while ($r = mysql_fetch_array($results)) {
  402. $tn = basename($r['aTn']);
  403. if (strpos($r['aTn'], '/') !== false) {
  404. mysql_query("UPDATE $atbl SET aTn = '$tn' WHERE id = {$r['id']}");
  405. }
  406. }
  407. // Clean XML cache and model cache
  408. $this->_clean(XML_CACHE);
  409. $this->_clean(CACHE . DS . 'models');
  410. $this->_clean(CACHE . DS . 'director');
  411. // Create avatars folder if it does not exist
  412. uses('Folder');
  413. new Folder(AVATARS, true);
  414. // Avatar cleanup
  415. $avs = glob(AVATARS . DS . '*');
  416. if (!empty($avs)) {
  417. foreach($avs as $a) {
  418. $file = basename($a);
  419. if (strpos($file, '.') === false) {
  420. $specs = getimagesize($a);
  421. switch(strtolower($specs['mime'])) {
  422. case 'image/jpeg':
  423. $new = $file . '.jpg';
  424. break;
  425. case 'image/gif':
  426. $new = $file . '.gif';
  427. break;
  428. default:
  429. $new = $file . '.png';
  430. break;
  431. }
  432. rename($a, AVATARS . DS . $new);
  433. }
  434. }
  435. }
  436. $this->Cookie->del('Login');
  437. $this->Cookie->del('Pass');
  438. $this->Session->delete('User');
  439. @mysql_query("UPDATE $acctbl SET version = '$version'");
  440. break;
  441. }
  442. } else {
  443. $this->set('error', true);
  444. }
  445. }
  446. ////
  447. // Clean a directory
  448. ////
  449. function _clean($dir) {
  450. if ($dh = @opendir($dir)) {
  451. while (($obj = readdir($dh))) {
  452. if ($obj=='.' || $obj=='..' || $obj =='.svn') continue;
  453. if (!@unlink($dir.'/'.$obj)) $this->Director->rmdirr($dir.'/'.$obj);
  454. }
  455. }
  456. }
  457. }