Exemple #1
0
<?php

pubnode_load_include("PubSourceXmlProcessor.php");
/**
 */
class PLoSProcessor extends PubSourceXmlProcessor
{
    public function __construct()
    {
        parent::__construct("plos");
    }
    public function fileMatchesFormat($file)
    {
        return $this->fileCheckPreamblePattern($file, "//NLM//") && $this->fileCheckRootElement($file, "article");
    }
    public function extractBody()
    {
        $body = $this->transformXmlForView("body");
        // HACK: rewrite img src urls, because no good way to change it by passing a param to the xsl
        // (the $img.src.path setting above doesn't work because unparsed-entity-uri() is returning
        // an absolute filesystem path, which causes $img.src.path to be ignored)
        $reldir = dirname($this->getAbsoluteDocPath());
        $pattern = '{src="([^"]+)/' . $reldir . '}';
        $body = preg_replace($pattern, 'src="' . file_create_url($reldir), $body);
        return $body;
    }
    protected function viewXslBasePath()
    {
        return drupal_get_path('module', 'pubnode_plos') . '/xsl';
    }
    public function addCss()
Exemple #2
0
<?php

pubnode_load_include("PubSourceImporter.php");
class PubSourceZipUploadImporter extends PubSourceImporter
{
    protected $fieldname;
    public function __construct($fieldname = "upload_main")
    {
        $this->fieldname = $fieldname;
    }
    public function willImport($form_state)
    {
        $fieldname = $this->fieldname;
        if (isset($_FILES['files']) && $_FILES['files']['name'][$fieldname] && is_uploaded_file($_FILES['files']['tmp_name'][$fieldname])) {
            $filename = trim(basename($_FILES['files']['name'][$fieldname]), '.');
            return preg_match('{\\.zip$}', $filename);
        }
        return FALSE;
    }
    /**
     * 'upload_zip' upload field must refer to a zip file containing 
     *   all files for the pubnode (may be at top-level or inside a subdirectory)
     */
    public function import(&$form_state, $docid = NULL)
    {
        $validators = array('file_validate_extensions' => array('zip'), 'file_validate_size' => array(100000000, 0));
        if ($file = file_save_upload($this->fieldname, $validators, file_directory_temp(), FILE_EXISTS_REPLACE)) {
            $zip = new ZipArchive();
            if ($zip->open($file->filepath) !== TRUE) {
                form_set_error(t("Cannot open !file", array("!file" => $file->filename)), 'error');
                return FALSE;
Exemple #3
0
 /** 
  * @param $spec any object containing a 'module' and a 'class' field.
  */
 protected function createLocal($cls)
 {
     pubnode_load_include("{$cls}.php");
     return new $cls();
 }