public function RepositoryLogin()
 {
     list($get, $post) = func_get_args();
     if (isset($get['repository_id'])) {
         $this->repo_model = WPRC_Loader::getModel('repositories');
         $this->repository = $this->repo_model->getRepositoryByField('id', (int) $get['repository_id']);
         if (empty($get['submit'])) {
             //$nonce=$get['_wpnonce'];
             if (!array_key_exists('_wpnonce', $get) || !wp_verify_nonce($get['_wpnonce'], 'installer-login-link')) {
                 die("Security check");
             }
             self::render();
         } else {
             //$nonce=$get['_wpnonce'];
             if (!array_key_exists('_wpnonce', $get) || !wp_verify_nonce($get['_wpnonce'], 'installer-login-form')) {
                 die("Security check");
             }
             if (!array_key_exists('repository_id', $get) || !array_key_exists('username', $get) || !array_key_exists('password', $get)) {
                 die;
             }
             $login = $this->repo_model->testLogin($get['repository_id'], $get['username'], $get['password'], isset($get['_plain']) && $get['_plain'] == 'true' ? true : false);
             if ($login != false && empty($login['error'])) {
                 echo json_encode(array('success' => 1, 'message' => $login['message']));
             } else {
                 echo json_encode(array('success' => 0, 'message' => $login['message']));
             }
             exit;
         }
     }
 }
 /**
  * Print javascript global array of texts
  */
 public static function printJsLanguage()
 {
     WPRC_Loader::includeLanguageContainer();
     $wprcLang = WPRC_LanguageContainer::getLanguageArray();
     if (count($wprcLang) == 0) {
         return false;
     }
     foreach ($wprcLang as $key => $value) {
         $lang_js[] = "'" . $key . "' : '" . $value . "'";
     }
     $lang_js_html = implode(',', $lang_js);
     $js = "<script type=\"text/javascript\">\r\n            var wprcLang = { \r\n                {$lang_js_html} \r\n            };\r\n        </script>";
     echo $js;
 }
 /**
  * Prepare report data from the post data
  *
  * @param array $post_data raw data
  * 
  * @return array report
  */
 public function prepareRequest(array $post_data)
 {
     // get key and type of extension that need to be checked
     if (!array_key_exists('check_extension_name', $post_data) || !array_key_exists('check_extension_type', $post_data)) {
         return false;
     }
     $check_extension_name = $post_data['check_extension_name'];
     $check_extension_type = $post_data['check_extension_type'];
     $check_extension_repository_url = $post_data['check_extension_repository_url'];
     $check_extension_version = $post_data['check_extension_version'];
     $check_extension_slug = $post_data['check_extension_slug'];
     $extension_model = WPRC_Loader::getModel('extensions');
     $extensions_tree = $extension_model->getFullExtensionsTree();
     $extensions_tree['themes'] = $extension_model->changeExtensionsKey($extensions_tree['themes'], 'Name');
     $typekeys = $extension_model->getExtensionTypeKeys();
     $activetypekeys = $extension_model->getActiveExtensionTypeKeys();
     // ---------- left extensions ------------
     if (array_key_exists($check_extension_type, $extensions_tree) && is_array($check_extension)) {
         $check_extension = $extensions_tree[$check_extension_type][$check_extension_name];
         $left_extension = $this->prepareExtensionInfo($check_extension_name, $check_extension_type, $check_extension);
     } else {
         $left_extension = array('name' => $check_extension_name, 'type' => $check_extension_type, 'repository_url' => $check_extension_repository_url, 'version' => $check_extension_version, 'slug' => $check_extension_slug);
     }
     $left_extensions = array($check_extension_name => $left_extension);
     // ---------- right extensions -----------
     $active_extensions = $extension_model->getActiveExtensions();
     // cycle on each extension type
     if (count($active_extensions) == 0) {
         return false;
     }
     $right_extensions = array();
     foreach ($active_extensions as $extension_type => $extensions) {
         for ($i = 0; $i < count($extensions); $i++) {
             $key = $activetypekeys[$extension_type];
             //$key=$typekeys[$extension_type];
             $extension = $extension_model->findExtensionwithKey($extensions_tree, $extension_type, $key, $extensions[$i]);
             if ($extension === false) {
                 continue;
             }
             //if (!isset($extensions_tree[$extension_type][$extensions[$i]])) continue;
             //$extension = $extensions_tree[$extension_type][$extensions[$i]];
             $right_extensions[$extension['Name']] = $this->prepareExtensionInfo($extensions[$i], $extension_type, $extension);
         }
     }
     // prepare report data
     $report_data = array('left_extensions' => $left_extensions, 'right_extensions' => $right_extensions);
     $creport = $this->formRequestStructure($report_data);
     //file_put_contents(WPRC_PLUGIN_PATH.'/debug_comp.txt',print_r($report_data,true),FILE_APPEND);
     return $creport;
 }
 /**
  * Save wprc settings
  * 
  * @param array $_GET array
  * @param array $_POST array
  */
 public function save($get, $post)
 {
     $settings = array();
     if (!array_key_exists('_wpnonce', $post) || !wp_verify_nonce($post['_wpnonce'], 'installer-settings-form')) {
         die("Security check");
     }
     if (array_key_exists('settings', $post) && is_array($post['settings'])) {
         $settings = $post['settings'];
     }
     $settings_model = WPRC_Loader::getModel('settings');
     $res = $settings_model->save($settings);
     $flag = 'failure';
     if ($res) {
         $flag = 'success';
     }
     $this->redirect_to_index($flag);
 }
 /**
  * Prepare report data
  *
  * @param array input data
  */
 public function prepareRequest(array $input_data)
 {
     $month_day = get_option('wprc_usage_sending_month_day');
     $send = false;
     if (!$month_day) {
         // Choose one day of the month between 2 and 27.
         // We'll not send usage reports out of those days
         $month_day = str_pad(rand(2, 27), 2, '0', STR_PAD_LEFT);
         update_option('wprc_usage_sending_month_day', $month_day);
         $current_day = date_i18n('d');
         if (strcmp($current_day, $month_day) === -1) {
             // If month day < today we'll send the report later on, but this same month
             $next_report_date = date_i18n('Ym' . $month_day, current_time('timestamp'));
             set_transient('wprc_usage_reports', $next_report_date);
         } else {
             $send = true;
         }
     }
     $today = date_i18n('Ymd', current_time('timestamp'));
     $transient = get_transient('wprc_usage_reports');
     if (!$transient || strcmp($today, $transient) >= 0) {
         $next_report_date = date_i18n('Ym' . $month_day, strtotime('first day of next month', current_time('timestamp')));
         set_transient('wprc_usage_reports', $next_report_date);
         $send = true;
     }
     if ($send) {
         // get data of all plugins
         WPRC_Loader::includeExtensionDataManager();
         $all_data = WPRC_ExtensionDataManager::getAllData('extension');
         $value = array();
         $report = $this->search_key($all_data, 'activated_extensions');
         $site_info = $this->getSiteInfo(true);
         $site_url = $site_info['site_url'];
         $raw_report_data = array('reports' => $report);
         if (!is_array($report)) {
             return false;
         }
         $report = $this->formRequestStructure($raw_report_data);
         return $report;
     }
     return false;
 }
Beispiel #6
0
 public static function execute($controller = '', $action = '')
 {
     if ($controller != '' && $action == '' || $controller == '' && $action != '') {
         return false;
     }
     $do = $action == '' ? self::getParam('wprc_action') : $action;
     $controller_name = $controller == '' ? self::getParam('wprc_c') : $controller;
     if ($do != '') {
         if ($controller_name) {
             $controllerObject = WPRC_Loader::getController($controller_name);
             if ($controllerObject) {
                 if (method_exists($controllerObject, $do)) {
                     if (@is_callable(array($controllerObject, $do))) {
                         //is public method
                         call_user_func_array(array($controllerObject, $do), array($_GET, $_POST));
                     }
                 }
             }
         }
         exit;
     }
 }
 /**
  * Send request to any file
  * 
  * @param string method
  * @param string url to send
  * @param mixed arguments to send
  */
 public function sendRequest($method, $url, $args, $timeout = 15)
 {
     WPRC_Loader::includeWordpressHttp();
     if (isset($args['request'])) {
         $body_array = array('action' => $args['action'], 'request' => serialize($args['request']));
     } else {
         $body_array = array('action' => $args['action']);
     }
     // log
     $debug_msg = sprintf('SERVER REQUEST, method: %s, timeout: %d, uri: %s, args: %s', $method, $timeout, $url, print_r($args, true));
     WPRC_Functions::log($debug_msg, 'server', 'server.log');
     switch ($method) {
         case 'post':
             $request = wp_remote_post($url, array('timeout' => $timeout, 'body' => $body_array));
             // log
             $debug_msg = sprintf('SERVER REQUEST, response: %s', print_r($request, true));
             WPRC_Functions::log($debug_msg, 'server', 'server.log');
             if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
                 // log
                 if (is_wp_error($request)) {
                     $debug_msg = sprintf('SERVER REQUEST, response error: %s', print_r($request->get_error_message(), true));
                 } else {
                     $debug_msg = sprintf('SERVER REQUEST, response error code: %s', print_r(wp_remote_retrieve_response_code($request), true));
                 }
                 WPRC_Functions::log($debug_msg, 'server', 'server.log');
                 // connection failed
                 return false;
             }
             $res = @unserialize(wp_remote_retrieve_body($request));
             if (false === $res) {
                 $res = new WP_Error('repository_connector_error', __('An unknown error occurred.', 'installer'), wp_remote_retrieve_body($request));
                 // log
                 $debug_msg = sprintf('SERVER REQUEST, response unknown error: %s', print_r(wp_remote_retrieve_body($request), true));
                 WPRC_Functions::log($debug_msg, 'server', 'server.log');
             }
             break;
     }
     return $res;
 }
