Пример #1
0
function update_notificiations_check()
{
    if (is_site_admin()) {
        $last_run = get_site_option('wdp_un_last_run');
        $now = time();
        if (empty($last_run)) {
            //first run
            update_notificiations_process();
            update_site_option('wdp_un_last_run', $now);
        } else {
            $time_ago = $now - $last_run;
            if ($time_ago > 43200) {
                //if ( $time_ago > 1 ) {
                update_notificiations_process();
                update_site_option('wdp_un_last_run', $now);
            }
        }
    }
}
function update_notificiations_page_output()
{
    global $wpdb, $current_site, $update_notificiations_version, $update_notificiations_server_url;
    if (!current_user_can('edit_users')) {
        echo "<p>Nice Try...</p>";
        //If accessed properly, this message doesn't appear.
        return;
    }
    if (isset($_GET['updated'])) {
        ?>
<div id="message" class="updated fade"><p><?php 
        _e('' . urldecode($_GET['updatedmsg']) . '');
        ?>
</p></div><?php 
    }
    if ($_GET['action'] == 'process') {
        update_site_option('wdp_un_enable_admin_notices', $_POST['enable_admin_notices']);
    }
    if ($_GET['action'] == 'update') {
        if (is_site_admin()) {
            $last_run = get_site_option('wdp_un_last_run');
            $now = time();
            if (empty($last_run)) {
                //first run
                update_notificiations_process();
                update_site_option('wdp_un_last_run', $now);
            } else {
                $time_ago = $now - $last_run;
                update_notificiations_process();
                update_site_option('wdp_un_last_run', $now);
            }
        }
    }
    echo '<div class="wrap">';
    switch ($_GET['action']) {
        //---------------------------------------------------//
        default:
            $data = get_site_option('wdp_un_last_response');
            $last_run = get_site_option('wdp_un_last_run');
            ?>
			<h2><?php 
            _e('WPMU DEV');
            ?>
</h2>
            <p><?php 
            echo stripslashes(get_site_option('wdp_un_text_page_head'));
            ?>
</p>
			<h3><?php 
            _e('Recently Released Plugins');
            ?>
</h3>
            <?php 
            echo "\n\t\t\t<table cellpadding='3' cellspacing='3' width='100%' class='widefat'> \n\t\t\t<thead><tr>\n\t\t\t<th scope='col'>Name</th>\n\t\t\t<th scope='col'>Description</th>\n\t\t\t</tr></thead>\n\t\t\t<tbody id='the-list'>\n\t\t\t";
            $latest_plugins = array();
            if (is_array($data)) {
                $latest_plugins = $data['latest_plugins'];
            }
            if (count($latest_plugins) > 0) {
                $class = 'alternate' == $class ? '' : 'alternate';
                foreach ($latest_plugins as $latest_plugin) {
                    //=========================================================//
                    echo "<tr class='" . $class . "'>";
                    echo "<td valign='top'><strong><a target='_blank' href='" . $latest_plugin['url'] . "'>" . stripslashes($latest_plugin['title']) . "</a></strong></td>";
                    echo "<td valign='top'>" . stripslashes($latest_plugin['short_description']) . "</td>";
                    echo "</tr>";
                    $class = 'alternate' == $class ? '' : 'alternate';
                    //=========================================================//
                }
            }
            ?>
			</tbody></table>
			<h3><?php 
            _e('Recently Released Themes');
            ?>
</h3>
            <?php 
            echo "\n\t\t\t<table cellpadding='3' cellspacing='3' width='100%' class='widefat'> \n\t\t\t<thead><tr>\n\t\t\t<th scope='col'>Name</th>\n\t\t\t<th scope='col'>Description</th>\n\t\t\t</tr></thead>\n\t\t\t<tbody id='the-list'>\n\t\t\t";
            $latest_themes = array();
            if (is_array($data)) {
                $latest_themes = $data['latest_themes'];
            }
            if (count($latest_themes) > 0) {
                $class = 'alternate' == $class ? '' : 'alternate';
                foreach ($latest_themes as $latest_theme) {
                    //=========================================================//
                    echo "<tr class='" . $class . "'>";
                    echo "<td valign='top'><strong><a target='_blank' href='" . $latest_theme['url'] . "'>" . stripslashes($latest_theme['title']) . "</a></strong></td>";
                    echo "<td valign='top'>" . stripslashes($latest_theme['short_description']) . "</td>";
                    echo "</tr>";
                    $class = 'alternate' == $class ? '' : 'alternate';
                    //=========================================================//
                }
            }
            ?>
			</tbody></table>
			<h3><?php 
            _e('Installed Plugins/Themes');
            ?>
</h3>
            <?php 
            echo "\n\t\t\t<table cellpadding='3' cellspacing='3' width='100%' class='widefat'> \n\t\t\t<thead><tr>\n\t\t\t<th scope='col'>Name</th>\n\t\t\t<th scope='col'>Installed Version</th>\n\t\t\t<th scope='col'>Latest Version</th>\n\t\t\t<th scope='col' width='75px'></th>\n\t\t\t</tr></thead>\n\t\t\t<tbody id='the-list'>\n\t\t\t";
            $projects = array();
            if (is_array($data)) {
                $remote_projects = $data['latest_versions'];
                $local_projects = get_site_option('wdp_un_local_projects');
                $local_project_ids = get_site_option('wdp_un_local_project_ids');
                if (is_array($local_projects)) {
                    foreach ($remote_projects as $remote_project) {
                        foreach ($local_projects as $local_project) {
                            if ($remote_project['id'] == $local_project['id']) {
                                $projects[$remote_project['id']]['title'] = $remote_project['title'];
                                $projects[$remote_project['id']]['url'] = $remote_project['url'];
                                $projects[$remote_project['id']]['remote_version'] = $remote_project['version'];
                                $projects[$remote_project['id']]['local_version'] = $local_project['version'];
                            }
                        }
                    }
                }
            }
            if (count($projects) > 0) {
                $class = 'alternate' == $class ? '' : 'alternate';
                foreach ($projects as $project) {
                    $local_version = $project['local_version'];
                    //$local_version = trim($local_version, '.0');
                    //$local_version = trim($local_version, '.0');
                    $remote_version = $project['remote_version'];
                    //$remote_version = trim($remote_version, '.0');
                    //$remote_version = trim($remote_version, '.0');
                    //$check = ($local_version == $remote_version) ? '' : "style='background-color:#FFEBE8;'";
                    $check = update_notificiations_version_check($local_version, $remote_version) ? '' : "style='background-color:#FFEBE8;'";
                    $upgrade_button_code = "<form style='display:inline;' method='get' action='" . $project['url'] . "'><input type='submit' value='Upgrade' class='button-secondary action' /></form> ";
                    //$upgrade_button = ($local_version == $remote_version) ? '' : $upgrade_button_code;
                    $upgrade_button = update_notificiations_version_check($local_version, $remote_version) ? '' : $upgrade_button_code;
                    //=========================================================//
                    echo "<tr class='" . $class . "' " . $check . " >";
                    echo "<td valign='top'><strong><a target='_blank' href='" . $project['url'] . "'>" . stripslashes($project['title']) . "</a></strong></td>";
                    echo "<td valign='top'><strong>" . $local_version . "</strong></td>";
                    echo "<td valign='top'><strong>" . $remote_version . "</strong></td>";
                    echo "<td valign='top'>" . $upgrade_button . "</td>";
                    echo "</tr>";
                    $class = 'alternate' == $class ? '' : 'alternate';
                    //=========================================================//
                }
            }
            ?>
			</tbody></table>
			<p><?php 
            _e('Please note that all data is updated every hour.');
            ?>
 <?php 
            _e('Last updated:');
            ?>
 <?php 
            echo date(get_option('date_format') . ' ' . get_option('time_format'), $last_run);
            ?>
 GMT - <a href="wpmu-admin.php?page=wpmudev&action=update&updated=true&updatedmsg=<?php 
            echo urlencode(__('Data updated.'));
            ?>
"><?php 
            _e('Update Now');
            ?>
</a></p>
			<p><small>* <?php 
            _e('Latest plugins, themes and installed plugins and themes above only refer to those provided to');
            ?>
 <a href="http://premium.wpmudev.org/join/"><?php 
            _e('WPMU DEV members');
            ?>
</a> <?php 
            _e('by Incsub - free plugins and themes are not included here.');
            ?>
</small></p>
			<h3><?php 
            _e('Settings');
            ?>
</h3>
            <form method="post" action="wpmu-admin.php?page=wpmudev&action=process&updated=true&updatedmsg=<?php 
            echo urlencode(__('Changes saved.'));
            ?>
">
            <table class="form-table">
            <tr valign="top">
            <th scope="row"><?php 
            _e('Enable Admin Notices');
            ?>
</th>
            <td>
            <?php 
            $enable_admin_notices = get_site_option('wdp_un_enable_admin_notices');
            ?>
            <select name="enable_admin_notices" id="enable_admin_notices" >
                <option value="yes" <?php 
            if ($enable_admin_notices == 'yes') {
                echo 'selected="selected"';
            }
            ?>
 ><?php 
            _e('Yes');
            ?>
</option>
                <option value="no" <?php 
            if ($enable_admin_notices == 'no') {
                echo 'selected="selected"';
            }
            ?>
 ><?php 
            _e('No');
            ?>
</option>
            </select>
			</td>
            </tr>
            </table>
            
            <p class="submit">
            <input type="submit" name="Submit" value="<?php 
            _e('Save Changes');
            ?>
" />
            </p>
            </form>
            <?php 
            break;
            //---------------------------------------------------//
        //---------------------------------------------------//
        case "temp":
            break;
            //---------------------------------------------------//
    }
    echo '</div>';
}