Skip to content

Commit 6f3e93d

Browse files
authored
Merge pull request #29 from Copyleaks/AI-code-detection-sunset-v2
warning message for deprecation for relevant users
2 parents b923411 + 63ca1f0 commit 6f3e93d

File tree

11 files changed

+161
-47
lines changed

11 files changed

+161
-47
lines changed

composer.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
{
22
"name": "copyleaks/php-plagiarism-checker",
33
"description": "Copyleaks detects online plagiarism and checks content distribution. Use Copyleaks to find out if textual content is original and where it has been used before. This package shows how to integrate with the Copyleaks cloud to search for copyright infringement.",
4-
"scripts": {
5-
"post-install-cmd": [
6-
"php deprecation-notice.php"
7-
],
8-
"post-update-cmd": [
9-
"php deprecation-notice.php"
10-
]
11-
},
12-
"minimum-stability": "dev",
4+
"minimum-stability": "dev",
135
"prefer-stable": true,
146
"require": {
157
"php": ">=7.4.0"

demo/composer.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
{
22
"name": "copyleaks/demo",
3-
"scripts": {
4-
"post-install-cmd": [
5-
"php ../deprecation-notice.php"
6-
],
7-
"post-update-cmd": [
8-
"php ../deprecation-notice.php"
9-
]
10-
},
113
"authors": [
124
{
135
"name": "Bayan Abuawad",

demo/demo.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ public function run(string $email, string $key, string $webook) {
6666

6767
// $this->TEST_submitUrl($loginResult);
6868

69-
$this->TEST_submitFile($loginResult);
69+
// $this->TEST_submitFile($loginResult);
7070

7171
// $this->TEST_submitOcrFile($loginResult);
7272

7373
// $this->TEST_export($loginResult);
7474

7575
// $this->TEST_aiDetectionSubmitNaturalLanguage($loginResult);
7676

77-
// $this->TEST_aiDetectionSubmitSourceCode($loginResult);
77+
$this->TEST_aiDetectionSubmitSourceCode($loginResult);
7878

7979
// $this->TEST_writingAssistant($loginResult);
80-
$this->TEST_textModeration($loginResult);
80+
// $this->TEST_textModeration($loginResult);
8181

8282

8383
} catch (Throwable $th) {
@@ -125,7 +125,7 @@ private function TEST_submitOcrFile(CopyleaksAuthToken $authToken) {
125125

126126
private function TEST_submitFile(CopyleaksAuthToken $authToken) {
127127
$submission = new CopyleaksFileSubmissionModel(
128-
"aGVsbG8gd29ybGQ=",
128+
"SGVsbG8gV29ybGQ=",
129129
"php.txt",
130130
new SubmissionProperties(
131131
new SubmissionWebhooks("$this->webookUrl/{STATUS}"),

deprecation-notice.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Models/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
include_once('submissions/index.php');
3434

3535
include_once('exports/index.php');
36-
36+
include_once('constants/Index.php');
3737
include_once('exceptions/Index.php');
3838
include_once('textModeration/index.php');

src/Models/constants/Index.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/*
3+
The MIT License(MIT)
4+
5+
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
*/
25+
26+
namespace Copyleaks;
27+
28+
include_once('SupportedFilesTypes.php');
29+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/*
3+
The MIT License(MIT)
4+
5+
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
*/
25+
namespace Copyleaks;
26+
27+
class SupportedFilesTypes
28+
{
29+
public const SUPPORTED_CODE_EXTENSIONS = [
30+
'ts',
31+
'py',
32+
'go',
33+
'cs',
34+
'c',
35+
'h',
36+
'idc',
37+
'cpp',
38+
'hpp',
39+
'c++',
40+
'h++',
41+
'cc',
42+
'hh',
43+
'java',
44+
'js',
45+
'swift',
46+
'rb',
47+
'pl',
48+
'php',
49+
'sh',
50+
'm',
51+
'scala',
52+
'rs',
53+
'vbs',
54+
'css'
55+
];
56+
}

src/clients/AIDetectionClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
namespace Copyleaks;
2727

2828
use InvalidArgumentException;
29-
29+
use Copyleaks\DeprecationService;
3030
class AIDetectionClient
3131
{
3232
/**
@@ -87,7 +87,7 @@ public function submitSourceCode(CopyleaksAuthToken $authToken, string $scanId,
8787
}
8888

8989
CopyleaksClientUtils::verifyAuthToken($authToken);
90-
90+
DeprecationService::showDeprecationMessage();
9191
$url = CopyleaksConfig::GET_API_SERVER_URI() . "/v2/writer-detector/source-code/$scanId/check";
9292
$authorization = "Authorization: Bearer " . $authToken->accessToken;
9393
$headers = array('Content-Type: application/json', 'User-Agent: ' . CopyleaksConfig::GET_USER_AGENT(), $authorization);

src/copyleaks.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
use Copyleaks\AIDetectionClient;
3131
use Copyleaks\WritingAssistantClient;
3232
use Copyleaks\TextModerationClient;
33-
33+
use Copyleaks\SupportedFilesTypes;
34+
use Copyleaks\DeprecationService;
3435
use InvalidArgumentException;
3536

3637
class Copyleaks
@@ -131,6 +132,15 @@ public function submitFile(CopyleaksAuthToken $authToken, string $scanId, Copyle
131132

132133
$this->verifyAuthToken($authToken);
133134

135+
$fileExtension = $this->getFileExtension($submission->filename);
136+
if (empty($fileExtension)) {
137+
error_log("Unable to determine file extension for: " . $submission->filename);
138+
throw new \Exception("File extension could not be determined");
139+
}
140+
if (in_array($fileExtension, SupportedFilesTypes::SUPPORTED_CODE_EXTENSIONS)) {
141+
DeprecationService::showDeprecationMessage();
142+
}
143+
134144
$url = CopyleaksConfig::GET_API_SERVER_URI() . "/v3/scans/submit/file/$scanId";
135145

136146
$authorization = "Authorization: Bearer $authToken->accessToken";
@@ -141,7 +151,19 @@ public function submitFile(CopyleaksAuthToken $authToken, string $scanId, Copyle
141151

142152
HttpClientService::Execute('PUT', $url, $headers, $submission);
143153
}
144-
154+
function getFileExtension($filename)
155+
{
156+
if (empty($filename)) {
157+
return '';
158+
}
159+
160+
$lastDotPos = strrpos($filename, '.');
161+
if ($lastDotPos !== false && $lastDotPos < strlen($filename) - 1) {
162+
return strtolower(substr($filename, $lastDotPos + 1));
163+
}
164+
165+
return '';
166+
}
145167
/**
146168
* Starting a new process by providing a OCR image file to scan.
147169
* For more info:

src/deprecationService.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
The MIT License(MIT)
4+
5+
Copyright(c) 2016 Copyleaks LTD (https://copyleaks.com)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
*/
25+
namespace Copyleaks;
26+
27+
class DeprecationService
28+
{
29+
public static function showDeprecationMessage()
30+
{
31+
// Trace equivalent - using error_log for logging
32+
error_log("DEPRECATION NOTICE: AI Code Detection will be discontinued on August 29, 2025. Please remove AI code detection integrations before the sunset date.");
33+
34+
// Red colored console output using ANSI escape codes
35+
echo "\033[31m"; // Red color
36+
echo "════════════════════════════════════════════════════════════════════\n";
37+
echo "DEPRECATION NOTICE !!!\n";
38+
echo "AI Code Detection will be discontinued on August 29, 2025.\n";
39+
echo "Please remove AI code detection integrations before the sunset date.\n";
40+
echo "════════════════════════════════════════════════════════════════════\n";
41+
echo "\033[0m"; // Reset color
42+
}
43+
}

0 commit comments

Comments
 (0)