Dotclear


Ignore:
Timestamp:
10/02/13 01:42:40 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
dcRepo
Message:

Document and clean up dcRepository classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.repository.php

    r2156 r2214  
    11<?php 
    2  
     2# -- BEGIN LICENSE BLOCK --------------------------------------- 
     3# 
     4# This file is part of Dotclear 2. 
     5# 
     6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     7# Licensed under the GPL version 2.0 license. 
     8# See LICENSE file or 
     9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     10# 
     11# -- END LICENSE BLOCK ----------------------------------------- 
     12if (!defined('DC_RC_PATH')) { return; } 
     13 
     14/** 
     15@ingroup DC_CORE 
     16@brief Repository modules XML feed reader 
     17 
     18Provides an object to parse XML feed of modules from repository. 
     19*/ 
    320class dcRepository 
    421{ 
     22     /** @var  object    dcCore instance */ 
    523     public $core; 
     24     /** @var  object    dcModules instance */ 
    625     public $modules; 
    726 
     27     /** @var  string    User agent used to query repository */ 
     28     protected $user_agent = 'DotClear.org RepoBrowser/0.1'; 
     29     /** @var  string    XML feed URL */ 
    830     protected $xml_url; 
     31     /** @var  array     Array of new/update modules from repository */ 
    932     protected $data; 
    1033 
     34     /** 
     35      * Constructor. 
     36      * 
     37      * @param object    $modules       dcModules instance 
     38      * @param string    $xml_url       XML feed URL 
     39      */ 
    1140     public function __construct(dcModules $modules, $xml_url) 
    1241     { 
     
    1443          $this->modules = $modules; 
    1544          $this->xml_url = $xml_url; 
    16      } 
    17  
     45          $this->user_agent = sprintf('Dotclear/%s)', DC_VERSION); 
     46     } 
     47 
     48     /** 
     49      * Check repository. 
     50      * 
     51      * @param boolean   $force         Force query repository 
     52      * @return     boolean   True if get feed or cache 
     53      */ 
    1854     public function check($force=false) 
    1955     { 
     
    5894     } 
    5995 
     96     /** 
     97      * Get a list of modules. 
     98      * 
     99      * @param boolean   $update   True to get update modules, false for new ones 
     100      * @return     array     List of update/new modules 
     101      */ 
    60102     public function get($update=false) 
    61103     { 
     
    63105     } 
    64106 
     107     /** 
     108      * Search a module. 
     109      * 
     110      * Search string is cleaned, split and compare to split: 
     111      * - module id and clean id, 
     112      * - module name, clean name, 
     113      * - module desccription. 
     114      * 
     115      * Every time a part of query is find on module, 
     116      * result accuracy grow. Result is sorted by acuracy. 
     117      * 
     118      * @param string    $pattern  String to search 
     119      * @return     array     Match modules 
     120      */ 
    65121     public function search($pattern) 
    66122     { 
     
    100156     } 
    101157 
     158     /** 
     159      * Quick download and install module. 
     160      * 
     161      * @param string    $url Module package URL 
     162      * @param string    $dest     Path to install module 
     163      * @return     integer        1 = installed, 2 = update 
     164      */ 
    102165     public function process($url, $dest) 
    103166     { 
     
    106169     } 
    107170 
     171     /** 
     172      * Download a module. 
     173      * 
     174      * @param string    $url Module package URL 
     175      * @param string    $dest     Path to put module package 
     176      */ 
    108177     public function download($url, $dest) 
    109178     { 
     
    123192     } 
    124193 
     194     /** 
     195      * Install a previously downloaded module. 
     196      * 
     197      * @param string    $path     Module package URL 
     198      * @param string    $path     Path to module package 
     199      * @return     integer        1 = installed, 2 = update 
     200      */ 
    125201     public function install($path) 
    126202     { 
     
    128204     } 
    129205 
    130      public static function agent() 
    131      { 
    132           return sprintf('Dotclear/%s)', DC_VERSION); 
    133      } 
    134  
     206     /** 
     207      * User Agent String. 
     208      * 
     209      * @param string    $str      User agent string 
     210      */ 
     211     public function agent($str) 
     212     { 
     213          $this->user_agent = $str; 
     214     } 
     215 
     216     /** 
     217      * Sanitize string. 
     218      * 
     219      * @param string    $str      String to sanitize 
     220      * @param null $_        Unused    param 
     221      */ 
    135222     public static function sanitize(&$str, $_) 
    136223     { 
     
    138225     } 
    139226 
    140      private static function compare($v1,$v2,$op) 
    141      { 
    142           $v1 = preg_replace('!-r(\d+)$!','-p$1',$v1); 
    143           $v2 = preg_replace('!-r(\d+)$!','-p$1',$v2); 
    144           return version_compare($v1,$v2,$op); 
    145      } 
    146  
     227     /** 
     228      * Compare version. 
     229      * 
     230      * @param string    $v1       Version 
     231      * @param string    $v2       Version 
     232      * @param string    $op       Comparison operator 
     233      * @return     boolean   True is comparison is true, dude! 
     234      */ 
     235     private static function compare($v1, $v2, $op) 
     236     { 
     237          return version_compare( 
     238               preg_replace('!-r(\d+)$!', '-p$1', $v1),  
     239               preg_replace('!-r(\d+)$!', '-p$1', $v2),  
     240               $op 
     241          ); 
     242     } 
     243 
     244     /**  
     245      * Sort modules list. 
     246      * 
     247      * @param array     $a        A module 
     248      * @param array     $b        A module 
     249      * @return     integer 
     250      */ 
    147251     private static function sort($a,$b) 
    148252     { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map