| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2021-10-10 09:26:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types = 1); | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  | // {{{ License
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // }}}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * WebFinger implementation for GNU social | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package   GNUsocial | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @author    Diogo Peralta Cordeiro <mail@diogo.site | 
					
						
							|  |  |  |  * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Component\FreeNetwork\Entity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use App\Core\DB\DB; | 
					
						
							|  |  |  | use App\Core\Entity; | 
					
						
							|  |  |  | use App\Core\Event; | 
					
						
							|  |  |  | use DateTimeInterface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Table Definition for freenetwork_actor | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @author    Diogo Peralta Cordeiro <mail@diogo.site | 
					
						
							|  |  |  |  * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class FreenetworkActor extends Entity | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // {{{ Autocode
 | 
					
						
							|  |  |  |     // @codeCoverageIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |     private string $profile_page; | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     private int $actor_id; | 
					
						
							|  |  |  |     private bool $is_local; | 
					
						
							| 
									
										
										
										
											2021-10-10 09:26:18 +01:00
										 |  |  |     private DateTimeInterface $created; | 
					
						
							|  |  |  |     private DateTimeInterface $modified; | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |     public function getProfilepage(): string | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |         return $this->profile_page; | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |     public function setProfilepage(string $profile_page): void | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |         $this->profile_page = $profile_page; | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function getSource(): string | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->source; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setSource(string $source): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->source = $source; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function getActorId(): int | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->actor_id; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setActorId(int $actor_id): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->actor_id = $actor_id; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |     public function getIsLocal(): bool | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $this->is_local; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setIsLocal(bool $is_local): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->is_local = $is_local; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function getCreated(): DateTimeInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->created; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setCreated(DateTimeInterface $created): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->created = $created; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function getModified(): DateTimeInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->modified; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function setModified(DateTimeInterface $modified): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->modified = $modified; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // @codeCoverageIgnoreEnd
 | 
					
						
							|  |  |  |     // }}} Autocode
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |     public static function getOrCreateByRemoteUri($actor_uri): self | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |         $fnactor = DB::findBy('freenetwork_actor', ['profile_page' => $actor_uri, 'is_local' => false]); | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |         if ($fnactor === []) { | 
					
						
							|  |  |  |             // TODO grab with webfinger
 | 
					
						
							|  |  |  |             // If already has for a different protocol and isn't local, update
 | 
					
						
							|  |  |  |             // else create actor and then fnactor
 | 
					
						
							|  |  |  |             $fnactor = self::create([ | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |                 'profile_page' => $actor_uri, | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |                 'actor_id'  => 1, | 
					
						
							|  |  |  |                 'is_local'  => false, | 
					
						
							|  |  |  |             ]); | 
					
						
							|  |  |  |             DB::persist($fnactor); | 
					
						
							|  |  |  |             return $fnactor; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $fnactor[0]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function schemaDef() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return [ | 
					
						
							|  |  |  |             'name'   => 'freenetwork_actor', | 
					
						
							|  |  |  |             'fields' => [ | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |                 'profile_page' => ['type' => 'text', 'not null' => true], | 
					
						
							|  |  |  |                 'actor_id'     => ['type' => 'int', 'not null' => true], | 
					
						
							|  |  |  |                 'is_local'     => ['type' => 'bool', 'not null' => true, 'description' => 'whether this was a locally generated or an imported actor'], | 
					
						
							|  |  |  |                 'created'      => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], | 
					
						
							|  |  |  |                 'modified'     => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |             'primary key' => ['profile_page'], | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |             'indexes'     => [ | 
					
						
							| 
									
										
										
										
											2021-10-18 13:22:02 +01:00
										 |  |  |                 'freenetwork_profile_page_idx' => ['actor_id'], | 
					
						
							| 
									
										
										
										
											2021-10-04 17:00:58 +01:00
										 |  |  |             ], | 
					
						
							|  |  |  |             'foreign keys' => [ | 
					
						
							|  |  |  |                 'freenetwork_actor_actor_id_fkey' => ['actor', ['actor_id' => 'id']], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |