function render_dashboard_page() { $this->list_table = new Amber_List_Table(); $this->list_table->prepare_items(); ?> <div class="wrap"> <form id="amber_dashboard" method="get"> <?php wp_nonce_field('amber_dashboard'); ?> <div id="icon-users" class="icon32"><br/></div> <h2>Amber Dashboard</h2> <div id="amber-stats"> <h3>Global Statistics</h3> <table> <tbody> <tr><td>Snapshots preserved</td><td><?php print $this->cache_size(); ?> </td></tr> <tr><td>Links to snapshot</td><td><?php print $this->queue_size(); ?> </td></tr> <tr><td>Last check</td><td><?php print $this->last_check(); ?> </td></tr> <tr><td>Disk space used</td><td><?php print $this->disk_usage() . " of " . Amber::get_option('amber_max_disk'); ?> MB</td></tr> </tbody> </table> <?php submit_button("Delete all snapshots", "small", "delete_all"); ?> <?php submit_button("Scan content for links to preserve", "small", "scan"); ?> <?php submit_button("Snapshot all new links", "small", "cache_now"); ?> <?php submit_button("Export list of snapshots", "small", "export"); ?> </div> </form> <form id="amber_dashboard-2"> <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?> " /> <?php $this->list_table->display(); ?> <div id="amber-lightbox"> <div id="amber-lightbox-content"> <div id="batch_status"></div> <input type="submit" name="stop" id="stop" class="button button-small" value="Stop"> </div> </div> </form> </div> <style> div#amber-stats { float: left; background:#ECECEC; border:1px solid #CCC; padding:0 10px; margin-top:5px; border-radius:5px; } p.submit { float: left; padding-right: 20px; } th.views, td.views { text-align: center; } div#amber-lightbox { width: 100%; height: 75%; z-index: 200; position: absolute; background-color: rgba(0,0,0,.7); left: -10px; top: 0; padding-top: 25%; display: none; } div#amber-lightbox-content { float: left; width: 50%; margin-left: 25%; top: 25%; postion: absolute; background:#ECECEC; border:1px solid #CCC; padding:30px; margin-top:5px; border-radius:5px; } div#batch_status { width: 80%; overflow: hidden; float: left; } div#amber-lightbox input { float: right; position: relative; } </style> <script type="text/javascript" > jQuery(document).ready(function($) { $("input#cache_now").click(function() { cache_all(); return false;}); $("input#scan").click(function() { scan_all(); return false;}); function show_status(s) { $("div#amber-lightbox").show(); $("#batch_status").html(s); } function show_status_done(s) { $("#batch_status").html(s); $("#amber-lightbox input").val("Close"); } function cache_one() { var data = { 'action': 'amber_cache', '_wpnonce': $("#_wpnonce").val() }; $.post(ajaxurl, data, function(response) { if (response) { // Cached a page, check to see if there's another show_status("Preserving..." + response); setTimeout(cache_one, 100); } else { show_status_done("Done preserving links"); } }); } function cache_all () { show_status("Preserving links..."); cache_one(); } function scan_one() { var data = { 'action': 'amber_scan', '_wpnonce': $("#_wpnonce").val()}; $.post(ajaxurl, data, function(response) { if (response && response != 0) { show_status("Scanning content. " + response + " items remaining."); setTimeout(scan_one, 100); } else { show_status_done("Done scanning content"); } }); } function scan_all () { show_status("Scanning content for links..."); var data = { 'action': 'amber_scan_start', '_wpnonce': $("#_wpnonce").val() }; $.post(ajaxurl, data, function(response) { if (response) { show_status(response + " items left to scan"); setTimeout(scan_one, 100); } else { show_status_done("No items to scan"); } }); } }); </script> <?php }
/** * Filter links that are candidates for caching to exclude local links, or links to URLs on the blacklist * @param $links array of links to check * @param $blacklist array of regular expressions to exclude */ private static function filter_regexp_excluded_links($links) { $blacklist = preg_split("/[,\\s]+/", Amber::get_option("amber_excluded_sites", "")); if (!$blacklist) { return $links; } $default_error_logging_level = error_reporting(); $result = array('cache' => array(), 'excluded' => array()); foreach ($links as $link) { $exclude = FALSE; foreach ($blacklist as $blacklistitem) { $blacklistitem = trim($blacklistitem); if ($blacklistitem) { $blacklistitem = preg_replace("/https?:\\/\\//i", "", $blacklistitem); $blacklistitem = str_replace("@", "\\@", $blacklistitem); $blacklistitem = '@' . $blacklistitem . '@'; $cleanedlink = preg_replace("/https?:\\/\\//i", "", $link); /* Hide warning messages from preg_match() that can be generated by invalid user-entered regular expressions. */ error_reporting(E_ALL ^ E_WARNING); $match_result = preg_match($blacklistitem, $cleanedlink); error_reporting($default_error_logging_level); if ($match_result === FALSE) { // Log compilation error explicitly, since we'd disabled warnings error_log("filter_regexp_excluded_links: Error processing excluded list regular expression for " . $blacklistitem); $error = error_get_last(); error_log($error["message"]); } else { if ($match_result) { $exclude = TRUE; } else { // If match_result === 0, meaning there was no match, so do nothing } } } } if ($exclude) { $result['excluded'][] = $link; } else { $result['cache'][] = $link; } } return $result; }
public static function add_meta_boxes() { $screens = explode(',', Amber::get_option('amber_post_types', 'post,page')); foreach ($screens as $screen) { add_meta_box('amber_sectionid', 'Amber', array('Amber', 'display_meta_boxes'), $screen, 'side'); } }