source: extensions/File_Uploader/install/functions.inc.php @ 19875

Last change on this file since 19875 was 19875, checked in by julien1311, 11 years ago

[file_uploader] lots of bug fixes

  • Property svn:eol-style set to LF
File size: 2.0 KB
Line 
1<?php
2function file_uploader_install($config) {
3        $query = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("file_uploader" ,"'.pwg_db_real_escape_string(serialize($config)).'", "File Uploader plugin parameters");';
4        pwg_query($query);
5}
6
7function file_uploader_update_db($file_uploader_default_config) {
8        global $conf;
9       
10        $config = array();
11       
12        if (isset($conf['file_uploader'])) {
13                $conf_file_uploader = unserialize($conf['file_uploader']);
14                foreach ($file_uploader_default_config as $key => $value) {
15                        if (isset($conf_file_uploader[$key]))
16                                $config[$key] = $conf_file_uploader[$key];
17                        else
18                                $config[$key] = $file_uploader_default_config[$key];
19                }
20                file_uploader_delete_conf("file_uploader");
21                file_uploader_install($config);
22        } else {
23                file_uploader_install($file_uploader_default_config);
24        }
25}
26
27function file_uploader_delete_conf($where) {
28        $query = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE (param="'.$where.'");';
29        pwg_query($query);
30}
31
32function file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir, $file_uploader_galleries_folder_name) {
33        //If the directory does not exist, we create it
34        if (!file_exists($file_uploader_galleries_dir))
35                if(!mkdir($file_uploader_galleries_dir))
36                        array_push($page['errors'], l10n('Unable to create folder ').$file_uploader_galleries_dir);
37                //If the physical category is not in database, we add it
38                else if (pwg_db_num_rows(pwg_query('SELECT id FROM '.CATEGORIES_TABLE.' WHERE dir = "'.$file_uploader_galleries_folder.'";')) == 0){
39                        $next_id = pwg_db_nextval('id', CATEGORIES_TABLE);
40                        $category_rank = pwg_db_fetch_assoc(pwg_query('SELECT MAX(rank) FROM '.CATEGORIES_TABLE.';'));
41                        $category_rank = $category_rank['MAX(rank)'] + 1;
42                        pwg_query('INSERT INTO '.CATEGORIES_TABLE.' (id, name, comment, dir, rank, status, visible, uppercats, global_rank, site_id) VALUES ('.$next_id.', "'.$file_uploader_galleries_folder_name.'", "Created by the File Uploader plugin", "'.$file_uploader_galleries_folder.'", '.$category_rank.', "private", "true", "'.$next_id.'", '.$category_rank.', 1);');
43                }
44}
45?>
Note: See TracBrowser for help on using the repository browser.