Skip to content

Commit

Permalink
add matcher for Siteplus
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofiia Kulish committed Dec 17, 2024
1 parent 0124610 commit 348935a
Show file tree
Hide file tree
Showing 9 changed files with 2,104 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Command-line interface utility to analyze the file structure of a web hosting se
| Sitejet | The `index.html` file exists and contains the `ed-element` and `webcard.apiHost=` strings |
| WebPresenceBuilder | The `index.html` file contains the `<meta name="generator" content="Web Presence Builder <vesrion>">` tag or contains the following DOM structure: the `div` tag with the `page` ID contains the `div` tags with the `watermark` and `layout` IDs |
| Site.pro | The `sitepro` folder exists and the `sitepro` string is contained in the `web.config` or `.htaccess` files |
| Duda.co | The `Style` folder contains the `desktop.css`, `mobile.css`, or `tablet.css` files. The style file contains the `dmDudaonePreviewBody` or `dudaSnipcartProductGalleryId` strings, or the `Scripts/runtime.js` file contains the `duda` string. |
| Duda.co | The `Style` folder contains the `desktop.css`, `mobile.css`, or `tablet.css` files. The style file contains the `dmDudaonePreviewBody` or `dudaSnipcartProductGalleryId` strings, or the `Scripts/runtime.js` file contains the `duda` string |
| Siteplus | The `index.html` file exists and contains the `edit.site` string, and the `/bundle/publish/<version>` directory exists and contains the `bundle.js` file. The `bundle.js` file contains the `siteplus` string |

## How to build phar
```shell
Expand Down
12 changes: 12 additions & 0 deletions src/MatchResult/Siteplus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);


namespace Plesk\Wappspector\MatchResult;

class Siteplus extends MatchResult
{
public const ID = 'siteplus';
public const NAME = 'Siteplus';
}
53 changes: 53 additions & 0 deletions src/Matchers/Siteplus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Plesk\Wappspector\Matchers;

use League\Flysystem\Filesystem;
use Plesk\Wappspector\Helper\InspectorHelper;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Siteplus as MatchResult;

class Siteplus implements MatcherInterface
{
private const PUBLISH_DIR_PATH = '/bundle/publish';

public function match(Filesystem $fs, string $path): MatchResultInterface
{
$rTrimPath = rtrim($path, '/');

$inspectorHelper = new InspectorHelper();

if (!$inspectorHelper->fileContainsString($fs, $rTrimPath . '/index.html', 'edit.site')) {
return new EmptyMatchResult();
}

if (!$fs->directoryExists($rTrimPath . self::PUBLISH_DIR_PATH)) {
return new EmptyMatchResult();
}

$publishDirList = $fs->listContents($rTrimPath . self::PUBLISH_DIR_PATH, false);

// do not check if the item is a directory as on the server when the files a copied the type of the
// directory is determined as 'file'.
// By default, there should be just 1 directory in the publish directory
$versionDirPath = $publishDirList->toArray()[0]['path'] ?? null;

if ($versionDirPath === null) {
return new EmptyMatchResult();
}

return $inspectorHelper->fileContainsString($fs, $versionDirPath . '/bundle.js', 'siteplus')
? new MatchResult($rTrimPath, $this->getSiteplusVersion($versionDirPath))
: new EmptyMatchResult();
}

private function getSiteplusVersion(string $versionDirPath): string
{
// get the last part of the path
$versionDirPathParts = explode('/', $versionDirPath);
return end($versionDirPathParts);
}
}
1 change: 1 addition & 0 deletions src/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Matchers\WebPresenceBuilder::class,
Matchers\Sitepro::class,
Matchers\Duda::class,
Matchers\Siteplus::class,

// Low priority wrappers. Should go last.
Matchers\Composer::class,
Expand Down
1 change: 1 addition & 0 deletions test-data/siteplus/0.58.3/bundle/publish/0.58.3/bundle.js

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions test-data/siteplus/0.58.3/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-data/siteplus/0.58.7/bundle/publish/0.58.7/bundle.js

Large diffs are not rendered by default.

Loading

0 comments on commit 348935a

Please sign in to comment.