source: extensions/showcase_subscribe/admin.php @ 28160

Last change on this file since 28160 was 11762, checked in by plg, 13 years ago

make the plugin compatible with Piwigo 2.1

File size: 6.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31load_language('plugin.lang', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
32
33define('SHOWCASE_SUBSCRIBE_BASE_URL', get_root_url().'admin.php?page=plugin-showcase_subscribe');
34
35if (!isset($conf['showcase_subscribe_url']))
36{
37  $conf['showcase_subscribe_url'] = 'http://piwigo.org/showcase';
38}
39
40// +-----------------------------------------------------------------------+
41// | Check Access and exit when user status is not ok                      |
42// +-----------------------------------------------------------------------+
43
44check_status(ACCESS_ADMINISTRATOR);
45
46// +-----------------------------------------------------------------------+
47// | process subscription                                                  |
48// +-----------------------------------------------------------------------+
49
50// searching for the date_creation
51$query = '
52SELECT registration_date
53  FROM '.USER_INFOS_TABLE.'
54  WHERE user_id = 1
55;';
56list($date_creation) = pwg_db_fetch_row(pwg_query($query));
57list($year) = explode('-', $date_creation);
58if ($year == 0)
59{
60  $query = '
61SELECT MIN(date_available)
62  FROM '.IMAGES_TABLE.'
63;';
64  list($date_creation) = pwg_db_fetch_row(pwg_query($query));
65}
66
67if (isset($_POST['submit_subscribe']))
68{
69  $url = $conf['showcase_subscribe_url'].'/ws.php';
70 
71  $get_data = array(
72    'format' => 'php',
73    );
74 
75  $post_data = array(
76    'method' => 'pwg.showcase.subscribe',
77    'url' => get_absolute_root_url(),
78    'date_creation' => $date_creation,
79    'name' => stripslashes($_POST['title']),
80    'comment' => stripslashes($_POST['description']),
81    'tags' => stripslashes($_POST['tags']),
82    'author' => stripslashes($_POST['author']),
83    'email' => $_POST['email'],
84    );
85
86  if (fetchRemote($url, $result, $get_data, $post_data))
87  {
88    $result = @unserialize($result);
89    // echo '<pre>'; print_r($result); echo '</pre>';
90  }
91  else
92  {
93    echo 'fetchRemote has failed<br>';
94  }
95}
96
97// +-----------------------------------------------------------------------+
98// | template init                                                         |
99// +-----------------------------------------------------------------------+
100
101$template->set_filenames(
102  array(
103    'plugin_admin_content' => dirname(__FILE__).'/admin.tpl'
104    )
105  );
106
107// +-----------------------------------------------------------------------+
108// | subscription state                                                    |
109// +-----------------------------------------------------------------------+
110
111$url = $conf['showcase_subscribe_url'].'/ws.php';
112
113$get_data = array(
114  'format' => 'php',
115  );
116 
117$post_data = array(
118  'method' => 'pwg.showcase.exists',
119  'url' => get_absolute_root_url(),
120  );
121
122if (fetchRemote($url, $result, $get_data, $post_data))
123{
124  $exists_result = @unserialize($result);
125  $subscription_status = $exists_result['result']['status'];
126}
127
128if (!isset($subscription_status))
129{
130  $subscription_status = 'connectionFailure';
131
132  array_push(
133    $page['errors'],
134    sprintf(
135      l10n('An error has occured, no connection to %s'),
136      $conf['showcase_subscribe_url']
137      )
138    );
139}
140
141if ('pending' == $subscription_status)
142{
143  array_push(
144    $page['infos'],
145    l10n('Your subscription is currently pending, if you have provided an email, you will be notified as soon as your gallery is registered')
146    );
147}
148
149if ('registered' == $subscription_status)
150{
151  array_push(
152    $page['infos'],
153    sprintf(
154      l10n('Your gallery is already registered in Piwigo Showcase, <a href="%s">see it →</a>'),
155      $exists_result['result']['picture_url']
156      )
157    );
158}
159
160
161// +-----------------------------------------------------------------------+
162// | prepare data for template                                             |
163// +-----------------------------------------------------------------------+
164
165$template->assign(
166  array(
167    'CURRENT_STATUS' => $subscription_status,
168    'URL' => get_absolute_root_url(),
169    'DATE_CREATION' => format_date($date_creation),
170    'EMAIL' => get_webmaster_mail_address(),
171    'TITLE' => strip_tags($conf['gallery_title']),
172    'TAGS' => '',
173    'DESCRIPTION' => '',
174    )
175  );
176
177// +-----------------------------------------------------------------------+
178// | sending html code                                                     |
179// +-----------------------------------------------------------------------+
180
181$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
182?>
Note: See TracBrowser for help on using the repository browser.