├── .gitignore ├── README.md ├── about.php ├── account.php ├── admin ├── footer.php ├── header.php ├── index.php ├── login.php ├── logout.php ├── preview.php ├── problems.php ├── profile.php ├── update.php └── users.php ├── codejudge-compiler ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ └── codejudge │ └── compiler │ ├── CodejudgeCompiler.java │ ├── RequestThread.java │ ├── TimedShell.java │ └── languages │ ├── C.java │ ├── Cpp.java │ ├── Java.java │ ├── Language.java │ └── Python.java ├── css ├── bootstrap-responsive.css └── bootstrap.css ├── eval.php ├── footer.php ├── functions.php ├── header.php ├── index.php ├── install.php ├── js ├── bootstrap-alert.js ├── bootstrap-button.js ├── bootstrap-carousel.js ├── bootstrap-collapse.js ├── bootstrap-dropdown.js ├── bootstrap-modal.js ├── bootstrap-popover.js ├── bootstrap-scrollspy.js ├── bootstrap-tab.js ├── bootstrap-tooltip.js ├── bootstrap-transition.js ├── bootstrap-typeahead.js └── jquery.js ├── license.txt ├── login.php ├── logout.php ├── markdown.php ├── scoreboard.php ├── solve.php ├── submissions.php └── update.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Codejudge .gitignore 2 | *~ 3 | dbinfo.php 4 | *.class 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Codejudge 2 | ========= 3 | 4 | **NOTE: This project is not maintained anymore!** 5 | 6 | Coding competitions are now easy to organise anytime, anywhere. 7 | 8 | Codejudge can be run from any PHP, MySQL server and can be used to power any coding competition and evaluate its solutions automatically. 9 | 10 | No need to run to big companies to host your event. You can set up Codejudge almost anywhere and anytime! 11 | 12 | ### Note 13 | 14 | Bleeding edge changes are on the `develop` branch and things most likely don't work there. You are recomended to use the `master` branch. If you love to experiment then go for the `develop` branch. 15 | 16 | A follow-up project to create a better judge was being worked on, but kind of stalled at the moment (due to lack of time from my side). Take a look at [judgev2](https://github.com/sankha93/judgev2) 17 | 18 | -------------------------------------------------------------------------------- /about.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | About Codejudge 14 | 15 | 16 | 17 | 18 | 19 | 20 | 30 | 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
48 |

Codejudge


49 |

Codejudge is a system used to hold coding competitions like this. Its easy to setup, fast and simple to use.

50 |

Codejudge is made by Sankha Narayan Guria. Find him at @sankha93 on Twitter.
51 | Mail me at sankha93@gmail.com.

52 |

Visit the Codejudge website at http://sankha93.github.com/codejudge for more information.

