Plugin's account page + sync license URL.

@author Vova Feldman (@svovaf)
@since  1.1.9.1

@param bool|number $plugin_id
@param bool        $add_action_nonce
@param array       $params

@return string
426118
function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
            if ( is_numeric( $plugin_id ) ) {
                $params['plugin_id'] = $plugin_id;
            }

            return $this->get_account_url(
                $this->get_unique_affix() . '_sync_license',
                $params,
                $add_action_nonce
            );
        }
1305275
function save_user( $user_id )
	{
		// verify nonce
		if( !isset($_POST['acf_nonce']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') )
		{
			return $user_id;
		}
		
		
		// $post_id to save against
		$post_id = 'user_' . $user_id;

		
		// update the post
		do_action('acf/save_post', $post_id);
				
	}
983530
protected function view_plugin_page() {
        global $USER;

        $o = '';

        $pluginsubtype = required_param('pluginsubtype', PARAM_ALPHA);
        $plugintype = required_param('plugin', PARAM_PLUGIN);
        $pluginaction = required_param('pluginaction', PARAM_ALPHA);

        $plugin = $this->get_plugin_by_type($pluginsubtype, $plugintype);
        if (!$plugin) {
            print_error('invalidformdata', '');
            return;
        }

        $o .= $plugin->view_page($pluginaction);

        return $o;
    }
739459
function _get_addon_info_filter( $data, $action = '', $args = null ) {
            $this->_logger->entrance();

            $parent_plugin_id = fs_request_get( 'parent_plugin_id', $this->_fs->get_id() );

            if ( $this->_fs->get_id() != $parent_plugin_id ||
                 ( 'plugin_information' !== $action ) ||
                 ! isset( $args->slug )
            ) {
                return $data;
            }

            // Find add-on by slug.
            $selected_addon = $this->_fs->get_addon_by_slug( $args->slug, WP_FS__DEV_MODE );

            if ( false === $selected_addon ) {
                return $data;
            }

            if ( ! isset( $selected_addon->info ) ) {
                // Setup some default info.
                $selected_addon->info                  = new stdClass();
                $selected_addon->info->selling_point_0 = 'Selling Point 1';
                $selected_addon->info->selling_point_1 = 'Selling Point 2';
                $selected_addon->info->selling_point_2 = 'Selling Point 3';
                $selected_addon->info->description     = '<p>Tell your users all about your add-on</p>';
            }

            fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );

            $data = $args;

            $has_free_plan = false;
            $has_paid_plan = false;

            // Load add-on pricing.
            $has_pricing  = false;
            $has_features = false;
            $plans        = false;

            $result = $this->_fs->get_api_plugin_scope()->get( $this->_fs->add_show_pending( "/addons/{$selected_addon->id}/pricing.json?type=visible" ) );

            if ( ! isset( $result->error ) ) {
                $plans = $result->plans;

                if ( is_array( $plans ) ) {
                    for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
                        $pricing  = isset( $plans[ $i ]->pricing ) ? $plans[ $i ]->pricing : null;
                        $features = isset( $plans[ $i ]->features ) ? $plans[ $i ]->features : null;

                        $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
                        $plan        = $plans[ $i ];

                        if ( 'free' == $plans[ $i ]->name ||
                             ! is_array( $pricing ) ||
                             0 == count( $pricing )
                        ) {
                            $has_free_plan = true;
                        }

                        if ( is_array( $pricing ) && 0 < count( $pricing ) ) {
                            $has_paid_plan = true;

                            foreach ( $pricing as &$prices ) {
                                $prices = new FS_Pricing( $prices );
                            }

                            $plan->pricing = $pricing;

                            $has_pricing = true;
                        }

                        if ( is_array( $features ) && 0 < count( $features ) ) {
                            $plan->features = $features;

                            $has_features = true;
                        }
                    }
                }
            }

            $latest = null;

            if ( ! $has_paid_plan && $selected_addon->is_wp_org_compliant ) {
                $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
                    'plugin_information', (object) array(
                    'slug'   => $selected_addon->slug,
                    'is_ssl' => is_ssl(),
                    'fields' => array(
                        'banners'         => true,
                        'reviews'         => true,
                        'downloaded'      => false,
                        'active_installs' => true
                    )
                ) );

                if ( ! empty( $repo_data ) ) {
                    $data                 = $repo_data;
                    $data->wp_org_missing = false;
                } else {
                    // Couldn't find plugin on .org.
                    $selected_addon->is_wp_org_compliant = false;

                    // Plugin is missing, not on Freemius nor WP.org.
                    $data->wp_org_missing = true;
                }

                $data->fs_missing = ( ! $has_free_plan || $data->wp_org_missing );
            } else {
                $data->wp_org_missing = false;

                $current_addon_version = false;
                if ( $this->_fs->is_addon_activated( $selected_addon->id ) ) {
                    $current_addon_version = $this->_fs->get_addon_instance( $selected_addon->id )->get_plugin_version();
                } else if ( $this->_fs->is_addon_installed( $selected_addon->id ) ) {
                    $addon_plugin_data = get_plugin_data(
                        ( WP_PLUGIN_DIR . '/' . $this->_fs->get_addon_basename( $selected_addon->id ) ),
                        false,
                        false
                    );

                    if ( ! empty( $addon_plugin_data ) ) {
                        $current_addon_version = $addon_plugin_data['Version'];
                    }
                }

                // Fetch latest version from Freemius.
                $latest = $this->_fs->_fetch_latest_version(
                    $selected_addon->id,
                    true,
                    WP_FS__TIME_24_HOURS_IN_SEC,
                    $current_addon_version
                );

                if ( $has_paid_plan ) {
                    $data->checkout_link = $this->_fs->checkout_url();
                }
                if ( $has_free_plan ) {
                    $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
                }

                $data->fs_missing = ( false === $latest );


                // Fetch as much as possible info from local files.
                $plugin_local_data = $this->_fs->get_plugin_data();
                $data->author      = $plugin_local_data['Author'];

                if ( ! empty( $selected_addon->info->banner_url ) ) {
                    $data->banners = array(
                        'low' => $selected_addon->info->banner_url,
                    );
                }

                if ( ! empty( $selected_addon->info->screenshots ) ) {
                    $view_vars                     = array(
                        'screenshots' => $selected_addon->info->screenshots,
                        'plugin'      => $selected_addon,
                    );
                    $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
                }

                if ( is_object( $latest ) ) {
                    $data->version      = $latest->version;
                    $data->last_updated = $latest->created;
                    $data->requires     = $latest->requires_platform_version;
                    $data->tested       = $latest->tested_up_to_version;
                } else {
                    // Add dummy version.
                    $data->version = '1.0.0';

                    // Add message to developer to deploy the plugin through Freemius.
                }
            }

            $data->name = $selected_addon->title;
            $view_vars  = array( 'plugin' => $selected_addon );

            if ( is_object( $latest ) && isset( $latest->readme ) && is_object( $latest->readme ) ) {
                $latest_version_readme_data = $latest->readme;
                if ( isset( $latest_version_readme_data->sections ) ) {
                    $data->sections = (array) $latest_version_readme_data->sections;
                } else {
                    $data->sections = array();
                }
            }

            $data->sections['description'] = fs_get_template( '/plugin-info/description.php', $view_vars );

            if ( $has_pricing ) {
                // Add plans to data.
                $data->plans = $plans;

                if ( $has_features ) {
                    $view_vars                  = array(
                        'plans'  => $plans,
                        'plugin' => $selected_addon,
                    );
                    $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
                }
            }

            $data->has_free_plan       = $has_free_plan;
            $data->has_paid_plan       = $has_paid_plan;
            $data->is_paid             = $has_paid_plan;
            $data->is_wp_org_compliant = $selected_addon->is_wp_org_compliant;

            return $data;
        }
