2016-08-20 18:32:19 +02:00
< ? php
// Exit if accessed directly
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
2014-11-02 14:14:46 +01:00
2021-08-02 09:56:47 +02:00
//add_action( 'login_init', 'send_frame_options_header', 10, 0 );
2024-06-29 14:04:42 +02:00
// Convenience function for translations in 'responsive' domain
function _r ( $text ) {
return __ ( $text , 'responsive' );
}
2015-02-22 16:02:17 +01:00
function openmamba_breadcrumbs () {
$text [ 'category' ] = '' ;
}
2014-12-08 17:04:48 +01:00
// custom fonts
2014-11-02 14:14:46 +01:00
function add_custom_font () {
2014-11-13 21:33:23 +01:00
$url = get_stylesheet_directory_uri () . '/fonts/comfortaa-regular/stylesheet.css' ;
2014-11-02 14:14:46 +01:00
wp_register_style ( 'comfortaaregular' , $url );
wp_enqueue_style ( 'comfortaaregular' );
wp_register_style ( 'comfortaalight' , $url );
wp_enqueue_style ( 'comfortaalight' );
wp_register_style ( 'comfortaabold' , $url );
wp_enqueue_style ( 'comfortaabold' );
}
2014-12-08 17:04:48 +01:00
add_action ( 'wp_print_styles' , 'add_custom_font' );
2014-11-02 14:14:46 +01:00
2015-07-12 15:45:26 +02:00
// add styles and scripts
function add_custom_scripts () {
wp_deregister_script ( 'jquery' );
$protocol = 'http:' ;
if ( $_SERVER [ 'HTTPS' ] == 'on' ) {
$protocol = 'https:' ;
}
2024-07-11 01:00:53 +02:00
//$output .= "<script type=\"text/javascript\" src=\"" . get_stylesheet_directory_uri() . "/scripts/jquery.cookiebar.js\"></script>\n";
2018-07-28 18:19:46 +02:00
wp_register_script ( 'jquery' , get_stylesheet_directory_uri () . " /scripts/jquery.min.js " , false , '1.11.3' );
2015-07-12 15:45:26 +02:00
wp_enqueue_script ( 'jquery' );
$JQUERY_LOADED = true ;
2018-07-28 18:19:46 +02:00
wp_register_script ( 'jquerymigrate' , get_stylesheet_directory_uri () . " /scripts/jquery-migrate-1.2.1.min.js " , false , '1.2.1' );
2015-07-12 15:45:26 +02:00
wp_enqueue_script ( 'jquerymigrate' );
}
add_action ( 'template_redirect' , 'add_custom_scripts' );
2015-11-10 18:47:41 +01:00
function add_mime_types ( $mime_types ) {
$mime_types [ 'txt' ] = 'text/plain' ;
return $mime_types ;
}
add_filter ( 'upload_mimes' , 'add_mime_types' , 1 , 1 );
2015-02-22 16:02:17 +01:00
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 .= '<li id="searchform-item">' . $searchform . '</li>' ;
}
return $items ;
}
add_filter ( 'wp_nav_menu_items' , 'add_search_box' , 10 , 2 );
2020-06-27 13:14:44 +02:00
function set_title ( $title ) {
2024-11-03 13:15:53 +01:00
$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 ];
2020-06-27 13:14:44 +02:00
parse_str ( $urlargs , $args );
$newtitle = $title ;
2024-07-11 01:00:53 +02:00
if ( array_key_exists ( 'arch' , $args )) {
2020-09-20 12:15:42 +02:00
if ( preg_match ( '/^[a-zA-Z0-9._]*$/' , $args [ 'arch' ])) {
$newtitle = urlencode ( $args [ 'arch' ]) . " - " . $newtitle ;
} else {
$newtitle = " Invalid request - " . $newtitle ;
}
2020-06-27 13:14:44 +02:00
}
2024-07-11 01:00:53 +02:00
if ( array_key_exists ( 'tag' , $args )) {
2020-09-20 12:15:42 +02:00
if ( preg_match ( '/^[a-zA-Z0-9._-]*$/' , $args [ 'tag' ])) {
$newtitle = urlencode ( $args [ 'tag' ]) . " - " . $newtitle ;
} else {
$newtitle = " Invalid request - " . $newtitle ;
}
2020-06-27 13:14:44 +02:00
}
2024-07-11 01:00:53 +02:00
if ( array_key_exists ( 'pkg' , $args )) {
2020-06-27 13:14:44 +02:00
if ( $args [ 'pkg' ] == '_index' )
$newtitle = 'Index - ' . $newtitle ;
else {
2020-09-20 12:15:42 +02:00
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 ;
}
2020-06-27 13:14:44 +02:00
}
}
return $newtitle ;
}
return $title ;
}
add_filter ( 'wp_title' , 'set_title' );
2014-11-02 14:14:46 +01:00
// openmamba downloads pages
2014-12-08 17:04:48 +01:00
function openmamba_download_link ( $milestone , $medium , $currarch , $ext , $mlword , $lang ) {
2018-07-28 18:00:25 +02:00
$latest_file = " /var/ftp/pub/openmamba/media/ " . $milestone . " / " . $medium . " / " . $lang . " /latest.inc.php " ;
if ( ! file_exists ( $latest_file )) return " " ;
2014-11-02 14:14:46 +01:00
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 ];
2015-01-09 13:45:16 +01:00
$ret = '' ;
2015-11-02 20:16:41 +01:00
# if ($lang != "it") {
2021-12-04 17:46:15 +01:00
$downloadmirror = 'https://cdn.openmamba.org/pub/openmamba/media' ;
2015-11-02 20:16:41 +01:00
# } else {
# $downloadmirror = '/media';
# }
2014-12-29 15:57:23 +01:00
if ( " $currreleasetag " != " " ) {
2015-01-09 13:45:16 +01:00
$ret .= " <table style='border:0;margin:0;margin-bottom:5px;'><tr><td style='vertical-align:middle;padding:4px;border:0;margin:0;width:20px;align:center;'><img src=/wp-content/themes/openmamba/download.png /></td> " ;
2015-07-11 19:19:29 +02:00
$ret .= " <td style='border:0;margin:0;padding:4px;'><h5 style='margin:1px;'><a href= \" " . $downloadmirror . " / $milestone / $medium / $lang / " .
2015-04-16 11:22:45 +02:00
$nameMedium [ $medium . '-' . $currreleasetag . '-' . $lang . '-' . $currarch ] . " \" > " ;
2015-01-09 13:45:16 +01:00
$ret .= " openmamba $displaymilestone $medium " ;
$ret .= __ ( 'for' , 'responsive' ) . " $currarch ( $mlword )</a> </h5> " ;
$ret .= " <i> " ;
$ret .= __ ( 'File size:' , 'responsive' ) . ' ' . $sizeMedium [ $medium . '-' . $currreleasetag . '-' . $lang . '-' . $currarch ] . 'B; ' ;
$ret .= __ ( 'Date' , 'responsive' ) . ': ' . substr ( $builddateMedium [ $medium . '-' . $currreleasetag . '-' . $lang . '-' . $currarch ],
2014-12-29 15:57:23 +01:00
0 , strpos ( $builddateMedium [ $medium . '-' . $currreleasetag . '-' . $lang . '-' . $currarch ], ' ' ));
2015-01-09 13:45:16 +01:00
$ret .= " ; Md5: " . $md5Medium [ $medium . '-' . $currreleasetag . '-' . $lang . '-' . $currarch ];
$ret .= " </i></td></tr></table> " ;
2014-12-29 15:57:23 +01:00
} else {
2015-01-09 13:45:16 +01:00
$ret .= " <table style='border:0;margin:0;margin-bottom:5px;'><tr><td style='vertical-align:middle;padding:4px;border:0;margin:0;width:20px;align:center;'><img src=/wp-content/themes/openmamba/download.png /></td> " ;
$ret .= " <td style='border:0;margin:0;padding:4px;'><h5 style='margin:1px;'> " ;
$ret .= " openmamba $displaymilestone $medium " ;
$ret .= __ ( 'for' , 'responsive' ) . " $currarch ( $mlword ) </h5> " ;
$ret .= " <i><font color=red> " ;
$ret .= __ ( 'Sorry, download is temporary unavailable. If the problem persists please report the problem.' , 'responsive' );
$ret .= " </font></i></td></tr></table> " ;
2014-12-29 15:57:23 +01:00
}
2015-01-09 13:45:16 +01:00
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 = '' ;
2024-07-11 01:00:53 +02:00
if ( isset ( $script_file )) {
2015-01-09 13:45:16 +01:00
$file = fopen ( $script_file , " r " );
while ( ! feof ( $file )) {
$b = fread ( $file , 1024 );
$ret .= $b ;
}
fclose ( $file );
}
return $ret ;
2014-11-02 14:14:46 +01:00
}
function openmamba_download_func ( $atts ) {
$a = shortcode_atts ( array (
'milestone' => 'devel' ,
'medium' => 'livedvd' ,
'multilang' => '0' ,
2021-01-07 10:31:36 +01:00
'archs' => 'x86_64;i586;arm;aarch64' , // bitmask: 1=x86_64 2=i586 3=arm
2014-11-02 14:14:46 +01:00
'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 " ;
}
2021-01-07 10:31:36 +01:00
$archname = array ( " x86_64 " , " aarch64 " , " i586 " , " arm " );
2014-11-02 14:14:46 +01:00
$mediaprefix = '/var/ftp/pub/openmamba/media' ;
$mediafallbackprefix = '/var/ftp/pub/openmamba/media/milestone2' ;
$outputlang = get_bloginfo ( " language " );
2015-06-06 15:33:05 +02:00
$outputlang = substr ( $outputlang , 0 , 2 );
2014-11-02 14:14:46 +01:00
if ( " $outputlang " != " it " ) {
$outputlang = " en " ;
$mlword = " multilanguage " ;
} else {
$mlword = " multilingue " ;
}
2015-01-09 13:45:16 +01:00
$ret = " <h3>openmamba $medium $displaymilestone </h3> " ;
2014-11-02 14:14:46 +01:00
2015-01-09 13:45:16 +01:00
$ret .= do_shortcode (
openmamba_infofile ( $mediaprefix , $milestone , $fallbackmilestone , $medium , $outputlang , " description " ));
$ret .= " <br><br> " ;
if ( $a [ 'multilang' ]) {
reset ( $archname );
2024-07-11 01:00:53 +02:00
foreach ( $archname as $ey => $currarch ) {
2015-01-09 13:45:16 +01:00
if ( strpos ( " ; " . $a [ 'archs' ] . " ; " , $currarch ) == false ) continue ;
$ret .= openmamba_download_link ( $milestone , $medium , $currarch , $ext , $mlword , " en " );
2014-11-02 14:14:46 +01:00
}
2015-01-09 13:45:16 +01:00
} else {
reset ( $archname );
$langs = array ( 'it' => 'italiano' , 'en' => 'english' , 'es' => 'español' );
2024-07-11 01:00:53 +02:00
foreach ( $archname as $ey => $currarch ) {
2015-01-09 13:45:16 +01:00
if ( strpos ( " ; " . $a [ 'archs' ] . " ; " , $currarch ) == false ) continue ;
$ret .= openmamba_download_link ( $milestone , $medium , $currarch , $ext , $langs [ $outputlang ], $outputlang );
}
2024-11-03 12:19:34 +01:00
$out = " " ;
2015-01-09 13:45:16 +01:00
foreach ( $langs as $l => $lang ) {
if ( $l == $outputlang ) continue ;
reset ( $archname );
2024-07-11 01:00:53 +02:00
foreach ( $archname as $ey => $currarch ) {
2015-01-09 13:45:16 +01:00
if ( strpos ( " ; " . $a [ 'archs' ] . " ; " , $currarch ) == false ) continue ;
2024-08-11 17:22:04 +02:00
$out .= openmamba_download_link ( $milestone , $medium , $currarch , $ext , $lang , $l );
2015-01-09 13:45:16 +01:00
}
2014-11-02 14:14:46 +01:00
}
2020-06-16 10:02:28 +02:00
$ret .= do_shortcode ( " [expand title= \" " . __ ( " More languages... " , " responsive " ) . " \" ] " . $out . " [/expand] " );
2014-11-02 14:14:46 +01:00
}
2015-01-09 13:45:16 +01:00
2020-06-16 10:02:28 +02:00
$ret .= do_shortcode ( " [expand title= \" " . __ ( " Features " , " responsive " ) . " \" ] " .
2015-01-09 13:45:16 +01:00
openmamba_infofile ( $mediaprefix , $milestone , $fallbackmilestone , $medium , $outputlang , " features " ) .
" [/expand] " );
2020-06-16 10:02:28 +02:00
$ret .= do_shortcode ( " [expand title= \" " . __ ( " Requirements " , " responsive " ) . " \" ] " .
2015-01-09 13:45:16 +01:00
openmamba_infofile ( $mediaprefix , $milestone , $fallbackmilestone , $medium , $outputlang , " requirements " ) .
" [/expand] " );
2020-06-16 10:02:28 +02:00
$ret .= do_shortcode ( " [expand title= \" " . __ ( " Preparation " , " responsive " ) . " \" ] " .
2015-01-09 13:45:16 +01:00
openmamba_infofile ( $mediaprefix , $milestone , $fallbackmilestone , $medium , $outputlang , " howto " ) .
" [/expand] " );
$ret .= " <hr> " ;
return $ret ;
2014-11-02 14:14:46 +01:00
}
add_shortcode ( 'openmamba_download' , 'openmamba_download_func' );
2014-11-13 21:33:23 +01:00
function openmamba_webbuild_func ( $atts ) {
2020-07-05 10:35:28 +02:00
$urlargspos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
2014-12-08 17:04:48 +01:00
if ( $urlargspos > 0 ) {
2020-07-05 10:35:28 +02:00
$urlargs = substr ( $_SERVER [ 'REQUEST_URI' ], $urlargspos );
2014-12-08 17:04:48 +01:00
}
2014-11-13 21:33:23 +01:00
$a = shortcode_atts ( array (
2015-07-11 19:19:29 +02:00
'host' => 'buildvm01.openmamba.org'
2014-11-13 21:33:23 +01:00
), $atts );
print '<script>host="' . $a [ 'host' ] . '"</script>' ;
$file = fopen ( get_stylesheet_directory () . '/webbuild.html.inc' , " r " );
print fread ( $file , 20000 );
flush ();
fclose ( $file );
2020-06-17 18:05:14 +02:00
print " <script> $ (document).ready(function() { ajax_getvalues( \" " . $urlargs . " \" , \" \" ); " ;
print " ajax_getvalues_refresh( \" \" ,user,user_email,encodeURIComponent(secret)); })</script> " ;
2014-11-13 21:33:23 +01:00
}
add_shortcode ( 'openmamba_webbuild' , 'openmamba_webbuild_func' );
2014-11-23 18:16:02 +01:00
function openmamba_webbuild_status_func () {
2020-07-05 10:35:28 +02:00
$urlargspos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
2014-11-23 18:16:02 +01:00
if ( $urlargspos > 0 ) {
2020-07-05 10:35:28 +02:00
$urlargs = substr ( $_SERVER [ 'REQUEST_URI' ], $urlargspos );
2014-11-23 18:16:02 +01:00
}
// print "<table width=\"100%\" style=\"border:0;\"><tr><td>";
2020-07-05 10:35:28 +02:00
// print "<div id=\"noajax_msg\"><p>AJAX support is not enabled in your browser. Live page updates will not be available, press Reload to update.</p></div>";
print " <div id= \" noajax_msg \" ></div> " ;
print " <span class=webbuild id= \" output \" > " . __ ( " Loading, please wait... " , " responsive " ) . " </span> " ;
2020-06-25 20:14:06 +02:00
print " <script> $ (document).ready(function() { webbuild_status_getvalues( \" " . $urlargs . " \" ); })</script> " ; //</td></tr></table>";
2014-11-23 18:16:02 +01:00
}
add_shortcode ( 'openmamba_webbuild_status' , 'openmamba_webbuild_status_func' );
2015-04-06 20:46:06 +02:00
function openmamba_distroquery_func () {
2020-07-05 10:35:28 +02:00
$urlargspos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
2015-04-06 20:46:06 +02:00
if ( $urlargspos > 0 ) {
2020-07-05 10:35:28 +02:00
$urlargs = substr ( $_SERVER [ 'REQUEST_URI' ], $urlargspos + 1 );
2015-04-06 20:46:06 +02:00
}
$outputlang = get_bloginfo ( " language " );
2015-06-06 15:33:05 +02:00
if ( substr ( $outputlang , 0 , 2 ) == " it " )
2015-04-06 20:46:06 +02:00
$outputlang = " it_IT.UTF-8 " ;
else
$outputlang = " en_US.UTF-8 " ;
2020-09-20 12:15:42 +02:00
if ( preg_match ( '/^[a-zA-Z0-9._\=\-\+\/\.\&\:]*$/' , $urlargs )) {
$ret = " <div id= \" noajax_msg \" ></div> " ;
$ret .= " <span id= \" queryform \" >Loading, please wait...</span><br> " ;
$ret .= " <span id= \" querystatus \" ></span><br><span id= \" queryreply \" > </span> " ;
$ret .= " <script> $ (document).ready(function() { distroquery_request( \" " . $urlargs . " \" ); })</script> " ;
} else {
$ret = " <span id= \" distromatic \" > " . __ ( " Invalid request. " , " responsive " ) . " </span><br> " ;
}
2020-06-25 20:14:06 +02:00
2015-12-08 15:19:02 +01:00
return $ret ;
2015-04-06 20:46:06 +02:00
}
add_shortcode ( 'openmamba_distroquery' , 'openmamba_distroquery_func' );
2020-06-25 20:14:06 +02:00
function openmamba_distromatic_func () {
2020-07-05 10:35:28 +02:00
$urlargspos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
2020-06-25 20:14:06 +02:00
if ( $urlargspos > 0 ) {
2020-07-05 10:35:28 +02:00
$urlargs = substr ( $_SERVER [ 'REQUEST_URI' ], $urlargspos + 1 );
2020-06-25 20:14:06 +02:00
}
$outputlang = get_bloginfo ( " language " );
if ( substr ( $outputlang , 0 , 2 ) == " it " )
$outputlang = " it_IT.UTF-8 " ;
else
$outputlang = " en_US.UTF-8 " ;
2020-09-20 12:15:42 +02:00
if ( preg_match ( '/^[a-zA-Z0-9._\=\-\+\/\.\&\:]*$/' , $urlargs )) {
$ret = " <span id= \" distromatic \" > " . __ ( " Loading, please wait... " , " responsive " ) . " </span><br> " ;
$ret .= " <script> $ (document).ready(function() { $ ('#distromatic').load('/distribution/distromatic.naked.html? " . $urlargs . " '); })</script> " ;
} else {
$ret = " <span id= \" distromatic \" > " . __ ( " Invalid request. " , " responsive " ) . " </span><br> " ;
}
2020-06-25 20:14:06 +02:00
return $ret ;
}
add_shortcode ( 'openmamba_distromatic' , 'openmamba_distromatic_func' );
function openmamba_showfile_func () {
2020-07-05 10:35:28 +02:00
$urlargspos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
2020-06-25 20:14:06 +02:00
if ( $urlargspos > 0 ) {
2020-07-05 10:35:28 +02:00
$urlargs = substr ( $_SERVER [ 'REQUEST_URI' ], $urlargspos + 1 );
2020-06-25 20:14:06 +02:00
}
2020-09-20 12:15:42 +02:00
if ( preg_match ( '/^[a-zA-Z0-9._\=\-\+\/\.\&\:]*$/' , $urlargs )) {
$ret = " <span id= \" distromatic \" > " . " Loading, please wait... " . " </span><br> " ;
$ret .= " <script> $ (document).ready(function() { $ ('#distromatic').load('/distribution/showfile.naked.html? " . $urlargs . " '); })</script> " ;
} else {
$ret = " <span id= \" distromatic \" > " . __ ( " Invalid request. " , " responsive " ) . " </span><br> " ;
}
2020-06-25 20:14:06 +02:00
return $ret ;
}
add_shortcode ( 'openmamba_showfile' , 'openmamba_showfile_func' );
function openmamba_downloadfile_func () {
2020-07-05 10:35:28 +02:00
$urlargspos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
2020-06-25 20:14:06 +02:00
if ( $urlargspos > 0 ) {
2020-07-05 10:35:28 +02:00
$urlargs = substr ( $_SERVER [ 'REQUEST_URI' ], $urlargspos + 1 );
2020-06-25 20:14:06 +02:00
parse_str ( $urlargs , $args );
if ( $args [ 'file' ]) {
2020-07-05 10:35:28 +02:00
$ret = " <span id= \" distromatic \" > " . __ ( " Starting download of " , " responsive " ) . " <strong> " . basename ( $args [ 'file' ]) . " </strong>, " . __ ( " please wait... " , " responsive " ) . " </span><br><br> " ;
2020-06-25 20:14:06 +02:00
$ret .= " <script> $ (document).ready(function() { window.location.href=' " . $args [ 'file' ] . " '; })</script> " ;
}
}
return $ret ;
}
add_shortcode ( 'openmamba_downloadfile' , 'openmamba_downloadfile_func' );
2014-11-02 14:14:46 +01:00
// 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 ;
}
2015-04-16 11:22:45 +02:00
2019-11-02 10:28:43 +01:00
// load_plugin_textdomain('user-registration' , get_site_url() . 'wp-content/themes/openmamba/languages/');
2015-07-11 21:50:33 +02:00
add_action ( 'wp_head' , 'hook_cookielaw' );
function hook_cookielaw ()
{
$outputlang = get_bloginfo ( " language " );
$outputlang = substr ( $outputlang , 0 , 2 );
2024-01-28 11:44:54 +01:00
//$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/ " ;
}
2019-11-02 10:28:43 +01:00
$accepttext = __ ( " I Understand " , " responsive " );
$policytext = __ ( " Cookie policy " , " responsive " );
2015-07-11 21:50:33 +02:00
$policyurl = " / " . $outputlang . " /info/policy/ " ;
$output = " <link rel= \" stylesheet \" type= \" text/css \" href= \" " . get_stylesheet_directory_uri () . " /styles/jquery.cookiebar.css \" /> \n " ;
$output .= " <script type= \" text/javascript \" src= \" " . get_stylesheet_directory_uri () . " /scripts/jquery.cookiebar.js \" ></script> \n " ;
$output .= " <script type= \" text/javascript \" > $ (document).ready(function() { $ .cookieBar( { " .
" message: \" " . $message . " \" ,acceptText: ' " . $accepttext . " ', " .
" policyText: ' " . $policytext . " ',policyURL: ' " . $policyurl . " ' }); });</script> \n " ;
2016-02-27 13:55:01 +01:00
$output .= " <script type= \" text/javascript \" >document.domain='openmamba.org';</script> \n " ;
2015-07-11 21:50:33 +02:00
echo $output ;
}
2015-11-02 20:16:41 +01:00
/* 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 = '<ul class="social-icons">' ;
foreach ( $sites as $key => $value ) {
if ( ! empty ( $responsive_options [ $key . '_uid' ] ) ) {
$html .= '<li class="' . esc_attr ( $key ) . '-icon"><a href="' . $responsive_options [ $key . '_uid' ] . '">' . '<img src="' . responsive_child_uri ( '/core/icons/' . esc_attr ( $key ) . '-icon.png' ) . '" width="24" height="24" alt="' . esc_html ( $value ) . '">' . '</a></li>' ;
}
}
$html .= '</ul><!-- .social-icons -->' ;
return $html ;
}
2021-08-02 09:56:47 +02:00
*/
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_to_localhost () {
2024-08-11 17:22:04 +02:00
$whitelist = [ '127.0.0.1' , " ::1 " , '176.9.120.93' , '2a01:4f8:151:7444::1:3' ];
2021-08-02 09:56:47 +02:00
if ( ! in_array ( $_SERVER [ 'REMOTE_ADDR' ], $whitelist ) ){
die ( 'REST API is disabled.' );
}
}
add_action ( 'rest_api_init' , 'restrict_rest_api_to_localhost' , 0 );
2023-08-17 10:00:05 +02:00
/* 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 (
2024-11-03 12:19:34 +01:00
'xtra.ltd' , 'tmobile.agency' , 'btee.online' , 'verizonconnect.online' , 'proton.me' ,
2024-01-28 11:44:54 +01:00
'eduonline.digital' , 'vofadonepro.online' , 'tasktracker.in' ))) {
2023-08-17 10:00:05 +02:00
error_log ( " user_registration_filter: email= " . $email . " blacklisted domain= " . $e1 [ 1 ] );
$user_id = 100 ;
} else {
2024-01-28 11:44:54 +01:00
//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 ] );
}
2023-08-17 10:00:05 +02:00
}
}
return $user_id ;
}
add_filter ( 'email_exists' , 'user_registration_filter' , 10 , 2 );
2023-08-21 10:51:40 +02:00
/* Security: prevent multisite signup */
function prevent_multisite_signup ()
{
wp_redirect ( site_url () );
die ();
}
add_action ( 'signup_header' , 'prevent_multisite_signup' );
2024-01-28 12:04:51 +01:00
/* 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 ;
}
2024-06-01 22:31:12 +02:00
// 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 ( ) {
2024-06-29 12:52:20 +02:00
add_rewrite_rule ( '^rpms/([^/]*)/([^/]*)/([^/]*)/?' ,
2024-06-01 22:31:12 +02:00
'index.php?distroquery=1&repo=$matches[1]&package=$matches[2]&arch=$matches[3]' , 'top' );
2024-06-29 12:52:20 +02:00
add_rewrite_rule ( '^rpms/([^/]*)/([^/]*)/?' ,
2024-06-01 22:31:12 +02:00
'index.php?distroquery=1&repo=$matches[1]&package=$matches[2]' , 'top' );
2024-06-29 12:52:20 +02:00
add_rewrite_rule ( '^rpms/([^/]*)/?' ,
2024-06-01 22:31:12 +02:00
'index.php?distroquery=1&repo=$matches[1]' , 'top' );
2024-06-29 12:52:20 +02:00
add_rewrite_rule ( '^rpms/?' ,
2024-06-01 22:31:12 +02:00
'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' ;
} );