晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/stando/public_html/wp-content/plugins/powerpress/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/stando/public_html/wp-content/plugins/powerpress/api-data-transfer-bus.class.php
<?php

class PowerpressNetworkDataBus{
    function __construct()
    {
        //Nothing here
    }

    /**
     * Returns requested data after deciding whether to pull the data from a cache or the API
     * @param $creds array of oauth credentials for blubrry api
     * @param $cacheName string
     * @param $requestUrl string
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @param $clientAuth bool
     * @return array of data
     */
    static function getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI, $clientAuth = true)
    {
		// value of $requestUrl should not have 
		if( preg_match('/^https?:\/\/([^\/]*)(.*)$/', $requestUrl, $matches) ) {
			$requestUrl = $matches[2];
		}
		
		if( empty($creds['post']) )
			$creds['post'] = false;
		
        $cache = get_option($cacheName);
        //Need direct API: will not use cache but directly call an API
        if ($needDirectAPI === false && !empty($cache)) {
            if (isset($cache['data']) && isset($cache['insert_timestamp']) && $cache['insert_timestamp'] > (time() - 4*60*60)) {
                //mail ('use cache 1', 'use cache 1 ', print_r('use cache 1', true));
                //case 1: there is still cache in database and it is created from less than 1 day
                return $cache['data'];
            } else if (isset($cache['last_error_timestamp']) && $cache['last_error_timestamp'] > time() - 60*60 && isset($cache['data'])) {
                //mail ('use cache 2', 'use cache 2 ', print_r('use cache 2', true));
                //case 2: if the cache is created from more than 1 days, but the last error is less than 1 hour
                return $cache['data'];
            } else {
                $props = $GLOBALS['ppn_object']->requestAPI($requestUrl, $clientAuth, $creds['post']);
                if (empty($props['error'])) {
                    $cache['data'] = $props;
                    $cache['insert_timestamp'] = time();
                    update_option($cacheName, $cache);
                    //case 3: there is no useful cache in case 1 and 2, call an API. If successful, insert new cache to database
                    //mail ('use API', 'use API ', print_r('use API', true));
                    return $props;
                } else {
                    $cache['last_error_timestamp'] = time();
                    $cache['insert_timestamp'] = 0;
					$cache['returned_data'] = $props;
                    update_option($cacheName, $cache);
                    if (isset($cache['data'])) {
                        //mail ('use cache 3', 'use cache 3 ', print_r('use cache 3', true));
                        //case 4: if the new API call also produces error, update the timestamp error
                        return $cache['data'];
                    } else {
                        //mail ('empty', 'empty', print_r('empty', true));
                        //case 5: nothing is useful, return error
                        return array('error' => $cache['error']);
                    }
                }
            }
        } else{
            $props = $GLOBALS['ppn_object']->requestAPI($requestUrl, $clientAuth, $creds['post']);
            if (isset($cacheName)) {
                if (empty($props['error'])) {
                    $cache['data'] = $props;
                    $cache['insert_timestamp'] = time();
                    update_option($cacheName, $cache);
                    //mail ('use API', 'use API ', print_r('use API', true));
                    return $props;
                } else {
                    $cache['last_error_timestamp'] = time();
                    $cache['insert_timestamp'] = 0;
                    $cache['error'] = $props['error'];
					$cache['returned_data'] = $props;
                    update_option($cacheName, $cache);
                    if (isset($cache['data'])) {
                        //mail ('use cache 3', 'use cache 3 ', print_r('use cache 3', true));
                        return $cache['data'];
                    } else {
                        //mail ('empty', 'empty', print_r('empty', true));
                        return array('error' => $cache['error']);
                    }
                }
            }
            return $props;
        }
    }

    /**
     * Returns networks associated to the account
     * @param $creds array of oauth credentials for blubrry api
     * @return array of networks
     */
    static function getNetworksInAccount($creds)
    {
        $cacheName = 'ppn-cache n';
        $requestUrl = '/2/powerpress/network';
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl,  true);
    }

    /**
     * Returns data about a specific network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array|bool--either the desired data or false
     */
    static function getSpecificNetworkInAccount($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        if (isset($networkInfo['network_id'])) {
            $cacheName = 'ppn-cache n-' . $networkInfo['network_id'];
            $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'];
            $props = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI);
            return $props;
        }
        return false;
    }

    /**
     * Returns all programs in a network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array of programs
     */
    static function getProgramsInNetwork($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        $cacheName = 'ppn-cache n-'.$networkInfo['network_id'].'-p';
        $requestUrl = '/2/powerpress/network/' . $networkInfo['network_id'] . '/programs';
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI);
    }

    /**
     * Changes the status of an applicant to the network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $appAction array with action and applicant id
     * @return array with return data or error
     */
    static function changeApplicationStatus($apiUrl, $creds, $networkInfo, $appAction)
    {
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/applicant/changestatus?action=' . $appAction['appAction'] . '&applicantId=' . $appAction['applicantId'];
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl,  true);
    }

    /**
     * Returns all lists in a network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array of lists
     */
    static function getListsInNetwork($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        $cacheName = 'ppn-cache n-'.$networkInfo['network_id'].'-l';
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/lists/';
        $props = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI);
        return $props;
    }

    /**
     * Creates a new list in a network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $create array of data about the new list
     * @return array with return data or error
     */
    static function createNewList($apiUrl, $creds, $networkInfo, $create)
    {
        $create['newListTitle'] = urlencode($create['newListTitle']);
        $create['newListDescription'] = urlencode($create['newListDescription']);
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/lists/new?title=' . $create['newListTitle'] . '&description=' . $create['newListDescription'];
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
    }

    /**
     * Adds programs to a list
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $addedPrograms array of programs
     * @return array with return data or error
     */
    static function updateProgramsInSpecificList($apiUrl, $creds, $networkInfo, $addedPrograms)
    {
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/lists/' . $networkInfo['list_id'] . '/update-programs?';
        if (isset($addedPrograms)) {
            foreach ($addedPrograms as $programId) {
                $requestUrl .= 'programId[]=' . $programId . '&';
            }
        }
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
    }

    /**
     * Deletes a list
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the list to be deleted
     * @return array with return data or error
     */
    static function deleteSpecificList($apiUrl, $creds, $networkInfo)
    {
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/lists/' . $networkInfo['list_id'] . '/delete';
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
    }

    /**
     * Returns all programs that have applied to a network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array of applicants
     */
    static function getApplicantsInNetwork($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        $cacheName = "ppn-cache n-".$networkInfo['network_id']."-a";
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/applicant';
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI);
    }

    /**
     * Returns data relating to one specific list
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the desired list
     * @return array|bool--array of list data or false
     */
    static function getSpecificListInNetwork ($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        if (!empty($networkInfo['network_id']) && !empty ($networkInfo['list_id'])) {
            $cacheName = 'ppn-cache n-' . $networkInfo['network_id'] . '-l-' . $networkInfo['list_id'];
            $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/lists/' . $networkInfo['list_id'] . '/programs';
            $props = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI = true);
            if (!empty($props['list_info']['list_title']) && !empty($props['list_info']['list_description'])) {
                PowerPressNetwork::insertOption('list_title', $props['list_info']['list_title']);
                PowerPressNetwork::insertOption('list_description', $props['list_info']['list_description']);
            }
            return $props;
        }
        return false;
    }

    /**
     * Returns data relating to one specific list
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the desired program
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array|bool--array of program data or false
     */
    static function getSpecificProgramInNetwork($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        $cacheName = 'ppn-cache n-'.$networkInfo['network_id'].'-p-'.$networkInfo['program_id'];
        if (!empty($networkInfo['network_id']) && !empty($networkInfo['program_id']) ) {
            $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/programs/' . $networkInfo['program_id'];
            $props = PowerpressNetworkDataBus::getCacheOrCallAPI(false, $cacheName, $requestUrl, $needDirectAPI);
            if (!empty($props['program_info']['program_id']) && !empty($props['program_info']['program_title'])) {
                PowerPressNetwork::insertOption('program_id', $props['program_info']['program_id']);
                PowerPressNetwork::insertOption('program_title', $props['program_info']['program_title']);
            }
            return $props;
        }
        return false;
    }

    /**
     * Removes a program from a network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the program to be removed
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array|bool--array of return data or false
     */
    static function removeSpecificProgramInNetwork($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        $cacheName = 'ppn-cache n-'.$networkInfo['network_id'].'-p-'.$networkInfo['program_id'];
        if (!empty($networkInfo['network_id']) && !empty($networkInfo['program_id']) ) {
            $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/programs/' . $networkInfo['program_id'] . '/delete';
            $props = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, $cacheName, $requestUrl, $needDirectAPI);
            if (!empty($props['program_info']['program_id']) && !empty($props['program_info']['program_title'])) {
                PowerPressNetwork::removeOption('program_id', $props['program_info']['program_id']);
                PowerPressNetwork::removeOption('program_title', $props['program_info']['program_title']);
            }
            return $props;
        }
        return false;
    }

    /**
     * Returns data about the user account associated to the network
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the desired program
     * @param $needDirectAPI bool--true if we do not want a cached result
     * @return array|bool--array of account data or false
     */
    static function getNetworkOwnerInformation($apiUrl, $creds, $networkInfo, $needDirectAPI)
    {
        if(!empty($networkInfo['network_id']))
        {
            $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/account/information/';
            $props = self::getCacheOrCallAPI($creds, null, $requestUrl, $needDirectAPI);
            return $props;
        } else {
            return false;
        }
    }

    /**
     * Given a feed URL, returns information about the applicant
     * @param $apiUrl string url to Blubrry api
     * @param $createUrl string url to wordpress site
     * @param $tokenInfo array which includes the id of the desired program
     * @return array of credentials
     */
    static function refreshTokenToGetCredentials($apiUrl, $createUrl, $tokenInfo)
    {
        $clientAuth = $tokenInfo['client_auth'];
        $refreshToken = $tokenInfo['refresh_token'];
        $oldAccessToken = $tokenInfo['access_token'];
        $requestUrl = $apiUrl . 'oauth2/token?grant_type=refresh_token&refresh_token=' . $refreshToken;
        $post = array('grant_type' => 'refresh_token', 'refresh_token' => $refreshToken, 'redirect_uri' => $createUrl . 'wp-admin/admin.php?page=network-plugin');
        $creds['post'] = $post;
        $props = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true, $clientAuth);
        $props['client_auth'] = $clientAuth;
        $props['refresh_token'] = $refreshToken;
        return $props;
    }

    /**
     * Given a feed URL, returns information about the applicant
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the desired program
     * @param $feedUrl string
     * @return array of applicant data
     */
    static function getFeedFromLink($apiUrl, $creds, $networkInfo, $feedUrl)
    {
        $feedUrl = trim($feedUrl);
        $feedUrl = preg_replace('#^(https?://|ftps?://)?(www.)?#', '', $feedUrl);
        $feedUrl = urlencode($feedUrl);
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/applicant/findshow?feedUrl=' . $feedUrl;
        $props = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
        $requestUrl = $apiUrl.'2/powerpress/network/'.$networkInfo['network_id'].'/lists/';
        $props['list'] = PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
        return $props;
    }

    /**
     * Returns data relating to one specific list
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the desired program
     * @param $add array of data about the applicant
     * @return array with return data or error
     */
    static function submitApplication($apiUrl, $creds, $networkInfo, $add)
    {
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/applicant/submit?listId=' . $add['listIdForApp'] . '&programId=' . $add['programIdForApp'] . '&feedUrl=' . $add['feedUrl'] . '&webName=' . $add['appLabel'];
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
    }

    /**
     * Returns data relating to one specific list
     * @param $apiUrl string
     * @param $creds array of oauth credentials for blubrry api
     * @param $networkInfo array which includes the id of the desired program
     * @param $update array of new data to overwrite the existing list data
     * @return array with return data or error
     */
    static function updateList($apiUrl, $creds, $networkInfo, $update)
    {
        $update['editListTitle'] = urlencode($update['editListTitle']);
        $update['editListDescription'] = urlencode($update['editListDescription']);
        $requestUrl = $apiUrl . '2/powerpress/network/' . $networkInfo['network_id'] . '/lists/'.$networkInfo['list_id'].'/edit?title=' . $update['editListTitle'] . '&description=' . $update['editListDescription'];
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);;

    }

    /**
     * Given a feed URL, returns information about the applicant
     * @param $apiUrl string
     * @param $post array
     * @return array of token data
     */
    static function checkTokenValidity($apiUrl, $post)
    {
        $creds['post'] = $post;
        $requestUrl = $apiUrl . '2/powerpress/network/token';
        return PowerpressNetworkDataBus::getCacheOrCallAPI($creds, null, $requestUrl, true);
    }
}

haha - 2025