Tacoen's shared code-snipsets
define("DEBUG", 1); define("DIR", "D:/zararadio/"); define("DIR_CONF", DIR."bin/"); define("DIR_TPL", DIR."template/"); define("DIR_SEQ", DIR."sequences/"); define("DIR_PLS", DIR."playlist/"); define("DIR_VOC", DIR."voice/"); define("DIR_ADS", DIR."ads/"); define("DIR_ADS", DIR."text/"); define("DIR_AUTO", DIR."auto/"); $whari = array( "minggu", "senin", "selasa", "rabu", "kamis", "jumat", "sabtu"); $hh = $whari[date("w",time())]; $jj = date("H",time()); $mmdd = date("m-d",time()); // what to queries $q0 = "*:*"; $q1 = "$hh:*"; $q2 = "*:$jj"; $q3 = "$hh:$jj"; if ($jj < 6) { $q4= "subuh"; } if (($jj >= 6) & ($jj < 10)) { $q4= "pagi"; } if (($jj >= 10) & ($jj < 14)) { $q4= "siang"; } if (($jj >= 14) & ($jj < 18)) { $q4= "sore"; } if (($jj >= 18) & ($jj <= 23)) { $q4= "malam"; } $q5 = "$mmdd:*"; $q6 = "$mmdd:$jj"; $object = array ( "ads0" => DIR_ADS, "ads1" => DIR_ADS, "ads2" => DIR_ADS, "ads3" => DIR_ADS, "ads4" => DIR_ADS, "pls0" => DIR_PLS, "pls1" => DIR_PLS, "pls2" => DIR_PLS, "pls3" => DIR_PLS, "pls4" => DIR_PLS, "seq0" => DIR_SEQ, "seq1" => DIR_SEQ, "seq2" => DIR_SEQ, "seq3" => DIR_SEQ, "seq4" => DIR_SEQ, "voc-talk" => DIR_VOC, "voc-open" => DIR_VOC, "voc-close" => DIR_VOC, "text" => DIR_TXT, "lock" => "" ); function pre_check($f,$o) { global $object; $ext = array ("lst","mp3","rot","seq"); if ($f) { foreach ($ext as $e) { $fi = $object[$o]."$f.$e"; if (file_exists($fi)) { $fc=$fi; } } return $fc; } } function make_values($I) { global $object, $q0, $q1, $q2, $q3, $q4, $q5, $q6; $values = array(); // Main function, make variable foreach (array_keys($object) as $o) { $values["$$o"] = pre_check($I["$q6"][$o],$o); /* 12-25:jam */ if (is_null ($values["$$o"])) { $values["$$o"] = pre_check($I["$q5"][$o],$o); } /* 12-25:* */ if (is_null ($values["$$o"])) { $values["$$o"] = pre_check($I["$q3"][$o],$o); } /* full */ if (is_null ($values["$$o"])) { $values["$$o"] = pre_check($I["$q2"][$o],$o); } /* jam */ if (is_null ($values["$$o"])) { $values["$$o"] = pre_check($I["$q1"][$o],$o); } /* hari */ if (is_null ($values["$$o"])) { $values["$$o"] = pre_check($I["$q4"][$o],$o); } /* siang/sore */ if (is_null ($values["$$o"])) { $values["$$o"] = pre_check($I["$q0"][$o],$o); } /* default values */ } return $values; } // Load configurations $values = make_values(parse_ini_file(DIR_CONF."claudio.ini",true)); if (DEBUG) { print_r($values); } $template = array ( "open.lst","close.lst","restart.lst", "apc.seq","auto1.lst","auto2.lst","auto3.lst", "ts1.seq","ts2.seq","ts3.seq", ); function parse_template($temp) { global $object, $q0, $q1, $q2, $q3, $q4, $q5, $q6, $values; foreach (array_keys($object) as $o) { if ($values["$$o"]) { $temp = preg_replace("/%".$o."%/i", "-1\t".$values["$$o"], $temp); } else { $temp = preg_replace("/%".$o."%/i", "", $temp); } } $temp = preg_replace("/^-1\t*[\n|\r]/", "", $temp); $temp = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $temp); $temp = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $temp); $temp = preg_replace("/\//","\\",$temp); /* win32 slash */ // count $c = explode("\n",$temp); $counter = count($c)-1; $finetemp = $counter . "\n" .$temp; return $finetemp; } foreach ($template as $tpl) { $temp = ""; if (file_exists(DIR_TPL.$tpl)) { $T = file(DIR_TPL.$tpl); $temp = implode ($T); $temp = $temp."\n"; $temp = parse_template($temp); if ($temp) { echo "$tpl\n\n$temp\n---------------\n"; } } } // Unfinished: Write $temp to new files //
sub CreateLST { my ($tpl_file,$output)=@_; my $spl; my $tpl = uc(tacoenf::load_as_string($tpl_file)); $tpl =~ s/\%pause(.*)\%/&pause($1,$sn)/gie; $tpl =~ s/\%(.*)\%/"-1\t".$file{uc($1)}/gie; $tpl = &removeblank($tpl); my $ntpl = @ntpl = split(/\n/,$tpl); my $str = $ntpl."\n".$tpl."\n"; tacoenf::save_file($output,$str,0); if ($debug) { print $tpl_file." -> ".$output."\n"; print "-"x60; print "\n"; print $str; print "-"x60; print "\n\n"; } } sub CreateSEQ { my ($tpl_file,$output)=@_; my $sn=0; my $str; my @ntpl = tacoenf::load_as_array($tpl_file); foreach $tpl(@ntpl) { $tpl =~ s/\%time\%/"file$sn=.time\nlength$n=-1\n"/gie; $tpl =~ s/\%pause(.*)\%/&seqpause($1,$sn)/gie; $tpl =~ s/\%(.*)\%/"file$sn=".$file{uc($1)}."\nlength$n=-1\n"/gie; $str .=$tpl; $sn++; } $str = &removeblank(&removeblank($str)); $strn = "\n[playlist]\n\n".$str."\nNumberofentries=".$sn."\nnextindex=0\n"; tacoenf::save_file($output,$strn,0); if ($debug) { print $tpl_file." -> ".$output."\n"; print "-"x60; print "\n"; print $strn; print "-"x60; print "\n\n"; } } sub removeblank { my $str = shift; $str =~ s/-1\t\n/\n/gi; $str =~ s/\n\n/\n/gi; $str =~ s/^[\s]//gi; $str =~ s/[\s]$//gi; return $str; } sub seqpause { my ($p,$n) = @_; my $pa = $p*1000; return "file$n=$p.pause\nlength=$pa\n"; } sub pause { my $p = shift; my $pa = $p*1000; return "$pa\t$p.pause"; }