Beispiel #8
0
function installer_repositories_page_tabs($current = 'default')
{
    if (isset($_GET['rtab'])) {
        $current = $_GET['rtab'];
    }
    $repo_model = WPRC_Loader::getModel('repositories');
    $not_delete_counts = count($repo_model->getAllRepositoriesNotDeleted());
    $delete_counts = count($repo_model->getAllRepositoriesDeleted());
    $tabs = array('default' => sprintf(__('Active repositories (%s)', 'installer'), $not_delete_counts), 'trash' => sprintf(__('Inactive repositories (%s)', 'installer'), $delete_counts));
    $links = array();
    foreach ($tabs as $tab => $name) {
        if ($tab == $current) {
            $links[] = '<a class="nav-tab nav-tab-active" href="?page=installer/pages/repositories.php&rtab=' . $tab . '">' . $name . '</a>';
        } else {
            $links[] = '<a class="nav-tab" href="?page=installer/pages/repositories.php&rtab=' . $tab . '">' . $name . '</a>';
        }
    }
    echo '<div id="icon-repositories-installer" class="icon32"><br></div>';
    echo '<h2 class="nav-tab-wrapper">';
    foreach ($links as $link) {
        echo $link;
    }
    echo '</h2>';
}
 /**
  * Display search results
  */
 public function displaySearchResults()
 {
     $wp_list_table = WPRC_Loader::getListTable('theme-install');
     $pagenum = $wp_list_table->get_pagenum();
     $wp_list_table->prepare_items();
     $title = __('Install Themes');
     $parent_file = 'themes.php';
     if (!is_network_admin()) {
         $submenu_file = 'themes.php';
     }
     wp_enqueue_script('theme-install');
     add_thickbox();
     wp_enqueue_script('theme-preview');
     if (isset($tab)) {
         $body_id = $tab;
         do_action('install_themes_pre_' . $tab);
         //Used to override the general interface, Eg, install or theme information.
     }
     $help = '<p>' . sprintf(__('You can find additional themes for your site by using the Theme Browser/Installer on this screen, which will display themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. These themes are designed and developed by third parties, are available free of charge, and are compatible with the license WordPress uses.', 'installer'), 'http://wordpress.org/extend/themes/') . '</p>';
     $help .= '<p>' . __('You can Search for themes by keyword, author, or tag, or can get more specific and search by criteria listed in the feature filter. Alternately, you can browse the themes that are Featured, Newest, or Recently Updated. When you find a theme you like, you can preview it or install it.', 'installer') . '</p>';
     $help .= '<p>' . __('You can Upload a theme manually if you have already downloaded its ZIP archive onto your computer (make sure it is from a trusted and original source). You can also do it the old-fashioned way and copy a downloaded theme&#8217;s folder via FTP into your <code>/wp-content/themes</code> directory.', 'installer') . '</p>';
     get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => $help));
     get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'installer') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>', 'installer') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'installer') . '</p>');
     include ABSPATH . 'wp-admin/admin-header.php';
     $this->renderAdditionalSearchUI();
     echo '<div class="wrap">';
     screen_icon();
     if (is_network_admin()) {
         echo '<h2>' . esc_html($title) . '</h2>';
     } else {
         echo '<h2 class="nav-tab-wrapper"><a href="themes.php" class="nav-tab">' . esc_html_x('Manage Themes', 'theme') . '</a>
         <a href="theme-install.php" class="nav-tab nav-tab-active">' . esc_html($title) . '</a></h2>';
     }
     $wp_list_table->views();
     $wp_list_table->display();
     echo '<br class="clear" />';
     if (isset($tab) && isset($paged)) {
         do_action('install_themes_' . $tab, $paged);
     }
     echo '</div>';
     include ABSPATH . 'wp-admin/admin-footer.php';
     exit;
 }
 /**
  * Check to see if the theme is already installed.
  *
  * @since 3.4
  * @access private
  *
  * @param object $theme - A WordPress.org Theme API object.
  * @return string Theme status.
  */
 private function _wp_get_theme($stylesheet = null, $theme_root = null)
 {
     global $wp_theme_directories;
     if (empty($stylesheet)) {
         $stylesheet = get_stylesheet();
     }
     if (empty($theme_root)) {
         $theme_root = get_raw_theme_root($stylesheet);
         if (false === $theme_root) {
             $theme_root = WP_CONTENT_DIR . '/themes';
         } elseif (!in_array($theme_root, (array) $wp_theme_directories)) {
             $theme_root = WP_CONTENT_DIR . $theme_root;
         }
     }
     if (class_exists('WP_Theme')) {
         return new WP_Theme($stylesheet, $theme_root);
     } else {
         WPRC_Loader::includeClass('class-wp-theme.php');
         return new WP_Theme($stylesheet, $theme_root);
     }
 }
<?php

