repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/src/Uv/Adapter.php
src/Uv/Adapter.php
<?php namespace React\Filesystem\Uv; use React\EventLoop\ExtUvLoop; use React\EventLoop\Loop; use React\Filesystem\AdapterInterface; use React\Filesystem\ModeTypeDetector; use React\Filesystem\PollInterface; use React\Filesystem\Stat; use React\Promise\PromiseInterface; use React\Filesystem\Node; final class Adapter implements AdapterInterface { use StatTrait; private ExtUvLoop $loop; private $uvLoop; private PollInterface $poll; public function __construct() { $loop = Loop::get(); if (!($loop instanceof ExtUvLoop)) { throw new \InvalidArgumentException('Event loop is expected to be ext-uv based, which it is not'); } $this->loop = $loop; $this->poll = new Poll($this->loop); $this->uvLoop = $loop->getUvLoop(); } public function detect(string $path): PromiseInterface { return $this->internalStat($path)->then(function (?Stat $stat) use ($path) { if ($stat === null) { return new NotExist($this->poll, $this, $this->loop, dirname($path) . DIRECTORY_SEPARATOR, basename($path)); } switch (ModeTypeDetector::detect($stat->mode())) { case Node\DirectoryInterface::class: return $this->directory($stat->path()); break; case Node\FileInterface::class: return $this->file($stat->path()); break; default: return new Node\Unknown($stat->path(), $stat->path()); break; } }); } public function directory(string $path): Node\DirectoryInterface { return new Directory($this->poll, $this, $this->loop, dirname($path) . DIRECTORY_SEPARATOR, basename($path)); } public function file(string $path): Node\FileInterface { return new File($this->poll, $this->loop, dirname($path) . DIRECTORY_SEPARATOR, basename($path)); } protected function uvLoop() { return $this->uvLoop; } protected function activate(): void { $this->poll->activate(); } protected function deactivate(): void { $this->poll->deactivate(); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/src/Uv/Poll.php
src/Uv/Poll.php
<?php namespace React\Filesystem\Uv; use React\EventLoop\ExtUvLoop; use React\EventLoop\TimerInterface; use React\Filesystem\Node\FileInterface; use React\Filesystem\PollInterface; use React\Filesystem\Stat; use React\Promise\Promise; use React\Promise\PromiseInterface; use RuntimeException; use React\EventLoop\LoopInterface; use React\Filesystem\Node; use UV; use function React\Promise\all; final class Poll implements PollInterface { private LoopInterface $loop; private int $workInProgress = 0; private ?TimerInterface $workInProgressTimer = null; private int $workInterval = 10; public function __construct(LoopInterface $loop) { $this->loop = $loop; } public function activate(): void { if ($this->workInProgress++ === 0) { $this->workInProgressTimer = $this->loop->addPeriodicTimer($this->workInterval, static function () {}); } } public function deactivate(): void { if (--$this->workInProgress <= 0) { $this->loop->cancelTimer($this->workInProgressTimer); } } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/src/Uv/StatTrait.php
src/Uv/StatTrait.php
<?php namespace React\Filesystem\Uv; use React\EventLoop\ExtUvLoop; use React\Filesystem\Node\FileInterface; use React\Filesystem\NodeNotFound; use React\Filesystem\Stat; use React\Promise\Promise; use React\Promise\PromiseInterface; use RuntimeException; use React\EventLoop\LoopInterface; use React\Filesystem\Node; use UV; trait StatTrait { protected function internalStat(string $path): PromiseInterface { return new Promise(function (callable $resolve, callable $reject) use ($path): void { $this->activate(); uv_fs_stat($this->uvLoop(), $path, function ($stat) use ($path, $resolve, $reject): void { $this->deactivate(); if (is_array($stat)) { $resolve(new Stat($path, $stat)); } else { $resolve(null); } }); }); } abstract protected function uvLoop(); // phpcs:disabled abstract protected function activate(): void; abstract protected function deactivate(): void; }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/src/Uv/NotExist.php
src/Uv/NotExist.php
<?php namespace React\Filesystem\Uv; use React\EventLoop\ExtUvLoop; use React\Filesystem\AdapterInterface; use React\Filesystem\Node; use React\Filesystem\PollInterface; use React\Promise\CancellablePromiseInterface; use React\Promise\Deferred; use React\Promise\Promise; use React\Promise\PromiseInterface; use function React\Promise\all; use function React\Promise\resolve; final class NotExist implements Node\NotExistInterface { use StatTrait; private ExtUvLoop $loop; private $uvLoop; private PollInterface $poll; private AdapterInterface $filesystem; private string $path; private string $name; public function __construct(PollInterface $poll, AdapterInterface $filesystem, ExtUvLoop $loop, string $path, string $name) { $this->poll = $poll; $this->filesystem = $filesystem; $this->loop = $loop; $this->uvLoop = $loop->getUvLoop(); $this->path = $path; $this->name = $name; } public function stat(): PromiseInterface { return $this->internalStat($this->path . $this->name); } public function createDirectory(): PromiseInterface { $this->activate(); return $this->filesystem->detect($this->path)->then(function (Node\NodeInterface $node): PromiseInterface { if ($node instanceof Node\NotExistInterface) { return $node->createDirectory(); } return resolve($node); })->then(function (Node\DirectoryInterface $directory): PromiseInterface { return new Promise(function (callable $resolve): void { uv_fs_mkdir($this->uvLoop, $this->path . $this->name, 0777, function () use ($resolve): void { $resolve(new Directory($this->poll, $this->filesystem, $this->loop, $this->path, $this->name)); $this->deactivate(); }); }); }); } public function createFile(): PromiseInterface { $file = new File($this->poll, $this->loop, $this->path, $this->name); return $this->filesystem->detect($this->path . DIRECTORY_SEPARATOR)->then(function (Node\NodeInterface $node): PromiseInterface { if ($node instanceof Node\NotExistInterface) { return $node->createDirectory(); } return resolve($node); })->then(function () use ($file): PromiseInterface { return $file->putContents(''); })->then(function () use ($file): Node\FileInterface { return $file; }); } public function unlink(): PromiseInterface { // Essentially a No-OP since it doesn't exist anyway return resolve(true); } public function path(): string { return $this->path; } public function name(): string { return $this->name; } protected function uvLoop() { return $this->uvLoop; } protected function activate(): void { $this->poll->activate(); } protected function deactivate(): void { $this->poll->deactivate(); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/src/Uv/Directory.php
src/Uv/Directory.php
<?php namespace React\Filesystem\Uv; use React\EventLoop\ExtUvLoop; use React\Filesystem\AdapterInterface; use React\Filesystem\Node; use React\Filesystem\PollInterface; use React\Promise\CancellablePromiseInterface; use React\Promise\Deferred; use React\Promise\PromiseInterface; use function React\Promise\all; use function React\Promise\resolve; final class Directory implements Node\DirectoryInterface { use StatTrait; private ExtUvLoop $loop; private $uvLoop; private PollInterface $poll; private AdapterInterface $filesystem; private string $path; private string $name; public function __construct(PollInterface $poll, AdapterInterface $filesystem, ExtUvLoop $loop, string $path, string $name) { $this->poll = $poll; $this->filesystem = $filesystem; $this->loop = $loop; $this->uvLoop = $loop->getUvLoop(); $this->path = $path; $this->name = $name; } public function stat(): PromiseInterface { return $this->internalStat($this->path . $this->name); } public function ls(): PromiseInterface { $this->activate(); $deferred = new Deferred(); uv_fs_scandir($this->uvLoop, $this->path . $this->name, function (array $contents) use ($deferred): void { $promises = []; foreach ($contents as $node) { $promises[] = $this->filesystem->detect($this->path . $this->name . DIRECTORY_SEPARATOR . $node)->then(null, function (\Throwable $throwable) use ($deferred, &$promises) { $deferred->reject($throwable); foreach ($promises as $promise) { if ($promise instanceof CancellablePromiseInterface) { $promise->cancel(); } } }); } $deferred->resolve(all($promises)); $this->deactivate(); }); return $deferred->promise(); } public function unlink(): PromiseInterface { $this->activate(); $deferred = new Deferred(); uv_fs_scandir($this->uvLoop, $this->path . $this->name, function (array $contents) use ($deferred): void { $this->deactivate(); if (count($contents) > 0) { $deferred->resolve(false); return; } $this->activate(); uv_fs_rmdir($this->uvLoop, $this->path . $this->name, function () use ($deferred): void { $this->deactivate(); $deferred->resolve(true); }); }); return $deferred->promise(); } public function path(): string { return $this->path; } public function name(): string { return $this->name; } protected function uvLoop() { return $this->uvLoop; } protected function activate(): void { $this->poll->activate(); } protected function deactivate(): void { $this->poll->deactivate(); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/src/Uv/File.php
src/Uv/File.php
<?php namespace React\Filesystem\Uv; use React\EventLoop\ExtUvLoop; use React\Filesystem\Node\FileInterface; use React\Filesystem\PollInterface; use React\Promise\Promise; use React\Promise\PromiseInterface; use UV; final class File implements FileInterface { use StatTrait; private ExtUvLoop $loop; private $uvLoop; private PollInterface $poll; private string $path; private string $name; public function __construct(PollInterface $poll, ExtUvLoop $loop, string $path, string $name) { $this->poll = $poll; $this->loop = $loop; $this->uvLoop = $loop->getUvLoop(); $this->path = $path; $this->name = $name; } public function stat(): PromiseInterface { return $this->internalStat($this->path . $this->name); } public function getContents(int $offset = 0 , ?int $maxlen = null): PromiseInterface { $this->activate(); return new Promise(function (callable $resolve) use ($offset, $maxlen): void { uv_fs_open($this->uvLoop, $this->path . DIRECTORY_SEPARATOR . $this->name, UV::O_RDONLY, 0, function ($fileDescriptor) use ($resolve, $offset, $maxlen): void { uv_fs_fstat($this->uvLoop, $fileDescriptor, function ($fileDescriptor, array $stat) use ($resolve, $offset, $maxlen): void { uv_fs_read($this->uvLoop, $fileDescriptor, $offset, $maxlen ?? (int)$stat['size'], function ($fileDescriptor, string $buffer) use ($resolve): void { $resolve($buffer); uv_fs_close($this->uvLoop, $fileDescriptor, function () { $this->deactivate(); }); }); }); }); }); } public function putContents(string $contents, int $flags = 0) { $this->activate(); return new Promise(function (callable $resolve) use ($contents, $flags): void { uv_fs_open( $this->uvLoop, $this->path . DIRECTORY_SEPARATOR . $this->name, (($flags & \FILE_APPEND) == \FILE_APPEND) ? UV::O_RDWR | UV::O_CREAT | UV::O_APPEND : UV::O_RDWR | UV::O_CREAT, 0644, function ($fileDescriptor) use ($resolve, $contents, $flags): void { uv_fs_write($this->uvLoop, $fileDescriptor, $contents, 0, function ($fileDescriptor, int $bytesWritten) use ($resolve): void { $resolve($bytesWritten); uv_fs_close($this->uvLoop, $fileDescriptor, function () { $this->deactivate(); }); }); } ); }); } public function unlink(): PromiseInterface { $this->activate(); return new Promise(function (callable $resolve): void { uv_fs_unlink($this->uvLoop, $this->path . DIRECTORY_SEPARATOR . $this->name, function () use ($resolve): void { $resolve(true); $this->deactivate(); }); }); } public function path(): string { return $this->path; } public function name(): string { return $this->name; } protected function uvLoop() { return $this->uvLoop; } protected function activate(): void { $this->poll->activate(); } protected function deactivate(): void { $this->poll->deactivate(); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/tests/NotExistTest.php
tests/NotExistTest.php
<?php namespace React\Tests\Filesystem; use React\Filesystem\AdapterInterface; use React\Filesystem\Node\NotExistInterface; use React\Promise\PromiseInterface; use function React\Async\await; final class NotExistTest extends AbstractFilesystemTestCase { /** * @test * * @dataProvider provideFilesystems */ public function createDirectory(AdapterInterface $filesystem): void { $dirName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'reactphp-filesystem-' . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR; await($filesystem->detect($dirName)->then(static function (NotExistInterface $notExist): PromiseInterface { return $notExist->createDirectory(); })); self::assertDirectoryExists($dirName); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/tests/FileTest.php
tests/FileTest.php
<?php namespace React\Tests\Filesystem; use React\Filesystem\AdapterInterface; use React\Filesystem\Node\FileInterface; use React\Filesystem\Node\NotExistInterface; use React\Filesystem\Stat; use React\Promise\Promise; use React\Promise\PromiseInterface; use function React\Async\await; use function React\Promise\all; final class FileTest extends AbstractFilesystemTestCase { /** * @test * * @dataProvider provideFilesystems */ public function stat(AdapterInterface $filesystem): void { $stat = await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface { return $file->stat(); })); self::assertInstanceOf(Stat::class, $stat); self::assertSame(filesize(__FILE__), $stat->size()); } /** * @test * * @dataProvider provideFilesystems */ public function getContents(AdapterInterface $filesystem): void { $fileContents = await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface { return $file->getContents(); })); self::assertSame(file_get_contents(__FILE__), $fileContents); } /** * @test * * @dataProvider provideFilesystems */ public function getContents34and5thCharacterFromFile(AdapterInterface $filesystem): void { $directoryName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR; $fileName = $directoryName . bin2hex(random_bytes(13)); mkdir($directoryName); \file_put_contents($fileName, 'abcdefghijklmnopqrstuvwxyz'); $fileContents = await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface { return $file->getContents(3, 3); })); self::assertSame('def', $fileContents); } /** * @test * * @dataProvider provideFilesystems */ public function putContents(AdapterInterface $filesystem): void { $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9)); $fileContents = bin2hex(random_bytes(128)); $writtenLength = await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(function (FileInterface $file) use ($fileContents): PromiseInterface { return $file->putContents($fileContents); })); self::assertSame($writtenLength, strlen(file_get_contents($fileName))); self::assertSame($fileContents, file_get_contents($fileName)); unlink($fileName); } /** * @test * * @dataProvider provideFilesystems */ public function putContentsMultipleBigFiles(AdapterInterface $filesystem): void { $directoryName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR; await($filesystem->detect($directoryName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createDirectory())); $fileNames = []; $fileContents = []; for ($i = 0; $i < 25; $i++) { $fileNames[] = $directoryName . bin2hex(random_bytes(13)); } foreach ($fileNames as $fileName) { $fileContents[$fileName] = bin2hex(random_bytes(4096)); touch($fileName); } $promises = []; foreach ($fileContents as $fileName => $fileContent) { $promises[$fileName] = $filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContent): PromiseInterface { return $file->putContents($fileContent); }); } $writtenLengths = await(all($promises)); foreach ($writtenLengths as $fileName => $writtenLength) { self::assertSame($writtenLength, strlen(file_get_contents($fileName))); self::assertSame($fileContents[$fileName], file_get_contents($fileName)); unlink($fileName); } } /** * @test * * @dataProvider provideFilesystems */ public function putContentsAppend(AdapterInterface $filesystem): void { $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9)); $fileContentsFirst = bin2hex(random_bytes(128)); $fileContentsSecond = bin2hex(random_bytes(128)); $writtenLengthFirst = await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(static function (FileInterface $file) use ($fileContentsFirst): PromiseInterface { return $file->putContents($fileContentsFirst); })); self::assertSame($writtenLengthFirst, strlen(file_get_contents($fileName))); self::assertSame($fileContentsFirst, file_get_contents($fileName)); $writtenLengthSecond = await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContentsSecond): PromiseInterface { return $file->putContents($fileContentsSecond, \FILE_APPEND); })); self::assertSame($writtenLengthFirst + $writtenLengthSecond, strlen(file_get_contents($fileName))); self::assertSame($fileContentsFirst . $fileContentsSecond, file_get_contents($fileName)); unlink($fileName); } /** * @test * * @dataProvider provideFilesystems */ public function putContentsAppendBigFile(AdapterInterface $filesystem): void { $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9)); await($filesystem->detect($fileName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createFile())); $fileContents = []; $writtenLength = 0; for ($i = 0; $i < 13; $i++) { $fileContents[] = bin2hex(random_bytes(4096)); } foreach ($fileContents as $fileContent) { $writtenLength += await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContent): PromiseInterface { return $file->putContents($fileContent, \FILE_APPEND); })); } self::assertSame($writtenLength, strlen(file_get_contents($fileName))); self::assertSame(implode('', $fileContents), file_get_contents($fileName)); unlink($fileName); } /** * @test * * @dataProvider provideFilesystems */ public function putContentsAppendMultipleBigFiles(AdapterInterface $filesystem): void { $this->runMultipleFilesTests($filesystem, 8, 4096, 4); } /** * @test * * @dataProvider provideFilesystems */ public function putContentsAppendLotsOfSmallFiles(AdapterInterface $filesystem): void { $this->runMultipleFilesTests($filesystem, 16, 16, 4); } /** * @test * * @dataProvider provideFilesystems */ public function putContentsAppendLoadsOfSmallFiles(AdapterInterface $filesystem): void { $this->runMultipleFilesTests($filesystem, 32, 8, 8); } public function runMultipleFilesTests(AdapterInterface $filesystem, int $fileCount, int $fileSize, int $chunkCount): void { $directoryName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR; mkdir($directoryName, 0777, true); $fileNames = []; $fileContents = []; for ($i = 0; $i < $fileCount; $i++) { $fileNames[] = $directoryName . bin2hex(random_bytes(13)); } foreach ($fileNames as $fileName) { $fileContents[$fileName] = []; touch($fileName); } foreach ($fileNames as $fileName) { for ($i = 0; $i < $chunkCount; $i++) { $fileContents[$fileName][] = bin2hex(random_bytes($fileSize)); } } $promises = []; foreach ($fileContents as $fileName => $fileContent) { $queue = new \SplQueue(); foreach ($fileContent as $chunk) { $queue->enqueue($chunk); } $promises[$fileName] = $filesystem->detect($fileName)->then(static function (FileInterface $file) use ($queue): PromiseInterface { return new Promise(function (callable $resolve, callable $reject) use ($queue, $file): void { $bytesWritten = 0; $writeFunction = function () use (&$writeFunction, &$bytesWritten, $queue, $file, $resolve, $reject) { if ($queue->count() > 0) { $file->putContents($queue->dequeue(), \FILE_APPEND)->then(function (int $writtenBytes) use (&$writeFunction, &$bytesWritten): void { $bytesWritten += $writtenBytes; $writeFunction(); }, $reject); return; } $resolve($bytesWritten); }; $writeFunction(); }); }); } $writtenLengths = await(all($promises)); foreach ($writtenLengths as $fileName => $writtenLength) { self::assertSame($writtenLength, strlen(file_get_contents($fileName))); self::assertSame(implode('', $fileContents[$fileName]), file_get_contents($fileName)); unlink($fileName); } } /** * @test * * @dataProvider provideFilesystems */ public function unlink(AdapterInterface $filesystem): void { $fileName = __FILE__ . '.' . time(); $fileContents = bin2hex(random_bytes(2048)); file_put_contents($fileName, $fileContents); self::assertFileExists($fileName); await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface { return $file->unlink(); })); self::assertFileDoesNotExist($fileName); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/tests/FactoryTest.php
tests/FactoryTest.php
<?php namespace React\Tests\Filesystem; use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; use function React\Async\await; final class FactoryTest extends AbstractFilesystemTestCase { /** * @test */ public function factory(): void { $node = await(Factory::create()->detect(__FILE__)); self::assertInstanceOf(FileInterface::class, $node); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/tests/AbstractFilesystemTestCase.php
tests/AbstractFilesystemTestCase.php
<?php namespace React\Tests\Filesystem; use PHPUnit\Framework\TestCase; use React\EventLoop; use React\EventLoop\ExtUvLoop; use React\EventLoop\LoopInterface; use React\Filesystem\AdapterInterface; use React\Filesystem\Eio; use React\Filesystem\Factory; use React\Filesystem\Fallback; use React\Filesystem\Uv; abstract class AbstractFilesystemTestCase extends TestCase { /** * @return iterable<array<AdapterInterface, LoopInterface>> */ final public function provideFilesystems(): iterable { $loop = EventLoop\Loop::get(); yield 'fallback' => [new Fallback\Adapter()]; if (\function_exists('eio_get_event_stream')) { yield 'eio' => [new Eio\Adapter()]; } if (\function_exists('uv_loop_new') && $loop instanceof ExtUvLoop) { yield 'uv' => [new Uv\Adapter()]; } yield 'factory' => [Factory::create()]; } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/tests/DirectoryTest.php
tests/DirectoryTest.php
<?php namespace React\Tests\Filesystem; use React\EventLoop\LoopInterface; use React\Filesystem\AdapterInterface; use React\Filesystem\Node\DirectoryInterface; use React\Filesystem\Node\FileInterface; use React\Filesystem\Stat; use React\Promise\PromiseInterface; use function React\Async\await; final class DirectoryTest extends AbstractFilesystemTestCase { /** * @test * * @dataProvider provideFilesystems */ public function stat(AdapterInterface $filesystem): void { $stat = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface { return $directory->stat(); })); self::assertInstanceOf(Stat::class, $stat); self::assertSame(stat(__DIR__)['size'], $stat->size()); } /** * @test * * @dataProvider provideFilesystems */ public function ls(AdapterInterface $filesystem): void { $expectedListing = []; $d = dir(__DIR__); while (false !== ($entry = $d->read())) { if ($entry === '.' || $entry === '..') { continue; } $expectedListing[__DIR__ . DIRECTORY_SEPARATOR . $entry] = is_file(__DIR__ . DIRECTORY_SEPARATOR . $entry) ? FileInterface::class : DirectoryInterface::class; } $d->close(); ksort($expectedListing); $directoryListing = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface { return $directory->ls(); })); $listing = []; foreach ($directoryListing as $node) { $listing[$node->path() . $node->name()] = $node instanceof FileInterface ? FileInterface::class : DirectoryInterface::class; } ksort($listing); self::assertSame($expectedListing, $listing); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/tests/FilesystemTest.php
tests/FilesystemTest.php
<?php namespace React\Tests\Filesystem; use React\Filesystem\AdapterInterface; use React\Filesystem\Node\DirectoryInterface; use React\Filesystem\Node\FileInterface; use React\Filesystem\Node\NotExistInterface; use function React\Async\await; final class FilesystemTest extends AbstractFilesystemTestCase { /** * @test * * @dataProvider provideFilesystems */ public function file(AdapterInterface $filesystem): void { $node = await($filesystem->detect(__FILE__)); self::assertInstanceOf(FileInterface::class, $node); } /** * @test * * @dataProvider provideFilesystems */ public function directory(AdapterInterface $filesystem): void { $node = await($filesystem->detect(__DIR__)); self::assertInstanceOf(DirectoryInterface::class, $node); } /** * @test * * @dataProvider provideFilesystems */ public function notExists(AdapterInterface $filesystem): void { $node = await($filesystem->detect(bin2hex(random_bytes(13)))); self::assertInstanceOf(NotExistInterface::class, $node); } }
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/file_tail.php
examples/file_tail.php
<?php use React\EventLoop\Loop; use React\EventLoop\TimerInterface; use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; require 'vendor/autoload.php'; $filename = tempnam(sys_get_temp_dir(), 'reactphp-filesystem-file-tail-example-'); $offset = 0; $file = Factory::create()->detect($filename)->then(function (FileInterface $file) { Loop::addPeriodicTimer(1, function (TimerInterface $timer) use ($file, &$offset): void { $file->getContents($offset)->then(function (string $contents) use (&$offset, $timer): void { echo $contents; $offset += strlen($contents); if (trim($contents) === 'done') { Loop::cancelTimer($timer); } }); }); })->done(); echo 'Append data to "', $filename, '" to see it appear beneath here, put "done" on a new line to stop watching it:', PHP_EOL;
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/file_read.php
examples/file_read.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; require 'vendor/autoload.php'; Factory::create()->detect(__FILE__)->then(function (FileInterface $file) { return $file->getContents(); })->then(static function (string $contents): void { echo $contents; })->done();
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/directory_nested_listing.php
examples/directory_nested_listing.php
<?php use React\EventLoop\Loop; use React\Filesystem\Factory; use React\Filesystem\Node\DirectoryInterface; use React\Filesystem\Node\NodeInterface; require 'vendor/autoload.php'; $filesystem = Factory::create(); $ls = static function (string $dir) use (&$ls, $filesystem): void { $filesystem->detect($dir)->then(function (DirectoryInterface $directory) { return $directory->ls(); })->then(static function (array $nodes) use (&$ls) { foreach ($nodes as $node) { assert($node instanceof NodeInterface); echo $node->path() . $node->name(), ': ', get_class($node), PHP_EOL; if ($node instanceof DirectoryInterface) { $ls($node->path() . $node->name()); } } })->then(null, function (Throwable $throwable) { echo $throwable; }); }; $ls(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src'); Loop::run(); echo '----------------------------', PHP_EOL, 'Done listing directory', PHP_EOL;
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/file_write.php
examples/file_write.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; require 'vendor/autoload.php'; Factory::create()->detect(__FILE__ . '.copy')->then(static function (FileInterface $file) { return $file->putContents(file_get_contents(__FILE__)); })->then(static function ($result): void { var_export([$result]); })->done();
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/file_stat.php
examples/file_stat.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; use React\Filesystem\Stat; require 'vendor/autoload.php'; Factory::create()->detect(__FILE__)->then(function (FileInterface $file) { return $file->stat(); })->then(static function (Stat $stat): void { echo $stat->path(), ': ', get_class($stat), PHP_EOL; echo 'Mode: ', $stat->mode(), PHP_EOL; echo 'Uid: ', $stat->uid(), PHP_EOL; echo 'Gid: ', $stat->gid(), PHP_EOL; echo 'Size: ', $stat->size(), PHP_EOL; echo 'Atime: ', $stat->atime()->format(DATE_ISO8601), PHP_EOL; echo 'Mtime: ', $stat->mtime()->format(DATE_ISO8601), PHP_EOL; echo 'Ctime: ', $stat->ctime()->format(DATE_ISO8601), PHP_EOL; })->done();
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/file_create_new.php
examples/file_create_new.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; use React\Filesystem\Node\NotExistInterface; use React\Filesystem\Stat; use React\Promise\PromiseInterface; require 'vendor/autoload.php'; Factory::create()->detect(sys_get_temp_dir() . __FILE__ . time() . time() . time() . time() . time() . time())->then(static function (NotExistInterface $node): PromiseInterface { return $node->createFile(); })->then(static function (FileInterface $file): PromiseInterface { return $file->stat(); })->then(static function (Stat $stat): void { echo $stat->path(), ': ', get_class($stat), PHP_EOL; echo 'Mode: ', $stat->mode(), PHP_EOL; echo 'Uid: ', $stat->uid(), PHP_EOL; echo 'Gid: ', $stat->gid(), PHP_EOL; echo 'Size: ', $stat->size(), PHP_EOL; echo 'Atime: ', $stat->atime()->format(DATE_ISO8601), PHP_EOL; echo 'Mtime: ', $stat->mtime()->format(DATE_ISO8601), PHP_EOL; echo 'Ctime: ', $stat->ctime()->format(DATE_ISO8601), PHP_EOL; })->done();
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/node_doesnt_exist.php
examples/node_doesnt_exist.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\NodeInterface; require 'vendor/autoload.php'; Factory::create()->detect(__FILE__ . time() . time() . time() . time() . time() . time())->then(static function (NodeInterface $node): void { echo get_class($node); })->done();
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/directory_listing.php
examples/directory_listing.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\DirectoryInterface; use React\Filesystem\Node\NodeInterface; require 'vendor/autoload.php'; Factory::create()->detect(__DIR__)->then(function (DirectoryInterface $directory) { return $directory->ls(); })->then(static function ($nodes) { foreach ($nodes as $node) { assert($node instanceof NodeInterface); echo $node->name(), ': ', get_class($node), PHP_EOL; } echo '----------------------------', PHP_EOL, 'Done listing directory', PHP_EOL; }, function (Throwable $throwable) { echo $throwable; });
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
reactphp/filesystem
https://github.com/reactphp/filesystem/blob/385933fdf47ad2db195c859523a8d854792dbad2/examples/file_unlink.php
examples/file_unlink.php
<?php use React\Filesystem\Factory; use React\Filesystem\Node\FileInterface; require 'vendor/autoload.php'; $filename = tempnam(sys_get_temp_dir(), 'reactphp-filesystem-file-tail-example-'); file_put_contents($filename, file_get_contents(__FILE__)); Factory::create()->detect($filename)->then(function (FileInterface $file) use ($filename) { return $file->unlink(); })->done();
php
MIT
385933fdf47ad2db195c859523a8d854792dbad2
2026-01-05T04:49:50.958304Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/autoload.php
src/Instagram/autoload.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /** * Register the autoloader for the Instagram Graph API PHP SDK classes. * * @param string $class rhe fully-qualified class name. * @return void */ spl_autoload_register( function ( $class ) { // project-specific namespace prefix $prefix = 'Instagram\\'; // require our file require substr( $class, strlen( $prefix ) ) . '.php'; } ); ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Instagram.php
src/Instagram/Instagram.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram; // other classes to use use Instagram\Request\Request; use Instagram\Request\Curl; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Instagram * * Core functionality for talking to the Instagram Graph API. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Instagram { /** * @const string Default Graph API version for requests. */ const DEFAULT_GRAPH_VERSION = 'v14.0'; /** * @var string $graphVersion the graph version we want to use. */ protected $graphVersion; /** * @var object $client the Instagram client service. */ protected $client; /** * @var string $accessToken access token to use with requests. */ protected $accessToken; /** * @var Request $request the request to the api. */ protected $request = ''; /** * @var string $pagingNextLink Instagram next page link. */ public $pagingNextLink = ''; /** * @var string $pagingPreviousLink Instagram previous page link. */ public $pagingPreviousLink = ''; /** * Contructor for instantiating a new Instagram object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // set our access token $this->setAccessToken( isset( $config['access_token'] ) ? $config['access_token'] : '' ); // instantiate the client $this->client = new Curl(); // set graph version $this->graphVersion = isset( $config['graph_version'] ) ? $config['graph_version'] : self::DEFAULT_GRAPH_VERSION; } /** * Sends a GET request to Graph and returns the result. * * @param array $params params for the GET request. * @return Instagram response. */ public function get( $params ) { // check for params $endpointParams = isset( $params['params'] ) ? $params['params'] : array(); // perform GET request return $this->sendRequest( Request::METHOD_GET, $params['endpoint'], $endpointParams ); } /** * Sends a POST request to Graph and returns the result. * * @param array $params params for the POST request. * @return Instagram response. */ public function post( $params ) { // check for params $endpointParams = isset( $params['params'] ) ? $params['params'] : array(); // perform POST request return $this->sendRequest( Request::METHOD_POST, $params['endpoint'], $endpointParams ); } /** * Sends a DELETE request to Graph and returns the result. * * @param array $params params for the DELETE request. * @return Instagram response. */ public function delete( $params ) { // check for params $endpointParams = isset( $params['params'] ) ? $params['params'] : array(); // perform DELETE request return $this->sendRequest( Request::METHOD_DELETE, $params['endpoint'], $endpointParams ); } /** * Send a request to the Instagram Graph API and returns the result. * * @param string $method HTTP method. * @param string $endpoint endpoint for the request. * @param string $params parameters for the endpoint. * @return Instagram response. */ public function sendRequest( $method, $endpoint, $params ) { // create our request $this->request = new Request( $method, $endpoint, $params, $this->graphVersion, $this->accessToken ); // send the request to the client for processing $response = $this->client->send( $this->request ); // set prev and next links $this->setPrevNextLinks( $response ); // append the request to the response $response['debug'] = $this; // return the response return $response; } /** * Send a custom GET request to the Instagram Graph API and returns the result. * * @param string $customUrl the entire url for the request. * @return Instagram response. */ public function sendCustomRequest( $customUrl ) { // create our request $this->request = new Request( Request::METHOD_GET ); // set our custom url for the request $this->request->setUrl( $this->graphVersion, $customUrl ); // return the response $response = $this->client->send( $this->request ); // set prev and next links $this->setPrevNextLinks( $response ); // append the request to the response $response['debug'] = $this; // return the response return $response; } /** * Request previous or next page data. * * @param string $page specific page to request. * @return array of previous or next page data.. */ public function getPage( $page ) { // get the page to use $pageUrl = Params::NEXT == $page ? $this->pagingNextLink : $this->pagingPreviousLink; // return the response from the request return $this->sendCustomRequest( $pageUrl ); } /** * Set previous and next links from the response. * * @param array &$response response from the api. * @return void. */ public function setPrevNextLinks( &$response ) { // set paging next/previous links $this->pagingNextLink = $response['paging_next_link'] = isset( $response[Fields::PAGING][Params::NEXT] ) ? $response[Fields::PAGING][Params::NEXT] : ''; $this->pagingPreviousLink = $response['paging_previous_link'] = isset( $response[Fields::PAGING][Params::PREVIOUS] ) ? $response[Fields::PAGING][Params::PREVIOUS] : ''; } /** * Set the access token. * * @param string $accessToken set the access token. * @return void. */ public function setAccessToken( $accessToken ) { $this->accessToken = $accessToken; } /** * Calculate next link based on the cursors. * * @param string $type type of link after or before. * @param array $response Instagram api response. * @param string $endpoint endpoint for the request. * @param array $params specific request params. * @return void */ public function calcLinkFromCursor( $type, &$response, $endpoint, $params ) { if ( isset( $response[Fields::PAGING][Fields::CURSORS][$type] ) ) { // we have paging // set the after cursor $params[$type] = $response[Fields::PAGING][Fields::CURSORS][$type]; // create our request $request = new Request( Request::METHOD_GET, $endpoint, $params, $this->graphVersion, $this->accessToken ); // set paging type based $pagingOrder = Params::AFTER == $type ? Params::NEXT : Params::PREVIOUS; // set paging next to the url for the next request $response[Fields::PAGING][$pagingOrder] = $request->getUrl(); } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Container/Container.php
src/Instagram/Container/Container.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Container; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Container * * Get info on a container. * - Endpoint Format: GET /{ig-container-id}/?fields={fields}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-container * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Container extends Instagram { /** * @var integer $containerId Instagram container id for publishing media. */ protected $containerId; /** * @var array $fields a list of all the fields we are requesting to get back. */ protected $fields = array( Fields::ID, Fields::STATUS, Fields::STATUS_CODE ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->containerId = $config['container_id']; } /** * Get the status of a container. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->containerId, 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/FacebookLogin/FacebookLogin.php
src/Instagram/FacebookLogin/FacebookLogin.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\FacebookLogin; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Request; use Instagram\Request\Params; use Instagram\Request\ResponseTypes; /** * FacebookLogin * * Core functionality for login dialog. * - Facebook Docs: https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow/ * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class FacebookLogin extends Instagram { /** * @const debug token endpoint */ const ENDPOINT = 'dialog/oauth'; /** * @var integer $appId Facebook application id. */ protected $appId; /** * @var integer $appId Facebook application secret. */ protected $appSecret; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config = array() ) { // call parent for setup parent::__construct( $config ); // set the application id $this->appId = $config['app_id']; // set the application secret $this->appSecret = $config['app_secret']; } /** * Get the url for a user to prompt them with the login dialog. * * @param string $redirectUri uri the user gets sent to after logging in with facebook. * @param array $permissions array of the permissions you want to request from the user. * @param string $state this gets passed back from facebook in the redirect uri. * @return Instagram response. */ public function getLoginDialogUrl( $redirectUri, $permissions, $state = '' ) { $params = array( // params required to generate the login url Params::CLIENT_ID => $this->appId, Params::REDIRECT_URI => $redirectUri, Params::STATE => $state, Params::SCOPE => Params::commaImplodeArray( $permissions ), Params::RESPONSE_TYPE => ResponseTypes::CODE, ); // return the login dialog url return Request::BASE_AUTHORIZATION_URL . '/' . $this->graphVersion . '/' . self::ENDPOINT . '?' . http_build_query( $params );; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/ResponseTypes.php
src/Instagram/Request/ResponseTypes.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * ResponseTypes * * Functionality and defines for the api response types. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class ResponseTypes { const CODE = 'code'; } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Curl.php
src/Instagram/Request/Curl.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; // other classes we need to use use Instagram\Request\Request; /** * Curl * * Handle curl functionality for requests. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Curl { /** * @var object $curl */ protected $curl; /** * @var int The curl client error code. */ protected $curlErrorCode = 0; /** * @var string $rawResponse The raw response from the server. */ protected $rawResponse; /** * Perform a curl call. * * @param Request $request * @return array The curl response. */ public function send( $request ) { $options = array( // curl options for the connection CURLOPT_URL => $request->getUrl(), CURLOPT_RETURNTRANSFER => true, // Return response as string CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_CAINFO => __DIR__ . '/certs/cacert.pem', ); if ( $request->getMethod() == Request::METHOD_POST ) { // need to add on post fields $options[CURLOPT_POSTFIELDS] = $request->getUrlBody(); } // initialize curl $this->curl = curl_init(); // set the options curl_setopt_array( $this->curl, $options ); // send the request $this->rawResponse = curl_exec( $this->curl ); // close curl connection curl_close( $this->curl ); // return nice json decoded response return json_decode( $this->rawResponse, true ); } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Request.php
src/Instagram/Request/Request.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * Request * * Responsible for setting up the request to the API. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Request { /** * @const string production Graph API URL. */ const BASE_GRAPH_URL = 'https://graph.facebook.com'; /** * @const string production Graph API URL. */ const BASE_AUTHORIZATION_URL = 'https://www.facebook.com'; /** * @const string METHOD_GET HTTP GET method. */ const METHOD_GET = 'GET'; /** * @const string METHOD_POST HTTP POST method. */ const METHOD_POST = 'POST'; /** * @const string METHOD_DELETE HTTP DELETE method. */ const METHOD_DELETE = 'DELETE'; /** * @var string $accessToken the access token to use for this request. */ protected $accessToken; /** * @var string $method the HTTP method for this request. */ protected $method; /** * @var string $endpoint the Graph endpoint for this request. */ protected $endpoint; /** * @var array $params the parameters to send with this request. */ protected $params = array(); /** * @var string $url enptoint url. */ protected $url; /** * Contructor for instantiating a request.. * * @param string $method the method type for the request. * @param string $endpoint the endpoint for the request. * @param array $params the parameters to be sent along with the request. * @param string $graphVersion the graph version for the request. * @param string $accessToken the access token to go along with the request. * @return void */ public function __construct( $method, $endpoint = '', $params = array(), $graphVersion = '', $accessToken = '' ) { // set HTTP method $this->method = strtoupper( $method ); // set endptoint $this->endpoint = $endpoint; // set any params $this->params = $params; // set access token $this->accessToken = $accessToken; // set url $this->setUrl( $graphVersion ); } /** * Set the full url for the request. * * @param string $graphVersion the graph version we are using. * @param string $customUrl custom url for the request. * @return void */ public function setUrl( $graphVersion, $customUrl = '' ) { // generate the full url $this->url = $customUrl ? $customUrl : self::BASE_GRAPH_URL . '/' . $graphVersion . $this->endpoint; if ( $this->getMethod() !== Request::METHOD_POST && !$customUrl ) { // not post or custom request so we have work to do // get the params $params = $this->getParams(); // build the query string and append to url $this->url .= '?' . http_build_query( $params ); } } /** * Returns the body of the request. * * @return string */ public function getUrlBody() { // get params $params = $this->getPostParams(); return http_build_query( $this->params ); } /** * Return the params for this request. * * @return array */ public function getParams() { if ( $this->accessToken ) { // append access token to params $this->params['access_token'] = $this->accessToken; } // return params array return $this->params; } /** * Return the HTTP method for this request. * * @return string */ public function getMethod() { return $this->method; } /** * Only return params on POST requests. * * @return array */ public function getPostParams() { if ( $this->getMethod() === 'POST' ) { // request is a post // return the array of params return $this->getParams(); } // return emtpy array return array(); } /** * Return the endpoint URL this request. * * @return string */ public function getUrl() { return $this->url; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/GrantTypes.php
src/Instagram/Request/GrantTypes.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * GrantTypes * * Functionality and defines for the api grant types * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class GrantTypes { const FB_EXCHANGE_TOKEN = 'fb_exchange_token'; } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/MediaTypes.php
src/Instagram/Request/MediaTypes.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * MediaTypes * * Functionality and defines for the Instagram Graph API media types parameter. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class MediaTypes { const VIDEO = 'VIDEO'; const CAROUSEL = 'CAROUSEL'; const REELS = 'REELS'; const STORIES = 'STORIES'; } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Fields.php
src/Instagram/Request/Fields.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; // other classes we need to use use Instagram\Request\Params; /** * Fields * * Functionality and defines for the Instagram Graph API fields query parameter. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Fields { const BIOGRAPHY = 'biography'; const BUSINESS_DISCOVERY = 'business_discovery'; const CAPTION = 'caption'; const CHILDREN = 'children'; const COMMENT_ID = 'comment_id'; const COMMENTS = 'comments'; const COMMENTS_COUNT = 'comments_count'; const CONFIG = 'config'; const CURSORS = 'cursors'; const FOLLOWERS_COUNT = 'followers_count'; const FOLLOWS_COUNT = 'follows_count'; const FROM = 'from'; const HIDDEN = 'hidden'; const ID = 'id'; const IG_ID = 'ig_id'; const INSTAGRAM_BUSINESS_ACCOUNT = 'instagram_business_account'; const IS_COMMENT_ENABLED = 'is_comment_enabled'; const LIKE_COUNT = 'like_count'; const MEDIA = 'media'; const MEDIA_COUNT = 'media_count'; const MEDIA_ID = 'media_id'; const MEDIA_PRODUCT_TYPE = 'media_product_type'; const MEDIA_TYPE = 'media_type'; const MEDIA_URL = 'media_url'; const MENTIONED_COMMENT = 'mentioned_comment'; const MENTIONED_MEDIA = 'mentioned_media'; const NAME = 'name'; const OWNER = 'owner'; const PAGING = 'paging'; const PARENT_ID = 'parent_id'; const PERMALINK = 'permalink'; const PROFILE_PICTURE_URL = 'profile_picture_url'; const QUOTA_USAGE = 'quota_usage'; const REPLIES = 'replies'; const SHORTCODE = 'shortcode'; const STATUS = 'status'; const STATUS_CODE = 'status_code'; const TEXT = 'text'; const THUMBNAIL_URL = 'thumbnail_url'; const TIMESTAMP = 'timestamp'; const USER = 'user'; const USERNAME = 'username'; const VIDEO_TITLE = 'video_title'; const WEBSITE = 'website'; /** * Return a list of all the fields we are requesting to get back for each comment. * * @param boolean $commaImplode defaults to always returning a comma imploded list of fields. * @return array of fields to request. */ public static function getDefaultCommentFields( $commaImplode = true ) { $defaultFields = array( // fields we can request self::FROM, self::HIDDEN, self::ID, self::LIKE_COUNT, self::MEDIA, self::PARENT_ID, self::TEXT, self::TIMESTAMP, self::USER, self::USERNAME ); // return default fields based on flag return $commaImplode ? Params::commaImplodeArray( $defaultFields ) : $defaultFields; } /** * Return a list of all the fields we are requesting to get back for a media post. * * @param boolean $commaImplode defaults to always returning a comma imploded list of fields. * @return array of fields to request. */ public static function getDefaultMediaFields( $commaImplode = true ) { $defaultFields = array( // fields we can request self::ID, self::CAPTION, self::COMMENTS_COUNT, self::LIKE_COUNT, self::MEDIA_TYPE, self::MEDIA_URL, self::PERMALINK, self::TIMESTAMP, self::THUMBNAIL_URL ); // return default fields based on flag return $commaImplode ? Params::commaImplodeArray( $defaultFields ) : $defaultFields; } /** * Return a list of all the fields we are requesting to get back for each of the media objects children. * * @param boolean $commaImplode defaults to always returning a comma imploded list of fields. * @return array of fields to request. */ public static function getDefaultMediaChildrenFields( $commaImplode = true ) { $defaultFields = array( // fields we can request self::ID, self::MEDIA_TYPE, self::MEDIA_URL ); // return default fields based on flag return $commaImplode ? Params::commaImplodeArray( $defaultFields ) : $defaultFields; } /** * Return a list of all the fields we are requesting to get back for each replies. * * @param boolean $commaImplode defaults to always returning a comma imploded list of fields. * @return array of fields to request. */ public static function getDefaultRepliesFields( $commaImplode = true ) { $defaultFields = array( // fields we can request self::FROM, self::HIDDEN, self::ID, self::LIKE_COUNT, self::MEDIA, self::PARENT_ID, self::TEXT, self::TIMESTAMP, self::USER, self::USERNAME ); // return default fields based on flag return $commaImplode ? Params::commaImplodeArray( $defaultFields ) : $defaultFields; } /** * Return a string with all the media fields params for the request. * * @return string for the fields parameter. */ public static function getDefaultMediaFieldsString() { return self::getDefaultMediaFields() . ',' . self::CHILDREN . '{' . self::getDefaultMediaChildrenFields() . '},' . self::COMMENTS . '{' . self::getDefaultCommentFields() . ',' . self::REPLIES . '{' . self::getDefaultRepliesFields() . '}' . '}' ; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Metric.php
src/Instagram/Request/Metric.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * Metric * * Functionality and defines for the Instagram Graph API metric query parameter. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Metric { const AUDIENCE_CITY = 'audience_city'; const AUDIENCE_COUNTRY = 'audience_country'; const AUDIENCE_GENDER_AGE = 'audience_gender_age'; const AUDIENCE_LOCALE = 'audience_locale'; const CAROUSEL_ALBUM_ENGAGEMENT = 'carousel_album_engagement'; const CAROUSEL_ALBUM_IMPRESSIONS = 'carousel_album_impressions'; const CAROUSEL_ALBUM_REACH = 'carousel_album_reach'; const CAROUSEL_ALBUM_SAVED = 'carousel_album_saved'; const CAROUSEL_ALBUM_VIDEO_VIEWS = 'carousel_album_video_views'; const EMAIL_CONTACTS = 'email_contacts'; const ENGAGEMENT = 'engagement'; const EXITS = 'exits'; const FOLLOWER_COUNT = 'follower_count'; const GET_DIRECTIONS_LINK = 'get_directions_clicks'; const IMPRESSIONS = 'impressions'; const MEDIA_TYPE_CAROUSEL_ALBUM = 'carousel_album'; const MEDIA_TYPE_IMAGE = 'image'; const MEDIA_TYPE_STORY = 'story'; const MEDIA_TYPE_VIDEO = 'video'; const ONLINE_FOLLOWERS = 'online_followers'; const PHONE_CALL_CLICKS = 'phone_call_clicks'; const PROFILE_VIEWS = 'profile_views'; const REACH = 'reach'; const REPLIES = 'replies'; const SAVED = 'saved'; const TAPS_BACK = 'taps_back'; const TAPS_FORWARD = 'taps_forward'; const TEXT_MESSAGE_CLICKS = 'text_message_clicks'; const VIDEO_VIEWS = 'video_views'; const WEBSITE_CLICKS = 'website_clicks'; } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Params.php
src/Instagram/Request/Params.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * Params * * Functionality and defines for the Instagram Graph API query parameters. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Params { const ACCESS_TOKEN = 'access_token'; const AFTER = 'after'; const BEFORE = 'before'; const CAPTION = 'caption'; const CHILDREN = 'children'; const CLIENT_ID = 'client_id'; const CLIENT_SECRET = 'client_secret'; const CODE = 'code'; const COMMENT_ENABLED = 'comment_enabled'; const COMMENT_ID = 'comment_id'; const CREATION_ID = 'creation_id'; const FB_EXCHANGE_TOKEN = 'fb_exchange_token'; const FIELDS = 'fields'; const GRANT_TYPE = 'grant_type'; const HIDE = 'hide'; const IMAGE_URL = 'image_url'; const INPUT_TOKEN = 'input_token'; const IS_CAROUSEL_ITEM = 'is_carousel_item'; const LIMIT = 'limit'; const LOCATION_ID = 'location_id'; const MEDIA_ID = 'media_id'; const MEDIA_TYPE = 'media_type'; const MESSAGE = 'message'; const METRIC = 'metric'; const NEXT = 'next'; const PERIOD = 'period'; const PREV = 'prev'; const PREVIOUS = 'previous'; const Q = 'q'; const REDIRECT_URI = 'redirect_uri'; const RESPONSE_TYPE = 'response_type'; const SCOPE = 'scope'; const SINCE = 'since'; const STATE = 'state'; const THUMB_OFFSET = 'thumb_offset'; const UNTIL = 'until'; const USER_ID = 'user_id'; const USER_TAGS = 'user_tags'; const VIDEO_URL = 'video_url'; /** * Get fields for a request. * * @param array $fields list of fields for the request. * @param boolean $commaImplode to implode the array or not to implode the array. * @return array fields array with comma separated string. */ public static function getFieldsParam( $fields, $commaImplode = true ) { return array( // return fields param self::FIELDS => $commaImplode ? self::commaImplodeArray( $fields ) : $fields ); } /** * Turn array into a comma separated string. * * @param array $array elements to be comma separated. * @return string comma separated list of fields */ public static function commaImplodeArray( $array = array() ) { // imploded string on commas and return return implode( ',', $array ); } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Scope.php
src/Instagram/Request/Scope.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * Scope * * Functionality and defines for the scope. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Scope { const ADS_MANAGEMENT = 'ads_management'; const BUSINESS_MANAGEMENT = 'business_management'; const INSTAGRAM_BASIC = 'instagram_basic'; const INSTAGRAM_CONTENT_PUBLISH = 'instagram_content_publish'; const INSTAGRAM_MANAGE_COMMENTS = 'instagram_manage_comments'; const INSTAGRAM_MANAGE_INSIGHTS = 'instagram_manage_insights'; const PAGES_SHOW_LIST = 'pages_show_list'; const PAGES_READ_ENGAGEMENT = 'pages_read_engagement'; } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Request/Period.php
src/Instagram/Request/Period.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Request; /** * Period * * Functionality and defines for the Instagram Graph API period query parameter. * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Period { const LIFETIME = 'lifetime'; const DAY = 'day'; const WEEK = 'week'; const DAYS_28 = 'days_28'; } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Hashtag/TopMedia.php
src/Instagram/Hashtag/TopMedia.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Hashtag; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Top Media * * Get top media for a hashtag. * - Endpoint Format: GET /{ig-hashtag-id}/top_media?user_id={user-id}&fields={fields}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-hashtag/top-media#returnable-fields * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class TopMedia extends Hashtag { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'top_media'; /** * @var integer $userId Instagram user id making the api request. */ protected $userId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->userId = $config['user_id']; } /** * Get info on a hashtag. * * @param array $params Params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->hashtagId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params Specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::getDefaultMediaFields() . ',' . Fields::CHILDREN . '{' . Fields::getDefaultMediaChildrenFields() . '}' ; // add on the since query param farthest back it can be set is 24 hours $params[Params::USER_ID] = $this->userId; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Hashtag/Hashtag.php
src/Instagram/Hashtag/Hashtag.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Hashtag; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Hashtag. * * Get the info for a hashtag. * - Endpoint Format: GET /{ig-hashtag-id}?access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-hashtag * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Hashtag extends Instagram { /** * @var integer $userId Instagram user id making the api request. */ protected $hashtagId; /** * @var array $fields a list of all the fields we are requesting to get back. */ protected $fields = array( Fields::ID, Fields::NAME ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->hashtagId = $config['hashtag_id']; } /** * Get info on a hashtag. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->hashtagId, 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Hashtag/RecentMedia.php
src/Instagram/Hashtag/RecentMedia.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Hashtag; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Recent Media * * Get recent media for a hashtag. * - Endpoint Format: GET /{ig-hashtag-id}/recent_media?user_id={user-id}&fields={fields}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-hashtag/recent-media * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class RecentMedia extends Hashtag { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'recent_media'; /** * @var integer $userId Instagram user id making the api request. */ protected $userId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->userId = $config['user_id']; } /** * Get info on a hashtag. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->hashtagId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params Specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::getDefaultMediaFields() . ',' . Fields::CHILDREN . '{' . Fields::getDefaultMediaChildrenFields() . '}' ; // add on the since query param farthest back it can be set is 24 hours $params[Params::USER_ID] = $this->userId; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/Insights.php
src/Instagram/User/Insights.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Metric; use Instagram\Request\Period; /** * Insights * * Get insights on the IG users business account. * - Endpoint Format: GET /{ig-user-id}/insights?metric={metric}&period={period}&since={since}&until={until}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/insights * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Insights extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'insights'; /** * @var array $metric a list of all the metrics we are requesting to get back. */ protected $metrics = array( Metric::IMPRESSIONS, Metric::REACH ); /** * @var array $period the period we are requesting to get back. */ protected $period = Period::DAY; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get insights on the user.. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // set the metrics param $params[Params::METRIC] = Params::commaImplodeArray( $this->metrics ); // set the period param $params[Params::PERIOD] = $this->period; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/Tags.php
src/Instagram/User/Tags.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Tags * * Get media the IG user has been tagged in. * - Endpoint Format: GET /{ig-user-id}/tags?access_toke={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/tags * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Tags extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'tags'; /** * @var array $fields a list of all the fields we are requesting to get back. */ protected $fields = array( Fields::ID, Fields::USERNAME, Fields::CAPTION, Fields::LIKE_COUNT, Fields::COMMENTS_COUNT, Fields::TIMESTAMP, Fields::MEDIA_PRODUCT_TYPE, Fields::MEDIA_TYPE, Fields::PERMALINK, Fields::MEDIA_URL ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get posts the user is tagged in. * * @param array $params Params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get media fields for the tagged posts $params[Params::FIELDS] = Fields::getDefaultMediaFields() . ',' . Fields::CHILDREN . '{' . Fields::getDefaultMediaChildrenFields() . '}' ; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/Stories.php
src/Instagram/User/Stories.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; /** * Stories * * Get stories on the IG user. * - Endpoint Format: GET /{ig-user-id}/stories?access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/stories * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Stories extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'stories'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get the users stories. * * @param array $params params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/Mentions.php
src/Instagram/User/Mentions.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; /** * Mentions * * Create comment on a comment the user is mentioned in. * - Endpoint Format: POST /{ig-user-id}/mentions?media_id={media_id}&message={message}&access_token={access-token} * - Endpoint Format: POST /{ig-user-id}/mentions?media_id={media_id}&comment_id={comment_id}&message={message}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/mentions * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Mentions extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'mentions'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Create a comment on a media post in which a user was mentioned. * * @param string $message comment to post. * @return Instagram response. */ public function replyToMedia( $params ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $params ); // ig get request $response = $this->post( $postParams ); // return response return $response; } /** * Create a comment on a comment in which a user was mentioned. * * @param string $message comment to post. * @return Instagram response. */ public function replyToComment( $params ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $params ); // ig get request $response = $this->post( $postParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/BusinessDiscovery.php
src/Instagram/User/BusinessDiscovery.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; use Instagram\Request\Request; use Instagram\User\Media; /** * Business Discovery * * Get info on the Instagram users business account such as info and posts. * - Endpoint Format: GET /{ig-user-id}?fields=business_discovery.username({username})&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/business_discovery * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class BusinessDiscovery extends User { /** * @var integer $username Instagram username to get info on. */ protected $username; /** * @var array $fields a list of all the fields we are requesting to get back for the business. */ protected $fields = array( Fields::USERNAME, Fields::WEBSITE, Fields::NAME, Fields::IG_ID, Fields::ID, Fields::PROFILE_PICTURE_URL, Fields::BIOGRAPHY, Fields::FOLLOWS_COUNT, Fields::FOLLOWERS_COUNT, Fields::MEDIA_COUNT ); /** * @var array $mediaFields a list of all the fields we are requesting to get back for each media object. */ protected $mediaFields = array( Fields::ID, Fields::USERNAME, Fields::CAPTION, Fields::LIKE_COUNT, Fields::COMMENTS_COUNT, Fields::TIMESTAMP, Fields::MEDIA_PRODUCT_TYPE, Fields::MEDIA_TYPE, Fields::OWNER, Fields::PERMALINK, Fields::MEDIA_URL, Fields::THUMBNAIL_URL ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // set the username $this->username = $config['username']; } /** * Get the users account business discovery information and posts. * * @param array $params Params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // calculate the next link for paging $this->calcNextLink( $response ); // set prev and next links $this->setPrevNextLinks( $response ); // return response return $response; } /** * Calculate next link based on the cursors. * * @param array $response Instagram api response. * @return void */ public function calcNextLink( &$response ) { if ( isset( $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::BEFORE] ) ) { // we have previous page // get fields string $fieldsString = $this->getParams(); // calculate after string with cursor $snippet = Fields::MEDIA . '.' . Params::BEFORE . '(' . $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::BEFORE] . '){'; // update old fields with cursor $newFieldsParams = str_replace( Fields::MEDIA . '{', $snippet, $fieldsString ); // create our media endpoint $endpoint = '/' . $this->userId . '/'; // create our request $request = new Request( Request::METHOD_GET, $endpoint, $newFieldsParams, $this->graphVersion, $this->accessToken ); // set paging next to the url for the next request $response[Fields::PAGING][Params::PREVIOUS] = $request->getUrl(); } if ( isset( $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::AFTER] ) ) { // we have another page // get fields string $fieldsString = $this->getParams(); // calculate after string with cursor $snippet = Fields::MEDIA . '.' . Params::AFTER . '(' . $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::AFTER] . '){'; // update old fields with cursor $newFieldsParams = str_replace( Fields::MEDIA . '{', $snippet, $fieldsString ); // create our media endpoint $endpoint = '/' . $this->userId . '/'; // create our request $request = new Request( Request::METHOD_GET, $endpoint, $newFieldsParams, $this->graphVersion, $this->accessToken ); // set paging next to the url for the next request $response[Fields::PAGING][Params::NEXT] = $request->getUrl(); } } /** * Request previous or next page data. * * @param string $page specific page to request. * @return array of previous or next page data.. */ public function getMediaPage( $page ) { // get the page to use $pageUrl = Params::NEXT == $page ? $this->pagingNextLink : $this->pagingPreviousLink; // return the response from the request $mediaPageRequest = $this->sendCustomRequest( $pageUrl ); // calculate the next link for paging $this->calcNextLink( $mediaPageRequest ); // set prev and next links $this->setPrevNextLinks( $mediaPageRequest ); return $mediaPageRequest; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // create our fields string for business discovery $fieldsString = Fields::BUSINESS_DISCOVERY . '.' . Fields::USERNAME . '(' . $this->username . '){' . Params::commaImplodeArray( $this->fields ) . ',' . Fields::MEDIA . '{' . Params::commaImplodeArray( $this->mediaFields ) . ',' . Fields::CHILDREN . '{' . Fields::getDefaultMediaChildrenFields() . '}' . '}' . '}'; // return our params return Params::getFieldsParam( $fieldsString, false ); } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/User.php
src/Instagram/User/User.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * User * * Get the IG Users info. * - Endpoint Format: GET /{ig-user-id}?fields={fields}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class User extends Instagram { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'me/accounts'; /** * @var string $userId Instagram user id. */ protected $userId; /** * @var array $fields a list of all the fields we are requesting to get back. */ protected $fields = array( Fields::BIOGRAPHY, Fields::ID, Fields::IG_ID, Fields::FOLLOWERS_COUNT, Fields::FOLLOWS_COUNT, Fields::MEDIA_COUNT, Fields::NAME, Fields::PROFILE_PICTURE_URL, Fields::USERNAME, Fields::WEBSITE ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->userId = isset( $config['user_id'] ) ? $config['user_id'] : ''; } /** * Get the users info. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId, 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get the users facebook pages. * * @param array $params params for the GET request. * @return Instagram response. */ public function getUserPages( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . self::ENDPOINT, 'params' => $params ); // ig get request $response = $this->get( $getParams ); // calculate the next link for paging $this->calcLinkFromCursor( Params::AFTER, $response, $getParams['endpoint'], $params ); // calcuate the before link $this->calcLinkFromCursor( Params::BEFORE, $response, $getParams['endpoint'], $params ); // set prev and next links $this->setPrevNextLinks( $response ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/MentionedMedia.php
src/Instagram/User/MentionedMedia.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Mentioned Media * * Get info on the media a user is mentioned in. * - Endpoint Format: GET /{ig-user-id}?fields=mentioned_media.media_id({media-id}){{fields}}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/mentioned_media * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class MentionedMedia extends User { /** * @var integer $mediaId Instagram media id making the api request. */ protected $mediaId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->mediaId = $config['media_id']; } /** * Get media the user is mentioned in. * * @param array $params Params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/', 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::MENTIONED_MEDIA . '.' . Fields::MEDIA_ID . '(' . $this->mediaId . '){' . Fields::getDefaultMediaFieldsString() . '}'; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/MentionedComment.php
src/Instagram/User/MentionedComment.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Mentioned Comment * * Get mentioned comment for user. * - Endpoint Format: GET /{ig-user-id}?fields=mentioned_comment.comment_id({comment-id}){{fields}}&access_toke={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/mentioned_comment * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class MentionedComment extends User { /** * @var integer $commentId id of the instagram comment. */ protected $commentId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->commentId = $config['comment_id']; } /** * Get comment user is mentioned in. * * @param array $params Params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/', 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::MENTIONED_COMMENT . '.' . Fields::COMMENT_ID . '(' . $this->commentId . '){' . Fields::getDefaultCommentFields() . ',' . Fields::REPLIES . '{' . Fields::getDefaultRepliesFields() . '}' . '}'; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/RecentlySearchedHashtags.php
src/Instagram/User/RecentlySearchedHashtags.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; /** * Recently Searched Hashtags * * Get recently searched hashtags for a user. * - Endpoint Format: GET /{ig-user-id}/recently_searched_hashtags?limit={limit}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/recently_searched_hashtags * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class RecentlySearchedHashtags extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'recently_searched_hashtags'; /** * @var max limit per page in the response. */ protected $maxReturnLimit = 30; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get hashtags a user has recently searched. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // set the limit param to max $params[Params::LIMIT] = $this->maxReturnLimit; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/MediaPublish.php
src/Instagram/User/MediaPublish.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; /** * Media Publish * * Handle publishing media. * - Endpoint Format: POST /{ig-user-id}/media_publish?creation_id={creation_id}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/media_publish * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class MediaPublish extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'media_publish'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Publish media to users IG account. * * @param string $containerId id of the container for posting the media. * @return Instagram response. */ public function create( $containerId ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => array( Params::CREATION_ID => $containerId ) ); // ig get request $response = $this->post( $postParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/ContentPublishingLimit.php
src/Instagram/User/ContentPublishingLimit.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Content Publishing Limit * * Get the IG Users info. * - Endpoint Format: GET /{ig-user-id}?fields={fields}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class ContentPublishingLimit extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'content_publishing_limit'; /** * @var array $fields a list of all the fields we are requesting to get back. */ protected $fields = array( Fields::CONFIG, Fields::QUOTA_USAGE ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get info on the users content publishing limits. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params = Params::getFieldsParam( $this->fields ); // add on the since query param farthest back it can be set is 24 hours $params[Params::SINCE] = ( new \DateTime())->modify( '-23 hours' )->getTimestamp(); // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/LiveMedia.php
src/Instagram/User/LiveMedia.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Live Media * * Get live media on the IG user. * - Endpoint Format: GET /{ig-user-id}/live_media?fields={fields}&since={since}&until={until}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/live_media * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class LiveMedia extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'live_media'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get live media for a user. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultMediaFields( false ) ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/User/Media.php
src/Instagram/User/Media.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\User; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; use Instagram\Request\MediaTypes; /** * Media * * Handle reading and creating media on the IG user. * - Endpoint Format: GET /{ig-user-id}/media * ?fields={fields}&access_token={access-token} * - Endpoint Format: POST IMAGE /{ig-user-id}/media * ?image_url={image-url}&is_carousel_item={is-carousel-item}&caption={caption}&location_id={location-id}&user_tags={user-tags}&access_token={access-token} * - Endpoint Format: POST VIDEO /{ig-user-id}/media * ?media_type=VIDEO&video_url={video-url}&is_carousel_item={is-carousel-item}&caption={caption}&location_id={location-id}&thumb_offset={thumb-offset}&access_token={access-token} * - Endpoint Format: POST CAROUSEL /{ig-user-id}/media * ?media_type={media-type}&caption={caption}&location_id={location-id}&children={children}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-user/media * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Media extends User { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'media'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Create a container for posting an image. * * @param array $params params for the POST request. * @return Instagram response. */ public function create( $params ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $params ? $params : array() ); if ( isset( $params[Params::CHILDREN] ) ) { // carousel container requires more children params $postParams['params'][Params::MEDIA_TYPE] = MediaTypes::CAROUSEL; } elseif ( isset( $params[Params::VIDEO_URL] ) && !isset( $params[Params::MEDIA_TYPE] ) ) { // video container requires more params and to not overide in case REELS is passed $postParams['params'][Params::MEDIA_TYPE] = MediaTypes::VIDEO; } elseif ( isset( $params[Params::VIDEO_URL] ) && isset( $params[Params::MEDIA_TYPE] ) ) { // set url and type to whatever is passed in $postParams['params'][Params::MEDIA_TYPE] = $params[Params::MEDIA_TYPE]; } elseif ( isset( $params[Params::IMAGE_URL] ) && isset( $params[Params::MEDIA_TYPE] ) ) { // set url and type to whatever is passed in $postParams['params'][Params::MEDIA_TYPE] = MediaTypes::STORIES; } // ig get request $response = $this->post( $postParams ); // return response return $response; } /** * Get the users media. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ), //$params ? $params : Params::getFieldsParam( $this->fields ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::getDefaultMediaFieldsString(); // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Comment/Replies.php
src/Instagram/Comment/Replies.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Comment; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Replies * * Replies on a specific media. * - Endpoint Format: GET /{ig-comment-id}/replies?fields={fields}&access_token={access-token} * - Endpoint Format: POST /{ig-comment-id}/replies?message={message}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-comment/replies * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Replies extends Comment { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'replies'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Create a reply on a comment. * * @param string $message reply to post. * @return Instagram Response. */ public function create( $message ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->commentId . '/' . self::ENDPOINT, 'params' => array( Params::MESSAGE => $message ) ); // ig get request $response = $this->post( $postParams ); // return response return $response; } /** * Get replies for a comment. * * @param array $paramsparams for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->commentId . '/' . $this->endpoint, 'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultCommentFields( false ) ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Comment/Comment.php
src/Instagram/Comment/Comment.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Comment; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Comment * * Get comments on a specific media. * - Endpoint Format: GET /{ig-comment-id}?fields={fields}&access_token={access-token} * - Endpoint Format: POST /{ig-comment-id}?hide={hide}&access_token={access-token} * - Endpoint Format: DELETE /{ig-comment-id}?access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-comment * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Comment extends Instagram { /** * @var integer $commentId Instagram id of the comment. */ protected $commentId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->commentId = $config['comment_id']; } /** * Get a comment. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->commentId, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::getDefaultCommentFields() . ',' . Fields::REPLIES . '{' . Fields::getDefaultCommentFields() . '}' ; // return our params return $params; } } /** * Set hide parameter on a comment. * * @param boolean $hide show or hide the comment with true|false. * @return Instagram Response. */ public function setHide( $hide ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->commentId, 'params' => array( Params::HIDE => $hide ) ); // ig get request $response = $this->post( $postParams ); // return response return $response; } /** * Delete a comment. * * @return Instagram Response. */ public function remove() { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->commentId ); // ig get request $response = $this->delete( $postParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Page/Page.php
src/Instagram/Page/Page.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Page; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Page * * Get the IG user connected to a Facebook Page. * - Endpoint Format: GET /{page-id}?fields=instagram_business_account&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/page * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Page Extends Instagram { /** * @var string $pageId page id to use with requests. */ protected $pageId; /** * @var array $fields a list of all the fields we are requesting to get back. */ protected $fields = array( Fields::INSTAGRAM_BUSINESS_ACCOUNT ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the page id $this->pageId = $config['page_id']; } /** * Get the Instagram user connected to the Facebook page. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->pageId, 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/AccessToken/AccessToken.php
src/Instagram/AccessToken/AccessToken.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\AccessToken; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\GrantTypes; /** * AccessToken * * Core functionality for access tokens. * - Endpoint Format: GET /oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&redirect_uri={redirect-uri}&code={code-parameter} * - Endpoint Format: GET /oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&grant_type=fb_exchange_token&fb_exchange_token={access-token} * - Endpoint Format: GET /debug_token?input_token={access-token}&access_token={access-token} * - Endpoint Format: GET|DELETE /{ig-user-id}/permissions/{permission-name}?access_token={access-token} * - Facebook Docs: https://developers.facebook.com/docs/facebook-login/guides/access-tokens * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class AccessToken extends Instagram { /** * @const debug token endpoint */ const ENDPOINT_DEBUG = 'debug_token'; /** * @const token permissions endpoint */ const ENDPOINT_PERMISSIONS = 'permissions'; /** * @const access token endpoint. */ const ENDPOINT_TOKEN = 'oauth/access_token'; /** * @var integer $appId Facebook application id. */ protected $appId; /** * @var integer $appId Facebook application secret. */ protected $appSecret; /** * @var integer $expiresAt time when the access token expires. */ protected $expiresAt = 0; /** * @var string $userId the user id of the access token. */ protected $userId; /** * @var string $value the access token. */ protected $value; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config = array() ) { // call parent for setup parent::__construct( $config ); // set the application id $this->appId = isset( $config['app_id'] ) ? $config['app_id'] : ''; // set the application secret $this->appSecret = isset( $config['app_secret'] ) ? $config['app_secret'] : ''; // set the access token $this->value = isset( $config['value'] ) ? $config['value'] : ''; // set the access token expire date $this->expiresAt = isset( $config['expires_at'] ) ? $config['expires_at'] : $this->expiresAt; // set the user id $this->userId = isset( $config['user_id'] ) ? $config['user_id'] : ''; } /** * Debug the access token. * * @return Instagram response. */ public function debug() { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . self::ENDPOINT_DEBUG, 'params' => array( Params::INPUT_TOKEN => $this->value ) ); // get request $response = $this->get( $getParams ); // return response return $response; } /** * Get access token from a code. * * @param string $code the code from the facebook redirect. * @param string $redirectUri uri the user gets sent to after logging in with facebook. * @return Instagram response. */ public function getAccessTokenFromCode( $code, $redirectUri ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . self::ENDPOINT_TOKEN, 'params' => array( Params::CLIENT_ID => $this->appId, Params::CLIENT_SECRET => $this->appSecret, Params::REDIRECT_URI => $redirectUri, Params::CODE => $code ) ); // get request $response = $this->get( $getParams ); // set class vars from response data $this->setDataFromResponse( $response ); // return response return $response; } /** * Get a long lived access token. * * @param string $accessToken the access token to exchange for a long lived one. * @return Instagram response. */ public function getLongLivedAccessToken( $accessToken ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . self::ENDPOINT_TOKEN, 'params' => array( Params::CLIENT_ID => $this->appId, Params::CLIENT_SECRET => $this->appSecret, Params::FB_EXCHANGE_TOKEN => $accessToken, Params::GRANT_TYPE => GrantTypes::FB_EXCHANGE_TOKEN, ) ); // get request $response = $this->get( $getParams ); // set class vars from response data $this->setDataFromResponse( $response ); // return response return $response; } /** * Get the permissions a user has for the access token. * * @return Instagram response. */ public function getPermissions() { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId. '/' . self::ENDPOINT_PERMISSIONS ); // get request $response = $this->get( $getParams ); // return response return $response; } /** * Check if the access token is long lived or not. * * @return boolean */ public function isLongLived() { // check if expires at meets long lived requirements return $this->expiresAt ? $this->expiresAt > time() + ( 60 * 60 * 2 ) : true; } /** * Revoke permissions for a users access token. * * @param string $permissionName name of the permission to revoke leave blank to revoke all permissions. * @return Instagram response. */ public function revokePermissions( $permissionName = '' ) { $deleteParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->userId. '/' . self::ENDPOINT_PERMISSIONS . '/' . $permissionName ); // delete request $response = $this->delete( $deleteParams ); // return response return $response; } /** * Set class variables from the token response. * * @param array $response the response from the api call. * @return void */ public function setDataFromResponse( $response ) { if ( isset( $response['access_token'] ) ) { // we have an access token // set the value from the response $this->value = $response['access_token']; // set expires at if we have it in the response $this->expiresAt = isset( $response['expires_in'] ) ? time() + $response['expires_in'] : 0; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/HashtagSearch/HashtagSearch.php
src/Instagram/HashtagSearch/HashtagSearch.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\HashtagSearch; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; /** * Hashtag Search. * * Get the id for a hashtag. * - Endpoint Format: GET /ig_hashtag_search?user_id={user-id}&q={q}&access_toke={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-hashtag-search * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class HashtagSearch extends Instagram { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'ig_hashtag_search'; /** * @var integer $userId Instagram user id making the api request. */ protected $userId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->userId = $config['user_id']; } /** * Get info on a hashtag. * * @param string $hashtagName name of hashtag to get ID for. * @return Instagram response. */ public function getSelf( $hashtagName ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . self::ENDPOINT, 'params' => array( Params::USER_ID => $this->userId, Params::Q => $hashtagName ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Media/Insights.php
src/Instagram/Media/Insights.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Media; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; use Instagram\Request\Metric; /** * Insights * * Get insights on a specific media. * - Endpoint Format: GET /{ig-media-id}/insights?access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-media/insights * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Insights extends Media { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'insights'; /** * @var Instagram endpoint for the request. */ protected $mediaType; /** * @var array $metric a list of all the metrics we are requesting to get back on a certain media type. */ protected $metrics = array( Metric::MEDIA_TYPE_CAROUSEL_ALBUM => array( Metric::IMPRESSIONS, Metric::REACH, Metric::CAROUSEL_ALBUM_ENGAGEMENT, Metric::CAROUSEL_ALBUM_IMPRESSIONS, Metric::CAROUSEL_ALBUM_REACH, Metric::CAROUSEL_ALBUM_SAVED, Metric::CAROUSEL_ALBUM_VIDEO_VIEWS, Metric::ENGAGEMENT, Metric::VIDEO_VIEWS, Metric::SAVED ), Metric::MEDIA_TYPE_VIDEO => array( Metric::IMPRESSIONS, Metric::REACH, Metric::ENGAGEMENT, Metric::VIDEO_VIEWS, Metric::SAVED ), Metric::MEDIA_TYPE_STORY => array( Metric::IMPRESSIONS, Metric::REACH, Metric::EXITS, Metric::REPLIES, Metric::TAPS_FORWARD, Metric::TAPS_BACK ) ); /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // set media type so we know what metrics to call for $this->mediaType = strtolower( $config['media_type'] ); } /** * Get insights on a media post. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->mediaId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // set the metrics param $params[Params::METRIC] = Params::commaImplodeArray( $this->metrics[$this->mediaType] ); // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Media/Children.php
src/Instagram/Media/Children.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Media; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Children * * Get children of a specific media. * - Endpoint Format: GET /{ig-media-id}/children?access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-media/children * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Children extends Media { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'children'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Get children on a media post. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->mediaId . '/' . self::ENDPOINT, 'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultMediaChildrenFields( false ) ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Media/Comments.php
src/Instagram/Media/Comments.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Media; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Comments * * Get comments on a specific media. * - Endpoint Format: GET /{ig-media-id}/comments?access_token={access-token} * - Endpoint Format: POST /{ig-media-id}/comments?message={message}&access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-media/comments * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Comments extends Media { /** * @const Instagram endpoint for the request. */ const ENDPOINT = 'comments'; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); } /** * Create a comment on a media post. * * @param string $message comment to post. * @return Instagram Response. */ public function create( $message ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->mediaId . '/' . self::ENDPOINT, 'params' => array( Params::MESSAGE => $message ) ); // ig get request $response = $this->post( $postParams ); // return response return $response; } /** * Get comments on a media post. * * @param array $params params for the GET request. * @return Instagram response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->mediaId . '/' . self::ENDPOINT, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Get params for the request. * * @param array $params Specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::getDefaultCommentFields() . ',' . Fields::REPLIES . '{' . Fields::getDefaultCommentFields() . '}' ; // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
jstolpe/instagram-graph-api-php-sdk
https://github.com/jstolpe/instagram-graph-api-php-sdk/blob/2a243c65d69fec9f64a4c36cbd214513609441c6/src/Instagram/Media/Media.php
src/Instagram/Media/Media.php
<?php /** * Copyright 2022 Justin Stolpe. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ namespace Instagram\Media; // other classes we need to use use Instagram\Instagram; use Instagram\Request\Params; use Instagram\Request\Fields; /** * Media * * Get info on a specific media. * - Endpoint Format: GET /{ig-media-id}?access_token={access-token} * - Facebook docs: https://developers.facebook.com/docs/instagram-api/reference/ig-media * * @package instagram-graph-api-php-sdk * @author Justin Stolpe * @link https://github.com/jstolpe/instagram-graph-api-php-sdk * @license https://opensource.org/licenses/MIT * @version 1.0 */ class Media extends Instagram { /** * @var integer $mediaId Instagram id of the media to get info on. */ protected $mediaId; /** * Contructor for instantiating a new object. * * @param array $config for the class. * @return void */ public function __construct( $config ) { // call parent for setup parent::__construct( $config ); // store the user id $this->mediaId = $config['media_id']; } /** * Get info on a hashtag. * * @param array $params Params for the GET request. * @return Instagram Response. */ public function getSelf( $params = array() ) { $getParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->mediaId, 'params' => $this->getParams( $params ) ); // ig get request $response = $this->get( $getParams ); // return response return $response; } /** * Set comments endabled for a media post. * * @param boolean $commentsEnabled enable or diable comments with true|false. * @return Instagram Response. */ public function setCommentsEnabled( $commentsEnabled ) { $postParams = array( // parameters for our endpoint 'endpoint' => '/' . $this->mediaId, 'params' => array( Params::COMMENT_ENABLED => $commentsEnabled ) ); // ig get request $response = $this->post( $postParams ); // return response return $response; } /** * Get params for the request. * * @param array $params specific params for the request. * @return array of params for the request. */ public function getParams( $params = array() ) { if ( $params ) { // specific params have been requested return $params; } else { // get all params // get field params $params[Params::FIELDS] = Fields::getDefaultMediaFieldsString(); // return our params return $params; } } } ?>
php
MIT
2a243c65d69fec9f64a4c36cbd214513609441c6
2026-01-05T04:50:12.911381Z
false
vinkla/headache
https://github.com/vinkla/headache/blob/92406487deae772dcfb020f52e6bc092e59a994e/headache.php
headache.php
<?php /** * Copyright (c) Vincent Klaiber * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @see https://github.com/vinkla/headache */ /* * Plugin Name: Headache * Description: An easy-to-swallow painkiller plugin for WordPress. * Author: Vincent Klaiber * Author URI: https://github.com/vinkla * Version: 3.6.0 * Plugin URI: https://github.com/vinkla/headache * GitHub Plugin URI: vinkla/headache */ declare(strict_types=1); namespace Headache; // Redirects all feeds to home page. function disable_feeds(): void { wp_redirect(home_url()); exit; } // Disable feeds. add_action('do_feed', __NAMESPACE__ . '\\disable_feeds', 1); add_action('do_feed_rdf', __NAMESPACE__ . '\\disable_feeds', 1); add_action('do_feed_rss', __NAMESPACE__ . '\\disable_feeds', 1); add_action('do_feed_rss2', __NAMESPACE__ . '\\disable_feeds', 1); add_action('do_feed_atom', __NAMESPACE__ . '\\disable_feeds', 1); // Disable comments feeds. add_action('do_feed_rss2_comments', __NAMESPACE__ . '\\disable_feeds', 1); add_action('do_feed_atom_comments', __NAMESPACE__ . '\\disable_feeds', 1); // Disable comments. add_filter('comments_open', '__return_false'); // Remove language dropdown on login screen. add_filter('login_display_language_dropdown', '__return_false'); // Disable XML RPC for security. add_filter('xmlrpc_enabled', '__return_false'); add_filter('xmlrpc_methods', '__return_false'); // Disable loading separate core block assets. add_filter('should_load_separate_core_block_assets', '__return_false'); // Remove WordPress version. remove_action('wp_head', 'wp_generator'); // Remove generated icons. remove_action('wp_head', 'wp_site_icon', 99); // Remove shortlink tag from <head>. remove_action('wp_head', 'wp_shortlink_wp_head', 10); // Remove shortlink tag from HTML headers. remove_action('template_redirect', 'wp_shortlink_header', 11); // Remove Really Simple Discovery link. remove_action('wp_head', 'rsd_link'); // Remove RSS feed links. remove_action('wp_head', 'feed_links', 2); // Remove all extra RSS feed links. remove_action('wp_head', 'feed_links_extra', 3); // Remove meta rel=dns-prefetch href=//s.w.org remove_action('wp_head', 'wp_resource_hints', 2); // Remove relational links for the posts. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10); // Remove REST API link tag from <head>. remove_action('wp_head', 'rest_output_link_wp_head', 10); // Remove REST API link tag from HTML headers. remove_action('template_redirect', 'rest_output_link_header', 11); // Remove emojis. // WordPress 6.4 deprecated the use of print_emoji_styles() function, but it has // been retained for backward compatibility purposes. // https://make.wordpress.org/core/2023/10/17/replacing-hard-coded-style-tags-with-wp_add_inline_style/ remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); // Remove oEmbeds. remove_action('wp_head', 'wp_oembed_add_discovery_links', 10); remove_action('wp_head', 'wp_oembed_add_host_js'); // Disable default users API endpoints for security. // https://www.wp-tweaks.com/hackers-can-find-your-wordpress-username/ function disable_rest_endpoints(array $endpoints): array { if (!is_user_logged_in()) { if (isset($endpoints['/wp/v2/users'])) { unset($endpoints['/wp/v2/users']); } if (isset($endpoints['/wp/v2/users/(?P<id>[\d]+)'])) { unset($endpoints['/wp/v2/users/(?P<id>[\d]+)']); } } return $endpoints; } add_filter('rest_endpoints', __NAMESPACE__ . '\\disable_rest_endpoints'); // Remove JPEG compression. function remove_jpeg_compression(): int { return 100; } add_filter('jpeg_quality', __NAMESPACE__ . '\\remove_jpeg_compression', 10, 2); // Update login page image link URL. function login_url(): string { return home_url(); } add_filter('login_headerurl', __NAMESPACE__ . '\\login_url'); // Update login page link title. function login_title(): string { return get_bloginfo('name'); } add_filter('login_headertext', __NAMESPACE__ . '\\login_title'); // Remove Gutenberg's front-end block styles. function remove_block_styles(): void { wp_deregister_style('wp-block-library'); wp_deregister_style('wp-block-library-theme'); } add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\remove_block_styles'); // Remove core block styles. // https://github.com/WordPress/gutenberg/issues/56065 function remove_core_block_styles(): void { wp_dequeue_style('core-block-supports'); } add_action('wp_footer', __NAMESPACE__ . '\\remove_core_block_styles'); // Remove Gutenberg's global styles. // https://github.com/WordPress/gutenberg/pull/34334#issuecomment-911531705 function remove_global_styles(): void { wp_dequeue_style('global-styles'); } add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\remove_global_styles'); // Remove classic theme styles. // https://github.com/WordPress/WordPress/commit/143fd4c1f71fe7d5f6bd7b64c491d9644d861355 function remove_classic_theme_styles(): void { wp_dequeue_style('classic-theme-styles'); } add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\remove_classic_theme_styles'); // Remove auto-sizes contain inline styles. // https://make.wordpress.org/core/2024/10/18/auto-sizes-for-lazy-loaded-images-in-wordpress-6-7/ function remove_auto_sizes_styles(): void { wp_dequeue_style('wp-img-auto-sizes-contain'); } add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\remove_auto_sizes_styles'); // Remove the SVG Filters that are mostly if not only used in Full Site Editing/Gutenberg // Detailed discussion at: https://github.com/WordPress/gutenberg/issues/36834 function remove_svg_filters(): void { remove_action('wp_body_open', 'gutenberg_global_styles_render_svg_filters'); remove_action('wp_body_open', 'wp_global_styles_render_svg_filters'); } add_action('init', __NAMESPACE__ . '\\remove_svg_filters'); // Remove contributor, subscriber and author roles. function remove_roles(): void { remove_role('author'); remove_role('contributor'); remove_role('subscriber'); } add_action('init', __NAMESPACE__ . '\\remove_roles'); // Disable attachment template loading and redirect to 404. // WordPress 6.4 introduced an update to disable attachment pages, but this // implementation is not as robust as the current one. // https://github.com/joppuyo/disable-media-pages/issues/41 // https://make.wordpress.org/core/2023/10/16/changes-to-attachment-pages/ function attachment_redirect_not_found(): void { if (is_attachment()) { global $wp_query; $wp_query->set_404(); status_header(404); nocache_headers(); } } add_filter('template_redirect', __NAMESPACE__ . '\\attachment_redirect_not_found'); // Disable attachment canonical redirect links. function disable_attachment_canonical_redirect_url(string $url): string { attachment_redirect_not_found(); return $url; } add_filter('redirect_canonical', __NAMESPACE__ . '\\disable_attachment_canonical_redirect_url', 0, 1); // Disable attachment links. function disable_attachment_link(string $url, int $id): string { if ($attachment_url = wp_get_attachment_url($id)) { return $attachment_url; } return $url; } add_filter('attachment_link', __NAMESPACE__ . '\\disable_attachment_link', 10, 2); // Randomize attachment slugs using UUIDs to avoid slug reservation. function disable_attachment_slug_reservation(string $slug, string $id, string $status, string $type): string { if ($type !== 'attachment') { return $slug; } if (preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $slug) > 0) { return $slug; } return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0x0fff) | 0x4000, random_int(0, 0x3fff) | 0x8000, random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff), ); } add_filter('wp_unique_post_slug', __NAMESPACE__ . '\\disable_attachment_slug_reservation', 10, 4); // Discourage search engines from indexing in non-production environments. function disable_indexing() { return wp_get_environment_type() === 'production' ? 1 : 0; } add_action('pre_option_blog_public', __NAMESPACE__ . '\\disable_indexing'); // Sanitize HTML content when pasting in TinyMCE editor. function sanitize_tiny_mce_html_content(array $config): array { $config['paste_preprocess'] = "function(plugin, args) { // Allow specific HTML tags while sanitizing the content const allowedTags = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'ol', 'ul', 'li', 'a']); const sanitizedContent = document.createElement('div'); sanitizedContent.innerHTML = args.content; // Remove elements not in the allowed tags sanitizedContent.querySelectorAll('*').forEach(element => { if (!allowedTags.has(element.tagName.toLowerCase())) { element.replaceWith(...element.childNodes); // Replace with child nodes } }); // Strip class and id attributes sanitizedContent.querySelectorAll('*').forEach(element => { element.removeAttribute('id'); element.removeAttribute('class'); }); // Return the clean HTML args.content = sanitizedContent.innerHTML; }"; return $config; } add_filter('tiny_mce_before_init', __NAMESPACE__ . '\\sanitize_tiny_mce_html_content'); // Disable the font library. // https://developer.wordpress.org/news/snippets/how-to-disable-the-font-library/ function disable_font_library(array $settings): array { $settings['fontLibraryEnabled'] = false; return $settings; } add_filter('block_editor_settings_all', __NAMESPACE__ . '\\disable_font_library');
php
MIT
92406487deae772dcfb020f52e6bc092e59a994e
2026-01-05T04:50:22.376521Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/District.php
src/ipip/db/District.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class District { public $reader = NULL; public function __construct($db) { $this->reader = new Reader($db); } public function find($ip, $language) { return $this->reader->find($ip, $language); } public function findMap($ip, $language) { return $this->reader->findMap($ip, $language); } public function findInfo($ip, $language) { $map = $this->findMap($ip, $language); if (NULL === $map) { return NULL; } return new DistrictInfo($map); } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/BaseStation.php
src/ipip/db/BaseStation.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class BaseStation { public $reader = NULL; public function __construct($db) { $this->reader = new Reader($db); } public function find($ip, $language) { return $this->reader->find($ip, $language); } public function findMap($ip, $language) { return $this->reader->findMap($ip, $language); } public function findInfo($ip, $language) { $map = $this->findMap($ip, $language); if (NULL === $map) { return NULL; } return new BaseStationInfo($map); } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/Reader.php
src/ipip/db/Reader.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class Reader { const IPV4 = 1; const IPV6 = 2; private $file = NULL; private $fileSize = 0; private $nodeCount = 0; private $nodeOffset = 0; private $meta = []; private $database = ''; /** * Reader constructor. * @param $database * @throws \Exception */ public function __construct($database) { $this->database = $database; $this->init(); } private function init() { if (is_readable($this->database) === FALSE) { throw new \InvalidArgumentException("The IP Database file \"{$this->database}\" does not exist or is not readable."); } $this->file = @fopen($this->database, 'rb'); if ($this->file === FALSE) { throw new \InvalidArgumentException("IP Database File opening \"{$this->database}\"."); } $this->fileSize = @filesize($this->database); if ($this->fileSize === FALSE) { throw new \UnexpectedValueException("Error determining the size of \"{$this->database}\"."); } $metaLength = unpack('N', fread($this->file, 4))[1]; $text = fread($this->file, $metaLength); $this->meta = json_decode($text, 1); if (isset($this->meta['fields']) === FALSE || isset($this->meta['languages']) === FALSE) { throw new \Exception('IP Database metadata error.'); } $fileSize = 4 + $metaLength + $this->meta['total_size']; if ($fileSize != $this->fileSize) { throw new \Exception('IP Database size error.'); } $this->nodeCount = $this->meta['node_count']; $this->nodeOffset = 4 + $metaLength; } /** * @param $ip * @param string $language * @return array|NULL */ public function find($ip, $language) { if (is_resource($this->file) === FALSE) { throw new \BadMethodCallException('IPIP DB closed.'); } if (isset($this->meta['languages'][$language]) === FALSE) { throw new \InvalidArgumentException("language : {$language} not support."); } if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === FALSE) { throw new \InvalidArgumentException("The value \"$ip\" is not a valid IP address."); } if (strpos($ip, '.') !== FALSE && !$this->supportV4()) { throw new \InvalidArgumentException("The Database not support IPv4 address."); } elseif (strpos($ip, ':') !== FALSE && !$this->supportV6()) { throw new \InvalidArgumentException("The Database not support IPv6 address."); } try { $node = $this->findNode($ip); if ($node > 0) { $data = $this->resolve($node); $values = explode("\t", $data); return array_slice($values, $this->meta['languages'][$language], count($this->meta['fields'])); } } catch (\Exception $e) { return NULL; } return NULL; } public function findMap($ip, $language) { $array = $this->find($ip, $language); if (NULL === $array) { return NULL; } return array_combine($this->meta['fields'], $array); } private $v4offset = 0; /** * @param $ip * @return int * @throws \Exception */ private function findNode($ip) { $binary = inet_pton($ip); $bitCount = strlen($binary) * 8; // 32 | 128 $key = substr($binary, 0, 2); $node = 0; $index = 0; if ($bitCount === 32) { if ($this->v4offset === 0) { for ($i = 0; $i < 96 && $node < $this->nodeCount; $i++) { if ($i >= 80) { $idx = 1; } else { $idx = 0; } $node = $this->readNode($node, $idx); if ($node > $this->nodeCount) { return 0; } } $this->v4offset = $node; } else { $node = $this->v4offset; } } for ($i = $index; $i < $bitCount; $i++) { if ($node >= $this->nodeCount) { break; } $node = $this->readNode($node, 1 & ((0xFF & ord($binary[$i >> 3])) >> 7 - ($i % 8))); } if ($node === $this->nodeCount) { return 0; } elseif ($node > $this->nodeCount) { return $node; } throw new \Exception("find node failed."); } /** * @param $node * @param $index * @return mixed * @throws \Exception */ private function readNode($node, $index) { return unpack('N', $this->read($this->file, $node * 8 + $index * 4, 4))[1]; } /** * @param $node * @return mixed * @throws \Exception */ private function resolve($node) { $resolved = $node - $this->nodeCount + $this->nodeCount * 8; if ($resolved >= $this->fileSize) { return NULL; } $bytes = $this->read($this->file, $resolved, 2); $size = unpack('N', str_pad($bytes, 4, "\x00", STR_PAD_LEFT))[1]; $resolved += 2; return $this->read($this->file, $resolved, $size); } public function close() { if (is_resource($this->file) === TRUE) { fclose($this->file); } } /** * @param $stream * @param $offset * @param $length * @return bool|string * @throws \Exception */ private function read($stream, $offset, $length) { if ($length > 0) { if (fseek($stream, $offset + $this->nodeOffset) === 0) { $value = fread($stream, $length); if (strlen($value) === $length) { return $value; } } throw new \Exception("The Database file read bad data."); } return ''; } public function supportV6() { return ($this->meta['ip_version'] & self::IPV6) === self::IPV6; } public function supportV4() { return ($this->meta['ip_version'] & self::IPV4) === self::IPV4; } public function getMeta() { return $this->meta; } /** * @return int UTC Timestamp */ public function getBuildTime() { return $this->meta['build']; } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/IDCInfo.php
src/ipip/db/IDCInfo.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class IDCInfo { public $country_name = ''; public $region_name = ''; public $city_name = ''; public $owner_domain = ''; public $isp_domain = ''; public $idc = ''; public function __construct(array $data) { foreach ($data AS $field => $value) { $this->{$field} = $value; } } public function __get($name) { return $this->{$name}; } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/BaseStationInfo.php
src/ipip/db/BaseStationInfo.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class BaseStationInfo { public $country_name = ''; public $region_name = ''; public $city_name = ''; public $owner_domain = ''; public $isp_domain = ''; public $base_station = ''; public function __construct(array $data) { foreach ($data AS $field => $value) { $this->{$field} = $value; } } public function __get($name) { return $this->{$name}; } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/IDC.php
src/ipip/db/IDC.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class IDC { public $reader = NULL; public function __construct($db) { $this->reader = new Reader($db); } public function find($ip, $language) { return $this->reader->find($ip, $language); } public function findMap($ip, $language) { return $this->reader->findMap($ip, $language); } public function findInfo($ip, $language) { $map = $this->findMap($ip, $language); if (NULL === $map) { return NULL; } return new IDCInfo($map); } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/CityInfo.php
src/ipip/db/CityInfo.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class CityInfo { public $country_name = ''; public $region_name = ''; public $city_name = ''; public $owner_domain = ''; public $isp_domain = ''; public $latitude = ''; public $longitude = ''; public $timezone = ''; public $utc_offset = ''; public $china_admin_code = ''; public $idd_code = ''; public $country_code = ''; public $continent_code = ''; public $idc = ''; public $base_station = ''; public $country_code3 = ''; public $european_union = ''; public $currency_code = ''; public $currency_name = ''; public $anycast = ''; public function __construct(array $data) { foreach ($data AS $field => $value) { $this->{$field} = $value; } } public function __get($name) { return $this->{$name}; } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/City.php
src/ipip/db/City.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class City { public $reader = NULL; public function __construct($db) { $this->reader = new Reader($db); } public function find($ip, $language) { return $this->reader->find($ip, $language); } public function findMap($ip, $language) { return $this->reader->findMap($ip, $language); } public function findInfo($ip, $language) { $map = $this->findMap($ip, $language); if (NULL === $map) { return NULL; } return new CityInfo($map); } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
ipipdotnet/ipdb-php
https://github.com/ipipdotnet/ipdb-php/blob/9be2e284369c34267487487f4492de26e20a7735/src/ipip/db/DistrictInfo.php
src/ipip/db/DistrictInfo.php
<?php /** * @site https://www.ipip.net * @desc Parse IP library in ipdb format * @copyright IPIP.net */ namespace ipip\db; class DistrictInfo { public $country_name = ''; public $region_name = ''; public $city_name = ''; public $district_name = ''; public $china_admin_code = ''; public $covering_radius = ''; public $longitude = ''; public $latitude = ''; public function __construct(array $data) { foreach ($data AS $field => $value) { $this->{$field} = $value; } } public function __get($name) { return $this->{$name}; } }
php
Apache-2.0
9be2e284369c34267487487f4492de26e20a7735
2026-01-05T04:50:23.381054Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/app-console.php
app-console.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright (c) 2010 SkeekS * @date 10.11.2017 */ // fcgi doesn't have STDIN and STDOUT defined by default defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); //Standard loader require_once(__DIR__ . '/bootstrap.php'); \Yii::beginProfile('Load config app'); if (YII_ENV == 'dev') { error_reporting(E_ALL); ini_set('display_errors', 'On'); } $config = new \Yiisoft\Config\Config( new \Yiisoft\Config\ConfigPaths(ROOT_DIR, "config"), null, [ \Yiisoft\Config\Modifier\RecursiveMerge::groups('console', 'console-' . ENV, 'params', "params-console-" . ENV), ], "params-console-" . ENV ); if ($config->has('console-' . ENV)) { $configData = $config->get('console-' . ENV); } else { $configData = $config->get('console'); } \Yii::endProfile('Load config app'); $application = new yii\console\Application($configData); $exitCode = $application->run(); exit($exitCode);
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/global.php
global.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright (c) 2010 SkeekS * @date 10.11.2017 */ defined('ROOT_DIR') or die('Please specify the constant "ROOT_DIR" in index.php in your application.'); defined('VENDOR_DIR') or define('VENDOR_DIR', ROOT_DIR . '/vendor'); //Если Yii окружение не определено раньше в index.php или @app/config/global.php if (!defined('YII_ENV')) { define('YII_ENV', 'prod'); } //А мы все равно ее определим if (!defined('YII_DEBUG')) { if (YII_ENV == 'prod') { defined('YII_DEBUG') or define('YII_DEBUG', false); } else { defined('YII_DEBUG') or define('YII_DEBUG', true); } } if (!defined('ENV')) { $env = getenv('ENV'); if (empty($env)) { $env = YII_ENV; } define('ENV', $env); } /** * Глобальный файл где задается настройка окружения. * Если файла не будет создано, то окружение будет считано функцией getenv() или по другому прниципу */ defined('APP_ENV_GLOBAL_FILE') or define('APP_ENV_GLOBAL_FILE', ROOT_DIR . '/global.php'); //Проверка файла который создается скриптом в момент установки проекта, если он создан, то прочитаются его настройки. $globalFileInited = APP_ENV_GLOBAL_FILE; if (file_exists($globalFileInited)) { require $globalFileInited; }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/app-web.php
app-web.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ $env = getenv('ENV'); if (!empty($env)) { defined('ENV') or define('ENV', $env); } require_once(__DIR__ . '/bootstrap.php'); \Yii::beginProfile('Load config app'); if (YII_ENV == 'dev') { error_reporting(E_ALL); ini_set('display_errors', 'On'); } $config = new \Yiisoft\Config\Config( new \Yiisoft\Config\ConfigPaths(ROOT_DIR, "config"), null, [ \Yiisoft\Config\Modifier\RecursiveMerge::groups('web', 'web-' . ENV, 'params', "params-web-" . ENV), ], "params-web-" . ENV ); if ($config->has('web-' . ENV)) { $configData = $config->get('web-' . ENV); } else { $configData = $config->get('web'); } //print_r($configData);die; \Yii::endProfile('Load config app'); \Yii::beginProfile('new app'); /*print_r($configData);die;*/ $application = new yii\web\Application($configData); \Yii::endProfile('new app'); $application->run();
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/requirements.php
requirements.php
<?php /** * Application requirement checker script. * * In order to run this script use the following console command: * php requirements.php * * In order to run this script from the web, you should copy it to the web root. * If you are using Linux you can create a hard link instead, using the following command: * ln requirements.php ../requirements.php */ // you may need to adjust this path to the correct Yii framework path define("ROOT_DIR", dirname(dirname(__DIR__))); $frameworkPath = ROOT_DIR . '/vendor/yiisoft/yii2'; if (!is_dir($frameworkPath)) { echo '<h1>Error</h1>'; echo '<p><strong>The path to yii framework seems to be incorrect.</strong></p>'; echo '<p>You need to install Yii framework via composer or adjust the framework path in file <abbr title="' . __FILE__ . '">' . basename(__FILE__) . '</abbr>.</p>'; echo '<p>Please refer to the <abbr title="' . dirname(__FILE__) . '/README.md">README</abbr> on how to install Yii.</p>'; } require_once($frameworkPath . '/requirements/YiiRequirementChecker.php'); $requirementsChecker = new YiiRequirementChecker(); $gdMemo = $imagickMemo = 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.'; $gdOK = $imagickOK = false; if (extension_loaded('imagick')) { $imagick = new Imagick(); $imagickFormats = $imagick->queryFormats('PNG'); if (in_array('PNG', $imagickFormats)) { $imagickOK = true; } else { $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.'; } } if (extension_loaded('gd')) { $gdInfo = gd_info(); if (!empty($gdInfo['FreeType Support'])) { $gdOK = true; } else { $gdMemo = 'GD extension should be installed with FreeType support in order to be used for image CAPTCHA.'; } } function wriatableCheck() { $dirs = [ 'console/runtime', 'common/runtime', 'frontend/runtime', 'frontend/web/assets', ]; foreach ($dirs as $dirPath) { $dirPath = ROOT_DIR . "/" . $dirPath; if (!is_dir($dirPath)) { return 0; break; } if (!is_writable($dirPath)) { return 0; break; } } return 1; } /** * Adjust requirements according to your application specifics. */ $requirements = array( // Database : array( 'name' => 'PDO extension', 'mandatory' => true, 'condition' => extension_loaded('pdo'), 'by' => 'All DB-related classes', ), /*array( 'name' => 'PDO SQLite extension', 'mandatory' => false, 'condition' => extension_loaded('pdo_sqlite'), 'by' => 'All DB-related classes', 'memo' => 'Required for SQLite database.', ),*/ array( 'name' => 'PDO MySQL extension', 'mandatory' => false, 'condition' => extension_loaded('pdo_mysql'), 'by' => 'All DB-related classes', 'memo' => 'Required for MySQL database.', ), /*array( 'name' => 'PDO PostgreSQL extension', 'mandatory' => false, 'condition' => extension_loaded('pdo_pgsql'), 'by' => 'All DB-related classes', 'memo' => 'Required for PostgreSQL database.', ),*/ // Cache : array( 'name' => 'Memcache extension', 'mandatory' => false, 'condition' => extension_loaded('memcache') || extension_loaded('memcached'), 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html">MemCache</a>', 'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc-2.0/yii-caching-memcache.html#$useMemcached-detail">MemCache::useMemcached</a> to <code>true</code>.' : '' ), array( 'name' => 'APC extension', 'mandatory' => false, 'condition' => extension_loaded('apc'), 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-caching-apccache.html">ApcCache</a>', ), // CAPTCHA: array( 'name' => 'GD PHP extension with FreeType support', 'mandatory' => false, 'condition' => $gdOK, 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>', 'memo' => $gdMemo, ), array( 'name' => 'ImageMagick PHP extension with PNG support', 'mandatory' => false, 'condition' => $imagickOK, 'by' => '<a href="http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html">Captcha</a>', 'memo' => $imagickMemo, ), // PHP ini : 'phpExposePhp' => array( 'name' => 'Expose PHP', 'mandatory' => false, 'condition' => $requirementsChecker->checkPhpIniOff("expose_php"), 'by' => 'Security reasons', 'memo' => '"expose_php" should be disabled at php.ini', ), 'phpAllowUrlInclude' => array( 'name' => 'PHP allow url include', 'mandatory' => false, 'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"), 'by' => 'Security reasons', 'memo' => '"allow_url_include" should be disabled at php.ini', ), 'phpSmtp' => array( 'name' => 'PHP mail SMTP', 'mandatory' => false, 'condition' => strlen(ini_get('SMTP')) > 0, 'by' => 'Email sending', 'memo' => 'PHP mail SMTP server required', ), 'short_open_tag' => array( 'name' => 'short_open_tag', 'mandatory' => false, 'condition' => $requirementsChecker->checkPhpIniOn("short_open_tag"), 'by' => 'SkeekS CMS', 'memo' => '"short_open_tag" should be enabled at php.ini', ), 'writableDirs' => array( 'name' => 'Writable Directories', 'mandatory' => false, 'condition' => wriatableCheck(), 'by' => 'SkeekS CMS', 'memo' => 'Verifying the existence and rights of access to directories', ), ); $requirementsChecker->checkYii()->check($requirements)->render();
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/bootstrap.php
bootstrap.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright (c) 2010 SkeekS * @date 10.11.2017 */ require(__DIR__ . '/global.php'); require(VENDOR_DIR . '/autoload.php'); require(VENDOR_DIR . '/yiisoft/yii2/Yii.php'); \Yii::setAlias('@root', ROOT_DIR); \Yii::setAlias('@vendor', VENDOR_DIR);
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasIcon.php
src/IHasIcon.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms; /** * @property string $icon; * * @author Semenov Alexander <semenov@skeeks.com> */ interface IHasIcon { /** * @return string */ public function getIcon(); /** * @param string $icon * @return mixed */ public function setIcon($icon); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/Module.php
src/Module.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright (c) 2010 SkeekS * @date 11.03.2018 */ namespace skeeks\cms; /** * Class Module * @package skeeks\cms */ class Module extends \yii\base\Module { public $controllerNamespace = 'skeeks\cms\controllers'; }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/Skeeks.php
src/Skeeks.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 27.03.2015 */ namespace skeeks\cms; use skeeks\cms\backend\BackendComponent; use skeeks\cms\models\CmsCompany; use skeeks\cms\models\CmsCompanyAddress; use skeeks\cms\models\CmsCompanyEmail; use skeeks\cms\models\CmsCompanyLink; use skeeks\cms\models\CmsCompanyPhone; use skeeks\cms\models\CmsContentElement; use skeeks\cms\models\CmsDeal; use skeeks\cms\models\CmsFaq; use skeeks\cms\models\CmsLog; use skeeks\cms\models\CmsProject; use skeeks\cms\models\CmsSite; use skeeks\cms\models\CmsSiteDomain; use skeeks\cms\models\CmsTask; use skeeks\cms\models\CmsTree; use skeeks\cms\models\CmsUser; use skeeks\cms\models\CmsUserAddress; use skeeks\cms\models\CmsUserEmail; use skeeks\cms\models\CmsUserPhone; use skeeks\cms\models\CmsWebNotify; use skeeks\cms\shop\models\ShopBill; use skeeks\cms\shop\models\ShopBonusTransaction; use skeeks\cms\shop\models\ShopCmsContentElement; use skeeks\cms\shop\models\ShopPayment; use skeeks\modules\cms\form2\cmsWidgets\form2\FormWidget; use yii\base\BootstrapInterface; use yii\base\Component; use yii\base\Event; use yii\caching\TagDependency; use yii\console\Application; use yii\db\BaseActiveRecord; use yii\helpers\ArrayHelper; use yii\web\View; /** * @property array $logTypes * @property CmsSite $site * * @author Semenov Alexander <semenov@skeeks.com> */ class Skeeks extends Component implements BootstrapInterface { /** * @var CmsSite */ protected $_site = null; /** * @var string */ public $siteClass = CmsSite::class; /** * @var array */ public $_logTypes = []; /** * @var string[] */ public $defaultLogTypes = [ CmsLog::LOG_TYPE_COMMENT => 'Комментарий', CmsLog::LOG_TYPE_DELETE => 'Удаление', CmsLog::LOG_TYPE_UPDATE => 'Обновление', CmsLog::LOG_TYPE_INSERT => 'Создание', ]; public function bootstrap($application) { Event::on(View::class, View::EVENT_AFTER_RENDER, function (Event $event) { /*<!--форма обратная связь--> [sx]w=skeeks-modules-cms-form2-cmsWidgets-form2-FormWidget&form_id=2[/sx]*/ if (BackendComponent::getCurrent()) { return false; } $content = $event->output; if (strpos($content, "[sx]") !== false) { $search = array( '/\[sx\](.*?)\[\/sx\]/is', ); $replace = array( '<strong>$1</strong>', ); /*$content = preg_replace ($search, $replace, $content);*/ $content = preg_replace_callback ($search, function ($matches) { $string = $matches[0]; $string = str_replace("[sx]", "", $string); $string = str_replace("[/sx]", "", $string); $string = html_entity_decode($string); $data = []; parse_str($string, $data); $wClass = ArrayHelper::getValue($data, "w"); if ($wClass == 'form') { $wClass = FormWidget::class; } if (!isset($data['namespace'])) { $data['namespace'] = md5($string); } if ($wClass) { $wClass = "\\" . $wClass; unset($data['w']); $wClass = str_replace("-", '\\', $wClass); if (class_exists($wClass)) { return $wClass::widget($data); } else { return $wClass; } } return ""; }, $content); $event->output = $content; } }); //Уведомления для пользователей Event::on(CmsLog::class, BaseActiveRecord::EVENT_AFTER_INSERT, function (Event $event) { /** * @var $sender CmsLog */ $sender = $event->sender; //Поставлена задача if ($sender->log_type == CmsLog::LOG_TYPE_INSERT) { if ($sender->model_code == CmsTask::class) { /** * @var $model CmsTask */ $model = $sender->model; if ($model->executor_id && $model->executor_id != $model->created_by) { $notify = new CmsWebNotify(); $notify->cms_user_id = $model->executor_id; $notify->name = "Вам поставлена новая задача"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); } } } if ($sender->log_type == CmsLog::LOG_TYPE_UPDATE) { if ($sender->model_code == CmsTask::class) { /** * @var $model CmsTask */ $model = $sender->model; //Только если не сам себе ставил задачу if ($model->executor_id != $model->created_by) { $executor = ArrayHelper::getValue($sender->data, "executor_id.value"); $status = ArrayHelper::getValue($sender->data, "status.value"); $oldStatus = ArrayHelper::getValue($sender->data, "status.old_value"); //У задачи поменялся исполнитель if ($executor) { $notify = new CmsWebNotify(); $notify->cms_user_id = $executor; $notify->name = "Вам передали задачу"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); } //У задачи поменялся статус if ($status) { if ($status == CmsTask::STATUS_ON_CHECK) { $notify = new CmsWebNotify(); $notify->cms_user_id = $model->created_by; $notify->name = "Вам необходимо проверить задачу"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); } /*if ($status == CmsTask::STATUS_READY) { $notify = new CmsWebNotify(); $notify->cms_user_id = $model->created_by; $notify->name = "Ваша задача проверена"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); }*/ if ($status == CmsTask::STATUS_CANCELED) { $notify = new CmsWebNotify(); $notify->cms_user_id = $model->created_by; $notify->name = "Задача отменена"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); $notify = new CmsWebNotify(); $notify->cms_user_id = $model->executor_id; $notify->name = "Задача отменена"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); } if ($status == CmsTask::STATUS_IN_WORK && $oldStatus == CmsTask::STATUS_ON_CHECK) { $notify = new CmsWebNotify(); $notify->cms_user_id = $model->executor_id; $notify->name = "Задача возобновлена"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify->save(); } } } } } //Добавлен комментарий if ($sender->log_type == CmsLog::LOG_TYPE_COMMENT) { //Комментарий к задаче if ($sender->model_code == CmsTask::class) { /** * @var $model CmsTask */ $model = $sender->model; $notify = new CmsWebNotify(); $notify->cms_user_id = $model->executor_id; $notify->name = "Добавлен новый комментарий к задаче"; $notify->model_id = $sender->model_id; $notify->model_code = $sender->model_code; $notify2 = clone $notify; $user_ids = []; if ($model->executor_id) { $user_ids[] = $model->executor_id; } if ($model->created_by) { $user_ids[] = $model->created_by; } $user_ids = array_unique($user_ids); if ($user_ids) { foreach ($user_ids as $id) { if ($id != \Yii::$app->user->id) { $notifyTmp = clone $notify; $notifyTmp->cms_user_id = $id; $notifyTmp->save(); } } } } } }); } public $modelsConfig = [ CmsFaq::class => [ 'name' => 'Вопросы/Ответы', 'name_one' => 'Вопрос/Ответ', 'controller' => 'cms/admin-cms-faq', ], CmsTree::class => [ 'name' => 'Разделы', 'name_one' => 'Раздел', 'controller' => 'cms/admin-tree', ], CmsCompany::class => [ 'name' => 'Компании', 'name_one' => 'Компания', 'controller' => 'cms/admin-cms-company', ], CmsCompanyEmail::class => [ 'name' => 'Email-ы компаний', 'name_one' => 'Email компании', 'controller' => 'cms/admin-cms-company-email', ], CmsCompanyPhone::class => [ 'name' => 'Телефоны компаний', 'name_one' => 'Телефон компании', 'controller' => 'cms/admin-cms-company-phone', ], CmsCompanyAddress::class => [ 'name' => 'Адреса компаний', 'name_one' => 'Адрес компании', 'controller' => 'cms/admin-cms-company-address', ], CmsCompanyLink::class => [ 'name' => 'Ссылки компаний', 'name_one' => 'Ссылка компании', 'controller' => 'cms/admin-cms-company-link', ], CmsUser::class => [ 'name' => 'Пользователи', 'name_one' => 'Пользователь', 'controller' => 'cms/admin-user', ], CmsUserEmail::class => [ 'name' => 'Email-ы клиентов', 'name_one' => 'Email клиента', 'controller' => 'cms/admin-user-email', ], CmsUserPhone::class => [ 'name' => 'Телефоны клиентов', 'name_one' => 'Телефон клиента', 'controller' => 'cms/admin-user-phone', ], CmsUserAddress::class => [ 'name' => 'Адреса клиентов', 'name_one' => 'Адрес клиента', 'controller' => 'cms/admin-user-address', ], CmsDeal::class => [ 'name' => 'Сделки', 'name_one' => 'Сделка', 'controller' => 'cms/admin-cms-deal', ], CmsProject::class => [ 'name' => 'Проекты', 'name_one' => 'Проект', 'controller' => 'cms/admin-cms-project', ], CmsTask::class => [ 'name' => 'Задачи', 'name_one' => 'Задача', 'controller' => 'cms/admin-cms-task', ], ShopBill::class => [ 'name' => 'Счета', 'name_one' => 'Счет', 'controller' => 'cms/admin-cms-bill', ], ShopPayment::class => [ 'name' => 'Платежи', 'name_one' => 'Платеж', 'controller' => 'shop/admin-payment', ], ShopBonusTransaction::class => [ 'name' => 'Бонусы', 'name_one' => 'Бонус', 'controller' => 'shop/admin-bonus-transaction', ], CmsContentElement::class => [ 'name' => 'Контент', 'name_one' => 'Контент', 'controller' => 'cms/admin-cms-content-element', ], ShopCmsContentElement::class => [ 'name' => 'Товары', 'name_one' => 'Товар', 'controller' => 'shop/admin-cms-content-element', ], ]; /** * @return array */ public function setLogTypes(array $logTypes) { $this->_logTypes = ArrayHelper::merge((array)$this->_logTypes, (array)$logTypes); return $this; } /** * @return array */ public function getLogTypes() { return ArrayHelper::merge((array)$this->defaultLogTypes, (array)$this->_logTypes); } /** * @var null */ private $_serverName = null; /** * @return CmsSite */ public function getSite() { $cmsSiteClass = $this->siteClass; if ($this->_site === null) { if (\Yii::$app instanceof \yii\console\Application) { if ($cms_site_id = getenv("CMS_SITE")) { $this->_site = $cmsSiteClass::find()->active()->andWhere(['id' => $cms_site_id])->one(); } else { $table = $cmsSiteClass::safeGetTableSchema(); if ($table) { if ($table->getColumn('is_default')) { $this->_site = $cmsSiteClass::find()->active()->andWhere(['is_default' => 1])->one(); } else { $this->_site = $cmsSiteClass::find()->active()->one(); } } } } else { $this->_serverName = \Yii::$app->getRequest()->getServerName(); $dependencySiteDomain = new TagDependency([ 'tags' => [ (new CmsSiteDomain())->getTableCacheTag(), ], ]); $cmsDomain = CmsSiteDomain::getDb()->cache(function ($db) { return CmsSiteDomain::find()->where(['domain' => $this->_serverName])->one(); }, null, $dependencySiteDomain); /** * @var CmsSiteDomain $cmsDomain */ if ($cmsDomain) { //$this->_site = $cmsDomain->cmsSite; $this->_site = CmsSiteDomain::getDb()->cache(function ($db) use ($cmsSiteClass, $cmsDomain) { return $cmsSiteClass::find()->andWhere(['id' => $cmsDomain->cms_site_id])->limit(1)->one(); }, null, new TagDependency([ 'tags' => [ (new CmsSiteDomain())->getTableCacheTagCmsSite($cmsDomain->cms_site_id), (new $cmsSiteClass())->getTableCacheTag(), ], ]) ); } else { $this->_site = CmsSiteDomain::getDb()->cache(function ($db) use ($cmsSiteClass) { return $cmsSiteClass::find()->active()->andWhere(['is_default' => 1])->one(); }, null, new TagDependency([ 'tags' => [ (new $cmsSiteClass())->getTableCacheTag(), ], ]) ); } } } if (\Yii::$app instanceof Application) { if ($this->_site) { if ($this->_site->cmsSiteMainDomain) { \Yii::$app->urlManager->hostInfo = $this->_site->cmsSiteMainDomain->url; } } } //Если только поставили проект, и база еще пустая. if (!$this->_site) { //$this->_site = new CmsSite(); //$this->_site->setIsNewRecord(true); } return $this->_site; } /** * @param CmsSite $cmsSite * @return $this */ public function setSite(CmsSite $cmsSite) { $this->_site = $cmsSite; return $this; } /** * @return void */ static public function unlimited() { set_time_limit(0); ini_set("memory_limit", "50G"); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasName.php
src/IHasName.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms; /** * @property string $name; * * @author Semenov Alexander <semenov@skeeks.com> */ interface IHasName { /** * @return string */ public function getName(); /** * @param string|array $name * @return mixed */ public function setName($name); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasConfigForm.php
src/IHasConfigForm.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms; use yii\widgets\ActiveForm; /** * @author Semenov Alexander <semenov@skeeks.com> */ interface IHasConfigForm { /** * @param ActiveForm $form * @return string */ public function renderConfigFormFields(ActiveForm $form); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasModel.php
src/IHasModel.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright 2010 SkeekS * @date 05.03.2017 */ namespace skeeks\cms; use yii\base\BaseObject; use yii\base\Component; use yii\base\Model; use yii\db\ActiveRecord; /** * @property $model; * * Interface IHasModel * @package skeeks\cms */ interface IHasModel { /** * @return Model|ActiveRecord */ public function getModel(); /** * @param Model|ActiveRecord|Component|Object $model * @return mixed */ public function setModel($model); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasPermissions.php
src/IHasPermissions.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright 2010 SkeekS * @date 05.03.2017 */ namespace skeeks\cms; /** * @property $permissionNames; * @property $permissionName; * @property bool $isAllow; * * Interface IHasPermissions * @package skeeks\cms */ interface IHasPermissions { /** * @return string */ public function getPermissionName(); /** * @return array */ public function getPermissionNames(); /** * @return bool */ public function getIsAllow(); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasPermission.php
src/IHasPermission.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright 2010 SkeekS * @date 05.03.2017 */ namespace skeeks\cms; /** * @property $permissionName; * * Interface IHasPermission * @package skeeks\cms */ interface IHasPermission { /** * @return string */ public function getPermissionName(); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasImage.php
src/IHasImage.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms; /** * @property string $image; * * @author Semenov Alexander <semenov@skeeks.com> */ interface IHasImage { /** * @return string */ public function getImage(); /** * @param string $image * @return mixed */ public function setImage($image); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/IHasUrl.php
src/IHasUrl.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link https://skeeks.com/ * @copyright 2010 SkeekS * @date 05.03.2017 */ namespace skeeks\cms; /** * @property $url; * * Interface IHasUrl * @package skeeks\cms */ interface IHasUrl { /** * @return string */ public function getUrl(); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/query/CmsTreeActiveQuery.php
src/query/CmsTreeActiveQuery.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\query; use skeeks\cms\models\CmsContentElementTree; use skeeks\cms\models\CmsTree; use skeeks\cms\models\Tree; use yii\helpers\ArrayHelper; /** * @author Semenov Alexander <semenov@skeeks.com> */ class CmsTreeActiveQuery extends CmsActiveQuery { public $is_active = false; /** * @param mixed $id * @return CmsTreeActiveQuery */ public function sxId(mixed $id) { return $this->andWhere(['sx_id' => $id]); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/query/CmsActiveQuery.php
src/query/CmsActiveQuery.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 09.03.2015 */ namespace skeeks\cms\query; use http\Exception\InvalidArgumentException; use skeeks\cms\components\Cms; use skeeks\cms\models\CmsSite; use skeeks\cms\models\User; use yii\db\ActiveQuery; /** * Class CmsActiveQuery * @package skeeks\cms\query */ class CmsActiveQuery extends ActiveQuery { public $is_active = true; /** * @param bool $state * @return $this */ public function active($state = true) { if ($this->is_active === true) { return $this->andWhere([$this->getPrimaryTableName().'.is_active' => $state]); } return $this->andWhere([$this->getPrimaryTableName().'.active' => ($state == true ? Cms::BOOL_Y : Cms::BOOL_N)]); } /** * @param bool $state * @return $this */ public function default($state = true) { if ($state === true) { return $this->andWhere([$this->getPrimaryTableName().'.is_default' => 1]); } else { return $this->andWhere(['!=', $this->getPrimaryTableName().'.is_default', 1]); } } /** * @param int|strin|User $user * @return static */ public function createdBy($user = null) { $user_id = null; if (!$user) { $user = \Yii::$app->user->identity; } if (is_int($user)) { $user_id = $user; } elseif (is_string($user)) { $user_id = (int) $user; } elseif ($user instanceof User) { $user_id = (int) $user->id; } else { throw new InvalidArgumentException("Parametr user invalid"); } return $this->andWhere([$this->getPrimaryTableName().'.created_by' => $user_id]); } /** * @param int $order * @return $this */ public function sort($order = SORT_ASC) { return $this->orderBy([$this->getPrimaryTableName().'.priority' => $order]); } /** * Фильтрация по сайту * @param int|CmsSite $cmsSite * * @return CmsActiveQuery */ public function cmsSite($cmsSite = null) { $cms_site_id = null; if (is_int($cmsSite)) { $cms_site_id = $cmsSite; } elseif ($cmsSite instanceof CmsSite) { $cms_site_id = $cmsSite->id; } else { $cms_site_id = \Yii::$app->skeeks->site->id; } $alias = $this->getPrimaryTableName(); if ($this->from) { foreach ($this->from as $code => $table) { if ($table == $alias) { $alias = $code; } } } return $this->andWhere([$alias.'.cms_site_id' => $cms_site_id]); } /** * @param string $word * @return $this */ public function search($word = '') { $modelClass = $this->modelClass; if ($modelClass::getTableSchema()->columns) { $where = []; $where[] = "or"; foreach ($modelClass::getTableSchema()->columns as $key => $column) { $where[] = ['like', $this->getPrimaryTableName() . "." . $key, $word]; } $this->andWhere($where); } return $this; } /** * @depricated * * @param bool $state * @return $this */ public function def($state = true) { return $this->andWhere(['def' => ($state == true ? Cms::BOOL_Y : Cms::BOOL_N)]); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/query/CmsContentPropertyActiveQuery.php
src/query/CmsContentPropertyActiveQuery.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\query; /** * @author Semenov Alexander <semenov@skeeks.com> */ class CmsContentPropertyActiveQuery extends CmsActiveQuery { /** * @param mixed $id * @return CmsContentPropertyActiveQuery */ public function sxId(mixed $id) { return $this->andWhere(['sx_id' => $id]); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/query/CmsStorageFileActiveQuery.php
src/query/CmsStorageFileActiveQuery.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\query; /** * @author Semenov Alexander <semenov@skeeks.com> */ class CmsStorageFileActiveQuery extends CmsActiveQuery { /** * @param string $clusterId * @param string $clusterFile * @return CmsStorageFileActiveQuery */ public function clusterFile(string $clusterId, string $clusterFile) { return $this ->andWhere([$this->getPrimaryTableName().'.cluster_id' => $clusterId]) ->andWhere([$this->getPrimaryTableName().'.cluster_file' => $clusterFile]) ; } /** * @param string $clusterId * @return CmsStorageFileActiveQuery */ public function cluster(string $clusterId) { return $this ->andWhere([$this->getPrimaryTableName().'.cluster_id' => $clusterId]) ; } /** * @param mixed $id * @return CmsStorageFileActiveQuery */ public function sxId(mixed $id) { return $this->andWhere(['sx_id' => $id]); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/query/CmsContentElementActiveQuery.php
src/query/CmsContentElementActiveQuery.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\query; use skeeks\cms\models\CmsContentElementTree; use skeeks\cms\models\CmsTree; use skeeks\cms\models\Tree; use yii\helpers\ArrayHelper; /** * @author Semenov Alexander <semenov@skeeks.com> */ class CmsContentElementActiveQuery extends CmsActiveQuery { /** * @param mixed $id * @return CmsTreeActiveQuery */ public function sxId(mixed $id) { return $this->andWhere(['sx_id' => $id]); } /** * Фильтрация по дате публикации * * @return CmsActiveQuery */ public function publishedTime() { $this->andWhere(["<=", $this->getPrimaryTableName().'.published_at', \Yii::$app->formatter->asTimestamp(time())]); return $this->andWhere([ 'or', [">=", $this->getPrimaryTableName().'.published_to', \Yii::$app->formatter->asTimestamp(time())], [$this->getPrimaryTableName().'.published_to' => null], ]); } /** * Фильтрация по разделам * * @param null|CmsTree $cmsTree если не укзан раздел то будет взят текущий раздел * @param bool $isDescendants искать привязку среди всех вложенных разделов? * @param bool $isJoinSecondTrees Искать элементы по второстепенной привязке? Находит элементы, которые не привязаны к основному разделу * @return $this */ public function cmsTree($cmsTree = null, $isDescendants = true, $isJoinSecondTrees = false) { if ($cmsTree === null) { $cmsTree = \Yii::$app->cms->currentTree; } if (!$cmsTree || !$cmsTree instanceof Tree) { return $this; } $treeIds = [$cmsTree->id]; if ($isDescendants) { //$treeIds = $cmsTree->getDescendants(null, true)->select(['id']); //print_r($treeIds->createCommand()->rawSql);die; $treeDescendantIds = $cmsTree->getDescendants()->select(['id'])->indexBy('id')->asArray()->all(); if ($treeDescendantIds) { $treeDescendantIds = array_keys($treeDescendantIds); $treeIds = ArrayHelper::merge($treeIds, $treeDescendantIds); } } if ($isJoinSecondTrees === true) { $this->joinWith('cmsContentElementTrees'); $this->andWhere([ 'or', [$this->getPrimaryTableName().'.tree_id' => $treeIds], [CmsContentElementTree::tableName().'.tree_id' => $treeIds], ]); $this->groupBy([$this->getPrimaryTableName().'.id']); } else { $this->andWhere([$this->getPrimaryTableName().'.tree_id' => $treeIds]); } return $this; } /** * @param bool $value * @return $this */ public function hasImage($value = true) { if ($value) { $this->andWhere(['is not', $this->getPrimaryTableName() . '.image_id', null]); } else { $this->andWhere([$this->getPrimaryTableName() . '.image_id' => null]); } return $this; } /** * @param int $content_id * @return CmsContentElementActiveQuery */ public function contentId(int $content_id) { return $this->andWhere([$this->getPrimaryTableName() . '.content_id' => $content_id]); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/ActiveRecord.php
src/base/ActiveRecord.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\base; use common\models\User; use skeeks\cms\models\behaviors\HasTableCache; use skeeks\cms\models\CmsUser; use skeeks\cms\query\CmsActiveQuery; use skeeks\cms\traits\TActiveRecord; use Yii; use yii\base\InvalidConfigException; use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; /** * @method string getTableCacheTag() * @method string getTableCacheTagCmsSite() * * @property integer $id * * @property integer $created_by * @property integer $updated_by * @property integer $created_at * @property integer $updated_at * * @property string $cacheTag * * @property CmsUser|User $createdBy * @property CmsUser|User $updatedBy * * @author Semenov Alexander <semenov@skeeks.com> */ class ActiveRecord extends \yii\db\ActiveRecord { use TActiveRecord; /** * @var array */ public $raw_row = []; static public function safeGetTableSchema() { try { return self::getTableSchema(); } catch (\Exception $exceptione) { return false; } } /** * @return CmsActiveQuery */ public static function find() { if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('is_active')) { return new CmsActiveQuery(get_called_class(), ['is_active' => true]); } return new CmsActiveQuery(get_called_class(), ['is_active' => false]); } /** @inheritdoc */ public static function populateRecord($record, $row) { /** @var static $record */ $record->raw_row = $row; return parent::populateRecord($record, $row); } /** * @inheritdoc */ public function behaviors() { $result = array_merge(parent::behaviors(), [ HasTableCache::class => [ 'class' => HasTableCache::class, 'cache' => \Yii::$app->cache, ], ]); try { if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('created_by') && self::safeGetTableSchema()->getColumn('updated_by')) { $result[BlameableBehavior::class] = [ 'class' => BlameableBehavior::class, 'value' => function ($event) { if (\Yii::$app instanceof \yii\console\Application) { return null; } else { $user = Yii::$app->get('user', false); return $user && !$user->isGuest ? $user->id : null; } }, ]; } elseif (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('created_by')) { $result[BlameableBehavior::class] = [ 'class' => BlameableBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_by'], ActiveRecord::EVENT_BEFORE_VALIDATE => [], //ActiveRecord::EVENT_BEFORE_VALIDATE => ['created_by'], ActiveRecord::EVENT_BEFORE_UPDATE => [], ], 'value' => function ($event) { if (\Yii::$app instanceof \yii\console\Application) { return null; } else { $user = Yii::$app->get('user', false); return $user && !$user->isGuest ? $user->id : null; } }, ]; } elseif (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('updated_by')) { $result[BlameableBehavior::class] = [ 'class' => BlameableBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['updated_by'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_by'], ], ]; } if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('created_at') && self::safeGetTableSchema()->getColumn('updated_at')) { $result[TimestampBehavior::class] = [ 'class' => TimestampBehavior::class, //'preserveNonEmptyValues' => true, /*'value' => function () { return date('U'); },*/ ]; } elseif (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('created_at')) { $result[TimestampBehavior::class] = [ 'class' => TimestampBehavior::class, //'preserveNonEmptyValues' => true, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => [], ], ]; } elseif (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('updated_at')) { $result[TimestampBehavior::class] = [ 'class' => TimestampBehavior::class, //'preserveNonEmptyValues' => true, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ]; } } catch (InvalidConfigException $e) { } return $result; } /** * @return \yii\db\ActiveQuery */ public function getCreatedBy() { return $this->hasOne(\Yii::$app->user->identityClass, ['id' => 'created_by']); } /** * @return \yii\db\ActiveQuery */ public function getUpdatedBy() { return $this->hasOne(\Yii::$app->user->identityClass, ['id' => 'updated_by']); } /** * @return array */ public function attributeLabels() { return [ 'id' => Yii::t('skeeks/cms', 'ID'), 'created_by' => Yii::t('skeeks/cms', 'Created By'), 'updated_by' => Yii::t('skeeks/cms', 'Updated By'), 'created_at' => Yii::t('skeeks/cms', 'Created At'), 'updated_at' => Yii::t('skeeks/cms', 'Updated At'), ]; } /** * @return array */ public function rules() { $result = []; if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('created_by')) { $result[] = ['created_by', 'integer']; } if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('updated_by')) { $result[] = ['updated_by', 'integer']; } if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('created_at')) { $result[] = ['created_at', 'integer']; } if (self::safeGetTableSchema() && self::safeGetTableSchema()->getColumn('updated_at')) { $result[] = ['updated_at', 'integer']; } return $result; /* return [ [[ 'created_by', 'updated_by', 'created_at', 'updated_at', 'id' ], 'integer'], ];*/ } /** * @return string */ public function getCacheTag() { return static::tableName().$this->primaryKey; } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/Theme.php
src/base/Theme.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 27.03.2015 */ namespace skeeks\cms\base; use skeeks\cms\IHasConfigForm; use skeeks\cms\traits\HasComponentDescriptorTrait; use skeeks\cms\traits\TConfigForm; use skeeks\yii2\config\ConfigBehavior; use skeeks\yii2\config\ConfigTrait; use skeeks\yii2\config\DynamicConfigModel; use yii\helpers\ArrayHelper; /** * @property DynamicConfigModel $configFormModel * @property array $treeViews * * @author Semenov Alexander <semenov@skeeks.com> */ abstract class Theme extends \yii\base\Theme { use HasComponentDescriptorTrait; //use TConfigForm; /** * Для каких сайтов доступна эта тема * @var array */ public $site_ids = []; public $tree_views = []; /** * @return array */ public function _getDefaultTreeViews() { return [ 'home' => [ 'name' => 'Главная страница', 'description' => '' ], 'text' => [ 'name' => 'Текстовый раздел', 'description' => 'Стандартное оформление раздела с текстом' ], 'contacts' => [ 'name' => 'Страница контактов', 'description' => 'Страница с картой, временем работы и контактами' ], ]; } /** * @return array */ public function getTreeViews() { return ArrayHelper::merge($this->_getDefaultTreeViews(), $this->tree_views); } /** * @var null */ protected $_configFormModel = null; /** * @return DynamicConfigModel * @throws \yii\base\InvalidConfigException */ public function getConfigFormModel() { if ($this->_configFormModel === null) { $data = $this->getConfigFormModelData(); $data["class"] = DynamicConfigModel::class; $this->_configFormModel = \Yii::createObject($data); //Установить значения из темы $data = ArrayHelper::toArray($this); $this->_configFormModel->setAttributes($data); } return $this->_configFormModel; } /** * Данные для формы настроек * * @return array */ public function getConfigFormModelData() { return []; } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/Controller.php
src/base/Controller.php
<?php /** * Controller * * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010-2014 SkeekS (Sx) * @date 03.11.2014 * @since 1.0.0 */ namespace skeeks\cms\base; use yii\helpers\ArrayHelper; use yii\web\Application; use yii\web\Controller as YiiWebController; /** * Class Controller * @package skeeks\cms\base */ class Controller extends YiiWebController { /** * @param string $view * @param array $params * @return string */ public function render($view, $params = []) { if ($this->module instanceof Application) { return parent::render($view, $params); } if (strpos($view, '/') && !strpos($view, '@app/views')) { return parent::render($view, $params); } $viewDir = "@app/views/modules/" . $this->module->id . '/' . $this->id; $viewApp = $viewDir . '/' . $view; if (isset(\Yii::$app->view->theme->pathMap['@app/views'])) { $tmpPaths = []; foreach (\Yii::$app->view->theme->pathMap['@app/views'] as $path) { $tmpPaths[] = $path . "/modules/" . $this->module->id . '/' . $this->id; } $tmpPaths[] = $this->viewPath; \Yii::$app->view->theme->pathMap = ArrayHelper::merge(\Yii::$app->view->theme->pathMap, [ $viewDir => $tmpPaths ]); } return parent::render($viewApp, $params); } /** * @param string $view * @param array $params * @return string */ public function renderPartial($view, $params = []) { if ($this->module instanceof Application) { return parent::renderPartial($view, $params); } if (strpos($view, '/') && !strpos($view, '@app/views')) { return parent::renderPartial($view, $params); } $viewDir = "@app/views/modules/" . $this->module->id . '/' . $this->id; $viewApp = $viewDir . '/' . $view; if (isset(\Yii::$app->view->theme->pathMap['@app/views'])) { $tmpPaths = []; foreach (\Yii::$app->view->theme->pathMap['@app/views'] as $path) { $tmpPaths[] = $path . "/modules/" . $this->module->id . '/' . $this->id; } $tmpPaths[] = $this->viewPath; \Yii::$app->view->theme->pathMap = ArrayHelper::merge(\Yii::$app->view->theme->pathMap, [ $viewDir => $tmpPaths ]); } return parent::renderPartial($viewApp, $params); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/ConfigFormInterface.php
src/base/ConfigFormInterface.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 02.03.2016 */ namespace skeeks\cms\base; use yii\widgets\ActiveForm; /** * * @deprecated * * Interface ConfigFormInterface * @package yii\base */ interface ConfigFormInterface { /** * @deprecated * @return string the view path that may be prefixed to a relative view name. */ public function renderConfigForm(ActiveForm $form); }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/AssetBundle.php
src/base/AssetBundle.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\base; use skeeks\sx\File; /** * @author Semenov Alexander <semenov@skeeks.com> */ class AssetBundle extends \yii\web\AssetBundle { /** * @param string $asset * @return string * @throws \yii\base\InvalidConfigException */ public static function getAssetUrl($asset) { return \Yii::$app->assetManager->getAssetUrl(\Yii::$app->assetManager->getBundle(static::className()), $asset); } protected $originalSourcePath = null; /** * @return $this */ protected function _implodeFiles() { $this->js = (array)$this->js; $this->css = (array)$this->css; //Если есть css нормально не работает if ($this->css) { return $this; } if (count($this->js) <= 1 && count($this->css) <= 1) { return $this; } $this->originalSourcePath = $this->sourcePath; $this->_implodeJs(); $this->_implodeCss(); return $this; } /** * @return $this */ protected function _implodeJs() { if (!$this->js) { return $this; } $filtTimes = [$this->className()]; foreach ($this->js as $js) { $filtTimes[] = fileatime($this->originalSourcePath.'/'.$js); } $fileName = 'skeeks-auto-'.md5(implode("", $filtTimes)).".js"; $fileMinJs = \Yii::getAlias('@app/runtime/assets/skeeks-auto/'.$fileName); if (file_exists($fileMinJs)) { $this->js = [ $fileName, ]; $this->sourcePath = '@app/runtime/assets/skeeks-auto'; return $this; } $fileContent = ""; foreach ($this->js as $js) { $fileContent .= file_get_contents(\Yii::getAlias($this->originalSourcePath.'/'.$js)); /*$f = fopen(\Yii::getAlias($this->originalSourcePath.'/'.$js), "r+"); $fileContent .= fgets($f); fclose($f);*/ } if ($fileContent) { $file = new File($fileMinJs); $file->make($fileContent); if (file_exists($fileMinJs)) { $this->js = [ $fileName, ]; $this->sourcePath = '@app/runtime/assets/skeeks-auto'; return $this; } } return $this; } /** * @return $this */ protected function _implodeCss() { if (!$this->css) { return $this; } $filtTimes = [$this->className()]; foreach ($this->css as $js) { $filtTimes[] = fileatime($this->originalSourcePath.'/'.$js); } $fileName = 'skeeks-auto-'.md5(implode("", $filtTimes)).".css"; $fileMinJs = \Yii::getAlias('@app/runtime/assets/skeeks-auto/'.$fileName); if (file_exists($fileMinJs)) { $this->css = [ $fileName, ]; $this->sourcePath = '@app/runtime/assets/skeeks-auto'; return $this; } $fileContent = ""; foreach ($this->css as $js) { /*$f = fopen(\Yii::getAlias($this->originalSourcePath.'/'.$js), "r+"); $fileContent .= fgets($f); fclose($f);*/ $fileContent .= file_get_contents(\Yii::getAlias($this->originalSourcePath.'/'.$js)); } if ($fileContent) { $file = new File($fileMinJs); $file->make($fileContent); if (file_exists($fileMinJs)) { $this->css = [ $fileName, ]; $this->sourcePath = '@app/runtime/assets/skeeks-auto'; return $this; } } return $this; } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/ComponentDescriptor.php
src/base/ComponentDescriptor.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\base; use skeeks\cms\IHasImage; use skeeks\cms\IHasName; use skeeks\cms\traits\THasImage; use skeeks\cms\traits\THasName; /** * @author Semenov Alexander <semenov@skeeks.com> */ class ComponentDescriptor extends \yii\base\Component implements IHasName, IHasImage { use THasName; use THasImage; public $description = ""; public $keywords = []; /** * @return string */ public function __toString() { return $this->toString(); } /** * @return string */ public function toString() { return $this->name; } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/DynamicModel.php
src/base/DynamicModel.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\base; /** * @author Semenov Alexander <semenov@skeeks.com> */ class DynamicModel extends \yii\base\DynamicModel { /** * @var string */ public $formName = null; protected $_attributeLabels = []; /** * @return null|string */ public function formName() { if ($this->formName === null) { return parent::formName(); } return $this->formName; } /** * @return array */ public function attributeLabels() { return $this->_attributeLabels; } /** * @param array $attributeLabels * @return $this */ public function setAttributeLebels($attributeLabels = []) { $this->_attributeLabels = []; return $this; } /** * @param string $attribute * @param string $value * @return $this */ public function setAttributeLebel(string $attribute, string $value) { $this->_attributeLabels[$attribute] = $value; return $this; } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/Widget.php
src/base/Widget.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 22.05.2015 */ namespace skeeks\cms\base; use skeeks\cms\traits\TWidget; use yii\base\ViewContextInterface; use yii\helpers\ArrayHelper; /** * Class Widget * @package skeeks\cms\base */ abstract class Widget extends Component implements ViewContextInterface { //Умеет все что умеет \yii\base\Widget use TWidget; /** * @var array */ public $contextData = []; /** * @param string $namespace Unique code, which is attached to the settings in the database * @param array $config Standard widget settings * * @return static */ public static function beginWidget($namespace, $config = []) { $config = ArrayHelper::merge(['namespace' => $namespace], $config); return static::begin($config); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/InputWidget.php
src/base/InputWidget.php
<?php /** * @link https://cms.skeeks.com/ * @copyright Copyright (c) 2010 SkeekS * @license https://cms.skeeks.com/license/ * @author Semenov Alexander <semenov@skeeks.com> */ namespace skeeks\cms\base; use yii\base\InvalidConfigException; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\helpers\Inflector; /** * @property string $wrapperId * * @author Semenov Alexander <semenov@skeeks.com> */ class InputWidget extends \yii\widgets\InputWidget { /** * @var string */ static public $autoIdPrefix = "InputWidget"; /** * @var array */ public $options = []; /** * @var array */ public $defaultOptions = [ 'type' => 'number', 'class' => 'form-control', ]; /** * @var array */ public $wrapperOptions = []; /** * @var array */ public $clientOptions = []; /** * @var */ public $viewFile; /** * @var bool */ public $dynamicReload = false; /** * @throws \yii\base\InvalidConfigException */ public function init() { parent::init(); if (!$this->viewFile) { throw new InvalidConfigException("Need view file"); } $this->wrapperOptions['id'] = $this->wrapperId; $this->clientOptions['id'] = $this->wrapperId; if ($this->dynamicReload) { $this->defaultOptions[\skeeks\cms\helpers\RequestResponse::DYNAMIC_RELOAD_FIELD_ELEMENT] = "true"; } $r = new \ReflectionClass(static::class); Html::addCssClass($this->wrapperOptions, "sx-".Inflector::camel2id($r->getShortName())); } /** * @return string */ public function getWrapperId() { return $this->id."-widget"; } /** * @inheritdoc */ public function run() { $element = ''; $options = ArrayHelper::merge($this->defaultOptions, $this->options); Html::addCssClass($options, 'sx-value-element'); if ($this->hasModel()) { $element = Html::activeTextInput($this->model, $this->attribute, $options); } else { $element = Html::textInput($this->name, $this->value, $options); } return $this->render($this->viewFile, [ 'element' => $element, ]); } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false
skeeks-cms/cms
https://github.com/skeeks-cms/cms/blob/c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf/src/base/WidgetRenderable.php
src/base/WidgetRenderable.php
<?php /** * @author Semenov Alexander <semenov@skeeks.com> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @date 26.05.2015 */ namespace skeeks\cms\base; use skeeks\yii2\form\fields\BoolField; use skeeks\yii2\form\fields\FieldSet; use skeeks\yii2\form\fields\NumberField; use yii\caching\ChainedDependency; use yii\caching\Dependency; use yii\caching\TagDependency; use yii\console\Application; use yii\helpers\ArrayHelper; /** * Class WidgetRenderable * @package skeeks\cms\base */ class WidgetRenderable extends Widget { /** * @var null Файл в котором будет реднериться виджет */ public $viewFile = "default"; /** * @var bool Кэш включен? */ public $is_cache = false; /** * @var bool Кэш для каждого из пользователей свой? */ public $is_cache_unique_for_user = true; /** * @var int Время жизни кэша */ public $cache_duration = 0; /** * @var array */ public $cache_tags = []; /** * @var array */ public $params = []; public function attributeLabels() { return array_merge(parent::attributeLabels(), [ 'viewFile' => \Yii::t('skeeks/cms', 'File-template'), 'is_cache' => "Включить кэширование", 'cache_duration' => "Время жизни кэша", 'is_cache_unique_for_user' => "У каждого юзера свой кэш?", ]); } public function attributeHints() { return array_merge(parent::attributeHints(), [ 'is_cache' => "Внимание если в виджете подключаются какие либо скрипты, то возможно, ваш виджет с кэшированием будет работать некорректно.", 'cache_duration' => "Максимальное время жизни кэша. Но он может сброситься и раньше по мере необходимости.", 'is_cache_unique_for_user' => "Если эта настройка включена, то у каждого авторизованного пользоателя этот блок будет кэшироваться по своему.", ]); } public function rules() { return ArrayHelper::merge(parent::rules(), [ [['viewFile'], 'string'], [['is_cache'], 'boolean'], [['cache_duration'], 'integer'], [['is_cache_unique_for_user'], 'boolean'], ]); } /** * @return array */ protected function _getConfigFormCache() { return [ 'cache' => [ 'class' => FieldSet::class, 'name' => 'Настройки кэширования', 'fields' => [ 'is_cache' => [ 'class' => BoolField::class, 'allowNull' => false, ], 'cache_duration' => [ 'class' => NumberField::class, 'append' => "сек", ], 'is_cache_unique_for_user' => [ 'class' => BoolField::class, 'allowNull' => false, ], ], ], ]; } /*public function run() { if ($this->viewFile) { return $this->render($this->viewFile, [ 'widget' => $this, ]); } else { return \Yii::t('skeeks/cms', "Template not found"); } }*/ public function getCacheTags() { $this->cache_tags; } /** * @var null|Dependency */ protected $_cacheDependency = null; /** * @return Dependency|ChainedDependency */ public function getCacheDependency() { if ($this->_cacheDependency === null) { $dependency = new ChainedDependency(); $dependency->dependencies = [ new TagDependency([ 'tags' => [ \Yii::$app instanceof Application ? "console" : "web", static::class, $this->namespace, $this->cmsUser ? $this->cmsUser->cacheTag : '', $this->cmsSite ? $this->cmsSite->cacheTag : '', ], ]), ]; $this->_cacheDependency = $dependency; } return $this->_cacheDependency; } /** * @param Dependency $dependency * @return $this */ public function setCacheDependency(Dependency $dependency) { $this->_cacheDependency = $dependency; return $this; } public function run() { $cacheKey = $this->getCacheKey($this->is_cache_unique_for_user).'WidgetRenderableRun'; $result = \Yii::$app->cache->get($cacheKey); if ($result === false || ($this->is_cache === false || $this->is_cache == "0")) { if ($this->viewFile) { try { $result = $this->render($this->viewFile, ArrayHelper::merge($this->params, [ 'widget' => $this, ])); } catch (\Exception $e) { $result = $e->getTraceAsString(); } } else { $result = \Yii::t('skeeks/cms', "Template not found"); } \Yii::$app->cache->set($cacheKey, $result, (int)$this->cache_duration, $this->getCacheDependency()); } return $result; } }
php
BSD-3-Clause
c22dc84c6fc4da5f67815a3339bc10c6c4aa39cf
2026-01-05T04:50:22.405425Z
false