first commit

This commit is contained in:
pakerpale
2020-06-10 06:21:34 +09:00
commit 20c9739ba9
1913 changed files with 266257 additions and 0 deletions

214
application/libraries/Auth.php Executable file
View File

@@ -0,0 +1,214 @@
<?php
use Hybridauth\Provider\Facebook;
use Hybridauth\Provider\Twitter;
use GuzzleHttp\Client;
use DirkGroenen\Pinterest\Pinterest;
class Auth
{
private $CI;
private $response;
private $isRequest;
public function __construct($params = [])
{
$this->CI = get_instance();
}
public function setIsRequest($isRequest)
{
$this->isRequest = $isRequest;
return $this;
}
public function getResponse()
{
return $this->response;
}
public function auth($name = '')
{
$this->CI->config->load('social');
$method = $name ? $name : $this->CI->input->post('auth');
$method = $method ? $method : 'crossmap';
$this->$method();
}
private function crossmap()
{
$this->response = ['code' => 404];
$query = $this->CI->db->from('cm_user')
->where('userName', $this->CI->input->post('userName'))
->where('password', md5($this->CI->input->post('userPasswd')))->get();
if ($query->num_rows() == 1) {
$this->CI->load->library('session');
$user = [
'userName' => $this->CI->input->post('userName'),
'userID' => $query->row()->userID
];
$this->CI->session->set_userdata('auth', json_encode($user));
$this->response = [
'code' => 200
];
}else if($query->num_rows() > 1){
log_message('debug', 'duplicated users');
$this->response = [
'code' => 400
];
}else {
$this->response = [
'code' => 404
];
}
}
private function kakao()
{
if ($this->isRequest) {
redirect($this->CI->config->item('kakao_base_uri')
. '/oauth/authorize?client_id='
. $this->CI->config->item('kakao_app_key')
. '&redirect_uri='
. $this->CI->config->item('kakao_redirect_uri')
. '&response_type=code');
} else {
$code = $this->CI->input->get('code');
$client = new Client();
try {
$response = $client->request('POST', $this->CI->config->item('kakao_base_uri') . '/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => $this->CI->config->item('kakao_app_key'),
'redirect_uri' => $this->CI->config->item('kakao_redirect_uri'),
'code' => $code
]
]);
$response = json_decode($response->getBody());
$response = $client->request('POST', $this->CI->config->item('kakao_api_base_uri') . '/v2/user/me', [
'headers' => [
'Authorization' => 'Bearer ' . $response->access_token
],
'form_params' => ['property_keys' => ['kakao_account.email', 'kakao_account.age_range', 'kakao_account.birthday', 'kakao_account.gender']]
]);
$userProfile = $response->getBody();
log_mesage('info', $userProfile);
$this->connected('kakao', $userProfile);
} catch (GuzzleHttp\Exception\ClientException $e) {
log_message('debug', 'Kakao SNS login :: Oops, we ran into an issue! ClientException');
} catch (GuzzleHttp\Exception\RequestException $e) {
log_message('debug', 'Kakao SNS login :: Oops, we ran into an issue! RequestException');
}
}
}
private function facebook()
{
$config = [
'callback' => $this->CI->config->item('facebook_redirect_uri'),
'keys' => [
'id' => $this->CI->config->item('facebook_app_key'), //Required: your Facebook application id
'secret' => $this->CI->config->item('facebook_app_secret') //Required: your Facebook application secret
]
];
if ($this->isRequest) {
try {
$adapter = new Facebook($config);
$adapter->authenticate();
$isConnected = $adapter->isConnected();
$userProfile = $adapter->getUserProfile();
//Disconnect the adapter
$adapter->disconnect();
log_mesage('info', print_r($userProfile, ture));
$this->connected('facebook', $userProfile);
} catch (\Exception $e) {
echo 'Oops, we ran into an issue! ' . $e->getMessage();
}
}
}
private function twitter()
{
$config = [
'callback' => 'https://local.cmap.co.kr/oauth/twitter',
'keys' => [
'key' => $this->CI->config->item('twitter_app_key'),
'secret' => $this->CI->config->item('twitter_app_secret')
]
];
try {
$adapter = new Twitter($config);
$adapter->authenticate();
$accessToken = $adapter->getAccessToken();
$userProfile = $adapter->getUserProfile();
$adapter->disconnect();
// $apiResponse = $twitter->apiRequest('account/settings.json');
log_mesage('info', print_r($userProfile, ture));
$this->connected('twitter', $userProfile);
} catch (\Exception $e) {
log_message('debug', 'Twitter SNS login :: Oops, we ran into an issue!');
log_message('debug', $e->getMessage());
}
}
private function pinterest()
{
if ($this->isRequest) {
try {
$pinterest = new Pinterest($this->CI->config->item('pinterest_app_key'), $this->CI->config->item('pinterest_app_secret'));
$loginurl = $pinterest->auth->getLoginUrl($this->CI->config->item('pinterest_redirect_uri'), array('read_public'));
redirect($loginurl);
} catch (\Exception $e) {
log_message('debug', 'Pinterest SNS login :: Oops, we ran into an issue!');
log_message('debug', $e->getMessage());
}
} else {
$userProfile = '';
$this->connected('pinterest', $userProfile);
}
}
private function naver()
{
if ($this->isRequest) {
$url = 'https://nid.naver.com/oauth2.0/authorize?response_type=code&client_id='
. $this->CI->config->item('naver_app_key')
. '&redirect_uri='
. $this->CI->config->item('naver_redirect_uri')
. '&state='
. $this->CI->config->item('naver_app_state');
redirect($url);
}
}
private function connected($name, $userProfile)
{
$this->CI->library('session');
$username = $this->register($name, $userProfile);
if ($this->login($username, '')) { }
}
private function register($name, $userProfile)
{
return 'username';
}
public function login($username, $password)
{
$query = $this->db->where("userName", $username)->where("password", $password)->get("cm_user");
if ($query->num_rows() > 0) {
foreach ($query->result() as $rows) {
$data = array(
'userID' => $rows->userID,
'userName' => $rows->userName,
'logged_in' => true,
);
$this->session->set_userdata($data);
return true;
}
} else {
return false;
}
}
}

