source: extensions/Back2Front/include/functions.inc.php @ 23177

Last change on this file since 23177 was 23177, checked in by mistic100, 11 years ago

use serialized array for config + custom upgrade process

File size: 2.6 KB
RevLine 
[10852]1<?php
[10981]2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
[23177]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*/
[10852]12function back2front_restaure_categories($item)
13{
14  global $conf;
[23177]15 
[10852]16  /* catch current verso categories */
[23177]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');
[10852]19
20  /* if verso € 'versos' cat only */
[23177]21  if (count($item['current_verso_cats']) == 1 && $item['current_verso_cats'][0] == $conf['back2front']['versos_cat'])
[10852]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 
[23177]41  $query = '
42DELETE FROM '.IMAGE_CATEGORY_TABLE.'
43  WHERE image_id = '.$item['verso_id'].'
44    AND category_id = '.$conf['back2front']['versos_cat'].'
45;';
46  pwg_query($query);
[10852]47}
48
[23177]49function back2front_check_storage()
50{
51  global $conf;
52 
53  if ($conf['back2front']['versos_cat'] != 0)
54  {
55    $query = '
56SELECT 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
[10852]90function picture_exists($id)
91{
[23177]92  if (!preg_match('#([0-9]{1,})#', $id) || $id == '0') return false;
[10852]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
[11219]101if (!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
[10852]109?>
Note: See TracBrowser for help on using the repository browser.