Skip to content

Commit

Permalink
Merge branch '2.3/develop' of git://github.com/pyrocms/pyrocms into 2…
Browse files Browse the repository at this point in the history
….3/develop
  • Loading branch information
Phil Sturgeon committed Mar 3, 2013
2 parents 44ae641 + e80112c commit 573bf4b
Show file tree
Hide file tree
Showing 22 changed files with 746 additions and 246 deletions.
4 changes: 2 additions & 2 deletions installer/controllers/installer.php
Expand Up @@ -168,7 +168,7 @@ public function index()
array(
'field' => 'password',
'label' => 'lang:password',
'rules' => 'trim'.(in_array($driver, array('mysql', 'pgsql')) ? '|required' : '')
'rules' => 'trim'
),
array(
'field' => 'port',
Expand Down Expand Up @@ -574,4 +574,4 @@ private function _render_view($view)
'page_output' => $this->parser->parse($view, $out, true)
));
}
}
}
9 changes: 6 additions & 3 deletions system/cms/core/MY_Controller.php
Expand Up @@ -283,7 +283,7 @@ private function pick_language()
// If we've been redirected from HTTP to HTTPS on admin, ?session= will be set to maintain language
if ($_SERVER['SERVER_PORT'] == 443 and ! empty($_GET['session'])) {
session_start($_GET['session']);
} else {
} else if ( ! isset($_SESSION)) {
session_start();
}

Expand Down Expand Up @@ -360,8 +360,11 @@ private function pick_language()
$CI_config->set_item('language', $config['supported_languages'][$lang]['folder']);

// Sets a constant to use throughout ALL of CI.
define('AUTO_LANGUAGE', $lang);

if ( ! defined('AUTO_LANGUAGE'))
{
define('AUTO_LANGUAGE', $lang);
}

log_message('debug', 'Defined const AUTO_LANGUAGE: '.AUTO_LANGUAGE);
}
}
Expand Down
130 changes: 69 additions & 61 deletions system/cms/modules/domains/controllers/admin.php
@@ -1,10 +1,13 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
<?php

use Pyro\Module\Domains\Model\Domain;