127
application/libraries/Cacher.php Executable file
View File

@@ -0,0 +1,127 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
use PHPHtmlParser\Dom;
class Cacher
{
private $CI;
public function __construct($params = [])
{
$this->CI = &get_instance();
$this->cache = &$this->CI->cache;
}
public function melon()
{
$hostUrl = 'https://www.melon.com';
$path = '/genre/song_list.htm?gnrCode=GN2100';
return $this->get($hostUrl . $path, '.service_list_song table tbody tr', 'melon', function ($s) {
preg_match_all('/\d+/', $s->find('.wrap a')[0]->getAttribute('href'), $matches);
return [
'img' => $s->find('img')->getAttribute('src'),
'url' => 'https://www.melon.com/album/detail.htm?albumId=' . $matches[0][0],
'title' => $s->find('.wrap_song_info a')->innerHtml,
'album' => $s->find('.wrap_song_info .rank02 a')->innerHtml,
];
});
}
public function chtoday($section, $article = null)
{
if ($article) {
return $this->get($article, 'article', null, function ($a) {
return [
'subtitle' => '',
'article' => $a->find('.article-body')->innerHtml
];
});
} else {
return $this->get('http://www.christiantoday.co.kr/' . $section, '.section-2 article', null, function ($a) {
return [
'img' => $a->find('figure img')->getAttribute('src'),
'url' => 'http://www.christiantoday.co.kr' . parse_url($a->find('a')[0]->getAttribute('href'))['path'],
'title' => $a->find('h4 a')->innerHtml,
'postExcerpt' => $a->find('summary')->innerHtml,
];
});
}
}
public function chdaily($section, $article = null)
{
if ($article) {
return $this->get($article, 'article', null, function ($a) {
return [
'subtitle' => '',
'article' => $a->find('section')->innerHtml
];
});
} else {
return $this->get('http://www.christianitydaily.com/' . $section, '.news-list-section article', null, function ($a) {
return [
'img' => $a->find('figure img')->getAttribute('src'),
'url' => 'http://www.christianitydaily.com' . parse_url($a->find('a')[0]->getAttribute('href'))['path'],
'title' => $a->find('h4 a')->innerHtml,
'postExcerpt' => $a->find('p')->innerHtml,
];
});
}
}
public function chdailykr($section, $article = null)
{
if ($article) {
return $this->get($article, 'article', null, function ($a) {
return [
'subtitle' => count($a->find('.article-sttl')) ? $a->find('.article-sttl')->innerHtml : '',
'article' => $a->find('.article-txt')->innerHtml
];
});
} else {
return $this->get('http://www.christiandaily.co.kr/' . $section, '.bk-listbasic1 li', null, function ($a) {
return [
'img' => $a->find('img')->getAttribute('src'),
'url' => 'http://www.christiandaily.co.kr' . parse_url($a->find('a')[0]->getAttribute('href'))['path'],
'title' => $a->find('h3')->innerHtml,
'postExcerpt' => $a->find('p')->innerHtml,
];
});
}
}
/**
* Get remote HTML, parsing and save it in cache file.
*
* @param string $url
* @param string $selecor
* @param string $cacheName
* @param callable $fn
* @return void
*/
private function get($url, $selecor, $cacheName, $fn)
{
if (is_null($cacheName) || !$data = $this->cache->get($cacheName)) {
$dom = new Dom;
$dom->loadFromUrl($url);
$tags = $dom->find($selecor);
if ($tags) {
$data = [];
foreach ($tags as $t) {
try {
array_push($data, $fn($t));
} catch (Exception $e) {
continue;
}
}
if (!is_null($cacheName) && count($data) > 5) {
$this->cache->save($cacheName, $data, 60 * 60);
}
}
}
return $data;
}
}

