/** * Implements functionThatShouldNotShowUp(); */ function test_function() { // Test a normal function should work properly. normalFunction('test data'); // Test exceptions: start simple - call a function that doesn't exist with a space in between the function name // and "(". functionThatDoesNotExist('param1', 'param2'); functionThatDoesNotExist2('param1', 'param2'); // Call a function within a function. abc(def('abc')); // Use a constant, that can be misconstrued as a function potentially. $test_result = 3 - TEST_CONST; // Test referring to an object. $testJsonResponse = (object) array('data' => 'abc'); $testJsonResponse->data = 'abc'; $result = drupal_json_decode($json->data); // Create a reference to returned value $a =& reference_returner_function(); // Static method call StaticTestClass::staticFunctionCall(); // Method call $someInstance->someMetod(); // Creating a class $a = new stdClass(); }
/** * function create() * * @param $back_url the url where the function retutn at the end of the operation * @return nothing */ function create($idTest, $back_test) { if (!sql_query("\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_testquest \r\n\t\t( idTest, type_quest, title_quest, sequence, page, difficult ) VALUES \r\n\t\t( \t'" . $idTest . "', \r\n\t\t\t'" . $this->getQuestionType() . "', \r\n\t\t\t'<span class=\"text_bold\">" . Lang::t('_QUEST_BREAK_PAGE') . "</span>',\r\n\t\t\t'" . $this->_getNextSequence($idTest) . "', \r\n\t\t\t'" . $this->_getPageNumber($idTest) . "',\r\n\t\t\t'0') ")) { errorCommunication(def('_OPERATION_FAILURE') . getBackUi(Util::str_replace_once('&', '&', $back_test), Lang::t('_BACK'))); } Util::jump_to('' . $back_test); }
public function run() { try { $this->req('ident'); } catch (\System\Error\Argument $e) { $this->req('id'); } def($this->template, 'system/text/show'); def($this->show_heading, true); $conds = array(); if (isset($ident)) { $conds['ident'] = $ident; } else { $conds['id_system_text'] = $id; } if ($text = \System\Text::get_first($conds)->fetch()) { $this->partial($template, array("text" => $text, "show_heading" => $show_heading)); } else { if (cfg('dev', 'debug', 'backend')) { throw new \System\Error\Config('Text was not found', isset($ident) ? $ident : $id); } else { throw new \System\Error\NotFound(); } } }
function __construct ($name) { $apps = Frix::config('APPS'); // Check if app is installed or throw an exception if (!array_key_exists($name, $apps)) { throw new AppException(sprintf('Application "%s" not installed!', $name)); } // Set name $this->name = $name; // Use the class-name to create verbose_name if it's not set $v_name = preg_replace('/App$/', '', get_class($this)); def($this->verbose_name, $v_name); // Configure the application path // $this->path = join_path(array(Frix::config('ROOT'), $apps[$name])); $this->path = $apps[$name]; // Setup models and views path def($this->views_path, join_path(array($this->path, 'views.php'))); def($this->models_path, join_path(array($this->path, 'models'))); }
/** * function create() * * @param $back_url the url where the function retutn at the end of the operation * @return nothing */ function create($id_poll, $back_poll) { if (!sql_query("\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_pollquest \r\n\t\t( id_poll, type_quest, title_quest, sequence, page ) VALUES \r\n\t\t( \t'" . $id_poll . "', \r\n\t\t\t'" . $this->getQuestionType() . "', \r\n\t\t\t'<span class=\"text_bold\">" . Lang::t('_QUEST_BREAK_PAGE') . "</span>',\r\n\t\t\t'" . $this->_getNextSequence($id_poll) . "', \r\n\t\t\t'" . $this->_getPageNumber($id_poll) . "' ) ")) { errorCommunication(def('_POLL_ERR_INS_QUEST') . getBackUi(Util::str_replace_once('&', '&', $back_poll), Lang::t('_BACK'))); } Util::jump_to('' . $back_poll); }
protected function __new__($email = null, $password = null) { $this->email = def("arbo.service.GoogleAPI@email", $email); $password = def("arbo.service.GoogleAPI@password", $password); $this->vars("Email", $this->email); $this->vars("Passwd", $password); $this->vars("accountType", "GOOGLE"); $this->vars("source", "Google-Contact-Lister"); $this->vars("service", "cl"); $this->do_post("https://www.google.com/accounts/ClientLogin"); foreach (explode("\n", $this->body()) as $line) { if (strpos($line, "SID=") === 0) { $this->sid = trim(substr($line, 4)); } else { if (strpos($line, "LSID=") === 0) { $this->lsid = trim(substr($line, 5)); } else { if (strpos($line, "Auth=") === 0) { $this->auth = trim(substr($line, 5)); } } } } if (empty($this->auth)) { throw new Exception("auth"); } }
/** * Execute this module * * @return void */ public function exec() { if (!$this->accessible()) { throw new \System\Error\Permissions(sprintf('Cannot access module "%s". Permission denied.', $this->get_path())); } $locals =& $this->opts; def($locals['per_page'], 20); def($locals['page'], intval($this->request->get('page'))); $locals['per_page'] = intval($locals['per_page']); $propagated = array(); if (count($this->parents)) { $propagated = $this->dbus->get_data($this->parents); $locals = array_merge($locals, $propagated); } foreach (self::$array_forced_locals as $var) { if (isset($locals[$var]) && !is_array($locals[$var])) { throw new \System\Error\Argument(sprintf('Local variable "$%s" must be an array for module "%s"', $var, $this->get_path())); } } foreach ($locals as $key => &$val) { if (is_string($val) && preg_match("/^\\#\\{[0-9]{1,3}\\}\$/", $val)) { $temp = $this->response->request->args; $temp_key = intval(substr($val, 2)); if (isset($temp[$temp_key])) { $locals[$key] = $temp[$temp_key]; } else { throw new \System\Error\Argument(sprintf('Path variable #{%s} was not found.', $temp_key)); } } } $this->opts = $locals; $this->run(); return $this; }
protected function __new__($user = null, $password = null) { $this->id = isset($user) ? $user : def("arbo.service.WassrAPI@user"); $password = isset($password) ? $password : def("arbo.service.WassrAPI@password"); if (isset($this->id)) { $this->auth($this->id, $password); } }
public static function from_def($parent, $name, array $def) { $def['parent'] = $parent; $def['name'] = $name; def($def['is_master'], false); if (strpos($def['model'], '\\') === 0) { $def['model'] = substr($def['model'], 1); } return new self($def); }
protected function __new__($login = null, $password = null) { $this->login = isset($login) ? $login : def("arbo.net.mail.Gmail@login"); $this->password = isset($password) ? $password : def("arbo.net.mail.Gmail@password"); parent::__new__($login); $this->resource = fsockopen("tls://smtp.gmail.com", 465, $errno, $errstr, 30); if ($this->resource === false) { throw new Exception("connect fail"); } }
/** Get domain init data * @return mixed */ public function load_config() { $cfg = cfg('domains', \System\Router::get_domain($this->host)); $this->rules = def($cfg['rules'], null); $this->layout = (array) def($cfg['layout'], array()); $this->policies = (array) def($cfg['policies'], array()); $this->context = (array) def($cfg['context'], array()); $this->init = (array) def($cfg['init'], array()); return $this; }
/** * 그룹 수정 * @class admin.site * @param $data: 자료 $no: 대상번호 -is_check: 입력변수 체크 여부 * @return */ function editSite($data, $no, $param = '') { global $mini; $param = param($param); def($param['is_check'], 1); //// 변수 체크 if ($param['is_check']) { checkFieldSite($data); } //// 번호 넣기 if (is_array($no) && isset($data['id'])) { __error('그룹 다중 수정에 아이디 수정이 포함되어 있습니다'); } if (!is_array($no)) { $tmp = $no; $no = array(); $no[0] = $tmp; } //// 수정할 수 없는 정보 제거 unset($data['no']); unset($data['date']); unset($data['mode']); unset($data['script']); //// 넘어오지 않은 변수 처리 if (empty($data['site_link'])) { $data['site_link'] = ''; } foreach ($no as $key => $val) { //// 번호 체크 check($val, 'type:num, name:그룹번호'); //// 데이터 로드 $data_ex = sql("SELECT * FROM {$mini['name']['site']} WHERE no={$val}"); if (!is_array($data_ex)) { __error('해당 그룹이 존재하지 않습니다'); } //// 권한체크 checkAdmin("\n\t\t\t\tsite: {$data_ex['no']}\n\t\t\t\ttype: ajax\n\t\t\t"); //// 기본변수 여부 체크 if (isset($data['name']) && !$data['name']) { __error('그룹 이름을 입력해 주세요'); } //// 이름 중복 체크 if (isset($data['name'])) { if (sql("SELECT COUNT(*) FROM {$mini['name']['site']} WHERE no!={$val} and name='{$data['name']}'")) { __error('중복된 그룹이름 입니다.'); } } //// 쿼리 sql("UPDATE {$mini['name']['site']} SET " . query($data, 'update') . " WHERE no={$val}"); //// 번호 재입력 $data['no'] = $val; //// 로그 기록 addLog(array('mode' => 'site_edit', 'field1' => $data['no'], 'ment' => arr_diff($data_ex, $data))); } }
protected function __new__($user = null, $password = null) { if (empty($user)) { $this->user = def("arbo.service.TwitterAPI@user"); $this->password = def("arbo.service.TwitterAPI@password"); } else { $this->user = $user; $this->password = $password; } $this->auth($this->user, $this->password); }
/** Alias to create simple input type * @param string $name Name of called method * @param array $args Arguments to the function */ public function __call($name, $args) { if (strpos($name, self::SEPARATOR_INPUT_METHOD) === 0) { $type = substr($name, strlen(self::SEPARATOR_INPUT_METHOD)); if (!isset($args[0])) { throw new \System\Error\Argument(sprintf('You must enter input name as first argument for System\\Form::%s method', $name)); } return $this->input(array("type" => $type, "name" => $args[0], "label" => def($args[1], ''), "required" => def($args[2], false), "info" => def($args[3], ''))); } else { throw new \System\Error\Wtf(sprintf('There is no form method "%s".', $name)); } }
public function run() { $res = $this->response; $status = 400; $message = 'fill-all-fields'; $data = null; $icons = \Car\Offer::get_attr_options('icon'); $opts = array(); foreach ($icons as $icon) { $opts[] = array('value' => $icon, 'name' => $icon); } $ident = $this->ident; def($ident, null); $f = $res->form(array('use_comm' => true)); $f->input(array('type' => 'text', 'name' => 'driver', 'required' => true)); $f->input(array('type' => 'text', 'name' => 'from', 'required' => true)); $f->input(array('type' => 'number', 'name' => 'seats', 'min' => 1, 'required' => true)); $f->input(array('type' => 'datetime', 'name' => 'departure', 'required' => true)); $f->input(array('type' => 'select', 'name' => 'icon', 'required' => true, 'options' => $opts)); $f->input(array('name' => 'phone', 'type' => 'phone', 'required' => true)); $f->input(array('type' => 'email', 'name' => 'email', 'required' => true)); $f->input(array('type' => 'textarea', 'name' => 'desc', 'required' => false)); if ($f->submited()) { if ($f->passed()) { $attrs = $f->get_data(); $status = 200; $message = 'saved'; if ($ident) { $item = \Car\Offer::get_first()->where(array('ident' => $ident))->fetch(); if (!$item) { throw new \System\Error\NotFound(); } } else { $item = new \Car\Offer(); } $item->update_attrs($attrs); $item->visible = true; $item->save(); if (!$item->sent_notif) { $item->send_notif($res); } $data = $item->get_data(); } else { $data = $f->get_errors(); } $res->mime = 'text/html'; if (!isset($ident) || $f->submited()) { $this->json_response($status, $message, $data); } } }
public static function __callStatic($method, $args) { if (self::is_enabled()) { if (self::is_ready()) { if (method_exists(self::get_driver(), $method)) { return self::get_driver()->{$method}(def($args[0], null), def($args[1], null), def($args[2], null)); } else { throw new \System\Error\Wtf(sprintf('Cache driver method does not exist: %s', $method)); } } } else { return null; } }
public function crawl() { echo 'starting crawl...', PHP_EOL; echo date('Y-m-d H:i:s'), PHP_EOL; $times = 0; $last_update = time(); try { $stream = fopen(sprintf('http://%s:%s@stream.twitter.com/1/statuses/sample.json', def('twitter_account'), def('twitter_password')), 'r'); while ($json = fgets($stream)) { $status = json_decode($json, true); if (!isset($status['text'])) { continue; } $text = $status['text']; $times += substr_count($text, '!'); $times += mb_substr_count($text, '!'); if ($times > 0 && time() - def('update_span', 180) > $last_update) { try { $counter = new BibitterCounter(); $counter->times($times); $counter->save(); C($counter)->commit(); unset($counter); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; Log::d($counter); exit; continue; } Log::debug(sprintf('updated: %d times on %s.', $times, date('Y-m-d H:i:s'))); Log::flush(); $times = 0; $last_update = time(); } } } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } Log::flush(); echo 'disconnected...', PHP_EOL; echo date('Y-m-d H:i:s'), PHP_EOL; for ($wait = 30; $wait > 0; $wait--) { sleep(1); echo 'recconect wait ' . $wait . ' sec', PHP_EOL; } $this->crawl(); }
function getAllFile($dir = '') { def($dir, './'); $output = array(); foreach (getDir("dir: {$dir}, is_file:1, full:1") as $key => $val) { if (preg_match("/(addon|file|sfile|image)\$/i", $val)) { continue; } if (is_dir($val)) { $output = array_merge($output, getAllFile($val)); } else { if (preg_match("/\\.(js|css|php|html|mini)\$/i", basename($val))) { $output[] = $val; } } } return $output; }
public function render_content() { $slots = $this->get_slots(); $json = array(); $data = array(); $this->flush(); foreach ($slots as $slot => $partials) { while ($partial = array_shift($partials)) { def($partial['locals'], array()); $json[] = $this->render_file(null, $partial['locals']); $data[] = $partial['locals']; } } if (count($data) == 1) { $this->response->status(intval(def($data[0]['status'], 200))); } return count($json) == 1 ? $json[0] : $json; }
public function current_image() { $current = $this->get_current(); $cache_key = 'api_image_' . $current . '.png'; if (!file_exists(work_path('cache/' . $cache_key))) { $image = imagecreatefrompng(path('resources/media/images/ex_api.png')); $color = imagecolorallocate($image, 51, 51, 51); $tb = imagettfbbox(36, 0, def('image_api_font'), $this->get_current()); imagettftext($image, 36, 0, ceil((160 - $tb[2]) / 2), 60, $color, def('image_api_font'), $this->get_current()); imagepng($image, work_path('cache/' . $cache_key)); imagedestroy($image); } $interval = 180; header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $interval) . ' GMT'); header('Cache-Control: max-age=' . $interval); header('Pragma: cache'); header('Content-Type: image/png'); readfile(work_path('cache/' . $cache_key)); exit; }
public function news($word, $period_start = null, $period_end = null) { $this->set_api_key(def("arbo.service.NtvAPI@news_api_key")); $this->vars("word", mb_convert_encoding($word, "SJIS", mb_detect_encoding($word))); if (!empty($period_start)) { $this->vars("period_start", $period_start); $this->vars("period_end", empty($period_end) ? $period_start : $period_end); } $this->header("Referer", $this->referer_domain); $this->do_get("news"); return NtvNewsResult::parse_list($this->body()); /*** $api = new NtvAPI(def("arbo.service.NtvAPI@test_domain")); try{ $result = $api->news("シャトル"); eq(true,true); }catch(Exception $e){ eq(false,$e->getMessage()); } */ }
protected function __new__($file_path) { $this->cmd = def("arbo.io.FFmpeg@cmd", "/usr/local/bin/ffmpeg"); $info = Command::error(sprintf("%s -i %s", $this->cmd, $file_path)); $file = new File($file_path); $this->name = $file->oname(); $this->ext = $file->ext(); $this->filename = $file_path; $this->framerate = preg_match("/frame rate: .+ -> ?([\\d\\.]+)/", $info, $match) ? (double) $match[1] : null; $this->bitrate = preg_match("/bitrate: (\\d+)/", $info, $match) ? (double) $match[1] : null; $this->duration = preg_match("/Duration: ([\\d\\:\\.]+)/", $info, $match) ? Date::parse_time($match[1]) : null; if (preg_match("/Video: (.+)/", $info, $match)) { $video = explode(",", $match[1]); if (isset($video[0])) { $this->video_codec = trim($video[0]); } if (isset($video[1])) { $this->format = trim($video[1]); } if (isset($video[2])) { list($this->width, $this->height) = explode("x", trim($video[2])); if (preg_match("/(\\d+) .+DAR (\\d+\\:\\d+)/", $this->height, $match)) { list(, $this->height, $this->aspect) = $match; } } if (empty($this->aspect) && isset($video[3])) { $this->aspect = preg_match("/DAR (\\d+\\:\\d+)/", $video[3], $match) ? $match[1] : null; } } if (preg_match("/Audio: (.+)/", $info, $match)) { $audio = explode(",", $match[1]); if (isset($audio[0])) { $this->audio_codec = trim($audio[0]); } if (isset($audio[1])) { $this->samplerate = preg_match("/\\d+/", $audio[1], $match) ? $match[0] : null; } } $this->frame_count = ceil($this->duration * $this->framerate); }
public function run() { $this->req('id'); $this->req('model'); def($conds, array()); def($opts, array()); $response = array('status' => 404, 'message' => 'model-not-found'); $model = System\Loader::get_class_from_model($model); if (class_exists($model)) { if ($item = $model::find($id)) { if ($item->can_be($model::VIEW, $request->user)) { $response['status'] = 200; $response['message'] = 'ok'; $response['data'] = $item->to_object(); } else { $response['status'] = 403; $response['message'] = 'access-denied'; } } else { $response['message'] = 'object-not-found'; } } $this->partial(null, $response); }
<?php def_alias('bu::layout', 'l'); def_accessor('title'); def_accessor('keywords'); def_accessor('description'); def('show_404', function () { write_log("404", RAW_HTTP_STRING); header("Status: 404 Not Found"); draw_page('Страница не найдена', view('404')); }); def('draw_page', function ($title, $content) { title($title); echo dview('layout/default', $content); });
* Setting this value to true will prevent you from streaming the PDF. * * @var bool */ global $_dompdf_debug; $_dompdf_debug = false; /** * Array of enabled debug message types * * @var array */ global $_DOMPDF_DEBUG_TYPES; $_DOMPDF_DEBUG_TYPES = array(); //array("page-break" => 1); /* Optionally enable different classes of debug output before the pdf content. * Visible if displaying pdf as text, * E.g. on repeated display of same pdf in browser when pdf is not taken out of * the browser cache and the premature output prevents setting of the mime type. */ def('DEBUGPNG', false); def('DEBUGKEEPTEMP', false); def('DEBUGCSS', false); /* Layout debugging. Will display rectangles around different block levels. * Visible in the PDF itself. */ def('DEBUG_LAYOUT', false); def('DEBUG_LAYOUT_LINES', true); def('DEBUG_LAYOUT_BLOCKS', true); def('DEBUG_LAYOUT_INLINE', true); def('DEBUG_LAYOUT_PADDINGBOX', true);
<?php require dirname(dirname(__FILE__)) . '/__settings__.php'; if (!isset($argv[1]) || $argv[1] !== def('cmd_password')) { die('abort'); } import('Bibitter'); $bibitter = new Bibitter(); $bibitter->crawl();
protected function __new__($api_key = null) { $this->set_api_key(isset($api_key) ? $api_key : def("arbo.service.YahooAPI@api_key")); }
<?php // Проверяем что нормально работает возвращаемое значение def('ret', function () { return 100; }); echo ret(); ?> --- 100
<?php // def_alias - создаёт алиас для функции. def('one', function () { echo 1; }); def_alias('one', 'two'); one(); two(); ?> --- 11
/** 최근게시물 * @class io * @param -id: 게시판아이디 -table: 임의지정테이블 -mode: 최근게시물모드 [!|issue|writer|relate|popup|memo] -order: 임의정렬쿼리 -where: 임의검색쿼리 -count: 출력수 -cut_title: 제목길이 -cut_ment: 내용길이 -skin: 게시물 스킨 -skin_not: 게시물이 없을 떄 스킨 -skin_first: 첫 게시물 스킨 -debug: debug모드 -is_key: 키테이블 사용여부 -type: 종류 [post!|cmt|memo|member] * @return Array 스킨이 있을 경우엔 리턴 안됨 */ function mhot($param) { global $mini; $param = param($param); def($param['cut_title'], 0); def($param['cut_ment'], 0); def($param['count'], 5); def($param['type'], 'post'); // 설정 기본값 def($mini['setting']['issue_interval'], 48); if (preg_match("/[^0-9]/", $mini['setting']['issue_interval'])) { $mini['setting']['issue_interval'] = 48; } if (preg_match("/[^0-9\\,]/", $param['count'])) { __error('출력개수에는 숫자와 ,만 입력 가능합니다' . ' (' . __FILE__ . ' line ' . __LINE__ . ' in ' . __FUNCTION__ . ')'); } if ($param['count'] > 100) { __error('출력개수는 100개를 초과할 수 없습니다' . ' (' . __FILE__ . ' line ' . __LINE__ . ' in ' . __FUNCTION__ . ')'); } $where = $order = $board_data = $table = ''; $data = $sel_board = array(); // 복수 게시판 지정(keyTable 이 사용된다) if (!empty($param['id']) && (strpos($param['id'], '[') !== false || $param['id'] == '*')) { $is_multi = 1; // 게시판 나눠넣기 if (strpos($param['id'], '[') !== false) { $sel_board = getStr($param['id']); } } // 테이블 임의지정 if (!empty($param['table'])) { $table = $param['table']; } // 키테이블 지정 if (!empty($param['is_key'])) { $table = $mini['name']['search']; } // 아이디로 테이블 지정 if (!$table && !empty($param['id']) && $param['id'] != '*') { if (!empty($mini['board']) && !empty($mini['board']['id']) && $mini['board']['id'] == $param['id']) { $board_data =& $mini['board']; } else { $board_data = getBoard($param['id'], 1); } $table = $param['type'] == 'post' ? $board_data['table'] : $board_data['table_cmt']; } // 키테이블인데 글, 댓글이 아닐 경우 에러 if (!empty($param['is_key']) && $param['type'] != 'post' && $param['type'] != 'cmt') { __error('검색테이블을 참조할 때는 글, 댓글 형식만 사용하실 수 있습니다' . ' (' . __FILE__ . ' line ' . __LINE__ . ' in ' . __FUNCTION__ . ')'); } // 특별 모드 if (!empty($param['mode'])) { switch ($param['mode']) { case 'issue': $where .= " and (issue=1 or (date>=DATE_ADD('{$mini['date']}', INTERVAL -{$mini['setting']['issue_interval']} HOUR) and date<=DATE_ADD('{$mini['date']}', INTERVAL 1 DAY)))"; $order .= ",issue*999999 + hit + vote*10 desc"; break; case 'writer': if (empty($mini['setting']['writer_no'])) { return 0; } $where .= " and target_member={$mini['setting']['writer_no']}"; $order .= ",no desc"; break; case 'relate': if (empty($mini['setting']['relate'])) { return 0; } $where .= " and " . sqlSel(explode(",", $mini['setting']['relate'])); $order .= ",no desc"; break; case 'popup': $where .= " and popup=1"; $order .= ",no desc"; break; case 'memo': $table = $mini['name']['memo']; $param['count'] = 20; $param['type'] = 'memo'; if (!empty($mini['log'])) { $where .= " and target_member={$mini['member']['no']} and date_read=0 and del_target=0"; $order .= ",no"; } break; } } // 여러 테이블 검색시 게시판 정보 로드 및 쿼리 설정 if (!empty($is_multi)) { $q_admin = ''; if (!empty($param['id']) && !empty($sel_board)) { $q_admin .= 'WHERE ' . sqlSel($sel_board); // $where .= " and ".sqlSel($sel_board, 'id'); } $data_board = sql("\n\t\t\tq: SELECT * FROM {$mini['name']['admin']} {$q_admin}\n\t\t\tmode: array\n\t\t"); $board_name = $board_data_arr = array(); if (!empty($data_board)) { foreach ($data_board as $key => $val) { $board_name[$val['no']] = $val['name']; parseBoard($val); $board_data_arr[$val['no']] = $val; } unset($data_board); } } // 키 테이블 검색시 종류에 따라 쿼리 설정 if (!empty($param['is_key'])) { $where .= $param['type'] == 'post' ? " and cmt_no=0" : " and cmt_no!=0"; } // 테이블명이 지정되지 않았다면 에러 if (empty($param['id']) && empty($param['table']) && empty($table)) { __error('게시판 아이디나 테이블명을 입력해주세요' . ' (' . __FILE__ . ' line ' . __LINE__ . ' in ' . __FUNCTION__ . ')'); } // 임의 설정 추가 if (!empty($param['where'])) { if (!preg_match("/^ ?(and|or)/i", $param['where'])) { $param['where'] = " and ({$param['where']})"; } $where .= $param['where']; } if (!empty($param['order'])) { if (!preg_match("/^\\,/i", $param['order'])) { $param['order'] = ",{$param['order']}"; } $order .= $param['order']; } else { if (empty($order)) { $order = ",date desc"; } } // 쪽지인데 로그인이 안되어 있다면 넘김 if (!empty($param['mode']) && $param['mode'] == 'memo' && empty($mini['log'])) { return false; } else { // 쿼리날림 if ($where) { $where = "WHERE " . substr($where, 4); } if ($order) { $order = "ORDER BY " . substr($order, 1); } // 복수 게시판일 경우 if (!empty($is_multi)) { // 전체 게시판일 때 if (empty($sel_board) && $param['id'] == '*') { $sel_board = array_keys($board_data_arr); } if (!empty($sel_board)) { $tmp_data = array(); $tmp_data_order = array(); $order_name = $order_type = ''; $order_data = array(); $data = array(); // order 분석 if (count(explode(",", $order)) > 1) { __error('정렬 기준은 한개만 가능합니다' . ' (' . __FILE__ . ' line ' . __LINE__ . ' in ' . __FUNCTION__ . ')'); } $tmp_order = explode(" ", str_replace("ORDER BY ", "", $order)); $order_name = $tmp_order[0]; $order_type = empty($tmp_order[1]) ? 'asc' : $tmp_order[1]; unset($tmp_order); foreach ($sel_board as $val) { // 키테이블 사용시 if (!empty($param['is_key'])) { $tmp_where = !empty($where) ? $where . " and id={$val}" : "WHERE id={$val}"; $table = $mini['name']['search']; } else { $tmp_where = $where; $table = $param['type'] == 'post' ? $mini['name']['board'] . $val : $mini['name']['cmt'] . $val; } $tmp_data = array_merge($tmp_data, sql(array('q' => "SELECT * FROM {$table} {$tmp_where} " . (!empty($param['is_key']) ? "GROUP BY num" : "") . " {$order} LIMIT {$param['count']}", 'mode' => 'array', 'extra_name' => 'id', 'extra_value' => $val))); } // 정렬 기준에 따라서 나눔 foreach ($tmp_data as $key => $val) { $order_data[$key] = $val[$order_name]; } // 정렬 if ($order_type == 'asc') { asort($order_data); } else { arsort($order_data); } // 정렬한 순서대로 data 정의 $i = 0; foreach ($order_data as $key => $val) { if ($i >= $param['count']) { break; } $data[$i] = $tmp_data[$key]; ++$i; } unset($tmp_data); unset($order_data); } } else { $data = sql(array('q' => "SELECT * FROM {$table} {$where} " . (!empty($param['is_key']) ? "GROUP BY num" : "") . " {$order} LIMIT {$param['count']}", 'mode' => 'array')); } if (!empty($data)) { $a = 0; $count_data = count($data); foreach ($data as $key => $val) { // 여러 게시판 사용시 게시판 정보 입력 if (!empty($is_multi)) { if (!empty($board_name[$data[$key]['id']])) { $data[$key]['board_name'] = $board_name[$data[$key]['id']]; } if (!empty($data[$key]['id'])) { $data[$key]['url_board'] = "{$mini['dir']}mini.php?id={$data[$key]['id']}"; } if (!empty($board_data_arr)) { $mini['board_data'] = $board_data_arr[$data[$key]['id']]; } } else { $mini['board_data'] = $board_data; } if (!empty($param['is_key'])) { // 키 테이블 사용 시 진짜 자료 로드 $val2 = sql("SELECT * FROM " . (!empty($data[$key]['cmt_no']) ? $mini['name']['cmt'] : $mini['name']['board']) . "{$data[$key]['id']} WHERE " . (!empty($data[$key]['cmt_no']) ? "no={$data[$key]['cmt_no']}" : "num={$data[$key]['num']}")); $data[$key] = array_merge($data[$key], $val2); } // title 은 포함된 변수가 많기 때문에 먼저 잘라준다 if (!empty($param['cut_title']) && !empty($data[$key]['title'])) { $data[$key]['title'] = strCut($data[$key]['title'], $param['cut_title']); } // 가공 함수 실행 $tmp_func = "parse" . ($param['type'] == 'cmt' ? 'comment' : $param['type']); if ($count_data == 1) { $tmp_func($data[$key], 'view'); } else { $tmp_func($data[$key], ''); } // 내용 자르기 if (!empty($param['cut_ment']) && !empty($data[$key]['ment'])) { $data[$key]['ment'] = strCut($data[$key]['ment'], $param['cut_ment']); $data[$key]['ment_notag'] = strCut($data[$key]['ment_notag'], $param['cut_ment']); } // if (!empty($param['debug'])) { // echo nl2br(print_r($data[$key], 1)); // exit; // } if (!empty($param['skin'])) { $skin = ''; if ($a == 0 && !empty($param['skin_first'])) { $skin = $param['skin_first']; } else { $skin = $param['skin']; } // 논리문 $preg_left = $preg_right = array(); $preg_left[] = "/\\[:([a-z0-9_]+)\\.([a-z0-9_]+)\\.([a-z0-9_]+):\\]/ie"; $preg_right[] = "\$data[{$key}]['\\1']['\\2']['\\3']"; $preg_left[] = "/\\[:([a-z0-9_]+)\\.([a-z0-9_]+):\\]/ie"; $preg_right[] = "\$data[{$key}]['\\1']['\\2']"; $preg_left[] = "/\\[:([a-z0-9_]+):\\]/ie"; $preg_right[] = "\$data[{$key}]['\\1']"; $skin = preg_replace($preg_left, $preg_right, $skin); echo $skin; } $a++; } if (empty($param['skin'])) { if (count($data) == 1 && $param['count'] == 1) { return current($data); } else { return $data; } } } else { if (!empty($param['skin_not'])) { echo $param['skin_not']; } } } }