コード例 #1
0
 /**
  * @see parent::displayMessage
  */
 function displayMessage($message, $header = null)
 {
     if ($header) {
         $this->out(" ----- {$header} ----- ", 0);
     }
     $message = preg_replace("/[\r\n]+/", "\n", $message);
     $colors = array("|" => "red", "^" => "green", "~" => "blue", "&" => "magenta");
     //$message = preg_replace('/([^\|\^\~\&]+)/', shColorText($message, $_color, "white"), $message);
     foreach ($colors as $_char => $_color) {
         $message = str_replace($_char, shColorText($_char, $_color), $message);
     }
     echo "{$message}\n ------------------ \n";
 }
コード例 #2
0
ファイル: style.php プロジェクト: fbone/mediboard4
/**
 * Enable you to set font style with tags
 * Ex: This is a <c c=blue bg=white s=bold>TEST</c>
 * 
 * @param string $str String to set font style
 * 
 * @return string
 */
function parseShColorTag($str)
{
    $tag = "/(<c[^>]*>)([^<]*)<\\/c>/";
    $innerTag = "/([\\w]+)=([\\w]+)/";
    preg_match_all($tag, $str, $r);
    if (!is_array($r[1])) {
        return $str;
    }
    foreach ($r[1] as $k => $v) {
        preg_match_all($innerTag, $v, $r2);
        if (!is_array($r2[1])) {
            return $str;
        }
        $c = $bg = $s = false;
        while (list($i, $value) = each($r2[1])) {
            switch ($value) {
                case 'c':
                    $c = $r2[2][$i];
                    break;
                case 'bg':
                    $bg = $r2[2][$i];
                    break;
                case 's':
                    $s = $r2[2][$i];
                    break;
            }
        }
        $string = shColorText($r[2][$k], $c, $bg, $s);
        $str = str_replace($r[0][$k], $string, $str);
    }
    return $str;
}
コード例 #3
0
ファイル: setup.php プロジェクト: fbone/mediboard4
/**
 * Setup Mediboard
 * 
 * @param string $subDir    modules|style
 * @param string $apacheGrp Name of the primary group for apache user
 *
 * @return void
 */
function setup($subDir, $apacheGrp)
{
    $currentDir = dirname(__FILE__);
    announce_script("Mediboard directories groups and mods");
    if (Task::isWindows()) {
        echo shColorText("This script does not work on Windows\n", "red");
        return;
    }
    $darwin_kernel = PHP_OS;
    // To MAC
    if ($darwin_kernel == "Darwin") {
        $APACHE_USER = trim(shell_exec("ps -ef|grep httpd|head -2|tail -1|cut -d' ' -f4"));
        $APACHE_GROUP = trim(shell_exec("groups " . $APACHE_USER . " | cut -d' ' -f1"));
    } else {
        $APACHE_USER = trim(shell_exec("ps -ef|grep apache|grep -v grep|head -2|tail -1|cut -d' ' -f1"));
        $APACHE_GROUP = trim(shell_exec("groups " . $APACHE_USER . " | cut -d' ' -f3"));
    }
    if ($apacheGrp != null) {
        $APACHE_GROUP = $apacheGrp;
    }
    $fic = fopen("/etc/group", "r");
    while (!feof($fic)) {
        $buffer = fgets($fic);
        if (preg_match("/^({$APACHE_GROUP}:)/m", $buffer)) {
            echo $APACHE_GROUP . " group exists!\n";
            // Check optional sub-directory
            switch ($subDir) {
                case "modules":
                    $BASE_PATH = "modules";
                    break;
                case "style":
                    $BASE_PATH = "style";
                    break;
                default:
                    $BASE_PATH = dirname($currentDir);
                    $SUB_PATH = array("lib/", "tmp/", "files/", "includes/", "modules/*/locales/", "modules/hprimxml/xsd/", "locales/*/");
            }
            // Change to Mediboard directory
            $MB_PATH = dirname($currentDir);
            chdir($MB_PATH);
            // Change group to allow Apache to access files as group
            $chgrp = recurse_chgrp($BASE_PATH, $APACHE_GROUP);
            check_errs($chgrp, false, "Failed to change files group to " . $APACHE_GROUP, "Files group changed to " . $APACHE_GROUP . "!");
            // Remove write access to all files for group and other
            $chmod = chmod_R($BASE_PATH, 0755, 0755);
            check_errs($chmod, false, "Failed to protect all files from writing", "Files protected from writing!");
            if ($BASE_PATH == dirname($currentDir)) {
                // Give write access to Apache for some directories
                foreach ($SUB_PATH as $ONE_PATH) {
                    foreach (glob($ONE_PATH) as $myPATH) {
                        $chmod = chmod_R($myPATH, 0765, 0765);
                    }
                }
                check_errs($chmod, false, "Failed to allow Apache writing to mandatory files", "Apache writing allowed for mandatory files!");
            }
            fclose($fic);
            return 1;
        }
    }
    echo "Error: group " . $APACHE_GROUP . " does not exist\n";
    return 0;
}