wordpress-theme-openmamba/functions.php

269 lines
11 KiB
PHP
Raw Normal View History

2014-11-02 14:14:46 +01:00
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) {
exit;
}
2015-02-22 16:02:17 +01:00
function openmamba_breadcrumbs() {
$text['category'] = '';
}
// 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');
}
add_action('wp_print_styles', 'add_custom_font');
2014-11-02 14:14:46 +01:00
// add styles and scripts
function add_custom_scripts() {
wp_deregister_script('jquery');
$protocol = 'http:';
if($_SERVER['HTTPS']=='on') {
$protocol='https:';
}
wp_register_script('jquery', $protocol.'//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false, '1.11.3');
wp_enqueue_script('jquery');
$JQUERY_LOADED = true;
wp_register_script('jquerymigrate', $protocol.'//code.jquery.com/jquery-migrate-1.2.1.min.js', false, '1.2.1');
wp_enqueue_script('jquerymigrate');
}
add_action('template_redirect', 'add_custom_scripts');
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);
2014-11-02 14:14:46 +01:00
// openmamba downloads pages
function openmamba_download_link($milestone, $medium, $currarch, $ext, $mlword, $lang) {
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 = '';
if ($lang != "it") {
2015-10-17 14:16:26 +02:00
$downloadmirror = 'http://cdn.openmamba.org/pub/openmamba/media';
} else {
$downloadmirror = '/media';
}
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>";
$ret .= "<td style='border:0;margin:0;padding:4px;'><h5 style='margin:1px;'><a href=\"" . $downloadmirror. "/$milestone/$medium/$lang/".
$nameMedium[$medium.'-'.$currreleasetag.'-'.$lang.'-'.$currarch]."\">";
2015-01-09 13:45:16 +01:00
$ret .= "openmamba $displaymilestone $medium ";
$ret .= __('for','responsive')." $currarch ($mlword)</a>&nbsp;</h5>";
$ret .= "<i>";
$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], ' '));
2015-01-09 13:45:16 +01:00
$ret .= "; Md5: " . $md5Medium[$medium.'-'.$currreleasetag.'-'.$lang.'-'.$currarch];
$ret .= "</i></td></tr></table>";
} 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)&nbsp;</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>";
}
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 = '';
if ($script_file) {
$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',
'archs' => 'x86_64;i586;arm', // 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", "i586", "arm");
$mediaprefix = '/var/ftp/pub/openmamba/media';
$mediafallbackprefix = '/var/ftp/pub/openmamba/media/milestone2';
$outputlang = get_bloginfo("language");
$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);
while (list(, $currarch) = each($archname)) {
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');
while (list(, $currarch) = each($archname)) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$ret .= openmamba_download_link($milestone,$medium,$currarch,$ext,$langs[$outputlang],$outputlang);
}
foreach ($langs as $l => $lang) {
if ($l == $outputlang) continue;
reset($archname);
while (list(, $currarch) = each($archname)) {
if (strpos(";".$a['archs'].";",$currarch) == false) continue;
$out .= openmamba_download_link($milestone,$medium,$currarch,$ext,$lang,$l);
}
2014-11-02 14:14:46 +01:00
}
2015-01-09 13:45:16 +01: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
$ret .= do_shortcode("&nbsp;&nbsp;&nbsp;[expand title=\"".__("Features",responsive)."\"]".
openmamba_infofile($mediaprefix,$milestone,$fallbackmilestone,$medium,$outputlang,"features").
"[/expand]");
$ret .= do_shortcode("&nbsp;&nbsp;&nbsp;[expand title=\"".__("Requirements",responsive)."\"]".
openmamba_infofile($mediaprefix,$milestone,$fallbackmilestone,$medium,$outputlang,"requirements").
"[/expand]");
$ret .= do_shortcode("&nbsp;&nbsp;&nbsp;[expand title=\"".__("Preparation",responsive)."\"]".
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 ) {
$urlargspos = strpos($_SERVER[REQUEST_URI], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER[REQUEST_URI], $urlargspos);
}
2014-11-13 21:33:23 +01:00
$a = shortcode_atts( array(
'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);
print "<script>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');
function openmamba_webbuild_status_func() {
$urlargspos = strpos($_SERVER[REQUEST_URI], '?');
if ($urlargspos > 0) {
$urlargs = substr($_SERVER[REQUEST_URI], $urlargspos);
}
// print "<table width=\"100%\" style=\"border:0;\"><tr><td>";
2015-04-06 20:46:06 +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 "<span class=webbuild id=\"output\">Loading, please wait...</span>";
print "<script>webbuild_status_getvalues(\"" . $urlargs . "\");</script>";//</td></tr></table>";
}
add_shortcode('openmamba_webbuild_status', 'openmamba_webbuild_status_func');
2015-04-06 20:46:06 +02:00
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")
2015-04-06 20:46:06 +02:00
$outputlang = "it_IT.UTF-8";
else
$outputlang = "en_US.UTF-8";
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 "<br><span id=\"queryform\"></span><br>";
print "<span id=\"querystatus\"></span><br><span id=\"queryreply\">&nbsp;</span>";
print "<script>distroquery_request(\"" . $urlargs . "\");</script>";
}
add_shortcode('openmamba_distroquery', 'openmamba_distroquery_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;
}
load_plugin_textdomain('theme-my-login' , get_site_url() . 'wp-content/plugins/theme-my-login/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);
$message = __("This website uses cookies to improve user experience.",responsive);
$accepttext = __("I Understand",responsive);
$policytext = __("Cookie policy",responsive);
$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";
echo $output;
}