first commit

This commit is contained in:
2025-07-18 16:20:14 +07:00
commit 98af45c018
16382 changed files with 3148096 additions and 0 deletions

View File

@@ -0,0 +1,242 @@
<?php
include "../../../include/boot.php";
include_once "../include/annotate_functions.php";
include "../../../include/authenticate.php";
global $plugins;
if (!in_array("annotate",$plugins))
{
header("Status: 403 plugin not activated");
exit($lang["error-plugin-not-activated"]);
}
$ref=getval("ref",0,true);
$col=getval("col",0,true);
$previewpage=getval("previewpage",1,true);
if ($col!=0)
{
$is_collection=true;
$collection=get_collection($col);
$resources=do_search("!collection".$col);
set_user_collection($userref,$col);
refresh_collection_frame();
$ref="C".$col;$realref=$col; // C allows us to distinguish a collection from a resource in the JS without adding extra params.
}
else
{
$is_collection=false;
$resources=do_search("!list".$ref);
$realref=$ref;
}
// prune unnannotated resources if necessary
$annotate=true;
if ($annotate_pdf_output_only_annotated)
{
$resources_modified=array();
$x=0;
for ($n=0;$n<count($resources);$n++)
{
unset($notes);
if ($annotate_pdf_output_only_annotated && $resources[$n]['annotation_count']!=0)
{
$resources_modified[$x]=$resources[$n];
$x++;
}
}
$resources=$resources_modified;
}
if (count($resources)==0){$annotate=false;}
# Fetch search details (for next/back browsing and forwarding of search params)
$search=getval("search","");
$order_by=getval("order_by","relevance");
$offset=getval("offset",0,true);
$restypes=getval("restypes","");
if (strpos($search,"!")!==false) {$restypes="";}
$archive=getval("archive",0,true);
$default_sort_direction="DESC";
if (substr($order_by,0,5)=="field"){$default_sort_direction="ASC";}
$sort=getval("sort",$default_sort_direction);
include "../../../include/header.php";
// a unique id allows us to isolate this page's temporary files.
$annotateid=uniqid($ref);
$jpghttppath=get_annotate_file_path($realref,false,"jpg");
?>
<?php if ($annotate){?>
<script type="text/javascript" language="JavaScript">
var annotate_previewimage_prefix = "";
(function(jQuery) {
var methods = {
preview : function() {
var url = '<?php echo $baseurl_short?>plugins/annotate/pages/annotate_pdf_gen.php';
var formdata = jQuery('#annotateform').serialize() + '&preview=true';
jQuery.ajax(url,{
data: formdata,
success: function(response) {jQuery(this).annotate('refresh',response);},
complete: function(response) {
jQuery('#error').html(response.responseText);
if (response.responseText=="nothing"){
jQuery('#heading').hide();
jQuery('#configform').hide();
jQuery('#previewdiv').hide();
jQuery('#introtext').hide();
jQuery('#noannotations').show();
jQuery('#noannotations').html("There are no annotations.");
}
},
beforeSend: function(response) {loadIt();}
});
},
refresh : function( pagecount ) {
document.previewimage.src = '<?php echo $jpghttppath;?>?' + Date.now();
if (pagecount>1)
{
jQuery('#previewPageOptions').show(); // display selector
pagecount++;
curval=jQuery('#previewpage').val();
jQuery('#previewpage')[0].options.length = 0;
for (x=1;x<pagecount;x++)
{
selected=false;
var selecthtml="";
if (x==curval){selected=true;}
if (selected){selecthtml=' selected="selected" ';}
jQuery('#previewpage').append('<option value='+x+' '+selecthtml+'>'+x+'/'+(pagecount-1)+'</option>');
}
}
else
{
jQuery('#previewPageOptions').hide();
}
},
revert : function() {
jQuery('#previewpage')[0].options.length = 0;
jQuery('#previewpage').append(new Option(1, 1,true,true));
jQuery('#previewpage').value=1;jQuery('#previewPageOptions').hide();
jQuery(this).annotate('preview');
}
};
jQuery.fn.annotate = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
}
};
})(jQuery)
</script>
<script>
function loadIt() {
document.previewimage.src = '<?php echo $baseurl_short?>gfx/images/ajax-loader-on-sheet.gif';}
</script>
<?php } ?>
<div class="BasicsBox" style="float:left;">
<?php
$urlparams = [
'ref' => $ref,
'search' => $search,
'offset' => $offset,
'order_by' => $order_by,
'sort' => $sort,
'archive' => $archive
];
if (!$is_collection){?>
<p><a href="<?php echo generateURL($baseurl_short . 'pages/view.php', $urlparams, ['annotate' => 'true'])?>" onClick="return CentralSpaceLoad(this);"><?php echo LINK_CARET_BACK ?><?php echo escape($lang["backtoresourceview"])?></a></p>
<?php } else {?>
<p><a href="<?php echo generateURL($baseurl_short . 'pages/search.php?', $urlparams, ['search' => '!collection' . substr($ref,1)])?>" onClick="return CentralSpaceLoad(this);"><?php echo LINK_CARET_BACK ?><?php echo escape($lang["backtoresults"])?></a></p>
<?php } ?>
<h1><?php echo escape($lang["annotatepdfconfig"]); ?></h1>
<?php if ($annotate){?>
<div id="heading" style="float:left;margin-bottom:0;" >
<p id="introtext"><?php echo escape($lang["annotatepdfintrotext"])?></p>
</div>
<div style="clear:left;"></div>
<div id="configform" >
<form method=post name="annotateform" id="annotateform" action="<?php echo $baseurl_short?>plugins/annotate/pages/annotate_pdf_gen.php" >
<input type=hidden name="ref" value="<?php echo escape($ref)?>">
<input type=hidden name="annotateid" value="<?php echo escape($annotateid)?>">
<?php
generateFormToken("annotateform");
if ($is_collection){?>
<div class="Question">
<label><?php echo escape($lang["collection"])?></label><div class="Fixed"><?php echo escape(i18n_get_collection_name($collection))?></div>
<div class="clearerleft"> </div>
</div>
<?php } else { ?>
<div class="Question">
<label><?php echo escape($lang["resourcetitle"])?></label><div class="Fixed"><?php echo escape(i18n_get_translated($resources[0]['field'.$view_title_field]))?></div>
<div class="clearerleft"> </div>
</div>
<?php } ?>
<div class="Question">
<label for="size"><?php echo escape($lang["size"])?></label>
<select class="shrtwidth" name="size" id="size" onChange="jQuery().annotate('preview'); "><?php echo $papersize_select ?>
</select>
<div class="clearerleft"> </div>
</div>
<div name="previewPageOptions" id="previewPageOptions" class="Question" style="display:none">
<label for="previewpage"><?php echo escape($lang['previewpage'])?></label>
<select class="shrtwidth" name="previewpage" id="previewpage" onChange="jQuery().annotate('preview'); ">
</select>
</div>
<?php if ($annotate_debug){?><div name="error" id="error"></div><?php } ?>
<?php if ($annotate_debug){?><div name="error2" id="error2"></div><?php } ?>
<div class="QuestionSubmit">
<input name="preview" type="button" value="&nbsp;&nbsp;<?php echo escape($lang["preview"])?>&nbsp;&nbsp;" onClick="jQuery().annotate('preview'); "/>
<input name="save" type="submit" value="&nbsp;&nbsp;<?php echo escape($lang["create"])?>&nbsp;&nbsp;" />
</div>
</form>
</div>
</div>
<div class="BasicsBox" style="float:left;">
<div id="previewdiv" style="float:left;padding:0px -50px 15px 0;height:425px;margin-right:-50px">
<img alt="" id="previewimage" name="previewimage" src=''/>
</div>
</div>
<?php }
?>
<div <?php if ($annotate){?>style="display:none;"<?php } ?> id="noannotations"><?php if (!$annotate){?>There are no annotations.<?php } ?></div></div>
<?php if ($annotate){?>
<script>
jQuery().annotate('preview');
</script>
<?php } ?>
<?php
include "../../../include/footer.php";
?>

