Пример #1
0
function printDebug($string)
{
    if (isCli()) {
        echo $string . "\n";
    } else {
        echo $string . '<br/>';
    }
}
Пример #2
0
function print_message($text)
{
    if (isCli()) {
        print Console_Color2::convert("%g" . $text . "%n\n", false);
    } else {
        echo '<div class="alert alert-success"><img src="images/16/tick.png" align="absmiddle"> ' . $text . '</div>';
    }
}
 /**
  *  load functions, to help controller
  *
  *  裡面包裹的 help function
  *  僅給 controller 使用
  *  並不給予 view 使用
  */
 protected function loadHelper(array $args)
 {
     // 目前並不是使用 controller 的方式, 所以這裡不進行以下動作
     return;
     if (isCli()) {
         // TODO: 找時間對 console 指令的格式, 做解析
         return;
     }
     $request = $args[0];
     $response = $args[1];
     $args = $args[2];
     LoadHelper::init($request, $response, $args);
 }
Пример #4
0
 private static function minifyJs()
 {
     $sourcePathConfig = tr::config()->get("app.minify");
     $minifier = new Minify\JS();
     if ($sourcePathConfig['js']) {
         foreach ($sourcePathConfig['js'] as $v) {
             if (isCli()) {
                 $v = ROOT_PATH . "/public/" . $v;
             }
             $minifier->add($v);
         }
     }
     $minifier->minify(ROOT_PATH . "/public/asset/global.js");
     return true;
 }
Пример #5
0
 public function authUpdate()
 {
     if (isCli() || static::$allowUpdate) {
         return true;
     }
     if (!static::instantiated($this)) {
         return true;
     }
     $me = Auth::user();
     if (!$me instanceof static) {
         return false;
     }
     if ($this->is($me) || $me->isAdmin()) {
         return true;
     }
     return false;
 }
