Permalink
Browse files

Добавлен плагин content_generator

  • Loading branch information...
stdex committed Feb 24, 2017
1 parent 8363700 commit 1615326c1f12423f8f9064fb63e572aad96d824d
Showing 432 changed files with 97,120 additions and 0 deletions.
@@ -0,0 +1,40 @@
<?php
if (!defined('NGCMS'))
exit('HAL');
// Preload config file
plugins_load_config();
switch ($_REQUEST['action']) {
default:
automation();
}
function automation()
{
global $twig, $PHP_SELF;
$tpath = locatePluginTemplates(array('config/main', 'config/automation'), 'content_generator', 1);
$xt = $twig->loadTemplate($tpath['config/automation'] . 'config/' . 'automation.tpl');
$tVars = array();
$xg = $twig->loadTemplate($tpath['config/main'] . 'config/' . 'main.tpl');
$tVars = array(
'entries' => $xt->render($tVars),
'php_self' => $PHP_SELF,
'plugin_url' => admin_url . '/admin.php?mod=extra-config&plugin=content_generator',
'skins_url' => skins_url,
'admin_url' => admin_url,
'home' => home,
'current_title' => 'Automation',
);
print $xg->render($tVars);
}
@@ -0,0 +1,68 @@
<?php
// Protect against hack attempts
if (!defined('NGCMS')) die ('HAL');
register_plugin_page('content_generator', '', 'plugin_content_generator', 0);
function newsGenerator($count) {
include_once(root . 'includes/inc/lib_admin.php');
include_once(__DIR__ . '/lib/Faker/autoload.php');
$faker = Faker\Factory::create('ru_RU');
for ($i = 0; $i < $count; $i++) {
$_REQUEST['title'] = iconv("utf-8", "windows-1251", $faker->realText(30, 1));
$_REQUEST['ng_news_content'] = iconv("utf-8", "windows-1251", $faker->realText());
$_REQUEST['approve'] = 1;
$_REQUEST['mainpage'] = 1;
addNews(['no.token' => true]);
}
}
function staticGenerator($count) {
include_once(root . 'actions/static.php');
include_once(__DIR__ . '/lib/Faker/autoload.php');
$faker = Faker\Factory::create('ru_RU');
for ($i = 0; $i < $count; $i++) {
$_REQUEST['title'] = iconv("utf-8", "windows-1251", $faker->realText(30, 1));
$_REQUEST['content'] = iconv("utf-8", "windows-1251", $faker->realText());
$_REQUEST['flag_published'] = 1;
$_REQUEST['token'] = genUToken('admin.static');
addStatic();
}
}
function plugin_content_generator() {
global $SUPRESS_TEMPLATE_SHOW, $SYSTEM_FLAGS;
$SUPRESS_TEMPLATE_SHOW = 1;
$SUPRESS_MAINBLOCK_SHOW = 1;
@header('Content-type: application/json; charset=utf-8');
$SYSTEM_FLAGS['http.headers'] = array(
'content-type' => 'application/json; charset=utf-8',
'cache-control' => 'private',
);
$count = (int)$_REQUEST['real_count'];
switch($_REQUEST['actionName']) {
case 'generate_news':
newsGenerator($count);
break;
case 'generate_static':
staticGenerator($count);
break;
}
ob_end_clean();
echo json_encode($count);
exit();
}
@@ -0,0 +1,71 @@
<?php
namespace Faker\Calculator;
class Iban
{
/**
* Generates IBAN Checksum
*
* @param string $iban
* @return string Checksum (numeric string)
*/
public static function checksum($iban)
{
// Move first four digits to end and set checksum to '00'
$checkString = substr($iban, 4) . substr($iban, 0, 2) . '00';
// Replace all letters with their number equivalents
$checkString = preg_replace_callback('/[A-Z]/', array('self','alphaToNumberCallback'), $checkString);
// Perform mod 97 and subtract from 98
$checksum = 98 - self::mod97($checkString);
return str_pad($checksum, 2, '0', STR_PAD_LEFT);
}
/**
* @return int
*/
private static function alphaToNumberCallback($match)
{
return self::alphaToNumber($match[0]);
}
/**
* Converts letter to number
*
* @param string $char
* @return int
*/
public static function alphaToNumber($char)
{
return ord($char) - 55;
}
/**
* Calculates mod97 on a numeric string
*
* @param string $number Numeric string
* @return int
*/
public static function mod97($number)
{
$checksum = (int)$number[0];
for ($i = 1, $size = strlen($number); $i < $size; $i++) {
$checksum = (10 * $checksum + (int) $number[$i]) % 97;
}
return $checksum;
}
/**
* Checks whether an IBAN has a valid checksum
*
* @param string $iban
* @return boolean
*/
public static function isValid($iban)
{
return self::checksum($iban) === substr($iban, 2, 2);
}
}
@@ -0,0 +1,74 @@
<?php
namespace Faker\Calculator;
use InvalidArgumentException;
/**
* Utility class for generating and validating Luhn numbers.
*
* Luhn algorithm is used to validate credit card numbers, IMEI numbers, and
* National Provider Identifier numbers.
*
* @see http://en.wikipedia.org/wiki/Luhn_algorithm
*/
class Luhn
{
/**
* @param string $number
* @return int
*/
private static function checksum($number)
{
$number = (string) $number;
$length = strlen($number);
$sum = 0;
for ($i = $length - 1; $i >= 0; $i -= 2) {
$sum += $number{$i};
}
for ($i = $length - 2; $i >= 0; $i -= 2) {
$sum += array_sum(str_split($number{$i} * 2));
}
return $sum % 10;
}
/**
* @param $partialNumber
* @return string
*/
public static function computeCheckDigit($partialNumber)
{
$checkDigit = self::checksum($partialNumber . '0');
if ($checkDigit === 0) {
return 0;
}
return (string) (10 - $checkDigit);
}
/**
* Checks whether a number (partial number + check digit) is Luhn compliant
*
* @param string $number
* @return bool
*/
public static function isValid($number)
{
return self::checksum($number) === 0;
}
/**
* Generate a Luhn compliant number.
*
* @param string $prefix
* @return string
*/
public static function generateLuhnNumber($partialValue)
{
if (!preg_match('/^\d+$/', $partialValue)) {
throw new InvalidArgumentException('Argument should be an integer.');
}
return $partialValue . Luhn::computeCheckDigit($partialValue);
}
}
@@ -0,0 +1,34 @@
<?php
namespace Faker;
/**
* This generator returns a default value for all called properties
* and methods. It works with Faker\Generator\Base->optional().
*/
class DefaultGenerator
{
protected $default;
public function __construct($default = null)
{
$this->default = $default;
}
/**
* @param string $attribute
*/
public function __get($attribute)
{
return $this->default;
}
/**
* @param string $method
* @param array $attributes
*/
public function __call($method, $attributes)
{
return $this->default;
}
}
@@ -0,0 +1,66 @@
<?php
namespace Faker;
class Documentor
{
protected $generator;
/**
* @param Generator $generator
*/
public function __construct(Generator $generator)
{
$this->generator = $generator;
}
/**
* @return array
*/
public function getFormatters()
{
$formatters = array();
$providers = array_reverse($this->generator->getProviders());
$providers[]= new Provider\Base($this->generator);
foreach ($providers as $provider) {
$providerClass = get_class($provider);
$formatters[$providerClass] = array();
$refl = new \ReflectionObject($provider);
foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflmethod) {
if ($reflmethod->getDeclaringClass()->getName() == 'Faker\Provider\Base' && $providerClass != 'Faker\Provider\Base') {
continue;
}
$methodName = $reflmethod->name;
if ($reflmethod->isConstructor()) {
continue;
}
$parameters = array();
foreach ($reflmethod->getParameters() as $reflparameter) {
$parameter = '$'. $reflparameter->getName();
if ($reflparameter->isDefaultValueAvailable()) {
$parameter .= ' = ' . var_export($reflparameter->getDefaultValue(), true);
}
$parameters []= $parameter;
}
$parameters = $parameters ? '('. join(', ', $parameters) . ')' : '';
try {
$example = $this->generator->format($methodName);
} catch (\InvalidArgumentException $e) {
$example = '';
}
if (is_array($example)) {
$example = "array('". join("', '", $example) . "')";
} elseif ($example instanceof \DateTime) {
$example = "DateTime('" . $example->format('Y-m-d H:i:s') . "')";
} elseif ($example instanceof Generator || $example instanceof UniqueGenerator) { // modifier
$example = '';
} else {
$example = var_export($example, true);
}
$formatters[$providerClass][$methodName . $parameters] = $example;
}
}
return $formatters;
}
}
Oops, something went wrong.

0 comments on commit 1615326

Please sign in to comment.