View File

@@ -0,0 +1,48 @@
<?php
// this program creates a new PDF document with annotations
include '../../../include/boot.php';
include_once "../include/annotate_functions.php";
include '../../../include/authenticate.php';
global $plugins;
if (!in_array("annotate",$plugins))
{
header("Status: 403 plugin not activated");
exit($lang["error-plugin-not-activated"]);
}
$ref=getval("ref",0);
$size=getval("size","letter");
$color=getval("color","yellow");
$previewpage=getval("previewpage",1,true);
$cleartmp=getval("cleartmp","");
if ($cleartmp!="")
{
echo escape(getval("annotateid",""));
clear_annotate_temp($ref,getval("annotateid",""));
exit("cleared");
}
if(getval("preview","")!="")
{
$preview=true;
}
else
{
$preview=false;
}
$is_collection=false;
if(substr($ref,0,1)=="C")
{
$ref=substr($ref,1);
$is_collection=true;
}
$result=create_annotated_pdf((int)$ref,$is_collection,$size,true,$preview);

View File

@@ -0,0 +1,29 @@
<?php
include_once "../../../include/boot.php";
include_once "../include/annotate_functions.php";
include_once "../../../include/authenticate.php";
$ref=getval("ref", 0, true);
if ($ref==0)
{
die($lang["annotate_ref_not_supplied"]);
}
global $plugins;
if (!in_array("annotate",$plugins))
{
header("Status: 403 plugin not activated");
exit($lang["error-plugin-not-activated"]);
}
$id=getval('id',0,true);
$oldtextnode=ps_value("SELECT node value FROM annotate_notes WHERE ref= ? AND note_id= ?",['i', $ref, 'i', $id],"");
if ($oldtextnode > 0)
{
check_delete_nodes([$oldtextnode]);
}
$notes=ps_query("DELETE FROM annotate_notes WHERE ref= ? AND note_id= ?", ['i', $ref, 'i', $id]);
$notes=ps_query("SELECT COUNT(note_id) FROM annotate_notes WHERE ref= ?", ['i', $ref]);
ps_query("UPDATE resource SET annotation_count= ? WHERE ref= ?", ['i', count($notes), 'i', $ref]);

