Dotclear

source: plugins/gallery/trunk/class.dc.gallery.integration.php @ 2272

Revision 2272, 3.6 KB checked in by bruno, 14 years ago (diff)

Sanitized versions checking

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Dotclear 2 Gallery plugin.
5#
6# Copyright (c) 2004-2008 Bruno Hondelatte, and contributors.
7# Many, many thanks to Olivier Meunier and the Dotclear Team.
8# Licensed under the GPL version 2.0 license.
9# See LICENSE file or
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13
14class dcGalleryIntegration
15{
16     protected $core;
17
18     public static $default_supported_modes = array(
19          "home" => array("default","default-page"),
20          "category" => array("category"),
21          "tag" => array("tag","tags"),
22          "archive" => array("archive"),
23          "search" => array("search"));
24
25     protected $type_mode_bind;
26
27     protected $integrations;
28     protected $supported_modes;
29     protected $settings;
30
31     
32     public function __construct($core)
33     {
34          if (version_compare(DC_VERSION,'2.2-alpha','>=')) {
35               $core->blog->settings->addNamespace('gallery');
36               $this->settings =& $core->blog->settings->gallery;
37          } else {
38               $core->blog->settings->setNamespace('gallery');
39               $this->settings =& $core->blog->settings;
40          }
41          $this->core =& $core; 
42          $this->integrations = $this->load();
43          $this->type_mode_bind=array();
44          if (function_exists('json_decode') &&
45               $this->settings->gallery_supported_modes) {
46                    $this->supported_modes = json_decode($this->settings->gallery_supported_modes);
47          } else {
48               $this->supported_modes = self::$default_supported_modes;
49          }
50          foreach ($this->supported_modes as $mode => $v) {
51               foreach ($v as $type)
52                    $this->type_mode_bind[$type]=$mode;
53          }
54     }
55
56     public function load() {
57          if ($this->settings->gallery_integrations != "") {
58               $integ = @unserialize(base64_decode($this->settings->gallery_integrations));
59               if ($integ === false)   
60                    $integ = array();
61          } else {
62               $integ = array();
63          }
64          return $integ;
65     }
66
67     public function save() {
68          $this->settings->put('gallery_integrations',
69               @base64_encode(serialize($this->integrations)),'string',
70               'Gallery integrations');
71
72     }
73
74     public function getModes() {
75          $integ = $this->integrations;
76          foreach ($this->supported_modes as $k=>$v) {
77               if (!array_key_exists($k,$integ)) {
78                    $integ[$k]=array('gal' => 'none','img' => 'none');
79               }
80          }
81          return $integ;
82     }
83
84     public function setMode($mode,$img,$gal) {
85          $this->integrations[$mode]=array('gal' => $gal,'img' => $img);
86     }
87
88     public function isEnabledForType($type,$check_gal=true,$check_img=true) {
89          if (!array_key_exists($type,$this->type_mode_bind))
90               return false;
91          $mode = $this->type_mode_bind[$type];
92
93          if (!array_key_exists($mode,$this->integrations)) {
94               return false;
95          } else {
96               return ($check_gal && $this->integrations[$mode]['gal'] != 'none')
97                    || ($check_img && $this->integrations[$mode]['img'] != 'none'); 
98          }
99
100     }
101
102     public function updateGetPostParams($type,&$params) {
103          if (!array_key_exists($type,$this->type_mode_bind))
104               return false;
105          $mode = $this->type_mode_bind[$type];
106          if (!array_key_exists($mode,$this->integrations))
107               return false;
108          $cond=array();
109          $post_types = array();
110          switch ($this->integrations[$mode]['img']) {
111          case 'selected':
112               $cond[]="'galitem'";
113               /* No break here, and it is wanted so! */
114          case 'all':
115               $post_types[]="galitem";
116          }
117          switch ($this->integrations[$mode]['gal']) {
118          case 'selected':
119               $cond[]="'gal'";
120               /* No break here, and it is wanted so! */
121          case 'all':
122               $post_types[]="gal";
123          }
124          $p="";
125          if (!empty($post_types)) {
126               $params['post_type'] = $post_types;
127               $params['post_type'][] = 'post';
128          }
129          if (!empty($cond)) {
130               if (!isset($params['sql']))
131                    $params['sql']="";
132               $params['sql'] .= "AND not (P.post_type in (".join(",",$cond).") AND P.post_selected='0') ";
133          }
134     }
135
136}
137?>
Note: See TracBrowser for help on using the repository browser.

Sites map