View source
<?php
define('FLIPPING_BOOK_MANAGEMENT_PATH', 'admin/config/media/flipping_book');
function flipping_book_permission() {
return array(
'administer flipping_book' => array(
'title' => t('Administer Flipping Book'),
),
'upload flipping_book' => array(
'title' => t('Upload Flipping Books'),
),
'access private flipping_books' => array(
'title' => t('Access private Flipping Books'),
'description' => t('Allow access to flipping books imported into the private folder.'),
),
);
}
function flipping_book_menu() {
$module_path = drupal_get_path('module', 'flipping_book');
$items = array();
$items[FLIPPING_BOOK_MANAGEMENT_PATH] = array(
'title' => 'Flipping Book',
'description' => 'Import, delete your Flipping Books',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flipping_book_management_form',
),
'access arguments' => array(
'upload flipping_book',
),
'file' => 'flipping_book.pages.inc',
'file path' => $module_path . '/includes',
);
$items[FLIPPING_BOOK_MANAGEMENT_PATH . '/import'] = array(
'title' => 'Import',
'access arguments' => array(
'upload flipping_book',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[FLIPPING_BOOK_MANAGEMENT_PATH . '/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flipping_book_settings_form',
),
'access arguments' => array(
'administer flipping_book',
),
'type' => MENU_LOCAL_TASK,
'file' => 'flipping_book.admin.inc',
'file path' => $module_path . '/includes',
);
$items[FLIPPING_BOOK_MANAGEMENT_PATH . '/%flipping_book/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flipping_book_delete_confirm',
4,
),
'access arguments' => array(
'administer flipping_book',
),
'type' => MENU_CALLBACK,
'context' => MENU_CONTEXT_INLINE,
'file' => 'flipping_book.admin.inc',
'file path' => $module_path . '/includes',
);
return $items;
}
function flipping_book_load_multiple(array $fbids) {
$flipping_books = array();
foreach ($fbids as $fbid) {
$flipping_books[$fbid] = flipping_book_load($fbid);
}
return $flipping_books;
}
function flipping_book_load($fbid) {
$flipping_books =& drupal_static(__FUNCTION__);
if (!isset($flipping_books[$fbid])) {
$flipping_book = db_select('flipping_book', 'f')
->fields('f')
->condition('f.fbid', $fbid, '=')
->execute()
->fetchObject();
if (empty($flipping_book)) {
return FALSE;
}
$flipping_book->uri = flipping_book_dir() . '/' . $flipping_book->dir . '/index.html';
$flipping_book->url = file_create_url($flipping_book->uri);
$flipping_book->path = preg_replace('/^\\/?/', '', parse_url($flipping_book->url, PHP_URL_PATH));
$flipping_books[$fbid] = $flipping_book;
}
return $flipping_books[$fbid];
}
function flipping_book_delete($fbid) {
$flipping_book = flipping_book_load($fbid);
$path = pathinfo(drupal_realpath($flipping_book->uri), PATHINFO_DIRNAME);
if (file_unmanaged_delete_recursive($path)) {
$result = db_delete('flipping_book')
->condition('fbid', $fbid, '=')
->execute();
}
else {
$result = FALSE;
}
return $result;
}
function flipping_book_views_api() {
return array(
"api" => "3.0",
);
}
function flipping_book_dir() {
$dir =& drupal_static(__FUNCTION__);
if (empty($dir)) {
$dir = variable_get('flipping_book_schema', 'public') . '://flipping_book';
}
return $dir;
}
function flipping_book_prepare_directory() {
$directory = flipping_book_dir();
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
}
function flipping_book_file_download($uri) {
if (arg(2) != 'flipping_book') {
return NULL;
}
$file_path = drupal_realpath($uri);
$denied = !file_exists($file_path) || !is_file($file_path) || !user_access('access private flipping_books');
if ($denied) {
return -1;
}
$file = new stdClass();
$uri_chunks = explode('/', $uri);
$file->filename = end($uri_chunks);
$file->filemime = file_get_mimetype($uri);
$file->filesize = filesize($file_path);
$headers = file_get_content_headers($file);
return $headers;
}