Changeset fcf3700


Ignore:
Timestamp:
04/30/10 15:46:52 (2 years ago)
Author:
maparent <maparent@…>
Branches:
('master', '8434b8322dd6f8ff37c17bd45b94e7a826f86b53')('vitrine', 'afe109c61a407808bd54d88bcccb1cde726a010a')
Children:
a04edbd9894622947728b10e2d889e6975b35391
Parents:
ad3626832640a4cfafb8e5960b72d0e8dec9819b
git-author:
maparent <maparent@9a151f2f-a8df-0310-a5c5-9fb547312938>2010-04-30 19:46:52+00:00
git-committer:
maparent <maparent@9a151f2f-a8df-0310-a5c5-9fb547312938>2010-04-30 19:46:52+00:00
Message:

Basic XSLT for spiders

git-svn-id: http://projects.coeus.ca/svn/eureka@564 9a151f2f-a8df-0310-a5c5-9fb547312938

Location:
trunk/html
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/html/admin/spider_admin.php

    r73ff047 rfcf3700  
    8585              } 
    8686 
    87               if($spider){echo "<form method='POST' action=''>\n"; 
     87              if($spider){echo "<form method='POST' action='' enctype='multipart/form-data'>\n"; 
    8888              echo "<input type='hidden' name='spider_id' value='{$spider->getId()}'>\n"; 
    8989              // Show admin UI 
  • trunk/html/classes/AbstractSpider.php

    rf1a2cb0 rfcf3700  
    154154        echo "<tr class='even'><td><b>"._("Feed URL")." : </b></td><td><input type='text' size='50' name='rep_base_url' value='{$this->getBaseUrl()}'></td></tr>\n"; 
    155155 
    156         echo "<tr class='ood'><td><b>"._("Base synchronization theme")." : </b></td><td>"; 
     156        echo "<tr class='odd'><td><b>"._("Base synchronization theme")." : </b></td><td>"; 
    157157        $vocabulary = new Vocabulary(VOC_EUREKA_THEME); 
    158158        if (($selected_theme = $this->getBaseTheme()) == null) 
     
    178178            echo sprintf(_("Last sync started %s and finised %s"), $this->getLastSyncStartTime(), $last_sync_date); 
    179179        } 
     180 
     181        echo "</tr>\n"; 
     182        echo "<tr class='even'><td><b>"._("XSLT Transformation")."</b>"; 
     183        $transform = $this->getXslTransform(); 
     184        if (strlen($transform) == 0) { 
     185            echo ' (<i>'._("none").'</i>)'; 
     186        } 
     187        echo "</td>\n<td><INPUT TYPE='hidden' name='MAX_FILE_SIZE' value='20000' />"; 
     188        echo "<input name='xsl_transform_import' type='file' /><br/>"; 
     189        echo "<textarea name='xsl_transform_content' rows='20' cols='80' wrap='off'>"; 
     190        echo htmlspecialchars($transform); 
     191        echo "</textarea>"; 
     192        echo "</td></tr>\n"; 
     193 
    180194        echo $childUi; 
    181195        echo "</table>\n"; 
     
    202216        { 
    203217            $this->setMetaDataExchangeFormat($_REQUEST['import_format']); 
     218        } 
     219        if (isset($_FILES['xsl_transform_import']['tmp_name']) 
     220            && $_FILES['xsl_transform_import']['tmp_name'] != '') { 
     221            $xsl = file_get_contents($_FILES['xsl_transform_import']['tmp_name']); 
     222        } else { 
     223            $xsl = $_REQUEST['xsl_transform_content']; 
     224        } 
     225        $xsl_dom = new DOMDocument(); 
     226        if ($xsl_dom->loadXml($xsl)) { 
     227            // TODO: Also check it is valid XSLT 
     228            $this->setXslTransform($xsl); 
     229        } else { 
     230            // If not XML, clear it. 
     231            $this->setXslTransform(''); 
    204232        } 
    205233 
     
    387415    } 
    388416 
     417    public function getXslTransform() 
     418    { 
     419        return $this->row['xsl_transform']; 
     420    } 
     421 
     422    public function setXslTransform($xsl) 
     423    { 
     424        $db=AbstractDb::getObject(); 
     425        $xsl = $db->EscapeString($xsl); 
     426        $db->execSqlUpdate("UPDATE spiders SET xsl_transform = '{$xsl}' WHERE spider_id = {$this->getId()};", false); 
     427        $this->refresh(); 
     428        return true; 
     429    } 
     430 
    389431    /** Run spider */ 
    390432    abstract protected function harvest($verbose=false); 
     
    451493        } 
    452494    } 
     495    protected function transformDoc($xml_dom) { 
     496        if (!isset($this->xsl_proc_cache)) { 
     497            $this->xsl_proc_cache = null; 
     498            $xsl = $this->getXslTransform(); 
     499            if (isset($xsl) && $xsl != '') { 
     500                $xsl_proc = new XSLTProcessor(); 
     501                $xsl_dom = new DOMDocument();  
     502                if ($xsl_dom->loadXml( $xsl )) { 
     503                    $xsl_proc->importStylesheet( $xsl_dom ); 
     504                    $this->xsl_proc_cache = $xsl_proc; 
     505                } 
     506            } 
     507        } 
     508        if ($this->xsl_proc_cache != null) { 
     509            $new_dom = $this->xsl_proc_cache->transformToDoc( $xml_dom ); 
     510            if ($new_dom) { 
     511                return $new_dom; 
     512            } 
     513        } 
     514        return $xml_dom; 
     515    } 
    453516} 
    454517 
  • trunk/html/classes/SpiderFeed.php

    r632619d rfcf3700  
    6767        else             { 
    6868            // Download the DOM document 
    69             $xml_dom = $xml_dom = DOMDocument :: load($this->getBaseURL()); 
     69            $xml_dom = DOMDocument :: load($this->getBaseURL()); 
    7070            if($xml_dom == null) { 
    7171                $this->reportAppend(sprintf(_("unable to retrieve feed at %s"), $this->getBaseURL())."<br>\n"); 
    7272            } 
    7373            else { 
     74                // TODO: Apply to items only?  
     75                $document = $this->transformDoc($document); 
    7476                // Create a XPath query object 
    7577                $xpath = new DOMXPath($xml_dom); 
  • trunk/html/classes/SpiderHTML.php

    r25259d1 rfcf3700  
    163163                    else { 
    164164                        $log .= sprintf("<strong>Processing <a href='%s'>%s</a></strong></td></tr><tr><td>\n", $link_url, $link["caption"]); 
     165                        $document = $this->transformDoc($document); 
    165166                        // Create an XPath for queries and register a default namespace for it. 
    166167                        $xpath = new DOMXPath($document); 
  • trunk/html/classes/SpiderOaiPmhClient.php

    r7e23ae3 rfcf3700  
    265265                // load the DOM in RAM 
    266266                $xml_dom = DOMDocument :: loadXML($xml_file_content); 
     267                $xml_dom = $this->transformDoc($xml_dom); 
    267268                if (OAI_PMH_VALIDATE_ENABLED && !$xml_dom->schemaValidate(OAI_PMH_VALIDATE_SCHEMA)) 
    268269                { 
  • trunk/html/include/schema_validate.php

    r72f6cf3 rfcf3700  
    409409        } 
    410410 
     411        $new_schema_version = 21; 
     412        if ($current_schema_version < $new_schema_version && $new_schema_version <= REQUIRED_SCHEMA_VERSION) 
     413        { 
     414            echo "<h2>"._("Preparing SQL statements to update schema to version:")." $new_schema_version</h2>"; 
     415            $sql .= "UPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     416            $sql .= "ALTER TABLE spiders ADD COLUMN xsl_transform text;\n"; 
     417        } 
     418 
    411419        $db->execSqlUpdate("BEGIN;\n$sql\nCOMMIT;\n", true); 
    412420        $db->execSqlUpdate("VACUUM ANALYSE;\n", true); 
Note: See TracChangeset for help on using the changeset viewer.