Пример #6
0
function print_message($text)
{
    if (isCli()) {
        c_echo("%g" . $text . "%n\n");
    } else {
        echo '<div class="alert alert-success"><img src="images/16/tick.png" align="absmiddle"> ' . $text . '</div>';
    }
}
Пример #7
0
}
$blti_admin_form = array_merge($blti_admin_form, array('organizationid:text:label=bl_organizationid:size=80', 'organizationurl:text:label=bl_organizationurl:size=80', 'organizationdescr:text:label=bl_organizationdescr:size=80'));
$blti_content_edit_form = array('preferheight:integer:label=bl_preferheight:size=80', 'launchinpopup:radio:label=bl_launchinpopup:choices=off,on', 'debuglaunch:radio:label=bl_debuglaunch:choices=off,on', 'sendname:radio:label=bl_sendname:choices=off,on', 'sendemailaddr:radio:label=bl_sendemailaddr:choices=off,on', 'allowroster:radio:label=bl_allowroster:choices=off,on', 'allowsetting:radio:label=bl_allowsetting:choices=off,on', 'customparameters:textarea:label=bl_customparameters:rows=5:cols=25');
if (!function_exists('isCli')) {
    function isCli()
    {
        $sapi_type = php_sapi_name();
        if (substr($sapi_type, 0, 3) == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
            return true;
        } else {
            return false;
        }
    }
}
// If we are running from the command line - do a unit test
if (isCli()) {
    function startsWith($haystack, $needle, $case = true)
    {
        if ($case) {
            return strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0;
        }
        return strcasecmp(substr($haystack, 0, strlen($needle)), $needle) === 0;
    }
    function endsWith($haystack, $needle, $case = true)
    {
        if ($case) {
            return strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0;
        }
        return strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0;
    }
    $i18nstrings = array_merge(foorm_i18n_util($blti_instructor_form), foorm_i18n_util($blti_admin_form), foorm_i18n_util($blti_content_edit_form));
Пример #8
0
define('SCHEDULE_MANAGEMENTINTERVAL', 'Management_Interval');
define('SCHEDULE_MANAGEMENTCOMMAND', 'Management_Command');
define('SCHEDULE_PURGEVIDEOHOURS', 'PurgeVideo_Hours');
define('SCHEDULE_PURGEIMAGEHOURS', 'PurgeImage_Hours');
define('SCHEDULE_PURGELAPSEHOURS', 'PurgeLapse_Hours');
define('SCHEDULE_PURGESPACEMODE', 'PurgeSpace_ModeEx');
define('SCHEDULE_PURGESPACELEVEL', 'PurgeSpace_Level');
define('SCHEDULE_AUTOCAPTUREINTERVAL', 'AutoCapture_Interval');
define('SCHEDULE_COMMANDSON', 'Commands_On');
define('SCHEDULE_COMMANDSOFF', 'Commands_Off');
define('SCHEDULE_MODES', 'Modes');
define('SCHEDULE_TIMES', 'Times');
$debugString = "";
$schedulePars = array();
$schedulePars = loadPars(BASE_DIR . '/' . SCHEDULE_CONFIG);
$cliCall = isCli();
$showLog = false;
$schedulePID = getSchedulePID();
if (!$cliCall && isset($_POST['action'])) {
    //Process any POST data
    switch ($_POST['action']) {
        case 'start':
            startSchedule();
            $schedulePID = getSchedulePID();
            break;
        case 'stop':
            stopSchedule($schedulePID);
            $schedulePID = getSchedulePID();
            break;
        case 'save':
            writeLog('Saved schedule settings');
Пример #9
0
function print_message($text)
{
    if (isCli()) {
        c_echo("%g" . $text . "%n\n");
    } else {
        echo '<div class="alert alert-success"><i class="fa fa-fw fa-check-circle" aria-hidden="true"></i> ' . $text . '</div>';
    }
}
Пример #10
0
    define('NAILS_COMMON_PATH', realpath(dirname(__FILE__) . '/../common/') . '/');
}
/**
 * Setup the basic system
 */
require_once NAILS_COMMON_PATH . 'core/CORE_NAILS_Common.php';
require_once NAILS_COMMON_PATH . 'src/Startup.php';
$oStartup = new Startup();
$oStartup->init();
Factory::setup();
//  Set to run indefinitely
set_time_limit(0);
//  Make sure we're running on UTC
date_default_timezone_set('UTC');
//  Only allow the console to run whilst on the CLI
if (!isCli()) {
    echo 'This tool can only be used on the command line.';
    exit(1);
}
//  Setup error handling
Factory::service('ErrorHandler');
//  Autoload the things
Factory::helper('app_setting');
Factory::helper('app_notification');
Factory::helper('date');
Factory::helper('tools');
Factory::helper('debug');
Factory::helper('language');
Factory::helper('text');
Factory::helper('exception');
Factory::helper('log');
Пример #11
0
class Flags
{
    const ONLINE = 1;
    const HONORS = 2;
    const ST = 4;
    const CANCELLED = 8;
}
function isCli()
{
    if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
        return true;
    } else {
        return false;
    }
}
define("IS_CLI", isCli());
if (IS_CLI) {
    if (!isset($argv)) {
        echo "Usage: <script> [fall|spring]";
        return;
    }
    $term = $argv[1];
    ini_set("display_errors", 1);
    ini_set("display_startup_errors", 1);
} else {
    $term = $_GET["term"];
}
if (!isset($term)) {
    $term = date("m") < "11" ? "fall" : "spring";
}
define("TERM", $term);
Пример #12
0
/**
 * Seconds to human readable
 * @param int $seconds
 * @return string
 */
function seconds2Human($seconds)
{
    $r = '';
    $_seconds = floor($seconds);
    $ms = $seconds - $_seconds;
    $seconds = $_seconds;
    if ($hours = floor($seconds / 3600)) {
        $r .= $hours . (isCli() ? ' h ' : ' час ');
        $seconds = $seconds % 3600;
    }
    if ($minutes = floor($seconds / 60)) {
        $r .= $minutes . (isCli() ? ' m ' : ' мин ');
        $seconds = $seconds % 60;
    }
    if ($minutes < 3) {
        $r .= ' ' . $seconds + ($ms > 0 ? round($ms) : 0) . (isCli() ? ' s' : ' сек');
    }
    return $r;
}
Пример #13
0
 /**
  * Application booting completed!
  * Lets run our awesome Application
  *
  * @return mixed
  * @throws \Exception
  */
 public function run()
 {
     /*
             | We will check if script running via console
             | then we will return out from here, else application
             | fall back down
     */
     if (isCli()) {
         return $this;
     }
     try {
         $response = $this->handle();
         if ($response instanceof ResponseInterface) {
             return $response->send();
         }
         return $response;
     } catch (\Exception $e) {
         if (ENV == 'development') {
             throw $e;
         }
         if (ENV == 'production') {
             /**
              * We will log exception if logger enabled
              */
             if ($this['debugger']->isLoggerEnabled()) {
                 $this['debugger']->log($e);
             }
             $this['debugger']->renderErrorPage($e);
         }
     }
 }
Пример #14
0
 /**
  * Default authCreate, depends on authUpdate permission of "owning" object
  * Model classes that can be created by users should implement this method...
  * Top level objects which have no "owners" (like, "User" or "Project"
  * should override this method without requiring a "owner" or "parent"
  */
 public static function authCreate(PkModel $parent = null, User $user = null)
 {
     return true;
     if (isCli()) {
         return true;
     }
     if ($parent && $parent instanceof PkModel) {
         return $parent->authUpdate($user);
     }
     return false;
 }
Пример #15
0
\Koch\Localization\Utf8::initialize();
/**
 * Constants
 *
 * Constants must be defined, after initialize_paths(),
 * because of the automatic apc constants cache in
 * define_ConstantsAndPaths().
 */
define('REWRITE_ENGINE_ON', 1);
define('TESTSUBJECT_DIR', dirname(__DIR__) . DIRECTORY_SEPARATOR);
// /../tests (trunk)
/**
 * We might need some debug utils,
 * when we are not in CLI mode.
 */
if (isCli() === false) {
    require_once KOCH . 'Debug/Debug.php';
}
/**
 * Gettext Replacement
 *
 * @param type $msgid
 */
if (!function_exists('_')) {
    function _($msgid)
    {
        return $msgid;
    }
}
function isCli()
{
Пример #16
0
function print_message($text)
{
    if (isCli()) {
        print Console_Color::convert("%g" . $text . "%n\n", false);
    } else {
        echo '
    <div class="alert alert-info">
      <button type="button" class="close" data-dismiss="alert">&times;</button>
      ' . $text . '
    </div>';
    }
}
Пример #17
0
/** Sets the path and name for the debug log IF 
 * PkLibConfig::getSuppressPkDebug() is FALSE
 * @staticvar type $logpath
 * @param type $path
 * @return string
 */
function appLogPath($path = null) {
  if (PkLibConfig::getSuppressPkDebug()) {
    error_log("Debug Suppressed - No Log");
    return getNullPath();
  }
  if (isCli()) {
    $base = __DIR__;
  } else {
    $base = $_SERVER['DOCUMENT_ROOT'] . '/..';
  }
  $defaultPath = $base . '/logs/app.log';
  static $logpath = null;
  error_log("defaultPath: [$defaultPath]");
  if ($path === false) {
    $logpath = $defaultPath;
    $res = makePathToFile($logpath);
    error_log("The used log path...$logpath");
    return $logpath;
  }
  if (!$path) {
    if (!$logpath) {
      $logpath = $defaultPath;
    }
    $res = makePathToFile($logpath);
    error_log("The used log path...$logpath");
    return $logpath;
  }
  $logpath = $path;
  $res = makePathToFile($logpath);
    error_log("The used log path...$logpath");
  return $logpath;
}
Пример #18
0
function logMsg($message, $filename = "", $type = 0, $print = false, $style = 'cli')
{
    # On recupere la date
    if (!isCli()) {
        $style = 'html';
    }
    $message_type = 'INFO    : ';
    $msg = 'INFO';
    $color = 'blue';
    $date_log = "\n" . '[' . date("Y-m-d") . ' ' . date("H:i:s") . '] ';
    switch ($type) {
        case 1:
            $message_type = 'SUCCESS : ';
            $msg = 'SUCCESS';
            $color = 'green';
            break;
        case 2:
            $message_type = 'INFO    : ';
            $msg = 'INFO';
            $color = 'blue';
            break;
        case 3:
            $message_type = 'ERROR   : ';
            $msg = 'ERROR';
            $color = 'red';
            break;
        case 4:
            $message_type = 'DEBUG   : ';
            $msg = 'DEBUG';
            $color = 'pink';
            break;
    }
    if ($style == 'html') {
        $print_style = "[<font color=\"" . $color . "\">" . $msg . "</font>] ";
    } else {
        $print_style = "[" . $msg . "]";
    }
    if ($filename == "") {
        $filename = dirname(__FILE__) . '/../logs/update-' . date("Y-m-d") . '.log';
    }
    // Assurons nous que le fichier est accessible en écriture
    if (is_string($filename)) {
        // Dans notre exemple, nous ouvrons le fichier $filename en mode d'ajout
        // Le pointeur de fichier est placé à la fin du fichier
        // c'est là que $somecontent sera placé
        if (!($handle = fopen($filename, 'a'))) {
            echo "Impossible d'ouvrir le fichier ({$filename})";
            exit;
        }
        // Ecrivons quelque chose dans notre fichier.
        if (fwrite($handle, $date_log . $message_type . $message . "\n") === FALSE) {
            echo "Impossible d'ecrire dans le fichier ({$filename})";
            exit;
        }
        fclose($handle);
    } else {
        echo "Le fichier {$filename} n'est pas accessible en écriture.";
    }
    /*
    	if (!empty($file)) {
    		fwrite($file, $date_log.$message_type.$message."\n");
    		fclose($file);
    	}*/
    # On log a l'ecran
    if ($style == 'cli') {
        echo $date_log . $message_type . $message;
    }
    if ($print) {
        return $print_style . $message . "<br/>";
    } else {
        return $date_log . $message_type . $message . "<br/>";
    }
}
Пример #19
0
 /**
  * Set all configurations and boot application.
  *
  * @return $this
  */
 public function bootApplication($request)
 {
     /*
     | -------------------------------------------------------------------
     | Check if script is running via cli and return false
     | -------------------------------------------------------------------
     |
     | We will check if script running via console
     | then we will return from here, else application
     | fall back down
     */
     if (isCli()) {
         return $this;
     }
     $this->bootInternals();
     $this->booted = true;
     return $this;
 }