HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //proc/self/cwd/wp-content/plugins/spotlight-social-photo-feeds/modules/MediaModule.php
<?php

namespace RebelCode\Spotlight\Instagram\Modules;

use Dhii\Services\Factories\Constructor;
use Dhii\Services\Factories\FuncService;
use Dhii\Services\Factories\Value;
use Psr\Container\ContainerInterface;
use RebelCode\Iris\Data\Source;
use RebelCode\Spotlight\Instagram\Actions\DeleteAllPostsAction;
use RebelCode\Spotlight\Instagram\Di\ArrayExtension;
use RebelCode\Spotlight\Instagram\Engine\IgPostStore;
use RebelCode\Spotlight\Instagram\Module;
use RebelCode\Spotlight\Instagram\PostTypes\MediaPostType;
use RebelCode\Spotlight\Instagram\Wp\MetaField;
use RebelCode\Spotlight\Instagram\Wp\PostType;

/**
 * The module that adds the media post type and all related functionality to the plugin.
 *
 * @since 0.1
 */
class MediaModule extends Module
{
    /**
     * @inheritDoc
     *
     * @since 0.1
     */
    public function getFactories() : array
    {
        return [
            //==========================================================================
            // POST TYPE
            //==========================================================================

            // The media CPT
            'cpt' => new Constructor(MediaPostType::class, [
                'cpt/slug',
                'cpt/args',
                'cpt/fields',
                '@engine/store/files',
            ]),

            // The media CPT slug name
            'cpt/slug' => new Value('sl-insta-media'),
            // The media CPT registration args
            'cpt/args' => new Value([
                'labels' => [
                    'name' => 'Spotlight posts',
                    'singular_name' => 'Spotlight post',
                ],
                'public' => false,
                'supports' => ['title', 'custom-fields'],
                'show_in_rest' => false,
            ]),
            // The meta fields for the media CPT
            'cpt/fields' => new Value([
                new MetaField(MediaPostType::MEDIA_ID),
                new MetaField(MediaPostType::USERNAME),
                new MetaField(MediaPostType::TIMESTAMP),
                new MetaField(MediaPostType::CAPTION),
                new MetaField(MediaPostType::TYPE),
                new MetaField(MediaPostType::URL),
                new MetaField(MediaPostType::PERMALINK),
                new MetaField(MediaPostType::THUMBNAIL_URL),
                new MetaField(MediaPostType::LIKES_COUNT),
                new MetaField(MediaPostType::COMMENTS_COUNT),
                new MetaField(MediaPostType::CHILDREN),
                new MetaField(MediaPostType::LAST_REQUESTED),
            ]),

            //==========================================================================
            // ACTIONS
            //==========================================================================

            'actions/delete_all' => new Constructor(DeleteAllPostsAction::class, [
                'cpt/slug',
                '@engine/store/files',
                '@engine/importer/scheduler/cron/hook',
                '@engine/importer/lock',
                '@engine/importer/interrupt',
            ]),

            //==========================================================================
            // MIGRATIONS
            //==========================================================================

            'migrations/0.4.1/generate_thumbnails' => new FuncService(
                ['@media/cpt', '@engine/store'],
                function ($v1, $v2, PostType $mediaCpt, IgPostStore $store) {
                    if (version_compare($v1, '0.4.1', '<')) {
                        foreach ($mediaCpt->query() as $post) {
                            // Extend the time limit by 10 seconds
                            set_time_limit(10);

                            // Convert from post to item and generate the thumbnails
                            $item = $store->postToItem($post);
                            $item = $store->getFileStore()->downloadForItem($item);

                            // Update the item
                            $store->insert($item);
                        }
                    }
                }
            ),

            'migrations/0.9/update_sources_meta' => new FuncService(['@wp/db'], function ($oldVer, $newVer, $wpdb) {
                if (version_compare($oldVer, '0.9', '<')) {
                    $sourceNameQuery = sprintf(
                        "SELECT post_id, meta_value FROM %s WHERE meta_key = '%s'",
                        $wpdb->postmeta,
                        MediaPostType::SOURCE_NAME
                    );

                    $sourceTypeQuery = sprintf(
                        "SELECT post_id, meta_value FROM %s WHERE meta_key = '%s'",
                        $wpdb->postmeta,
                        MediaPostType::SOURCE_TYPE
                    );

                    $sourceQuery = sprintf(
                        'SELECT st.post_id, sn.meta_value as name, st.meta_value as type
                        FROM (%s) as sn
                        JOIN (%s) as st
                        ON sn.post_id = st.post_id',
                        $sourceNameQuery,
                        $sourceTypeQuery
                    );

                    $rows = $wpdb->get_results($sourceQuery);

                    if (is_array($rows)) {
                        foreach ($rows as $row) {
                            $source = new Source($row->name, $row->type);
                            delete_post_meta($row->post_id, MediaPostType::SOURCE_NAME);
                            delete_post_meta($row->post_id, MediaPostType::SOURCE_TYPE);
                            add_post_meta($row->post_id, MediaPostType::SOURCE, (string) $source);
                        }
                    }
                }
            }),
        ];
    }

    /**
     * @inheritDoc
     *
     * @since 0.1
     */
    public function getExtensions() : array
    {
        return [
            // Add the post type to WordPress
            'wp/post_types' => new ArrayExtension(['cpt']),

            // Add the migrations
            'migrator/migrations' => new ArrayExtension([
                'migrations/0.4.1/generate_thumbnails',
                'migrations/0.9/update_sources_meta',
            ]),
        ];
    }
}