<?php
namespace App\Http\Controllers\Member;
use App\Article;
use App\Category;
use App\Http\Requests\ArticleRequest;
use App\Mail\AdminNewArticle;
use App\Mail\AdminUpdateArticle;
use App\Tag;
use Illuminate\Support\Facades\Mail;
class ArticleController extends MemberController
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$conditions = [];
if (request()->input('Filter')) {
$filter_fields = [
'title',
'status',
];
foreach (request()->input('Filter') as $param_name => $param_value) {
if (!$param_value) {
continue;
}
//$value = urldecode($value);
if (in_array($param_name, $filter_fields)) {
$like_params = ['title'];
if (in_array($param_name, $like_params)) {
$conditions[] = [$param_name, 'like', '%' . $param_value . '%'];
} else {
$conditions[] = [$param_name, '=', $param_value];
}
}
}
}
$orderBy = [
'col' => request()->input('order', 'id'),
'dir' => request()->input('dir', 'desc'),
];
$articles = Article::where('user_id', auth()->id())
->where($conditions)
->orderBy($orderBy['col'], $orderBy['dir'])
->paginate();
$orderBy['dir'] = ($orderBy['dir'] === 'asc') ? 'desc' : 'asc';
return view('member.articles.index', [
'articles' => $articles,
'orderBy' => $orderBy,
]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$categories = Category::where('status', 1)->pluck('name', 'id');
$tags = Tag::where('status', 1)->pluck('name', 'id');
return view('member.articles.create', [
'categories' => $categories,
'tags' => $tags,
]);
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\ArticleRequest $request
* @return \Illuminate\Http\Response
*/
public function store(ArticleRequest $request)
{
$data = $request->only([
'title',
'slug',
'summary',
'content',
'upload_featured_image',
'main_category_id',
'category',
'tags',
'reason',
'read_time',
]);
/**
* @var \App\File|null $featured_image
*/
$featured_image = \App\Helpers\Upload::process('upload_featured_image');
if ($featured_image) {
$data['featured_image_id'] = $featured_image->id;
}
$category = $data['category'];
$data['user_id'] = auth()->id();
$data['status'] = 3; // 3=New Pending Review
$data['pay_type'] = 1;
$reason = $data['reason'];
unset($data['upload_featured_image'], $data['category'], $data['tags'], $data['reason']);
$article = Article::create($data);
$article->categories()->sync([$category => ['main' => 1]]);
if ((bool)get_option('alert_admin_new_article', 1)) {
if (!empty(get_option('admin_email'))) {
Mail::send(new AdminNewArticle($article, $reason));
}
}
session()->flash('message', __('Your article has been added and it is pending for review.'));
return redirect()->route('member.articles.index');
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function edit(Article $article)
{
/**
* Check if this article belongs to the auth user
*/
if ($article->user_id !== auth()->id()) {
abort(404);
}
/**
* Only active articles can be edited
*/
if ($article->status === 2) {
session()->flash('danger', __("Rejected articles can not be edited."));
return redirect()->route('member.articles.index');
}
$article_update = $article->tmp_content;
if (empty($article->tmp_content)) {
$article_update = new \stdClass();
$article_update->title = $article->title;
$article_update->slug = $article->slug;
$article_update->summary = $article->summary;
$article_update->content = $article->content;
$article_update->featured_image_id = null;
}
return view('member.articles.edit', [
'article' => $article,
'article_update' => $article_update,
]);
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\ArticleRequest $request
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function update(ArticleRequest $request, Article $article)
{
/**
* Check if this article belongs to the auth user
*/
if ($article->user_id !== auth()->id()) {
abort(404);
}
/**
* Only active articles can be edited
*/
if ($article->status === 2) {
abort(404);
}
$data = $request->only([
'title',
'slug',
'summary',
'content',
'upload_featured_image',
'reason',
'read_time',
]);
/**
* @var \App\File|null $featured_image
*/
$featured_image = \App\Helpers\Upload::process('upload_featured_image');
if ($featured_image) {
$data['featured_image_id'] = $featured_image->id;
}
/**
* 1=active, 2=Hard Disabled, 3=New Pending Review, 5=New Need Improvements, 4=Update Pending Review,
* 6=Update Need Improvements, 7=Soft Disabled, 8=Draft
*/
$currentStatus = $article->status;
if ($currentStatus === 1) {
$data['status'] = 4;
}
if ($currentStatus === 5) {
$data['status'] = 3;
}
if ($currentStatus === 6) {
$data['status'] = 4;
}
if (in_array($currentStatus, [3, 4])) {
$data['status'] = $currentStatus;
}
$reason = $data['reason'];
unset($data['upload_featured_image'], $data['reason']);
if (in_array($data['status'], [3, 5])) {
$data_save = [
'title' => $data['title'],
'slug' => $data['slug'],
'summary' => $data['summary'],
'content' => $data['content'],
'featured_image_id' => $data['featured_image_id'] ?? null,
'read_time' => $data['read_time'],
'status' => $data['status'],
'tmp_content' => null,
];
} else {
$tmp_data = [
'title' => $data['title'],
'slug' => $data['slug'],
'summary' => $data['summary'],
'content' => $data['content'],
'featured_image_id' => $data['featured_image_id'] ?? null,
'read_time' => $data['read_time'],
];
$data_save = [
'status' => $data['status'],
'tmp_content' => $tmp_data,
];
}
if ($article->update($data_save)) {
if ((bool)get_option('alert_admin_update_article', 1)) {
if (!empty(get_option('admin_email'))) {
Mail::send(new AdminUpdateArticle($article, $reason));
}
}
session()->flash('message', __('Your article is pending for review.'));
return redirect()->route('member.articles.index');
}
}
}
// If it reached here, it'll be considered rendered
$this->assets[$id]['rendered'] = true;
$assetURL = $asset['url'];
// If a query string starter is already present we add the version parameter by appending it
if (strpos($assetURL, '?') !== false) {
$assetURL .= "&v={$asset['version']}";
} else {
// otherwise let this be a start
$assetURL .= "?v={$asset['version']}";
}
if ($asset['type'] === static::TYPE_STYLE) {
$media = null;
if ($asset['media']) {
$media = ' media="' . e_attr($asset['media']) . '"';
}
$html = '<link rel="stylesheet" id="' . $id . '" type="text/css" href="' . $assetURL . '"'. $media . '>'
. "\n";
return $html;
}
// Handle scripts
if ($asset['type'] === static::TYPE_SCRIPT) {
$extra = null;
if ($asset['async']) {
$extra = ' async';
} elseif ($asset['defer']) {
$extra = ' defer';
}
$html = '<script id="' . $id . '" type="text/javascript" src="' . $assetURL . '"'. $extra . '></script>'
. "\n";
return $html;
}
return '';
}
}
<?php
/* Здесь проверяется существование переменных */
if (isset($_POST['email-phone'])) {$phone = $_POST['email-phone'];}
if (isset($_POST['site'])) {$site = $_POST['site'];}
if (isset($_POST['list'])) {$list = $_POST['list'];}
/* Сюда впишите свою эл. почту */
$address = "marsseo73@yandex.ru";
/* А здесь прописывается текст сообщения, \n - перенос строки */
$mes = "Тема: Заказ обратного звонка!\nТелефон: $phone\nИмя: $name\nE-mail: $email\nСайт: $site\nЛист: $list";
/* А эта функция как раз занимается отправкой письма на указанный вами email */
$sub='Заказ'; //сабж
$email='Заказ <vpluce.ru>'; // от кого
$send = mail ($address,$sub,$mes,"Content-type:text/plain; charset = utf-8\r\nFrom:$email");
ini_set('short_open_tag', 'On');
header('Refresh: 3; URL=index.html');
?>
<p class="c_title">Шаг 3 – Информация о компании</p>
<form action="send.php" id="to_slides" class="coversion-form">
<div class="left-step-two">
<p>Продвигался сайт раньше и как?</p>
<input class="conv_more" type="text" name="site_promotion" placeholder="С помощью контекстной рекламы">
<img class="conv_save conv_save8" src="//site.ru/form_conversion/img/save.png" alt="">
<p>Есть ли команда, обслуживающая сайт?</p>
<label for="select_3_1" class="select select_3_1">
<input type="radio" name="list_3_1" value="not_changed" id="bg_3_1" checked />
<input type="radio" name="list_3_1" value="not_changed" id="select_3_1">
<label class="bg" for="bg_3_1"></label>
<div class="items">
<input type="radio" name="list_3_1" value="Да, внутри компании" id="list[3_1_0]">
<label for="list[3_1_0]">Да, внутри компании</label>
<input type="radio" name="list_3_1" value="Да, вне компании" id="list[3_1_1]">
<label for="list[3_1_1]">Да, вне компании</label>
<input type="radio" name="list_3_1" value="Нет" id="list[3_1_2]">
<label for="list[3_1_2]">Нет</label>
<span id="text">Постоянной команды нет</span>
</div>
<img class="conv_save conv_save9" src="//site.ru/form_conversion/img/save.png" alt="">
</label>
<p class="mdscreencheck_3_1" style="margin-top: 76px;margin-bottom: 23px;">Есть ли в вашей компании специалисты?</p>
<input class="expert" data-label="по разработке сайтов" type="checkbox" id="check_3_1">
<label for="check_3_1" class="check_3_1"><p>по разработке сайтов</p></label>
<input class="expert" data-label="по продвижению сайтов" type="checkbox" id="check_3_2" checked>
<label for="check_3_2" class="check_3_1 mdscreenwidth"><p>по продвижению сайтов</p></label>
<input class="expert" data-label="по маркетингу" type="checkbox" id="check_3_3">
<label for="check_3_3" class="check_3_1"><p>по маркетингу</p></label>
<input class="expert" data-label="по администрированию сайтов" type="checkbox" id="check_3_4">
<label for="check_3_4" class="check_3_1 mdscreenwidth"><p>по администрированию сайтов</p></label>
<input class="expert" data-label="копирайтеры" type="checkbox" id="check_3_5">
<label for="check_3_5" class="check_3_1"><p>копирайтеры</p></label>
<input class="expert" data-label="дизайнеры" type="checkbox" id="check_3_6">
<label for="check_3_6" class="check_3_1"><p>дизайнеры</p></label>
</div>
<div class="right-step-two">
<p>Регион продвижения</p>
<input class="conv_more" type="text" name="region_promotion" placeholder="Ваш регион">
<img class="conv_save conv_save10" src="//site.ru/form_conversion/img/save.png" alt="">
<p>Сколько лет домену?</p>
<label for="select_3_2" class="select select_3_2">
<input type="radio" name="list_3_2" value="not_changed" id="bg_3_2" checked />
<input type="radio" name="list_3_2" value="not_changed" id="select_3_2">
<label class="bg" for="bg_3_2"></label>
<div class="items">
<input type="radio" name="list_3_2" value="Меньше чем 6 месяцев" id="list[3_2_0]">
<label for="list[3_2_0]">Меньше чем 6 месяцев</label>
<input type="radio" name="list_3_2" value="От 6 до 24 месяцев" id="list[3_2_1]">
<label for="list[3_2_1]">От 6 до 24 месяцев</label>
<input type="radio" name="list_3_2" value="Более 24 месяцев" id="list[3_2_2]">
<label for="list[3_2_2]">Более 24 месяцев</label>
<span id="text">8</span>
</div>
<img class="conv_save conv_save11" src="//site.ru/form_conversion/img/save.png" alt="">
</label>
<p class="mobile-adressite mdscreen_adressite" style="margin-top: 78px;">Адрес сайта</p>
<input class="conv_more mdscreen_adressite" type="text" name="site" placeholder="www.art-collection.spb.ru">
<img class="conv_save conv_save12" src="//site.ru/form_conversion/img/save.png" alt="">
<p>Ваш контактный телефонный номер</p>
<input class="conv_more" type="text" name="phone" placeholder="+9 712 123-45-67">
<img class="conv_save conv_save13" src="//site.ru/form_conversion/img/save.png" alt="">
<p>Электронная почта</p>
<input class="conv_more" type="text" name="email" placeholder="info@art-collection.spb.ru">
<img class="conv_save conv_save14" src="//site.ru/form_conversion/img/save.png" alt="">
</div>
<div style="clear: both;"></div>
<div class="buttons">
<span id="back_to_step_two" class="next_step">ВЕРНУТЬСЯ</span>
<input type="submit" name="" style="color:#8a8a8a;" value="ОТПРАВИТЬ" class="next_step send-coversia">
<span>Введенные данные сохранятся</span>
</div>
</form>
</div>