Файл: adultscript-2.0.3-pro/files/admin/modules/link/components/add.php
Строк: 93
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_link_add
{
private $db;
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$errors = array();
$messages = array();
$link = array(
'title' => '', 'description' => '', 'url' => '', 'target' => '', 'hardlink' => 0,
'type' => '', 'widget' => '', 'status' => 1, 'name' => '', 'email' => '', 'linkback' => ''
);
if (isset($_POST['submit_add_link'])) {
$filter = VF::factory('filter');
$title = $filter->get('title');
$desc = $filter->get('description');
$url = trim($_POST['url']);
$type = $filter->get('type');
$widget = $filter->get('widget');
$target = $filter->get('target');
$status = (int) trim($_POST['status']);
$name = $filter->get('name');
$email = $filter->get('email');
$linkback = $filter->get('linkback');
$hardlink = (int) trim($_POST['hardlink']);
if ($title == '') {
$errors[] = 'Please enter link title!';
} elseif (!VValid::length($title, 1, 255)) {
$errors[] = 'Link title can contain maximum 255 characters!';
} else {
$link['title'] = $title;
}
if ($desc != '') {
if (!VValid::length($desc, 1, 255)) {
$errors[] = 'Link description can contain maximum 255 characters!';
} else {
$link['description'] = $desc;
}
}
if ($url == '') {
$errors[] = 'Please enter link url!';
} elseif (!VValid::url($url)) {
$errors[] = 'Link url is not a valid url address!';
} elseif (!VValid::length($url, 1, 255)) {
$errors[] = 'Link url can contain maximum 255 characters!';
} else {
$link['url'] = $url;
}
if ($type == '') {
$errors[] = 'Please select link type!';
} else {
$link['type'] = $type;
}
if ($widget == '') {
$errors[] = 'Please select a widget for this link!';
} else {
$link['widget'] = $widget;
}
$link['name'] = $name;
$link['email'] = $email;
$link['linkback'] = $linkback;
$link['target'] = $target;
$link['status'] = $status;
if (!$errors) {
$linkback = str_replace(array('http://', 'www.'), '', $linkback);
$pagerank = VPagerank::get($linkback);
$this->db->query("INSERT INTO #__link
SET title = '".$this->db->escape($title)."',
description = '".$this->db->escape($desc)."',
url = '".$this->db->escape($url)."',
name = '".$this->db->escape($name)."',
email = '".$this->db->escape($email)."',
linkback = '".$this->db->escape($linkback)."',
pagerank = ".$pagerank.",
type = '".$this->db->escape($type)."',
widget = '".$this->db->escape($widget)."',
target = '".$this->db->escape($target)."',
hardlink = '".$hardlink."',
status = '".$status."'");
if ($this->db->affected_rows()) {
VF::factory('cache')->remove('link_'.$widget);
$messages[] = 'Link added!';
} else {
$errors[] = 'Failed to add link!';
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'link';
$tpl->submenu = 'link_add';
$tpl->meta_title = 'Admin::Link::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->link = $link;
$tpl->load(array('header', 'link_add', 'footer'));
$tpl->display();
}
}