Skip to content

Commit

Permalink
Detect SPIP version
Browse files Browse the repository at this point in the history
* Add SPIP adapter
* Detect by spip.php or spip_loader.php

Reference :
* CMS-Garden#76
  • Loading branch information
camlafit committed Dec 30, 2021
1 parent 6b808e6 commit bea01b2
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Command/AbstractDetectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Cmsgarden\Cmsscanner\Detector\Adapter\PrestashopAdapter;
use Cmsgarden\Cmsscanner\Detector\Adapter\RedaxoAdapter;
use Cmsgarden\Cmsscanner\Detector\Adapter\ShopwareAdapter;
use Cmsgarden\Cmsscanner\Detector\Adapter\SpipAdapter;
use Cmsgarden\Cmsscanner\Detector\Adapter\Typo3CmsAdapter;
use Cmsgarden\Cmsscanner\Detector\Adapter\WordpressAdapter;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -69,6 +70,7 @@ public function __construct($name = null)
->addAdapter(new WordpressAdapter())
->addAdapter(new DrupalAdapter())
->addAdapter(new Typo3CmsAdapter())
->addAdapter(new SpipAdapter())
;
}

Expand Down
111 changes: 111 additions & 0 deletions src/Detector/Adapter/SpipAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* @package CMSScanner
* @copyright Copyright (C) 2014 - 2021 CMS-Garden.org
* @license MIT <https://tldrlegal.com/license/mit-license>
* @link https://www.cms-garden.org
*/

namespace Cmsgarden\Cmsscanner\Detector\Adapter;

use Cmsgarden\Cmsscanner\Detector\System;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

/**
* Class PrestashopAdapter
* @package Cmsgarden\Cmsscanner\Detector\Adapter
*
* @since 1.0.0
*/
class SpipAdapter implements AdapterInterface
{

/**
* Version detection information for Spip
* @var array
*/
protected $versions = array(
array( // 6.x
'filename' => '/ecrire/inc_version.php',
'regexp' => '/\s*\$spip_version_branche\s*=\s*[\'"](.*)[\'"]\s*/',
),
);

/**
* SPIP has a file called version.php that can be used to search for working installations
*
* @param Finder $finder finder instance to append the criteria
*
* @return Finder
*/
public function appendDetectionCriteria(Finder $finder)
{
$finder->name('spip.php');
$finder->name('spip_loader.php');
return $finder;
}

/**
* try to verify a search result and work around some well known false positives
*
* @param SplFileInfo $file file to examine
*
* @return bool|System
*/
public function detectSystem(SplFileInfo $file)
{
$fileName = $file->getFilename();
if ($fileName !== "spip.php" && $fileName !== "spip_loader.php") {
return false;
}
$path = new \SplFileInfo($file->getPathInfo()->getPath());

// Return result if working
return new System($this->getName(), $path);
}

/**
* determine version of a SPIP installation within a specified path
*
* @param \SplFileInfo $path directory where the system is installed
*
* @return null|string
*/
public function detectVersion(\SplFileInfo $path)
{
foreach ($this->versions as $version) {
$sysEnvBuilder = $path->getRealPath() . $version['filename'];
if (!file_exists($sysEnvBuilder)) {
continue;
}
if (!is_readable($sysEnvBuilder)) {
throw new \RuntimeException(sprintf("Unreadable version information file %s", $sysEnvBuilder));
}
if (preg_match($version['regexp'], file_get_contents($sysEnvBuilder), $matches)) {
if (count($matches) > 1) {
return str_replace(',', '.', $matches[1]);
}
}
}
// this must not happen usually
return null;
}

/**
* @InheritDoc
*/
public function detectModules(\SplFileInfo $path)
{
// TODO implement this function
return false;
}

/***
* @return string
*/
public function getName()
{
return 'SPIP';
}
}

0 comments on commit bea01b2

Please sign in to comment.