function admin() { if (TANTAN_FLICKR_CACHEMODE == "fs" && !is_writable(dirname(__FILE__) . '/flickr-cache/')) { echo "<div class='wrap'>\n <h2>Permissions Error</h2>\n <p>This plugin requires that the directory <strong>" . dirname(__FILE__) . "/flickr-cache/</strong> be writable by the web server.</p> \n <p>You may want to try to manually delete this flickr-cache directory, and have the plugin try to create it to see if that will fix this problem.</p>\n <p>Otherwise, please contact your server administrator to ensure the proper permissions are set for this directory. </p>\n </div>\n "; return; } elseif (!get_settings('permalink_structure')) { $error = "In order to view your photo album, your <a href='options-permalink.php'>WordPress permalinks</a> need to be set to something other than <em>Default</em>."; /* } elseif (!function_exists('curl_init')) { $error = "You do not have the required libraries to use this plugin. The PHP library <a href='http://us2.php.net/curl'>libcurl</a> needs to be installed on your server."; */ } elseif (@constant('DB_CHARSET') === null) { $error = "Your database character encoding does not seem to be set. It is <strong>strongly</strong> recommended that you set it to <em>utf8</em> for maximum compatibility. <a href=\"http://codex.wordpress.org/Editing_wp-config.php#Database_character_set\">Instructions are available here.</a> " . "Once you have set your database encoding, please deactivate and reactivate this plugin."; } if ($_POST['action'] == 'savekey') { update_option('silas_flickr_apikey', $_POST['flickr_apikey']); update_option('silas_flickr_sharedsecret', $_POST['flickr_sharedsecret']); $message = "Saved API Key."; } elseif ($_POST['action'] == 'resetkey') { update_option('silas_flickr_apikey', false); update_option('silas_flickr_sharedsecret', false); $message = "API Key reset"; } $flickr_apikey = get_option('silas_flickr_apikey'); $flickr_sharedsecret = get_option('silas_flickr_sharedsecret'); if ($flickr_apikey && $flickr_sharedsecret) { require_once dirname(__FILE__) . '/lib.flickr.php'; $flickr = new TanTanFlickr(); if ($flickr->cache == 'db') { global $wpdb; $wpdb->hide_errors(); $charset_collate = ''; if (method_exists($wpdb, 'supports_collation') && $wpdb->supports_collation() || version_compare(mysql_get_server_info($wpdb->dbh), '4.1.0', '>=')) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } $wpdb->query("\n CREATE TABLE IF NOT EXISTS `{$flickr->cache_table}` (\n `command` CHAR( 255 ) NOT NULL ,\n `request` CHAR( 35 ) NOT NULL ,\n `response` MEDIUMTEXT NOT NULL ,\n `created` DATETIME NOT NULL ,\n `expiration` DATETIME NOT NULL ,\n INDEX ( `request` ),\n\t\t\t\t\tINDEX ( `command` )\n ) {$charset_collate}"); // $wpdb->query("CREATE INDEX commandCreated on {$flickr->cache_table}(command, created)"); $wpdb->show_errors(); if (function_exists('wp_schedule_event')) { wp_clear_scheduled_hook('tantan_flickr_clear_cache_event'); wp_schedule_event(time(), 'daily', 'tantan_flickr_clear_cache_event'); } } if ($_POST['action'] == 'save') { $flickr->clearCache(); $token = $flickr->auth_getToken($_POST['frob']); if ($token) { update_option('silas_flickr_token', $token); } else { $error = $flickr->getErrorMsg(); } } elseif ($_POST['action'] == 'logout') { update_option('silas_flickr_token', ''); $flickr->clearCache(); } elseif ($_POST['action'] == 'savebase') { $url = parse_url(get_bloginfo('siteurl')); $baseurl = $url['path'] . '/' . $_POST['baseurl']; if (!ereg('.*/$', $baseurl)) { $baseurl .= '/'; } if ($_POST['synidcateoff'] || strlen($_POST['baseurl']) <= 0) { $baseurl = false; } update_option('silas_flickr_baseurl_pre', $url['path'] . '/'); update_option('silas_flickr_baseurl', $baseurl); update_option('silas_flickr_hideprivate', $_POST['hideprivate']); update_option('silas_flickr_showbadge', $_POST['showbadge']); update_option('silas_flickr_linkoptions', $_POST['linkoptions']); } $auth_token = get_option('silas_flickr_token'); $baseurl = get_option('silas_flickr_baseurl'); $baseurl_pre = get_option('silas_flickr_baseurl_pre'); $hideprivate = get_option('silas_flickr_hideprivate'); $showbadge = get_option('silas_flickr_showbadge'); $linkoptions = get_option('silas_flickr_linkoptions'); $hideAlbums = get_option('silas_flickr_hidealbums'); $hideGroups = get_option('silas_flickr_hidegroups'); $groupOrder = get_option('silas_flickr_grouporder'); $albumOrder = get_option('silas_flickr_albumorder'); $flickrAuth = false; if (!$auth_token) { $flickr->clearCache(); $frob = $flickr->getFrob(); $error = $flickr->getErrorMsg(); $flickrAuth = false; } else { $flickr->setToken($auth_token); $flickr->setOption(array('hidePrivatePhotos' => get_option('silas_flickr_hideprivate'))); $user = $flickr->auth_checkToken(); if (!$user) { // get a new frob and try to re-authenticate $error = $flickr->getErrorMsg(); update_option('silas_flickr_token', ''); $flickr->setToken(''); $frob = $flickr->getFrob(); } else { $flickrAuth = true; $flickr->setUser($user); update_option('silas_flickr_user', $user); } } } // apikey check if ($flickrAuth) { // passed authentication if ($_POST['action'] == 'clearcache') { if ($_POST['album'] == 'all') { if ($flickr->clearCache()) { $message = "Successfully cleared the cache."; } else { $error = "Cache clear failed. Try manually deleting the 'flickr-cache' directory or the silas_flickr_cache database table."; } } else { $flickr->startClearCache(); $albums = $flickr->getAlbums(); $photos = $flickr->getPhotos($_POST['album']); $flickr->doneClearCache(); $message = "Refreshed " . count($photos) . " photos in " . $albums[$_POST['album']]['title'] . "."; } } elseif ($_POST['action'] == 'savealbumsettings') { if (!is_array($_POST['hideAlbum'])) { $_POST['hideAlbum'] = array(); } update_option('silas_flickr_hidealbums', $_POST['hideAlbum']); $hideAlbums = $_POST['hideAlbum']; if (!is_array($_POST['albumOrder'])) { $_POST['albumOrder'] = array(); } asort($_POST['albumOrder']); update_option('silas_flickr_albumorder', $_POST['albumOrder']); $albumOrder = $_POST['albumOrder']; $message .= "Saved album settings. "; if (is_array($_POST['clearAlbum'])) { $flickr->startClearCache(); foreach ($_POST['clearAlbum'] as $album_id) { $photos = $flickr->getPhotos($album_id); } $flickr->doneClearCache(); $message .= "Cleared cache for selected albums. "; } } elseif ($_POST['action'] == 'savegroupsettings') { if (!is_array($_POST['hideGroup'])) { $_POST['hideGroup'] = array(); } update_option('silas_flickr_hidegroups', $_POST['hideGroup']); $hideGroups = $_POST['hideGroup']; if (!is_array($_POST['groupOrder'])) { $_POST['groupOrder'] = array(); } asort($_POST['groupOrder']); update_option('silas_flickr_grouporder', $_POST['groupOrder']); $groupOrder = $_POST['groupOrder']; $message .= "Saved group settings. "; if (is_array($_POST['clearGroup'])) { $flickr->startClearCache(); foreach ($_POST['clearGroup'] as $group_id) { $photos = $flickr->getPhotosByGroup($group_id); } $flickr->doneClearCache(); $message .= "Cleared cache for selected groups. "; } } } include dirname(__FILE__) . '/admin-options.html'; }