1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: $plugin_is_filter = 900 | THEME_PLUGIN;
12: $plugin_description = gettext("Provides a means for users to login/out from your theme pages.");
13: $plugin_author = "Stephen Billard (sbillard)";
14:
15: $option_interface = 'user_logout_options';
16: if (isset($_zp_gallery_page) && getOption('user_logout_login_form') > 1) {
17: setOption('colorbox_' . $_zp_gallery->getCurrentTheme() . '_' . stripSuffix($_zp_gallery_page), 1, false);
18: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/colorbox_js.php');
19: if (!zp_has_filter('theme_head', 'colorbox::css')) {
20: zp_register_filter('theme_head', 'colorbox::css');
21: }
22: }
23:
24: 25: 26: 27:
28: class user_logout_options {
29:
30: function __construct() {
31: setOptionDefault('user_logout_login_form', 0);
32: }
33:
34: function getOptionsSupported() {
35: return array(gettext('Login form') => array('key' => 'user_logout_login_form', 'type' => OPTION_TYPE_RADIO,
36: 'buttons' => array(gettext('None') => 0, gettext('Form') => 1, gettext('Colorbox') => 2),
37: 'desc' => gettext('If the user is not logged-in display an <em>in-line</em> logon form or a link to a modal <em>Colorbox</em> form.'))
38: );
39: }
40:
41: function handleOption($option, $currentValue) {
42:
43: }
44:
45: }
46:
47: if (in_context(ZP_INDEX)) {
48: if (isset($_GET['userlog'])) {
49: if ($_GET['userlog'] == 0) {
50: if (!$location = Zenphoto_Authority::handleLogout()) {
51: $__redirect = array();
52: if (in_context(ZP_ALBUM)) {
53: $__redirect['album'] = $_zp_current_album->name;
54: }
55: if (in_context(ZP_IMAGE)) {
56: $__redirect['image'] = $_zp_current_image->filename;
57: }
58: if (in_context(ZP_ZENPAGE_PAGE)) {
59: $__redirect['title'] = $_zp_current_zenpage_page->getTitlelink();
60: }
61: if (in_context(ZP_ZENPAGE_NEWS_ARTICLE)) {
62: $__redirect['title'] = $_zp_current_zenpage_news->getTitlelink();
63: }
64: if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
65: $__redirect['category'] = $_zp_current_category->getTitlelink();
66: }
67: if (isset($_GET['p'])) {
68: $__redirect['p'] = sanitize($_GET['p']);
69: }
70: if (isset($_GET['searchfields'])) {
71: $__redirect['searchfields'] = sanitize($_GET['searchfields']);
72: }
73: if (isset($_GET['words'])) {
74: $__redirect['words'] = sanitize($_GET['words']);
75: }
76: if (isset($_GET['date'])) {
77: $__redirect['date'] = sanitize($_GET['date']);
78: }
79: if (isset($_GET['title'])) {
80: $__redirect['title'] = sanitize($_GET['title']);
81: }
82: if (isset($_GET['page'])) {
83: $__redirect['page'] = sanitize($_GET['page']);
84: }
85:
86: $params = '';
87: if (!empty($__redirect)) {
88: foreach ($__redirect as $param => $value) {
89: $params .= '&' . $param . '=' . $value;
90: }
91: }
92: $location = FULLWEBPATH . '/index.php?fromlogout' . $params;
93: }
94: header("Location: " . $location);
95: exitZP();
96: }
97: }
98: }
99:
100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111:
112: function printUserLogin_out($before = '', $after = '', $showLoginForm = NULL, $logouttext = NULL) {
113: global $_zp_gallery, $__redirect, $_zp_current_admin_obj, $_zp_login_error, $_zp_gallery_page;
114: $excludedPages = array('password.php', 'register.php', 'favorites.php', '404.php');
115: $logintext = gettext('Login');
116: if (is_null($logouttext))
117: $logouttext = gettext("Logout");
118: $params = array("'userlog=0'");
119: if (!empty($__redirect)) {
120: foreach ($__redirect as $param => $value) {
121: $params[] .= "'" . $param . '=' . urlencode($value) . "'";
122: }
123: }
124: if (is_null($showLoginForm)) {
125: $showLoginForm = getOption('user_logout_login_form');
126: }
127: if (is_object($_zp_current_admin_obj)) {
128: if (!$_zp_current_admin_obj->logout_link) {
129: return;
130: }
131: }
132: $cookies = Zenphoto_Authority::getAuthCookies();
133: if (empty($cookies) || !zp_loggedin()) {
134: if (!in_array($_zp_gallery_page, $excludedPages)) {
135: switch ($showLoginForm) {
136: case 1:
137: ?>
138: <div class="passwordform">
139: <?php printPasswordForm('', true, false); ?>
140: </div>
141: <?php
142: break;
143: case 2:
144: if ((getOption('colorbox_' . $_zp_gallery->getCurrentTheme() . '_' . stripSuffix($_zp_gallery_page))) && (zp_has_filter('theme_head', 'colorbox::css'))) { ?>
145: <script type="text/javascript">
146:
147: $(document).ready(function() {
148: $(".logonlink").colorbox({
149: inline: true,
150: innerWidth: "400px",
151: href: "#passwordform",
152: close: '<?php echo gettext("close"); ?>',
153: open: $('#passwordform_enclosure .errorbox').length
154: });
155: });
156:
157: </script>
158: <?php if ($before) { echo '<span class="beforetext">' . html_encodeTagged($before) . '</span>'; } ?>
159: <a href="#" class="logonlink" title="<?php echo $logintext; ?>"><?php echo $logintext; ?></a>
160: <span id="passwordform_enclosure" style="display:none">
161: <div class="passwordform">
162: <?php printPasswordForm('', true, false); ?>
163: </div>
164: </span>
165: <?php if ($after) { echo '<span class="aftertext">' . html_encodeTagged($after) . '</span>'; }
166: }
167: break;
168: default:
169: if ($loginlink = zp_apply_filter('login_link',getCustomPageURL('password'))) {
170: if ($before) { echo '<span class="beforetext">' . html_encodeTagged($before) . '</span>'; } ?>
171: <a href="<?php echo $loginlink; ?>" title="<?php echo $logintext; ?>"><?php echo $logintext; ?></a>
172: <?php if ($after) { echo '<span class="aftertext">' . html_encodeTagged($after) . '</span>'; }
173: }
174: }
175: }
176: } else {
177: if ($before) { echo '<span class="beforetext">' . html_encodeTagged($before) . '</span>'; }
178: $logoutlink = "javascript:launchScript('" . FULLWEBPATH . "/',[" . implode(',', $params) . "]);";
179: ?>
180: <a href="<?php echo $logoutlink; ?>" title="<?php echo $logouttext; ?>"><?php echo $logouttext; ?></a>
181: <?php if ($after) { echo '<span class="aftertext">' . html_encodeTagged($after) . '</span>'; }
182: }
183: }
184: ?>