1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /* |
---|
5 | * restore verso to its original categories |
---|
6 | * criterias : |
---|
7 | * - verso 'versos' cat only => restore verso to original categories |
---|
8 | * - otherwise nothing is changed |
---|
9 | * |
---|
10 | * $item = array('verso_id', 'categories'); |
---|
11 | */ |
---|
12 | function back2front_restaure_categories($item) |
---|
13 | { |
---|
14 | global $conf; |
---|
15 | |
---|
16 | /* catch current verso categories */ |
---|
17 | $query = 'SELECT DISTINCT category_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$item['verso_id'].';'; |
---|
18 | $item['current_verso_cats'] = array_from_query($query, 'category_id'); |
---|
19 | |
---|
20 | /* if verso 'versos' cat only */ |
---|
21 | if (count($item['current_verso_cats']) == 1 && $item['current_verso_cats'][0] == $conf['back2front']['versos_cat']) |
---|
22 | { |
---|
23 | foreach (explode(',',$item['categories']) as $cat) |
---|
24 | { |
---|
25 | $datas[] = array( |
---|
26 | 'image_id' => $item['verso_id'], |
---|
27 | 'category_id' => $cat, |
---|
28 | ); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | if (isset($datas)) |
---|
33 | { |
---|
34 | mass_inserts( |
---|
35 | IMAGE_CATEGORY_TABLE, |
---|
36 | array('image_id', 'category_id'), |
---|
37 | $datas |
---|
38 | ); |
---|
39 | } |
---|
40 | |
---|
41 | $query = ' |
---|
42 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
43 | WHERE image_id = '.$item['verso_id'].' |
---|
44 | AND category_id = '.$conf['back2front']['versos_cat'].' |
---|
45 | ;'; |
---|
46 | pwg_query($query); |
---|
47 | } |
---|
48 | |
---|
49 | function back2front_check_storage() |
---|
50 | { |
---|
51 | global $conf; |
---|
52 | |
---|
53 | if ($conf['back2front']['versos_cat'] != 0) |
---|
54 | { |
---|
55 | $query = ' |
---|
56 | SELECT COUNT(*) FROM '.CATEGORIES_TABLE.' |
---|
57 | WHERE id = '.$conf['back2front']['versos_cat'].' |
---|
58 | AND name = "Back2Front private album" |
---|
59 | ;'; |
---|
60 | $result = pwg_query($query); |
---|
61 | |
---|
62 | if (pwg_db_num_rows($result)) |
---|
63 | { |
---|
64 | return; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | $versos_cat = create_virtual_category('Back2Front private album'); |
---|
69 | $versos_cat = array( |
---|
70 | 'id' => $versos_cat['id'], |
---|
71 | 'comment' => 'Used by Back2Front to store backsides.', |
---|
72 | 'status' => 'private', |
---|
73 | 'visible' => 'false', |
---|
74 | 'commentable' => 'false', |
---|
75 | ); |
---|
76 | |
---|
77 | mass_updates( |
---|
78 | CATEGORIES_TABLE, |
---|
79 | array( |
---|
80 | 'primary' => array('id'), |
---|
81 | 'update' => array_diff(array_keys($versos_cat), array('id')) |
---|
82 | ), |
---|
83 | array($versos_cat) |
---|
84 | ); |
---|
85 | |
---|
86 | $conf['back2front']['versos_cat'] = $versos_cat['id']; |
---|
87 | conf_update_param('back2front', serialize($conf['back2front'])); |
---|
88 | } |
---|
89 | |
---|
90 | function picture_exists($id) |
---|
91 | { |
---|
92 | if (!preg_match('#([0-9]{1,})#', $id) || $id == '0') return false; |
---|
93 | |
---|
94 | $query = "SELECT id FROM ".IMAGES_TABLE." WHERE id = ".$id.";"; |
---|
95 | $result = pwg_query($query); |
---|
96 | |
---|
97 | if (pwg_db_num_rows($result)) return true; |
---|
98 | else return false; |
---|
99 | } |
---|
100 | |
---|
101 | if (!function_exists('stripslashes_deep')) |
---|
102 | { |
---|
103 | function stripslashes_deep($value) |
---|
104 | { |
---|
105 | return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | ?> |
---|