345028
public function getPlugin($plugin_id) {
    $cart = $this->getCart();
    $paymentMethodManager = \Drupal::service('plugin.manager.acm_payment_method');
    return $paymentMethodManager->createInstance($plugin_id, [], $cart);
  }
672919
private function fetch_license_by_key( $license_id, $license_key ) {
            $this->_logger->entrance();

            $api = $this->get_current_or_network_user_api_scope();

            $result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );

            return $this->is_api_result_entity( $result ) ?
                new FS_Plugin_License( $result ) :
                $result;
        }
167569
function dynamic_init( array $plugin_info ) {
            $this->_logger->entrance();

            $this->parse_settings( $plugin_info );

            if ( is_admin() && $this->is_theme() && $this->is_premium() && ! $this->has_active_valid_license() ) {
                $this->add_ajax_action(
                    'delete_theme_update_data',
                    array( &$this, '_delete_theme_update_data_action' )
                );
            }

            if ( ! self::is_ajax() ) {
                if ( ! $this->is_addon() || $this->is_only_premium() ) {
                    add_action(
                        ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
                        array( &$this, '_prepare_admin_menu' ),
                        WP_FS__LOWEST_PRIORITY
                    );
                }
            }

            if ( $this->should_stop_execution() ) {
                return;
            }

            if ( ! $this->is_registered() ) {
                if ( $this->is_anonymous() ) {
                    // If user skipped, no need to test connectivity.
                    $this->_has_api_connection = true;
                    $this->_is_on              = true;
                } else {
                    if ( ! $this->has_api_connectivity() ) {
                        if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
                             $this->_admin_notices->has_sticky( 'failed_connect_api' )
                        ) {
                            if ( ! $this->_enable_anonymous || $this->is_premium() ) {
                                // If anonymous mode is disabled, add firewall admin-notice message.
                                add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );

                                $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
                                add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
                                    &$this,
                                    '_email_about_firewall_issue'
                                ) );

                                add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
                                    &$this,
                                    '_retry_connectivity_test'
                                ) );

                                /**
                                 * Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
                                 *
                                 * @author Vova Feldman (@svovaf)
                                 * @since  2.0.0
                                 */
                                /*$this->add_ajax_action( 'resolve_firewall_issues', array(
                                    &$this,
                                    '_email_about_firewall_issue'
                                ) );

                                $this->add_ajax_action( 'retry_connectivity_test', array(
                                    &$this,
                                    '_retry_connectivity_test'
                                ) );*/
                            }
                        }

                        return;
                    } else {
                        $this->_admin_notices->remove_sticky( array(
                            'failed_connect_api_first',
                            'failed_connect_api',
                        ) );

                        if ( $this->_anonymous_mode ) {
                            // Simulate anonymous mode.
                            $this->_is_anonymous = true;
                        }
                    }
                }
            }

            /**
             * This should be executed even if Freemius is off for the core module,
             * otherwise, the add-ons dialogbox won't work properly. This is esepcially
             * relevant when the developer decided to turn FS off for existing users.
             *
             * @author Vova Feldman (@svovaf)
             */
            if ( $this->is_user_in_admin() &&
                'plugin-information' === fs_request_get( 'tab', false ) &&
                 $this->should_use_freemius_updater_and_dialog() &&
                 (
                     ( $this->is_addon() && $this->get_slug() == fs_request_get( 'plugin', false ) ) ||
                     ( $this->has_addons() && $this->get_id() == fs_request_get( 'parent_plugin_id', false ) )
                 )
            ) {
                require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';

                new FS_Plugin_Info_Dialog( $this->is_addon() ? $this->get_parent_instance() : $this );
            }

            // Check if Freemius is on for the current plugin.
            // This MUST be executed after all the plugin variables has been loaded.
            if ( ! $this->is_registered() && ! $this->is_on() ) {
                return;
            }

            if ( $this->has_api_connectivity() ) {
                if ( self::is_cron() ) {
                    $this->hook_callback_to_sync_cron();
                } else if ( $this->is_user_in_admin() ) {
                    /**
                     * Schedule daily data sync cron if:
                     *
                     *  1. User opted-in (for tracking).
                     *  2. If skipped, but later upgraded (opted-in via upgrade).
                     *
                     * @author Vova Feldman (@svovaf)
                     * @since  1.1.7.3
                     *
                     */
                    if ( $this->is_registered() ) {
                        if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
                            $this->schedule_sync_cron();
                        }
                    }

                    /**
                     * Check if requested for manual blocking background sync.
                     */
                    if ( fs_request_has( 'background_sync' ) ) {
                        $this->run_manual_sync();
                    }
                }
            }

            if ( $this->is_registered() ) {
                $this->hook_callback_to_install_sync();
            }

            if ( $this->is_addon() ) {
                if ( $this->is_parent_plugin_installed() ) {
                    // Link to parent FS.
                    $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );

                    // Get parent plugin reference.
                    $this->_parent_plugin = $this->_parent->get_plugin();
                }
            }

            if ( $this->is_user_in_admin() ) {
                if ( $this->is_addon() ) {
                    if ( ! $this->is_parent_plugin_installed() ) {
                        $parent_name = $this->get_option( $plugin_info, 'parent_name', null );

                        if ( isset( $plugin_info['parent'] ) ) {
                            $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
                        }

                        $this->_admin_notices->add(
                            ( ! empty( $parent_name ) ?
                                sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
                                sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
                            ),
                            $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
                            'error'
                        );

                        return;
                    } else {
                        if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
                            // If parent plugin activated, automatically install add-on for the user.
                            $this->_activate_addon_account( $this->_parent );
                        } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
                            // If add-on activated and parent not, automatically install parent for the user.
                            $this->activate_parent_account( $this->_parent );
                        }

                        // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
                        if ( $this->is_premium() ) {
                            // Remove add-on download admin-notice.
                            $this->_parent->_admin_notices->remove_sticky( array(
                                'addon_plan_upgraded_' . $this->_slug,
                                'no_addon_license_' . $this->_slug,
                            ) );
                        }

//						$this->deactivate_premium_only_addon_without_license();
                    }
                }

                add_action( 'admin_init', array( &$this, '_admin_init_action' ) );

