/** * Checks if the user has uploaded a social media tokens JSON file * @return boolean If a file exists, true, else false. */ function ppp_has_local_tokens() { $token_file = apply_filters('ppp_local_social_token_path', ppp_get_upload_path() . '/ppp-social-tokens.json'); $local_tokens = false; if (!file_exists($token_file)) { return $local_tokens; } $local_tokens = json_decode(file_get_contents($token_file)); // Failed to parse as JSON if (false === $local_tokens) { return $local_tokens; } // No social tokens found in the format we accept or it was empty if (empty($local_tokens) || (!isset($local_tokens->twitter) || !isset($local_tokens->facebook) || !isset($local_tokens->linkedin))) { return false; } return apply_filters('ppp_local_tokens', $local_tokens, $token_file); }
/** * Verifies our directory exists, and it's protected * * @since 2.2 * @return void */ function ppp_set_uploads_dir() { $upload_path = ppp_get_upload_path(); if (false === get_transient('ppp_check_protection_files')) { // Make sure the /ppp folder is created wp_mkdir_p($upload_path); // Prevent directory browsing and direct access to all files $rules = "Options -Indexes\n"; $rules .= "deny from all\n"; $htaccess_exists = file_exists($upload_path . '/.htaccess'); if ($htaccess_exists) { $contents = @file_get_contents($upload_path . '/.htaccess'); if ($contents !== $rules || !$contents) { // Update the .htaccess rules if they don't match @file_put_contents($upload_path . '/.htaccess', $rules); } } elseif (wp_is_writable($upload_path)) { // Create the file if it doesn't exist @file_put_contents($upload_path . '/.htaccess', $rules); } // Top level blank index.php if (!file_exists($upload_path . '/index.php') && wp_is_writable($upload_path)) { @file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.'); } // Check for the files once per day set_transient('ppp_check_protection_files', true, 3600 * 24); } }