View File

@@ -0,0 +1,23 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation {
public function is_unique($str, $field)
{
if (substr_count($field, '.')==3)
{
list($table,$field,$id_field,$id_val) = explode('.', $field);
$query = $this->CI->db->limit(1)->where($field,$str)->where($id_field.' != ',$id_val)->get($table);
} else {
list($table, $field)=explode('.', $field);
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
}
return $query->num_rows() === 0;
}
}
// END MY Form Validation Class
/* End of file MY_Form_validation.php */
/* Location: ./application/libraries/MY_Form_validation.php */

View File

@@ -0,0 +1,254 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Native Session using Memcached
*
* Another session library extension that uses Native PHP session
* mechanism instead of the original Codeigniter cookie-based way.
* It also takes memcached as the session data storage, which will
* boost the performance of your app.
*
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author Saturn <yangg.hu@gmail.com>
* @license The MIT license
* @link https://github.com/cnsaturn/codeigniter-my-session
*/
// Set session configs...
new Cache_Session_Handler;
session_start();
Class MY_Session Extends CI_Session
{
/**
* Session Constructor
*
* The constructor runs the session routines automatically
* whenever the class is instantiated.
*/
public function __construct($params = array())
{
parent::__construct($params);
}
// --------------------------------------------------------------------
/**
* Fetch the current session data if it exists
*
* @access public
* @return bool
*/
public function sess_read()
{
// Fetch the cookie
$session = $_SESSION;
// Is the session data we unserialized an array with the correct format?
if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity']))
{
log_message('debug', 'A session was not found.');
$this->sess_destroy(FALSE);
return FALSE;
}
// Is the session current?
if (($session['last_activity'] + $this->sess_expiration) < $this->now)
{
$this->sess_destroy(FALSE);
return FALSE;
}
// Does the IP Match?
if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address())
{
$this->sess_destroy(FALSE);
return FALSE;
}
// Does the User Agent Match?
if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120)))
{
$this->sess_destroy(FALSE);
return FALSE;
}
// Session is valid!
$this->userdata = $session;
unset($session);
return TRUE;
}
// --------------------------------------------------------------------
/**
* Write the session data
*
* @access public
* @return void
*/
public function sess_write()
{
// set the custom userdata, the session data we will set in a second
$_SESSION = array();
foreach($this->userdata as $key => $val)
{
$_SESSION[$key] = $val;
}
}
// --------------------------------------------------------------------
/**
* Create a new session
*
* @access public
* @return void
*/
public function sess_create()
{
if(session_id() == '')
{
session_start();
}
$_SESSION['session_id'] = session_id();
$_SESSION['ip_address'] = $this->CI->input->ip_address();
$_SESSION['user_agent'] = substr($this->CI->input->user_agent(), 0, 120);
$_SESSION['last_activity'] = $this->now;
$this->userdata = $_SESSION;
}
// --------------------------------------------------------------------
/**
* Update an existing session
*
* @access public
* @return void
*/
public function sess_update()
{
// We only update the session every five minutes by default
if(($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
{
return;
}
// Regenerate session id
session_regenerate_id();
// Update the session data in the session data array
$this->userdata['session_id'] = session_id();
$this->userdata['last_activity'] = $this->now;
}
// --------------------------------------------------------------------
/**
* Destroy the current session
*
* @access public
* @return void
*/
public function sess_destroy($destroy = TRUE)
{
session_unset();
session_regenerate_id();
if($destroy)
{
session_destroy();
}
}
// --------------------------------------------------------------------
/**
* Does nothing for native sessions
*
* @access public
* @return void
*/
public function _sess_gc(){}
}
// Customize the PHP Session handler
// @see http://php.net/manual/en/function.session-set-save-handler.php
class Cache_Session_Handler
{
private $_lifetime = 0;
private $_CI;
public function __construct()
{
session_name(config_item('sess_cookie_name'));
session_set_save_handler(
array($this, "open"),
array($this, "close"),
array($this, "read"),
array($this, "write"),
array($this, "destroy"),
array($this, "gc")
);
// Ref the 'CI' super global object
$this->_CI = & get_instance();
if( ! $this->_CI->load->is_loaded('cache'))
{
// Make sure your 2.0+ CI Cache driver library is loaded
// and set as the primary cache solution
$this->_CI->load->driver(
'cache',
array('adapter' => 'memcached', 'backup' => 'file'
));
}
}
public function open()
{
$this->_lifetime = ini_get('session.gc_maxlifetime');
if($this->_lifetime <= config_item('sess_expiration'))
{
$this->_lifetime = config_item('sess_expiration');
}
return TRUE;
}
public function read($id)
{
return $this->_CI->cache->get("sess_{$id}");
}
public function write($id, $data)
{
return $this->_CI->cache->replace("sess_{$id}", $data, $this->_lifetime);
}
public function destroy($id)
{
return $this->_CI->cache->delete("sess_{$id}");
}
public function gc()
{
return TRUE;
}
public function close()
{
return TRUE;
}
public function __destruct()
{
session_write_close();
}
}

View File

@@ -0,0 +1,212 @@
<?php
class MobileCertification
{
private $CI;
public function __construct($params = [])
{
$this->CI = &get_instance();
$this->input = &$this->CI->input;
$this->output = &$this->CI->output;
}
public function mobile_auth_callback()
{
# request
$rec_cert = trim($this->input->get_post('rec_cert', TRUE));
$certNum = trim($this->input->get_post('certNum', TRUE));
$SES_MEMBER_ID = $this->session->userdata('C_Member_Id');
if (strlen($rec_cert) == 0 || strlen($certNum) == 0) {
gf_alert('본인인증에 실패했습니다.', 'self_close');
exit;
}
$iv = $certNum;
//암호화모듈 호출
if (extension_loaded('ICERTSecu')) {
//01.인증결과 1차 복호화
$rec_cert = ICertSeed(2, 0, $iv, $rec_cert);
//02.복호화 데이터 Split (rec_cert 1차암호화데이터 / 위변조 검증값 / 암복화확장변수)
$decStr_Split = explode("/", $rec_cert);
$encPara = $decStr_Split[0]; //rec_cert 1차 암호화데이터
$encMsg = $decStr_Split[1]; //위변조 검증값
//03.인증결과 2차 복호화
$rec_cert = ICertSeed(2, 0, $iv, $encPara);
//04. 복호화 된 결과자료 "/"로 Split 하기
$decStr_Split = explode("/", $rec_cert);
$certNum = $decStr_Split[0];
$date = $decStr_Split[1];
$CI = $decStr_Split[2];
$phoneNo = $decStr_Split[3];
$phoneCorp = $decStr_Split[4];
$birthDay = $decStr_Split[5];
$gender = $decStr_Split[6];
$nation = $decStr_Split[7];
$name = $decStr_Split[8];
$result = $decStr_Split[9];
$certMet = $decStr_Split[10];
$ip = $decStr_Split[11];
$M_name = $decStr_Split[12];
$M_birthDay = $decStr_Split[13];
$M_Gender = $decStr_Split[14];
$M_nation = $decStr_Split[15];
$plusInfo = $decStr_Split[16];
$DI = $decStr_Split[17];
//05. CI,DI 복호화
if (strlen($CI) > 0) $CI = ICertSeed(2, 0, $iv, $CI);
if (strlen($DI) > 0) $DI = ICertSeed(2, 0, $iv, $DI);
function paramChk($pattern, $param)
{
$result = preg_match($pattern, $param);
return $result;
}
// 요청번호 (최대 40byte까지 유효)
if (strlen($certNum) > 40 || strlen($certNum) == 0) {
gf_alert('요청번호 비정상', 'self_close');
exit;
}
// 요청일시 (숫자 14자리만 유효)
$patn = "/^[0-9]*$/";
if (strlen($date) != 14 || paramchk($patn, $date) == 0) {
gf_alert('휴대폰번호 비정상', 'self_close');
exit;
}
// 휴대폰번호 (값이 있는 경우에는 숫자 10 또는 11자리까지만 유효)
$patn = "/^[0-9]*$/";
if ((strlen($phoneNo) != 10 && strlen($phoneNo) != 11) || paramChk($patn, $phoneNo) == 0) {
gf_alert('휴대폰번호 비정상', 'self_close');
exit;
}
} else {
gf_alert('본인인증에 실패했습니다.', 'self_close');
exit;
}
$this->load->model('web/m_member');
if ($plusInfo == 'member_join1') {
$result = $this->m_member->member_where_mobile_CI_select($CI);
if (count($result) > 0) {
gf_alert('이미 가입되어있는 번호입니다.', 'self_close');
exit;
}
} else if ($plusInfo == 'member_join2') { // 14세 미만
$result = $this->m_member->member_where_parent_CI_select($CI);
if (count($result) > 0) {
gf_alert('이미 가입되어있는 부모님 번호입니다.', 'self_close');
exit;
}
} else if ($plusInfo == 'email_check') {
$req_data = array();
$req_data['member_id'] = $SES_MEMBER_ID;
$req_data['CI'] = $CI;
$count = $this->m_member->member_where_mobile_CI_member_id_count($req_data);
if ($count == 0) {
gf_alert('본인명의의 휴대폰 번호가 아닙니다.', 'self_close');
exit;
}
} else if ($plusInfo == 'member_edit') {
$req_data = array();
$req_data['member_id'] = $SES_MEMBER_ID;
$req_data['CI'] = $CI;
$count = $this->m_member->member_where_mobile_CI_member_id_count($req_data);
if ($count == 0) {
gf_alert('본인명의의 휴대폰 번호로만 변경가능합니다.', 'self_close');
exit;
}
}
$name = iconv("EUC-KR", "UTF-8", $name);
$return_data = array();
$return_data['CI'] = $CI;
$return_data['type'] = $plusInfo;
$return_data['name'] = $name;
$return_data['phone'] = $phoneNo;
# view
return $this->load->view('/web/comm/kmc_mobile_auth_fin', $return_data);
}
public function mobile_auth_encode()
{
# request
$mobile = trim($this->input->get_post('mobile', TRUE));
$type = trim($this->input->get_post('type', TRUE));
$mobile = str_replace('-', '', $mobile);
$cur_time = date('YmdHis');
$rand_no = rand(100000, 999999);
//요청 번호 생성
$cert_num = $cur_time . $rand_no;
$cpId = 'CRMM1001'; // 회원사ID
$urlCode = '003001'; // URL 코드
$certNum = $cert_num; // 요청번호
$date = $cur_time; // 요청일시
$certMet = 'M'; // 본인인증방법
$birthDay = ''; // 생년월일
$gender = ''; // 성별
$name = ''; // 성명
$phoneNo = $mobile; // 휴대폰번호
$phoneCorp = ''; // 이동통신사
$nation = ''; // 내외국인 구분
$plusInfo = $type; // 추가DATA정보
$extendVar = "0000000000000000"; // 확장변수
$name = str_replace(" ", "+", $name); //성명에 space가 들어가는 경우 "+"로 치환하여 암호화 처리
// 02. tr_cert 데이터변수 조합 (서버로 전송할 데이터 "/"로 조합)
$tr_cert = $cpId . "/" . $urlCode . "/" . $certNum . "/" . $date . "/" . $certMet . "/" . $birthDay . "/" . $gender . "/" . $name . "/" . $phoneNo . "/" . $phoneCorp . "/" . $nation . "/" . $plusInfo . "/" . $extendVar;
//암호화모듈 호출
$enc_tr_cert = '';
if (extension_loaded('ICERTSecu')) {
log_message('info', '========== ICERTSecu exteision loaded =========');
//03. 1차암호화
$enc_tr_cert = ICertSeed(1, 0, '', $tr_cert);
//04. 변조검증값 생성
$enc_tr_cert_hash = ICertHMac($enc_tr_cert);
//05. 2차암호화
$enc_tr_cert = $enc_tr_cert . "/" . $enc_tr_cert_hash . "/" . "0000000000000000";
$enc_tr_cert = ICertSeed(1, 0, '', $enc_tr_cert);
}else {
log_message('info', '========== ICERTSecu exteision not loaded =========');
}
if ($enc_tr_cert == '') {
$return_data['result'] = array('code' => '9999');
} else {
$return_data['result'] = array('code' => '0000', 'data' => $enc_tr_cert);
}
# view
$this->output
->set_status_header(200)
->set_content_type('application/json')
->set_output(json_encode($return_data));
}
}

View File

@@ -0,0 +1,253 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* This class is written based entirely on the work found below
* www.techbytes.co.in/blogs/2006/01/15/consuming-rss-with-php-the-simple-way/
* All credit should be given to the original author
*
* Example:
$this->load->library('rssparser');
$this->rssparser->set_feed_url('http://example.com/feed');
$this->rssparser->set_cache_life(30);
$rss = $this->rssparser->getFeed(6); // Get six items from the feed
// Using a callback function to parse addictional XML fields
$this->load->library('rssparser', array($this, 'parseFile')); // parseFile method of current class
function parseFile($data, $item)
{
$data['summary'] = (string)$item->summary;
return $data;
}
*/
class RSSParser {
public $feed_uri = NULL; // Feed URI
public $data = FALSE; // Associative array containing all the feed items
public $channel_data = array(); // Store RSS Channel Data in an array
public $feed_unavailable = NULL; // Boolean variable which indicates whether an RSS feed was unavailable
public $cache_life = 0; // Cache lifetime
public $cache_dir = './hoosk/hoosk0/cache/'; // Cache directory
public $write_cache_flag = FALSE; // Flag to write to cache
public $callback = FALSE; // Callback to read custom data
function __construct($callback = FALSE)
{
if ($callback)
{
$this->callback = $callback;
}
}
// --------------------------------------------------------------------
function get_http_response_code($url) {
$headers = get_headers($url);
return substr($headers[0], 9, 3);
}
function parse()
{
// Are we caching?
if ($this->cache_life != 0)
{
$filename = $this->cache_dir.'rss_Parse_'.md5($this->feed_uri);
// Is there a cache file ?
if (file_exists($filename))
{
// Has it expired?
$timedif = (time() - filemtime($filename));
if ($timedif < ( $this->cache_life * 60))
{
$rawFeed = file_get_contents($filename);
}
else
{
// So raise the falg
$this->write_cache_flag = true;
}
}
else
{
// Raise the flag to write the cache
$this->write_cache_flag = true;
}
}
// Reset
$this->data = array();
$this->channel_data = array();
// Parse the document
if (!isset($rawFeed))
{
if($this->get_http_response_code($this->feed_uri) != "200"){
return false;
}else{
$rawFeed = file_get_contents($this->feed_uri);
}
}
$xml = new SimpleXmlElement($rawFeed, 0, false);
if ($xml->channel)
{
// Assign the channel data
$this->channel_data['title'] = $xml->channel->title;
$this->channel_data['description'] = $xml->channel->description;
// Build the item array
foreach ($xml->channel->item as $item)
{
$data = array();
$data['title'] = (string)$item->title;
$data['description'] = (string)$item->description;
$data['pubDate'] = (string)$item->pubDate;
$data['link'] = (string)$item->link;
$dc = $item->children('http://purl.org/dc/elements/1.1/');
$data['author'] = (string)$dc->creator;
if ($this->callback)
{
$data = call_user_func($this->callback, $data, $item);
}
$this->data[] = $data;
}
}
else
{
// Assign the channel data
$this->channel_data['title'] = $xml->title;
$this->channel_data['description'] = $xml->subtitle;
// Build the item array
foreach ($xml->entry as $item)
{
$data = array();
$data['id'] = (string)$item->id;
$data['title'] = (string)$item->title;
$data['description'] = (string)$item->content;
$data['pubDate'] = (string)$item->published;
$data['link'] = (string)$item->link['href'];
$dc = $item->children('http://purl.org/dc/elements/1.1/');
$data['author'] = (string)$dc->creator;
if ($this->callback)
{
$data = call_user_func($this->callback, $data, $item);
}
$this->data[] = $data;
}
}
// Do we need to write the cache file?
if ($this->write_cache_flag)
{
if (!$fp = @fopen($filename, 'wb'))
{
echo "RSSParser error";
log_message('error', "Unable to write cache file: ".$filename);
return;
}
flock($fp, LOCK_EX);
fwrite($fp, $rawFeed);
flock($fp, LOCK_UN);
fclose($fp);
}
return TRUE;
}
// --------------------------------------------------------------------
function set_cache_life($period = NULL)
{
$this->cache_life = $period;
return $this;
}
// --------------------------------------------------------------------
function set_feed_url($url = NULL)
{
$this->feed_uri = $url;
return $this;
}
// --------------------------------------------------------------------
/* Return the feeds one at a time: when there are no more feeds return false
* @param No of items to return from the feed
* @return Associative array of items
*/
function getFeed($num)
{
$this->parse();
$c = 0;
$return = array();
foreach ($this->data AS $item)
{
$return[] = $item;
$c++;
if ($c == $num)
{
break;
}
}
return $return;
}
// --------------------------------------------------------------------
/* Return channel data for the feed */
function & getChannelData()
{
$flag = false;
if (!empty($this->channel_data))
{
return $this->channel_data;
}
else
{
return $flag;
}
}
// --------------------------------------------------------------------
/* Were we unable to retreive the feeds ? */
function errorInResponse()
{
return $this->feed_unavailable;
}
// --------------------------------------------------------------------
/* Initialize the feed data */
function clear()
{
$this->feed_uri = NULL;
$this->data = FALSE;
$this->channel_data = array();
$this->cache_life = 0;
$this->callback = FALSE;
return $this;
}
}
/* End of file RSSParser.php */
/* Location: ./application/libraries/RSSParser.php */

View File

@@ -0,0 +1,50 @@
<?php
class Search
{
private $CI;
public function __construct($params = [])
{
$this->CI = &get_instance();
}
public function searchByPostTitle($postTitle, $limit, $exception = [], $activeQ = false)
{
$titleSegments = [];
foreach (explode(' ', $postTitle) as $k => $t) {
if (mb_strlen($t, 'utf-8') > ($activeQ ? 1 : 3)) array_push($titleSegments, $this->clean($t));
}
$this->CI->db
->join('cm_post_tag t', 'p.postID=t.postID', 'left')
->from('cm_post p');
foreach ($titleSegments as $k => $t) {
!$k ? $this->CI->db->like('postTitle', $t) : $this->CI->db->or_like('postTitle', $t);
$this->CI->db->or_like('tag', $t);
}
if ($activeQ) {
return $this->CI->db;
} else {
$rows = $this->CI->db->limit($limit + count($exception))
->get()->result();
return array_filter($rows, function ($row) use ($exception) {
if ($exception && count($exception)) {
$duplicated = false;
foreach ($exception as $ex) {
$duplicated = $row->postID == $ex;
}
return !$duplicated;
}
return true;
});
}
}
private function clean($string)
{
return trim(preg_replace('/[^\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}0-9a-zA-Z\s]/u', "", $string));
}
}

26
application/libraries/Sioen.php Executable file
View File

@@ -0,0 +1,26 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sioen {
public function __construct()
{
require_once APPPATH.'third_party/Michelf/Markdown.inc.php';
require_once APPPATH.'third_party/Sioen/Converter.php';
require_once APPPATH.'third_party/Sioen/ToHtmlContext.php';
require_once APPPATH.'third_party/Sioen/ToJsonContext.php';
require_once APPPATH.'third_party/Sioen/Types/ConverterInterface.php';
require_once APPPATH.'third_party/Sioen/Types/BaseConverter.php';
require_once APPPATH.'third_party/Sioen/Types/BlockquoteConverter.php';
require_once APPPATH.'third_party/Sioen/Types/HeadingConverter.php';
require_once APPPATH.'third_party/Sioen/Types/IframeConverter.php';
require_once APPPATH.'third_party/Sioen/Types/ImageConverter.php';
require_once APPPATH.'third_party/Sioen/Types/ListConverter.php';
require_once APPPATH.'third_party/Sioen/Types/ParagraphConverter.php';
require_once APPPATH.'third_party/Sioen/Types/ColumnsConverter.php';
require_once APPPATH.'third_party/Sioen/Types/ButtonConverter.php';
require_once APPPATH.'third_party/Sioen/Types/AccordionConverter.php';
require_once APPPATH.'third_party/Sioen/Types/ImageExtendedConverter.php';
require_once APPPATH.'third_party/Sioen/Types/IframeExtendedConverter.php';
}
}

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>