-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxcore.php
26 lines (26 loc) · 59.4 KB
/
wxcore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
class wcComment { static function add( $idnode, $idfile,$author, $authoremail, $comment, $language) { if(filter_var( $authoremail, FILTER_VALIDATE_EMAIL) ) { $idnode = intval($idnode); $idfile = intval($idfile); if ( $idnode>= 0 ) { if ( $idfile >= 0 ) { $db = wcCore::getDatabaseHandle(); $temp = sprintf( "%d,%d,'%s','%s','%s','%s'" , $idnode, $idfile , htmlspecialchars ($author, ENT_QUOTES, 'UTF-8'), $authoremail , htmlspecialchars ($comment, ENT_QUOTES, 'UTF-8') , $language); if ($db->queryInsert('Comments', 'idNode, idFile, author, email, comment, idLanguage', $temp)>0) { wcComment::updateNodeCommentsCount($idnode, $idfile); return 0; } } else { return 4; } } else { return 3; } } else { return 2; } return 1; } static function approve($idcomment) { } static function disable($idcomment) { } static function fetch( $language, $idnode, $idfile=0, $page=0, $pageentries=10 ) { $db = wcCore::getDatabaseHandle(); $idnode = intval($idnode); $idfile = intval($idfile); $language = filter_var($language, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); if ( $idnode >= 0 ) { if ( $idfile >= 0 ) { $temp = sprintf( "idNode = %d and idFile = %d and idLanguage = '%s'" , $idnode, $idfile , $language ); return $db->querySelect('Comments', $temp); } } return null; } static function get($idcomment) { } static function remove($idcomment) { } static function updateNodeCommentsCount($idnode, $idfile) { $result = 0; $db = wcCore::getDatabaseHandle(); $idnode = intval($idnode); $idfile = intval($idfile); $where = sprintf('idNode = %d and idFile = %d group by idNode,idFile', $idnode, $idfile); $nodes = $db->querySelect('Comments', $where, 'idNode, idFile, count(idNode) kc','1'); $kn = count($nodes); if ($kn > 0 ) { if ($idfile == 0) { if ($db->queryUpdate('Nodes','countComment='.$nodes[0]['kc'], 'idNode = '.$nodes[0]['idNode']) > 0) $result++; } else { if ($db->queryUpdate('Files','countComment='.$nodes[0]['kc'], 'idNode = '.$nodes[0]['idNode']. ' and idFile='.$nodes[0]['idFile']) > 0) $result++; } } return $result; } static function updateAllCommentsCount() { $db = wcCore::getDatabaseHandle(); $nodes = $db->querySelect('Comments', '1 group by idNode,idFile','idNode, idFile, count(idNode) kc'); $kn = count($nodes); $result = 0; for ($k=0 ; $k < $kn; $k++) { if (intval($nodes[$k]['idFile'])==0) { if ($db->queryUpdate('Nodes','countComment='.$nodes[$k]['kc'], 'idNode = '.$nodes[$k]['idNode']) > 0) $result++; } else { if ($db->queryUpdate('Files','countComment='.$nodes[$k]['kc'], 'idNode = '.$nodes[$k]['idNode']. ' and idFile='.$nodes[$k]['idFile']) > 0) $result++; } } return $result; } } ?><?php
class wcController { public $Name; public $Action; public $Data; public $Body; public $Type; public $Template = ''; public function __construct($name='',$type='',$area='') { $this->Name = $name; $this->Action = wcCore::varGet('q'); $this->Data = array(); $this->Body = ''; $this->Type = $type; $this->Area = $area; $this->Data['LANGUAGE'] = wcCore::getLanguage($area); $this->Data['URLSTATIC']= wcCore::cacheFetch(SITE.'urlStaticTheme'); $this->Data['PATHSITE'] = wcCore::cacheFetch(SITE.'pathSite'); $this->Template = 'default'; ob_start(); } public function loadTemplate($path='') { if (strlen($path)==0) $path=sprintf('./views/%s-%s-%s.php', $this->Name, $this->Template, $this->Type ); if (file_exists($path) ) { ob_start(); include $path; $this->Body = ob_get_contents(); ob_end_clean(); } else { echo "<br />"; } } public function render() { $this->loadTemplate(); $this->processPlugins(); $this->processData(); echo $this->Body ; function renderPage() { global $ctrl; $ctrl->loadTemplate(); $ctrl->processData(); $ctrl->processPlugins(); $ctrl->processData(); $ctrl->render(); } } public function processData() { $page=$this->Body; foreach($this->Data as $key => $value) { $search='<!--[-'.$key.'-]-->'; $page=str_replace( $search ,$value, $page); } $this->Body = $page; } public function processPlugins() { $page=$this->Body; while($p=strpos($page,'<[')) { $pos=$p+2; if ($pe=strpos($page,']>',$pos)) { $pcmd=strpos($page,':',$pos); $v=substr($page,$pcmd+1,$pe-$pcmd-1 ); $args=array(); $kv=strlen($v); $cmd=$val=''; $bcmd=true; for ($k=0;$k<$kv;$k++) { $a=$v[$k]; if (($a=='|') || ($a=="\n")|| ($a=="\r")) { $args[$cmd]=$val; $bcmd=true; $cmd=$val=''; continue; } if ($a=='=') $bcmd=false; else { if ($bcmd) $cmd.=$a; else $val.=$a; } } $args[$cmd]=$val; $cmd= substr($page,$pos, $pcmd-$pos); $func='plugin__'.$cmd; $temp=substr($page,0,$pos-2).$func($args).substr($page,$pe+2); $page=$temp; } else break; } $this->Body = $page; } public function loadCache() { if (is_null( $this->Action)) $path=sprintf('./cache/%s-%s-%s.php', $this->Name, $this->Template, $this->Type ); else $path=sprintf('./cache/%s-%s-%s.php', $this->Name, $this->Action, $this->Type ); if (file_exists($path)) { $mtime=@filemtime($path); if ( $mtime!== FALSE ) { $dtime = time()-$mtime; if ($dtime < 60) { $fin = fopen($path, "r"); if (FALSE !== $fin) { $this->Body = fread($fin, filesize($path)); fclose($fin); echo $this->Body; echo "*** CACHE *** "; return true; } } else unlink($path); } return false; } return false; } public function saveCache() { $path=sprintf('./cache/%s-%s-%s.php', $this->Name, $this->Template, $this->Type ); $fout = fopen($path, "w"); if ($fout !== FALSE) { fwrite($fout, $this->Body); fclose($fout); } } public function setTemplate($name) { $name = wcCore::cleanText($name); $this->Template = $name; } public function write($name) { if (isset($this->Data[$name])) echo $this->Data[$name]; } } ?>
<?php
function my_autoloader($class_name) { include ''. $class_name . '.php';} spl_autoload_register('my_autoloader'); wcCore::initialize(); interface iComponent { public static function componentInstall(); public static function componentUninstall(); } interface iHtml { static function lineBreak(); static function encode($text,$symbol,$option); static function encodeCode($text, $option); static function encodeCss($filename); static function encodeJs($filename); static function encodeLink($text,$link,$option); static function encodeHeader($text,$size); static function encodeNavList($labelnav,$items,$optionNAV,$optionsUL,$optionsLI); static function encodeList($items,$options,$optionsli); static function encodeFormTime($fieldname,$timestamp,$inc_min); static function encodeFormDate($fieldname,$timestamp,$inc_min); static function encodeLabel($id,$text,$options); static function encodeRadio($name,$value,$default,$options); static function encodeInputbox($name,$value,$options); static function enforceUrl($link); static function enforceMailto($link); } class wcTimer { var $ts; function __construct() { $this->ts=microtime(true); } function elapsed() { return (round(microtime(true) - $this->ts,4)); } } class wcCore { const accessModeReadOnly=0; const accessModeReadWrite=1; const accessModeOwner=2; const Version='1.0'; static function cacheStore($var,$value,$ttl=3600,$cachetype=0) { if (defined('EXT_APC')==true) apc_store($var,$value,$ttl); } static function cacheFetch($var,$cachetype=0) { if (defined('EXT_APC')==true) return apc_fetch($var); return false; } static function cleanText($text) { return filter_var( html_entity_decode($text), FILTER_SANITIZE_STRING ); } static function debugVar( $va, $option='') { echo '<pre '.$option.'>'; var_dump($va); echo '</pre>'; } static function getPlatform() { $agent = $_SERVER["HTTP_USER_AGENT"] ; $result = array(); $result['browser_name']=''; $result['browser_version']=''; $result['browser_build']=''; $ksl = strlen($agent); $pos = strpos ( $agent, '/' ); if ($pos !== false) { $result['browser_name'] = substr($agent, 0, $pos); $opos = $pos; $pos = strpos ( $agent, ' ',$pos ); if ($pos !== false) { $result['browser_version'] = substr($agent, ++$opos, $pos-$opos); $opos = $pos; $pos = strpos ( $agent, '(',$pos ); if ($pos !== false) { $agent = substr($agent, $pos+1, $ksl); $pos = strpos ( $agent, ')',$pos ); $result['platform'] = substr($agent, 0, $pos); $result['misc'] = trim(strtolower(substr($agent, $pos+1, $ksl))); } } } $os = explode(';', strtolower($result['platform'] )); $result['device'] = trim($os[0]); $result['device_detailed'] = trim($os[2]); $result['regional_settings'] = trim($os[3]); if ( strpos( $result['misc'], 'firefox/' ) ) { $result['browser_name'] = 'firefox'; if ( $pos = strpos( $result['misc'], 'gecko/' ) >= 0 ) { $pose = strpos( $result['misc'], ' ' ); $result['browser_build'] = substr($result['misc'], 5+$pos, $pose-($pos+5)); } if ($pos = strpos( $result['misc'], 'firefox/' )) $result['browser_version'] = substr($result['misc'], 8+$pos, $ksl); } if ( $pos = strpos( $result['misc'], 'safari/' ) ) { $result['browser_name'] = 'safari'; $result['browser_build'] = substr($result['misc'], 7+$pos, $ksl); $pos = strpos( $result['misc'], 'version/' ); if ( $pos >= 0 ) { $pose = strpos( $result['misc'], ' ', $pos+1 ); $result['browser_version'] = substr($result['misc'], 8+$pos, $pose-($pos+7)); } } if ( $pos = strpos( $result['misc'], 'chrome/' ) ) { $result['browser_name'] = 'chrome'; $pose = strpos( $result['misc'], ' ', $pos+1 ); $result['browser_build'] = substr($result['misc'], 7+$pos, $pose-($pos+7)); $result['browser_version'] = $result['browser_build']; } $result['browser_name'] = strtolower($result['browser_name']); return $result; } static function getDatabaseHandle($access_mode = 0) { global $CONFIG; switch($access_mode) { case 0: $dbHandle =new wcDB($CONFIG['dbDSNR']); break; case 1: $dbHandle=new wcDB($CONFIG['dbDSNW']); break; case 2: $dbHandle=new wcDB($CONFIG['dbDSNO']); break; } if (isset($dbHandle)) return $dbHandle; return null; } static function getGUID() { if (function_exists('com_create_guid') !== true) { $result = array(); for ($i = 0; $i < 8; ++$i) { switch ($i) { case 3: $result[$i] = mt_rand(16384, 20479); break; case 4: $result[$i] = mt_rand(32768, 49151); break; default: $result[$i] = mt_rand(0, 65535); break; } } return vsprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', $result); } return trim(com_create_guid(), '{}'); } static function getLanguage($area='') { global $CONFIG; $lang = wcCore::cacheFetch(SITE.$area.'language'); if (empty($lang) ) { if ( $lang === false) { if (isset($CONFIG['language'])) $lang=$CONFIG['language']; else $lang=1; } if (isset($_GET[$area.'language'])) { $langSession=$_GET[$area.'language']; } else { $langSession=wcCore::varSession($area.'LANGUAGE'); } if (is_null($langSession)===false) $lang = $langSession; } $_SESSION[$area.'LANGUAGE']=$lang; return $lang; } static function getLanguagesSite($status=1,$area='') { $db = wcCore::getDatabaseHandle(); $status= intval($status); if (is_object($db)) { if ($area=='admin') $result = $db->querySelect('LanguagesIso639','attrEnabledAdmin=\''.$status.'\' order by description','code,description'); else $result = $db->querySelect('languagesIso639','attrEnabled=\''.$status.'\' order by description','code,description'); return $result; } return null; } static function getServerID() { return crc32(sha1(php_uname('n'))); } static function getUniqueIDHex() { $s=uniqid(null,true); $s1=substr($s,0,14); $s2=substr($s,15); return "0x$s1$s2"; } static function getUniqueIDInt() { $s=uniqid(null,true); $s1=substr($s,0,14); $s2=substr($s,15); $num = base_convert("0x$s1$s2", 16,10); return $num; } function getUniqueIDString() { $s=uniqid(null,true); $s1=substr($s,0,14); $s2=substr($s,15); return base_convert($s1.$s2, 16, 36); } static function initialize() { if (defined('WCCORE')==true) die('wcCore already defined'); define('WCCORE','1'); if (extension_loaded('APC')) define('EXT_APC','1'); if (extension_loaded('memcache')) define('EXT_MEMCACHE','1'); session_start(); if (wcCore::cacheFetch('dbEnv')===false) { } if (defined('SITE')=== FALSE) die('WCCORE: UNDEFINED SITE'); } static function getSettings($var) { $db=wcCore::getDatabaseHandle(); $items = $db->querySelect('Settings', "keyname in ($var)"); $val = array(); $ki=count($items); for ($k=0 ; $k < $ki ; ++$k) { $val[ $items[$k]['keyname'] ] = $items[$k]['keyvalue']; } return $val; } static function prepareDatabaseSchema($uninstall=false) { if ($uninstall === true) { } else { } } static function redirect($url='index.php',$type='js') { switch ($type) { case 'php': header('location: '.$url); break; default: echo sprintf("<script type=\"text/javascript\">window.location = '%s';</script>",$url); break; } } static function stringEncode($data) { return htmlentities($data,ENT_QUOTES,"UTF-8"); } static function stringDecode($data) { return html_entity_decode($data,ENT_QUOTES,"UTF-8"); } static function varGet($name,$filter=-1) { if (isset($_GET[$name])) { if ($filter>=0) { return filter_var($_GET[$name],$filter); } else return $_GET[$name]; } return null; } static function varPost($name,$filter=-1) { if (isset($_POST[$name])) { if ($filter>=0) { return filter_var($_POST[$name],$filter); } else return $_POST[$name]; } return null; } static function varSession($name) { if (isset($_SESSION[$name])) return $_SESSION[$name]; return null; } } <?php class wcDB { public $dbHandle; var $dbUser; var $dbHost; var $dbDatabase; var $dbPassword; var $dbPort; var $dbSocket; var $dbLastError; function __construct($dsn) { $values = explode(';', $dsn); $this->dbHandle = null; if (count($values) >= 5) { $this->dbHost = $values[0]; $this->dbDatabase = $values[1]; $this->dbUser = $values[2]; $this->dbPassword = $values[3]; $this->dbPort = $values[4]; if (count($values) >= 6) $this->dbSocket = $values[5]; } } function checkError() { if (mysqli_connect_errno()) return mysqli_connect_error(); return null; } function connect() { if ($this->dbHandle === null) { if (strlen($this->dbSocket) > 0) $this->dbHandle = @mysqli_connect('', $this->dbUser, $this->dbPassword, $this->dbDatabase, 0, $this->dbSocket); else $this->dbHandle = @mysqli_connect($this->dbHost, $this->dbUser, $this->dbPassword, $this->dbDatabase, $this->dbPort); if ($this->dbHandle === false) { $dbLastError = mysqli_connect_error(); } else { $this->dbHandle->query('SET NAMES utf8'); $this->dbHandle->set_charset('utf8'); $dbLastError = ''; } } return $this->dbHandle; } function disconnect() { if ($this->dbHandle) mysqli_close($this->dbHandle); $this->dbHandle = null; } function getLastID() { return $this->dbHandle->insert_id; } function escapeString($value) { return $this->dbHandle->real_escape_string($value); } function query($sql) { $arr = array(); if ($this->Connect()) { $result = $this->dbHandle->query($sql); if ($result != false) { if (is_object($result)) { while ($row = mysqli_fetch_assoc($result)) { $arr[] = $row; } $result->close(); } } } return $arr; } function queryInsert($table, $fields, $values) { if ($this->Connect() != null) { $sql = sprintf("insert into %s_%s (%s) values (%s)", SITE, $table, $fields, $values); $this->dbHandle->query($sql); return $this->dbHandle->affected_rows; } return 0; } function querySelect($table, $condition = '1', $fields = '*', $limit = 0, $offset = 0) { if (defined('SITE') === FALSE) die('wcdb: UNDEFINED SITE'); $arr = array(); if ($this->Connect()) { if ($this->dbHandle == NULL) return null; if ($condition == '1') $sql = sprintf("select %s from %s_%s", $fields, SITE, $table); else $sql = sprintf("select %s from %s_%s where %s ", $fields, SITE, $table, $condition); if ($limit > 0) $sql .= " limit $offset, $limit"; if ($result = $this->dbHandle->query($sql)) { if (is_object($result)) { while ($row = mysqli_fetch_assoc($result)) { $arr[] = $row; } $result->close(); } } } return $arr; } function queryUpdate($table, $set, $condition = '1') { if ($this->Connect()) { $sql = sprintf("update %s_%s set %s where %s", SITE, $table, $set, $condition); if (!$this->dbHandle->query($sql)) { printf("ERROR: %s<br />", $this->dbHandle->error); } return $this->dbHandle->affected_rows; } return 0; } function queryDelete($table, $condition = '1') { if ($this->Connect()) { $sql = sprintf("delete from %s_%s where %s", SITE, $table, $condition); $this->dbHandle->query($sql); return $this->dbHandle->affected_rows; } return 0; } } ?>
<?php
class wcDBsqlite { public $dbHandle; public $dbFilePath; public $dbLastError; function __construct($dsn) { $values = explode( ';', $dsn ); $this->dbHandle=null; if (count( $values ) >= 5) { $this->dbFilePath = $values[0]; } } function checkError() { } function connect() { if ($this->dbHandle === null) { if ( strlen($this->dbSocket)> 0) $this->dbHandle = @mysqli_connect( '' , $this->dbUser , $this->dbPassword , $this->dbDatabase,0, $this->dbSocket); else $this->dbHandle = @mysqli_connect( $this->dbHost, $this->dbUser , $this->dbPassword , $this->dbDatabase, $this->dbPort); if ($this->dbHandle === false) { $dbLastError=mysqli_connect_error(); } else { $this->dbHandle->query( 'SET NAMES utf8' ); $this->dbHandle->set_charset('utf8'); $dbLastError=''; } } return $this->dbHandle; } function disconnect() { if ($this->dbHandle) mysqli_close($this->dbHandle); $this->dbHandle = null; } function getLastID() { return $this->dbHandle->insert_id; } function escapeString($value) { return $this->dbHandle->real_escape_string( $value ); } function query($sql) { $arr=array(); if ($this->Connect()) { $result = $this->dbHandle->query( $sql ); if ( $result != false) { if (is_object($result)) { while ($row = mysqli_fetch_assoc( $result ) ) { $arr[]=$row; } $result->close(); } } } return $arr; } function queryInsert($table, $fields, $values) { if ($this->Connect() != null ) { $sql = sprintf("insert into %s_%s (%s) values (%s)", SITE, $table, $fields, $values ); $this->dbHandle->query( $sql ); return $this->dbHandle->affected_rows; } return 0; } function querySelect($table, $condition='1', $fields='*', $limit=0, $offset=0 ) { if (defined('SITE')=== FALSE) die('wcdb: UNDEFINED SITE'); $arr=array(); if ($this->Connect()) { if ($this->dbHandle == NULL) return NULL; if ($condition == '1') $sql = sprintf("select %s from %s_%s", $fields, SITE, $table); else $sql = sprintf("select %s from %s_%s where %s ", $fields, SITE, $table, $condition); if ($limit > 0) $sql.=" limit $offset, $limit"; if ( $result = $this->dbHandle->query( $sql )) { if (is_object($result)) { while ($row = mysqli_fetch_assoc( $result ) ) { $arr[]=$row; } $result->close(); } } } return $arr; } function queryUpdate($table, $set, $condition='1') { if ($this->Connect()) { $sql = sprintf("update %s_%s set %s where %s", SITE, $table, $set, $condition); $this->dbHandle->query( $sql ); return $this->dbHandle->affected_rows; } return 0; } function queryDelete($table,$condition='1') { if ($this->Connect()) { $sql = sprintf("delete from %s_%s where %s", SITE, $table, $condition); $this->dbHandle->query( $sql ); return $this->dbHandle->affected_rows; } return 0; } } ?>
<?php
class wcDirectory { static function getLatest($params=array()) { global $ctrl; $limit = 10; $idlanguage = 'en'; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; if ( isset( $params['idlanguage'] )) $idlanguage = $params['idlanguage']; } } $result = array(); $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('Directory', sprintf( "idLanguage = '%s' order by dateAdded desc", $idlanguage ), "*" , $limit); $ki=count($items); for($k=0; $k<$ki; ++$k) { $items[$k]['website'] = wcHtml5::enforceUrl ( $items[$k]['website'] ); $items[$k]['email'] = wcHtml5::enforceMailto( $items[$k]['email'] ); $result[]= $items[$k]; } return $result; } static function browseRange($params) { global $ctrl; $limit = 10; $idlanguage = 'en'; $value=''; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; if ( isset( $params['idlanguage'] )) $idlanguage = $params['idlanguage']; if ( isset( $params['value'] )) $value = $params['value']; } } $result = array(); if ( $value == '') return $result; $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('Directory', sprintf( "idLanguage = '%s' and name like '%s%%' order by attrWeight desc, name ", $idlanguage, $value ), "*" , 1000); $ki=count($items); for($k=0; $k<$ki; ++$k) { $items[$k]['website'] = wcHtml5::enforceUrl ( $items[$k]['website'] ); $items[$k]['email'] = wcHtml5::enforceMailto( $items[$k]['email'] ); $result[]= $items[$k]; } return $result; } } ?><?php
class wcEvents { static function getLatest($params=array()) { global $ctrl; $limit = 10; $idlanguage = 'en'; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; if ( isset( $params['idlanguage'] )) $idlanguage = $params['idlanguage']; } } $result = array(); $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('Events e left join vsc_Nodes n on e.idNode = n.idNode ', sprintf( "CURDATE() < e.dateEnd and n.idLanguage = '%s' and n.attrStatus = 1 order by e.dateStart desc ", $idlanguage ), "DATE_FORMAT(e.dateStart, '%Y-%m-%d %H:%i') timestampStart,DATE_FORMAT(e.dateEnd, '%Y-%m-%d %H:%i') timestampEnd,n.title , e.idNode" , $limit); return $items; } } ?><?php class wcFiles { static function getImagesSet( $params=array() ) { global $ctrl; $limit = 10; $idlanguage = 'en'; $mode = 'random'; $data = ''; $rel = ''; $max = 3; $nodeid = 0; $pageid = 0; $width = 0; $height = 0; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; if ( isset( $params['nodeid'] )) $nodeid = $params['nodeid']; if ( isset( $params['width'] )) $width = $params['width']; if ( isset( $params['height'] )) $height = $params['height']; if ( isset( $params['pageid'] )) $pageid = $params['pageid']; if ( isset( $params['idlanguage'] )) $idlanguage = $params['idlanguage']; if ( isset( $params['rel'] )) $rel = sprintf(' rel="%s" ',$params['rel']); if ( isset( $params['mode'] )) { switch( $params['mode'] ) { case 'latest': $mode = 'latest'; break; case 'gallery': $mode = 'latest'; break; default: $mode = 'random'; break; } } } } $db=wcCore::getDatabaseHandle(); switch( $mode ) { case 'pageid': $sql = sprintf(" idNode = %d and attrStatus = 5 and fileType='image/jpeg' order by attrWeight", $nodeid); $items = $db->querySelect('Files', $sql , "idFile,idNode,caption" , $limit); break; case 'latest': $items = $db->querySelect('Files', " attrStatus = 5 and fileType='image/jpeg' order by dateAdded desc", "idFile,idNode,caption" , $limit); break; default: $items = $db->querySelect('Files', " attrStatus = 5 and fileType='image/jpeg' ORDER BY RAND() ", "idFile,idNode,caption" , $limit); break; } $kitems=count($items); for ($k=0;$k<$kitems;$k++) { $large =sprintf('files/%d/%d_m.jpg', $items[$k]['idNode'],$items[$k]['idFile']); $thumb =sprintf('files/%d/%d_t.jpg', $items[$k]['idNode'],$items[$k]['idFile']); $title = htmlspecialchars( $items[$k]['caption'], ENT_QUOTES ); $size = ''; if ($width > 0) $size = 'width="'.$width.'"'; if ($height > 0) $size .= ' height="'.$height.'"'; $data.=sprintf('<li><a href="%s" %s title="%s"><img src="%s" %s alt=""/></a></li>',$large,$rel, $title,$thumb,$size, $title); } return $data; } } ?><?php
class wcFileSystem { const TYPE_FILE = 1; const TYPE_DIR = 2; const TYPE_ALL = 3; const MIME_UNKNOWN = '*UNKNOWN*' ; const MIME_JPEG = 'image/jpeg'; const MIME_JPEG2000 = 'image/jpeg2000'; const MIME_GIF = 'image/gif'; const MIME_PNG = 'image/png'; const MIME_PDF = 'application/x-pdf'; const MIME_ZIP = 'application/zip'; const MIME_BZIP = 'application/x-bzip'; const MIME_GZIP = 'application/x-gzip'; static function getDirContents($path, $mode=3) { $entries = array(); $path = rtrim ($path, '/').DIRECTORY_SEPARATOR; if (is_dir($path)) { if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if ($file == '.' ) continue; if ($file == '..') continue; $entry = $path.$file; if ($mode == 3) { $entries[] = $entry; continue; } if ($mode == 1) { if (is_file($entry)) { $entries[] = $entry; } continue; } if ($mode == 2) { if (is_dir($entry)) $entries[] = $entry; continue; } } closedir($dh); } } return $entries; } static function createDir($dir, $access = 0775) { @mkdir($dir, $access); clearstatcache(); } static function getFileType($filename) { $fin= fopen($filename, 'rb'); if ($fin) { $buf= fread($fin, 30); if( substr($buf,0,3) == 'BZh' ) return wcFileSystem::MIME_BZIP; if( substr($buf,0,4) == 'GIF8' ) return wcFileSystem::MIME_GIF; if ( bin2hex(substr($buf,0,2)) == '1f8b' ) return wcFileSystem::MIME_GZIP; if ( bin2hex(substr($buf,0,2)) == 'ffd8' ) return wcFileSystem::MIME_JPEG; if ( bin2hex(substr($buf,0,23)) == '0000000c6a5020200d0a870a00000014667479706a7032' ) return wcFileSystem::MIME_JPEG2000; if ( bin2hex(substr($buf,0, 4)) == '25504446' ) return wcFileSystem::MIME_PDF; if ( bin2hex(substr($buf,0, 8)) == '89504e470d0a1a0a' ) return wcFileSystem::MIME_PNG; fclose($fin); } return wcFileSystem::MIME_UNKNOWN; } static function getImageFileInfo( $filename ) { $info =array(); $size = getimagesize( $filename , $iptcinfo); if (isset($size) === true) { $info['type'] = $size['mime']; $info['dimension']['width'] = $size[0]; $info['dimension']['height'] = $size[1]; $info['dimension']['xratio'] = $size[0] / $size[1]; $info['dimension']['yratio'] = $size[1] / $size[0]; $exif = exif_read_data( $filename , 'IFD0'); if (is_array($exif)) { $info['exif']['filename'] = (isset($exif['FileName'])) ? $exif['FileName'] : ''; $info['exif']['datetimestamp'] = (isset($exif['FileDateTime'])) ? $exif['FileDateTime'] : ''; $info['exif']['size'] = (isset($exif['FileSize'])) ? $exif['FileSize'] : ''; $info['exif']['make'] = (isset($exif['Make'])) ? $exif['Make'] : ''; $info['exif']['model'] = (isset($exif['Model'])) ? $exif['Model'] : ''; $info['exif']['datetimeoriginal'] = (isset($exif['DateTimeOriginal']))? $exif['DateTimeOriginal'] : ''; $info['exif']['exposuretime'] = (isset($exif['ExposureTime'])) ? $exif['ExposureTime'] : ''; $info['exif']['fnumber'] = (isset($exif['FNumber'])) ? $exif['FNumber'] : ''; $info['exif']['isospeedrating'] = (isset($exif['ISOSpeedRatings'])) ? $exif['ISOSpeedRatings'] : ''; $info['exif']['shutterspeedvalue'] = (isset($exif['ShutterSpeedValue']))? $exif['ShutterSpeedValue'] : ''; $info['exif']['aperturevalue'] = (isset($exif['ApertureValue'])) ? $exif['ApertureValue'] : ''; $info['exif']['exposurebias'] = (isset($exif['ExposureBiasValue']))? $exif['ExposureBiasValue'] : ''; $info['exif']['maxaperturevalue'] = (isset($exif['MaxApertureValue'])) ? $exif['MaxApertureValue'] : ''; $info['exif']['flash'] = (isset($exif['Flash'])) ? $exif['Flash'] : ''; $info['exif']['focallength'] = (isset($exif['FocalLength'])) ? $exif['FocalLength'] : ''; $info['exif']['meteringmode'] = (isset($exif['MeteringMode'])) ? $exif['MeteringMode'] : ''; } if (isset($iptcinfo["APP13"])) { $iptc = iptcparse($iptcinfo["APP13"]); $info['iptc']['title'] = (isset($iptc['2#005'][0])) ? $iptc['2#005'][0] : ''; $info['iptc']['keywords'] = (isset($iptc['2#025'][0])) ? implode( '|', $iptc['2#025'] ) : ''; $info['iptc']['creationdate'] = (isset($iptc['2#055'][0])) ? $iptc['2#055'][0] : ''; $info['iptc']['caption'] = (isset($iptc['2#120'][0])) ? $iptc['2#055'][0] : ''; } } else { $info['type'] = wcFileSystem::getFileType($filename); } $info['size'] = filesize ( $filename ); return $info; } } ?>
<?php
class wcHtml5 { static function lineBreak() { return '<br>'; } static function encode($text,$symbol,$option='') { return "<{$symbol} {$option}>{$text}</{$symbol}>"; } static function encodeCode($text, $option='') { return "<pre $option>$text</pre>"; } static function encodeCss($filename) { return sprintf("<link type=\"text/css\" href=\"%s\" rel=\"stylesheet\" />\n", $filename); } static function encodeJs($filename) { return sprintf("<script type=\"text/javascript\" src=\"%s\"></script>\n", $filename); } static function encodeLink($text,$link,$option='') { return sprintf('<a href="%s" %s>%s</a>',$link,$option,$text); } static function encodeHeader($text,$size=1) { return "<h{$size}>{$text}</h{$size}>"; } static function encodeNavList($labelnav,$items,$optionsNAV,$optionsUL='',$optionsLI='') { $kc=count($items); $d="<nav {$optionsNAV}><h5>{$labelnav}</h5><ul {$optionsUL}>"; for ($k=0;$k<$kc;$k++) { $d.="<li {$optionsLI}>".$items[$k].'</li>'; } $d.='</ul></nav>'; return $d; } static function encodeList($items,$options='',$optionsli='') { $kc=count($items); $d="<ul {$options}>"; for ($k=0;$k<$kc;$k++) { $d.="<li {$optionsli}>".$items[$k].'</li>'; } $d.='</ul>'; return $d; } static function encodeFormTime($fieldname,$timestamp=0,$inc_min=1) { if ($timestamp==0) $timestamp=time(); $hour=date('H',$timestamp); $min=date('i',$timestamp); $code="<select name=\"{$fieldname}_hour\""; for ($k=1;$k<25;$k++) { if ($k==$hour) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; $code.="<select name=\"{$fieldname}_minute\""; for ($k=0;$k<60;$k+=$inc_min) { if ($k==$min) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; return $code; } static function encodeFormDate($fieldname,$timestamp=0,$inc_min=10) { if ($timestamp==0) $timestamp=time(); $year=date('Y',$timestamp); $month=date('n',$timestamp); $day=date('j',$timestamp); $code="<select name=\"{$fieldname}_month\""; for ($k=1;$k<13;$k++) { if ($k==$month) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; $code.="<select name=\"{$fieldname}_day\""; for ($k=1;$k<32;$k++) { if ($k==$day) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; $code.="<select name=\"{$fieldname}_year\""; for ($k=$year;$k<$year+$inc_min;$k++) { if ($k==$year) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; return $code; } static function encodeLabel($id,$text,$options='') { return sprintf("<label for=\"%s\" %s>%s</label>", $id, $options, $text); } static function encodeRadio($name,$value,$default='',$options='') { if ($value==$default) $checked=" checked=\"checked\""; else $checked=''; $code=sprintf("<input type=\"radio\" name=\"%s\" value=\"%s\" %s %s/>", $name, $value , $checked, $options); return $code; } static function encodeInputbox($name,$value,$options='') { $code=sprintf("<input type=\"text\" name=\"%s\" value=\"%s\" %s />", $name, $value, $options); return $code; } static function encodeTable($items,$options='',$optionstr='', $optionstd='') { $kc=count($items); $d="<table {$options}>"; for ($k=0;$k<$kc;$k++) { $d.="<tr {$optionstr}>"; if (is_array($items[$k])) { $ks=count($items[$k]); foreach ($items[$k] as $i => $value) { $d.="<td {$optionstd}>{$value}</td>"; } $d.="<tr />"; } } $d.='</table>'; return $d; } static function enforceUrl($link) { $link = trim(strtolower( $link )); if (substr($link,0,7) != 'http://' ) $link = 'http://'. $link; return $link; } static function enforceMailto($link) { $link = trim(strtolower($link)); if ( ($link == '-') || ($link=='')) { $link = ''; } else { if (substr($link,0,7) != 'mailto:' ) $link = 'mailto:'. $link; } return $link; } } ?>
<?php
class wcImport { static function getHashes($mode=0,$idnode=0) { global $CONFIG; $hashes=array(); $id=$idnode; if ($id>0) { $path=trim($CONFIG['pathSite']); if (strlen($path)>0) { $path=sprintf("%sfiles/%d", $path ,$id); @mkdir($path,0775); } } switch($mode) { case 2: $db = wcCore::getDatabaseHandle(); $hashes = $db->querySelect('Files', 'idNode = '. $id, 'hashMD5'); break; case 1: break; default: $db = wcCore::getDatabaseHandle(); $sql = sprintf( 'SELECT * FROM tkFiles WHERE idNode="%d";' , $this->data['nodeContent']['idNode']); $hashes = $db->query($sql); break; } } static function imageResize($filenameSrc,$filenameDest,$width=100,$height=100,$watermark='',$quality=75) { $info=getimagesize($filenameSrc); if ($watermark!='') $imgW=@imagecreatefrompng($watermark); $owidth=$width; if (count($info)>0) { switch($info[2]) { case IMG_GIF: $imgS = @imagecreatefromgif($filenameSrc); break; case IMG_JPG: $imgS = @imagecreatefromjpeg($filenameSrc); break; case IMG_JPEG: $imgS = @imagecreatefromjpeg($filenameSrc); break; case IMG_PNG: $imgS = @imagecreatefrompng($filenameSrc); break; case IMG_BMP: $imgS = @imagecreatefromwbmp($filenameSrc); break; case IMG_WBMP: $imgS = @imagecreatefromwbmp($filenameSrc); break; default: echo "File: $filenameSrc<br />"; die('invalid media type'); break; } if (isset($imgS)) { $imgD = imageCreateTrueColor($width,$height); $dst_x=0; $dst_y=0; if ($width==$height) { if ($info[0]>$info[1]) { $diff=($info[0]-$info[1])/2; $src_w=$src_h=$info[1]; $src_x=$diff; $src_y=0; if ($info[1]<$height) { $src_y=($height-$info[1])/2; } imageCopyResampled($imgD, $imgS,0,0, $src_x , $src_y , $width , $height , $src_w , $src_h ); } if ($info[0]==$info[1]) { $src_w=$src_h=$info[0]; $src_x=0; $src_y=0; imageCopyResampled($imgD, $imgS,0,0, $src_x , $src_y , $width , $height , $src_w , $src_h ); } if ($info[0]<$info[1]) { $diff=($info[1]-$info[0])/2; $src_w=$src_h=$info[0]; $src_y=$diff; $src_x=0; imageCopyResampled($imgD, $imgS,0,0, $src_x , $src_y , $width , $height , $src_w , $src_h ); } } else { if ($info[0]>$info[1]) { $nh=ceil(($width/$info[0])*$info[1]); imageCopyResampled($imgD, $imgS, 0, $height-$nh, 0 , 0 , $width , $nh , $info[0] , $info[1] ); } if ($info[0]==$info[1]) { if ($info[0]>=$width) { } else { } } if ($info[0]<$info[1]) { $nw=ceil(($height/$info[1])*$info[0]); imageCopyResampled($imgD, $imgS, ($width-$nw)/2 , 0, 0 , 0 , $nw , $height , $info[0] , $info[1] ); } } if (isset($imgW)) { $infow=getimagesize($watermark); if ($info[0]<$info[1]) { $newh=($owidth*$infow[1])/$infow[0]; imageCopyResampled($imgD,$imgW,0,0,0,0,$owidth,$newh,$infow[0],$infow[1]); } else imageCopyResampled($imgD,$imgW,0,0,0,0,$width,($width*$infow[1])/$infow[0],$infow[0],$infow[1]); imageDestroy($imgW); } imageDestroy($imgS); imageJPEG($imgD,$filenameDest,$quality); imageDestroy($imgD); if (file_exists($filenameDest)) return true; } } return false; } static function importFiles($idnode , $filenames ) { if (is_array($filenames) === true ) { $kf = count($filenames); echo "Processing $kf files<br />"; if ($kf == 0 ) return 0; $target_dir = sprintf( "%s/_%s/files/%d", dirname(getcwd() ), SITE, $idnode); @mkdir($target_dir, 0777, true); echo "Target dir [$target_dir]<br />"; $processfiles=0; $db = wcCore::getDatabaseHandle(); $hashes = wcImport::getHashes(2, $idnode); $ki = count($hashes); echo "<hr /><h2>Hashes</h2>"; var_dump($hashes); echo "<hr /><br />"; echo $kf; for ($k = 0 ; $k < $kf ; ++$k ) { $filename = $filenames[$k]; echo "<hr />- Processing $filename<br />"; if (file_exists($filename)) { $path_parts = pathinfo( $filename ); $hash = md5_file( $filename ); $size = filesize( $filename ); $caption = strtolower ( filter_var($path_parts['filename'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES ) ); $caption = strtr( $caption, '_!$.=,',' ' ); $caption = preg_replace('/\[.*\]/', '', $caption); $extension = strtolower ( $path_parts['extension']); $values=sprintf(" %d , now(), '%s', '%s' ,'%s' , %d", $idnode, $extension , $caption , $hash, $size ); $db->queryInsert('Files','idNode , dateAdded, fileExt , caption , hashMD5, fileSize', $values); $id = $db->dbHandle->insert_id; if ($id > 0) { echo "inserted id [$id]<br />"; echo getcwd().'<br />'; $dest = sprintf ( "%s/%d.%s" , $target_dir, $id , $extension ); echo "SRC <br />[$filename]<br />[$dest]<br /><br />"; rename( $filename, $dest ); if (file_exists( $dest )) { echo "- File copied successfully<br />"; } else { echo "File copy failed..<br />"; $temp = sprintf("idFile=%d",$id); $db->queryDelete('Files', $temp); } } } else { echo "File copy failed..<br />"; } } } return 0; } static function indexMissingFiles() { $db = wcCore::getDatabaseHandle(); $log = new wcLog(); $log->init(); $log->write('admin interface, looking for missing files'); $items = $db->querySelect('Files', 'attrStatus=5','idFile,idNode,fileExt'); global $CONFIG; $path = $CONFIG['pathSite']; if (strlen(trim($path))==0) { $log->write("Fatal error, base path for the current site is empty, check config file under woxdata/<sitename>, variable is pathSite"); } else { $log->write("Processing path:".$path); $ki=count($items); $missing=0; for ($k=0;$k < $ki ; ++$k) { $file = sprintf("%sfiles/%s/%s.%s", $path, $items[$k]['idNode'], $items[$k]['idFile'], $items[$k]['fileExt'] ); if (file_exists($file) === false) { ++$missing; $log->write("Missing: $file"); } } $log->write('admin interface, found '. $missing . ' missing file(s)'); $log->write('admin interface, missing files scanning is done'); } return $log->idBatch; } static function indexFilesMetadata($max='0') { global $CONFIG; $db = wcCore::getDatabaseHandle(); $log = new wcLog(); $log->init(); $log->write('admin interface, beginning metadata scanning'); $items = $db->querySelect('Files', 'attrStatus=0','idFile,idNode,fileExt'); $path = $CONFIG['pathSite'].'/files'; $ic = 0; $ki=count($items); echo "Path: $path"; for ($k=0;$k < $ki ; ++$k) { $file = sprintf("%s/%s/%s.%s", $path, $items[$k]['idNode'], $items[$k]['idFile'], $items[$k]['fileExt'] ); if (file_exists($file) === true) { $info = wcFileSystem::getImageFileInfo( $file ); $title = trim( (isset($info['iptc']['title'])) ? $info['iptc']['title'] : '' ); $date = trim( (isset($info['exif']['datetimeoriginal'])) ? $info['exif']['datetimeoriginal'] : ''); $width = trim( (isset($info['dimension']['width' ])) ? $info['dimension']['width' ] : 0); $height = trim( (isset($info['dimension']['height'])) ? $info['dimension']['height'] : 0); $type = trim( (isset($info['type'])) ? $info['type'] : 'unknown'); $set='attrStatus=4'; if (strlen($title)>0) $set.= sprintf( ", caption='%s'", filter_var($title, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH ) ); if (strlen($date)>0) $set.= sprintf( ", dateAdded= timestamp('%s')", $date ); if ($width != '0') $set.= sprintf( ", attrInt1 = %s", $width ); if ($height != '0') $set.= sprintf( ", attrInt2 = %s", $height ); if (strlen($type)>0) $set.= sprintf( ", fileType='%s'", filter_var($type, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH ) ); if (strlen($type)>0) $set.= sprintf( ", fileType='%s'", filter_var($type, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH ) ); $set .= ", metadata = '". addslashes(base64_encode(serialize($info)))."'"; $ic += $db->queryUpdate('Files',$set ,'idFile='.$items[$k]['idFile']); if ($max > 0) if ($ic >= $max) break; } } $log->write('admin interface, metadata import: '. $ic . ' file(s) processed'); $log->write('admin interface, ending metadata scanning'); return $log->idBatch; } static function indexGenerateThumbnails($max=0) { global $CONFIG; $log = new wcLog(); $log->init(); $log->write('admin interface, thumbnail generation started'); $db = wcCore::getDatabaseHandle(); $settings = wcCore::getSettings("'image_thumbnailsize_width', 'image_thumbnailsize_height', 'image_mediumsize_width', 'image_mediumsize_height'"); if (count($settings) != 4) { $msg='missing one of the following parameter in table <site>_Settings : '."'image_thumbnailsize_width', 'image_thumbnailsize_height', 'image_mediumsize_width', 'image_mediumsize_height'"; $log->write($msg); die($msg); } $items = $db->querySelect('Files', 'attrStatus=4','idFile,idNode,fileExt'); $ki=count($items); $path = $CONFIG['pathSite'].'/files'; $ic=0; for ($k=0;$k < $ki ; ++$k) { $fileSrc = sprintf("%s/%s/%s.%s", $path, $items[$k]['idNode'], $items[$k]['idFile'], $items[$k]['fileExt'] ); $fileDstThumb = sprintf("%s/%s/%s_t.jpg", $path, $items[$k]['idNode'], $items[$k]['idFile'], $items[$k]['fileExt'] ); $fileDstMedium = sprintf("%s/%s/%s_m.jpg", $path, $items[$k]['idNode'], $items[$k]['idFile'], $items[$k]['fileExt'] ); if (file_exists($fileSrc) === true) { @unlink($fileDstThumb); @unlink($fileDstMedium); if (wcImport::imageResize($fileSrc, $fileDstThumb, intval( $settings['image_thumbnailsize_width'] ) , intval( $settings['image_thumbnailsize_height'] )) === true) { $log->write('thumbnail generation, generation of thumbnail: '. $fileDstThumb); if (wcImport::imageResize($fileSrc, $fileDstMedium, intval( $settings['image_mediumsize_width'] ) , intval( $settings['image_mediumsize_height'] ), '',85) === true) { $log->write('thumbnail generation, generation of medium sized file: '. $fileDstMedium); $ic++; $db->queryUpdate('Files','attrStatus=5','idFile='.$items[$k]['idFile']); } else $log->write('thumbnail generation, failed generation of medium sized file: '. $fileDstMedium); } else $log->write('thumbnail generation, failed generation of thumbnail: '. $fileDstThumb); } else $log->write('thumbnail generation: cannot find source file : '. $fileSrc); } $log->write('admin interface, thumbnail generation, '. $ic . ' file(s) processed'); $log->write('admin interface, thumbnail generation ended'); return $log->idBatch; } static function indexRebuildOrder() { $db = wcCore::getDatabaseHandle(); $log = new wcLog(); $log->init(); $log->write('admin interface, indexRebuildOrder'); $items = $db->querySelect('Files', '1 order by idNode','distinct idNode'); $ki=count($items); $errors=0; for ($k=0;$k < $ki ; ++$k) { $buffer = sprintf(" - Processing idNode [%d]<br />", $items[$k]['idNode']); $log->write($buffer); $itemsN = $db->querySelect('Files', 'idNode='.$items[$k]['idNode']. ' and attrStatus=5 and fileExt = "jpg" order by attrWeight' ,'idFile,attrWeight'); $weight = 0 ; $kiN=count($itemsN); for ($kN=0;$kN < $kiN ; ++$kN) { if ( $itemsN[$kN]['attrWeight'] != $weight ) { echo $itemsN[$kN]['idFile'].'/'.$itemsN[$kN]['attrWeight'].' -- Weight not matching , rebuilding<br />'; $db->queryUpdate('Files','attrWeight='.$weight, 'idFile='.$itemsN[$kN]['idFile']); ++$errors; } ++$weight; } } $log->write('admin interface, errors: '.$errors); $log->write('admin interface, indexRebuildOrder is done'); return $log->idBatch; } } ?><?php
class wcLog { public $idBatch; public $db; function __construct() { $this->idBatch = ''; $this->db = null; $logs = array(); } function init() { $this->db = wcCore::getDatabaseHandle(); $items = $this->db->query('select uuid() uuid' ); $this->idBatch = $items[0]['uuid']; } function write($summary, $detailed='') { if (strlen($this->idBatch)>0) { if (is_object($this->db)) { if ( strlen($summary) > 0) { if ( strlen($detailed) == 0) $this->db->queryInsert('Logs', "idBatch,summary", sprintf("'%s', '%s'", $this->idBatch, addslashes( $summary)) ); else $this->db->queryInsert('Logs', "idBatch,summary, detailed", sprintf("'%s', '%s','%s'", $this->idBatch, addslashes( $summary), addslashes($detailed)) ); } } } } static function getLogEntries($idbatch) { $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('Logs' , " idBatch='$idbatch'", 'dateLogged, summary, detailed' ); return $items; } } ?><?php
class wcMember { static function register($data) { if (is_array($data) == false) return 1; $password = $password1 = $password2=''; $nickname = $email = ''; foreach( $data as $key => $value) { switch ($key) { case 'nickname': $nickname = htmlspecialchars( trim( strip_tags( $value ) ) ); if (strlen ($nickname) < 2 ) return 2; break; case 'email': $value = htmlspecialchars( filter_var(strip_tags($value), FILTER_VALIDATE_EMAIL)); if ($value === false) return 3; $email = trim ($value) ; break; case 'password1': $password1=trim($value); break; case 'password2': $password2=trim($value); break; case 'language': $language=trim($value); break; default: break; } } if (strlen($email) == 0) return 7; if (strlen($password1) == 0) return 8; if (strlen($password2) == 0) return 9; if ($password1 == $password2) $password = $password1; else return 4; $db = wcCore::getDatabaseHandle(); $db->connect(); $condition = sprintf( "nickname = '%s' or email = '%s' " , $nickname, $email); $result = $db->querySelect('Members', $condition, 'count(*) as cnt'); if (is_array($result)) { $count = intval( $result[0]['cnt'] ) ; if ( $count > 0) { return 10; } else { $values = sprintf( "'%s','%s','%s','%s', '%s',now() ", $language, $nickname, $email, sha1($password), sha1(rand()) ); $result = $db->queryInsert('Members', 'idLanguage, nickname, email, hash1, hash2 , dateCreated', $values); if ($result==-1) { switch ($db->dbHandle->errno) { case 1062: return 6; default: return 5; break; } } else { if ($result == 1) { return 0; } } } } return 5; } } ?><?php
class wcMembers { static function getLatest($params=array()) { global $ctrl; $limit = 10; $idlanguage = 'en'; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; } } $result = array(); $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('Members', sprintf( "1 order by dateCreated desc" ), "id, idLanguage, attrStatus, email, hash1, hash2, firstname, lastname, nickname, ifnull(dateLastlogin,'---') dateLastlogin, dateCreated" , $limit); $ki=count($items); for($k=0; $k<$ki; ++$k) { $items[$k]['email'] = wcHtml5::enforceMailto( $items[$k]['email'] ); $result[]= $items[$k]; } return $result; } static function browseRange($params) { global $ctrl; $limit = 10; $idlanguage = 'en'; $value=''; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; if ( isset( $params['value'] )) $value = $params['value']; } } $result = array(); if ( $value == '') return $result; $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('Members', sprintf( "nickname like '%s%%' order by nickname desc", $value ), "id, idLanguage, attrStatus, email, hash1, hash2, firstname, lastname, nickname, ifnull(dateLastlogin,'---') dateLastlogin, dateCreated" , 1000); $ki=count($items); for($k=0; $k<$ki; ++$k) { $items[$k]['email'] = wcHtml5::enforceMailto( $items[$k]['email'] ); $result[]= $items[$k]; } return $result; } } ?><?php
class wcNewsArticle { function getArticle($id) { } } ?><?php
class wcNews { static function addNews($params=array()) { $idLanguage = 'en'; $content = ''; $status = 2; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['content'] )) $content = $params['content']; if ( isset( $params['idLanguage'] )) $idlanguage = $params['idLanguage']; if ( isset( $params['status'] )) $status = $params['status']; } } if (strlen($content)>0) if (strlen($idLanguage)) { $db = wcCore::getDatabaseHandle(1); $db->query('START transaction'); $data = $db->querySelect('News', '1', "max(idNews)+1 id" ); $db->queryInsert('News', 'idNews, idLanguage, content,attrStatus' , sprintf( "%d, '%s','%s',%d", $data[0]['id'], $idlanguage, addslashes($content), $status ) ); $result = $db->query('commit'); return $result; } return 0; } static function getLatest($params=array()) { $limit = 10; if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; } } $db = wcCore::getDatabaseHandle(); if (isset($items)) return $items; return null; } static function updateNewsContent($id, $content) { $db = wcCore::getDatabaseHandle(); $content= addslashes( $content ); return $db->queryUpdate('News', sprintf("content = '$content'") , sprintf( "idNews = %d", $id ) ) ; } } ?><?php
class wcNode { public $currentNode; function __construct() { $this->initialize(); } static function getList($params=array()) { $limit = 10; $idNodeType = 0; $idlanguage = wcCore::getLanguage(); if (isset( $params) ) { if (is_array( $params )) { if ( isset( $params['limit'] )) $limit = $params['limit']; if ( isset( $params['idNodeType'] )) $idNodeType = $params['idNodeType']; if ( isset( $params['idlanguage'] )) $idlanguage = $params['idlanguage']; } } $db = wcCore::getDatabaseHandle(); $items = $db->querySelect('nodes', sprintf( "idNodeType = %d and attrPublished = 1 order by datePublishStart desc", $idNodeType ), "DATE_FORMAT(datePublishStart, '%Y-%m-%d %H:%i') timestamp, contentTitle" , $limit); return $items; } function initialize() { $this->currentNode['id']=0; $this->currentNode['idLanguage']=0; $this->currentNode['idMediaThumbnail']=0; $this->currentNode['idParent']=0; $this->currentNode['idNodeType']=0; $this->currentNode['dateCreation']=date("Y-m-d H:i:s"); $this->currentNode['dateLastUpdated']=date("Y-m-d H:i:s"); $this->currentNode['datePublishStart']=date("Y-m-d H:i:s"); $this->currentNode['datePublishEnd']=date("Y-m-d H:i:s",strtotime('+50 year')); $this->currentNode['idGUID']=wcCore::getGUID(); $this->currentNode['attrPublished']=0; $this->currentNode['contentTitle']=''; $this->currentNode['contentSummary']=''; $this->currentNode['contentBody']=''; $this->currentNode['contentTags']=''; } function loadbyGUID($id) { $db = wcCore::getDatabaseHandle(); $data = $db->querySelect('Nodes','idGUID=\''.$id.'\'','*'); if (count($data)>0) { $this->currentNode = $data[0]; $this->currentNode['contentTitle'] = wcCore::stringDecode( $this->currentNode['contentTitle']); $this->currentNode['contentSummary']= wcCore::stringDecode( $this->currentNode['contentSummary'] ); $this->currentNode['contentBody'] = wcCore::stringDecode( $this->currentNode['contentBody']); $this->currentNode['contentTags'] = wcCore::stringDecode( $this->currentNode['contentTags'] ); return true; } else { $this->initialize(); } return false; } function loadbyID($id) { $db = wcCore::getDatabaseHandle(); $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT); $data = $db->querySelect('Nodes','id='.$id,'*'); if (count($data)>0) { $this->currentNode = $data[0]; } else { $this->initialize(); } } function save() { $err=0; $db = wcCore::getDatabaseHandle(1); $db->connect(); $set = sprintf("dateLastUpdated=now(), contentTitle='%s', contentSummary='%s', contentBody='%s', contentTags='%s' ", wcCore::stringEncode( $this->currentNode['contentTitle']), wcCore::stringEncode($this->currentNode['contentSummary']) , wcCore::stringEncode($this->currentNode['contentBody']), wcCore::stringEncode($this->currentNode['contentTags'])); $where = sprintf("idGUID='%s'", $this->currentNode['idGUID'] ); $err= $db->queryUpdate('Nodes', $set, $where); return $err; } } ?>
<?php
class wcNodes { public $log; function __construct() { } function addNode($type='***') { $db = wcCore::getDatabaseHandle(); $db->queryInsert('Nodes','dateCreation,dateLastUpdated,datePublishStart,datePublishEnd,contentTitle,contentSummary,contentBody,contentTags', 'now(),now(),now(),date_add(now() interval 30 year), \'\', \'\', \'\', \'\' '); } function getNode() { } function } ?><?php
function getLatestCalendarEntries($params=array()) { global $ctrl; $sql=sprintf("SELECT v.* , n.title, n.summary,n.idFile FROM %sCalendar v JOIN %sNodes n ON v.idNode = n.idNode WHERE n.attrStatus =5 and n.codeLanguage='%s' ORDER BY dateStart LIMIT 0 , 10",SITE,SITE, $ctrl->Data['LANGUAGE']); $db=wcCore::getDatabaseHandle(); $data=$db->query($sql); $kdata=count($data); $result=array(); for ($k=0;$k<$kdata;$k++) { $link = sprintf("page-%d.html",$data[$k]['idNode']); $temp = date(date("m/d/Y", $data[$k]['dateStart'])); $t = utf8_encode(htmlspecialchars ($data[$k]['summary'])); $title = utf8_encode( htmlspecialchars( $data[$k]['title'])) ; $result[]= sprintf( '<span class="formatDate">%s</span> <span class="formatLink"><a href="%s" title="%s">%s</a></span><br /><span class="formatP">%s</span>', $temp, $link, $title , $title, $t ); } return $result; } function getLatestNews($params=array()) { global $ctrl; $sql=sprintf("SELECT n . * , f.idNode FROM %sNews n LEFT JOIN vscFiles f ON n.idFile = f.idFile where codeLanguage='%s' and attrStatus=1 order by attrWeight desc, datePublishStart desc limit 0,10",SITE,$ctrl->Data['LANGUAGE']); $db=wcCore::getDatabaseHandle(); $patht=wcCore::CacheFetch(SITE.'urlStaticTheme'); $path=wcCore::CacheFetch(SITE.'urlFiles'); $news=$db->query($sql); $knews=count($news); $result=array(); for ($k=0;$k<$knews;$k++) { $title=''; $link=''; $dlink=$news[$k]['link']; if (substr($dlink,0,1) == '[') { if ( substr($dlink,-1,1) == ']') { $dlinka=explode(':',substr($dlink,1,strlen($dlink)-2)); if (count($dlinka)==2) { switch($dlinka[0]) { case 'page': $link=sprintf('<a href="page-%s.html">lien</a>',$dlinka[1],utf8_encode($news[$k]['title']) ); break; default: break; } } } } $title=sprintf('<h4>%s</h4>',utf8_encode($news[$k]['title']) ); $idfile=$news[$k]['idFile']; $data=''; if ($idfile>0) $data.= sprintf('<img src="%s/%d/t-%d.jpg" alt="photo"/>',$path,$news[$k]['idNode'],$idfile); else $data.= sprintf('<img src="%snopic.jpg" alt="pas de photo" />',$patht); $data.=sprintf( '%s<p>%s</p><p>%s</p> ' ,$title, utf8_encode($news[$k]['content']), $link); $result[]=$data; } return $result; } function plugin__getChildNodes($params=array()) { $data=''; if (is_array($params)) { if (isset($params['lng'])) { $id = wcCore::varGet('id'); $lng = $params['lng']; $items=array(); $db=wcCore::getDatabaseHandle(); $sql=sprintf("SELECT * FROM tk_nodes_%s where idNodeParent=%d order by attrWeight, title", $lng, $id); $row=$db->query($sql); $krow=count($row); if ($krow>0) { $data.= '<ul>'; for ($k=0;$k<$krow;$k++) { $data.=sprintf("<li><a href=\"%s-%d.html\">%s</a></li>", $row[$k]['attrType'], $row[$k]['idNode'] , wcCore::stringHtmlEncode( $row[$k]['title']) ) ; } $data.= '</ul>'; } } } return $data; } function plugin__getFilesLastAdded($params=array()) { $data=''; $max=3; $path=wcCore::CacheFetch(SITE.'urlFiles'); if (is_array($params)) { if (isset($params['rel'])) $rel=sprintf(' rel="%s" ',$params['rel']); else $rel=''; if (isset($params['max'])) { $max=$params['max']; $db=wcCore::getDatabaseHandle(); $sql=sprintf("SELECT idFile,idNode,caption FROM %sFiles where fileExt='jpg' order by dateAdded desc limit 0,%d",SITE,$max); $row=$db->query($sql); $krow=count($row); for ($k=0;$k<$krow;$k++) { $large=sprintf('%s/%d/m-%d.jpg',$path,$row[$k]['idNode'],$row[$k]['idFile']); $thumb=sprintf('%s/%d/t-%d.jpg',$path,$row[$k]['idNode'],$row[$k]['idFile']); $data.=sprintf('<li><a href="%s" %s><img src="%s" alt=""/></a></li>',$large,$rel,$thumb); } } } return $data; } function plugin__snippet($params=array()) { $data=''; $max=3; $id=''; $width=800; $height=600; if (is_array($params)) { if (isset($params['rel'])) $rel=sprintf(' rel="%s" ',$params['rel']); else $rel=''; if (isset($params['w'])) $width=$params['w']; if (isset($params['h'])) $height=$params['h']; $data.=sprintf('<a href="snippet-%s.html" title="information" rel="clearbox(%s,,%s,,click)">%s</a> ',$params['id'],$width,$height,$params['text']); } return $data; } function plugin__relatedLinks($params=array()) { $data=''; $max=3; $id=wcCore::varGet('id'); if (is_array($params)) { } if ($id) { $db=wcCore::getDatabaseHandle(); $sql=sprintf("SELECT idChild,n.attrWeight,n.title, n.idPage FROM %sNodesRelation nr join %sNodes n on nr.idChild= n.idNode WHERE idParent=%s order by attrWeight desc",SITE,SITE,$id); $row=$db->query($sql); $krow=count($row); $data.='<ul id="relatedLinks">'; if ($krow>0) { $data.='<h2>Pages additionnelles</h2>'; for ($k=0;$k<$krow;$k++) $data.= sprintf('<li><a href="page-%s.html">%s</a></li>', $row[$k]['idChild'], $row[$k]['title']); } $data.='</ul>'; } return $data; } function plugin__showFilesFromArray($files,$options) { global $ctrl,$CONFIG; $data=''; $kpage=0; $kcol=7; $maxperpage=21; $krows=count($files); if ($krows>0) { $data.='<div id="gallery-thumbs"><ul><li>'; for ($k=0;$k<$krows;$k++) { if (($k%$kcol)==0) if ($k>0) $data.='</li><li>'; $large=sprintf('%sfiles/%d/m-%d.jpg',$CONFIG['pathSite'],$ctrl->info[0]['idNode'],$files[$k]['idFile']); $thumb=sprintf('%sfiles/%d/t-%d.jpg',$CONFIG['pathSite'],$ctrl->info[0]['idNode'],$files[$k]['idFile']); $c=utf8_encode($files[$k]['caption']); $data.=sprintf('<a href="%s" title="%s" %s><img src="%s" alt="%s"/></a>',$large,$c,$options,$thumb,$c); } $data.='</li></ul></div>'; } return $data; } ?><?php class wcSecurity { static function isAuthenticated() { if ( isset( $_SESSION['user']['id'] ) ) return true; return false; } static function requireAuthentication( $urlRedirect = 'login.php' ) { if ( wcSecurity::isAuthenticated() == false ) wcCore::redirect( $urlRedirect ); } static function authenticate($user,$password) { $db = wcCore::getDatabaseHandle(); $email = trim( wcCore::stringEncode( strip_tags ( stripslashes ( $user ) ) ) ); $db = wcCore::getDatabaseHandle(); $data = $db->querySelect('members', sprintf( "email = '%s' and hash1='%s' ", $email, sha1($password)), '*' , 1); $kdata = count($data); if ($kdata>0) { $_SESSION['user']['email'] = $email; $_SESSION['user']['nickname'] = $data[0]['nickname'] ; $_SESSION['user']['id'] = $data[0]['id'] ; $_SESSION['user']['firstname'] = $data[0]['firstname'] ; $_SESSION['user']['lastname'] = $data[0]['lastname'] ; $sql=sprintf("email = '%s' and hash1='%s' ", $email, sha1($password) ); $db->queryUpdate('Members', 'dateLastlogin=now()', $sql); } } static function logoff($urlRedirect='/') { unset( $_SESSION['user'] ); if ( isset( $_COOKIE[ session_name() ] ) ) setcookie(session_name(), '', time()-42000, '/'); wcCore::redirect( $urlRedirect ); } static function getUsername() { if ( isset( $_SESSION['user']['name'] ) ) return $_SESSION['user']['name']; return null; } } ?>
<?php
class wcXHtml2 implements iHtml { static function lineBreak() { return '<br />'; } static function encode($text,$symbol,$option='') { return "<{$symbol} {$option}>{$text}</{$symbol}>"; } static function encodeCode($text, $option='') { return "<pre $option>$text</pre>"; } static function encodeCss($filename) { return sprintf("<link type=\"text/css\" href=\"%s\" rel=\"stylesheet\" />\n", $filename); } static function encodeJs($filename) { return sprintf("<script type=\"text/javascript\" src=\"%s\"></script>\n", $filename); } static function encodeLink($text,$link,$option='') { return sprintf('<a href="%s" %s>%s</a>',$link,$option,$text); } static function encodeHeader($text,$size=1) { return "<h{$size}>{$text}</h{$size}>"; } static function encodeNavList($labelnav,$items,$optionsNAV,$optionsUL='',$optionsLI='') { $kc=count($items); $d="<nl {$optionsNAV}><label>{$labelnav}</label><ul {$optionsUL}>"; for ($k=0;$k<$kc;$k++) { $d.="<li {$optionsLI}>".$items[$k].'</li>'; } $d.='</ul></nl>'; return $d; } static function encodeList($items,$options='',$optionsli='') { $kc=count($items); $d="<ul {$options}>"; for ($k=0;$k<$kc;$k++) { $d.="<li {$optionsli}>".$items[$k].'</li>'; } $d.='</ul>'; return $d; } static function encodeFormTime($fieldname,$timestamp=0,$inc_min=1) { if ($timestamp==0) $timestamp=time(); $hour=date('H',$timestamp); $min=date('i',$timestamp); $code="<select name=\"{$fieldname}_hour\""; for ($k=1;$k<25;$k++) { if ($k==$hour) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; $code.="<select name=\"{$fieldname}_minute\""; for ($k=0;$k<60;$k+=$inc_min) { if ($k==$min) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; return $code; } static function encodeFormDate($fieldname,$timestamp=0,$inc_min=10) { if ($timestamp==0) $timestamp=time(); $year=date('Y',$timestamp); $month=date('n',$timestamp); $day=date('j',$timestamp); $code="<select name=\"{$fieldname}_month\""; for ($k=1;$k<13;$k++) { if ($k==$month) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; $code.="<select name=\"{$fieldname}_day\""; for ($k=1;$k<32;$k++) { if ($k==$day) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; $code.="<select name=\"{$fieldname}_year\""; for ($k=$year;$k<$year+$inc_min;$k++) { if ($k==$year) $code.="<option value=\"{$k}\" selected=\"selected\">{$k}</option>"; else $code.="<option value=\"{$k}\">{$k}</option>"; } $code.="</select>"; return $code; } static function encodeLabel($id,$text,$options='') { return sprintf("<label for=\"%s\" %s>%s</label>", $id, $options, $text); } static function encodeRadio($name,$value,$default='',$options='') { if ($value==$default) $checked=" checked=\"checked\""; else $checked=''; $code=sprintf("<input type=\"radio\" name=\"%s\" value=\"%s\" %s %s/>", $name, $value , $checked, $options); return $code; } static function encodeInputbox($name,$value,$options='') { $code=sprintf("<input type=\"text\" name=\"%s\" value=\"%s\" %s />", $name, $value, $options); return $code; } static function enforceUrl($link) { $link = trim(strtolower( $link )); if (substr($link,0,7) != 'http://' ) $link = 'http://'. $link; return $link; } static function enforceMailto($link) { $link = trim(strtolower($link)); if ( ($link == '-') || ($link=='')) { $link = ''; } else { if (substr($link,0,7) != 'mailto:' ) $link = 'mailto:'. $link; } return $link; } } ?>