|
1 | | -# Copyleaks PHP SDK |
| 1 | +# Copyleaks SDK |
| 2 | +The official [Copyleaks](https://copyleaks.com/) PHP library, supporting PHP versions >=7.4.0. |
2 | 3 |
|
3 | | -Copyleaks SDK is a simple framework that allows you to scan text for plagiarism and detect content distribution online, using the Copyleaks plagiarism checker cloud. |
| 4 | +## 🚀 Getting Started |
| 5 | +Before you start, ensure you have the following: |
4 | 6 |
|
5 | | -Using Copyleaks SDK you can check for plagiarism in: |
6 | | -* Online content and webpages |
7 | | -* Local and cloud files (see [supported files](https://api.copyleaks.com/documentation/specifications#2-supported-file-types)) |
8 | | -* Free text |
9 | | -* OCR (Optical Character Recognition) - scanning pictures with textual content (see [supported files](https://api.copyleaks.com/documentation/specifications#6-supported-image-types-ocr)) |
| 7 | +* An active Copyleaks account. If you don’t have one, [sign up for free](https://copyleaks.com/signup). |
| 8 | +* You can find your API key on the [API Dashboard](https://api.copyleaks.com/dashboard). |
10 | 9 |
|
11 | | -## Installation |
| 10 | +Once you have your account and API key: |
12 | 11 |
|
13 | | -Install using [Packagist](https://packagist.org/packages/copyleaks/php-plagiarism-checker) |
| 12 | +**Install the SDK**: |
14 | 13 |
|
| 14 | +Install using [Packagist](https://packagist.org/packages/copyleaks/php-plagiarism-checker) |
15 | 15 | ```bash |
16 | 16 | composer require copyleaks/php-plagiarism-checker |
17 | 17 | ``` |
18 | 18 |
|
19 | | -## Register and Get Your API Key |
20 | | -To use the Copyleaks API you need to first be a registered user. The registration to Copyleaks takes a minute and is free of charge. [Signup](https://api.copyleaks.com/?register=true) and make sure to confirm your account. |
| 19 | +## 📚 Documentation |
| 20 | +To learn more about how to use Copyleaks API please check out our [Documentation](https://docs.copyleaks.com/resources/sdks/php/). |
| 21 | + |
| 22 | +## 💡 Usage Examples |
| 23 | +Here are some common usage examples for the Copyleaks SDK. You can also see a comprehensive code example in the `demo.php` file on our GitHub repository: [demo.php](https://github.com/Copyleaks/PHP-Plagiarism-Checker/blob/master/demo/demo.php). |
| 24 | + |
| 25 | +### Get Authentication Token |
| 26 | +This example demonstrates how to log in to the Copyleaks API and obtain an authentication token. |
| 27 | + |
| 28 | +```php |
| 29 | +<?php |
| 30 | + |
| 31 | + require_once(__DIR__ . '/vendor/autoload.php'); |
21 | 32 |
|
22 | | -As a signed user you can generate your personal API key. Do so on your [dashboard home](https://api.copyleaks.com/dashboard) under 'API Access Credentials'. |
| 33 | + use Copyleaks\Copyleaks; |
| 34 | + use Copyleaks\CopyleaksFileSubmissionModel; |
| 35 | + use Copyleaks\SubmissionProperties; |
| 36 | + use Copyleaks\SubmissionWebhooks; |
23 | 37 |
|
24 | | -For more information check out our [API guide](https://api.copyleaks.com/documentation/v3). |
| 38 | + // --- Your Credentials --- |
| 39 | + $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS'; |
| 40 | + $KEY = 'YOUR_API_KEY'; |
| 41 | + $WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}'; |
| 42 | + // -------------------- |
| 43 | + |
| 44 | + // Log in to the Copyleaks API |
| 45 | + echo "Authenticating...\n"; |
| 46 | + $copyleaks = new Copyleaks(); |
| 47 | + $loginToken = $copyleaks->login($EMAIL_ADDRESS, $KEY); |
| 48 | + echo "✅ Logged in successfully!\n"; |
| 49 | + |
| 50 | +``` |
| 51 | +For a detailed understanding of the authentication process, refer to the Copyleaks Login Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/account/login). |
| 52 | +## |
| 53 | +### Submit Text for Plagiarism Scan |
| 54 | +This example shows how to prepare and submit raw text content for a plagiarism scan. |
25 | 55 |
|
26 | | -## Usage |
27 | 56 | ```php |
28 | | -include_once('vendor/copyleaks/php-plagiarism-checker/autoload.php'); |
29 | | -use Copyleaks\Copyleaks; |
| 57 | +<?php |
| 58 | + |
| 59 | + require_once(__DIR__ . '/vendor/autoload.php'); |
| 60 | + |
| 61 | + use Copyleaks\Copyleaks; |
| 62 | + use Copyleaks\CopyleaksFileSubmissionModel; |
| 63 | + use Copyleaks\SubmissionProperties; |
| 64 | + use Copyleaks\SubmissionWebhooks; |
| 65 | + |
| 66 | + // --- Your Credentials --- |
| 67 | + $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS'; |
| 68 | + $KEY = 'YOUR_API_KEY'; |
| 69 | + $WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}'; |
| 70 | + // -------------------- |
| 71 | + |
| 72 | + // Prepare your content for scanning |
| 73 | + echo "Submitting text for scanning...\n"; |
| 74 | + $textToScan = "Hello world, this is a test."; |
| 75 | + $base64Content = base64_encode($textToScan); |
| 76 | + $scanId = time(); |
| 77 | + |
| 78 | + // Configure the scan |
| 79 | + $webhooks = new SubmissionWebhooks($WEBHOOK_URL); |
| 80 | + $properties = new SubmissionProperties($webhooks); |
| 81 | + $properties->setSandbox(true); // Turn on sandbox mode for testing |
| 82 | + |
| 83 | + $submission = new CopyleaksFileSubmissionModel($base64Content, 'test.txt', $properties); |
| 84 | + |
| 85 | + // Submit the scan to Copyleaks |
| 86 | + $copyleaks->submitFile($loginToken, $scanId, $submission); |
| 87 | + echo "🚀 Scan submitted successfully! Scan ID: " . $scanId . "\n"; |
| 88 | + echo "You will be notified via your webhook when the scan is complete.\n"; |
| 89 | + |
| 90 | +``` |
| 91 | +For a full guide please refer to our step by step [Guide](https://docs.copyleaks.com/guides/authenticity/detect-plagiarism-text) |
| 92 | + |
| 93 | +For a detailed understanding of the plagiarism detection process, refer to the Copyleaks Submit Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/scans/submit-file) |
| 94 | +## |
| 95 | +### AI-Generated Text Detection |
| 96 | +Use the AI detection client to determine if content was generated by artificial intelligence. |
| 97 | + |
| 98 | +```php |
| 99 | +<?php |
| 100 | + |
| 101 | + require_once(__DIR__ . '/vendor/autoload.php'); |
| 102 | + |
| 103 | + use Copyleaks\Copyleaks; |
| 104 | + use Copyleaks\CopyleaksNaturalLanguageSubmissionModel; |
| 105 | + |
| 106 | + // --- Your Credentials --- |
| 107 | + $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS'; |
| 108 | + $KEY = 'YOUR_API_KEY'; |
| 109 | + $WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}'; |
| 110 | + // -------------------- |
| 111 | + |
| 112 | + $sampleText = "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey. Lions are known for their strength, teamwork, and complex social structures."; |
| 113 | + |
| 114 | + $submission = new CopyleaksNaturalLanguageSubmissionModel( |
| 115 | + $sampleText, |
| 116 | + ); |
| 117 | + $submission->sandbox = true; |
| 118 | + |
| 119 | + $response = $this->copyleaks->aiDetectionClient->submitNaturalLanguage($authToken, time(), $submission); |
| 120 | + $this->logInfo('AI Detection - submitNaturalLanguage', $response); |
30 | 121 |
|
31 | | -$copyleaks = new Copyleaks(); |
32 | | -$loginResult = $copyleaks->login(<your email>,<your api key>); |
33 | | -echo json_encode($loginResult); |
34 | 122 | ``` |
35 | | -* (Option) To change the Identity server URI (default:"https://id.copyleaks.com"): |
36 | | -```rb |
37 | | -CopyleaksConfig::SET_IDENTITY_SERVER_URI("<your identity server URI>"); |
| 123 | + |
| 124 | +### Writing Assistant |
| 125 | +Get intelligent suggestions for improving grammar, spelling, style, and overall writing quality. |
| 126 | + |
| 127 | +```php |
| 128 | +<?php |
| 129 | + |
| 130 | + require_once(__DIR__ . '/vendor/autoload.php'); |
| 131 | + |
| 132 | + use Copyleaks\Copyleaks; |
| 133 | + use Copyleaks\CopyleaksWritingAssistantSubmissionModel; |
| 134 | + |
| 135 | + // --- Your Credentials --- |
| 136 | + $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS'; |
| 137 | + $KEY = 'YOUR_API_KEY'; |
| 138 | + $WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}'; |
| 139 | + // -------------------- |
| 140 | + |
| 141 | + $sampleText = "Lions are the only cat that live in groups, called pride. A prides typically consists of a few adult males, several feales, and their offspring. This social structure is essential for hunting and raising young cubs. Female lions, or lionesses are the primary hunters of the prid. They work together in cordinated groups to take down prey usually targeting large herbiores like zbras, wildebeest and buffalo. Their teamwork and strategy during hunts highlight the intelligence and coperation that are key to their survival."; |
| 142 | + |
| 143 | + $scoreWeights = new ScoreWeights( |
| 144 | + 0.1, 0.2, 0.3, 0.4 |
| 145 | + ); |
| 146 | + |
| 147 | + $submission = new CopyleaksWritingAssistantSubmissionModel( |
| 148 | + $sampleText, |
| 149 | + ); |
| 150 | + |
| 151 | + $submission->sandbox = true; |
| 152 | + $submission->score = $scoreWeights; |
| 153 | + |
| 154 | + $response = $this->copyleaks->writingAssistantClient->submitText($authToken, time(), $submission); |
| 155 | + $this->logInfo('Writing Assistant - submitText', $response); |
| 156 | + |
38 | 157 | ``` |
39 | | -* (Option) To change the API server URI (default:"https://api.copyleaks.com"): |
40 | | -```rb |
41 | | -CopyleaksConfig::SET_API_SERVER_URI("<your API server URI>"); |
| 158 | +For a full guide please refer to our step by step [Guide](https://docs.copyleaks.com/guides/writing/check-grammar/) |
| 159 | + |
| 160 | +For a detailed understanding of the Writing assistant process, refer to the Copyleaks writing feedback Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/writing-assistant/check/) |
| 161 | +## |
| 162 | +### Text Moderation |
| 163 | +Scan and moderate text content for unsafe, inappropriate, or policy-violating material across various categories. |
| 164 | + |
| 165 | +```php |
| 166 | +<?php |
| 167 | + |
| 168 | + require_once(__DIR__ . '/vendor/autoload.php'); |
| 169 | + |
| 170 | + use Copyleaks\Copyleaks; |
| 171 | + use Copyleaks\CopyleaksTextModerationRequestModel; |
| 172 | + |
| 173 | + // --- Your Credentials --- |
| 174 | + $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS'; |
| 175 | + $KEY = 'YOUR_API_KEY'; |
| 176 | + $WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}'; |
| 177 | + // -------------------- |
| 178 | + |
| 179 | + var labelsArray = new CopyleaksTextModerationLabel[] |
| 180 | + { |
| 181 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.ADULT_V1), |
| 182 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.TOXIC_V1), |
| 183 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.VIOLENT_V1), |
| 184 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.PROFANITY_V1), |
| 185 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.SELF_HARM_V1), |
| 186 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.HARASSMENT_V1), |
| 187 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.HATE_SPEECH_V1), |
| 188 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.DRUGS_V1), |
| 189 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.FIREARMS_V1), |
| 190 | + new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants.CYBERSECURITY_V1) |
| 191 | + }; |
| 192 | + |
| 193 | + var model = new CopyleaksTextModerationRequestModel( |
| 194 | + text: "This is some text to scan.", |
| 195 | + sandbox: true, |
| 196 | + language: CopyleaksTextModerationLanguages.ENGLISH, |
| 197 | + labels: labelsArray |
| 198 | + ); |
| 199 | + |
| 200 | + $response = $this->copyleaks->textModerationClient->submitText($authToken, time(), $model); |
| 201 | + $textModerationResponse= CopyleaksTextModerationResponseModel::fromArray(json_decode(json_encode($response), true)); |
| 202 | + |
| 203 | + $this->logInfo('Text Moderation - submitText', $textModerationResponse); |
| 204 | + |
42 | 205 | ``` |
| 206 | +For a full guide please refer to our step by step [Guide](https://docs.copyleaks.com/guides/moderation/moderate-text/) |
| 207 | + |
| 208 | +For a detailed understanding of the Text moderation process, refer to the Copyleaks text moderation Endpoint [Documentation](https://docs.copyleaks.com/reference/actions/text-moderation/check/) |
| 209 | +## |
| 210 | +## Further Resources |
| 211 | + |
| 212 | +* **Copyleaks API Dashboard:** Manage your API keys, monitor usage, and view analytics from your personalized dashboard. [Access Dashboard](https://api.copyleaks.com/dashboard) |
| 213 | +* **Copyleaks SDK Documentation:** Explore comprehensive guides, API references, and code examples for seamless integration. [Read Documentation](https://docs.copyleaks.com/resources/sdks/overview/) |
| 214 | + |
43 | 215 |
|
44 | | -## Demo |
45 | | -See [demo.php](./demo/demo.php) under demo folder for an example. |
46 | | -## Read More |
47 | | -* [API Homepage](https://api.copyleaks.com/) |
48 | | -* [API Documentation](https://api.copyleaks.com/documentation) |
49 | | -* [Plagiarism Report](https://github.com/Copyleaks/plagiarism-report) |
| 216 | +## Support |
| 217 | +* If you need assistance, please contact Copyleaks Support via our support portal: Contact Copyleaks [Support](https://help.copyleaks.com/s/contactsupport). |
| 218 | +* To arrange a product demonstration, book a demo here: [Booking Link](https://copyleaks.com/book-a-demo). |
0 commit comments