\n";
wp_register_script('jquery', get_stylesheet_directory_uri() . "/scripts/jquery.min.js", false, '1.11.3');
wp_enqueue_script('jquery');
$JQUERY_LOADED = true;
wp_register_script('jquerymigrate', get_stylesheet_directory_uri() . "/scripts/jquery-migrate-1.2.1.min.js", false, '1.2.1');
wp_enqueue_script('jquerymigrate');
}
add_action('template_redirect', 'add_custom_scripts');
function add_mime_types($mime_types) {
$mime_types['txt'] = 'text/plain';
return $mime_types;
}
add_filter('upload_mimes', 'add_mime_types', 1, 1);
function add_search_box($items, $args) {
if($args->theme_location == 'header-menu') {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
return $items .= '
' . $searchform . '';
}
return $items;
}
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function set_title($title) {
$url = $_SERVER['REQUEST_URI'];
$spliturl = explode('?', $url);
$splituri = explode('/', $spliturl[0]);
if (sizeof($splituri) > 2 && $splituri[2] == "rpms") {
// Set title for distroquery-api
if (sizeof($splituri) > 5) {
if ($splituri[5] == "")
return $splituri[4] . " (" . _r("Source RPM") . ") | ";
else
return $splituri[4] . " (" . $splituri[5] . ") | ";
} else if (sizeof($splituri) > 4) {
return _r("Repository") . " " . $splituri[3] . " | ";
}
return _r("Repositories") . " | ";
} else if (sizeof($spliturl) > 1) {
// Set title for obsolete packages pages
$urlargs = $spliturl[1];
parse_str($urlargs, $args);
$newtitle = $title;
if (array_key_exists('arch', $args)) {
if (preg_match('/^[a-zA-Z0-9._]*$/', $args['arch'])) {
$newtitle = urlencode($args['arch']) . " - " . $newtitle;
} else {
$newtitle = " Invalid request - " . $newtitle;
}
}
if (array_key_exists('tag', $args)) {
if (preg_match('/^[a-zA-Z0-9._-]*$/', $args['tag'])) {
$newtitle = urlencode($args['tag']) . " - " . $newtitle;
} else {
$newtitle = " Invalid request - " . $newtitle;
}
}
if (array_key_exists('pkg', $args)) {
if ($args['pkg'] == '_index')
$newtitle = 'Index - ' . $newtitle;
else {
if (preg_match('/^[a-zA-Z0-9._+-]*$/', $args['pkg'])) {
$e = explode('.', urlencode($args['pkg']));
$newtitle = $e[0] . " - " . $e[1] . " - " . $newtitle;
} else {
$newtitle = " Invalid request - " . $newtitle;
}
}
}
return $newtitle;
}
return $title;
}
add_filter('wp_title','set_title');
// openmamba downloads pages
function openmamba_download_link($milestone, $medium, $currarch, $ext, $mlword, $lang) {
$latest_file = "/var/ftp/pub/openmamba/media/".$milestone."/".$medium."/".$lang."/latest.inc.php";
if (!file_exists($latest_file)) return "";
eval(file_get_contents("/var/ftp/pub/openmamba/media/".$milestone."/".$medium."/".$lang."/latest.inc.php"));
if ("$milestone" == "devel") {
$displaymilestone = "rolling";
} else {
$displaymilestone = "$milestone";
}
$currreleasetag=$releaseTag[$medium.'-'.$milestone.'-'.$lang.'-'.$currarch];
$ret = '';
# if ($lang != "it") {
$downloadmirror = 'https://cdn.openmamba.org/pub/openmamba/media';
# } else {
# $downloadmirror = '/media';
# }
if ("$currreleasetag" != "") {
$ret .= " | ";
$ret .= "";
$ret .= "";
$ret .= __('File size:','responsive').' '.$sizeMedium[$medium.'-'.$currreleasetag.'-'.$lang.'-'.$currarch].'B; ';
$ret .= __('Date','responsive').': '.substr($builddateMedium[$medium.'-'.$currreleasetag.'-'.$lang.'-'.$currarch],
0, strpos($builddateMedium[$medium.'-'.$currreleasetag.'-'.$lang.'-'.$currarch], ' '));
$ret .= "; Md5: " . $md5Medium[$medium.'-'.$currreleasetag.'-'.$lang.'-'.$currarch];
$ret .= " |
";
} else {
$ret .= " | ";
$ret .= "";
$ret .= "openmamba $displaymilestone $medium ";
$ret .= __('for','responsive')." $currarch ($mlword) ";
$ret .= "";
$ret .= __('Sorry, download is temporary unavailable. If the problem persists please report the problem.','responsive');
$ret .= " |
";
}
return $ret;
}
function openmamba_infofile($mediaprefix, $milestone, $fallbackmilestone, $medium, $outputlang, $filename) {
if (file_exists("$mediaprefix/$milestone/$medium/info/$filename.$outputlang.html.inc")) {
$script_file = "$mediaprefix/$milestone/$medium/info/$filename.$outputlang.html.inc";
} else if (file_exists("$mediaprefix/$fallbackmilestone/$medium/info/$filename.$outputlang.html.inc")) {
$script_file = "$mediaprefix/$fallbackmilestone/$medium/info/$filename.$outputlang.html.inc";
}
$ret = '';
if (isset($script_file)) {
$file = fopen($script_file, "r");
while (!feof($file)) {
$b=fread($file,1024);
$ret .= $b;
}
fclose($file);
}
return $ret;
}
function openmamba_download_func( $atts ) {
$a = shortcode_atts( array(
'milestone' => 'devel',
'medium' => 'livedvd',
'multilang' => '0',
'archs' => 'x86_64;i586;arm;aarch64', // bitmask: 1=x86_64 2=i586 3=arm
'ext' => '.iso'
), $atts );
$milestone = $a['milestone'];
$medium = $a['medium'];
$ext = $a['ext'];
$fallbackmilestone = 'milestone2';
if ("$milestone" == "devel") {
$displaymilestone = "rolling";
$suffixmilestone = "snapshot";
} else {
$displaymilestone = "$milestone";
$suffixmilestone = "$milestone";
}
$archname = array("x86_64", "aarch64", "i586", "arm");
$mediaprefix = '/var/ftp/pub/openmamba/media';
$mediafallbackprefix = '/var/ftp/pub/openmamba/media/milestone2';
$outputlang = get_bloginfo("language");
$outputlang = substr($outputlang,0,2);
if ("$outputlang" != "it") {
$outputlang = "en";
$mlword = "multilanguage";
} else {
$mlword = "multilingue";
}
$ret = "openmamba $medium $displaymilestone
";
$ret .= do_shortcode(
openmamba_infofile($mediaprefix,$milestone,$fallbackmilestone,$medium,$outputlang,"description"));
$ret .= "
";
if ($a['multilang']) {
reset($archname);
foreach($archname as $ey => $currarch) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$mlword,"en");
}
} else {
reset($archname);
$langs = array('it' => 'italiano','en' => 'english','es' => 'espaƱol');
foreach($archname as $ey => $currarch) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$langs[$outputlang],$outputlang);
}
$out = "";
foreach ($langs as $l => $lang) {
if ($l == $outputlang) continue;
reset($archname);
foreach($archname as $ey => $currarch) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$out .= openmamba_download_link($milestone,$medium,$currarch,$ext,$lang,$l);
}
}
$ret .= do_shortcode("[expand title=\"". __("More languages...","responsive") . "\"]". $out ."[/expand]");
}
$ret .= do_shortcode(" [expand title=\"".__("Features","responsive")."\"]".
openmamba_infofile($mediaprefix,$milestone,$fallbackmilestone,$medium,$outputlang,"features").
"[/expand]");
$ret .= do_shortcode(" [expand title=\"".__("Requirements","responsive")."\"]".
openmamba_infofile($mediaprefix,$milestone,$fallbackmilestone,$medium,$outputlang,"requirements").
"[/expand]");
$ret .= do_shortcode(" [expand title=\"".__("Preparation","responsive")."\"]".
openmamba_infofile($mediaprefix,$milestone,$fallbackmilestone,$medium,$outputlang,"howto").
"[/expand]");
$ret .= "
";
return $ret;
}
add_shortcode('openmamba_download', 'openmamba_download_func');
function openmamba_webbuild_func( $atts ) {
$urlargspos = strpos($_SERVER['REQUEST_URI'], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos);
}
$a = shortcode_atts( array(
'host' => 'buildvm01.openmamba.org'
), $atts );
print '';
$file = fopen(get_stylesheet_directory() . '/webbuild.html.inc', "r");
print fread($file, 20000);
flush();
fclose($file);
print "";
}
add_shortcode('openmamba_webbuild', 'openmamba_webbuild_func');
function openmamba_webbuild_status_func() {
$urlargspos = strpos($_SERVER['REQUEST_URI'], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos);
}
// print "";
// print "AJAX support is not enabled in your browser. Live page updates will not be available, press Reload to update. ";
print "";
print "" . __("Loading, please wait...", "responsive") . "";
print "";// |
";
}
add_shortcode('openmamba_webbuild_status', 'openmamba_webbuild_status_func');
function openmamba_distroquery_func() {
$urlargspos = strpos($_SERVER['REQUEST_URI'], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos + 1);
}
$outputlang = get_bloginfo("language");
if (substr($outputlang, 0, 2) == "it")
$outputlang = "it_IT.UTF-8";
else
$outputlang = "en_US.UTF-8";
if (preg_match('/^[a-zA-Z0-9._\=\-\+\/\.\&\:]*$/', $urlargs)) {
$ret = "";
$ret .= "Loading, please wait...
";
$ret .= "
";
$ret .= "";
} else {
$ret = "" . __("Invalid request.", "responsive") . "
";
}
return $ret;
}
add_shortcode('openmamba_distroquery', 'openmamba_distroquery_func');
function openmamba_distromatic_func() {
$urlargspos = strpos($_SERVER['REQUEST_URI'], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos + 1);
}
$outputlang = get_bloginfo("language");
if (substr($outputlang, 0, 2) == "it")
$outputlang = "it_IT.UTF-8";
else
$outputlang = "en_US.UTF-8";
if (preg_match('/^[a-zA-Z0-9._\=\-\+\/\.\&\:]*$/', $urlargs)) {
$ret = "" . __("Loading, please wait...", "responsive") . "
";
$ret .= "";
} else {
$ret = "" . __("Invalid request.", "responsive") . "
";
}
return $ret;
}
add_shortcode('openmamba_distromatic', 'openmamba_distromatic_func');
function openmamba_showfile_func() {
$urlargspos = strpos($_SERVER['REQUEST_URI'], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos + 1);
}
if (preg_match('/^[a-zA-Z0-9._\=\-\+\/\.\&\:]*$/', $urlargs)) {
$ret = "" . "Loading, please wait..." . "
";
$ret .= "";
} else {
$ret = "" . __("Invalid request.", "responsive") . "
";
}
return $ret;
}
add_shortcode('openmamba_showfile', 'openmamba_showfile_func');
function openmamba_downloadfile_func() {
$urlargspos = strpos($_SERVER['REQUEST_URI'], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER['REQUEST_URI'], $urlargspos + 1);
parse_str($urlargs, $args);
if ($args['file']) {
$ret = "" . __("Starting download of", "responsive") . " " . basename($args['file']) . ", " . __("please wait...", "responsive") . "
";
$ret .= "";
}
}
return $ret;
}
add_shortcode('openmamba_downloadfile', 'openmamba_downloadfile_func');
// bbpress tag cloud
add_filter('widget_tag_cloud_args','set_number_tags');
function set_number_tags($args) {
$args = array('number' => 10, 'largest' => 20);
return $args;
}
// load_plugin_textdomain('user-registration' , get_site_url() . 'wp-content/themes/openmamba/languages/');
add_action('wp_head','hook_cookielaw');
function hook_cookielaw()
{
$outputlang = get_bloginfo("language");
$outputlang = substr($outputlang,0,2);
//$message = __("This website only uses first party technical cookies necessary for the correct functioning of it.","responsive");
if ("$outputlang" == "it") {
$message = "Questo sito usa esclusivamente cookie di prima parte di tipo tecnico necessari per il corretto funzionamento dello stesso.";
$policyurl = "/" . $outputlang . "/info/policy/";
} else {
$message = "This website only uses first party technical cookies necessary for the correct functioning of it.";
$policyurl = "/" . $outputlang . "/about/policy/";
}
$accepttext = __("I Understand","responsive");
$policytext = __("Cookie policy","responsive");
$policyurl = "/" . $outputlang . "/info/policy/";
$output = "\n";
$output .= "\n";
$output .= "\n";
$output .= "\n";
echo $output;
}
/*function responsive_get_social_icons() {
$responsive_options = responsive_get_options();
$sites = array (
'foursquare' => __( 'foursquare', 'responsive' ),
'twitter' => __( 'Twitter', 'responsive' ),
'facebook' => __( 'Facebook', 'responsive' ),
'linkedin' => __( 'LinkedIn', 'responsive' ),
'youtube' => __( 'YouTube', 'responsive' ),
'stumbleupon' => __( 'StumbleUpon', 'responsive' ),
'rss' => __( 'RSS Feed', 'responsive' ),
'googleplus' => __( 'Google+', 'responsive' ),
'instagram' => __( 'Instagram', 'responsive' ),
'pinterest' => __( 'Pinterest', 'responsive' ),
'yelp' => __( 'Yelp!', 'responsive' ),
'vimeo' => __( 'Vimeo', 'responsive' ),
);
$html = '';
foreach( $sites as $key => $value ) {
if ( !empty( $responsive_options[$key . '_uid'] ) ) {
$html .= '- ' . '' . '
';
}
}
$html .= '
';
return $html;
}
*/
function wpb_imagelink_setup() {
$image_set = get_option( 'image_default_link_type' );
if ($image_set !== 'none') {
update_option('image_default_link_type', 'none');
}
}
add_action('admin_init', 'wpb_imagelink_setup', 10);
/* Security: restrict access to wp-json */
function restrict_rest_api_access() {
$whitelist = [ '127.0.0.1', "::1", '176.9.120.93', '2a01:4f8:151:7444::1:3' ];
// Allow whitelisted ip addresses
if (in_array($_SERVER['REMOTE_ADDR'], $whitelist) ){
return;
}
// List of allowed endpoint prefixes (adjust as needed)
$allowed_prefixes = [
'openid-connect', // Allow /wp-json/openid-connect/*
// Add other prefixes here if needed
];
// Get the current REST route
$request_uri = $_SERVER['REQUEST_URI'];
// Check if the request URI matches any allowed prefix
foreach ($allowed_prefixes as $prefix) {
if (strpos($request_uri, '/it/wp-json/' . $prefix) === 0) {
return; // Allow access
}
}
die( 'REST API is disabled.' );
}
add_action('rest_api_init', 'restrict_rest_api_access', 10, 3 );
/* Security: filter email domains frequently used for spam registrations */
function user_registration_filter($user_id, $email) {
if ($user_id == false) {
$e1 = explode("@", $email);
if (in_array($e1[1], array(
'xtra.ltd','tmobile.agency','btee.online','verizonconnect.online','proton.me',
'eduonline.digital','vofadonepro.online','tasktracker.in'))) {
error_log( "user_registration_filter: email=" . $email . " blacklisted domain=" . $e1[1] );
$user_id = 100;
} else {
//preg_match("/[0-9]{2}$/", $e1[0]) ||
if (preg_match("/[0-9]{3}$/", $e1[0]) || in_array($e1[0], array('astro_yoga'))) {
error_log( "user_registration_filter: email=" . $email . " blacklisted ([0-9]{2}$) domain=" . $e1[1] );
$user_id = 100;
} else {
error_log( "user_registration_filter: email=" . $email . " whitelisted domain=" . $e1[1] );
}
}
}
return $user_id;
}
add_filter('email_exists', 'user_registration_filter', 10, 2);
/* Security: prevent multisite signup */
function prevent_multisite_signup()
{
wp_redirect( site_url() );
die();
}
add_action( 'signup_header', 'prevent_multisite_signup' );
/* Fix for missing js support in bbpress editor */
add_filter ('bbp_body_class', 'rew_unset_no_js') ;
function rew_unset_no_js($classes) {
if (in_array ('single-forum', $classes) || in_array ('single-topic', $classes)) {
if (($key = array_search('no-js', $classes)) !== false) {
unset($classes[$key]);
}
}
return $classes ;
}
// Distroquery API management
add_filter( 'query_vars', function( $query_vars ) {
$query_vars[] = 'distroquery';
$query_vars[] = 'repo';
$query_vars[] = 'package';
$query_vars[] = 'arch';
return $query_vars;
} );
function distroquery_api_rewrite_rules ( ) {
add_rewrite_rule ( '^rpms/([^/]*)/([^/]*)/([^/]*)/?',
'index.php?distroquery=1&repo=$matches[1]&package=$matches[2]&arch=$matches[3]','top' );
add_rewrite_rule ( '^rpms/([^/]*)/([^/]*)/?',
'index.php?distroquery=1&repo=$matches[1]&package=$matches[2]','top' );
add_rewrite_rule ( '^rpms/([^/]*)/?',
'index.php?distroquery=1&repo=$matches[1]','top' );
add_rewrite_rule ( '^rpms/?',
'index.php?distroquery=1','top' );
}
add_action ( 'init', 'distroquery_api_rewrite_rules', 10, 0 ) ;
add_filter( 'template_include', function( $template ) {
if ( get_query_var( 'distroquery' ) == false || get_query_var( 'distroquery' ) == '' ) {
return $template;
}
return get_theme_file_path() . '/distroquery.php';
} );
// openid-connect filters
function my_oidc_clients() {
if ( ! defined( 'OIDC_CLIENT_ID' ) || ! defined( 'OIDC_CLIENT_KEY' ) ) {
// Please define client id and key in wp-config.php.
return;
}
return array(
OIDC_CLIENT_ID => array(
'name' => 'openmamba package sources',
'secret' => OIDC_CLIENT_KEY,
'redirect_uri' => 'https://src.openmamba.org/user/oauth2/openmamba/callback',
'grant_types' => array( 'authorization_code' ),
'scope' => 'openid profile',
),
);
}
add_filter( 'oidc_registered_clients', 'my_oidc_clients' );
function my_oidc_capability() {
return 'read';
}
add_filter( 'oidc_minimal_capability', 'my_oidc_capability' );
function my_user_claims($claims, $user) {
$claims['email'] = $user->user_email;
return $claims;
}
add_filter( 'oidc_user_claims', 'my_user_claims', 10, 2 );