Solving the problem of integration and change of design for any project.
1. Using curl, we obtain the page from a remote host (store cookies)
2. Get content and cut out the plot ... body>
3. Paste the code area in the right place (adjoin css, edit the custom templates /include/client)
Example class to work with the curl and cookies, support.class.php:
<?php
class Support {
var $supportHost;
var $reguestUrl;
var $reguestParams;
var $responseData;
var $cookie;
function __construct( $url, $host = 'http://ticket.loc/' ) {
$this->supportHost = $host;
$this->reguestUrl = $this->supportHost.$url;
$this->sendReguest();
}
public function sendReguest() {
if (!empty($_GET)) {
$g_str = '?';
foreach ($_GET as $g_k => $g_v) {
$g_str .= $g_k . '=' . $g_v . '&';
}
$this->reguestUrl .= $g_str;
}
if (!empty($_POST)) {
foreach ($_POST as $p_k => $p_v) {
$this->reguestParams .= $p_k . '=' . $p_v . '&';
}
}
$ch = curl_init($this->reguestUrl);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER);
curl_setopt($ch, CURLOPT_POST, 1);
if ( isset($_SESSION) ) {
curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=' . $_SESSION);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->reguestParams);
$this->responseData = curl_exec($ch);
// PHPSESSID - standart php cookie name
if (preg_match('#Set-Cookie:\s+PHPSESSID=(.*);#Ui', $this->responseData, $match)) $_SESSION = $match;
curl_close($ch);
}
public function getResponse() {
$match = array();
if ( preg_match( '#<body>(.*)</body>#Uis', $this->responseData, &$match ) ) {
return $match;
}
}
}
?>
Example "as it work" on Cacke-php:
core/router.php:
...
Router:('/support/',
array('controller' => 'support', 'action' => 'index', 'uri'=>null),
array('uri' => '.*')
);
controllers/support_controller.php:
<?php
App:('Controller', 'Base');
class SupportController extends BaseController
{
...
public function index() {
unset($_GET);
require_once '../include/support.class.php';
// $this->params - url in osTicket system like http://myosticket.com
$support = new Support( $this->params );
$this->set( 'support_html', $support->getResponse() );
}
}
?>
And my template views/support/index.ctp:
<?php
$html->css('/css/support/client-colors', 'stylesheet', array('media'=>'all'), false);
$html->css('/css/support/main', 'stylesheet', array('media'=>'all'), false);
?>
<div class="content">
<h2><span>Support</span></h2>
<div id="sbody">
<?=$support_html?>
</div>
</div>
Thats all