/**
* PyroCMS domain Admin Controller
*
* Provides an admin for the domain module.
*
* @author Ryan Thompson - AI Web Systems, Inc.
* @author PyroCMS Dev Team
* @package PyroCMS\Core\Modules\Domains\Controllers
*/
class Admin extends Admin_Controller
Expand All @@ -15,7 +18,7 @@ class Admin extends Admin_Controller
* @var array
*/
protected $validation_rules = array(
array(
'domain' => array(
'field' => 'domain',
'label' => 'lang:domains:domain',
'rules' => 'trim|required|max_length[250]|callback__check_unique'
Expand All @@ -36,61 +39,60 @@ public function __construct()

// Load the required classes
$this->load->library('form_validation');
$this->load->model('domain_m');
$this->load->helper('domains');
$this->lang->load('domains');

$this->form_validation->set_rules($this->validation_rules);

$this->domain_m->_site_id = site_id();

}

/**
* List all domains
*/
public function index()
{
// Create pagination links
$total_rows = $this->domain_m->count_all();
$this->template->pagination = create_pagination('admin/domains/index', $total_rows);

// Using this data, get the relevant results
$this->template->domains = $this->domain_m->get_all();
ci()->pdb->getQueryGrammar()->setTablePrefix('core_');
$domains = Domain::all();
ci()->pdb->getQueryGrammar()->setTablePrefix(SITE_REF.'_');

$this->template->build('admin/index');
$this->template
->set('domains',$domains)
->build('admin/index');
}

/**
* Create a new domain
*/
public function add()
{
$messages = array();
$domain = new Domain();

// Got validation?
if ($this->form_validation->run())
{
if ($this->domain_m->insert($_POST))
{
$this->session->set_flashdata('success', lang('domains:add_success'));
if ($this->form_validation->run()) {

redirect('admin/domains');
ci()->pdb->getQueryGrammar()->setTablePrefix('core_');
$result = Redirect::create(array(
'domain' => $this->input->post('domain'),
'site_id' => site_id(),
'type' => $this->input->post('type')
));
ci()->pdb->getQueryGrammar()->setTablePrefix(SITE_REF.'_');

if ($result) {
$this->session->set_flashdata('success', lang('domains:add_success'));
} else {
$this->session->set_flashdata('error', lang('domains:add_error'));
}

$messages['error'] = lang('domains:add_error');
redirect('admin/domains');
}

$domain = new stdClass();

// Loop through each validation rule
foreach($this->validation_rules as $rule)
{
foreach ($this->validation_rules as $rule) {
$domain->$rule['field'] = set_value($rule['field']);
}

$this->template
->set('domain', $domain)
->set('messages', $messages)
->build('admin/form');
}

Expand All @@ -103,31 +105,41 @@ public function add()
*/
public function edit($id = 0)
{
$messages = array();
// Got ID?
$id or redirect('admin/domains');

ci()->pdb->getQueryGrammar()->setTablePrefix('core_');
// Get the domain
if ( !$domain = $this->domain_m->get($id) )
{
if ( ! $domain = Domain::find($id)) {
redirec('admin/domains');
}

if ($this->form_validation->run())
{
if ($this->domain_m->update($id, $this->input->post()))
{
$this->session->set_flashdata('success', $this->lang->line('domains:edit_success'));
$this->form_validation->set_rules(array_merge($this->validation_rules, array(
'domain' => array(
'field' => 'domain',
'label' => 'lang:domains:domain',
'rules' => 'trim|required|max_length[250]|callback__check_unique['.$id.']'
)
)));

if ($this->form_validation->run()) {
$domain->domain = $this->input->post('domain');
$domain->site_id = site_id();
$domain->type = $this->input->post('type');

redirect('admin/domains');
if ($domain->save()) {
$this->session->set_flashdata('success', $this->lang->line('domains:edit_success'));
} else {
$this->session->set_flashdata('error', $this->lang->line('domains:edit_error'));
}

$messages['error'] = lang('domains:edit_error');
redirect('admin/domains');
}

ci()->pdb->getQueryGrammar()->setTablePrefix(SITE_REF.'_');

$this->template
->set('domain', $domain)
->set('messages', $messages)
->build('admin/form');
}

Expand All @@ -142,33 +154,29 @@ public function delete($id = 0)
{
$id_array = ( ! empty($id)) ? array($id) : $this->input->post('action_to');

ci()->pdb->getQueryGrammar()->setTablePrefix('core_');
// Delete multiple
if( ! empty($id_array))
{
if( ! empty($id_array)) {
$deleted = 0;
$to_delete = 0;
foreach ($id_array as $id)
{
if ($this->domain_m->delete($id))
{
foreach ($id_array as $id) {
if (Domain::find($id)->delete()) {
$deleted++;
}
else
{
} else {
$this->session->set_flashdata('error', sprintf($this->lang->line('domains:mass_delete_error'), $id));
}
$to_delete++;
}

if ($deleted > 0)
{
if ($deleted > 0) {
$this->session->set_flashdata('success', sprintf($this->lang->line('domains:mass_delete_success'), $deleted, $to_delete));
}
}
else
{

} else {
$this->session->set_flashdata('error', $this->lang->line('domains:no_select_error'));
}
}

ci()->pdb->getQueryGrammar()->setTablePrefix(SITE_REF.'_');

redirect('admin/domains');
}
Expand All @@ -179,16 +187,16 @@ public function delete($id = 0)
* @param string $domain
* @return bool
*/
public function _check_unique($domain)
public function _check_unique($domain, $id = null)
{
$id = $this->uri->segment(4);

if ($this->domain_m->check_domain($domain, $id))
{
ci()->pdb->getQueryGrammar()->setTablePrefix('core_');
$domain = Domain::findByDomainAndId($domain, $id);
ci()->pdb->getQueryGrammar()->setTablePrefix('default_');
if ($domain->isEmpty()) {
return true;
} else {
$this->form_validation->set_message('_check_unique', sprintf(lang('domains:request_conflict_error'), $domain));
return false;
}

return true;
}
}
3 changes: 3 additions & 0 deletions system/cms/modules/domains/details.php
Expand Up @@ -47,6 +47,7 @@ public function info()

public function install()
{
$this->pdb->getQueryGrammar()->setTablePrefix('core_');
$schema = $this->pdb->getSchemaBuilder();

$schema->dropIfExists('domains');
Expand All @@ -62,6 +63,8 @@ public function install()
$table->unique('domain');
});

$this->pdb->getQueryGrammar()->setTablePrefix(SITE_REF.'_');

return true;
}

Expand Down
61 changes: 0 additions & 61 deletions system/cms/modules/domains/models/domain_m.php

This file was deleted.

@@ -0,0 +1,44 @@
<?php namespace Pyro\Module\Domains\Model;

/**
* Domain model
*
* @author PyroCMS Dev Team
* @package PyroCMS\Core\Modules\Redirects\Models
*/
class Domain extends \Illuminate\Database\Eloquent\Model
{
/**
* Define the table name
*
* @var string
*/
protected $table = 'domains';

/**
* Disable updated_at and created_at on table
*
* @var boolean
*/
public $timestamps = false;

public function site()
{
return $this->belongsTo('site');
}

/**
* Find by domain with ID
*
* @param string $domain The domain
* @param int $id of the domain
*
* @return void
*/
public static function findByDomainAndId($domain, $id = 0)
{
return static::where('id', '!=', $id)
->where('domain', '=', $domain)->first();
}

}

0 comments on commit 573bf4b

Please sign in to comment.