//				if ( $this->is_registered() ||
//				     $this->is_anonymous() ||
//				     $this->is_pending_activation()
//				) {
//					$this->_init_admin();
//				}
            }

            /**
             * Should be called outside `$this->is_user_in_admin()` scope
             * because the updater has some logic that needs to be executed
             * during AJAX calls.
             *
             * Currently we need to hook to the `http_request_host_is_external` filter.
             * In the future, there might be additional logic added.
             *
             * @author Vova Feldman
             * @since  1.2.1.6
             */
            if (
                $this->should_use_freemius_updater_and_dialog() &&
                (
                    $this->is_premium() ||
                    /**
                     * If not premium but the premium version is installed, also instantiate the updater so that the
                     * plugin information dialog of the premium version will have the information from the server.
                     *
                     * @author Leo Fajardo (@leorw)
                     * @since 2.2.3
                     */
                    ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->premium_plugin_basename() ) ) )
                ) &&
                $this->has_release_on_freemius()
            ) {
                FS_Plugin_Updater::instance( $this );
            }

            $this->do_action( 'initiated' );

            if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
                if ( isset( $this->_storage->prev_is_premium ) ) {
                    $this->apply_filters(
                        'after_code_type_change',
                        // New code type.
                        $this->_plugin->is_premium
                    );
                } else {
                    // Set for code type for the first time.
                    $this->_storage->prev_is_premium = $this->_plugin->is_premium;
                }
            }

            if ( ! $this->is_addon() ) {
                if ( $this->is_registered() ) {
                    // Fix for upgrade from versions < 1.0.9.
                    if ( ! isset( $this->_storage->activation_timestamp ) ) {
                        $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
                    }

                    $this->do_action( 'after_init_plugin_registered' );
                } else if ( $this->is_anonymous() ) {
                    $this->do_action( 'after_init_plugin_anonymous' );
                } else if ( $this->is_pending_activation() ) {
                    $this->do_action( 'after_init_plugin_pending_activations' );
                }
            } else {
                if ( $this->is_registered() ) {
                    $this->do_action( 'after_init_addon_registered' );
                } else if ( $this->is_anonymous() ) {
                    $this->do_action( 'after_init_addon_anonymous' );
                } else if ( $this->is_pending_activation() ) {
                    $this->do_action( 'after_init_addon_pending_activations' );
                }
            }
        }