View File

@@ -0,0 +1,88 @@
<?php
include_once "../../../include/boot.php";
include_once "../include/annotate_functions.php";
$k=getval("k","");if (($k=="") || (!check_access_key(getval("ref",""),$k))) {include_once "../../../include/authenticate.php";}
$ref=getval("ref", 0, true);
if ($ref==0)
{
die($lang["annotate_ref_not_supplied"]);
}
global $plugins;
if (!in_array("annotate",$plugins))
{
header("Status: 403 plugin not activated");
exit($lang["error-plugin-not-activated"]);
}
$preview_width = getval("pw", 0, true);
$preview_height = getval("ph", 0, true);
$page = getval("page", 1, true);
// Get notes based on page:
$sql_and = '';
$sql_params[] = 'i'; $sql_params[] = $ref;
if($page >= 1)
{
$sql_and = ' AND page = ?';
$sql_params[] = 'i'; $sql_params[] = $page;
}
$notes=ps_query("SELECT ref, top_pos, left_pos, width, height, preview_width, preview_height, note_id, user, `page`, node FROM annotate_notes WHERE ref= ?" . $sql_and, $sql_params);
$notecount = count($notes);
ps_query("UPDATE resource SET annotation_count= ? WHERE ref= ?", ['i', $notecount, 'i', $ref]);
// check if display size is different from original preview size, and if so, modify coordinates
for($i=0;$i<$notecount;$i++)
{
$annotate_node =[];
get_node($notes[$i]["node"],$annotate_node);
$notes[$i]["note"] = $annotate_node["name"];
}
$json="[";
$notes_array=array();
for ($x=0;$x<count($notes);$x++)
{
$ratio=$preview_width/$notes[$x]['preview_width'];
$notes[$x]['width']=$ratio*$notes[$x]['width'];
$notes[$x]['height']=$ratio*$notes[$x]['height'];
$notes[$x]['top_pos']=$ratio*$notes[$x]['top_pos'];
$notes[$x]['left_pos']=$ratio*$notes[$x]['left_pos'];
$notes[$x]['note'] = str_replace(chr(13). chr(10), '<br />\n', $notes[$x]['note']);
$notes[$x]['note'] = str_replace(chr(13), '<br />\n', $notes[$x]['note']);
$notes[$x]['note'] = str_replace(chr(10), '<br />\n', $notes[$x]['note']);
if (!$annotate_show_author) # Don't display author unless set in config
{
$notes[$x]['note'] = substr(strstr($notes[$x]['note'],": "),2);
}
if ($x>0){$json.=",";}
$json.="{";
$json.='"top":'.round($notes[$x]['top_pos']).', ';
$json.='"left":'.round($notes[$x]['left_pos']).', ';
$json.='"width":'.round($notes[$x]['width']).', ';
$json.='"height":'.round($notes[$x]['height']).', ';
$json.='"text":"'.config_encode($notes[$x]['note']).'", ';
$json.='"id":"'.$notes[$x]['note_id'].'", ';
if (isset($userref) && (($notes[$x]['user']==$userref) || in_array($usergroup,$annotate_admin_edit_access)))
{
$json.='"editable":true';
}
else
{
$json.='"editable":false';
}
$json.="}";
}
$json.="]";
echo $json;

View File

