public function __construct($keyStr)
 {
     $iniParams = ini::read(os::path('lib', 'modules', 'captcha', 'config.ini'));
     foreach ($iniParams as $k => $v) {
         $this->{$k} = $v;
     }
     // CAPTCHA image colors (RGB, 0-255)
     // $this->foreground_color = array(0, 0, 0);
     // $this->background_color = array(220, 230, 255);
     $this->foreground_color = array(mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $this->background_color = array(mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
     // Что надо нарисовать
     $this->keyString = $keyStr;
 }
Esempio n. 2
0
 /**
  * Вытаскивает таблицу маршрутизации из .ini файла, если не находит — возвращает пустой массив.
  */
 private function load_ini(Context $ctx)
 {
     $raw = array();
     foreach ($ctx->config->get('routes', array()) as $k => $v) {
         $raw['GET/' . $k] = $v;
     }
     foreach (os::find('lib', 'modules', '*', 'route.ini') as $iniFile) {
         foreach (ini::read($iniFile) as $k => $v) {
             if (is_array($v)) {
                 $raw[$k] = $v;
                 $raw[$k]['static'] = true;
             } elseif ('dynamic' == $k and false !== strpos($v, '::')) {
                 list($class, $method) = explode('::', $v);
                 if (method_exists($class, $method)) {
                     try {
                         if (is_array($tmp = call_user_func(array($class, $method), $ctx))) {
                             foreach ($tmp as $k => $v) {
                                 $raw[$k] = $v;
                             }
                         }
                     } catch (Exception $e) {
                         Logger::log(get_class($e) . ' in ' . $v . '()');
                     }
                 }
             }
         }
     }
     // Опрос динамических маршрутов.
     foreach ((array) $ctx->registry->poll('ru.molinos.cms.route.poll') as $tmp) {
         if (!empty($tmp['result'])) {
             foreach ($tmp['result'] as $k => $v) {
                 $raw[$k] = $v;
             }
         }
     }
     return $raw;
 }
Esempio n. 3
0
 /**
  * Сканирует классы, обновляет файлы module.ini
  */
 public function rebuildMeta()
 {
     foreach (os::find('lib', 'modules', '*', 'module.ini') as $iniFileName) {
         $moduleName = basename(dirname($iniFileName));
         if (!empty($argv[1]) and $argv[1] != $moduleName) {
             continue;
         }
         $ini = ini::read($iniFileName);
         $path = dirname($iniFileName);
         if (file_exists($routeFileName = os::path($path, 'route.ini'))) {
             $routes = ini::read($routeFileName);
         } else {
             $routes = array();
         }
         // Удаляем временные маршруты, считанные из комментариев в прошлый раз.
         foreach ($routes as $k => $v) {
             if (is_array($v) and !empty($v['volatile'])) {
                 unset($routes[$k]);
             }
         }
         foreach ($ini as $k => $v) {
             if (is_array($v)) {
                 unset($ini[$k]);
             }
         }
         foreach (os::find($path, '*.php') as $fileName) {
             $baseName = basename($fileName);
             if (0 === strpos($baseName, 'test')) {
                 continue;
             } elseif ('.test.php' == substr($baseName, -9)) {
                 continue;
             }
             $source = strtolower(file_get_contents($fileName));
             if (preg_match('@^\\s*(?:abstract\\s+)?class\\s+([a-z0-9_]+)(\\s+extends\\s+([^\\s]+))*(\\s+implements\\s+([^\\n\\r]+))*@m', $source, $m)) {
                 $className = $m[1];
                 $ini['classes'][$m[1]] = $baseName;
                 if (preg_match_all('#(?:@mcms_message\\s+)([a-z0-9.]+)(?:[^{]*public\\s+static\\s+function\\s+)([^(]+)#s', $source, $m)) {
                     foreach ($m[1] as $idx => $message) {
                         $method = $m[2][$idx];
                         $ini['messages'][$message][] = $className . '::' . $method;
                     }
                 }
                 if (preg_match_all('#(?:@route\\s+)([a-z0-9./-]+)(?:[^{]*public\\s+static\\s+function\\s+)([^(]+)#s', $source, $m)) {
                     foreach ($m[1] as $idx => $route) {
                         $parts = explode('//', $route);
                         $parts[0] = strtoupper($parts[0]);
                         $routes[implode('//', $parts)] = array('call' => $className . '::' . $m[2][$idx], 'volatile' => true);
                     }
                 }
             } elseif (preg_match('@^\\s*interface\\s+([a-z0-9_]+)@m', $source, $m)) {
                 $ini['classes'][$m[1]] = $baseName;
             }
         }
         $ini['changelog'] = 'http://molinos-cms.googlecode.com/svn/dist/' . MCMS_RELEASE . '/changelogs/' . $moduleName . '.txt';
         if (!empty($ini['classes'])) {
             ksort($ini['classes']);
         }
         if (!empty($routes)) {
             ksort($routes);
             ini::write($routeFileName, $routes);
         } elseif (file_exists($routeFileName)) {
             unlink($routeFileName);
         }
         ini::write($iniFileName, $ini);
     }
 }
$buff = null;
ini::open($cfgile);
ini::read('main', 'wordWrap', $buff);
c("memo1")->wordWrap = (bool) $buff;
ini::read('main', 'ws', $buff);
c("Form1")->windowState = (int) $buff;
ini::read('main', 'width', $buff);
if ($buff) {
    c("Form1")->w = $buff;
}
ini::read('main', 'height', $buff);
if ($buff) {
    c("Form1")->h = $buff;
}
ini::read('main', 'x', $buff);
if ($buff) {
    c("Form1")->x = $buff;
}
ini::read('main', 'y', $buff);
if ($buff) {
    //c("Form1")->position = poDefault;
    c("Form1")->y = $buff;
}
ini::read('font', 'name', $buff);
if ($buff) {
    c("memo1")->font->name = $buff;
}
ini::read('font', 'size', $buff);
if ($buff) {
    c("memo1")->font->size = $buff;
}
Esempio n. 5
0
 /**
  * Деинсталляция модуля.
  */
 public static function uninstall($moduleName)
 {
     $inipath = os::path('lib', 'modules', $moduleName, 'module.ini');
     if (file_exists($inipath)) {
         $ini = ini::read($inipath);
         if ('required' == $ini['priority']) {
             return false;
         }
     }
     os::rmdir(dirname($inipath));
     Logger::log($moduleName . ': uninstalled.');
     return true;
 }
Esempio n. 6
0
    {
        foreach ($this->lines as &$line) {
            if ($line['type'] != 'entry') {
                continue;
            }
            if ($line['section'] != $section) {
                continue;
            }
            if ($line['key'] != $key) {
                continue;
            }
            $line['value'] = $value;
            $line['data'] = $key . " = " . $value . "\r\n";
            return;
        }
        throw new Exception('Missing Section or Key');
    }
    public function write($file)
    {
        $fp = fopen($file, 'w');
        foreach ($this->lines as $line) {
            fwrite($fp, $line['data']);
        }
        fclose($fp);
    }
}
$ini = new ini();
$ini->read("C:\\php.ini");
$ini->set('PHP', 'engine', 'Off');
echo $ini->get('PHP', 'engine');
$ini->write("C:\\php.ini");
Esempio n. 7
0
 public function run()
 {
     $tmpdir = os::mkdir(os::path('tmp', 'modules'));
     $existing = $this->getExistingModules();
     foreach (glob(os::path('lib', 'modules', '*', 'module.ini')) as $inifile) {
         $module = basename(dirname($inifile));
         $ini = array_merge(array('priority' => 'optional', 'section' => 'service'), ini::read($inifile));
         foreach (array('section', 'version', 'name') as $k) {
             if (!array_key_exists($k, $ini)) {
                 printf("warning: %s has no '%s' key, module ignored.\n", $module, $k);
                 continue 2;
             }
         }
         if (!in_array($zipname = $module . '-' . $ini['version'] . '.zip', $existing)) {
             zip::fromFolder($fullzipname = os::path($tmpdir, $zipname), dirname($inifile));
             printf("new file: %s\n", basename($fullzipname));
         }
         foreach ($ini as $k => $v) {
             if (is_array($v)) {
                 unset($ini[$k]);
             }
         }
         $ini['filename'] = $zipname;
         $this->modules[$module] = $ini;
     }
     ksort($this->modules);
     ini::write($this->inifile, $this->modules);
 }
Esempio n. 8
0
 /**
  * Determines the most appropriate language file to read in based on the language preferences
  * of the current user as determined in the $_SESSION['lang'], $_SESSION['lang2'] and
  * $_SESSION['lang3'] variables.
  * @return i18n This instance to enable method chaining.
  */
 public function read()
 {
     $file = $this->findFile();
     // We should've already thrown an exception by here, should it even be empty.
     assert(!empty($file));
     return parent::read($file);
 }
Esempio n. 9
0
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'client.inc';
$paths = array();
foreach (os::find('lib/modules/*') as $moduleName) {
    $fileName = os::path('wiki', 'mod_' . basename($moduleName)) . '.wiki';
    $paths[] = $fileName;
}
foreach (os::find('lib/modules/*/route.ini') as $routeName) {
    $ini = ini::read($routeName);
    foreach (array_keys($ini) as $path) {
        if (2 == count($parts = explode('//', $path, 2))) {
            if (0 === strpos($parts[1], 'api/')) {
                $paths[] = os::path('wiki', str_replace('.', '_', str_replace('/', '_', $parts[1])) . '.wiki');
            }
        }
    }
}
foreach (os::find('lib/modules/*/module.ini') as $fileName) {
    $ini = ini::read($fileName);
    if (!empty($ini['messages']) and is_array($ini['messages'])) {
        foreach (array_keys($ini['messages']) as $messageName) {
            $paths[] = $k = os::path('wiki', preg_replace('/[^a-z]+/', '_', $messageName) . '.wiki');
        }
    }
}
sort($paths);
foreach (array_unique($paths) as $path) {
    if (!file_exists($path)) {
        printf("+ %s\n", $path);
        touch($path);
    }
}