-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirect_screenshot_editor.php
More file actions
166 lines (140 loc) · 4.78 KB
/
Copy pathdirect_screenshot_editor.php
File metadata and controls
166 lines (140 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
// Bootstrapping Laravel in a standalone script
require __DIR__ . '/vendor/autoload.php';
$app = require_once __DIR__ . '/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
// Now we can use Laravel models, facades, etc.
use App\Models\Project;
/**
* Simple class for direct screenshot manipulation via code
*/
class ProjectScreenshotManager
{
/**
* Add a screenshot URL to a project
*/
public static function addScreenshot(int $projectId, string $screenshotUrl): bool
{
try {
$project = Project::findOrFail($projectId);
$screenshots = $project->screenshots ?? [];
$screenshots[] = $screenshotUrl;
$project->screenshots = $screenshots;
$project->save();
echo "Screenshot added to project {$project->title}\n";
return true;
} catch (\Exception $e) {
echo "Error: {$e->getMessage()}\n";
return false;
}
}
/**
* Update all screenshots for a project
*/
public static function updateScreenshots(int $projectId, array $screenshotUrls): bool
{
try {
$project = Project::findOrFail($projectId);
$project->screenshots = $screenshotUrls;
$project->save();
echo "Screenshots updated for project {$project->title}\n";
return true;
} catch (\Exception $e) {
echo "Error: {$e->getMessage()}\n";
return false;
}
}
/**
* Remove a screenshot at a specific index
*/
public static function removeScreenshot(int $projectId, int $index): bool
{
try {
$project = Project::findOrFail($projectId);
$screenshots = $project->screenshots ?? [];
if (isset($screenshots[$index])) {
array_splice($screenshots, $index, 1);
$project->screenshots = $screenshots;
$project->save();
echo "Screenshot removed from project {$project->title}\n";
return true;
} else {
echo "Screenshot index not found\n";
return false;
}
} catch (\Exception $e) {
echo "Error: {$e->getMessage()}\n";
return false;
}
}
/**
* Get all screenshots for a project
*/
public static function getScreenshots(int $projectId): array
{
try {
$project = Project::findOrFail($projectId);
return $project->screenshots ?? [];
} catch (\Exception $e) {
echo "Error: {$e->getMessage()}\n";
return [];
}
}
/**
* List all screenshots for a project
*/
public static function listScreenshots(int $projectId): void
{
try {
$project = Project::findOrFail($projectId);
$screenshots = $project->screenshots ?? [];
echo "Screenshots for project '{$project->title}' (ID: $projectId):\n";
if (empty($screenshots)) {
echo " No screenshots found.\n";
return;
}
foreach ($screenshots as $index => $url) {
echo " [$index] $url\n";
}
} catch (\Exception $e) {
echo "Error: {$e->getMessage()}\n";
}
}
}
// Example usage - MODIFY THESE VALUES TO MANAGE YOUR PROJECT'S SCREENSHOTS
// Project ID you want to modify
$projectId = 1; // Change this to your project ID
// Action to perform: 'list', 'add', 'remove', 'update'
$action = 'list'; // Change this to the action you want
// For 'add' action - URL of the screenshot to add
$screenshotUrl = 'https://example.com/screenshot.png';
// For 'update' action - New list of screenshot URLs
$screenshotUrls = [
'https://example.com/screenshot1.png',
'https://example.com/screenshot2.png',
// Add more URLs as needed
];
// For 'remove' action - Index of the screenshot to remove
$screenshotIndex = 0;
// Execute the action
switch ($action) {
case 'list':
ProjectScreenshotManager::listScreenshots($projectId);
break;
case 'add':
ProjectScreenshotManager::addScreenshot($projectId, $screenshotUrl);
break;
case 'remove':
ProjectScreenshotManager::removeScreenshot($projectId, $screenshotIndex);
break;
case 'update':
ProjectScreenshotManager::updateScreenshots($projectId, $screenshotUrls);
break;
default:
echo "Unknown action: $action\n";
}
// Show the updated screenshots
if ($action !== 'list') {
echo "\nUpdated screenshots:\n";
ProjectScreenshotManager::listScreenshots($projectId);
}