1332155
public static function getPluginNameFromNodeId($jnode_id) {
		$result = '';
		//$jid = $jnode_id;
		$plugins = static::getPlugins('both');
		foreach($plugins as $plugin) {
			$id = rtrim(static::getPluginNodeId($plugin->name), '/');
			if (strcasecmp($jnode_id, $id) == 0) {
				$result = $plugin->name;
				break;
			}
		}
		return $result;
	}
1287128
def get_action_definition(action_plugin = nil)
      plugins = action_plugin.nil? ? http_get('plugins') : [action_plugin]
      ret = {}
      plugins.each do |p|
        ret[p] = http_get("/plugins/#{p}")
      end
      ret
    end
1157795
public function getLinkToAction($actionName, $params, $pk_link = false)
    {
        $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName);

        $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\'';

        $params['icon'] = (isset($params['icon']) ? $params['icon'] : 'icon-th-list');
        $params['params']['class'] = (isset($params['params']['class']) ? $params['params']['class'] : 'btn');
        $params['only_icon'] = (isset($params['only_icon']) ? $params['only_icon'] : true);
        $params['size'] = $this->defaultSize($params);
        $params['params']['class'] .= ' ' . $params['size'];
        $title = '__(\'' . $params['label'] . '\', array(), \'' . $this->getI18nCatalogue() . '\')';
        $label = (!$params['only_icon'] ? ' \'.' . $title : '\'');

        return '[?php echo link_to(\'<i class="' . $params['icon'] . '"></i>'
        . $label . ', \'' . $this->getModuleName() . '/' . $action
        . $url_params . ', ' . $this->asPhp($params['params']) . ') ?]';
    }