@@ -0,0 +1,79 @@
<?php
include_once "../../../include/boot.php";
include_once "../include/annotate_functions.php";
include_once "../../../include/authenticate.php";
$ref=getval("ref", 0, true);
if ($ref==0)
{
die($lang["annotate_ref_not_supplied"]);
}
global $plugins;
if (!in_array("annotate",$plugins))
{
header("Status: 403 plugin not activated");
exit($lang["error-plugin-not-activated"]);
}
$top=getval('top','');
$left=getval('left','');
$width=getval('width','');
$height=getval('height','');
$text=getval('text','');
$text=str_replace("<br />\n"," ",$text);// remove the breaks added by get.php
$page = getval('page', 1);
$id=getval('id',0,true);
$preview_width=getval('pw','');
$preview_height=getval('ph','');
$curnode=ps_value("SELECT node value FROM annotate_notes WHERE ref= ? AND note_id= ?",['i', $ref, 'i', $id],"");
if (substr($text,0,strlen($username))!=$username)
{
$text=$username.": ".$text;
}
if ($curnode > 0 && get_nodes_use_count([$curnode]) == 1)
{
// Reuse same node
$savenode = set_node($curnode,$annotate_resource_type_field,$text,null,0);
}
else
{
// Remove node from resource and create new node
delete_resource_nodes($ref,[$curnode]);
$savenode = set_node(null,$annotate_resource_type_field,$text,null,0);
add_resource_nodes($ref,[$savenode], true, true);
}
if ($id > 0)
{
ps_query("DELETE FROM annotate_notes WHERE ref= ? AND note_id= ?", ['i', $ref, 'i', $id]);
}
if (substr($text,0,strlen($username))!=$username)
{
$text=$username.": ".$text;
}
ps_query("INSERT INTO annotate_notes (ref,top_pos,left_pos,width,height,preview_width,preview_height,node,user,`page`) VALUES (?,?,?,?,?,?,?,?,?,?) ",
[
'i',$ref,
'i',$top,
'i',$left,
'i',$width,
'i',$height,
'i',$preview_width,
'i',$preview_height,
'i',$savenode,
'i',$userref,
'i',$page
]
);
$annotateid = sql_insert_id();
echo $annotateid;
$notes=ps_query("SELECT count(note_id) FROM annotate_notes WHERE ref= ?", ['i', $ref]);
ps_query("UPDATE resource SET annotation_count= ? WHERE ref= ?", ['i', count($notes), 'i', $ref]);

View File

@@ -0,0 +1,43 @@
<?php
#
# Annotate setup page
#
// Do the include and authorization checking ritual -- don't change this section.
include '../../../include/boot.php';
include_once "../include/annotate_functions.php";
include '../../../include/authenticate.php'; if (!checkperm('a')) {exit ($lang['error-permissiondenied']);}
$plugin_name = 'annotate';
if(!in_array($plugin_name, $plugins))
{
plugin_activate_for_setup($plugin_name);
}
// Specify the name of this plugin and the heading to display for the page.
$plugin_name = 'annotate';
$plugin_page_heading = $lang['annotate_configuration'];
// Build the $page_def array of descriptions of each configuration variable the plugin uses.
$page_def[] = config_add_text_list_input('annotate_ext_exclude', $lang['extensions_to_exclude']);
$page_def[] = config_add_multi_rtype_select('annotate_rt_exclude', $lang['resource_types_to_exclude']);
$page_def[] = config_add_single_select('annotate_font', $lang['annotate_font'], array('helvetica', 'dejavusanscondensed'), false);
$page_def[] = config_add_boolean_select('annotate_debug', $lang['annotatedebug']);
$page_def[] = config_add_boolean_select('annotate_public_view', $lang['annotate_public_view']);
$page_def[] = config_add_boolean_select('annotate_show_author', $lang['annotate_show_author']);
$page_def[] = config_add_boolean_select('annotate_pdf_output', $lang["annotate_pdf_output"]);
$page_def[] = config_add_boolean_select('annotate_pdf_output_only_annotated', $lang["annotate_pdf_output_only_annotated"]);
$page_def[] = config_add_multi_group_select('annotate_admin_edit_access', $lang["annotate_admin_edit_access"]);
$page_def[] = config_add_single_ftype_select("annotate_resource_type_field", $lang["admin_resource_type_field"],300,false,[FIELD_TYPE_DYNAMIC_KEYWORDS_LIST]);
// Do the page generation ritual -- don't change this section.
config_gen_setup_post($page_def, $plugin_name);
include '../../../include/header.php';
if(empty($annotate_resource_type_field) || $annotate_resource_type_field == 0)
{
?>
<div class="PageInformal"><?php echo escape($lang['annotate_metadatafield_error']); ?></div>
<script>jQuery(document).ready(function(){jQuery('#annotate_resource_type_field').addClass('highlighted');});</script>
<?php
}
config_gen_setup_html($page_def, $plugin_name, null, $plugin_page_heading);
include '../../../include/footer.php';