BeforeAfter
5 years ago
Pro
5 years ago
ActionIcons.php
5 years ago
AttachmentDisplay.php
5 years ago
BeforeAfter.php
5 years ago
CharacterLimit.php
5 years ago
Comment.php
5 years ago
CommentCount.php
5 years ago
CommentLink.php
5 years ago
CustomField.php
5 years ago
CustomFieldType.php
5 years ago
Date.php
5 years ago
DateTimeFormat.php
5 years ago
ExifData.php
5 years ago
Image.php
5 years ago
Images.php
5 years ago
Label.php
5 years ago
LinkLabel.php
5 years ago
LinkToMenu.php
5 years ago
MediaLink.php
5 years ago
Message.php
5 years ago
Meta.php
5 years ago
MissingImageSize.php
5 years ago
NumberFormat.php
5 years ago
NumberOfItems.php
5 years ago
Password.php
5 years ago
PathScope.php
5 years ago
Post.php
5 years ago
PostFormatIcon.php
5 years ago
PostLink.php
5 years ago
PostStatus.php
5 years ago
PostType.php
5 years ago
Pro.php
5 years ago
Separator.php
5 years ago
StatusIcon.php
5 years ago
StringLimit.php
5 years ago
Taxonomy.php
5 years ago
Term.php
5 years ago
TermLink.php
5 years ago
Time.php
5 years ago
Toggle.php
5 years ago
Type.php
5 years ago
User.php
5 years ago
UserLink.php
5 years ago
Width.php
5 years ago
WordLimit.php
5 years ago
WordsPerMinute.php
5 years ago
PathScope.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Settings\Column; |
| 4 | |
| 5 | use AC\Settings; |
| 6 | use AC\View; |
| 7 | |
| 8 | class PathScope extends Settings\Column |
| 9 | implements Settings\FormatValue { |
| 10 | |
| 11 | /** |
| 12 | * @var string |
| 13 | */ |
| 14 | private $path_scope; |
| 15 | |
| 16 | protected function define_options() { |
| 17 | return [ |
| 18 | 'path_scope' => 'full', |
| 19 | ]; |
| 20 | } |
| 21 | |
| 22 | public function create_view() { |
| 23 | $select = $this->create_element( 'select', 'path_scope' ) |
| 24 | ->set_options( [ |
| 25 | 'full' => __( 'Full Path', 'codepress-admin-columns' ), |
| 26 | 'relative-domain' => __( 'Relative to domain', 'codepress-admin-columns' ), |
| 27 | 'relative-uploads' => __( 'Relative to main uploads folder', 'codepress-admin-columns' ), |
| 28 | 'local' => __( 'Local Path', 'codepress-admin-columns' ), |
| 29 | ] ); |
| 30 | |
| 31 | $view = new View( [ |
| 32 | 'label' => __( 'Path scope', 'codepress-admin-columns' ), |
| 33 | 'tooltip' => __( 'Part of the file path to display', 'codepress-admin-columns' ), |
| 34 | 'setting' => $select, |
| 35 | ] ); |
| 36 | |
| 37 | return $view; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @return string |
| 42 | */ |
| 43 | public function get_path_scope() { |
| 44 | return $this->path_scope; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param string $path_scope |
| 49 | * |
| 50 | * @return bool |
| 51 | */ |
| 52 | public function set_path_scope( $path_scope ) { |
| 53 | $this->path_scope = $path_scope; |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | public function format( $value, $original_value ) { |
| 59 | $file = $value; |
| 60 | $value = ''; |
| 61 | |
| 62 | if ( $file ) { |
| 63 | |
| 64 | switch ( $this->get_path_scope() ) { |
| 65 | case 'relative-domain' : |
| 66 | $file = str_replace( 'https://', 'http://', $file ); |
| 67 | $url = str_replace( 'https://', 'http://', home_url( '/' ) ); |
| 68 | |
| 69 | if ( strpos( $file, $url ) === 0 ) { |
| 70 | $file = '/' . substr( $file, strlen( $url ) ); |
| 71 | } |
| 72 | |
| 73 | break; |
| 74 | case 'relative-uploads' : |
| 75 | $file = str_replace( 'https://', 'http://', $file ); |
| 76 | $upload_dir = wp_upload_dir(); |
| 77 | $url = str_replace( 'https://', 'http://', $upload_dir['baseurl'] ); |
| 78 | |
| 79 | if ( strpos( $file, $url ) === 0 ) { |
| 80 | $file = substr( $file, strlen( $url ) ); |
| 81 | } |
| 82 | |
| 83 | break; |
| 84 | case 'local' : |
| 85 | $file = get_attached_file( $original_value ); |
| 86 | |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | $value = $file; |
| 91 | } |
| 92 | |
| 93 | return $value; |
| 94 | } |
| 95 | |
| 96 | } |