1073807
def get_action(plugin, action_id)
      the_plugin = hawk_escape plugin
      the_action_id = hawk_escape action_id
      ret = http_get "/actions/#{the_plugin}/#{the_action_id}"
      Trigger::Action.new(ret)
    end
440576
public function getStringToSign(RequestInterface $request, $timestamp, $nonce)
    {
        $params = $this->getParamsToSign($request, $timestamp, $nonce);

        // Convert booleans to strings.
        $params = $this->prepareParameters($params);

        // Build signing string from combined params
        $parameterString = new QueryString($params);

        $url = Url::factory($request->getUrl())->setQuery('')->setFragment(null);

        return strtoupper($request->getMethod()) . '&'
             . rawurlencode($url) . '&'
             . rawurlencode((string) $parameterString);
    }
1026325
public function nonce(string $directive = 'script-src', string $nonce = ''): string
    {
        $ruleKeys = \array_keys($this->policies);
        if (!\in_array($directive, $ruleKeys)) {
            return '';
        }

        if (empty($nonce)) {
            $nonce = Base64::encode(\random_bytes(18));
        }
        $this->policies[$directive]['nonces'] []= $nonce;
        return $nonce;
    }
927461
protected function nonce()
    {
        $action = ($this->getParameter('action') == null) ?
                    $this->RequestContext->getControls()->getControl('action')
                  : $this->getParameter('action');

        return $this->Nonces->create($action);
    }
991794
private function cancel_subscription_or_trial( $plugin_id ) {
            $fs = null;
            if ( $plugin_id == $this->get_id() ) {
                $fs = $this;
            } else if ( $this->is_addon_activated( $plugin_id ) ) {
                $fs = self::get_instance_by_id( $plugin_id );
            }

            $result = null;

            if ( ! is_null( $fs ) ) {
                $result = $fs->is_paid_trial() ?
                    $fs->_cancel_trial() :
                    $fs->_downgrade_site();
            }

            return $result;
        }
