import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.awt.Color; import readers.Box; import readers.fonts.Font; import readers.ColorRange; public class sigPlace { final static String ROOTDIR = "sitefiles"; final static String REFDIR = "ref"; final static String OUTDIR = "out"; final static String ARTICLESDIR = "articles"; final static String UPLOADSDIR = "uploads"; final static String COMMENTSDIR = "comments"; final static String DIRECTORYLISTING_FILENAME = "DIRECTORY_LISTING"; static int PORT = 8080; static String SECRET = ""; static double COLOR_ROTATION = 0; static boolean inCodeBlock = false; static String storedCodeBlock = ""; final static HashMap map = new HashMap<>(Map.ofEntries( new AbstractMap.SimpleEntry<>("$SITENAME", "SigPlace"), new AbstractMap.SimpleEntry<>("$SITE_BACKCOL", "#111"), new AbstractMap.SimpleEntry<>("$TITLE_CONTENT_START", "

"), new AbstractMap.SimpleEntry<>("$TITLE_CONTENT_END", "

"), new AbstractMap.SimpleEntry<>("$CONTENT_END", "
"), new AbstractMap.SimpleEntry<>("$DATE_CONTENT_START", "
") )); final static HashMap ops = new HashMap<>(Map.ofEntries( new AbstractMap.SimpleEntry<>( "%DEFAULT", Paths.get(REFDIR,"DEFAULT.html")), new AbstractMap.SimpleEntry<>( "%NAVBAR", Paths.get(REFDIR,"NAVBAR.html")), new AbstractMap.SimpleEntry<>( "%FOOTER", Paths.get(REFDIR,"FOOTER.html")) )); static void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) { seek(arr,i,SEEKCOLOR,FINALCOLOR,width,0); } static int seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width,int farthestRight) { arr[i]=FINALCOLOR.getRGB(); int X = i%width; for (int x=-1;x<=1;x++) { for (int y=-1;y<=1;y++) { int newX=(i+x+y*width)%width; int newY=(i+x+y*width)/width; if (newX>=0&&newY>=0&&newX<=width&&newY<=arr.length/width) { Color col = new Color(arr[i+x+y*width]); if (!col.equals(Color.MAGENTA)&&SEEKCOLOR.colorInRange(col)) { farthestRight=seek(arr,i+x+y*width,SEEKCOLOR,FINALCOLOR,width,farthestRight); } } } } return X>farthestRight?X:farthestRight; } final static int TRANSPARENT = new Color(0,0,0,0).getRGB(); public static void main(String[] args) { /*String fontName = "sdvx_littleScore"; String value = "9328"; Path f = Paths.get("sdvx1.png"); BufferedImage img; try { img = ImageIO.read(f.toFile()); Box scoreBox = new Box(717,1096,146,34); int[] arr = img.getRGB(scoreBox.x, scoreBox.y, scoreBox.w, scoreBox.h, null, 0, scoreBox.w); BufferedImage newImg = new BufferedImage(scoreBox.w,scoreBox.h,BufferedImage.TYPE_INT_ARGB); final ColorRange TARGETCOLOR = new ColorRange(160,255,170,255,190,255); final ColorRange SEEKINGCOLOR = new ColorRange(26,255,53,255,80,255); final Color FINALCOLOR = Color.MAGENTA; for (int i=0;i data; try { data = Files.readAllLines(secretFile); SECRET = data.get(0); } catch (IOException e1) { System.out.println("Client secret must be included in .clientsecret!"); e1.printStackTrace(); } if (args.length>0&&args.length%2==0) { int i=0; while (i items = Files.walk(Paths.get("out")).filter((p)->!p.toAbsolutePath().toString().contains("images/")).iterator(); ParseArticleFiles(items); items = Files.walk(Paths.get("out")).iterator(); ConvertArticleReferences(items); items = Files.walk(Paths.get("out","articles")).iterator(); GenerateArticleFiles(items); }catch (IOException e) { e.printStackTrace(); System.err.println("Copying files over failed!"); return; } System.out.println("Building directory listings..."); try { buildDirectoryListings(); } catch (IOException e) { e.printStackTrace(); System.err.println("Failed to build directory listings!"); return; } System.out.println("Site has been built into the "+OUTDIR+" directory."); ExportCodeFile(); System.out.println("\nStarting web server..."); new sigServer(); } private static String JSON(HashMap testMap) { StringBuilder sb = new StringBuilder(); String temp = testMap.toString(); if (temp.charAt(0)=='{') { sb.append("{"); int marker=1; boolean ending=false; while (marker items) { while (items.hasNext()) { Path f = items.next(); System.out.println(" Found "+f.getFileName()); if (Files.isRegularFile(f)) { try { System.out.println(" Preparing "+f.getFileName()); List content = Files.readAllLines(f); if (isHTMLFile(f)) { content.addAll(0,Files.readAllLines(ops.get("%NAVBAR"))); content.addAll(0,Files.readAllLines(ops.get("%DEFAULT"))); content.addAll(Files.readAllLines(ops.get("%FOOTER"))); } System.out.println(" Parsing "+f.getFileName()); for (int i=0;i0&&(isHTMLFile(f)||isArticleFile(f))) { if (!inCodeBlock) { if (s.trim().equals("
")) {
                                    //System.out.println("Inside 
");
                                    inCodeBlock=true;
                                    storedCodeBlock="";
                                    s=s.substring(0,s.indexOf("
"));
                                }
                            }
                            if (inCodeBlock&&s.trim().equals("
")) { inCodeBlock=false; boolean keyword=false; boolean inString=false; boolean inComment=false; boolean inMultiLineComment=false; char stringChar=' '; boolean canBeNumericalConstant=false; int lengthOfConstant=0; storedCodeBlock+=s.substring(0,s.indexOf("
")); storedCodeBlock=storedCodeBlock.replaceAll(Pattern.quote("<"),"\2"); storedCodeBlock+="
"; int startPos=0; String endText=s.substring(s.indexOf("")+"".length(),s.length()); s=""; for (int j=0;j"; startPos=j+1; } if (!inComment&&!inMultiLineComment&&(j>0&&storedCodeBlock.charAt(j-1)!='\\'&&(!inString&&(storedCodeBlock.charAt(j)=='"'||storedCodeBlock.charAt(j)=='\'')||inString&&(storedCodeBlock.charAt(j)==stringChar)))) { inString=!inString; if (inString) { stringChar=storedCodeBlock.charAt(j); s+=SPAN("string")+stringChar; } else { s+=stringChar; s+=""; startPos=j+1; } } else if (!inString) { if (canBeNumericalConstant&&validNumericalConstantCharacters(lengthOfConstant, j)) { lengthOfConstant++; //System.out.println("Length of Constant now "+lengthOfConstant); } if (j>0&&storedCodeBlock.charAt(j)=='/'&&storedCodeBlock.charAt(j+1)=='*'||inMultiLineComment) { if (!inMultiLineComment) { inMultiLineComment=true; } else { if (storedCodeBlock.charAt(j-1)=='*'&&storedCodeBlock.charAt(j)=='/') { inMultiLineComment=false; s+=SPAN("comment")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+""; startPos=j+1; } } //Stops further execution since we're in a comment. } else if (j>0&&storedCodeBlock.charAt(j)=='/'&&storedCodeBlock.charAt(j+1)=='/'||inComment) { if (!inComment) { inComment=true; } //Stops further execution since we're in a comment. } else if (canBeNumericalConstant&&lengthOfConstant>0&&!(validNumericalConstantCharacters(lengthOfConstant, j))) { s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+""+storedCodeBlock.charAt(j); //System.out.println("Setting "+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)); lengthOfConstant=0; canBeNumericalConstant=false; startPos=j+1; } else if (!canBeNumericalConstant&&storedCodeBlock.charAt(j)=='.') { //Previous section was a member. s+=SPAN("class")+storedCodeBlock.substring(startPos,j)+""+storedCodeBlock.charAt(j); startPos=j+1; } else if (j>3&&storedCodeBlock.substring(j-3,j+1).equals("true")&&!isAlphanumeric(j-4)&&!isAlphanumeric(j+1)) { s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+""; startPos=j+1; } else if (j>4&&storedCodeBlock.substring(j-4,j+1).equals("false")&&!isAlphanumeric(j-5)&&!isAlphanumeric(j+1)) { s+=SPAN("number")+storedCodeBlock.substring(startPos,j)+storedCodeBlock.charAt(j)+""; startPos=j+1; } else if (storedCodeBlock.charAt(j)=='(') { s+=SPAN("function")+storedCodeBlock.substring(startPos,j)+""+storedCodeBlock.charAt(j); startPos=j+1; } else if (j>0&&isAlphanumeric(j-1) && storedCodeBlock.charAt(j)==' '&&storedCodeBlock.charAt(j-1)!=' ') { //Previous section was a keyword. keyword=true; s+=SPAN("keyword")+storedCodeBlock.substring(startPos,j)+""+storedCodeBlock.charAt(j); startPos=j+1; } else if (j>0&&isAlphanumeric(j-1) && (storedCodeBlock.charAt(j)==';'||storedCodeBlock.charAt(j)==':')) { //Previous section was a keyword. //keyword=true; s+=SPAN("keyword")+storedCodeBlock.substring(startPos,j)+""+storedCodeBlock.charAt(j); startPos=j+1; } else if (keyword&&!(storedCodeBlock.charAt(j)=='_'||storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9'||storedCodeBlock.charAt(j)>='A'&&storedCodeBlock.charAt(j)<='Z'||storedCodeBlock.charAt(j)>='a'&&storedCodeBlock.charAt(j)<='z'||storedCodeBlock.charAt(j)==' ')) { keyword=false; s+=SPAN("variable")+storedCodeBlock.substring(startPos,j)+""+storedCodeBlock.charAt(j); startPos=j+1; } else if (!isAlphanumeric(j)){ if (startPos='0'&&storedCodeBlock.charAt(j)<='9')) { canBeNumericalConstant=false; } if (!canBeNumericalConstant&&!isAlphanumeric(j)) { canBeNumericalConstant=true; lengthOfConstant=0; //System.out.println("Found "+storedCodeBlock.charAt(j)+", can be numeric..."); } } for (int j=0;j0&&isArticleFile(f)&&!inCodeBlock) { //Check for markdown pieces. if (s.charAt(0)=='-') { //Start of a title piece. s=s.replace("-",map.get("$TITLE_CONTENT_START")); s=s+map.get("$TITLE_CONTENT_END").replace("%ID%","id=\"content_"+f+"\""); //Use โคˆ if there's more text to be shown than can fit. } else if (s.startsWith("===")) { s=map.get("$CONTENT_END")+map.get("$DATE_CONTENT_START")+s.replace("===","")+map.get("$CONTENT_END")+"%CONDITIONAL_EXPAND%"+map.get("$CONTENT_END"); } else if (s.charAt(0)==':') { //Image with caption. //Format: //:,,, String[] splitter = s.split(Pattern.quote(",")); StringBuilder captionText = new StringBuilder(splitter[3]); for (int j=4;j
"+captionText.toString()+"
"; } else { //It's regular content, so add paragraphs. s="

\n"+s+"\n

"; } } else { if (s.length()==0&&isArticleFile(f)&&!inCodeBlock) { s="
"; //Setup a line break here. } } if (!endPreLine) { for (String key : map.keySet()) { s=s.replaceAll(Pattern.quote(key),map.get(key)); } } if (s.trim().length()==0) { content.remove(i--); } else { content.set(i,s); } } System.out.println(" Writing to "+f.toAbsolutePath()); Files.write(f, content, Charset.defaultCharset(),StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE); System.out.println(" "+f.getFileName() + " conversion complete!"); } catch (IOException e) { e.printStackTrace(); } } } */ } private static boolean validNumericalConstantCharacters(int lengthOfConstant, int j) { return storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9'||lengthOfConstant>0&&storedCodeBlock.charAt(j)=='.'||lengthOfConstant>0&&storedCodeBlock.charAt(j)>='A'&&lengthOfConstant>0&&storedCodeBlock.charAt(j)<='F'||lengthOfConstant>0&&storedCodeBlock.charAt(j)>='a'&&lengthOfConstant>0&&storedCodeBlock.charAt(j)<='f'||lengthOfConstant>0&&storedCodeBlock.charAt(j)=='x'||lengthOfConstant>0&&storedCodeBlock.charAt(j)=='X'; } private static boolean isAlphanumeric(int j) { return storedCodeBlock.charAt(j)>='0'&&storedCodeBlock.charAt(j)<='9'||storedCodeBlock.charAt(j)>='A'&&storedCodeBlock.charAt(j)<='Z'||storedCodeBlock.charAt(j)>='a'&&storedCodeBlock.charAt(j)<='z'; } /** * Writes a span tag with the included class. * **/ private static String SPAN(String className) { return ""; } private static void GenerateArticleFiles(Iterator items){ System.out.println(" Generating article files..."); while (items.hasNext()) { Path f = items.next(); try { if (Files.isRegularFile(f)&&isArticleFile(f)) { boolean inCodeBlock = false; System.out.println(" Creating article for "+f.getFileName()); List content = Files.readAllLines(f); List preContent = Files.readAllLines(ops.get("%DEFAULT")); preContent.addAll(Files.readAllLines(ops.get("%NAVBAR"))); List postContent = Files.readAllLines(ops.get("%FOOTER")); StringBuilder sb = new StringBuilder(); for (String d : preContent) { for (String k : sigPlace.map.keySet()) { d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k)); } sb.append(d).append("\n"); } int lineNumb=0; for (String d : content) { lineNumb++; if (d.trim().equals("
")) {
                            System.out.println("
 in "+f+" Line "+lineNumb+": "+d);
                            inCodeBlock=true;
                        }
                        if (inCodeBlock&&d.trim().equals("
")) { inCodeBlock=false; } if (!inCodeBlock) { for (String k : sigPlace.map.keySet()) { d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k)); } d=d.replaceFirst("div class=\"content\"","div class=\"expandedContent\""); d=d.replaceFirst("%CONDITIONAL_EXPAND%",""); } sb.append(d).append("\n"); } System.out.println(" Generating comment section for "+f+"."); Path ff = Paths.get(REFDIR,"COMMENT.html"); List commentHTML = Files.readAllLines(ff); for (int i=0;i items) { while (items.hasNext()) { Path f = items.next(); System.out.println(" Looking for Article References..."+f.getFileName()); boolean articleJavascriptIncluded=false; if (Files.isRegularFile(f)&&isHTMLFile(f)) { System.out.println(" Searching "+f.getFileName()); try { List content = Files.readAllLines(f); for (int i=0;i0&&s.contains("$ARTICLE_PREVIEW")) { String article = ARTICLESDIR+"/"+s.replace("$ARTICLE_PREVIEW ","")+".article"; if (Files.exists(Paths.get(OUTDIR,article))) { System.out.println(" Found article preview request in "+f.getFileName()+" for article "+article+"."); Path file = Paths.get(OUTDIR,article); List newData = Files.readAllLines(file); if (newData.size()>0) { content.set(i,newData.get(0) .replace("

","

") .replace("

","

๐Ÿ”—")); for (int j=1;j



⤈ Click to expand.
"); content.set(i+newData.size()-1,lastline);//




⤈ Click to expand.
"); } else { content.set(i,""); } if (!articleJavascriptIncluded) { List articlejs = Files.readAllLines(Paths.get(REFDIR,"article.js")); for (int j=articlejs.size()-1;j>=0;j--) { content.add(i,articlejs.get(j)); } articleJavascriptIncluded=true; } } } } Files.write(f,content); } catch (IOException e) { e.printStackTrace(); } } } } static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { Files.walk(Paths.get(sourceDirectoryLocation)) .forEach(source -> { Path destination = Paths.get(destinationDirectoryLocation, source.toString() .substring(sourceDirectoryLocation.length())); try { if (Files.isDirectory(destination)) { Files.createDirectories(destination); } else { Files.copy(source, destination, new CopyOption[]{StandardCopyOption.COPY_ATTRIBUTES,StandardCopyOption.REPLACE_EXISTING}); } } catch (IOException e) { e.printStackTrace(); } }); } static void buildDirectoryListings() throws IOException { String startingPath=Paths.get(sigPlace.OUTDIR).toAbsolutePath().toString(); HashMap> map = new HashMap<>(); Iterator it = Files.walk(Paths.get(sigPlace.OUTDIR)).iterator(); map.put("/",new ArrayList()); while (it.hasNext()) { Path f = it.next(); if (!f.getFileName().toString().equals(OUTDIR)) { String myKey = f.toAbsolutePath().toString().replace(startingPath,"").replace(f.getFileName().toString(),""); //System.out.println(myKey+","+f); map.putIfAbsent(myKey,new ArrayList()); map.get(myKey).add(f); } } System.out.println("Directory structure determined:"); System.out.println(" "+map); for (String key : map.keySet()) { System.out.println("Creating directory listing for "+key+"..."); StringBuilder sb = new StringBuilder(""); List data = Files.readAllLines(ops.get("%DEFAULT")); List data2 = Files.readAllLines(ops.get("%FOOTER")); for (String d : data) { for (String k : sigPlace.map.keySet()) { d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k)); } sb.append(d).append("\n"); } sb.append("

Directory Listing for "+key+"

"); sb.append(""); for (Path f : map.get(key)) { sb.append("
") .append("") .append((Files.isDirectory(f)?"📁":"🗎")) .append("") .append("") .append(f.getFileName()) .append("\t") .append(Files.getLastModifiedTime(f)) .append("\t") .append(Files.getOwner(f)) .append("\t") .append(Files.size(f)) .append("
\n"); } for (String d : data2) { for (String k : sigPlace.map.keySet()) { d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k)); } sb.append(d).append("\n"); } Path newf = Files.write(Paths.get(OUTDIR,key,DIRECTORYLISTING_FILENAME),sb.toString().getBytes()); System.out.println(" Added info for ("+map.size()+") files to "+newf.toAbsolutePath()); } } private static boolean isArticleFile(Path f) { return f.getFileName().toString().contains(".article"); } private static boolean isHTMLFile(Path f) { return f.getFileName().toString().contains(".html"); } private static void ExportCodeFile() { try { Path file = Paths.get("sigServer.java"); List data = Files.readAllLines(file); int i=0; while (!data.get(i++).contains("sigServer()")&&i