Skip to content

Instantly share code, notes, and snippets.

@igorw
Created April 27, 2010 17:20
Show Gist options
  • Select an option

  • Save igorw/381020 to your computer and use it in GitHub Desktop.

Select an option

Save igorw/381020 to your computer and use it in GitHub Desktop.
Index: mpv
===================================================================
--- mpv (revision 0)
+++ mpv (revision 0)
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+php "$(dirname $0)/cli.php" "$@"
Property changes on: mpv
___________________________________________________________________
Added: svn:executable
+ *
Index: includes/mpv.php
===================================================================
--- includes/mpv.php (revision 288)
+++ includes/mpv.php (working copy)
@@ -40,6 +40,11 @@
const ERROR_INFO = 4;
/**
+ * Output validation report as plain text
+ */
+ const OUTPUT_TEXT = 0;
+
+ /**
* Output validation report as BBcode
*/
const OUTPUT_BBCODE = 1;
@@ -758,6 +763,14 @@
case self::OUTPUT_HTML:
$text = htmlspecialchars($this->message);
return generate_text_for_html_display($text);
+
+ case self::OUTPUT_TEXT:
+ $text = htmlspecialchars($this->message);
+ $text = generate_text_for_html_display($text);
+ $text = htmlspecialchars_decode(strip_tags(str_replace('<br />', "\n", $text)));
+ $text = str_replace("\n\n", "\n", $text);
+ $text = str_replace("\n", PHP_EOL, $text);
+ return $text;
default:
throw new Exception($lang['UNKNOWN_OUTPUT'] . ' "' . (int)$this->output_type . '"');
Index: cli.php
===================================================================
--- cli.php (revision 0)
+++ cli.php (revision 0)
@@ -0,0 +1,50 @@
+#!/usr/bin/php
+<?php
+/**
+* command line client
+* usage:
+* path/to/php.exe mpv.php my-mod.zip
+*
+* @package mpv
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+if (php_sapi_name() != 'cli')
+{
+ die('Please run this from the command line.');
+}
+
+if (!isset($argv[1]))
+{
+ die("Usage: mpv my-mod.zip\n");
+}
+
+if (!file_exists($argv[1]))
+{
+ die("Error: file {$argv[1]} not found\n");
+}
+
+$phpEx = substr(strrchr(__FILE__, '.'), 1);
+$root_path = './';
+
+// Will define all needed things.
+require('./mpv_config.' . $phpEx);
+require('./includes/lang.' . $phpEx);
+
+if (version_compare(PHP_VERSION, '5.2.0', '<'))
+{
+ die($lang['MIN_PHP']);
+}
+require('./includes/functions_mpv.' . $phpEx);
+require('./includes/mpv.' . $phpEx);
+
+error_reporting(E_ALL);
+
+$mpv = new mpv(null, mpv::UNZIP_PREFERENCE, false);
+$mpv->output_type = (mpv::OUTPUT_TEXT);
+$mpv->validate($argv[1]);
+
+print $lang['VALIDATION_RESULTS'] . "\n\n" . $mpv;
@katanacrimson

Copy link
Copy Markdown

Can always use the constant PHP_SAPI instead of php_sapi_name()

;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment