add_action('plugin_install', 'scribd_install'); // Add a configure action $thisplugin->add_action('plugin_configure', 'scribd_configure'); // Add a uninstall action $thisplugin->add_action('plugin_uninstall', 'scribd_uninstall'); // Add plugin_cleanup action $thisplugin->add_action('plugin_cleanup', 'scribd_cleanup'); // Add a filter which gets called after the file is successfull uploaded $thisplugin->add_filter('add_file_data_success', 'scribd_upload'); // Add a filter for displaying the scribd viewer on display image page $thisplugin->add_filter('file_data', 'scribd_file_data'); // Add a filter for deleting the scribd document $thisplugin->add_filter('before_delete_file', 'scribd_delete_file'); // Add page_start action $thisplugin->add_action('page_start', 'scribd_init'); function scribd_init() { // We will only consider those extenstions which are supported by Scribd global $scribd_valid_extensions; $scribd_valid_extensions = array('pdf', 'txt', 'rtf', 'ppt', 'doc', 'xls'); } // Install function // Stores the api key and secret in config table and add two new fields to pictures table function scribd_install() { global $CONFIG; // Install if ($_POST['scribd_api_key'] && $_POST['scribd_api_secret']) { // Run the query to add both these values to config table $query = "REPLACE INTO {$CONFIG['TABLE_CONFIG']} (`name`, `value`) VALUES ('scribd_api_key', '{$_POST['scribd_api_key']}'), ('scribd_api_secret', '{$_POST['scribd_api_secret']}')"; cpg_db_query($query); // If we already have scribd_api_key in config then it means this plugin was installed earlier also // and the fields from pictures table and config options were not removed. In such a case no need to add scribd fields if (!isset($CONFIG['scribd_api_key'])) { // Run the sql to add scribd_doc_id and scribd_access_key fields to pictures table $query = "ALTER TABLE {$CONFIG['TABLE_PICTURES']} ADD `scribd_doc_id` INT NOT NULL , ADD `scribd_access_key` VARCHAR( 255 ) NOT NULL"; cpg_db_query($query); } return true; // Loop again } else { return 1; } } // Uninstall plugin function scribd_uninstall() { global $CONFIG; // If the cleanup form has not been posted then show the cleanup form if (!isset($_POST['drop'])) { return 1; } // If user chose to drop the fields (scribd_doc_id) if ($_POST['drop']) { // Remove the config options $query = "DELETE FROM {$CONFIG['TABLE_CONFIG']} WHERE name IN ('scribd_api_key','scribd_api_secret')"; cpg_db_query($query); // Delete the scribd fields from pictures table $query = "ALTER TABLE {$CONFIG['TABLE_PICTURES']} DROP `scribd_doc_id`, DROP `scribd_access_key`"; cpg_db_query($query); } return true; } // Configure function // Displays the form to input the api key and secret function scribd_configure() { echo <<< EOT
EOT; } // Ask if we want to drop the scribd fields function scribd_cleanup($action) { global $CONFIG; if ($action == 1) { ?> upload($file); // If document got uploaded successfully then we will have a doc id if ($data['doc_id']) { // Add this doc_id to the respective record in pictures table $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET scribd_doc_id = '{$data['doc_id']}', scribd_access_key = '{$data['access_key']}' WHERE pid = '{$pic_data['pid']}' "; cpg_db_query($query); } else { // If upload to scribd fails, we are doing nothing // In such a case the document will be handled normally via cpg and no scribd viewer will be used } } return $pic_data; } // Function which embeds the scribd viewer on display image page function scribd_file_data($pic_data) { global $CONFIG, $scribd_valid_extensions; $file = $CONFIG['fullpath'] . $pic_data['filepath'] . $pic_data['filename']; $tmp = explode('.',$file); $EOA = count($tmp) - 1; $extension = strtolower($tmp[$EOA]); $picture_url = get_pic_url($pic_data, 'fullsize'); // We will replace the file html only if it is a valid scribd document // Sorry, height and width of the object is fixed to 600 and 800 respectively. if ($pic_data['scribd_doc_id'] && is_document($file) && in_array($extension, $scribd_valid_extensions)) { $pic_data['html'] = <<