<?php
$summa = false;
$x = false;
$y = false;
if (isset($_POST['myform'])) {
$x = $_POST['x']?? false;
$y = $_POST['y']?? false;
if ($x !== false && $y !== false && is_numeric($x) && is_numeric($y)) $summa = $x + $y;
}
?>
<?php if ($summa !== false) : ?><p>Сумма равна: <?=$summa?></p><?php endif ?>
<form name="myform" action="<?=$_SERVER['REQUEST_URI']?>" method="post">
<div>
X: <input type="text" name="x" value="<?=$x?>" />
</div>
<div>
Y: <input type="text" name="y" value="<?=$y?>" />
</div>
<div>
<input type="submit" name="myform" value="Сумма" />
</div>
</form>
//взять строку
$txt = "моя строка"; // $_POST['text'];
//разбить на символы
$chars = preg_split("//", $txt,-1, PREG_SPLIT_NO_EMPTY);
//оставить нечетные
$odd = array_filter($chars, function($idx){ return $idx & 1;}, ARRAY_FILTER_USE_KEY);
//слить обратно
//$result = implode("", $odd);
//в целом четные буквы можно еще удалить, например, так
$result = preg_replace("/.(.)/", "$1", $txt);
echo $result;
ini_set('display_errors',1);
error_reporting(E_ALL);
<?php
require_once "start.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Регистрация</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="styles/main.css" />
</head>
<body>
<table id="main">
<?php
require_once "blocks/top.php";
?>
<tr>
<td colspan="2">
<table cellpadding="0" cellpadding="0" id="content">
<tr>
<td>
<?php
require_once "blocks/reg.php";
?>
</td>
<td id="banners_240">
<?php
require_once "blocks/banners_240.php";
?>
</td>
</tr>
</table>
</td>
</tr>
<?php
require_once "blocks/footer.php";
?>
</table>
</body>
</html>
<?php
if (!empty($_POST["button_reg"])) {
$email = htmlspecialchars($_POST["email"]);
$password_1 = htmlspecialchars($_POST["password_1"]);
$password_2 = htmlspecialchars($_POST["password_2"]);
if (strlen($email) < 3) $success = false;
elseif (strlen($password_1) < 3) $success = false;
elseif ($password_1 != $password_2) $success = false;
else $success = addUser ($email, md5($password_1));
if (!$success) $alert = "Ошибка при регистрации";
else $alert = "Вы успешно зарегистрировались";
include "alert.php";
}
?>
<h2>Регистрация</h2>
<form name="reg" action="" method="post">
<table>
<tr>
<td>E-mail:</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td>Пароль:</td>
<td>
<input type="password_1" name="password" />
</td>
</tr>
<tr>
<td>Подтвердите пароль:</td>
<td>
<input type="password_2" name="password" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="button_reg" value="Зарегистрироваться" />
</td>
</tr>
</table>
</form>
<?php
$mysqli = false;
function connectDB() {
global $mysqli;
$mysqli = new mysqli("localhost", "root", "", "mysite-local");
$mysqli->query("SET NAMES 'utf8',");
}
function getAllArticles () {
global $mysqli;
connectDB();
$result_set = $mysqli->query("SELECT * FROM `articles`");
closeDB();
return resultSetToArray($result_set);
}
function getAllGuestBookComments () {
global $mysqli;
connectDB();
$result_set = $mysqli->query("SELECT * FROM `guestbook`");
closeDB();
return resultSetToArray($result_set);
}
function addGuestBookComment($name, $comment) {
global $mysqli;
connectDB();
$success = $mysqli->query("INSERT INTO `guestbook` (`name`,`comment`) VALUES ('$name', '$comment')");
closeDB();
return $success;
}
function addUser ($email, $password) {
global $mysqli;
connectDB();
$success = $mysqli->query("INSERT INTO `users`(`email`, `password`) VALUES ('$email', '$password')");
closeDB();
return $success;
}
function getArticle($id) {
global $mysqli;
connectDB();
$result_set = $mysqli->query("SELECT * FROM `articles` WHERE `id`='$id'");
closeDB();
return $result_set->fetch_assoc();
}
function resultSetToArray($result_set) {
$array = array();
while (($row = $result_set->fetch_assoc()) !=false)
$array [] = $row;
return $array;
}
function closeDB() {
global $mysqli;
$mysqli->close();
}
?>
<p><b><?php echo $name;?>:</b><?php echo $comment;?></p>
function addGuestBookComment($name, $comment) {
global $mysqli;
connectDB();
$success = $mysqli->query("INSERT INTO `questbook`(`name`, `comment`) VALUES ('$name', '$comment')");
closeDB();
return $success;
}
<div class="article">
<h2><?php echo $title;?></h2>
<p class="article_img">
<img src="images/article_<?php echo $id;?>.png" alt="<?php echo $title;?>" />
</p>
<?php echo $intro_text;?>
<p>
<a href="article.php?id=<?php echo $id;?>">Читать дальше</a>
</p>
</div>
<hr/>
<?php
use yii\web\JsExpression;
use wbraganca\fancytree\FancytreeWidget;
use wokster\treebehavior\NestedSetsTreeBehavior;
/**
/* @var $this yii\web\View */
/* @var $data array */
$this->title = 'дерево категорий';
?>
<div class "">
<div class = "row">
<div class = "col-xs-6 col-sm-6 col-md-6 col-lg-6">
<div class = "box box-primary">
<dib class = "box-header with-border">
<h3 class ="box-title">дерево</h3>
<div class ="box-tools pull-right">
<a href="<?=\yii\helpers\Url::toRoute('/menu/create')?>" class="btn btn-box-tool"><i class="fa fa-plus-square-o" aria-hidden="true"></i></a>
<button type="button" class="btn btn-box-tool" data-wiget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div><!--/.box-header -->
<div class="box-body">
<?php
// Example of data.
echo
\wbraganca\fancytree\FancytreeWidget::widget([
'options' =>[
'source' => $data,
'extensions' => ['dnd'],
'dnd' => [
'preventVoidMoves' => true,
'preventRecursiveMoves' => true,
'autoExpandMS' => 400,
'dragStart' => new JsExpression('function(node, data) {
return true;
}'),
'dragEnter' => new JsExpression('function(node, data) {
return true;
}'),
'dragDrop' => new JsExpression('function(node, data) {
$.get("move",{item: data.otherNode.data["id"], action: data.hitMode, second: node.data["id"]},function(e ) {
data.otherNode.moveTo(node, data.hitMode);
console.log(e);
});
}'),
],
/* 'activate' => new JsExpression ('function(event,data) {
var title = data.node.title;
var id = data.node.key.substr(1);
$("#cat-info .box-header>h3") .text(title);
$.get("/menu/view-ajax",(id: id),function(data) {
$("#cat-info" .box-body").html (data);
});
}'),*/
]
]);
?>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
<div class="box box-primary" id="cat-info">
<div class="box-header with-border">
<h3 class="box-title">инфо</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-wiget="collapse"><i class="fa fa-minus"></i>
</button>
</div>
</div>
</div><!--/.box-header-->
</div class="box-body">
</div>
</div>
</div>
</div>
</div>
?>
'activate' => new JsExpression ('function(event,data) {
var title = data.node.title;
var id = data.node.key.substr(1);
$("#cat-info .box-header>h3") .text(title);
$.get("/menu/view-ajax",(id: id),function(data) {
$("#cat-info" .box-body").html (data);
});
}'),*/
echo
\wbraganca\fancytree\FancytreeWidget::widget([
'options' =>[
'source' => $data,
'extensions' => ['dnd'],
'dnd' => [
'preventVoidMoves' => true,
'preventRecursiveMoves' => true,
'autoExpandMS' => 400,
'dragStart' => new JsExpression('function(node, data) {
return true;
}'),
'dragEnter' => new JsExpression('function(node, data) {
return true;
}'),
/* 'dragDrop' => new JsExpression('function(node, data) {
$.get("move",{item: data.otherNode.data["id"], action: data.hitMode, second: node.data["id"]},function(e ) {
data.otherNode.moveTo(node, data.hitMode);
console.log(e);
});*/
'dragDrop' => new JsExpression('function (node, data) {
$.get("/menu/move",(item: data.otherNode.key.substr(1), action: data.hitMode, second:node.key.substr(1)},function() {
data.otherNode.moveTo(node, data.hitMode);
});
}'),
],
/* 'activate' => new JsExpression ('function(event,data) {
var title = data.node.title;
var id = data.node.key.substr(1);
$("#cat-info .box-header>h3") .text(title);
$.get("/menu/view-ajax",(id: id),function(data) {
$("#cat-info" .box-body").html (data);
});
}'),*/
]
]);
?>
public function actions()
{
return [
'images-get' => [
'class' => 'vova07\imperavi\actions\GetAction',
'url' => '/backend/web/uploads/images/articles', // URL адрес папки где хранятся изображения.
'path' => '@backend/web/uploads/images/articles' , // Или абсолютный путь к папке с изображениями.
/* 'url' => \Yii::$app->controller->module->allRedactorImageUrl, */
// Directory URL address, where files are stored.
/* 'path' => \Yii::$app->controller->module->redactor_upload_path_alias, // Or absolute path to directory where files are stored.*/
'type' => \vova07\imperavi\actions\GetAction::TYPE_IMAGES,
/* 'imageManagerJson' => Url::to(['/arcticle/image-get']),*/
'imageManagerJson' => \yii\helpers\Url::toRoute(['/article/article/images-get']),
],
<?php
namespace sand\blog\models;
use common\components\behaviors\StatusBehavior;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\web\UploadedFile;
use common\models\User;
use common\models\ImageManager;
/**
* This is the model class for table "blog".
*
* @property integer $id
* @property string $title
* @property string $text
* @property string $image
* @property string $url
* @property string $date_create
* @property string $date_update
* @property integer $status_id
* @property integer $sort
*/
class Blog extends ActiveRecord
{
const STATUS_LIST = ['off','on'];
const IMAGES_SIZE = [
['50','50'],
['800',null],
];
public $tags_array;
public $file;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'blog';
}
public function behaviors()
{
return [
'timestampBehavior'=>[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'date_create',
'updatedAtAttribute' => 'date_update',
'value' => new Expression('NOW()'),
],
'statusBehavior'=>[
'class' => StatusBehavior::className(),
'statusList' => self::STATUS_LIST,
]
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title', 'url'], 'required'],
[['text'], 'string'],
[['url'], 'unique'],
[['status_id', 'sort'], 'integer'],
[['sort'], 'integer', 'max'=>99, 'min'=>1],
[['title', 'url'], 'string', 'max' => 150],
[['image'], 'string', 'max' => 100],
[['file'], 'image'],
[['tags_array','date_create','date_update'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Заголовок',
'text' => 'Текст',
'url' => 'ЧПУ',
'status_id' => 'Статус',
'sort' => 'Сортировка',
'tags_array' => 'Тэги',
'image' => 'Картинка',
'file' => 'Картинка',
'tagsAsString' => 'Тэги',
'author.username' => 'Имя Автора',
'author.email' => 'Почта Автора',
'date_update' => 'Обновлено',
'date_create' => 'Создано',
];
}
public function getAuthor(){
return $this->hasOne(User::className(),['id'=>'user_id']);
}
public function getImages()
{
return $this->hasMany(ImageManager::className(), ['item_id' => 'id'])->andWhere(['class'=>self::tableName()])->orderBy('sort');
}
public function getImagesLinks()
{
return ArrayHelper::getColumn($this->images,'imageUrl');
}
public function getImagesLinksData()
{
return ArrayHelper::toArray($this->images,[
ImageManager::className() => [
'caption'=>'name',
'key'=>'id',
]]
);
}
public function getBlogTag(){
return $this->hasMany(BlogTag::className(),['blog_id'=>'id']);
}
public function getTags()
{
return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->via('blogTag');
}
public function getTagsAsString()
{
$arr = \yii\helpers\ArrayHelper::map($this->tags,'id','name');
return implode(', ',$arr);
}
public function getSmallImage()
{
if($this->image){
$path = str_replace('admin.','',Url::home(true)).'uploads/images/blog/50x50/'.$this->image;
}else{
$path = str_replace('admin.','',Url::home(true)).'uploads/images/ss.jpg';
}
return $path;
}
public function afterFind()
{
parent::afterFind();
$this->tags_array = $this->tags;
}
public function beforeSave($insert)
{
if($file = UploadedFile::getInstance($this, 'file')){
$dir = Yii::getAlias('@images').'/blog/';
if(file_exists($dir.$this->image)){
unlink($dir.$this->image);
}
if(file_exists($dir.'50x50/'.$this->image)){
unlink($dir.'50x50/'.$this->image);
}
if(file_exists($dir.'800x/'.$this->image)){
unlink($dir.'800x/'.$this->image);
}
$this->image = strtotime('now').'_'.Yii::$app->getSecurity()->generateRandomString(6) . '.' . $file->extension;
$file->saveAs($dir.$this->image);
$imag = Yii::$app->image->load($dir.$this->image);
$imag->background('#fff',0);
$imag->resize('50','50', Yii\image\drivers\Image::INVERSE);
$imag->crop('50','50');
$imag->save($dir.'50x50/'.$this->image, 90);
$imag = Yii::$app->image->load($dir.$this->image);
$imag->background('#fff',0);
$imag->resize('800',null, Yii\image\drivers\Image::INVERSE);
$imag->save($dir.'800x/'.$this->image, 90);
}
return parent::beforeSave($insert);
}
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
$arr = \yii\helpers\ArrayHelper::map($this->tags,'id','id');
foreach ($this->tags_array as $one){
if(!in_array($one,$arr)){
$model = new BlogTag();
$model->blog_id = $this->id;
$model->tag_id = $one;
$model->save();
}
if(isset($arr[$one])){
unset($arr[$one]);
}
}
BlogTag::deleteAll(['tag_id'=>$arr]);
}
public function beforeDelete()
{ if (parent::beforeDelete()) {
$dir = Yii::getAlias('@images').'/blog/';
/*if($this->image != '')*/
if(!empty($this->image))
/* if($this->image && file_exists($dir.$this->image))*/
if (isset($this->image) && file_exists($idr.$this->image)){
unlink($dir.$this->image);
}
/* if(file_exists($dir.$this->image)){
unlink($dir.$this->image);
}*/
foreach (self::IMAGES_SIZE as $size){
$size_dir = $size[0].'x';
if($size[1] !== null)
$size_dir .= $size[1];
/* if(file_exists($dir.$this->image)){
unlink($dir.$size_dir.'/'.$this->image);
}*/
}
BlogTag::deleteAll(['blog_id'=>$this->id]);
return true;
} else {
return false;
}
}
}