示例#1
0
文件: lib.php 项目: jmorwick/mypdfdb
function merge_pdf_metadata($pdf_ids, $path)
{
    if (count($pdf_ids) < 2) {
        err_bad_input_format("expected at least 2 pdf ids");
    }
    // validate pdf arguments and gather merged pdf attributes
    $attributes = array();
    $tags = array();
    $total_pages = 0;
    foreach ($pdf_ids as $pdf_id) {
        $pdf = get_pdf_info($pdf_id);
        if (!$pdf) {
            err_bad_input_data('pdfid', $pdf_id, 'not a valid pdf id');
        }
        if (!isset($attributes['title']) && $pdf['title']) {
            $attributes['title'] = $pdf['title'];
        }
        if (!isset($attributes['date']) && $pdf['date']) {
            $attributes['date'] = $pdf['date'];
        }
        if (!isset($attributes['origin']) && $pdf['origin']) {
            $attributes['origin'] = $pdf['origin'];
        }
        if (!isset($attributes['recipient']) && $pdf['recipient']) {
            $attributes['recipient'] = $pdf['recipient'];
        }
        $tags = array_unique(array_merge($tags, find_tags_for_pdf($pdf_id)));
    }
    foreach ($pdf_ids as $pdf_id) {
        delete_pdf_metadata($pdf_id);
    }
    $new_id = add_pdf_to_db($path, $attributes);
    foreach ($tags as $tag) {
        tag_pdf($new_id, $tag);
    }
    if (!$new_id) {
        err_internal("could not insert merged file to db");
    }
    return $new_id;
}
示例#2
0
function service_associate_tags($args)
{
    if (count($args) != 2) {
        err_bad_input_format("expected two argument in URL (dash-separated list of tag ids followed by dash-separated list of pdf ids)");
    }
    $tags = explode('-', $args[0]);
    $pdfs = explode('-', $args[1]);
    foreach ($tags as $tag) {
        if (!get_tag_info($tag)) {
            err_bad_input_data('tagid', $tag, 'not a valid tag id');
        }
    }
    foreach ($pdfs as $pdf) {
        if (!get_pdf_info($pdf)) {
            err_bad_input_data('pdfid', $pdf, 'not a valid pdf id');
        }
    }
    foreach ($pdfs as $pdf_id) {
        foreach ($tags as $tag) {
            tag_pdf($pdf_id, $tag);
        }
    }
}