Exemplo n.º 1
0
<?php

include_once 'data.php';
include_once 'functions.php';
session_write_close();
if (!isset($_GET['from'])) {
    $from = '0';
} else {
    settype($_GET['from'], "integer");
    $from = $_GET['from'];
}
// CACHING
if (isset($_GET['from']) && !isset($_GET['browse']['No PDF']) && !isset($_GET['browse']['Not Indexed'])) {
    $cache_name = cache_name();
    $db_change = database_change(array('library', 'shelves', 'projects', 'projectsusers', 'projectsfiles', 'filescategories', 'notes'));
    cache_start($db_change);
    $total_files_array = read_export_files($db_change);
}
if (!isset($_GET['project'])) {
    $project = '';
} else {
    $project = $_GET['project'];
}
if (!isset($_SESSION['limit'])) {
    $limit = 10;
} else {
    settype($_SESSION['limit'], "integer");
    $limit = $_SESSION['limit'];
}
if (!isset($_SESSION['orderby'])) {
    $orderby = 'id';
         $k = $k + 1;
     }
 }
 $query_array = array_filter($query_array);
 $query_string = join('', $query_array);
 $query_string = 'search_query=' . urlencode($query_string);
 if (!empty($id_array)) {
     $query_string = join(',', $id_array);
     $query_string = 'id_list=' . urlencode($query_string);
 }
 ########## search arXiv ##############
 if (!empty($query_array) && empty($_GET['load']) && empty($_GET['save']) && empty($_GET['delete'])) {
     ############# caching ################
     $cache_name = cache_name();
     $cache_name .= '_download';
     $db_change = database_change(array('library'));
     cache_start($db_change);
     ########## register the time of search ##############
     if (!empty($_SESSION['session_download_arxiv_searchname']) && $from == 1) {
         database_connect(IL_DATABASE_PATH, 'library');
         $stmt = $dbHandle->prepare("UPDATE searches SET searchvalue=:searchvalue WHERE userID=:user AND searchname=:searchname AND searchfield='arxiv_last_search'");
         $stmt->bindParam(':user', $user, PDO::PARAM_STR);
         $stmt->bindParam(':searchname', $searchname, PDO::PARAM_STR);
         $stmt->bindParam(':searchvalue', $searchvalue, PDO::PARAM_STR);
         $user = $_SESSION['user_id'];
         $searchname = "arxiv#" . $_SESSION['session_download_arxiv_searchname'];
         $searchvalue = time();
         $stmt->execute();
     }
     ########## search arXiv ##############
     $request_url = "http://export.arxiv.org/api/query?" . $query_string . $category_string . $edat_string . $year_string . "&start=" . ($from - 1) . "&max_results=10&sortBy=lastUpdatedDate&sortOrder=descending";
Exemplo n.º 3
0
 // Store current table name hash in session.
 $table_name_hash = '';
 $table_name_array = $_GET;
 $table_name_array['orderby'] = $orderby;
 unset($table_name_array['_']);
 unset($table_name_array['from']);
 unset($table_name_array['limit']);
 unset($table_name_array['display']);
 $table_name_array['user_id'] = $_SESSION['user_id'];
 $table_name_array = array_filter($table_name_array);
 ksort($table_name_array);
 $table_name_hash = 'search_' . hash('crc32', json_encode($table_name_array));
 $_SESSION['display_files'] = $table_name_hash;
 session_write_close();
 // FILE CACHING
 $db_change = database_change(array('library', 'shelves', 'projects', 'projectsusers', 'projectsfiles', 'filescategories', 'notes', 'annotations'), array('full_text'), array('clipboard'));
 if (isset($_GET['from'])) {
     $cache_name = cache_name();
     cache_start($db_change);
 }
 //READ PROJECTS
 database_connect(IL_DATABASE_PATH, 'library');
 $desktop_projects = array();
 $desktop_projects = read_desktop($dbHandle);
 ######### LIMITS ################
 ######### RATING ################
 $rating_search = '';
 $rating_searches = array();
 if (!isset($_GET['rating'])) {
     $_GET['rating'][] = 1;
     $_GET['rating'][] = 2;
Exemplo n.º 4
0
<?php

include_once 'data.php';
include_once 'functions.php';
session_write_close();
// CACHING
$cache_name = cache_name();
$db_change = database_change(array('library', 'shelves', 'filescategories', 'searches', 'categories'));
cache_start($db_change);
if (!isset($_GET['select'])) {
    $_GET['select'] = 'library';
}
if ($_GET['select'] != 'library' && $_GET['select'] != 'shelf' && $_GET['select'] != 'project' && $_GET['select'] != 'clipboard') {
    $_GET['select'] = 'library';
}
$in = '';
if ($_GET['select'] == 'shelf') {
    $in = "INNER JOIN shelves ON library.id=shelves.fileID WHERE shelves.userID=" . intval($_SESSION['user_id']);
}
if ($_GET['select'] == 'clipboard' && !empty($_SESSION['session_clipboard'])) {
    $in = join(",", $_SESSION['session_clipboard']);
    $in = "WHERE id IN ({$in})";
}
if ($_GET['select'] == 'clipboard' && empty($_SESSION['session_clipboard'])) {
    $in = "WHERE id IN ()";
}
empty($in) ? $where = 'WHERE' : ($where = 'AND');
database_connect($database_path, 'library');
### CATEGORY ###################################################################
if (isset($_GET['open']) && in_array("category", $_GET['open'])) {
    $subfiles = '';
Exemplo n.º 5
0
function perform_search($sql)
{
    global $dbHandle;
    global $limit;
    global $from;
    global $orderby;
    global $ordering;
    global $result;
    global $rows;
    global $case;
    // Generate table name hash.
    $table_name_hash = '';
    $table_name_array = $_GET;
    $table_name_array['orderby'] = $orderby;
    unset($table_name_array['_']);
    unset($table_name_array['from']);
    unset($table_name_array['limit']);
    unset($table_name_array['display']);
    $table_name_array['user_id'] = $_SESSION['user_id'];
    $table_name_array = array_filter($table_name_array);
    ksort($table_name_array);
    $table_name_hash = 'search_' . hash('crc32', json_encode($table_name_array));
    $_SESSION['display_files'] = $table_name_hash;
    // Read db change times.
    $db_change = database_change(array('library', 'shelves', 'projects', 'projectsusers', 'projectsfiles', 'filescategories', 'notes', 'annotations'), array('full_text'), array('clipboard'));
    $quoted_path = $dbHandle->quote(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'history.sq3');
    $dbHandle->exec("ATTACH DATABASE {$quoted_path} as history");
    if (isset($_GET['select']) && $_GET['select'] == 'clipboard') {
        attach_clipboard($dbHandle);
    }
    $quoted_path = $dbHandle->quote(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'fulltext.sq3');
    if (isset($_GET['browse']) && array_key_exists('Not Indexed', $_GET['browse']) || isset($_GET['searchtype']) && $_GET['searchtype'] == 'pdf' || isset($_GET['searchtype']) && $_GET['searchtype'] == 'global') {
        $dbHandle->exec("ATTACH DATABASE {$quoted_path} AS fulltextdatabase");
    }
    $quoted_path = $dbHandle->quote(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'discussions.sq3');
    if (isset($_GET['browse']) && array_key_exists('Discussed Items', $_GET['browse'])) {
        $dbHandle->exec("ATTACH DATABASE {$quoted_path} AS discussionsdatabase");
    }
    $dbHandle->exec("CREATE TABLE IF NOT EXISTS history.search_tables (" . "id INTEGER PRIMARY KEY," . "table_name TEXT NOT NULL DEFAULT ''," . "created TEXT NOT NULL DEFAULT ''," . "total_rows TEXT NOT NULL DEFAULT '')");
    // Delete stale tables.
    $dbHandle->beginTransaction();
    $result = $dbHandle->query("SELECT id, table_name, created FROM history.search_tables");
    $rows = $result->fetchAll(PDO::FETCH_ASSOC);
    $result = null;
    foreach ($rows as $row) {
        if ($row['created'] < $db_change || isset($_GET['browse']['Discussed Items']) || isset($_GET['browse']['Viewed in the last 8 hours'])) {
            $dbHandle->exec("DROP TABLE history.`" . $row['table_name'] . "`");
            $dbHandle->exec("DELETE FROM history.search_tables WHERE id=" . $row['id']);
        }
    }
    $dbHandle->commit();
    $rows = null;
    // Check if cache table exists.
    $result = $dbHandle->query("SELECT count(*) FROM history.sqlite_master WHERE type='table' AND name='{$table_name_hash}'");
    $table = $result->fetchColumn();
    $result = null;
    // No. Get all ids ordered + total count and save to history.
    // Yes. Do id-based paging.
    if ($table == 0) {
        $dbHandle->sqliteCreateFunction('regexp_match', 'sqlite_regexp', 3);
        if ($case == 1) {
            $dbHandle->exec("PRAGMA case_sensitive_like = 1");
        }
        $dbHandle->exec("CREATE TABLE IF NOT EXISTS history.`" . $table_name_hash . "` " . "(id INTEGER PRIMARY KEY, itemID INTEGER NOT NULL DEFAULT '')");
        $dbHandle->beginTransaction();
        $dbHandle->exec("INSERT INTO history.`{$table_name_hash}` (itemID) " . $sql);
        $dbHandle->exec("INSERT INTO history.search_tables(table_name,created,total_rows)" . " VALUES('{$table_name_hash}', '" . time() . "', (SELECT count(*) FROM history.`{$table_name_hash}`))");
        $dbHandle->commit();
    }
    if ($orderby == 'id') {
        $result = $dbHandle->query("SELECT id,file,authors,title,journal,secondary_title,year,volume,pages,abstract,uid,doi,url,addition_date,rating,bibtex\r\n            FROM library WHERE id IN (SELECT itemID FROM history.`{$table_name_hash}` ORDER BY id DESC LIMIT {$limit} OFFSET {$from}) ORDER BY id DESC");
    } else {
        $result = $dbHandle->query("SELECT id,file,authors,title,journal,secondary_title,year,volume,pages,abstract,uid,doi,url,addition_date,rating,bibtex\r\n            FROM library WHERE id IN (SELECT itemID FROM history.`{$table_name_hash}` LIMIT {$limit} OFFSET {$from}) {$ordering}");
    }
    $result2 = $dbHandle->query("SELECT total_rows FROM history.search_tables WHERE table_name='{$table_name_hash}'");
    $rows = $result2->fetchColumn();
    $result2 = null;
    $dbHandle->exec("DETACH history");
    $dbHandle->exec("DETACH clipboard");
    $dbHandle->exec("DETACH fulltextdatabase");
    $dbHandle->exec("PRAGMA shrink_memory");
}