1153589
public function get_info($plugin_name)
    {
        static $composer_lock, $license_uris = array(
            'Apache'       => 'http://www.apache.org/licenses/LICENSE-2.0.html',
            'Apache-2'     => 'http://www.apache.org/licenses/LICENSE-2.0.html',
            'Apache-1'     => 'http://www.apache.org/licenses/LICENSE-1.0',
            'Apache-1.1'   => 'http://www.apache.org/licenses/LICENSE-1.1',
            'GPL'          => 'http://www.gnu.org/licenses/gpl.html',
            'GPLv2'        => 'http://www.gnu.org/licenses/gpl-2.0.html',
            'GPL-2.0'      => 'http://www.gnu.org/licenses/gpl-2.0.html',
            'GPLv3'        => 'http://www.gnu.org/licenses/gpl-3.0.html',
            'GPLv3+'       => 'http://www.gnu.org/licenses/gpl-3.0.html',
            'GPL-3.0'      => 'http://www.gnu.org/licenses/gpl-3.0.html',
            'GPL-3.0+'     => 'http://www.gnu.org/licenses/gpl.html',
            'GPL-2.0+'     => 'http://www.gnu.org/licenses/gpl.html',
            'AGPLv3'       => 'http://www.gnu.org/licenses/agpl.html',
            'AGPLv3+'      => 'http://www.gnu.org/licenses/agpl.html',
            'AGPL-3.0'     => 'http://www.gnu.org/licenses/agpl.html',
            'LGPL'         => 'http://www.gnu.org/licenses/lgpl.html',
            'LGPLv2'       => 'http://www.gnu.org/licenses/lgpl-2.0.html',
            'LGPLv2.1'     => 'http://www.gnu.org/licenses/lgpl-2.1.html',
            'LGPLv3'       => 'http://www.gnu.org/licenses/lgpl.html',
            'LGPL-2.0'     => 'http://www.gnu.org/licenses/lgpl-2.0.html',
            'LGPL-2.1'     => 'http://www.gnu.org/licenses/lgpl-2.1.html',
            'LGPL-3.0'     => 'http://www.gnu.org/licenses/lgpl.html',
            'LGPL-3.0+'    => 'http://www.gnu.org/licenses/lgpl.html',
            'BSD'          => 'http://opensource.org/licenses/bsd-license.html',
            'BSD-2-Clause' => 'http://opensource.org/licenses/BSD-2-Clause',
            'BSD-3-Clause' => 'http://opensource.org/licenses/BSD-3-Clause',
            'FreeBSD'      => 'http://opensource.org/licenses/BSD-2-Clause',
            'MIT'          => 'http://www.opensource.org/licenses/mit-license.php',
            'PHP'          => 'http://opensource.org/licenses/PHP-3.0',
            'PHP-3'        => 'http://www.php.net/license/3_01.txt',
            'PHP-3.0'      => 'http://www.php.net/license/3_0.txt',
            'PHP-3.01'     => 'http://www.php.net/license/3_01.txt',
        );

        $dir  = dir($this->dir);
        $fn   = unslashify($dir->path) . "/$plugin_name/$plugin_name.php";
        $info = false;

        if (!class_exists($plugin_name, false)) {
            if (is_readable($fn)) {
                include($fn);
            }
            else {
                return false;
            }
        }

        if (class_exists($plugin_name)) {
            $info = $plugin_name::info();
        }

        // fall back to composer.json file
        if (!$info) {
            $composer = INSTALL_PATH . "/plugins/$plugin_name/composer.json";
            if (is_readable($composer) && ($json = @json_decode(file_get_contents($composer), true))) {
                list($info['vendor'], $info['name']) = explode('/', $json['name']);
                $info['version'] = $json['version'];
                $info['license'] = $json['license'];
                $info['uri']     = $json['homepage'];
                $info['require'] = array_filter(array_keys((array)$json['require']), function($pname) {
                    if (strpos($pname, '/') == false) {
                        return false;
                    }
                    list($vendor, $name) = explode('/', $pname);
                    return !($name == 'plugin-installer' || $vendor == 'pear-pear');
                });
            }

            // read local composer.lock file (once)
            if (!isset($composer_lock)) {
                $composer_lock = @json_decode(@file_get_contents(INSTALL_PATH . "/composer.lock"), true);
                if ($composer_lock['packages']) {
                    foreach ($composer_lock['packages'] as $i => $package) {
                        $composer_lock['installed'][$package['name']] = $package;
                    }
                }
            }

            // load additional information from local composer.lock file
            if ($lock = $composer_lock['installed'][$json['name']]) {
                $info['version'] = $lock['version'];
                $info['uri']     = $lock['homepage'] ?: $lock['source']['uri'];
                $info['src_uri'] = $lock['dist']['uri'] ?: $lock['source']['uri'];
            }
        }

        // fall back to package.xml file
        if (!$info) {
            $package = INSTALL_PATH . "/plugins/$plugin_name/package.xml";
            if (is_readable($package) && ($file = file_get_contents($package))) {
                $doc = new DOMDocument();
                $doc->loadXML($file);
                $xpath = new DOMXPath($doc);
                $xpath->registerNamespace('rc', "http://pear.php.net/dtd/package-2.0");

                // XPaths of plugin metadata elements
                $metadata = array(
                    'name'    => 'string(//rc:package/rc:name)',
                    'version' => 'string(//rc:package/rc:version/rc:release)',
                    'license' => 'string(//rc:package/rc:license)',
                    'license_uri' => 'string(//rc:package/rc:license/@uri)',
                    'src_uri' => 'string(//rc:package/rc:srcuri)',
                    'uri'     => 'string(//rc:package/rc:uri)',
                );

                foreach ($metadata as $key => $path) {
                    $info[$key] = $xpath->evaluate($path);
                }

                // dependent required plugins (can be used, but not included in config)
                $deps = $xpath->evaluate('//rc:package/rc:dependencies/rc:required/rc:package/rc:name');
                for ($i = 0; $i < $deps->length; $i++) {
                    $dn = $deps->item($i)->nodeValue;
                    $info['require'][] = $dn;
                }
            }
        }

        // At least provide the name
        if (!$info && class_exists($plugin_name)) {
            $info = array('name' => $plugin_name, 'version' => '--');
        }
        else if ($info['license'] && empty($info['license_uri']) && ($license_uri = $license_uris[$info['license']])) {
            $info['license_uri'] = $license_uri;
        }

        return $info;
    }