53 |
54 | 55 | 58 | -------------------------------------------------------------------------------- /account.php: -------------------------------------------------------------------------------- 1 | 16 |
  • Problems
  • 17 |
  • Submissions
  • 18 |
  • Scoreboard
  • 19 |
  • Account
  • 20 |
  • Logout
  • 21 | 22 | 23 | 24 | 25 | 26 | 27 |
    28 | \nAccount settings updated!\n
    "); 31 | else if(isset($_GET['passerror'])) 32 | echo("
    \nThe old password you entered is wrong. Please enter the correct password and try again.\n
    "); 33 | else if(isset($_GET['derror'])) 34 | echo("
    \nPlease enter all the details asked before you can continue!\n
    "); 35 | ?> 36 | Account settings for
    37 |
    38 | 39 |

    Change Password

    40 | Old password:
    41 | New password:

    42 | 43 |
    44 |
    45 | 46 |
    47 | 48 |

    Change Email

    49 | 54 | Email:

    55 | 56 |
    57 | 58 | 59 | 62 | -------------------------------------------------------------------------------- /admin/footer.php: -------------------------------------------------------------------------------- 1 | 10 |
    11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /admin/header.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | Codejudge Admin Panel 15 | 16 | 17 | 18 | 19 | 20 | 21 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 26 | 27 |
    28 | 29 | \nSettings Saved!\n
    "); 32 | else if(isset($_GET['passerror'])) 33 | echo("
    \nThe old password is incorrect!\n
    "); 34 | else if(isset($_GET['derror'])) 35 | echo("
    \nPlease enter all the details asked before you can continue!\n
    "); 36 | ?> 37 | 41 |
    42 |
    43 |
    44 | 49 | 50 | Name of event:
    51 | /> Accept submissions
    52 |

    Languages

    53 | /> C
    54 | /> C++
    55 | /> Java
    56 | /> Python

    57 | 58 |
    59 |
    60 | 61 |
    62 | 63 |

    Change Password

    64 | Old password:
    65 | New password:

    66 | 67 |
    68 |
    69 | 70 |
    71 | 72 |

    Change Email

    73 | 78 | Email:

    79 | 80 |
    81 |
    82 |
    83 | 84 | 85 | 88 | -------------------------------------------------------------------------------- /admin/login.php: -------------------------------------------------------------------------------- 1 | 30 | 31 | 32 | 33 | 34 | Codejudge Admin Panel Login 35 | 36 | 37 | 38 | 39 | 40 | 41 | 51 | 52 | 53 | 54 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 80 | 81 |
    82 | 83 | \nYou have logged out successfully!\n
    "); 86 | else if(isset($_GET['error'])) 87 | echo("
    \nIncorrect Password!\n
    "); 88 | else if(isset($_GET['derror'])) 89 | echo("
    \nPlease enter all the details asked before you can continue!\n
    "); 90 | ?> 91 |

    Login

    92 |

    Please login to use the admin panel.


    93 |
    94 | Password:

    95 | 96 |
    97 | 98 | 99 | 102 | -------------------------------------------------------------------------------- /admin/logout.php: -------------------------------------------------------------------------------- 1 | 17 | -------------------------------------------------------------------------------- /admin/preview.php: -------------------------------------------------------------------------------- 1 | You have not entered either the title or the problem text!"); 13 | else { 14 | include('../markdown.php'); 15 | $out = Markdown($_POST['text']); 16 | echo("
    \n

    ".$_POST['title']."

    \n"); 17 | echo($out); 18 | } 19 | } else if($_POST['action'] == 'code' and is_numeric($_POST['id'])) { 20 | // formatting for codes 21 | include('../functions.php'); 22 | connectdb(); 23 | echo("

    ".$_POST['name']."

    \n"); 24 | $query = "SELECT filename, soln FROM solve WHERE (username='".mysql_real_escape_string($_POST['uname'])."' AND problem_id='".$_POST['id']."')"; 25 | $result = mysql_query($query); 26 | $row = mysql_fetch_array($result); 27 | $str = str_replace("<", "<", $row['soln']); 28 | echo("".$row['filename']."

    \n
    ".str_replace(">", ">", $str)."
    "); 29 | } 30 | ?> 31 | -------------------------------------------------------------------------------- /admin/problems.php: -------------------------------------------------------------------------------- 1 | 18 |
  • Admin Panel
  • 19 |
  • Users
  • 20 |
  • Logout
  • 21 | 22 | 23 | 24 | 25 | 26 | 27 |
    28 | \nProblem added!\n
    "); 31 | else if(isset($_GET['deleted'])) 32 | echo("
    \nProblem deleted!\n
    "); 33 | else if(isset($_GET['updated'])) 34 | echo("
    \nProblem updated!\n
    "); 35 | else if(isset($_GET['derror'])) 36 | echo("
    \nPlease enter all the details asked before you can continue!\n
    "); 37 | ?> 38 | 42 |
    43 |
    44 | Below is a list of already added problems. Click on a problem to edit it. 45 | 71 |
    72 | 76 |

    Edit a Problem

    77 |
    78 | 79 | 80 | 85 |
    86 |
    87 | Problem Title:
    88 |
    89 |
    90 | Time Limit: ms 91 |
    92 |
    93 |
    94 | Detailed problem: Markdown formatting supported

    95 |
    96 |
    97 |
    98 |
    99 |
    100 |
    101 |
    102 |
    103 |
    104 | 105 | 106 | 107 |
    108 |
    109 | 111 |

    Add a Problem

    112 |
    113 | 114 | 119 |
    120 |
    121 | Problem Title:
    122 |
    123 |
    124 | Time Limit: ms 125 |
    126 |
    127 |
    128 | Detailed problem: Markdown formatting supported

    129 |
    130 |
    131 |
    132 |
    133 |
    134 |
    135 |
    136 |
    137 |
    138 | 139 | 140 |
    141 |
    142 | 143 |
    144 |
    145 | 146 | 149 | -------------------------------------------------------------------------------- /admin/profile.php: -------------------------------------------------------------------------------- 1 | 18 |
  • Admin Panel
  • 19 |
  • Users
  • 20 |
  • Logout
  • 21 | 22 | 23 | 24 | 25 | 26 | 27 |
    28 | 34 |

    Profile details for Banned");?>

    35 | Email: 36 |

    37 | Details of problems attempted: 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | \n"); 57 | else if($row['status'] == 2) 58 | echo("\n"); 59 | } 60 | } 61 | ?> 62 | 63 |
    ProblemAttemptsStatus
    ".$field['name']."".$row['attempts']); 55 | if($row['status'] == 1) 56 | echo("Attempted
    Solved
    64 |
    65 |
    66 | 67 | 70 | -------------------------------------------------------------------------------- /admin/update.php: -------------------------------------------------------------------------------- 1 | 91 | -------------------------------------------------------------------------------- /admin/users.php: -------------------------------------------------------------------------------- 1 | 18 |
  • Admin Panel
  • 19 |
  • Users
  • 20 |
  • Logout
  • 21 | 22 | 23 | 24 | 25 | 26 | 27 |
    28 | \nThe user has been banned.\n
    "); 31 | else if(isset($_GET['unbanned'])) 32 | echo("
    \nThe user has been unbanned.\n
    "); 33 | ?> 34 | Below is a list of users registered. You can view the details of the user or ban him. 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | \n"); 59 | else if($row['status'] == 0) 60 | echo("Unban\n"); 61 | } 62 | ?> 63 | 64 |
    NameSolvedAttemptedAction
    ".$row['username']); 51 | if($row['status'] == 0) 52 | echo(" Banned"); 53 | echo("".mysql_num_rows($res)); 54 | $sql = "SELECT * FROM solve WHERE (status='1' AND username='".$row['username']."')"; 55 | $res = mysql_query($sql); 56 | echo("".mysql_num_rows($res).""); 57 | if($row['status'] == 1) 58 | echo("Ban
    65 | 66 | 67 | 70 | -------------------------------------------------------------------------------- /codejudge-compiler/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /codejudge-compiler/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | codejudge-compiler 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /codejudge-compiler/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.6 12 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/CodejudgeCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server 7 | */ 8 | 9 | package codejudge.compiler; 10 | 11 | import java.io.IOException; 12 | import java.net.ServerSocket; 13 | import java.net.Socket; 14 | 15 | public class CodejudgeCompiler { 16 | 17 | public static void main(String args[]) { 18 | int n=0; 19 | try { 20 | ServerSocket server = new ServerSocket(3029); // create a new socket to listen on 21 | System.out.println("Codejudge compilation server running ..."); 22 | while(true) { 23 | n++; 24 | // accept any incoming connection and process it on a new thread 25 | Socket s = server.accept(); 26 | RequestThread request = new RequestThread(s, n); 27 | request.start(); 28 | } 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/RequestThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server : Thread that runs on each request 7 | */ 8 | 9 | package codejudge.compiler; 10 | 11 | import java.io.BufferedReader; 12 | import java.io.File; 13 | import java.io.FileInputStream; 14 | import java.io.FileNotFoundException; 15 | import java.io.FileOutputStream; 16 | import java.io.IOException; 17 | import java.io.InputStreamReader; 18 | import java.io.PrintWriter; 19 | import java.net.Socket; 20 | 21 | import codejudge.compiler.languages.C; 22 | import codejudge.compiler.languages.Cpp; 23 | import codejudge.compiler.languages.Java; 24 | import codejudge.compiler.languages.Language; 25 | import codejudge.compiler.languages.Python; 26 | 27 | public class RequestThread extends Thread { 28 | 29 | Socket s; // socket connection 30 | int n; // request number 31 | File dir; // staging directory 32 | 33 | public RequestThread(Socket s, int n) { 34 | this.s=s; 35 | this.n=n; 36 | dir = new File("stage/" + n); 37 | } 38 | 39 | public void run() { 40 | dir.mkdirs(); // create staging directory 41 | try { 42 | BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); 43 | PrintWriter out = new PrintWriter(s.getOutputStream(), true); 44 | // read input from the PHP script 45 | String file = in.readLine(); 46 | int timeout = Integer.parseInt(in.readLine()); 47 | String contents = in.readLine().replace("$_n_$", "\n"); 48 | String input = in.readLine().replace("$_n_$", "\n"); 49 | String lang = in.readLine(); 50 | System.out.println("Compiling " + file + "..."); 51 | // create the sample input file 52 | PrintWriter writer = new PrintWriter(new FileOutputStream("stage/" + n +"/in.txt")); 53 | writer.println(input); 54 | writer.close(); 55 | Language l = null; 56 | // create the language specific compiler 57 | if(lang.equals("c")) 58 | l = new C(file, timeout, contents, dir.getAbsolutePath()); 59 | else if(lang.equals("cpp")) 60 | l = new Cpp(file, timeout, contents, dir.getAbsolutePath()); 61 | else if(lang.equals("java")) 62 | l = new Java(file, timeout, contents, dir.getAbsolutePath()); 63 | else if(lang.equals("python")) 64 | l = new Python(file, timeout, contents, dir.getAbsolutePath()); 65 | l.compile(); // compile the file 66 | String errors = compileErrors(); 67 | if(!errors.equals("")) { // check for compilation errors 68 | out.println("0"); 69 | out.println(errors); 70 | } else { 71 | // execute the program and return output 72 | l.execute(); 73 | if(l.timedout) 74 | out.println(2); 75 | else { 76 | out.println("1"); 77 | out.println(execMsg()); 78 | } 79 | } 80 | s.close(); 81 | } catch (IOException e) { 82 | e.printStackTrace(); 83 | } 84 | } 85 | 86 | // method to return the compiler errors 87 | public String compileErrors() { 88 | String line, content = ""; 89 | try { 90 | BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(dir.getAbsolutePath() + "/err.txt"))); 91 | while((line = fin.readLine()) != null) 92 | content += (line + "\n"); 93 | } catch (FileNotFoundException e) { 94 | e.printStackTrace(); 95 | } catch (IOException e) { 96 | e.printStackTrace(); 97 | } 98 | return content.trim(); 99 | } 100 | 101 | // method to return the execution output 102 | public String execMsg() { 103 | String line, content = ""; 104 | try { 105 | BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(dir.getAbsolutePath() + "/out.txt"))); 106 | while((line = fin.readLine()) != null) 107 | content += (line + "\n"); 108 | } catch (FileNotFoundException e) { 109 | e.printStackTrace(); 110 | } catch (IOException e) { 111 | e.printStackTrace(); 112 | } 113 | return content.trim(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/TimedShell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Timer Shell that executes a commend with a timeout period 7 | */ 8 | 9 | package codejudge.compiler; 10 | 11 | import codejudge.compiler.languages.Language; 12 | 13 | public class TimedShell extends Thread { 14 | 15 | Language parent; 16 | Process p; 17 | long time; 18 | 19 | public TimedShell(Language parent, Process p, long time){ 20 | this.parent = parent; 21 | this.p = p; 22 | this.time = time; 23 | } 24 | 25 | // Sleep until timeout and then terminate the process 26 | public void run() { 27 | try { 28 | sleep(time); 29 | } catch (InterruptedException e) { 30 | e.printStackTrace(); 31 | } 32 | try { 33 | p.exitValue(); 34 | parent.timedout = false; 35 | } catch (IllegalThreadStateException e) { 36 | parent.timedout = true; 37 | p.destroy(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/languages/C.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server: Compiler for the C language 7 | */ 8 | 9 | package codejudge.compiler.languages; 10 | 11 | import java.io.BufferedWriter; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStreamWriter; 16 | 17 | import codejudge.compiler.TimedShell; 18 | 19 | public class C extends Language { 20 | 21 | String file, contents, dir; 22 | int timeout; 23 | 24 | public C(String file, int timeout, String contents, String dir) { 25 | this.file = file; 26 | this.timeout = timeout; 27 | this.contents = contents; 28 | this.dir = dir; 29 | } 30 | public void compile() { 31 | try { 32 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file))); 33 | out.write(contents); 34 | out.close(); 35 | // create the compiler script 36 | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh"))); 37 | out.write("cd \"" + dir +"\"\n"); 38 | out.write("gcc -lm " + file + " 2> err.txt"); 39 | out.close(); 40 | Runtime r = Runtime.getRuntime(); 41 | Process p = r.exec("chmod +x " + dir + "/compile.sh"); 42 | p.waitFor(); 43 | p = r.exec(dir + "/compile.sh"); // execute the compiler script 44 | TimedShell shell = new TimedShell(this, p, timeout); 45 | shell.start(); 46 | p.waitFor(); 47 | } catch (FileNotFoundException e) { 48 | e.printStackTrace(); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } catch (InterruptedException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | public void execute() { 57 | try { 58 | // create the execution script 59 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh"))); 60 | out.write("cd \"" + dir +"\"\n"); 61 | out.write("chroot .\n"); 62 | out.write("./a.out < in.txt > out.txt"); 63 | out.close(); 64 | Runtime r = Runtime.getRuntime(); 65 | Process p = r.exec("chmod +x " + dir + "/run.sh"); 66 | p.waitFor(); 67 | p = r.exec(dir + "/run.sh"); // execute the script 68 | TimedShell shell = new TimedShell(this, p, 3000); 69 | shell.start(); 70 | p.waitFor(); 71 | } catch (FileNotFoundException e) { 72 | e.printStackTrace(); 73 | } catch (IOException e) { 74 | e.printStackTrace(); 75 | } catch (InterruptedException e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/languages/Cpp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server: Compiler for the C++ language 7 | */ 8 | 9 | package codejudge.compiler.languages; 10 | 11 | import java.io.BufferedWriter; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStreamWriter; 16 | 17 | import codejudge.compiler.TimedShell; 18 | 19 | public class Cpp extends Language { 20 | 21 | String file, contents, dir; 22 | int timeout; 23 | 24 | public Cpp(String file, int timeout, String contents, String dir) { 25 | this.file = file; 26 | this.timeout = timeout; 27 | this.contents = contents; 28 | this.dir = dir; 29 | } 30 | public void compile() { 31 | try { 32 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file))); 33 | out.write(contents); 34 | out.close(); 35 | // create the compiler script 36 | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh"))); 37 | out.write("cd \"" + dir +"\"\n"); 38 | out.write("g++ -lm " + file + " 2> err.txt"); 39 | out.close(); 40 | Runtime r = Runtime.getRuntime(); 41 | Process p = r.exec("chmod +x " + dir + "/compile.sh"); 42 | p.waitFor(); 43 | p = r.exec(dir + "/compile.sh"); // execute the compiler script 44 | p.waitFor(); 45 | } catch (FileNotFoundException e) { 46 | e.printStackTrace(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } catch (InterruptedException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | public void execute() { 55 | try { 56 | // create the execution script 57 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh"))); 58 | out.write("cd \"" + dir +"\"\n"); 59 | out.write("chroot .\n"); 60 | out.write("./a.out < in.txt > out.txt"); 61 | out.close(); 62 | Runtime r = Runtime.getRuntime(); 63 | Process p = r.exec("chmod +x " + dir + "/run.sh"); 64 | p.waitFor(); 65 | p = r.exec(dir + "/run.sh"); // execute the script 66 | TimedShell shell = new TimedShell(this, p, 3000); 67 | shell.start(); 68 | p.waitFor(); 69 | } catch (FileNotFoundException e) { 70 | e.printStackTrace(); 71 | } catch (IOException e) { 72 | e.printStackTrace(); 73 | } catch (InterruptedException e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/languages/Java.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server: Compiler for the Java language 7 | */ 8 | 9 | package codejudge.compiler.languages; 10 | 11 | import java.io.BufferedWriter; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStreamWriter; 16 | 17 | import codejudge.compiler.TimedShell; 18 | 19 | public class Java extends Language { 20 | 21 | String file, contents, dir; 22 | int timeout; 23 | 24 | public Java(String file, int timeout, String contents, String dir) { 25 | this.file = file; 26 | this.timeout = timeout; 27 | this.contents = contents; 28 | this.dir = dir; 29 | } 30 | public void compile() { 31 | try { 32 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file))); 33 | out.write(contents); 34 | out.close(); 35 | // create the compiler script 36 | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh"))); 37 | out.write("cd \"" + dir +"\"\n"); 38 | out.write("javac " + file + " 2> err.txt"); 39 | out.close(); 40 | Runtime r = Runtime.getRuntime(); 41 | Process p = r.exec("chmod +x " + dir + "/compile.sh"); 42 | p.waitFor(); 43 | p = r.exec(dir + "/compile.sh"); // execute the compiler script 44 | p.waitFor(); 45 | } catch (FileNotFoundException e) { 46 | e.printStackTrace(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } catch (InterruptedException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | public void execute() { 55 | try { 56 | // create the execution script 57 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh"))); 58 | out.write("cd \"" + dir +"\"\n"); 59 | out.write("chroot .\n"); 60 | out.write("java " + file.substring(0, file.length() - 5) + " < in.txt > out.txt"); 61 | out.close(); 62 | Runtime r = Runtime.getRuntime(); 63 | Process p = r.exec("chmod +x " + dir + "/run.sh"); 64 | p.waitFor(); 65 | p = r.exec(dir + "/run.sh"); // execute the script 66 | TimedShell shell = new TimedShell(this, p, 3000); 67 | shell.start(); 68 | p.waitFor(); 69 | } catch (FileNotFoundException e) { 70 | e.printStackTrace(); 71 | } catch (IOException e) { 72 | e.printStackTrace(); 73 | } catch (InterruptedException e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/languages/Language.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server: The base interface for each language 7 | */ 8 | 9 | package codejudge.compiler.languages; 10 | 11 | public abstract class Language { 12 | 13 | public boolean timedout = false; 14 | public abstract void execute(); // method to override when executing a program 15 | public abstract void compile(); // method to override when compiling a program 16 | 17 | } 18 | -------------------------------------------------------------------------------- /codejudge-compiler/src/codejudge/compiler/languages/Python.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Codejudge 3 | * Copyright 2012, Sankha Narayan Guria (sankha93@gmail.com) 4 | * Licensed under MIT License. 5 | * 6 | * Codejudge Compiler Server: Compiler for the Python language 7 | */ 8 | 9 | package codejudge.compiler.languages; 10 | 11 | import java.io.BufferedWriter; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStreamWriter; 16 | 17 | import codejudge.compiler.TimedShell; 18 | 19 | public class Python extends Language { 20 | 21 | String file, contents, dir; 22 | int timeout; 23 | 24 | public Python(String file, int timeout, String contents, String dir) { 25 | this.file = file; 26 | this.timeout = timeout; 27 | this.contents = contents; 28 | this.dir = dir; 29 | } 30 | 31 | public void compile() { 32 | try { 33 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file))); 34 | out.write(contents); 35 | out.close(); 36 | // create the execution script 37 | out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh"))); 38 | out.write("cd \"" + dir +"\"\n"); 39 | out.write("chroot .\n"); 40 | out.write("python " + file + "< in.txt > out.txt 2>err.txt"); 41 | out.close(); 42 | Runtime r = Runtime.getRuntime(); 43 | Process p = r.exec("chmod +x " + dir + "/run.sh"); 44 | p.waitFor(); 45 | p = r.exec(dir + "/run.sh"); // execute the script 46 | TimedShell shell = new TimedShell(this, p, 3000); 47 | shell.start(); 48 | p.waitFor(); 49 | } catch (FileNotFoundException e) { 50 | e.printStackTrace(); 51 | } catch (IOException e) { 52 | e.printStackTrace(); 53 | } catch (InterruptedException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | 58 | public void execute() { 59 | // nothing to be done here 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /css/bootstrap-responsive.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Responsive v2.0.4 3 | * 4 | * Copyright 2012 Twitter, Inc 5 | * Licensed under the Apache License v2.0 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Designed and built with all the love in the world @twitter by @mdo and @fat. 9 | */ 10 | 11 | .clearfix { 12 | *zoom: 1; 13 | } 14 | 15 | .clearfix:before, 16 | .clearfix:after { 17 | display: table; 18 | content: ""; 19 | } 20 | 21 | .clearfix:after { 22 | clear: both; 23 | } 24 | 25 | .hide-text { 26 | font: 0/0 a; 27 | color: transparent; 28 | text-shadow: none; 29 | background-color: transparent; 30 | border: 0; 31 | } 32 | 33 | .input-block-level { 34 | display: block; 35 | width: 100%; 36 | min-height: 28px; 37 | -webkit-box-sizing: border-box; 38 | -moz-box-sizing: border-box; 39 | -ms-box-sizing: border-box; 40 | box-sizing: border-box; 41 | } 42 | 43 | .hidden { 44 | display: none; 45 | visibility: hidden; 46 | } 47 | 48 | .visible-phone { 49 | display: none !important; 50 | } 51 | 52 | .visible-tablet { 53 | display: none !important; 54 | } 55 | 56 | .hidden-desktop { 57 | display: none !important; 58 | } 59 | 60 | @media (max-width: 767px) { 61 | .visible-phone { 62 | display: inherit !important; 63 | } 64 | .hidden-phone { 65 | display: none !important; 66 | } 67 | .hidden-desktop { 68 | display: inherit !important; 69 | } 70 | .visible-desktop { 71 | display: none !important; 72 | } 73 | } 74 | 75 | @media (min-width: 768px) and (max-width: 979px) { 76 | .visible-tablet { 77 | display: inherit !important; 78 | } 79 | .hidden-tablet { 80 | display: none !important; 81 | } 82 | .hidden-desktop { 83 | display: inherit !important; 84 | } 85 | .visible-desktop { 86 | display: none !important ; 87 | } 88 | } 89 | 90 | @media (max-width: 480px) { 91 | .nav-collapse { 92 | -webkit-transform: translate3d(0, 0, 0); 93 | } 94 | .page-header h1 small { 95 | display: block; 96 | line-height: 18px; 97 | } 98 | input[type="checkbox"], 99 | input[type="radio"] { 100 | border: 1px solid #ccc; 101 | } 102 | .form-horizontal .control-group > label { 103 | float: none; 104 | width: auto; 105 | padding-top: 0; 106 | text-align: left; 107 | } 108 | .form-horizontal .controls { 109 | margin-left: 0; 110 | } 111 | .form-horizontal .control-list { 112 | padding-top: 0; 113 | } 114 | .form-horizontal .form-actions { 115 | padding-right: 10px; 116 | padding-left: 10px; 117 | } 118 | .modal { 119 | position: absolute; 120 | top: 10px; 121 | right: 10px; 122 | left: 10px; 123 | width: auto; 124 | margin: 0; 125 | } 126 | .modal.fade.in { 127 | top: auto; 128 | } 129 | .modal-header .close { 130 | padding: 10px; 131 | margin: -10px; 132 | } 133 | .carousel-caption { 134 | position: static; 135 | } 136 | } 137 | 138 | @media (max-width: 767px) { 139 | body { 140 | padding-right: 20px; 141 | padding-left: 20px; 142 | } 143 | .navbar-fixed-top, 144 | .navbar-fixed-bottom { 145 | margin-right: -20px; 146 | margin-left: -20px; 147 | } 148 | .container-fluid { 149 | padding: 0; 150 | } 151 | .dl-horizontal dt { 152 | float: none; 153 | width: auto; 154 | clear: none; 155 | text-align: left; 156 | } 157 | .dl-horizontal dd { 158 | margin-left: 0; 159 | } 160 | .container { 161 | width: auto; 162 | } 163 | .row-fluid { 164 | width: 100%; 165 | } 166 | .row, 167 | .thumbnails { 168 | margin-left: 0; 169 | } 170 | [class*="span"], 171 | .row-fluid [class*="span"] { 172 | display: block; 173 | float: none; 174 | width: auto; 175 | margin-left: 0; 176 | } 177 | .input-large, 178 | .input-xlarge, 179 | .input-xxlarge, 180 | input[class*="span"], 181 | select[class*="span"], 182 | textarea[class*="span"], 183 | .uneditable-input { 184 | display: block; 185 | width: 100%; 186 | min-height: 28px; 187 | -webkit-box-sizing: border-box; 188 | -moz-box-sizing: border-box; 189 | -ms-box-sizing: border-box; 190 | box-sizing: border-box; 191 | } 192 | .input-prepend input, 193 | .input-append input, 194 | .input-prepend input[class*="span"], 195 | .input-append input[class*="span"] { 196 | display: inline-block; 197 | width: auto; 198 | } 199 | } 200 | 201 | @media (min-width: 768px) and (max-width: 979px) { 202 | .row { 203 | margin-left: -20px; 204 | *zoom: 1; 205 | } 206 | .row:before, 207 | .row:after { 208 | display: table; 209 | content: ""; 210 | } 211 | .row:after { 212 | clear: both; 213 | } 214 | [class*="span"] { 215 | float: left; 216 | margin-left: 20px; 217 | } 218 | .container, 219 | .navbar-fixed-top .container, 220 | .navbar-fixed-bottom .container { 221 | width: 724px; 222 | } 223 | .span12 { 224 | width: 724px; 225 | } 226 | .span11 { 227 | width: 662px; 228 | } 229 | .span10 { 230 | width: 600px; 231 | } 232 | .span9 { 233 | width: 538px; 234 | } 235 | .span8 { 236 | width: 476px; 237 | } 238 | .span7 { 239 | width: 414px; 240 | } 241 | .span6 { 242 | width: 352px; 243 | } 244 | .span5 { 245 | width: 290px; 246 | } 247 | .span4 { 248 | width: 228px; 249 | } 250 | .span3 { 251 | width: 166px; 252 | } 253 | .span2 { 254 | width: 104px; 255 | } 256 | .span1 { 257 | width: 42px; 258 | } 259 | .offset12 { 260 | margin-left: 764px; 261 | } 262 | .offset11 { 263 | margin-left: 702px; 264 | } 265 | .offset10 { 266 | margin-left: 640px; 267 | } 268 | .offset9 { 269 | margin-left: 578px; 270 | } 271 | .offset8 { 272 | margin-left: 516px; 273 | } 274 | .offset7 { 275 | margin-left: 454px; 276 | } 277 | .offset6 { 278 | margin-left: 392px; 279 | } 280 | .offset5 { 281 | margin-left: 330px; 282 | } 283 | .offset4 { 284 | margin-left: 268px; 285 | } 286 | .offset3 { 287 | margin-left: 206px; 288 | } 289 | .offset2 { 290 | margin-left: 144px; 291 | } 292 | .offset1 { 293 | margin-left: 82px; 294 | } 295 | .row-fluid { 296 | width: 100%; 297 | *zoom: 1; 298 | } 299 | .row-fluid:before, 300 | .row-fluid:after { 301 | display: table; 302 | content: ""; 303 | } 304 | .row-fluid:after { 305 | clear: both; 306 | } 307 | .row-fluid [class*="span"] { 308 | display: block; 309 | float: left; 310 | width: 100%; 311 | min-height: 28px; 312 | margin-left: 2.762430939%; 313 | *margin-left: 2.709239449638298%; 314 | -webkit-box-sizing: border-box; 315 | -moz-box-sizing: border-box; 316 | -ms-box-sizing: border-box; 317 | box-sizing: border-box; 318 | } 319 | .row-fluid [class*="span"]:first-child { 320 | margin-left: 0; 321 | } 322 | .row-fluid .span12 { 323 | width: 99.999999993%; 324 | *width: 99.9468085036383%; 325 | } 326 | .row-fluid .span11 { 327 | width: 91.436464082%; 328 | *width: 91.38327259263829%; 329 | } 330 | .row-fluid .span10 { 331 | width: 82.87292817100001%; 332 | *width: 82.8197366816383%; 333 | } 334 | .row-fluid .span9 { 335 | width: 74.30939226%; 336 | *width: 74.25620077063829%; 337 | } 338 | .row-fluid .span8 { 339 | width: 65.74585634900001%; 340 | *width: 65.6926648596383%; 341 | } 342 | .row-fluid .span7 { 343 | width: 57.182320438000005%; 344 | *width: 57.129128948638304%; 345 | } 346 | .row-fluid .span6 { 347 | width: 48.618784527%; 348 | *width: 48.5655930376383%; 349 | } 350 | .row-fluid .span5 { 351 | width: 40.055248616%; 352 | *width: 40.0020571266383%; 353 | } 354 | .row-fluid .span4 { 355 | width: 31.491712705%; 356 | *width: 31.4385212156383%; 357 | } 358 | .row-fluid .span3 { 359 | width: 22.928176794%; 360 | *width: 22.874985304638297%; 361 | } 362 | .row-fluid .span2 { 363 | width: 14.364640883%; 364 | *width: 14.311449393638298%; 365 | } 366 | .row-fluid .span1 { 367 | width: 5.801104972%; 368 | *width: 5.747913482638298%; 369 | } 370 | input, 371 | textarea, 372 | .uneditable-input { 373 | margin-left: 0; 374 | } 375 | input.span12, 376 | textarea.span12, 377 | .uneditable-input.span12 { 378 | width: 714px; 379 | } 380 | input.span11, 381 | textarea.span11, 382 | .uneditable-input.span11 { 383 | width: 652px; 384 | } 385 | input.span10, 386 | textarea.span10, 387 | .uneditable-input.span10 { 388 | width: 590px; 389 | } 390 | input.span9, 391 | textarea.span9, 392 | .uneditable-input.span9 { 393 | width: 528px; 394 | } 395 | input.span8, 396 | textarea.span8, 397 | .uneditable-input.span8 { 398 | width: 466px; 399 | } 400 | input.span7, 401 | textarea.span7, 402 | .uneditable-input.span7 { 403 | width: 404px; 404 | } 405 | input.span6, 406 | textarea.span6, 407 | .uneditable-input.span6 { 408 | width: 342px; 409 | } 410 | input.span5, 411 | textarea.span5, 412 | .uneditable-input.span5 { 413 | width: 280px; 414 | } 415 | input.span4, 416 | textarea.span4, 417 | .uneditable-input.span4 { 418 | width: 218px; 419 | } 420 | input.span3, 421 | textarea.span3, 422 | .uneditable-input.span3 { 423 | width: 156px; 424 | } 425 | input.span2, 426 | textarea.span2, 427 | .uneditable-input.span2 { 428 | width: 94px; 429 | } 430 | input.span1, 431 | textarea.span1, 432 | .uneditable-input.span1 { 433 | width: 32px; 434 | } 435 | } 436 | 437 | @media (min-width: 1200px) { 438 | .row { 439 | margin-left: -30px; 440 | *zoom: 1; 441 | } 442 | .row:before, 443 | .row:after { 444 | display: table; 445 | content: ""; 446 | } 447 | .row:after { 448 | clear: both; 449 | } 450 | [class*="span"] { 451 | float: left; 452 | margin-left: 30px; 453 | } 454 | .container, 455 | .navbar-fixed-top .container, 456 | .navbar-fixed-bottom .container { 457 | width: 1170px; 458 | } 459 | .span12 { 460 | width: 1170px; 461 | } 462 | .span11 { 463 | width: 1070px; 464 | } 465 | .span10 { 466 | width: 970px; 467 | } 468 | .span9 { 469 | width: 870px; 470 | } 471 | .span8 { 472 | width: 770px; 473 | } 474 | .span7 { 475 | width: 670px; 476 | } 477 | .span6 { 478 | width: 570px; 479 | } 480 | .span5 { 481 | width: 470px; 482 | } 483 | .span4 { 484 | width: 370px; 485 | } 486 | .span3 { 487 | width: 270px; 488 | } 489 | .span2 { 490 | width: 170px; 491 | } 492 | .span1 { 493 | width: 70px; 494 | } 495 | .offset12 { 496 | margin-left: 1230px; 497 | } 498 | .offset11 { 499 | margin-left: 1130px; 500 | } 501 | .offset10 { 502 | margin-left: 1030px; 503 | } 504 | .offset9 { 505 | margin-left: 930px; 506 | } 507 | .offset8 { 508 | margin-left: 830px; 509 | } 510 | .offset7 { 511 | margin-left: 730px; 512 | } 513 | .offset6 { 514 | margin-left: 630px; 515 | } 516 | .offset5 { 517 | margin-left: 530px; 518 | } 519 | .offset4 { 520 | margin-left: 430px; 521 | } 522 | .offset3 { 523 | margin-left: 330px; 524 | } 525 | .offset2 { 526 | margin-left: 230px; 527 | } 528 | .offset1 { 529 | margin-left: 130px; 530 | } 531 | .row-fluid { 532 | width: 100%; 533 | *zoom: 1; 534 | } 535 | .row-fluid:before, 536 | .row-fluid:after { 537 | display: table; 538 | content: ""; 539 | } 540 | .row-fluid:after { 541 | clear: both; 542 | } 543 | .row-fluid [class*="span"] { 544 | display: block; 545 | float: left; 546 | width: 100%; 547 | min-height: 28px; 548 | margin-left: 2.564102564%; 549 | *margin-left: 2.510911074638298%; 550 | -webkit-box-sizing: border-box; 551 | -moz-box-sizing: border-box; 552 | -ms-box-sizing: border-box; 553 | box-sizing: border-box; 554 | } 555 | .row-fluid [class*="span"]:first-child { 556 | margin-left: 0; 557 | } 558 | .row-fluid .span12 { 559 | width: 100%; 560 | *width: 99.94680851063829%; 561 | } 562 | .row-fluid .span11 { 563 | width: 91.45299145300001%; 564 | *width: 91.3997999636383%; 565 | } 566 | .row-fluid .span10 { 567 | width: 82.905982906%; 568 | *width: 82.8527914166383%; 569 | } 570 | .row-fluid .span9 { 571 | width: 74.358974359%; 572 | *width: 74.30578286963829%; 573 | } 574 | .row-fluid .span8 { 575 | width: 65.81196581200001%; 576 | *width: 65.7587743226383%; 577 | } 578 | .row-fluid .span7 { 579 | width: 57.264957265%; 580 | *width: 57.2117657756383%; 581 | } 582 | .row-fluid .span6 { 583 | width: 48.717948718%; 584 | *width: 48.6647572286383%; 585 | } 586 | .row-fluid .span5 { 587 | width: 40.170940171000005%; 588 | *width: 40.117748681638304%; 589 | } 590 | .row-fluid .span4 { 591 | width: 31.623931624%; 592 | *width: 31.5707401346383%; 593 | } 594 | .row-fluid .span3 { 595 | width: 23.076923077%; 596 | *width: 23.0237315876383%; 597 | } 598 | .row-fluid .span2 { 599 | width: 14.529914530000001%; 600 | *width: 14.4767230406383%; 601 | } 602 | .row-fluid .span1 { 603 | width: 5.982905983%; 604 | *width: 5.929714493638298%; 605 | } 606 | input, 607 | textarea, 608 | .uneditable-input { 609 | margin-left: 0; 610 | } 611 | input.span12, 612 | textarea.span12, 613 | .uneditable-input.span12 { 614 | width: 1160px; 615 | } 616 | input.span11, 617 | textarea.span11, 618 | .uneditable-input.span11 { 619 | width: 1060px; 620 | } 621 | input.span10, 622 | textarea.span10, 623 | .uneditable-input.span10 { 624 | width: 960px; 625 | } 626 | input.span9, 627 | textarea.span9, 628 | .uneditable-input.span9 { 629 | width: 860px; 630 | } 631 | input.span8, 632 | textarea.span8, 633 | .uneditable-input.span8 { 634 | width: 760px; 635 | } 636 | input.span7, 637 | textarea.span7, 638 | .uneditable-input.span7 { 639 | width: 660px; 640 | } 641 | input.span6, 642 | textarea.span6, 643 | .uneditable-input.span6 { 644 | width: 560px; 645 | } 646 | input.span5, 647 | textarea.span5, 648 | .uneditable-input.span5 { 649 | width: 460px; 650 | } 651 | input.span4, 652 | textarea.span4, 653 | .uneditable-input.span4 { 654 | width: 360px; 655 | } 656 | input.span3, 657 | textarea.span3, 658 | .uneditable-input.span3 { 659 | width: 260px; 660 | } 661 | input.span2, 662 | textarea.span2, 663 | .uneditable-input.span2 { 664 | width: 160px; 665 | } 666 | input.span1, 667 | textarea.span1, 668 | .uneditable-input.span1 { 669 | width: 60px; 670 | } 671 | .thumbnails { 672 | margin-left: -30px; 673 | } 674 | .thumbnails > li { 675 | margin-left: 30px; 676 | } 677 | .row-fluid .thumbnails { 678 | margin-left: 0; 679 | } 680 | } 681 | 682 | @media (max-width: 979px) { 683 | body { 684 | padding-top: 0; 685 | } 686 | .navbar-fixed-top, 687 | .navbar-fixed-bottom { 688 | position: static; 689 | } 690 | .navbar-fixed-top { 691 | margin-bottom: 18px; 692 | } 693 | .navbar-fixed-bottom { 694 | margin-top: 18px; 695 | } 696 | .navbar-fixed-top .navbar-inner, 697 | .navbar-fixed-bottom .navbar-inner { 698 | padding: 5px; 699 | } 700 | .navbar .container { 701 | width: auto; 702 | padding: 0; 703 | } 704 | .navbar .brand { 705 | padding-right: 10px; 706 | padding-left: 10px; 707 | margin: 0 0 0 -5px; 708 | } 709 | .nav-collapse { 710 | clear: both; 711 | } 712 | .nav-collapse .nav { 713 | float: none; 714 | margin: 0 0 9px; 715 | } 716 | .nav-collapse .nav > li { 717 | float: none; 718 | } 719 | .nav-collapse .nav > li > a { 720 | margin-bottom: 2px; 721 | } 722 | .nav-collapse .nav > .divider-vertical { 723 | display: none; 724 | } 725 | .nav-collapse .nav .nav-header { 726 | color: #999999; 727 | text-shadow: none; 728 | } 729 | .nav-collapse .nav > li > a, 730 | .nav-collapse .dropdown-menu a { 731 | padding: 6px 15px; 732 | font-weight: bold; 733 | color: #999999; 734 | -webkit-border-radius: 3px; 735 | -moz-border-radius: 3px; 736 | border-radius: 3px; 737 | } 738 | .nav-collapse .btn { 739 | padding: 4px 10px 4px; 740 | font-weight: normal; 741 | -webkit-border-radius: 4px; 742 | -moz-border-radius: 4px; 743 | border-radius: 4px; 744 | } 745 | .nav-collapse .dropdown-menu li + li a { 746 | margin-bottom: 2px; 747 | } 748 | .nav-collapse .nav > li > a:hover, 749 | .nav-collapse .dropdown-menu a:hover { 750 | background-color: #222222; 751 | } 752 | .nav-collapse.in .btn-group { 753 | padding: 0; 754 | margin-top: 5px; 755 | } 756 | .nav-collapse .dropdown-menu { 757 | position: static; 758 | top: auto; 759 | left: auto; 760 | display: block; 761 | float: none; 762 | max-width: none; 763 | padding: 0; 764 | margin: 0 15px; 765 | background-color: transparent; 766 | border: none; 767 | -webkit-border-radius: 0; 768 | -moz-border-radius: 0; 769 | border-radius: 0; 770 | -webkit-box-shadow: none; 771 | -moz-box-shadow: none; 772 | box-shadow: none; 773 | } 774 | .nav-collapse .dropdown-menu:before, 775 | .nav-collapse .dropdown-menu:after { 776 | display: none; 777 | } 778 | .nav-collapse .dropdown-menu .divider { 779 | display: none; 780 | } 781 | .nav-collapse .navbar-form, 782 | .nav-collapse .navbar-search { 783 | float: none; 784 | padding: 9px 15px; 785 | margin: 9px 0; 786 | border-top: 1px solid #222222; 787 | border-bottom: 1px solid #222222; 788 | -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); 789 | -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); 790 | box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1); 791 | } 792 | .navbar .nav-collapse .nav.pull-right { 793 | float: none; 794 | margin-left: 0; 795 | } 796 | .nav-collapse, 797 | .nav-collapse.collapse { 798 | height: 0; 799 | overflow: hidden; 800 | } 801 | .navbar .btn-navbar { 802 | display: block; 803 | } 804 | .navbar-static .navbar-inner { 805 | padding-right: 10px; 806 | padding-left: 10px; 807 | } 808 | } 809 | 810 | @media (min-width: 980px) { 811 | .nav-collapse.collapse { 812 | height: auto !important; 813 | overflow: visible !important; 814 | } 815 | } 816 | -------------------------------------------------------------------------------- /eval.php: -------------------------------------------------------------------------------- 1 | 85 | -------------------------------------------------------------------------------- /footer.php: -------------------------------------------------------------------------------- 1 | 10 |
    11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | <?php echo(getName()); ?> 15 | 16 | 17 | 18 | 19 | 20 | 21 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 26 | 27 |
    28 | \nCongratulations! You have solved the problem successfully.\n
    "); 31 | ?> 32 | Below is a list of available problems for you to solve.

    33 | 63 | \n

    ".$selected['name']."

    \n"); 69 | echo($out); 70 | ?> 71 |
    72 |
    73 | 74 | 80 | have solved the problem. 81 |
    82 | 85 | 86 | 87 | 90 | -------------------------------------------------------------------------------- /install.php: -------------------------------------------------------------------------------- 1 | "); 20 | fclose($fp); 21 | include('dbinfo.php'); 22 | // connect to the MySQL server 23 | mysql_connect($host,$user,$password); 24 | // create the database 25 | mysql_query("CREATE DATABASE $database"); 26 | mysql_select_db($database) or die('Error connecting to database.'); 27 | // create the preferences table 28 | mysql_query("CREATE TABLE `prefs` ( 29 | `name` varchar(30) NOT NULL, 30 | `accept` int(11) NOT NULL, 31 | `c` int(11) NOT NULL, 32 | `cpp` int(11) NOT NULL, 33 | `java` int(11) NOT NULL, 34 | `python` int(11) NOT NULL 35 | )"); 36 | // fill it with default preferences 37 | mysql_query("INSERT INTO `prefs` (`name`, `accept`, `c`, `cpp`, `java`, `python`) VALUES 38 | ('Codejudge', 1, 1, 1, 1, 1)"); 39 | // create the problems table 40 | mysql_query("CREATE TABLE IF NOT EXISTS `problems` ( 41 | `sl` int(11) NOT NULL AUTO_INCREMENT, 42 | `name` varchar(200) NOT NULL, 43 | `text` text NOT NULL, 44 | `input` text NOT NULL, 45 | `output` text NOT NULL, 46 | `time` int(11) NOT NULL DEFAULT '3000', 47 | PRIMARY KEY (`sl`) 48 | )"); 49 | // create the solve table 50 | mysql_query("CREATE TABLE IF NOT EXISTS `solve` ( 51 | `sl` int(11) NOT NULL AUTO_INCREMENT, 52 | `problem_id` int(11) NOT NULL, 53 | `username` varchar(25) NOT NULL, 54 | `status` int(11) NOT NULL DEFAULT '1', 55 | `attempts` int(11) NOT NULL DEFAULT '1', 56 | `soln` text NOT NULL, 57 | `filename` varchar(25) NOT NULL, 58 | `lang` varchar(20) NOT NULL, 59 | PRIMARY KEY (`sl`) 60 | )"); 61 | // create the users table 62 | mysql_query("CREATE TABLE IF NOT EXISTS `users` ( 63 | `sl` int(11) NOT NULL AUTO_INCREMENT, 64 | `username` varchar(25) NOT NULL, 65 | `salt` varchar(6) NOT NULL, 66 | `hash` varchar(80) NOT NULL, 67 | `email` varchar(100) NOT NULL, 68 | `status` int(11) NOT NULL DEFAULT '1', 69 | PRIMARY KEY (`sl`) 70 | )"); 71 | // create the user 'admin' with password 'admin' 72 | $salt=randomAlphaNum(5); 73 | $pass="admin"; 74 | $hash=crypt($pass,$salt); 75 | $sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('$pass', '$salt', '$hash', '".$_POST['email']."')"; 76 | mysql_query($sql); 77 | header("Location: install.php?installed=1"); 78 | } 79 | ?> 80 | 81 | 82 | 83 | 84 | Codejudge Setup 85 | 86 | 87 | 88 | 89 | 90 | 91 | 101 | 102 | 103 | 104 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 130 | 131 |
    132 | 134 |
    Codejudge is successfully installed!
    135 | 136 | You can login to the admin panel here with the password admin. You can change it once you login to the admin panel. 137 | 138 | Welcome to the Codejudge setup. This will help you set up Codejudge on your server. Make sure that you have MySQL running before you proceed. 139 |

    Details

    140 |
    141 | Database Host:
    142 | Username:
    143 | Password:
    144 | Database Name:
    145 | Email:
    146 | Compiler Server Host:
    147 | Compiler Server Port:
    148 | 149 |
    150 | 151 |
    Codejudge is already installed. Please remove the files and re-install it.
    152 | 153 |
    154 | 155 | 158 | -------------------------------------------------------------------------------- /js/bootstrap-alert.js: -------------------------------------------------------------------------------- 1 | /* ========================================================== 2 | * bootstrap-alert.js v2.0.4 3 | * http://twitter.github.com/bootstrap/javascript.html#alerts 4 | * ========================================================== 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* ALERT CLASS DEFINITION 27 | * ====================== */ 28 | 29 | var dismiss = '[data-dismiss="alert"]' 30 | , Alert = function (el) { 31 | $(el).on('click', dismiss, this.close) 32 | } 33 | 34 | Alert.prototype.close = function (e) { 35 | var $this = $(this) 36 | , selector = $this.attr('data-target') 37 | , $parent 38 | 39 | if (!selector) { 40 | selector = $this.attr('href') 41 | selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 42 | } 43 | 44 | $parent = $(selector) 45 | 46 | e && e.preventDefault() 47 | 48 | $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) 49 | 50 | $parent.trigger(e = $.Event('close')) 51 | 52 | if (e.isDefaultPrevented()) return 53 | 54 | $parent.removeClass('in') 55 | 56 | function removeElement() { 57 | $parent 58 | .trigger('closed') 59 | .remove() 60 | } 61 | 62 | $.support.transition && $parent.hasClass('fade') ? 63 | $parent.on($.support.transition.end, removeElement) : 64 | removeElement() 65 | } 66 | 67 | 68 | /* ALERT PLUGIN DEFINITION 69 | * ======================= */ 70 | 71 | $.fn.alert = function (option) { 72 | return this.each(function () { 73 | var $this = $(this) 74 | , data = $this.data('alert') 75 | if (!data) $this.data('alert', (data = new Alert(this))) 76 | if (typeof option == 'string') data[option].call($this) 77 | }) 78 | } 79 | 80 | $.fn.alert.Constructor = Alert 81 | 82 | 83 | /* ALERT DATA-API 84 | * ============== */ 85 | 86 | $(function () { 87 | $('body').on('click.alert.data-api', dismiss, Alert.prototype.close) 88 | }) 89 | 90 | }(window.jQuery); -------------------------------------------------------------------------------- /js/bootstrap-button.js: -------------------------------------------------------------------------------- 1 | /* ============================================================ 2 | * bootstrap-button.js v2.0.4 3 | * http://twitter.github.com/bootstrap/javascript.html#buttons 4 | * ============================================================ 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ============================================================ */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* BUTTON PUBLIC CLASS DEFINITION 27 | * ============================== */ 28 | 29 | var Button = function (element, options) { 30 | this.$element = $(element) 31 | this.options = $.extend({}, $.fn.button.defaults, options) 32 | } 33 | 34 | Button.prototype.setState = function (state) { 35 | var d = 'disabled' 36 | , $el = this.$element 37 | , data = $el.data() 38 | , val = $el.is('input') ? 'val' : 'html' 39 | 40 | state = state + 'Text' 41 | data.resetText || $el.data('resetText', $el[val]()) 42 | 43 | $el[val](data[state] || this.options[state]) 44 | 45 | // push to event loop to allow forms to submit 46 | setTimeout(function () { 47 | state == 'loadingText' ? 48 | $el.addClass(d).attr(d, d) : 49 | $el.removeClass(d).removeAttr(d) 50 | }, 0) 51 | } 52 | 53 | Button.prototype.toggle = function () { 54 | var $parent = this.$element.parent('[data-toggle="buttons-radio"]') 55 | 56 | $parent && $parent 57 | .find('.active') 58 | .removeClass('active') 59 | 60 | this.$element.toggleClass('active') 61 | } 62 | 63 | 64 | /* BUTTON PLUGIN DEFINITION 65 | * ======================== */ 66 | 67 | $.fn.button = function (option) { 68 | return this.each(function () { 69 | var $this = $(this) 70 | , data = $this.data('button') 71 | , options = typeof option == 'object' && option 72 | if (!data) $this.data('button', (data = new Button(this, options))) 73 | if (option == 'toggle') data.toggle() 74 | else if (option) data.setState(option) 75 | }) 76 | } 77 | 78 | $.fn.button.defaults = { 79 | loadingText: 'loading...' 80 | } 81 | 82 | $.fn.button.Constructor = Button 83 | 84 | 85 | /* BUTTON DATA-API 86 | * =============== */ 87 | 88 | $(function () { 89 | $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) { 90 | var $btn = $(e.target) 91 | if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') 92 | $btn.button('toggle') 93 | }) 94 | }) 95 | 96 | }(window.jQuery); -------------------------------------------------------------------------------- /js/bootstrap-carousel.js: -------------------------------------------------------------------------------- 1 | /* ========================================================== 2 | * bootstrap-carousel.js v2.0.4 3 | * http://twitter.github.com/bootstrap/javascript.html#carousel 4 | * ========================================================== 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================== */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* CAROUSEL CLASS DEFINITION 27 | * ========================= */ 28 | 29 | var Carousel = function (element, options) { 30 | this.$element = $(element) 31 | this.options = options 32 | this.options.slide && this.slide(this.options.slide) 33 | this.options.pause == 'hover' && this.$element 34 | .on('mouseenter', $.proxy(this.pause, this)) 35 | .on('mouseleave', $.proxy(this.cycle, this)) 36 | } 37 | 38 | Carousel.prototype = { 39 | 40 | cycle: function (e) { 41 | if (!e) this.paused = false 42 | this.options.interval 43 | && !this.paused 44 | && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) 45 | return this 46 | } 47 | 48 | , to: function (pos) { 49 | var $active = this.$element.find('.active') 50 | , children = $active.parent().children() 51 | , activePos = children.index($active) 52 | , that = this 53 | 54 | if (pos > (children.length - 1) || pos < 0) return 55 | 56 | if (this.sliding) { 57 | return this.$element.one('slid', function () { 58 | that.to(pos) 59 | }) 60 | } 61 | 62 | if (activePos == pos) { 63 | return this.pause().cycle() 64 | } 65 | 66 | return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos])) 67 | } 68 | 69 | , pause: function (e) { 70 | if (!e) this.paused = true 71 | clearInterval(this.interval) 72 | this.interval = null 73 | return this 74 | } 75 | 76 | , next: function () { 77 | if (this.sliding) return 78 | return this.slide('next') 79 | } 80 | 81 | , prev: function () { 82 | if (this.sliding) return 83 | return this.slide('prev') 84 | } 85 | 86 | , slide: function (type, next) { 87 | var $active = this.$element.find('.active') 88 | , $next = next || $active[type]() 89 | , isCycling = this.interval 90 | , direction = type == 'next' ? 'left' : 'right' 91 | , fallback = type == 'next' ? 'first' : 'last' 92 | , that = this 93 | , e = $.Event('slide') 94 | 95 | this.sliding = true 96 | 97 | isCycling && this.pause() 98 | 99 | $next = $next.length ? $next : this.$element.find('.item')[fallback]() 100 | 101 | if ($next.hasClass('active')) return 102 | 103 | if ($.support.transition && this.$element.hasClass('slide')) { 104 | this.$element.trigger(e) 105 | if (e.isDefaultPrevented()) return 106 | $next.addClass(type) 107 | $next[0].offsetWidth // force reflow 108 | $active.addClass(direction) 109 | $next.addClass(direction) 110 | this.$element.one($.support.transition.end, function () { 111 | $next.removeClass([type, direction].join(' ')).addClass('active') 112 | $active.removeClass(['active', direction].join(' ')) 113 | that.sliding = false 114 | setTimeout(function () { that.$element.trigger('slid') }, 0) 115 | }) 116 | } else { 117 | this.$element.trigger(e) 118 | if (e.isDefaultPrevented()) return 119 | $active.removeClass('active') 120 | $next.addClass('active') 121 | this.sliding = false 122 | this.$element.trigger('slid') 123 | } 124 | 125 | isCycling && this.cycle() 126 | 127 | return this 128 | } 129 | 130 | } 131 | 132 | 133 | /* CAROUSEL PLUGIN DEFINITION 134 | * ========================== */ 135 | 136 | $.fn.carousel = function (option) { 137 | return this.each(function () { 138 | var $this = $(this) 139 | , data = $this.data('carousel') 140 | , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option) 141 | if (!data) $this.data('carousel', (data = new Carousel(this, options))) 142 | if (typeof option == 'number') data.to(option) 143 | else if (typeof option == 'string' || (option = options.slide)) data[option]() 144 | else if (options.interval) data.cycle() 145 | }) 146 | } 147 | 148 | $.fn.carousel.defaults = { 149 | interval: 5000 150 | , pause: 'hover' 151 | } 152 | 153 | $.fn.carousel.Constructor = Carousel 154 | 155 | 156 | /* CAROUSEL DATA-API 157 | * ================= */ 158 | 159 | $(function () { 160 | $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) { 161 | var $this = $(this), href 162 | , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 163 | , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data()) 164 | $target.carousel(options) 165 | e.preventDefault() 166 | }) 167 | }) 168 | 169 | }(window.jQuery); -------------------------------------------------------------------------------- /js/bootstrap-collapse.js: -------------------------------------------------------------------------------- 1 | /* ============================================================= 2 | * bootstrap-collapse.js v2.0.4 3 | * http://twitter.github.com/bootstrap/javascript.html#collapse 4 | * ============================================================= 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ============================================================ */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* COLLAPSE PUBLIC CLASS DEFINITION 27 | * ================================ */ 28 | 29 | var Collapse = function (element, options) { 30 | this.$element = $(element) 31 | this.options = $.extend({}, $.fn.collapse.defaults, options) 32 | 33 | if (this.options.parent) { 34 | this.$parent = $(this.options.parent) 35 | } 36 | 37 | this.options.toggle && this.toggle() 38 | } 39 | 40 | Collapse.prototype = { 41 | 42 | constructor: Collapse 43 | 44 | , dimension: function () { 45 | var hasWidth = this.$element.hasClass('width') 46 | return hasWidth ? 'width' : 'height' 47 | } 48 | 49 | , show: function () { 50 | var dimension 51 | , scroll 52 | , actives 53 | , hasData 54 | 55 | if (this.transitioning) return 56 | 57 | dimension = this.dimension() 58 | scroll = $.camelCase(['scroll', dimension].join('-')) 59 | actives = this.$parent && this.$parent.find('> .accordion-group > .in') 60 | 61 | if (actives && actives.length) { 62 | hasData = actives.data('collapse') 63 | if (hasData && hasData.transitioning) return 64 | actives.collapse('hide') 65 | hasData || actives.data('collapse', null) 66 | } 67 | 68 | this.$element[dimension](0) 69 | this.transition('addClass', $.Event('show'), 'shown') 70 | this.$element[dimension](this.$element[0][scroll]) 71 | } 72 | 73 | , hide: function () { 74 | var dimension 75 | if (this.transitioning) return 76 | dimension = this.dimension() 77 | this.reset(this.$element[dimension]()) 78 | this.transition('removeClass', $.Event('hide'), 'hidden') 79 | this.$element[dimension](0) 80 | } 81 | 82 | , reset: function (size) { 83 | var dimension = this.dimension() 84 | 85 | this.$element 86 | .removeClass('collapse') 87 | [dimension](size || 'auto') 88 | [0].offsetWidth 89 | 90 | this.$element[size !== null ? 'addClass' : 'removeClass']('collapse') 91 | 92 | return this 93 | } 94 | 95 | , transition: function (method, startEvent, completeEvent) { 96 | var that = this 97 | , complete = function () { 98 | if (startEvent.type == 'show') that.reset() 99 | that.transitioning = 0 100 | that.$element.trigger(completeEvent) 101 | } 102 | 103 | this.$element.trigger(startEvent) 104 | 105 | if (startEvent.isDefaultPrevented()) return 106 | 107 | this.transitioning = 1 108 | 109 | this.$element[method]('in') 110 | 111 | $.support.transition && this.$element.hasClass('collapse') ? 112 | this.$element.one($.support.transition.end, complete) : 113 | complete() 114 | } 115 | 116 | , toggle: function () { 117 | this[this.$element.hasClass('in') ? 'hide' : 'show']() 118 | } 119 | 120 | } 121 | 122 | 123 | /* COLLAPSIBLE PLUGIN DEFINITION 124 | * ============================== */ 125 | 126 | $.fn.collapse = function (option) { 127 | return this.each(function () { 128 | var $this = $(this) 129 | , data = $this.data('collapse') 130 | , options = typeof option == 'object' && option 131 | if (!data) $this.data('collapse', (data = new Collapse(this, options))) 132 | if (typeof option == 'string') data[option]() 133 | }) 134 | } 135 | 136 | $.fn.collapse.defaults = { 137 | toggle: true 138 | } 139 | 140 | $.fn.collapse.Constructor = Collapse 141 | 142 | 143 | /* COLLAPSIBLE DATA-API 144 | * ==================== */ 145 | 146 | $(function () { 147 | $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) { 148 | var $this = $(this), href 149 | , target = $this.attr('data-target') 150 | || e.preventDefault() 151 | || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 152 | , option = $(target).data('collapse') ? 'toggle' : $this.data() 153 | $(target).collapse(option) 154 | }) 155 | }) 156 | 157 | }(window.jQuery); -------------------------------------------------------------------------------- /js/bootstrap-dropdown.js: -------------------------------------------------------------------------------- 1 | /* ============================================================ 2 | * bootstrap-dropdown.js v2.0.4 3 | * http://twitter.github.com/bootstrap/javascript.html#dropdowns 4 | * ============================================================ 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ============================================================ */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* DROPDOWN CLASS DEFINITION 27 | * ========================= */ 28 | 29 | var toggle = '[data-toggle="dropdown"]' 30 | , Dropdown = function (element) { 31 | var $el = $(element).on('click.dropdown.data-api', this.toggle) 32 | $('html').on('click.dropdown.data-api', function () { 33 | $el.parent().removeClass('open') 34 | }) 35 | } 36 | 37 | Dropdown.prototype = { 38 | 39 | constructor: Dropdown 40 | 41 | , toggle: function (e) { 42 | var $this = $(this) 43 | , $parent 44 | , selector 45 | , isActive 46 | 47 | if ($this.is('.disabled, :disabled')) return 48 | 49 | selector = $this.attr('data-target') 50 | 51 | if (!selector) { 52 | selector = $this.attr('href') 53 | selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 54 | } 55 | 56 | $parent = $(selector) 57 | $parent.length || ($parent = $this.parent()) 58 | 59 | isActive = $parent.hasClass('open') 60 | 61 | clearMenus() 62 | 63 | if (!isActive) $parent.toggleClass('open') 64 | 65 | return false 66 | } 67 | 68 | } 69 | 70 | function clearMenus() { 71 | $(toggle).parent().removeClass('open') 72 | } 73 | 74 | 75 | /* DROPDOWN PLUGIN DEFINITION 76 | * ========================== */ 77 | 78 | $.fn.dropdown = function (option) { 79 | return this.each(function () { 80 | var $this = $(this) 81 | , data = $this.data('dropdown') 82 | if (!data) $this.data('dropdown', (data = new Dropdown(this))) 83 | if (typeof option == 'string') data[option].call($this) 84 | }) 85 | } 86 | 87 | $.fn.dropdown.Constructor = Dropdown 88 | 89 | 90 | /* APPLY TO STANDARD DROPDOWN ELEMENTS 91 | * =================================== */ 92 | 93 | $(function () { 94 | $('html').on('click.dropdown.data-api', clearMenus) 95 | $('body') 96 | .on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() }) 97 | .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle) 98 | }) 99 | 100 | }(window.jQuery); -------------------------------------------------------------------------------- /js/bootstrap-modal.js: -------------------------------------------------------------------------------- 1 | /* ========================================================= 2 | * bootstrap-modal.js v2.0.4 3 | * http://twitter.github.com/bootstrap/javascript.html#modals 4 | * ========================================================= 5 | * Copyright 2012 Twitter, Inc. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * ========================================================= */ 19 | 20 | 21 | !function ($) { 22 | 23 | "use strict"; // jshint ;_; 24 | 25 | 26 | /* MODAL CLASS DEFINITION 27 | * ====================== */ 28 | 29 | var Modal = function (content, options) { 30 | this.options = options 31 | this.$element = $(content) 32 | .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this)) 33 | } 34 | 35 | Modal.prototype = { 36 | 37 | constructor: Modal 38 | 39 | , toggle: function () { 40 | return this[!this.isShown ? 'show' : 'hide']() 41 | } 42 | 43 | , show: function () { 44 | var that = this 45 | , e = $.Event('show') 46 | 47 | this.$element.trigger(e) 48 | 49 | if (this.isShown || e.isDefaultPrevented()) return 50 | 51 | $('body').addClass('modal-open') 52 | 53 | this.isShown = true 54 | 55 | escape.call(this) 56 | backdrop.call(this, function () { 57 | var transition = $.support.transition && that.$element.hasClass('fade') 58 | 59 | if (!that.$element.parent().length) { 60 | that.$element.appendTo(document.body) //don't move modals dom position 61 | } 62 | 63 | that.$element 64 | .show() 65 | 66 | if (transition) { 67 | that.$element[0].offsetWidth // force reflow 68 | } 69 | 70 | that.$element.addClass('in') 71 | 72 | transition ? 73 | that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : 74 | that.$element.trigger('shown') 75 | 76 | }) 77 | } 78 | 79 | , hide: function (e) { 80 | e && e.preventDefault() 81 | 82 | var that = this 83 | 84 | e = $.Event('hide') 85 | 86 | this.$element.trigger(e) 87 | 88 | if (!this.isShown || e.isDefaultPrevented()) return 89 | 90 | this.isShown = false 91 | 92 | $('body').removeClass('modal-open') 93 | 94 | escape.call(this) 95 | 96 | this.$element.removeClass('in') 97 | 98 | $.support.transition && this.$element.hasClass('fade') ? 99 | hideWithTransition.call(this) : 100 | hideModal.call(this) 101 | } 102 | 103 | } 104 | 105 | 106 | /* MODAL PRIVATE METHODS 107 | * ===================== */ 108 | 109 | function hideWithTransition() { 110 | var that = this 111 | , timeout = setTimeout(function () { 112 | that.$element.off($.support.transition.end) 113 | hideModal.call(that) 114 | }, 500) 115 | 116 | this.$element.one($.support.transition.end, function () { 117 | clearTimeout(timeout) 118 | hideModal.call(that) 119 | }) 120 | } 121 | 122 | function hideModal(that) { 123 | this.$element 124 | .hide() 125 | .trigger('hidden') 126 | 127 | backdrop.call(this) 128 | } 129 | 130 | function backdrop(callback) { 131 | var that = this 132 | , animate = this.$element.hasClass('fade') ? 'fade' : '' 133 | 134 | if (this.isShown && this.options.backdrop) { 135 | var doAnimate = $.support.transition && animate 136 | 137 | this.$backdrop = $(' 135 | 136 | 139 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | 17 | -------------------------------------------------------------------------------- /markdown.php: -------------------------------------------------------------------------------- 1 | 8 | # 9 | # Original Markdown 10 | # Copyright (c) 2004-2006 John Gruber 11 | # 12 | # 13 | 14 | 15 | define( 'MARKDOWN_VERSION', "1.0.1o" ); # Sun 8 Jan 2012 16 | 17 | 18 | # 19 | # Global default settings: 20 | # 21 | 22 | # Change to ">" for HTML output 23 | @define( 'MARKDOWN_EMPTY_ELEMENT_SUFFIX', " />"); 24 | 25 | # Define the width of a tab for code blocks. 26 | @define( 'MARKDOWN_TAB_WIDTH', 4 ); 27 | 28 | 29 | # 30 | # WordPress settings: 31 | # 32 | 33 | # Change to false to remove Markdown from posts and/or comments. 34 | @define( 'MARKDOWN_WP_POSTS', true ); 35 | @define( 'MARKDOWN_WP_COMMENTS', true ); 36 | 37 | 38 | 39 | ### Standard Function Interface ### 40 | 41 | @define( 'MARKDOWN_PARSER_CLASS', 'Markdown_Parser' ); 42 | 43 | function Markdown($text) { 44 | # 45 | # Initialize the parser and return the result of its transform method. 46 | # 47 | # Setup static parser variable. 48 | static $parser; 49 | if (!isset($parser)) { 50 | $parser_class = MARKDOWN_PARSER_CLASS; 51 | $parser = new $parser_class; 52 | } 53 | 54 | # Transform text using parser. 55 | return $parser->transform($text); 56 | } 57 | 58 | 59 | ### WordPress Plugin Interface ### 60 | 61 | /* 62 | Plugin Name: Markdown 63 | Plugin URI: http://michelf.com/projects/php-markdown/ 64 | Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... 65 | Version: 1.0.1o 66 | Author: Michel Fortin 67 | Author URI: http://michelf.com/ 68 | */ 69 | 70 | if (isset($wp_version)) { 71 | # More details about how it works here: 72 | # 73 | 74 | # Post content and excerpts 75 | # - Remove WordPress paragraph generator. 76 | # - Run Markdown on excerpt, then remove all tags. 77 | # - Add paragraph tag around the excerpt, but remove it for the excerpt rss. 78 | if (MARKDOWN_WP_POSTS) { 79 | remove_filter('the_content', 'wpautop'); 80 | remove_filter('the_content_rss', 'wpautop'); 81 | remove_filter('the_excerpt', 'wpautop'); 82 | add_filter('the_content', 'Markdown', 6); 83 | add_filter('the_content_rss', 'Markdown', 6); 84 | add_filter('get_the_excerpt', 'Markdown', 6); 85 | add_filter('get_the_excerpt', 'trim', 7); 86 | add_filter('the_excerpt', 'mdwp_add_p'); 87 | add_filter('the_excerpt_rss', 'mdwp_strip_p'); 88 | 89 | remove_filter('content_save_pre', 'balanceTags', 50); 90 | remove_filter('excerpt_save_pre', 'balanceTags', 50); 91 | add_filter('the_content', 'balanceTags', 50); 92 | add_filter('get_the_excerpt', 'balanceTags', 9); 93 | } 94 | 95 | # Comments 96 | # - Remove WordPress paragraph generator. 97 | # - Remove WordPress auto-link generator. 98 | # - Scramble important tags before passing them to the kses filter. 99 | # - Run Markdown on excerpt then remove paragraph tags. 100 | if (MARKDOWN_WP_COMMENTS) { 101 | remove_filter('comment_text', 'wpautop', 30); 102 | remove_filter('comment_text', 'make_clickable'); 103 | add_filter('pre_comment_content', 'Markdown', 6); 104 | add_filter('pre_comment_content', 'mdwp_hide_tags', 8); 105 | add_filter('pre_comment_content', 'mdwp_show_tags', 12); 106 | add_filter('get_comment_text', 'Markdown', 6); 107 | add_filter('get_comment_excerpt', 'Markdown', 6); 108 | add_filter('get_comment_excerpt', 'mdwp_strip_p', 7); 109 | 110 | global $mdwp_hidden_tags, $mdwp_placeholders; 111 | $mdwp_hidden_tags = explode(' ', 112 | '

     
  • '); 113 | $mdwp_placeholders = explode(' ', str_rot13( 114 | 'pEj07ZbbBZ U1kqgh4w4p pre2zmeN6K QTi31t9pre ol0MP1jzJR '. 115 | 'ML5IjmbRol ulANi1NsGY J7zRLJqPul liA8ctl16T K9nhooUHli')); 116 | } 117 | 118 | function mdwp_add_p($text) { 119 | if (!preg_match('{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $text)) { 120 | $text = '

    '.$text.'

    '; 121 | $text = preg_replace('{\n{2,}}', "

    \n\n

    ", $text); 122 | } 123 | return $text; 124 | } 125 | 126 | function mdwp_strip_p($t) { return preg_replace('{}i', '', $t); } 127 | 128 | function mdwp_hide_tags($text) { 129 | global $mdwp_hidden_tags, $mdwp_placeholders; 130 | return str_replace($mdwp_hidden_tags, $mdwp_placeholders, $text); 131 | } 132 | function mdwp_show_tags($text) { 133 | global $mdwp_hidden_tags, $mdwp_placeholders; 134 | return str_replace($mdwp_placeholders, $mdwp_hidden_tags, $text); 135 | } 136 | } 137 | 138 | 139 | ### bBlog Plugin Info ### 140 | 141 | function identify_modifier_markdown() { 142 | return array( 143 | 'name' => 'markdown', 144 | 'type' => 'modifier', 145 | 'nicename' => 'Markdown', 146 | 'description' => 'A text-to-HTML conversion tool for web writers', 147 | 'authors' => 'Michel Fortin and John Gruber', 148 | 'licence' => 'BSD-like', 149 | 'version' => MARKDOWN_VERSION, 150 | 'help' => 'Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More...' 151 | ); 152 | } 153 | 154 | 155 | ### Smarty Modifier Interface ### 156 | 157 | function smarty_modifier_markdown($text) { 158 | return Markdown($text); 159 | } 160 | 161 | 162 | ### Textile Compatibility Mode ### 163 | 164 | # Rename this file to "classTextile.php" and it can replace Textile everywhere. 165 | 166 | if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) { 167 | # Try to include PHP SmartyPants. Should be in the same directory. 168 | @include_once 'smartypants.php'; 169 | # Fake Textile class. It calls Markdown instead. 170 | class Textile { 171 | function TextileThis($text, $lite='', $encode='') { 172 | if ($lite == '' && $encode == '') $text = Markdown($text); 173 | if (function_exists('SmartyPants')) $text = SmartyPants($text); 174 | return $text; 175 | } 176 | # Fake restricted version: restrictions are not supported for now. 177 | function TextileRestricted($text, $lite='', $noimage='') { 178 | return $this->TextileThis($text, $lite); 179 | } 180 | # Workaround to ensure compatibility with TextPattern 4.0.3. 181 | function blockLite($text) { return $text; } 182 | } 183 | } 184 | 185 | 186 | 187 | # 188 | # Markdown Parser Class 189 | # 190 | 191 | class Markdown_Parser { 192 | 193 | # Regex to match balanced [brackets]. 194 | # Needed to insert a maximum bracked depth while converting to PHP. 195 | var $nested_brackets_depth = 6; 196 | var $nested_brackets_re; 197 | 198 | var $nested_url_parenthesis_depth = 4; 199 | var $nested_url_parenthesis_re; 200 | 201 | # Table of hash values for escaped characters: 202 | var $escape_chars = '\`*_{}[]()>#+-.!'; 203 | var $escape_chars_re; 204 | 205 | # Change to ">" for HTML output. 206 | var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX; 207 | var $tab_width = MARKDOWN_TAB_WIDTH; 208 | 209 | # Change to `true` to disallow markup or entities. 210 | var $no_markup = false; 211 | var $no_entities = false; 212 | 213 | # Predefined urls and titles for reference links and images. 214 | var $predef_urls = array(); 215 | var $predef_titles = array(); 216 | 217 | 218 | function Markdown_Parser() { 219 | # 220 | # Constructor function. Initialize appropriate member variables. 221 | # 222 | $this->_initDetab(); 223 | $this->prepareItalicsAndBold(); 224 | 225 | $this->nested_brackets_re = 226 | str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). 227 | str_repeat('\])*', $this->nested_brackets_depth); 228 | 229 | $this->nested_url_parenthesis_re = 230 | str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). 231 | str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); 232 | 233 | $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; 234 | 235 | # Sort document, block, and span gamut in ascendent priority order. 236 | asort($this->document_gamut); 237 | asort($this->block_gamut); 238 | asort($this->span_gamut); 239 | } 240 | 241 | 242 | # Internal hashes used during transformation. 243 | var $urls = array(); 244 | var $titles = array(); 245 | var $html_hashes = array(); 246 | 247 | # Status flag to avoid invalid nesting. 248 | var $in_anchor = false; 249 | 250 | 251 | function setup() { 252 | # 253 | # Called before the transformation process starts to setup parser 254 | # states. 255 | # 256 | # Clear global hashes. 257 | $this->urls = $this->predef_urls; 258 | $this->titles = $this->predef_titles; 259 | $this->html_hashes = array(); 260 | 261 | $in_anchor = false; 262 | } 263 | 264 | function teardown() { 265 | # 266 | # Called after the transformation process to clear any variable 267 | # which may be taking up memory unnecessarly. 268 | # 269 | $this->urls = array(); 270 | $this->titles = array(); 271 | $this->html_hashes = array(); 272 | } 273 | 274 | 275 | function transform($text) { 276 | # 277 | # Main function. Performs some preprocessing on the input text 278 | # and pass it through the document gamut. 279 | # 280 | $this->setup(); 281 | 282 | # Remove UTF-8 BOM and marker character in input, if present. 283 | $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); 284 | 285 | # Standardize line endings: 286 | # DOS to Unix and Mac to Unix 287 | $text = preg_replace('{\r\n?}', "\n", $text); 288 | 289 | # Make sure $text ends with a couple of newlines: 290 | $text .= "\n\n"; 291 | 292 | # Convert all tabs to spaces. 293 | $text = $this->detab($text); 294 | 295 | # Turn block-level HTML blocks into hash entries 296 | $text = $this->hashHTMLBlocks($text); 297 | 298 | # Strip any lines consisting only of spaces and tabs. 299 | # This makes subsequent regexen easier to write, because we can 300 | # match consecutive blank lines with /\n+/ instead of something 301 | # contorted like /[ ]*\n+/ . 302 | $text = preg_replace('/^[ ]+$/m', '', $text); 303 | 304 | # Run document gamut methods. 305 | foreach ($this->document_gamut as $method => $priority) { 306 | $text = $this->$method($text); 307 | } 308 | 309 | $this->teardown(); 310 | 311 | return $text . "\n"; 312 | } 313 | 314 | var $document_gamut = array( 315 | # Strip link definitions, store in hashes. 316 | "stripLinkDefinitions" => 20, 317 | 318 | "runBasicBlockGamut" => 30, 319 | ); 320 | 321 | 322 | function stripLinkDefinitions($text) { 323 | # 324 | # Strips link definitions from text, stores the URLs and titles in 325 | # hash references. 326 | # 327 | $less_than_tab = $this->tab_width - 1; 328 | 329 | # Link defs are in the form: ^[id]: url "optional title" 330 | $text = preg_replace_callback('{ 331 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 332 | [ ]* 333 | \n? # maybe *one* newline 334 | [ ]* 335 | (?: 336 | <(.+?)> # url = $2 337 | | 338 | (\S+?) # url = $3 339 | ) 340 | [ ]* 341 | \n? # maybe one newline 342 | [ ]* 343 | (?: 344 | (?<=\s) # lookbehind for whitespace 345 | ["(] 346 | (.*?) # title = $4 347 | [")] 348 | [ ]* 349 | )? # title is optional 350 | (?:\n+|\Z) 351 | }xm', 352 | array(&$this, '_stripLinkDefinitions_callback'), 353 | $text); 354 | return $text; 355 | } 356 | function _stripLinkDefinitions_callback($matches) { 357 | $link_id = strtolower($matches[1]); 358 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; 359 | $this->urls[$link_id] = $url; 360 | $this->titles[$link_id] =& $matches[4]; 361 | return ''; # String that will replace the block 362 | } 363 | 364 | 365 | function hashHTMLBlocks($text) { 366 | if ($this->no_markup) return $text; 367 | 368 | $less_than_tab = $this->tab_width - 1; 369 | 370 | # Hashify HTML blocks: 371 | # We only want to do this for block-level HTML tags, such as headers, 372 | # lists, and tables. That's because we still want to wrap

    s around 373 | # "paragraphs" that are wrapped in non-block-level tags, such as anchors, 374 | # phrase emphasis, and spans. The list of tags we're looking for is 375 | # hard-coded: 376 | # 377 | # * List "a" is made of tags which can be both inline or block-level. 378 | # These will be treated block-level when the start tag is alone on 379 | # its line, otherwise they're not matched here and will be taken as 380 | # inline later. 381 | # * List "b" is made of tags which are always block-level; 382 | # 383 | $block_tags_a_re = 'ins|del'; 384 | $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. 385 | 'script|noscript|form|fieldset|iframe|math'; 386 | 387 | # Regular expression for the content of a block tag. 388 | $nested_tags_level = 4; 389 | $attr = ' 390 | (?> # optional tag attributes 391 | \s # starts with whitespace 392 | (?> 393 | [^>"/]+ # text outside quotes 394 | | 395 | /+(?!>) # slash not followed by ">" 396 | | 397 | "[^"]*" # text inside double quotes (tolerate ">") 398 | | 399 | \'[^\']*\' # text inside single quotes (tolerate ">") 400 | )* 401 | )? 402 | '; 403 | $content = 404 | str_repeat(' 405 | (?> 406 | [^<]+ # content without tag 407 | | 408 | <\2 # nested opening tag 409 | '.$attr.' # attributes 410 | (?> 411 | /> 412 | | 413 | >', $nested_tags_level). # end of opening tag 414 | '.*?'. # last level nested tag content 415 | str_repeat(' 416 | # closing nested tag 417 | ) 418 | | 419 | <(?!/\2\s*> # other tags with a different name 420 | ) 421 | )*', 422 | $nested_tags_level); 423 | $content2 = str_replace('\2', '\3', $content); 424 | 425 | # First, look for nested blocks, e.g.: 426 | #

    427 | #
    428 | # tags for inner block must be indented. 429 | #
    430 | #
    431 | # 432 | # The outermost tags must start at the left margin for this to match, and 433 | # the inner nested divs must be indented. 434 | # We need to do this before the next, more liberal match, because the next 435 | # match will start at the first `
    ` and stop at the first `
    `. 436 | $text = preg_replace_callback('{(?> 437 | (?> 438 | (?<=\n\n) # Starting after a blank line 439 | | # or 440 | \A\n? # the beginning of the doc 441 | ) 442 | ( # save in $1 443 | 444 | # Match from `\n` to `\n`, handling nested tags 445 | # in between. 446 | 447 | [ ]{0,'.$less_than_tab.'} 448 | <('.$block_tags_b_re.')# start tag = $2 449 | '.$attr.'> # attributes followed by > and \n 450 | '.$content.' # content, support nesting 451 | # the matching end tag 452 | [ ]* # trailing spaces/tabs 453 | (?=\n+|\Z) # followed by a newline or end of document 454 | 455 | | # Special version for tags of group a. 456 | 457 | [ ]{0,'.$less_than_tab.'} 458 | <('.$block_tags_a_re.')# start tag = $3 459 | '.$attr.'>[ ]*\n # attributes followed by > 460 | '.$content2.' # content, support nesting 461 | # the matching end tag 462 | [ ]* # trailing spaces/tabs 463 | (?=\n+|\Z) # followed by a newline or end of document 464 | 465 | | # Special case just for
    . It was easier to make a special 466 | # case than to make the other regex more complicated. 467 | 468 | [ ]{0,'.$less_than_tab.'} 469 | <(hr) # start tag = $2 470 | '.$attr.' # attributes 471 | /?> # the matching end tag 472 | [ ]* 473 | (?=\n{2,}|\Z) # followed by a blank line or end of document 474 | 475 | | # Special case for standalone HTML comments: 476 | 477 | [ ]{0,'.$less_than_tab.'} 478 | (?s: 479 | 480 | ) 481 | [ ]* 482 | (?=\n{2,}|\Z) # followed by a blank line or end of document 483 | 484 | | # PHP and ASP-style processor instructions ( 491 | ) 492 | [ ]* 493 | (?=\n{2,}|\Z) # followed by a blank line or end of document 494 | 495 | ) 496 | )}Sxmi', 497 | array(&$this, '_hashHTMLBlocks_callback'), 498 | $text); 499 | 500 | return $text; 501 | } 502 | function _hashHTMLBlocks_callback($matches) { 503 | $text = $matches[1]; 504 | $key = $this->hashBlock($text); 505 | return "\n\n$key\n\n"; 506 | } 507 | 508 | 509 | function hashPart($text, $boundary = 'X') { 510 | # 511 | # Called whenever a tag must be hashed when a function insert an atomic 512 | # element in the text stream. Passing $text to through this function gives 513 | # a unique text-token which will be reverted back when calling unhash. 514 | # 515 | # The $boundary argument specify what character should be used to surround 516 | # the token. By convension, "B" is used for block elements that needs not 517 | # to be wrapped into paragraph tags at the end, ":" is used for elements 518 | # that are word separators and "X" is used in the general case. 519 | # 520 | # Swap back any tag hash found in $text so we do not have to `unhash` 521 | # multiple times at the end. 522 | $text = $this->unhash($text); 523 | 524 | # Then hash the block. 525 | static $i = 0; 526 | $key = "$boundary\x1A" . ++$i . $boundary; 527 | $this->html_hashes[$key] = $text; 528 | return $key; # String that will replace the tag. 529 | } 530 | 531 | 532 | function hashBlock($text) { 533 | # 534 | # Shortcut function for hashPart with block-level boundaries. 535 | # 536 | return $this->hashPart($text, 'B'); 537 | } 538 | 539 | 540 | var $block_gamut = array( 541 | # 542 | # These are all the transformations that form block-level 543 | # tags like paragraphs, headers, and list items. 544 | # 545 | "doHeaders" => 10, 546 | "doHorizontalRules" => 20, 547 | 548 | "doLists" => 40, 549 | "doCodeBlocks" => 50, 550 | "doBlockQuotes" => 60, 551 | ); 552 | 553 | function runBlockGamut($text) { 554 | # 555 | # Run block gamut tranformations. 556 | # 557 | # We need to escape raw HTML in Markdown source before doing anything 558 | # else. This need to be done for each block, and not only at the 559 | # begining in the Markdown function since hashed blocks can be part of 560 | # list items and could have been indented. Indented blocks would have 561 | # been seen as a code block in a previous pass of hashHTMLBlocks. 562 | $text = $this->hashHTMLBlocks($text); 563 | 564 | return $this->runBasicBlockGamut($text); 565 | } 566 | 567 | function runBasicBlockGamut($text) { 568 | # 569 | # Run block gamut tranformations, without hashing HTML blocks. This is 570 | # useful when HTML blocks are known to be already hashed, like in the first 571 | # whole-document pass. 572 | # 573 | foreach ($this->block_gamut as $method => $priority) { 574 | $text = $this->$method($text); 575 | } 576 | 577 | # Finally form paragraph and restore hashed blocks. 578 | $text = $this->formParagraphs($text); 579 | 580 | return $text; 581 | } 582 | 583 | 584 | function doHorizontalRules($text) { 585 | # Do Horizontal Rules: 586 | return preg_replace( 587 | '{ 588 | ^[ ]{0,3} # Leading space 589 | ([-*_]) # $1: First marker 590 | (?> # Repeated marker group 591 | [ ]{0,2} # Zero, one, or two spaces. 592 | \1 # Marker character 593 | ){2,} # Group repeated at least twice 594 | [ ]* # Tailing spaces 595 | $ # End of line. 596 | }mx', 597 | "\n".$this->hashBlock("empty_element_suffix")."\n", 598 | $text); 599 | } 600 | 601 | 602 | var $span_gamut = array( 603 | # 604 | # These are all the transformations that occur *within* block-level 605 | # tags like paragraphs, headers, and list items. 606 | # 607 | # Process character escapes, code spans, and inline HTML 608 | # in one shot. 609 | "parseSpan" => -30, 610 | 611 | # Process anchor and image tags. Images must come first, 612 | # because ![foo][f] looks like an anchor. 613 | "doImages" => 10, 614 | "doAnchors" => 20, 615 | 616 | # Make links out of things like `` 617 | # Must come after doAnchors, because you can use < and > 618 | # delimiters in inline links like [this](). 619 | "doAutoLinks" => 30, 620 | "encodeAmpsAndAngles" => 40, 621 | 622 | "doItalicsAndBold" => 50, 623 | "doHardBreaks" => 60, 624 | ); 625 | 626 | function runSpanGamut($text) { 627 | # 628 | # Run span gamut tranformations. 629 | # 630 | foreach ($this->span_gamut as $method => $priority) { 631 | $text = $this->$method($text); 632 | } 633 | 634 | return $text; 635 | } 636 | 637 | 638 | function doHardBreaks($text) { 639 | # Do hard breaks: 640 | return preg_replace_callback('/ {2,}\n/', 641 | array(&$this, '_doHardBreaks_callback'), $text); 642 | } 643 | function _doHardBreaks_callback($matches) { 644 | return $this->hashPart("empty_element_suffix\n"); 645 | } 646 | 647 | 648 | function doAnchors($text) { 649 | # 650 | # Turn Markdown link shortcuts into XHTML tags. 651 | # 652 | if ($this->in_anchor) return $text; 653 | $this->in_anchor = true; 654 | 655 | # 656 | # First, handle reference-style links: [link text] [id] 657 | # 658 | $text = preg_replace_callback('{ 659 | ( # wrap whole match in $1 660 | \[ 661 | ('.$this->nested_brackets_re.') # link text = $2 662 | \] 663 | 664 | [ ]? # one optional space 665 | (?:\n[ ]*)? # one optional newline followed by spaces 666 | 667 | \[ 668 | (.*?) # id = $3 669 | \] 670 | ) 671 | }xs', 672 | array(&$this, '_doAnchors_reference_callback'), $text); 673 | 674 | # 675 | # Next, inline-style links: [link text](url "optional title") 676 | # 677 | $text = preg_replace_callback('{ 678 | ( # wrap whole match in $1 679 | \[ 680 | ('.$this->nested_brackets_re.') # link text = $2 681 | \] 682 | \( # literal paren 683 | [ \n]* 684 | (?: 685 | <(.+?)> # href = $3 686 | | 687 | ('.$this->nested_url_parenthesis_re.') # href = $4 688 | ) 689 | [ \n]* 690 | ( # $5 691 | ([\'"]) # quote char = $6 692 | (.*?) # Title = $7 693 | \6 # matching quote 694 | [ \n]* # ignore any spaces/tabs between closing quote and ) 695 | )? # title is optional 696 | \) 697 | ) 698 | }xs', 699 | array(&$this, '_doAnchors_inline_callback'), $text); 700 | 701 | # 702 | # Last, handle reference-style shortcuts: [link text] 703 | # These must come last in case you've also got [link text][1] 704 | # or [link text](/foo) 705 | # 706 | $text = preg_replace_callback('{ 707 | ( # wrap whole match in $1 708 | \[ 709 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] 710 | \] 711 | ) 712 | }xs', 713 | array(&$this, '_doAnchors_reference_callback'), $text); 714 | 715 | $this->in_anchor = false; 716 | return $text; 717 | } 718 | function _doAnchors_reference_callback($matches) { 719 | $whole_match = $matches[1]; 720 | $link_text = $matches[2]; 721 | $link_id =& $matches[3]; 722 | 723 | if ($link_id == "") { 724 | # for shortcut links like [this][] or [this]. 725 | $link_id = $link_text; 726 | } 727 | 728 | # lower-case and turn embedded newlines into spaces 729 | $link_id = strtolower($link_id); 730 | $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); 731 | 732 | if (isset($this->urls[$link_id])) { 733 | $url = $this->urls[$link_id]; 734 | $url = $this->encodeAttribute($url); 735 | 736 | $result = "titles[$link_id] ) ) { 738 | $title = $this->titles[$link_id]; 739 | $title = $this->encodeAttribute($title); 740 | $result .= " title=\"$title\""; 741 | } 742 | 743 | $link_text = $this->runSpanGamut($link_text); 744 | $result .= ">$link_text"; 745 | $result = $this->hashPart($result); 746 | } 747 | else { 748 | $result = $whole_match; 749 | } 750 | return $result; 751 | } 752 | function _doAnchors_inline_callback($matches) { 753 | $whole_match = $matches[1]; 754 | $link_text = $this->runSpanGamut($matches[2]); 755 | $url = $matches[3] == '' ? $matches[4] : $matches[3]; 756 | $title =& $matches[7]; 757 | 758 | $url = $this->encodeAttribute($url); 759 | 760 | $result = "encodeAttribute($title); 763 | $result .= " title=\"$title\""; 764 | } 765 | 766 | $link_text = $this->runSpanGamut($link_text); 767 | $result .= ">$link_text"; 768 | 769 | return $this->hashPart($result); 770 | } 771 | 772 | 773 | function doImages($text) { 774 | # 775 | # Turn Markdown image shortcuts into tags. 776 | # 777 | # 778 | # First, handle reference-style labeled images: ![alt text][id] 779 | # 780 | $text = preg_replace_callback('{ 781 | ( # wrap whole match in $1 782 | !\[ 783 | ('.$this->nested_brackets_re.') # alt text = $2 784 | \] 785 | 786 | [ ]? # one optional space 787 | (?:\n[ ]*)? # one optional newline followed by spaces 788 | 789 | \[ 790 | (.*?) # id = $3 791 | \] 792 | 793 | ) 794 | }xs', 795 | array(&$this, '_doImages_reference_callback'), $text); 796 | 797 | # 798 | # Next, handle inline images: ![alt text](url "optional title") 799 | # Don't forget: encode * and _ 800 | # 801 | $text = preg_replace_callback('{ 802 | ( # wrap whole match in $1 803 | !\[ 804 | ('.$this->nested_brackets_re.') # alt text = $2 805 | \] 806 | \s? # One optional whitespace character 807 | \( # literal paren 808 | [ \n]* 809 | (?: 810 | <(\S*)> # src url = $3 811 | | 812 | ('.$this->nested_url_parenthesis_re.') # src url = $4 813 | ) 814 | [ \n]* 815 | ( # $5 816 | ([\'"]) # quote char = $6 817 | (.*?) # title = $7 818 | \6 # matching quote 819 | [ \n]* 820 | )? # title is optional 821 | \) 822 | ) 823 | }xs', 824 | array(&$this, '_doImages_inline_callback'), $text); 825 | 826 | return $text; 827 | } 828 | function _doImages_reference_callback($matches) { 829 | $whole_match = $matches[1]; 830 | $alt_text = $matches[2]; 831 | $link_id = strtolower($matches[3]); 832 | 833 | if ($link_id == "") { 834 | $link_id = strtolower($alt_text); # for shortcut links like ![this][]. 835 | } 836 | 837 | $alt_text = $this->encodeAttribute($alt_text); 838 | if (isset($this->urls[$link_id])) { 839 | $url = $this->encodeAttribute($this->urls[$link_id]); 840 | $result = "\"$alt_text\"";titles[$link_id])) { 842 | $title = $this->titles[$link_id]; 843 | $title = $this->encodeAttribute($title); 844 | $result .= " title=\"$title\""; 845 | } 846 | $result .= $this->empty_element_suffix; 847 | $result = $this->hashPart($result); 848 | } 849 | else { 850 | # If there's no such link ID, leave intact: 851 | $result = $whole_match; 852 | } 853 | 854 | return $result; 855 | } 856 | function _doImages_inline_callback($matches) { 857 | $whole_match = $matches[1]; 858 | $alt_text = $matches[2]; 859 | $url = $matches[3] == '' ? $matches[4] : $matches[3]; 860 | $title =& $matches[7]; 861 | 862 | $alt_text = $this->encodeAttribute($alt_text); 863 | $url = $this->encodeAttribute($url); 864 | $result = "\"$alt_text\"";encodeAttribute($title); 867 | $result .= " title=\"$title\""; # $title already quoted 868 | } 869 | $result .= $this->empty_element_suffix; 870 | 871 | return $this->hashPart($result); 872 | } 873 | 874 | 875 | function doHeaders($text) { 876 | # Setext-style headers: 877 | # Header 1 878 | # ======== 879 | # 880 | # Header 2 881 | # -------- 882 | # 883 | $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', 884 | array(&$this, '_doHeaders_callback_setext'), $text); 885 | 886 | # atx-style headers: 887 | # # Header 1 888 | # ## Header 2 889 | # ## Header 2 with closing hashes ## 890 | # ... 891 | # ###### Header 6 892 | # 893 | $text = preg_replace_callback('{ 894 | ^(\#{1,6}) # $1 = string of #\'s 895 | [ ]* 896 | (.+?) # $2 = Header text 897 | [ ]* 898 | \#* # optional closing #\'s (not counted) 899 | \n+ 900 | }xm', 901 | array(&$this, '_doHeaders_callback_atx'), $text); 902 | 903 | return $text; 904 | } 905 | function _doHeaders_callback_setext($matches) { 906 | # Terrible hack to check we haven't found an empty list item. 907 | if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) 908 | return $matches[0]; 909 | 910 | $level = $matches[2]{0} == '=' ? 1 : 2; 911 | $block = "".$this->runSpanGamut($matches[1]).""; 912 | return "\n" . $this->hashBlock($block) . "\n\n"; 913 | } 914 | function _doHeaders_callback_atx($matches) { 915 | $level = strlen($matches[1]); 916 | $block = "".$this->runSpanGamut($matches[2]).""; 917 | return "\n" . $this->hashBlock($block) . "\n\n"; 918 | } 919 | 920 | 921 | function doLists($text) { 922 | # 923 | # Form HTML ordered (numbered) and unordered (bulleted) lists. 924 | # 925 | $less_than_tab = $this->tab_width - 1; 926 | 927 | # Re-usable patterns to match list item bullets and number markers: 928 | $marker_ul_re = '[*+-]'; 929 | $marker_ol_re = '\d+[\.]'; 930 | $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; 931 | 932 | $markers_relist = array( 933 | $marker_ul_re => $marker_ol_re, 934 | $marker_ol_re => $marker_ul_re, 935 | ); 936 | 937 | foreach ($markers_relist as $marker_re => $other_marker_re) { 938 | # Re-usable pattern to match any entirel ul or ol list: 939 | $whole_list_re = ' 940 | ( # $1 = whole list 941 | ( # $2 942 | ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces 943 | ('.$marker_re.') # $4 = first list item marker 944 | [ ]+ 945 | ) 946 | (?s:.+?) 947 | ( # $5 948 | \z 949 | | 950 | \n{2,} 951 | (?=\S) 952 | (?! # Negative lookahead for another list item marker 953 | [ ]* 954 | '.$marker_re.'[ ]+ 955 | ) 956 | | 957 | (?= # Lookahead for another kind of list 958 | \n 959 | \3 # Must have the same indentation 960 | '.$other_marker_re.'[ ]+ 961 | ) 962 | ) 963 | ) 964 | '; // mx 965 | 966 | # We use a different prefix before nested lists than top-level lists. 967 | # See extended comment in _ProcessListItems(). 968 | 969 | if ($this->list_level) { 970 | $text = preg_replace_callback('{ 971 | ^ 972 | '.$whole_list_re.' 973 | }mx', 974 | array(&$this, '_doLists_callback'), $text); 975 | } 976 | else { 977 | $text = preg_replace_callback('{ 978 | (?:(?<=\n)\n|\A\n?) # Must eat the newline 979 | '.$whole_list_re.' 980 | }mx', 981 | array(&$this, '_doLists_callback'), $text); 982 | } 983 | } 984 | 985 | return $text; 986 | } 987 | function _doLists_callback($matches) { 988 | # Re-usable patterns to match list item bullets and number markers: 989 | $marker_ul_re = '[*+-]'; 990 | $marker_ol_re = '\d+[\.]'; 991 | $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; 992 | 993 | $list = $matches[1]; 994 | $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; 995 | 996 | $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); 997 | 998 | $list .= "\n"; 999 | $result = $this->processListItems($list, $marker_any_re); 1000 | 1001 | $result = $this->hashBlock("<$list_type>\n" . $result . ""); 1002 | return "\n". $result ."\n\n"; 1003 | } 1004 | 1005 | var $list_level = 0; 1006 | 1007 | function processListItems($list_str, $marker_any_re) { 1008 | # 1009 | # Process the contents of a single ordered or unordered list, splitting it 1010 | # into individual list items. 1011 | # 1012 | # The $this->list_level global keeps track of when we're inside a list. 1013 | # Each time we enter a list, we increment it; when we leave a list, 1014 | # we decrement. If it's zero, we're not in a list anymore. 1015 | # 1016 | # We do this because when we're not inside a list, we want to treat 1017 | # something like this: 1018 | # 1019 | # I recommend upgrading to version 1020 | # 8. Oops, now this line is treated 1021 | # as a sub-list. 1022 | # 1023 | # As a single paragraph, despite the fact that the second line starts 1024 | # with a digit-period-space sequence. 1025 | # 1026 | # Whereas when we're inside a list (or sub-list), that line will be 1027 | # treated as the start of a sub-list. What a kludge, huh? This is 1028 | # an aspect of Markdown's syntax that's hard to parse perfectly 1029 | # without resorting to mind-reading. Perhaps the solution is to 1030 | # change the syntax rules such that sub-lists must start with a 1031 | # starting cardinal number; e.g. "1." or "a.". 1032 | 1033 | $this->list_level++; 1034 | 1035 | # trim trailing blank lines: 1036 | $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); 1037 | 1038 | $list_str = preg_replace_callback('{ 1039 | (\n)? # leading line = $1 1040 | (^[ ]*) # leading whitespace = $2 1041 | ('.$marker_any_re.' # list marker and space = $3 1042 | (?:[ ]+|(?=\n)) # space only required if item is not empty 1043 | ) 1044 | ((?s:.*?)) # list item text = $4 1045 | (?:(\n+(?=\n))|\n) # tailing blank line = $5 1046 | (?= \n* (\z | \2 ('.$marker_any_re.') (?:[ ]+|(?=\n)))) 1047 | }xm', 1048 | array(&$this, '_processListItems_callback'), $list_str); 1049 | 1050 | $this->list_level--; 1051 | return $list_str; 1052 | } 1053 | function _processListItems_callback($matches) { 1054 | $item = $matches[4]; 1055 | $leading_line =& $matches[1]; 1056 | $leading_space =& $matches[2]; 1057 | $marker_space = $matches[3]; 1058 | $tailing_blank_line =& $matches[5]; 1059 | 1060 | if ($leading_line || $tailing_blank_line || 1061 | preg_match('/\n{2,}/', $item)) 1062 | { 1063 | # Replace marker with the appropriate whitespace indentation 1064 | $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; 1065 | $item = $this->runBlockGamut($this->outdent($item)."\n"); 1066 | } 1067 | else { 1068 | # Recursion for sub-lists: 1069 | $item = $this->doLists($this->outdent($item)); 1070 | $item = preg_replace('/\n+$/', '', $item); 1071 | $item = $this->runSpanGamut($item); 1072 | } 1073 | 1074 | return "
  • " . $item . "
  • \n"; 1075 | } 1076 | 1077 | 1078 | function doCodeBlocks($text) { 1079 | # 1080 | # Process Markdown `
    ` blocks.
    1081 | 	#
    1082 | 		$text = preg_replace_callback('{
    1083 | 				(?:\n\n|\A\n?)
    1084 | 				(	            # $1 = the code block -- one or more lines, starting with a space/tab
    1085 | 				  (?>
    1086 | 					[ ]{'.$this->tab_width.'}  # Lines must start with a tab or a tab-width of spaces
    1087 | 					.*\n+
    1088 | 				  )+
    1089 | 				)
    1090 | 				((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z)	# Lookahead for non-space at line-start, or end of doc
    1091 | 			}xm',
    1092 | 			array(&$this, '_doCodeBlocks_callback'), $text);
    1093 | 
    1094 | 		return $text;
    1095 | 	}
    1096 | 	function _doCodeBlocks_callback($matches) {
    1097 | 		$codeblock = $matches[1];
    1098 | 
    1099 | 		$codeblock = $this->outdent($codeblock);
    1100 | 		$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
    1101 | 
    1102 | 		# trim leading newlines and trailing newlines
    1103 | 		$codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
    1104 | 
    1105 | 		$codeblock = "
    $codeblock\n
    "; 1106 | return "\n\n".$this->hashBlock($codeblock)."\n\n"; 1107 | } 1108 | 1109 | 1110 | function makeCodeSpan($code) { 1111 | # 1112 | # Create a code span markup for $code. Called from handleSpanToken. 1113 | # 1114 | $code = htmlspecialchars(trim($code), ENT_NOQUOTES); 1115 | return $this->hashPart("$code"); 1116 | } 1117 | 1118 | 1119 | var $em_relist = array( 1120 | '' => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(?em_relist as $em => $em_re) { 1142 | foreach ($this->strong_relist as $strong => $strong_re) { 1143 | # Construct list of allowed token expressions. 1144 | $token_relist = array(); 1145 | if (isset($this->em_strong_relist["$em$strong"])) { 1146 | $token_relist[] = $this->em_strong_relist["$em$strong"]; 1147 | } 1148 | $token_relist[] = $em_re; 1149 | $token_relist[] = $strong_re; 1150 | 1151 | # Construct master expression from list. 1152 | $token_re = '{('. implode('|', $token_relist) .')}'; 1153 | $this->em_strong_prepared_relist["$em$strong"] = $token_re; 1154 | } 1155 | } 1156 | } 1157 | 1158 | function doItalicsAndBold($text) { 1159 | $token_stack = array(''); 1160 | $text_stack = array(''); 1161 | $em = ''; 1162 | $strong = ''; 1163 | $tree_char_em = false; 1164 | 1165 | while (1) { 1166 | # 1167 | # Get prepared regular expression for seraching emphasis tokens 1168 | # in current context. 1169 | # 1170 | $token_re = $this->em_strong_prepared_relist["$em$strong"]; 1171 | 1172 | # 1173 | # Each loop iteration search for the next emphasis token. 1174 | # Each token is then passed to handleSpanToken. 1175 | # 1176 | $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); 1177 | $text_stack[0] .= $parts[0]; 1178 | $token =& $parts[1]; 1179 | $text =& $parts[2]; 1180 | 1181 | if (empty($token)) { 1182 | # Reached end of text span: empty stack without emitting. 1183 | # any more emphasis. 1184 | while ($token_stack[0]) { 1185 | $text_stack[1] .= array_shift($token_stack); 1186 | $text_stack[0] .= array_shift($text_stack); 1187 | } 1188 | break; 1189 | } 1190 | 1191 | $token_len = strlen($token); 1192 | if ($tree_char_em) { 1193 | # Reached closing marker while inside a three-char emphasis. 1194 | if ($token_len == 3) { 1195 | # Three-char closing marker, close em and strong. 1196 | array_shift($token_stack); 1197 | $span = array_shift($text_stack); 1198 | $span = $this->runSpanGamut($span); 1199 | $span = "$span"; 1200 | $text_stack[0] .= $this->hashPart($span); 1201 | $em = ''; 1202 | $strong = ''; 1203 | } else { 1204 | # Other closing marker: close one em or strong and 1205 | # change current token state to match the other 1206 | $token_stack[0] = str_repeat($token{0}, 3-$token_len); 1207 | $tag = $token_len == 2 ? "strong" : "em"; 1208 | $span = $text_stack[0]; 1209 | $span = $this->runSpanGamut($span); 1210 | $span = "<$tag>$span"; 1211 | $text_stack[0] = $this->hashPart($span); 1212 | $$tag = ''; # $$tag stands for $em or $strong 1213 | } 1214 | $tree_char_em = false; 1215 | } else if ($token_len == 3) { 1216 | if ($em) { 1217 | # Reached closing marker for both em and strong. 1218 | # Closing strong marker: 1219 | for ($i = 0; $i < 2; ++$i) { 1220 | $shifted_token = array_shift($token_stack); 1221 | $tag = strlen($shifted_token) == 2 ? "strong" : "em"; 1222 | $span = array_shift($text_stack); 1223 | $span = $this->runSpanGamut($span); 1224 | $span = "<$tag>$span"; 1225 | $text_stack[0] .= $this->hashPart($span); 1226 | $$tag = ''; # $$tag stands for $em or $strong 1227 | } 1228 | } else { 1229 | # Reached opening three-char emphasis marker. Push on token 1230 | # stack; will be handled by the special condition above. 1231 | $em = $token{0}; 1232 | $strong = "$em$em"; 1233 | array_unshift($token_stack, $token); 1234 | array_unshift($text_stack, ''); 1235 | $tree_char_em = true; 1236 | } 1237 | } else if ($token_len == 2) { 1238 | if ($strong) { 1239 | # Unwind any dangling emphasis marker: 1240 | if (strlen($token_stack[0]) == 1) { 1241 | $text_stack[1] .= array_shift($token_stack); 1242 | $text_stack[0] .= array_shift($text_stack); 1243 | } 1244 | # Closing strong marker: 1245 | array_shift($token_stack); 1246 | $span = array_shift($text_stack); 1247 | $span = $this->runSpanGamut($span); 1248 | $span = "$span"; 1249 | $text_stack[0] .= $this->hashPart($span); 1250 | $strong = ''; 1251 | } else { 1252 | array_unshift($token_stack, $token); 1253 | array_unshift($text_stack, ''); 1254 | $strong = $token; 1255 | } 1256 | } else { 1257 | # Here $token_len == 1 1258 | if ($em) { 1259 | if (strlen($token_stack[0]) == 1) { 1260 | # Closing emphasis marker: 1261 | array_shift($token_stack); 1262 | $span = array_shift($text_stack); 1263 | $span = $this->runSpanGamut($span); 1264 | $span = "$span"; 1265 | $text_stack[0] .= $this->hashPart($span); 1266 | $em = ''; 1267 | } else { 1268 | $text_stack[0] .= $token; 1269 | } 1270 | } else { 1271 | array_unshift($token_stack, $token); 1272 | array_unshift($text_stack, ''); 1273 | $em = $token; 1274 | } 1275 | } 1276 | } 1277 | return $text_stack[0]; 1278 | } 1279 | 1280 | 1281 | function doBlockQuotes($text) { 1282 | $text = preg_replace_callback('/ 1283 | ( # Wrap whole match in $1 1284 | (?> 1285 | ^[ ]*>[ ]? # ">" at the start of a line 1286 | .+\n # rest of the first line 1287 | (.+\n)* # subsequent consecutive lines 1288 | \n* # blanks 1289 | )+ 1290 | ) 1291 | /xm', 1292 | array(&$this, '_doBlockQuotes_callback'), $text); 1293 | 1294 | return $text; 1295 | } 1296 | function _doBlockQuotes_callback($matches) { 1297 | $bq = $matches[1]; 1298 | # trim one level of quoting - trim whitespace-only lines 1299 | $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); 1300 | $bq = $this->runBlockGamut($bq); # recurse 1301 | 1302 | $bq = preg_replace('/^/m', " ", $bq); 1303 | # These leading spaces cause problem with
     content, 
    1304 | 		# so we need to fix that:
    1305 | 		$bq = preg_replace_callback('{(\s*
    .+?
    )}sx', 1306 | array(&$this, '_doBlockQuotes_callback2'), $bq); 1307 | 1308 | return "\n". $this->hashBlock("
    \n$bq\n
    ")."\n\n"; 1309 | } 1310 | function _doBlockQuotes_callback2($matches) { 1311 | $pre = $matches[1]; 1312 | $pre = preg_replace('/^ /m', '', $pre); 1313 | return $pre; 1314 | } 1315 | 1316 | 1317 | function formParagraphs($text) { 1318 | # 1319 | # Params: 1320 | # $text - string to process with html

    tags 1321 | # 1322 | # Strip leading and trailing lines: 1323 | $text = preg_replace('/\A\n+|\n+\z/', '', $text); 1324 | 1325 | $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); 1326 | 1327 | # 1328 | # Wrap

    tags and unhashify HTML blocks 1329 | # 1330 | foreach ($grafs as $key => $value) { 1331 | if (!preg_match('/^B\x1A[0-9]+B$/', $value)) { 1332 | # Is a paragraph. 1333 | $value = $this->runSpanGamut($value); 1334 | $value = preg_replace('/^([ ]*)/', "

    ", $value); 1335 | $value .= "

    "; 1336 | $grafs[$key] = $this->unhash($value); 1337 | } 1338 | else { 1339 | # Is a block. 1340 | # Modify elements of @grafs in-place... 1341 | $graf = $value; 1342 | $block = $this->html_hashes[$graf]; 1343 | $graf = $block; 1344 | // if (preg_match('{ 1345 | // \A 1346 | // ( # $1 =
    tag 1347 | //
    ]* 1349 | // \b 1350 | // markdown\s*=\s* ([\'"]) # $2 = attr quote char 1351 | // 1 1352 | // \2 1353 | // [^>]* 1354 | // > 1355 | // ) 1356 | // ( # $3 = contents 1357 | // .* 1358 | // ) 1359 | // (
    ) # $4 = closing tag 1360 | // \z 1361 | // }xs', $block, $matches)) 1362 | // { 1363 | // list(, $div_open, , $div_content, $div_close) = $matches; 1364 | // 1365 | // # We can't call Markdown(), because that resets the hash; 1366 | // # that initialization code should be pulled into its own sub, though. 1367 | // $div_content = $this->hashHTMLBlocks($div_content); 1368 | // 1369 | // # Run document gamut methods on the content. 1370 | // foreach ($this->document_gamut as $method => $priority) { 1371 | // $div_content = $this->$method($div_content); 1372 | // } 1373 | // 1374 | // $div_open = preg_replace( 1375 | // '{\smarkdown\s*=\s*([\'"]).+?\1}', '', $div_open); 1376 | // 1377 | // $graf = $div_open . "\n" . $div_content . "\n" . $div_close; 1378 | // } 1379 | $grafs[$key] = $graf; 1380 | } 1381 | } 1382 | 1383 | return implode("\n\n", $grafs); 1384 | } 1385 | 1386 | 1387 | function encodeAttribute($text) { 1388 | # 1389 | # Encode text for a double-quoted HTML attribute. This function 1390 | # is *not* suitable for attributes enclosed in single quotes. 1391 | # 1392 | $text = $this->encodeAmpsAndAngles($text); 1393 | $text = str_replace('"', '"', $text); 1394 | return $text; 1395 | } 1396 | 1397 | 1398 | function encodeAmpsAndAngles($text) { 1399 | # 1400 | # Smart processing for ampersands and angle brackets that need to 1401 | # be encoded. Valid character entities are left alone unless the 1402 | # no-entities mode is set. 1403 | # 1404 | if ($this->no_entities) { 1405 | $text = str_replace('&', '&', $text); 1406 | } else { 1407 | # Ampersand-encoding based entirely on Nat Irons's Amputator 1408 | # MT plugin: 1409 | $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', 1410 | '&', $text);; 1411 | } 1412 | # Encode remaining <'s 1413 | $text = str_replace('<', '<', $text); 1414 | 1415 | return $text; 1416 | } 1417 | 1418 | 1419 | function doAutoLinks($text) { 1420 | $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', 1421 | array(&$this, '_doAutoLinks_url_callback'), $text); 1422 | 1423 | # Email addresses: 1424 | $text = preg_replace_callback('{ 1425 | < 1426 | (?:mailto:)? 1427 | ( 1428 | (?: 1429 | [-!#$%&\'*+/=?^_`.{|}~\w\x80-\xFF]+ 1430 | | 1431 | ".*?" 1432 | ) 1433 | \@ 1434 | (?: 1435 | [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+ 1436 | | 1437 | \[[\d.a-fA-F:]+\] # IPv4 & IPv6 1438 | ) 1439 | ) 1440 | > 1441 | }xi', 1442 | array(&$this, '_doAutoLinks_email_callback'), $text); 1443 | 1444 | return $text; 1445 | } 1446 | function _doAutoLinks_url_callback($matches) { 1447 | $url = $this->encodeAttribute($matches[1]); 1448 | $link = "$url"; 1449 | return $this->hashPart($link); 1450 | } 1451 | function _doAutoLinks_email_callback($matches) { 1452 | $address = $matches[1]; 1453 | $link = $this->encodeEmailAddress($address); 1454 | return $this->hashPart($link); 1455 | } 1456 | 1457 | 1458 | function encodeEmailAddress($addr) { 1459 | # 1460 | # Input: an email address, e.g. "foo@example.com" 1461 | # 1462 | # Output: the email address as a mailto link, with each character 1463 | # of the address encoded as either a decimal or hex entity, in 1464 | # the hopes of foiling most address harvesting spam bots. E.g.: 1465 | # 1466 | #

    foo@exampl 1469 | # e.com

    1470 | # 1471 | # Based by a filter by Matthew Wickline, posted to BBEdit-Talk. 1472 | # With some optimizations by Milian Wolff. 1473 | # 1474 | $addr = "mailto:" . $addr; 1475 | $chars = preg_split('/(? $char) { 1479 | $ord = ord($char); 1480 | # Ignore non-ascii chars. 1481 | if ($ord < 128) { 1482 | $r = ($seed * (1 + $key)) % 100; # Pseudo-random function. 1483 | # roughly 10% raw, 45% hex, 45% dec 1484 | # '@' *must* be encoded. I insist. 1485 | if ($r > 90 && $char != '@') /* do nothing */; 1486 | else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; 1487 | else $chars[$key] = '&#'.$ord.';'; 1488 | } 1489 | } 1490 | 1491 | $addr = implode('', $chars); 1492 | $text = implode('', array_slice($chars, 7)); # text without `mailto:` 1493 | $addr = "$text"; 1494 | 1495 | return $addr; 1496 | } 1497 | 1498 | 1499 | function parseSpan($str) { 1500 | # 1501 | # Take the string $str and parse it into tokens, hashing embeded HTML, 1502 | # escaped characters and handling code spans. 1503 | # 1504 | $output = ''; 1505 | 1506 | $span_re = '{ 1507 | ( 1508 | \\\\'.$this->escape_chars_re.' 1509 | | 1510 | (?no_markup ? '' : ' 1513 | | 1514 | # comment 1515 | | 1516 | <\?.*?\?> | <%.*?%> # processing instruction 1517 | | 1518 | <[/!$]?[-a-zA-Z0-9:_]+ # regular tags 1519 | (?> 1520 | \s 1521 | (?>[^"\'>]+|"[^"]*"|\'[^\']*\')* 1522 | )? 1523 | > 1524 | ').' 1525 | ) 1526 | }xs'; 1527 | 1528 | while (1) { 1529 | # 1530 | # Each loop iteration seach for either the next tag, the next 1531 | # openning code span marker, or the next escaped character. 1532 | # Each token is then passed to handleSpanToken. 1533 | # 1534 | $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); 1535 | 1536 | # Create token from text preceding tag. 1537 | if ($parts[0] != "") { 1538 | $output .= $parts[0]; 1539 | } 1540 | 1541 | # Check if we reach the end. 1542 | if (isset($parts[1])) { 1543 | $output .= $this->handleSpanToken($parts[1], $parts[2]); 1544 | $str = $parts[2]; 1545 | } 1546 | else { 1547 | break; 1548 | } 1549 | } 1550 | 1551 | return $output; 1552 | } 1553 | 1554 | 1555 | function handleSpanToken($token, &$str) { 1556 | # 1557 | # Handle $token provided by parseSpan by determining its nature and 1558 | # returning the corresponding value that should replace it. 1559 | # 1560 | switch ($token{0}) { 1561 | case "\\": 1562 | return $this->hashPart("&#". ord($token{1}). ";"); 1563 | case "`": 1564 | # Search for end marker in remaining text. 1565 | if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', 1566 | $str, $matches)) 1567 | { 1568 | $str = $matches[2]; 1569 | $codespan = $this->makeCodeSpan($matches[1]); 1570 | return $this->hashPart($codespan); 1571 | } 1572 | return $token; // return as text since no ending marker found. 1573 | default: 1574 | return $this->hashPart($token); 1575 | } 1576 | } 1577 | 1578 | 1579 | function outdent($text) { 1580 | # 1581 | # Remove one level of line-leading tabs or spaces 1582 | # 1583 | return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); 1584 | } 1585 | 1586 | 1587 | # String length function for detab. `_initDetab` will create a function to 1588 | # hanlde UTF-8 if the default function does not exist. 1589 | var $utf8_strlen = 'mb_strlen'; 1590 | 1591 | function detab($text) { 1592 | # 1593 | # Replace tabs with the appropriate amount of space. 1594 | # 1595 | # For each line we separate the line in blocks delemited by 1596 | # tab characters. Then we reconstruct every line by adding the 1597 | # appropriate number of space between each blocks. 1598 | 1599 | $text = preg_replace_callback('/^.*\t.*$/m', 1600 | array(&$this, '_detab_callback'), $text); 1601 | 1602 | return $text; 1603 | } 1604 | function _detab_callback($matches) { 1605 | $line = $matches[0]; 1606 | $strlen = $this->utf8_strlen; # strlen function for UTF-8. 1607 | 1608 | # Split in blocks. 1609 | $blocks = explode("\t", $line); 1610 | # Add each blocks to the line. 1611 | $line = $blocks[0]; 1612 | unset($blocks[0]); # Do not add first block twice. 1613 | foreach ($blocks as $block) { 1614 | # Calculate amount of space, insert spaces, insert block. 1615 | $amount = $this->tab_width - 1616 | $strlen($line, 'UTF-8') % $this->tab_width; 1617 | $line .= str_repeat(" ", $amount) . $block; 1618 | } 1619 | return $line; 1620 | } 1621 | function _initDetab() { 1622 | # 1623 | # Check for the availability of the function in the `utf8_strlen` property 1624 | # (initially `mb_strlen`). If the function is not available, create a 1625 | # function that will loosely count the number of UTF-8 characters with a 1626 | # regular expression. 1627 | # 1628 | if (function_exists($this->utf8_strlen)) return; 1629 | $this->utf8_strlen = create_function('$text', 'return preg_match_all( 1630 | "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", 1631 | $text, $m);'); 1632 | } 1633 | 1634 | 1635 | function unhash($text) { 1636 | # 1637 | # Swap back in all the tags hashed by _HashHTMLBlocks. 1638 | # 1639 | return preg_replace_callback('/(.)\x1A[0-9]+\1/', 1640 | array(&$this, '_unhash_callback'), $text); 1641 | } 1642 | function _unhash_callback($matches) { 1643 | return $this->html_hashes[$matches[0]]; 1644 | } 1645 | 1646 | } 1647 | 1648 | /* 1649 | 1650 | PHP Markdown 1651 | ============ 1652 | 1653 | Description 1654 | ----------- 1655 | 1656 | This is a PHP translation of the original Markdown formatter written in 1657 | Perl by John Gruber. 1658 | 1659 | Markdown is a text-to-HTML filter; it translates an easy-to-read / 1660 | easy-to-write structured text format into HTML. Markdown's text format 1661 | is most similar to that of plain text email, and supports features such 1662 | as headers, *emphasis*, code blocks, blockquotes, and links. 1663 | 1664 | Markdown's syntax is designed not as a generic markup language, but 1665 | specifically to serve as a front-end to (X)HTML. You can use span-level 1666 | HTML tags anywhere in a Markdown document, and you can use block level 1667 | HTML tags (like
    and as well). 1668 | 1669 | For more information about Markdown's syntax, see: 1670 | 1671 | 1672 | 1673 | 1674 | Bugs 1675 | ---- 1676 | 1677 | To file bug reports please send email to: 1678 | 1679 | 1680 | 1681 | Please include with your report: (1) the example input; (2) the output you 1682 | expected; (3) the output Markdown actually produced. 1683 | 1684 | 1685 | Version History 1686 | --------------- 1687 | 1688 | See the readme file for detailed release notes for this version. 1689 | 1690 | 1691 | Copyright and License 1692 | --------------------- 1693 | 1694 | PHP Markdown 1695 | Copyright (c) 2004-2009 Michel Fortin 1696 | 1697 | All rights reserved. 1698 | 1699 | Based on Markdown 1700 | Copyright (c) 2003-2006 John Gruber 1701 | 1702 | All rights reserved. 1703 | 1704 | Redistribution and use in source and binary forms, with or without 1705 | modification, are permitted provided that the following conditions are 1706 | met: 1707 | 1708 | * Redistributions of source code must retain the above copyright notice, 1709 | this list of conditions and the following disclaimer. 1710 | 1711 | * Redistributions in binary form must reproduce the above copyright 1712 | notice, this list of conditions and the following disclaimer in the 1713 | documentation and/or other materials provided with the distribution. 1714 | 1715 | * Neither the name "Markdown" nor the names of its contributors may 1716 | be used to endorse or promote products derived from this software 1717 | without specific prior written permission. 1718 | 1719 | This software is provided by the copyright holders and contributors "as 1720 | is" and any express or implied warranties, including, but not limited 1721 | to, the implied warranties of merchantability and fitness for a 1722 | particular purpose are disclaimed. In no event shall the copyright owner 1723 | or contributors be liable for any direct, indirect, incidental, special, 1724 | exemplary, or consequential damages (including, but not limited to, 1725 | procurement of substitute goods or services; loss of use, data, or 1726 | profits; or business interruption) however caused and on any theory of 1727 | liability, whether in contract, strict liability, or tort (including 1728 | negligence or otherwise) arising in any way out of the use of this 1729 | software, even if advised of the possibility of such damage. 1730 | 1731 | */ 1732 | ?> -------------------------------------------------------------------------------- /scoreboard.php: -------------------------------------------------------------------------------- 1 | 16 |
  • Problems
  • 17 |
  • Submissions
  • 18 |
  • Scoreboard
  • 19 |
  • Account
  • 20 |
  • Logout
  • 21 | 22 | 23 | 24 | 25 | 26 | 27 |
    28 | The current standings of all the participants, the number of problems they have attempted and solved. 29 |
    30 | 31 | 32 | 33 | 34 | 35 | 36 | "); 49 | } 50 | ?> 51 | 52 |
    NameSolvedAttempted
    ".$row['username']." "); 44 | if($row['status'] == 0) echo(" Banned"); 45 | echo("".mysql_num_rows($res)); 46 | $sql = "SELECT * FROM solve WHERE (status='1' AND username='".$row['username']."')"; 47 | $res = mysql_query($sql); 48 | echo("".mysql_num_rows($res)."
    53 |
    54 | 55 | 58 | -------------------------------------------------------------------------------- /solve.php: -------------------------------------------------------------------------------- 1 | 16 |
  • Problems
  • 17 |
  • Submissions
  • 18 |
  • Scoreboard
  • 19 |
  • Account
  • 20 |
  • Logout
  • 21 | 22 |
    23 | 24 | 25 | 26 | 27 |
    28 | \nYour program exceeded the time limit. Maybe you should improve your algorithm.\n
    "); 31 | if(isset($_GET['cerror'])) 32 | echo("
    \nThe following errors occured:
    \n
    \n".$_SESSION['cerror']."\n
    \n
    "); 33 | else if(isset($_GET['oerror'])) 34 | echo("
    \nYour program output did not match the solution for the problem. Please check your program and try again.\n
    "); 35 | else if(isset($_GET['lerror'])) 36 | echo("
    \nYou did not use one of the allowed languages. Please use a language that is allowed.\n
    "); 37 | else if(isset($_GET['serror'])) 38 | echo("
    \nCould not connect to the compiler server. Please contact the admin to solve the problem.\n
    "); 39 | else if(isset($_GET['derror'])) 40 | echo("
    \nPlease enter all the details asked before you can continue!\n
    "); 41 | else if(isset($_GET['ferror'])) 42 | echo("
    \nPlease enter a legal filename.\n
    "); 43 | 44 | $query = "SELECT * FROM prefs"; 45 | $result = mysql_query($query); 46 | $accept = mysql_fetch_array($result); 47 | $query = "SELECT status FROM users WHERE username='".$_SESSION['username']."'"; 48 | $result = mysql_query($query); 49 | $status = mysql_fetch_array($result); 50 | if($accept['accept'] == 0) 51 | echo("
    \nSubmissions are closed now!\n
    "); 52 | if($status['status'] == 0) 53 | echo("
    \nYou have been banned. You cannot submit a solution.\n
    "); 54 | ?> 55 |

    Submit Solution

    56 | \n

    ".$row['name']."

    \n"); 65 | echo($out); 66 | ?> 67 |
    Time Limit: seconds 68 |
    69 | 78 | 79 | '); 81 | else 82 | echo(''); 83 | ?> 84 | 85 | 86 |
    87 |
    88 | Language: 89 | 96 | 97 | 103 |
    104 |
    105 | Filename: 106 |
    Type your program below:

    107 |
    108 | "); 109 | else echo(""); 110 | ?> 111 | You are allowed to use any of the following languages: 112 | \n"); 119 | ?> 120 | 121 | 124 | 125 | 126 | 140 | 143 | -------------------------------------------------------------------------------- /submissions.php: -------------------------------------------------------------------------------- 1 | 16 |
  • Problems
  • 17 |
  • Submissions
  • 18 |
  • Scoreboard
  • 19 |
  • Account
  • 20 |
  • Logout
  • 21 | 22 | 23 | 24 | 25 | 26 | 27 |
    28 | Below is a list of submissions you have made. Click on any to edit it. 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | \n"); 48 | else if($row['status'] == 2) 49 | echo("\n"); 50 | } 51 | } 52 | ?> 53 | 54 |
    ProblemAttemptsStatus
    ".$field['name']."".$row['attempts']); 46 | if($row['status'] == 1) 47 | echo("Attempted
    Solved
    55 |
    56 | 57 | 60 | -------------------------------------------------------------------------------- /update.php: -------------------------------------------------------------------------------- 1 | 38 | --------------------------------------------------------------------------------