if (!defined('ABSPATH')) {
    die('Security check');
}
if (!current_user_can('manage_options')) {
    die('Access Denied');
}
// include needed files
WPRC_Loader::includeWPListTable();
$wp_list_table = WPRC_Loader::getListTable('deleted-repositories');
//Handle bulk deletes
$doaction = $wp_list_table->current_action();
if ($doaction) {
    $repository_model = WPRC_Loader::getModel('repositories');
}
$url = admin_url() . 'admin.php?page=' . WPRC_PLUGIN_FOLDER . '/pages/deleted-repositories.php';
if ($doaction && isset($_REQUEST['checked'])) {
    check_admin_referer('bulk-list-deleted-repositories');
    if ('undelete' == $doaction) {
        $bulklinks = (array) $_REQUEST['checked'];
        foreach ($bulklinks as $id) {
            $repository_id = (int) $id;
            $repository_model->softundeleteRepository($repository_id);
        }
    }
} elseif ($doaction) {
    switch ($doaction) {
        case 'undelete':
            if (!isset($_REQUEST['id'])) {
                break;
 /**
  * Prepare uninstall data for the sending
  * 
  * @param array array of posted data
  * 
  * @return array associative array of specified format
  */
 public function prepareRequest(array $post_array)
 {
     if (!array_key_exists('extension_keys', $post_array) || !array_key_exists('extension_type', $post_array) || !array_key_exists('uninstall_reason_code', $post_array)) {
         return false;
     }
     if (!is_array($post_array['extension_keys'])) {
         return false;
     }
     $extension_keys = $post_array['extension_keys'];
     // disable request sending if several plugins were deactivated
     if (count($extension_keys) > 1) {
         //return false;
     }
     $extension_type = preg_match('/^(plugin|theme)$/', $post_array['extension_type']) ? $post_array['extension_type'] : '';
     // set uninstall reason code
     $uninstall_reason_code = $post_array['uninstall_reason_code'];
     if (array_key_exists('uninstall_reason_code_child', $post_array) && $post_array['uninstall_reason_code_child'] != '') {
         $uninstall_reason_code .= '-' . $post_array['uninstall_reason_code_child'];
     }
     // set uninstall reason description
     $uninstall_reason_description = $this->filterText($post_array['uninstall_reason_description']);
     // set uninstall reason items -------------------------------
     $problem_array_name = '';
     $unistall_reason_items_type = '';
     switch ($uninstall_reason_code) {
         case '3-1':
             $problem_array_name = 'problem_themes';
             $unistall_reason_items_type = 'theme';
             break;
         case '3-2':
             $problem_array_name = 'problem_plugins';
             $unistall_reason_items_type = 'plugin';
             break;
     }
     $uninstall_reason_items_names = array();
     $uninstall_reason_items = array();
     if (isset($problem_array_name) && array_key_exists($problem_array_name, $post_array)) {
         if (is_array($post_array[$problem_array_name]) && count($post_array[$problem_array_name]) > 0) {
             $uninstall_reason_items_names = $post_array[$problem_array_name];
         }
     }
     // get all extension data
     $ext_model = WPRC_Loader::getModel('extensions');
     $all_extensions = $ext_model->getFullExtensionsTree();
     $all_extensions['themes'] = $ext_model->changeExtensionsKey($all_extensions['themes'], 'Name');
     // form plural extension type name
     $unistall_reason_items_type_plural = $unistall_reason_items_type . 's';
     // set all information for uninstall reason items
     $extension_path = '';
     for ($i = 0; $i < count($uninstall_reason_items_names); $i++) {
         $extension = $all_extensions[$unistall_reason_items_type_plural][$uninstall_reason_items_names[$i]];
         if ($unistall_reason_items_type == 'plugin') {
             $extension_path = $uninstall_reason_items_names[$i];
         }
         $uninstall_reason_items[$uninstall_reason_items_names[$i]] = array('name' => $extension['Name'], 'type' => $unistall_reason_items_type, 'path' => $extension_path, 'version' => $extension['Version'], 'slug' => $extension['extension_slug'], 'repository_url' => $extension['repository_endpoint_url']);
     }
     // set report data array ------------------------------------
     $extensions = array();
     // form plural extension type name
     $extension_type_plural = $extension_type . 's';
     $extension_path = '';
     for ($i = 0; $i < count($extension_keys); $i++) {
         if (!isset($all_extensions[$extension_type_plural][$extension_keys[$i]])) {
             continue;
         }
         $extension = $all_extensions[$extension_type_plural][$extension_keys[$i]];
         if ($extension_type == 'plugin') {
             $extension_path = $extension_keys[$i];
         }
         $slug = '';
         if (array_key_exists('extension_slug', $extension)) {
             $slug = $extension['extension_slug'];
         }
         $repository_endpoint_url = '';
         if (array_key_exists('repository_endpoint_url', $extension)) {
             $repository_endpoint_url = $extension['repository_endpoint_url'];
         }
         $extensions[$extension_keys[$i]] = array('name' => $extension['Name'], 'type' => $extension_type, 'path' => $extension_path, 'version' => $extension['Version'], 'slug' => $slug, 'repository_url' => $repository_endpoint_url);
     }
     $report_data = array('extensions' => $extensions, 'uninstall_reason_code' => $uninstall_reason_code, 'uninstall_reason_description' => $uninstall_reason_description, 'uninstall_reason_items' => $uninstall_reason_items);
     $report = $this->formRequestStructure($report_data);
     //file_put_contents(WPRC_PLUGIN_PATH.'/debug_uninstall.txt',print_r($report_data,true),FILE_APPEND);
     return $report;
 }
 /**
  * Display search results
  */
 public function displaySearchResults()
 {
     //global $tab, $paged;
     if (!current_user_can('install_plugins')) {
         wp_die(__('You do not have sufficient permissions to install plugins on this site.', 'installer'));
     }
     if (is_multisite() && !is_network_admin()) {
         wp_redirect(network_admin_url('plugin-install.php'));
         exit;
     }
     $wp_list_table = WPRC_Loader::getListTable('plugin-install');
     $pagenum = $wp_list_table->get_pagenum();
     $wp_list_table->prepare_items();
     $title = __('Install Plugins', 'installer');
     $parent_file = 'plugins.php';
     wp_enqueue_script('plugin-install');
     if (isset($tab)) {
         if ('plugin-information' != $tab) {
             add_thickbox();
         }
         $body_id = $tab;
         do_action('install_plugins_pre_' . $tab);
         //Used to override the general interface, Eg, install or plugin information.
     }
     //get_current_screen()->add_help_tab( array(
     //'id'		=> 'overview',
     //'title'		=> __('Overview', 'installer'),
     //'content'	=>
     //	'<p>' . sprintf(__('Plugins hook into WordPress to extend its functionality with custom features. Plugins are developed independently from the core WordPress application by thousands of developers all over the world. All plugins in the official <a href="%s" target="_blank">WordPress.org Plugin Directory</a> are compatible with the license WordPress uses. You can find new plugins to install by searching or browsing the Directory right here in your own Plugins section.'), 'http:wordpress.org/extend/plugins/') . '</p>'
     //) );
     //get_current_screen()->add_help_tab( array(
     //'id'		=> 'adding-plugins',
     //'title'		=> __('Adding Plugins', 'installer'),
     //'content'	=>
     //	'<p>' . __('If you know what you&#8217;re looking for, Search is your best bet. The Search screen has options to search the WordPress.org Plugin Directory for a particular Term, Author, or Tag. You can also search the directory by selecting a popular tags. Tags in larger type mean more plugins have been labeled with that tag.', 'installer') . '</p>' .
     //	'<p>' . __('If you just want to get an idea of what&#8217;s available, you can browse Featured, Popular, Newest, and Recently Updated plugins by using the links in the upper left of the screen. These sections rotate regularly.', 'installer') . '</p>' .
     //	'<p>' . __('If you want to install a plugin that you&#8217;ve downloaded elsewhere, click the Upload in the upper left. You will be prompted to upload the .zip package, and once uploaded, you can activate the new plugin.', 'installer') . '</p>'
     //) );
     //
     //get_current_screen()->set_help_sidebar(
     //	'<p><strong>' . __('For more information:', 'installer') . '</strong></p>' .
     //	'<p>' . __('<a href="http:codex.wordpress.org/Plugins_Add_New_Screen" target="_blank">Documentation on Installing Plugins</a>', 'installer') . '</p>' .
     //	'<p>' . __('<a href="http:wordpress.org/support/" target="_blank">Support Forums</a>', 'installer') . '</p>'
     //);
     include ABSPATH . 'wp-admin/admin-header.php';
     $this->renderAdditionalSearchUI();
     echo '<div class="wrap">';
     screen_icon();
     echo '<h2>' . esc_html($title) . '</h2>';
     $wp_list_table->views();
     $wp_list_table->display();
     echo '<br class="clear" />';
     if (isset($tab) && isset($paged)) {
         do_action('install_plugins_' . $tab, $paged);
     }
     echo '</div>';
     include ABSPATH . 'wp-admin/admin-footer.php';
     exit;
 }
    public function display_rows()
    {
        $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()), 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array());
        list($columns, $hidden) = $this->get_column_info();
        $style = array();
        foreach ($columns as $column_name => $column_display_name) {
            $style[$column_name] = in_array($column_name, $hidden) ? 'style="display:none;"' : '';
        }
        $nonce_login = wp_create_nonce('installer-login-link');
        foreach ((array) $this->items as $plugin) {
            //echo '<pre>'; print_r($plugin); echo '</pre>';
            if (is_object($plugin)) {
                $plugin = (array) $plugin;
            }
            $title = wp_kses($plugin['name'], $plugins_allowedtags);
            //Limit description to 400char, and remove any HTML.
            $description = strip_tags($plugin['description']);
            if (strlen($description) > 400) {
                $description = mb_substr($description, 0, 400) . '&#8230;';
            }
            //remove any trailing entities
            $description = preg_replace('/&[^;\\s]{0,6}$/', '', $description);
            //strip leading/trailing & multiple consecutive lines
            $description = trim($description);
            $description = preg_replace("|(\r?\n)+|", "\n", $description);
            //\n => <br>
            $description = nl2br($description);
            $version = wp_kses($plugin['version'], $plugins_allowedtags);
            $name = strip_tags($title . ' ' . $version);
            $author = $plugin['author'];
            if (!empty($plugin['author'])) {
                $author = ' <cite>' . sprintf(__('By %s', 'installer'), $author) . '.</cite>';
            }
            $author = wp_kses($author, $plugins_allowedtags);
            $action_links = array();
            $action_links[] = '<a href="' . self_admin_url('plugin-install.php?tab=plugin-information&amp;repository_id=' . $plugin['repository']->id . '&amp;plugin=' . $plugin['slug'] . '&amp;TB_iframe=true&amp;width=600&amp;height=550') . '" class="thickbox" title="' . esc_attr(sprintf(__('More information about %s', 'installer'), $name)) . '">' . __('Details', 'installer') . '</a>';
            // set price
            $no_price_value = __('Free', 'installer');
            $plugin_price = $no_price_value;
            if (array_key_exists('price', $plugin)) {
                $plugin_price = $plugin['price'] != 0 && isset($plugin['price']) ? $plugin['currency']->symbol . $plugin['price'] . ' (' . $plugin['currency']->name . ')' : $no_price_value;
            }
            $plugin_source = '';
            if (array_key_exists('repository', $plugin)) {
                $plugin_source = $plugin['repository']->repository_name;
            }
            if (current_user_can('install_plugins') || current_user_can('update_plugins')) {
                //$plugin['purchase_url'] = 'http://wpml.org/shop/checkout/?buy_now=2'; // DEBUG
                WPRC_Loader::includeListTable('wprc-plugin-information');
                $status = WPRC_PluginInformation::wprc_install_plugin_install_status($plugin);
                //$action_links[]=$status['status'];
                if ($status['status'] != 'latest_installed' && $status['status'] != 'newer_installed') {
                    if (isset($plugin['purchase_link']) && !empty($plugin['purchase_link']) && $plugin_price != $no_price_value) {
                        $purl = WPRC_Functions::sanitizeURL($plugin['purchase_link']);
                        $return_url = rawurlencode(admin_url('plugin-install.php?tab=plugin-information&repository_id=' . $plugin['repository']->id . '&plugin=' . $plugin['slug']));
                        $salt = rawurlencode($plugin['salt']);
                        if (strpos($purl, '?')) {
                            $url_glue = '&';
                        } else {
                            $url_glue = '?';
                        }
                        $purl .= $url_glue . 'return_to=' . $return_url . '&rsalt=' . $salt;
                        $status = array('status' => 'paid', 'url' => $purl, 'version' => $plugin['version']);
                    }
                    /*else
                                 {
                                     WPRC_Loader::includeListTable('wprc-plugin-information');
                    		$status = WPRC_PluginInformation::wprc_install_plugin_install_status( $plugin );    
                                 }*/
                }
                $url_glue = false === strpos($status['url'], '?') ? '?' : '&';
                $status['url'] .= $url_glue . 'repository_id=' . $plugin['repository']->id;
                $showedmessage = false;
                switch ($status['status']) {
                    case 'install':
                        if ($status['url']) {
                            $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr(sprintf(__('Install %s', 'installer'), $name)) . '">' . __('Install Now', 'installer') . '</a>';
                        }
                        break;
                    case 'update_available':
                        if ($status['url']) {
                            $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr(sprintf(__('Update to version %s', 'installer'), $status['version'])) . '">' . sprintf(__('Update Now', 'installer'), $status['version']) . '</a>';
                        }
                        break;
                    case 'paid':
                        //$action_links[] = '<a href="' . $status['url'] . '" class="thickbox">' . __('Buy' , 'installer') . ' (' . $plugin['currency'] . $plugin['price'].')</a>';
                        if (isset($plugin['message']) && !empty($plugin['message'])) {
                            $action_links[] = WPRC_Functions::formatMessage($plugin['message']);
                            $showedmessage = true;
                        } else {
                            //$action_links[] = '<a href=" ' . admin_url('admin.php?wprc_c=repository-login&wprc_action=RepositoryLogin&repository_id=' . $plugin['repository']->id) . '&buyurl='.rawurlencode($status['url']).'" class="thickbox" title="' . __('Buy', 'installer') . '">' . __('Buy ' , 'installer') . ' (' . $plugin['currency'] . $plugin['price'].')</a>';
                            //$action_links[] = '<a href=" ' . $status['url']  . '" class="thickbox" title="' . __('Buy', 'installer') . '">' . __('Buy' , 'installer') . ' (' . $plugin['currency'] . $plugin['price'].')</a>';
                            $action_links[] = '<a href=" ' . $status['url'] . '&TB_iframe=true' . '" class="thickbox" title="' . sprintf(__('Buy %s', 'installer'), $name) . '">' . sprintf(__('Buy %s', 'installer'), '(' . $plugin['currency']->symbol . $plugin['price'] . ' ' . $plugin['currency']->name . ')') . '</a>';
                        }
                        if (empty($plugin['repository']->repository_username) && empty($plugin['repository']->repository_password)) {
                            $action_links[] = '<a href=" ' . admin_url('admin.php?wprc_c=repository-login&amp;wprc_action=RepositoryLogin&amp;repository_id=' . $plugin['repository']->id . '&amp;_wpnonce=' . $nonce_login) . '" class="thickbox" title="' . __('Log in', 'installer') . '">' . __('Login', 'installer') . '</a>';
                        }
                        break;
                    case 'latest_installed':
                    case 'newer_installed':
                        $action_links[] = '<span title="' . esc_attr__('This plugin is already installed and is up to date', 'installer') . ' ">' . __('Installed', 'installer') . '</span>';
                        break;
                }
                if (isset($plugin['message']) && !empty($plugin['message'])) {
                    $message = WPRC_Functions::formatMessage($plugin['message']);
                    if (isset($plugin['message_type']) && $plugin['message_type'] == 'notify') {
                        WPRC_AdminNotifier::addMessage('wprc-plugin-info-' . $plugin['slug'], $message);
                    } elseif (!$showedmessage) {
                        $action_links[] = $message;
                    }
                }
            }
            // add check compatibility link
            //            $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&amp;repository_id='. $plugin['repository']->id .'&amp;plugin=' . $plugin['slug'] .
            //                '&amp;TB_iframe=true&amp;width=600&amp;height=550' ) . '" class="thickbox" title="' .
            //                esc_attr( sprintf( __( 'Check compatibility of "%s" plugin with activated extensions', 'installer' ), $name ) ) . '">' . __( 'Check compatibility', 'installer' ) . '</a>';
            $slug = isset($plugin['slug']) ? '&amp;extension_slug=' . $plugin['slug'] : '';
            $action_links[] = '<a href="' . self_admin_url('admin.php?wprc_c=repository-reporter&amp;wprc_action=checkCompatibility&amp;repository_id=' . $plugin['repository']->id . '&amp;repository_url=' . $plugin['repository']->repository_endpoint_url . '&amp;extension_name=' . $plugin['name'] . '&amp;extension_version=' . $plugin['version'] . $slug . '&amp;extension_type_singular=plugin&amp;extension_type=plugins&amp;TB_iframe=true&amp;width=300&amp;height=400') . '" class="thickbox" title="' . esc_attr(sprintf(__('Check compatibility status for "%s" plugin', 'installer'), $name)) . '">' . __('Check compatibility', 'installer') . '</a>';
            $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin);
            if (!isset($plugin['num_ratings']) || empty($plugin['num_ratings'])) {
                $plugin['num_ratings'] = 0;
            }
            if (!isset($plugin['rating']) || empty($plugin['rating'])) {
                $plugin['rating'] = 0;
            }
            ?>
		<tr>
			<td class="name column-name"<?php 
            echo $style['name'];
            ?>
><strong><?php 
            echo $title;
            ?>
</strong>
				<div class="action-links"><?php 
            if (!empty($action_links)) {
                echo implode(' | ', $action_links);
            }
            ?>
</div>
			</td>
			<td class="vers column-version"<?php 
            echo $style['version'];
            ?>
><?php 
            echo $version;
            ?>
</td>
			<td class="vers column-rating"<?php 
            echo $style['rating'];
            ?>
>
				<?php 
            global $wp_version;
            if (version_compare($wp_version, "3.4", "<")) {
                ?>
				<div class="star-holder" title="<?php 
                printf(_n('(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings'], 'installer'), number_format_i18n(intval($plugin['num_ratings'])));
                ?>
">
					<div class="star star-rating" style="width: <?php 
                echo esc_attr($plugin['rating']);
                ?>
px"></div>
					<?php 
                $color = get_user_option('admin_color');
                if (empty($color) || 'fresh' == $color) {
                    $star_url = admin_url('images/gray-star.png?v=20110615');
                } else {
                    $star_url = admin_url('images/star.png?v=20110615');
                }
                // 'Classic' Blue star
                ?>
					<div class="star star5"><img src="<?php 
                echo $star_url;
                ?>
" alt="<?php 
                esc_attr_e('5 stars');
                ?>
" /></div>
					<div class="star star4"><img src="<?php 
                echo $star_url;
                ?>
" alt="<?php 
                esc_attr_e('4 stars');
                ?>
" /></div>
					<div class="star star3"><img src="<?php 
                echo $star_url;
                ?>
" alt="<?php 
                esc_attr_e('3 stars');
                ?>
" /></div>
					<div class="star star2"><img src="<?php 
                echo $star_url;
                ?>
" alt="<?php 
                esc_attr_e('2 stars');
                ?>
" /></div>
					<div class="star star1"><img src="<?php 
                echo $star_url;
                ?>
" alt="<?php 
                esc_attr_e('1 star');
                ?>
" /></div>
				</div>
			<?php 
            } else {
                ?>
				<div class="star-holder" title="<?php 
                printf(_n('(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings'], 'installer'), number_format_i18n(intval($plugin['num_ratings'])));
                ?>
">
					<div class="star star-rating" style="width: <?php 
                echo esc_attr(str_replace(',', '.', $plugin['rating']));
                ?>
px"></div>
				</div>
			<?php 
            }
            ?>
			</td>
			<td class="desc column-description"<?php 
            echo $style['description'];
            ?>