913254
public function linkAction(Request $request, $id, $locale)
    {
        /** @var PageInterface $page */
        $page = $this->admin->getObject($id);

        if (!$page) {
            throw new NotFoundHttpException(sprintf('unable to find the Page with id : %s', $id));
        }

        if ($request->getMethod() == 'POST') {
            $linkPageId = $request->get('page');
            if (!$linkPageId) {
                $this->get('session')->getFlashBag()->add('sonata_flash_error', 'flash_link_error');
            } else {
                /** @var PageInterface $linkPage */
                $linkPage = $this->admin->getObject($linkPageId);

                $page->addTranslation($linkPage);

                $this->admin->update($page);

                if ($this->isXmlHttpRequest()) {
                    $html = $this->renderView(
                        '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig',
                        ['object' => $page, 'admin' => $this->admin]
                    );

                    return $this->renderJson(
                        [
                            'result' => 'ok',
                            'html' => $html,
                        ]
                    );
                }

                $this->get('session')->getFlashBag()->add('sonata_flash_success', 'flash_link_success');

                return new RedirectResponse($this->admin->generateUrl('edit', ['id' => $page->getId()]));
            }
        }

        $pages = $this->admin->getModelManager()->findBy($this->admin->getClass(), ['locale' => $locale]);

        if (count($pages)) {
            $pages = new ArrayCollection($pages);
            $originalLocale = $page->getLocale();
            $pages = $pages->filter(
                function (PageInterface $linkPage) use ($originalLocale) {
                    return !in_array($originalLocale, $linkPage->getTranslatedLocales());
                }
            );
        }

        return $this->renderWithExtraParams(
            '@NetworkingInitCms/PageAdmin/page_translation_link_list.html.twig',
            [
                'page' => $page,
                'pages' => $pages,
                'locale' => $locale,
                'original_language' => \Locale::getDisplayLanguage($page->getLocale()),
                'language' => \Locale::getDisplayLanguage($locale),
                'admin' => $this->admin,
            ]
        );
    }