><?php 
            echo $description, $author;
            ?>
</td>
            <td class="source column-source" align="left"><?php 
            echo $plugin_source;
            ?>
</td>
            <td class="price column-price" align="left"><?php 
            echo $plugin_price;
            ?>
</td>
		</tr>
		<?php 
        }
    }
 public static function wprc_plugin_update_row($file, $plugin_data)
 {
     $current = get_site_transient('update_plugins');
     if (!isset($current->response[$file])) {
         return false;
     }
     $r = $current->response[$file];
     $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array()), 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), 'code' => array(), 'em' => array(), 'strong' => array());
     $plugin_name = wp_kses($plugin_data['Name'], $plugins_allowedtags);
     if (isset($r->repository_id)) {
         $details_url = self_admin_url('plugin-install.php?tab=plugin-information&repository_id=' . $r->repository_id . '&plugin=' . $r->slug . '&section=changelog&TB_iframe=true&width=640&height=484');
     } else {
         $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&section=changelog&TB_iframe=true&width=640&height=484');
     }
     $wp_list_table = _get_list_table('WP_Plugins_List_Table');
     if (is_network_admin() || !is_multisite()) {
         echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
         if (!current_user_can('update_plugins')) {
             printf(__('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>.', 'installer'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version);
         } else {
             if (empty($r->package)) {
                 $ext_model = WPRC_Loader::getModel('extensions');
                 $repository = $ext_model->get_extension_repository($file);
                 $nonce_login = wp_create_nonce('installer-login-link');
                 if (!empty($repository)) {
                     printf(__('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. To update this plugin, first <a class="thickbox" href="%5$s">log-in to %6$s</a>.', 'installer'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, admin_url('admin.php?wprc_c=repository-login&amp;wprc_action=RepositoryLogin&amp;repository_id=' . $repository->id . '&amp;_wpnonce=' . $nonce_login), $repository->repository_name);
                 } else {
                     printf(__('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>', 'installer'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version);
                 }
             } else {
                 printf(__('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update now</a>.', 'installer'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=') . $file, 'upgrade-plugin_' . $file));
             }
         }
         //if ( empty($r->package) )
         //{
         /*if (isset($r->message) && !empty($r->message))
         		{
         				echo '<br /> '.wp_kses($r->message, $plugins_allowedtags);
         		}*/
         if (isset($r->message) && !empty($r->message)) {
             $message = WPRC_Functions::formatMessage($r->message);
             if (isset($r->message_type) && $r->message_type == 'notify') {
                 WPRC_AdminNotifier::addMessage('wprc-plugin-info-' . $r->slug, $message);
             } else {
                 echo $message;
             }
         } else {
             if (isset($r->repository_id) && isset($r->purchase) && !empty($r->purchase) && isset($r->price) && !empty($r->price)) {
                 echo '<br /> ';
                 $purl = WPRC_Functions::sanitizeURL($r->purchase);
                 $return_url = rawurlencode(admin_url('plugin-install.php?tab=plugin-information&repository_id=' . $r->repository_id . '&plugin=' . $r->slug));
                 $salt = rawurlencode($r->repository_salt);
                 if (strpos($purl, '?')) {
                     $url_glue = '&';
                 } else {
                     $url_glue = '?';
                 }
                 $purl .= $url_glue . 'return_to=' . $return_url . '&rsalt=' . $salt;
                 echo '<a href="' . $purl . '&TB_iframe=true&width=640&height=484' . '" class="thickbox" title="' . sprintf(__('Upgrade %s', 'installer'), '(' . $r->currency->symbol . $r->price . ' ' . $r->currency->name . ')') . '">' . sprintf(__('Upgrade %s', 'installer'), '(' . $r->currency->symbol . $r->price . ' ' . $r->currency->name . ')') . '</a>';
             }
         }
         //}
         do_action("in_plugin_update_message-{$file}", $plugin_data, $r);
         echo '</div></td></tr>';
     }
 }
 public static function wprc_update_extensions_maps()
 {
     WPRC_Loader::getRepositoryConnector();
     $url = WPRC_UPDATE_REPOS_URL;
     $timestamp = 0;
     $current = get_transient('wprc_update_extensions_maps');
     if (isset($current) && $current != false) {
         if (isset($current->last_checked)) {
             $timestamp = $current->last_checked;
         }
     }
     $args = array('action' => 'extensions_map', 'request' => array('timestamp' => $timestamp));
     // get existing extensions list
     $em = WPRC_Loader::getModel('extensions');
     $ext = $em->getFullExtensionsTree();
     $extensions = array();
     $ext_map = array();
     foreach (array('plugins', 'themes') as $etype) {
         $extensions[$etype] = array();
         foreach ($ext[$etype] as $exte) {
             $tmp = (array) $exte;
             if (isset($tmp['Name'])) {
                 $extensions[$etype][] = $tmp['Name'];
                 $ext_map[$etype][$tmp['Name']] = $tmp;
             } elseif (isset($tmp['name'])) {
                 $extensions[$etype][] = $tmp['name'];
                 $ext_map[$etype][$tmp['name']] = $tmp;
             }
         }
         $args['request'][$etype] = $extensions[$etype];
         unset($extensions[$etype]);
         unset($ext[$etype]);
     }
     // send request for info
     $response = WPRC_RepositoryConnector::sendRequest('post', $url, $args);
     if (isset($response) && $response != false && !is_wp_error($response)) {
         if (isset($response->result)) {
             if ($response->result == 'up_to_date') {
                 $current = new stdClass();
                 $current->last_checked = time();
                 $current->count = 0;
                 set_transient('wprc_update_extensions_maps', $current);
                 return false;
             } else {
                 $repo_model = WPRC_Loader::getModel('repositories');
                 $installed_repos = $repo_model->getAllRepositories();
                 $repo_map = array();
                 foreach ($installed_repos as $repo) {
                     $repo_map[$repo->repository_endpoint_url] = $repo->id;
                 }
                 unset($installed_repos);
                 $ext_count = 0;
                 foreach (array('plugins', 'themes') as $etype) {
                     if (isset($response->{$etype})) {
                         $tmp = (array) $response->{$etype};
                         foreach ($tmp as $name => $einfo) {
                             $einfo = (array) $einfo;
                             if (isset($ext_map[$etype]) && isset($ext_map[$etype][$name])) {
                                 if (isset($ext_map[$etype][$name]['repository_id'])) {
                                     if (isset($repo_map[$einfo['repository_url']])) {
                                         $type_id = $einfo['extension_type'] == 1 ? 1 : 2;
                                         $data = array('extension_name' => $einfo['extension_name'], 'extension_type_id' => $type_id, 'extension_slug' => $einfo['extension_slug'], 'extension_path' => $einfo['extension_path'], 'repository_id' => $repo_map[$einfo['repository_url']], 'extension_was_installed' => 1);
                                         $format = array('%s', '%d', '%s', '%s', '%d', '%d');
                                         $where = array('extension_name' => $name);
                                         $where_format = array('%s');
                                         $em->updateExtension($data, $where, $format, $where_format);
                                         $ext_count++;
                                     }
                                 } else {
                                     if (isset($repo_map[$einfo['repository_url']])) {
                                         $type_name = $einfo['extension_type'] == 1 ? 'plugins' : 'themes';
                                         $em->addExtensionInstalled($name, $einfo['extension_slug'], $einfo['extension_path'], $type_name, $repo_map[$einfo['repository_url']], 1);
                                         $ext_count++;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $current = new stdClass();
                 $current->last_checked = time();
                 $current->count = $ext_count;
                 set_transient('wprc_update_extensions_maps', $current);
                 return $ext_count;
             }
         }
     }
 }
Beispiel #17
0
}
$result = '';
$result_msg = '';
if (array_key_exists('result', $_GET)) {
    $result = $_GET['result'];
    switch ($result) {
        case 'success':
            $result_msg = __('Settings are saved', 'installer');
            break;
        case 'failure':
            // $result_msg = __('Settings are not saved. Change a values of the settings please', 'installer');
            $result_msg = __('Settings are saved', 'installer');
            break;
    }
}
$settings_model = WPRC_Loader::getModel('settings');
$settings = $settings_model->getSettings();
$show_msg = '';
if (array_key_exists('warning', $_GET)) {
    $show_msg = $_GET['warning'];
}
$msg = '';
switch ($show_msg) {
    case 'https_not_provided':
        $msg = __('HTTPS is not provided by server. Please connect with your site administrator', 'installer');
        break;
}
?>

<div class="wrap">
	<h2><?php 
 public function getCorrectWorkReportStatus()
 {
     echo '<h1 align="center">getCorrectWorkReportStatus</h1>';
     $cwr = WPRC_Loader::getRequester('correct-work-reporter');
     $cwr->getStatus();
 }
 /**
  * Search plugins in multiple repositories 
  * This method replaces 'plugins_api' and 'themes_api' function
  */
 public function extensionsApi($state, $action, $args, $extension_type)
 {
     // default wp behaviour for tabs other than search
     //if ($action=='hot_tags') return false;
     if (isset($_GET['tab'])) {
         if ($_GET['tab'] != 'dashboard' && $_GET['tab'] != 'search' && $_GET['tab'] != 'plugin-information' && $_GET['tab'] != 'theme-information') {
             return false;
         }
     }
     $rauth = true;
     $rpass = '';
     $ruser = '';
     if (isset($_GET['repository_id']) && isset($_GET['user']) && isset($_GET['pass']) && ($action == 'plugin_information' || $action == 'theme_information')) {
         $rm = WPRC_Loader::getModel('repositories');
         $rid = $_GET['repository_id'];
         $repository = $rm->getRepository($rid);
         $ruser = rawurldecode($_GET['user']);
         $rsalt = $repository->repository_authsalt;
         $rpass = rawurldecode($_GET['pass']);
         //WPRC_Security::decrypt($repository->repository_authsalt,rawurldecode($_GET['pass']));
         $login = $rm->testLogin($rid, $ruser, $rpass);
         if ($login != false && empty($login['error'])) {
             $rauth = true;
         } else {
             $rauth = false;
         }
     }
     $repositories_ids = array();
     if (isset($args->repositories)) {
         $repositories_ids = $args->repositories;
         unset($args->repositories);
     }
     $rm = WPRC_Loader::getModel('repositories');
     $repos = $rm->getRepositoriesByIds($repositories_ids);
     $results = array();
     // Remade per_page parameters in order to get consistent pagination
     $per_page = 0;
     $repos_number = count($repos);
     if ($action == 'query_plugins') {
         $per_page = WPRC_PLUGINS_API_QUERY_PLUGINS_PER_PAGE;
     } elseif ($action == 'query_themes') {
         $per_page = WPRC_THEMES_API_QUERY_THEMES_PER_PAGE;
     }
     $results_per_repo = array();
     for ($i = 0; $i < $repos_number; $i++) {
         $res = false;
         $server_url = $repos[$i]->repository_endpoint_url;
         $repository_name = $repos[$i]->repository_name;
         $repository_username = $repos[$i]->repository_username;
         $repository_password = $repos[$i]->repository_password;
         $salt = $repos[$i]->repository_authsalt;
         $rid = $repos[$i]->id;
         $body_array = array('action' => $action);
         if ($repository_username != '' && $repository_password != '') {
             /*$args->username = $repository_username;
               $args->password = $repository_password;*/
             //$send_password=WPRC_Security::encrypt($salt,$repository_password);
             $body_array['auth'] = array('user' => $repository_username, 'pass' => $repository_password, 'salt' => $salt);
             //$body_array['auth'] = array('user'=>$repository_username,'pass'=>$repository_password,'salt'=>$salt);
         } else {
             unset($args->username);
             unset($args->password);
         }
         $request_array = $args;
         $request_array->per_page = $per_page;
         $body_array['request'] = serialize($args);
         if (isset($args->slug)) {
             $body_array['slug'] = $args->slug;
         }
         // debug log
         $reqargs = $body_array;
         if (isset($reqargs['auth'])) {
             $reqargs['auth'] = 'AUTH info';
         }
         $msg = sprintf("API Request to %s, request args: %s", $server_url, print_r($reqargs, true));
         WPRC_Functions::log($msg, 'api', 'api.log');
         unset($reqargs);
         $cached_request_results = apply_filters('wprc_extensions_api_before_each_repository', $server_url, $action, $args);
         if ($cached_request_results) {
             $results[$server_url] = $cached_request_results;
             // log
             $msg = sprintf("API Request to %s, using cached results", $server_url);
             WPRC_Functions::log($msg, 'api', 'api.log');
             continue;
         }
         $request = wp_remote_post($server_url, array('timeout' => 15, 'body' => $body_array));
         // log
         $msg = sprintf("API Request to %s, timeout: %d, response: %s", $server_url, 15, print_r($request, true));
         WPRC_Functions::log($msg, 'api', 'api.log');
         if (is_wp_error($request)) {
             $res = new WP_Error('extensions_api_failed', __('An unexpected HTTP Error occurred during the API request.', 'installer'), $request->get_error_message());
             // log
             $msg = sprintf("API Request to %s, response error: %s", $server_url, print_r($request->get_error_message(), true));
             WPRC_Functions::log($msg, 'api', 'api.log');
         } else {
             $request_body = wp_remote_retrieve_body($request);
             if (is_serialized($request_body)) {
                 $res = @unserialize($request_body);
             }
             if (false === $res) {
                 $res = new WP_Error('extensions_api_failed', __('An unknown error occurred.', 'installer'), wp_remote_retrieve_body($request));
                 // log
                 $msg = sprintf("API Request to %s, unknown error in response body: %s", $server_url, print_r($request_body, true));
                 WPRC_Functions::log($msg, 'api', 'api.log');
             } else {
                 if (is_object($res) && isset($res->error)) {
                     $res = new WP_Error('extensions_api_failed', $res->error, wp_remote_retrieve_body($request));
                     // log
                     $msg = sprintf("API Request to %s, action not implemented error: %s", $server_url, print_r($res, true));
                     WPRC_Functions::log($msg, 'api', 'api.log');
                 } else {
                     if (is_array($res) && isset($res['error'])) {
                         $res = new WP_Error('extensions_api_failed', $res['error'], wp_remote_retrieve_body($request));
                         // log
                         $msg = sprintf("API Request to %s, action not implemented error: %s", $server_url, print_r($res, true));
                         WPRC_Functions::log($msg, 'api', 'api.log');
                     } else {
                         // add some custom info onto the results (like repository salt etc..)
                         if ($action == 'query_plugins') {
                             foreach ($res->plugins as $key => $extension) {
                                 $res->plugins[$key]->salt = $salt;
                                 $res->plugins[$key]->repository_id = $rid;
                                 // strip non-serializable characters
                                 $res->plugins[$key]->description = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x80-\\xFF]/u', '', $res->plugins[$key]->description);
                             }
                         } elseif ($action == 'query_themes') {
                             foreach ($res->themes as $key => $extension) {
                                 $res->themes[$key]->salt = $salt;
                                 $res->themes[$key]->repository_id = $rid;
                                 // strip non-serializable characters
                                 $res->themes[$key]->description = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x80-\\xFF]/u', '', $res->themes[$key]->description);
                             }
                         } elseif ($action == 'plugin_information' || $action == 'theme_information') {
                             if (is_object($res)) {
                                 $res->rauth = $rauth;
                                 $res->pass = $rpass;
                                 $res->user = $ruser;
                                 $res->salt = $salt;
                                 $res->repository_id = $rid;
                             }
                         }
                     }
                 }
             }
         }
         $cached_them = apply_filters('wprc_extensions_api_after_each_repository', $server_url, $action, $args, $res);
         // log
         $msg = sprintf("API Request to %s, results cached: %s", $server_url, $cached_them == false ? 'NO' : 'YES');
         WPRC_Functions::log($msg, 'api', 'api.log');
         // set source
         $results[$server_url] = $res;
     }
     $general_results = new stdClass();
     $general_results->results = $results;
     return $general_results;
 }
Beispiel #20
0
function wprc_filter_uber_alles()
{
    global $wprc_plugins_api, $wprc_themes_api, $wprc_rc;
    wprc_disable_filters_for('plugins_api_args');
    wprc_disable_filters_for('plugins_api');
    wprc_disable_filters_for('plugins_api_result');
    wprc_disable_filters_for('themes_api_args');
    wprc_disable_filters_for('themes_api');
    wprc_disable_filters_for('themes_api_result');
    /*
    // remove views upgrade filter
    remove_filter('pre_set_site_transient_update_plugins', 'check_for_views_plugin_updates');
    */
    // remove wpml upgrade filter
    remove_filter('pre_set_site_transient_update_plugins', 'check_for_WPML_plugin_updates');
    // remove all pre transient update filters ??
    //wprc_disable_filters_for('pre_set_site_transient_update_plugins');
    //wprc_disable_filters_for('pre_set_site_transient_update_themes');
    add_filter('plugins_api_args', array($wprc_plugins_api, 'extensionsApiArgs'), 1, 2);
    add_filter('plugins_api', array($wprc_plugins_api, 'extensionsApi'), 1, 3);
    add_filter('plugins_api_result', array($wprc_plugins_api, 'extensionsApiResult'), 1, 3);
    add_filter('themes_api_args', array($wprc_themes_api, 'extensionsApiArgs'), 1, 2);
    add_filter('themes_api', array($wprc_themes_api, 'extensionsApi'), 1, 3);
    add_filter('themes_api_result', array($wprc_themes_api, 'extensionsApiResult'), 1, 3);
    // for details and update info on our repositories
    remove_action('install_plugins_pre_plugin-information', 'install_plugin_information');
    add_action('install_plugins_pre_plugin-information', array($wprc_rc, 'wprc_install_plugin_information'));
    remove_action('install_themes_pre_theme-information', 'install_theme_information');
    add_action('install_themes_pre_theme-information', array($wprc_rc, 'wprc_install_theme_information'));
    //remove_action('wp_ajax_fetch-list','wp_ajax_fetch_list');
    //add_action('wp_ajax_fetch-list','wprc_ajax_fetch_list');
    WPRC_Loader::includeExtensionsApi();
    add_action('wp_ajax_clear-extension-search-cache', array('WPRC_Extensions_API', 'clear_extension_search_cache'));
}
 public function clearLoginInfo($get, $post)
 {
     $msg = sprintf('Repositories clear login enter');
     WPRC_Functions::log($msg, 'controller', 'controller.log');
     if (isset($get['repository_id'])) {
         //$nonce=$get['_wpnonce'];
         if (!array_key_exists('_wpnonce', $get) || !wp_verify_nonce($get['_wpnonce'], 'installer-clear-link')) {
             die("Security check");
         }
         if (!array_key_exists('repository_id', $get)) {
             die;
         }
         $model = WPRC_Loader::getModel('repositories');
         $result = $model->clearLogin(intval($get['repository_id']));
         if ($result) {
             // clear cache
             $rmcache = WPRC_Loader::getModel('cached-requests');
             $rmcache->cleanCache();
             // clear updates
             delete_site_transient('update_themes');
             delete_site_transient('update_plugins');
         }
         echo json_encode(array('result' => $result));
     }
     $msg = sprintf('Repositories clear login completed');
     WPRC_Functions::log($msg, 'controller', 'controller.log');
     exit;
 }
 /**
  * Reset plugin timer
  * 
  * This method should be called on 'deactivate_plugin' hook
  * 
  * @param string plugin name
  */
 public function resetPluginTimer($plugin_name)
 {
     WPRC_Loader::includeExtensionTimer();
     WPRC_ExtensionTimer::deleteTimer($plugin_name);
 }
 public function __construct()
 {
     $rc = WPRC_Loader::getRepositoryConnector();
     $this->RepositoryConnector = $rc;
 }
 public function addExtensionInstalled($extension_name, $extension_slug, $extension_path, $extension_type, $repository_id, $ext_was_installed)
 {
     // get extension type id
     $et_model = WPRC_Loader::getModel('extension-types');
     $types = $et_model->getExtensionTypesList();
     if (!array_key_exists($extension_type, $types)) {
         return false;
     }
     $extension_type_id = $types[$extension_type]['id'];
     $extension_exists = $this->isExtensionExists($extension_slug, $extension_type_id, $repository_id);
     // insert extension
     $insert_array = array('extension_name' => $extension_name, 'extension_slug' => $extension_slug, 'extension_path' => $extension_path, 'extension_type_id' => $extension_type_id, 'repository_id' => $repository_id, 'extension_was_installed' => $ext_was_installed);
     $insert_format_array = array('%s', '%s', '%s', '%d', '%d', '%d');
     $where = array('extension_name' => $extension_name);
     $where_format = array('%s');
     if ($extension_exists) {
         return $this->wpdb->update($this->table_name, $insert_array, $where, $insert_format_array, $where_format);
     }
     return $this->wpdb->insert($this->table_name, $insert_array, $insert_format_array);
 }
 public static function wprc_update_themes()
 {
     global $wp_version;
     $WP_UPDATE_THEMES_URL = WPRC_WP_THEMES_UPDATE_REPO;
     //include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
     if (defined('WP_INSTALLING')) {
         return false;
     }
     //if ( !function_exists( 'get_themes' ) )
     //require_once( ABSPATH . 'wp-includes/theme.php' );
     //$installed_themes = get_themes( );
     $last_update = get_site_transient('update_themes');
     if (!is_object($last_update)) {
         $last_update = new stdClass();
     }
     // Check for updated every 60 minutes if hitting update pages; else, check every 12 hours.
     $timeout = in_array(current_filter(), array('load-themes.php', 'load-update.php', 'load-update-core.php')) ? 3600 : 43200;
     $time_not_changed = isset($last_update->last_checked) && $timeout > time() - $last_update->last_checked;
     //$themes = array();
     $checked = array();
     $exclude_fields = array('Template Files', 'Stylesheet Files', 'Status', 'Theme Root', 'Theme Root URI', 'Template Dir', 'Stylesheet Dir', 'Description', 'Tags', 'Screenshot');
     // Put slug of current theme into request.
     //$themes['current_theme'] = get_option( 'stylesheet' );
     // get themes data from the DB
     $extensions_model = WPRC_Loader::getModel('extensions');
     $extensions = $extensions_model->getFullExtensionsTree();
     $installed_themes = $extensions['themes'];
     // arrange themes according to repository (if enabled)
     $repos = array();
     $current_theme = get_option('stylesheet');
     foreach ($installed_themes as $key => $theme) {
         $checked[$theme['Stylesheet']] = $theme['Version'];
         $rkey = $theme['repository_endpoint_url'] === null ? WPRC_WP_THEMES_REPO : $theme['repository_endpoint_url'];
         $sendtheme = $theme;
         // remove unwanted fields from the theme that is going to be sent
         unset($sendtheme['repository_endpoint_url']);
         unset($sendtheme['repository_id']);
         unset($sendtheme['repository_user']);
         unset($sendtheme['repository_pass']);
         unset($sendtheme['repository_salt']);
         unset($sendtheme['repository_name']);
         unset($sendtheme['repository_enabled']);
         unset($sendtheme['repository_deleted']);
         unset($sendtheme['extension_was_installed']);
         unset($sendtheme['type_name']);
         unset($sendtheme['extension_slug']);
         foreach ((array) $theme as $key2 => $value) {
             if (in_array($key2, $exclude_fields)) {
                 unset($sendtheme[$key2]);
             }
         }
         if (!isset($repos[$rkey])) {
             $repos[$rkey] = array('id' => $theme['repository_id'], 'url' => $rkey, 'user' => $theme['repository_user'], 'pass' => $theme['repository_pass'], 'salt' => $theme['repository_salt'], 'name' => $theme['repository_name'], 'themes' => array('current_theme' => $current_theme, $sendtheme['Stylesheet'] => $sendtheme));
             // Wordpress uses different install repository URL from Update Repository URL so hardcode it
             if ($rkey === WPRC_WP_THEMES_REPO) {
                 $repos[$rkey]['url'] = $WP_UPDATE_THEMES_URL;
             }
         } else {
             $repos[$rkey]['themes'][$sendtheme['Stylesheet']] = $sendtheme;
         }
     }
     $theme_changed = false;
     foreach ($checked as $slug => $v) {
         $update_request->checked[$slug] = $v;
         if (!isset($last_update->checked[$slug]) || strval($last_update->checked[$slug]) !== strval($v)) {
             $theme_changed = true;
         }
     }
     if (isset($last_update->response) && is_array($last_update->response)) {
         foreach ($last_update->response as $slug => $update_details) {
             if (!isset($checked[$slug])) {
                 $theme_changed = true;
                 break;
             }
         }
     }
     if ($time_not_changed && !$theme_changed) {
         return false;
     }
     // Update last_checked for current to prevent multiple blocking requests if request hangs
     $last_update->last_checked = time();
     set_site_transient('update_themes', $last_update);
     $allresponses = array();
     //WPRC_Loader::includeSecurity();
     foreach ($repos as $repo) {
         $to_send = $repo['themes'];
         $server_url = $repo['url'];
         $repository_username = $repo['user'];
         $repository_password = $repo['pass'];
         $repository_salt = $repo['salt'];
         // action is themes-update by default
         $body_array = array('action' => 'themes_update');
         // add authorization if needed
         if ($repository_username != '' && $repository_username != null && $repository_password != '' && $repository_password != null) {
             //$sendpassword=WPRC_Security::encrypt($repository_salt,$repository_password);
             $body_array['auth'] = array('user' => $repository_username, 'pass' => $repository_password, 'salt' => $repository_salt);
         } else {
             unset($body_array['auth']);
         }
         $body_array['themes'] = serialize($to_send);
         if ($server_url === $WP_UPDATE_THEMES_URL) {
             unset($body_array['action']);
         }
         $options = array('timeout' => defined('DOING_CRON') && DOING_CRON ? 30 : 3, 'body' => $body_array, 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
         // debug log
         $reqargs = $body_array;
         if (isset($reqargs['auth'])) {
             $reqargs['auth'] = 'AUTH info';
         }
         $msg = sprintf("THEME UPDATE API Request to %s, timeout: %d, wpversion: %s, request args: %s", $server_url, $options['timeout'], $wp_version, print_r($reqargs, true));
         WPRC_Functions::log($msg, 'api', 'api.log');
         unset($reqargs);
         // send request
         $raw_response = wp_remote_post($server_url, $options);
         // log
         $msg = sprintf("THEME UPDATE API Request to %s, response: %s", $server_url, print_r($raw_response, true));
         WPRC_Functions::log($msg, 'api', 'api.log');
         if (is_wp_error($raw_response) || 200 != wp_remote_retrieve_response_code($raw_response)) {
             // log
             if (is_wp_error($raw_response)) {
                 $msg = sprintf("THEME UPDATE API Request to %s, response error: %s", $server_url, print_r($raw_response->get_error_message(), true));
                 WPRC_Functions::log($msg, 'api', 'api.log');
             }
             continue;
             //return false;
         }
         $response = @unserialize(wp_remote_retrieve_body($raw_response));
         // merge with other results
         if (false === $response) {
             // log
             $msg = sprintf("THEME UPDATE API Request to %s, response unserialize failed: %s", $server_url, print_r(wp_remote_retrieve_body($raw_response), true));
             WPRC_Functions::log($msg, 'api', 'api.log');
         } else {
             if (is_object($response) && isset($response->error)) {
                 $response = new WP_Error('extensions_api_failed', $response->error, wp_remote_retrieve_body($raw_response));
                 // log
                 $msg = sprintf("THEME UPDATE API Request to %s, action not implemented error: %s", $server_url, print_r($response, true));
                 WPRC_Functions::log($msg, 'api', 'api.log');
             } else {
                 if (is_array($response) && isset($response['error'])) {
                     $response = new WP_Error('extensions_api_failed', $response['error'], wp_remote_retrieve_body($raw_response));
                     // log
                     $msg = sprintf("THEME UPDATE API Request to %s, action not implemented error: %s", $server_url, print_r($response, true));
                     WPRC_Functions::log($msg, 'api', 'api.log');
                 } else {
                     // add some info about repository id etc..
                     foreach ($response as $key => $them) {
                         if (is_object($response[$key])) {
                             $response[$key]->repository_id = $repo['id'];
                             $response[$key]->repository_salt = $repo['salt'];
                         } else {
                             if (is_array($response[$key])) {
                                 $response[$key]['repository_id'] = $repo['id'];
                                 $response[$key]['repository_salt'] = $repo['salt'];
                             }
                         }
                         $response[$key] = (array) $response[$key];
                     }
                     $allresponses = array_merge($allresponses, $response);
                 }
             }
         }
     }
     // update transients for themes
     $new_update = new stdClass();
     $new_update->last_checked = time();
     $new_update->checked = $checked;
     $new_update->response = $allresponses;
     set_site_transient('update_themes', $new_update);
 }
<?php

if (!defined('ABSPATH')) {
    die('Security check');
}
// prepare fields values for the form in the template
$site_id = WPRC_Installer::getSiteId();
// get lists of extensions
$em = WPRC_Loader::getModel('extensions');
$extension_keys = array();
$bulk_deactivate = 0;
$bulk_data = array();
// get extenstions to deactivate
if (array_key_exists('checked', $_POST)) {
    // bulk deactivation
    // bulk deactivation accessible for plugins only
    $extension_type = 'plugin';
    $extension_keys = $_POST['checked'];
    $bulk_deactivate = 1;
    $bulk_data['_wpnonce'] = $_POST['_wpnonce'];
    $bulk_data['_wp_http_referer'] = $_POST['_wp_http_referer'];
    $bulk_data['checked'] = $_POST['checked'];
    $bulk_data['action'] = $_POST['action'];
    $bulk_data['action2'] = $_POST['action2'];
    $url = admin_url('plugins.php');
} else {
    // single extension deactivation
    $url = $_SERVER['REQUEST_URI'];
    $extension = WPRC_UrlAnalyzer::getExtensionFromUrl($url);
    $extension_type = $extension['type'];
    $extension_path = $extension['name'];
 public function __construct()
 {
     $this->model = WPRC_Loader::getModel('cached-requests');
 }
 function testLogin($repository_id, $username, $password, $plain = false)
 {
     //$rm = $this->repo_model;//WPRC_Loader::getModel('repositories');
     $repo = $this->getRepositoryByField('id', $repository_id);
     $body_array = array('action' => 'repository_login');
     $salt = $repo->repository_authsalt;
     //WPRC_Loader::includeSecurity();
     //$body_array['auth'] = array('user'=>$username,'pass'=>WPRC_Security::encrypt($salt,$password),'salt'=>$salt);
     $body_array['auth'] = array('user' => $username, 'pass' => $password, 'salt' => $salt);
     if ($plain) {
         $body_array['auth']['_plain'] = 'true';
     }
     // log
     if (!$plain) {
         $msg = sprintf('Repository Login to %s with auth, timeout: %d, action: %s', $repo->repository_endpoint_url, 5, $body_array['action']);
     } else {
         $msg = sprintf('Repository Login to %s with auth plain, timeout: %d, action: %s', $repo->repository_endpoint_url, 5, $body_array['action']);
     }
     WPRC_Functions::log($msg, 'controller', 'controller.log');
     $request = wp_remote_post($repo->repository_endpoint_url, array('timeout' => 15, 'body' => $body_array));
     // log
     $msg = sprintf('Repository Login to %s with auth, response: %s', $repo->repository_endpoint_url, print_r($request, true));
     WPRC_Functions::log($msg, 'controller', 'controller.log');
     if (is_wp_error($request)) {
         $res = new WP_Error('repository_login_failed', __('An unexpected HTTP Error occurred during the API request.', 'installer'), $request->get_error_message());
         // log
         $msg = sprintf('Repository Login to %s with auth, response error: %s', $repo->repository_endpoint_url, print_r($request->get_error_message()));
         WPRC_Functions::log($msg, 'controller', 'controller.log');
     } else {
         $request_body = wp_remote_retrieve_body($request);
         if (is_serialized($request_body)) {
             $res = @unserialize($request_body);
         }
     }
     if (!isset($res) || $res == false || is_wp_error($res)) {
         // log
         $msg = sprintf('Repository Login to %s with auth, response unserialize error: %s', $repo->repository_endpoint_url, print_r(wp_remote_retrieve_body($request)));
         WPRC_Functions::log($msg, 'controller', 'controller.log');
         return false;
     }
     if (isset($res->error) && !isset($res->success)) {
         $response = array('error' => 1, 'message' => $res->error);
     } else {
         $response = array('error' => 0, 'message' => $res->success);
         $doupdate = false;
         if ($plain && isset($res->pass) && $res->pass != '') {
             $password = $res->pass;
             $doupdate = true;
         }
         if (!$plain) {
             $doupdate = true;
         }
         if ($doupdate) {
             $this->updateRepositoryAuth($repository_id, $username, $password);
             // clear cache
             $rmcache = WPRC_Loader::getModel('cached-requests');
             $rmcache->cleanCache();
             // clear update data
             delete_site_transient('update_plugins');
             delete_site_transient('update_themes');
         }
     }
     return $response;
 }