/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { if (X4Core_core::$insta == NULL) { // Set the instance to the first controller loaded X4Core_core::$insta = $this; } }
/** * Call the specified plugin method * * @param string $module plugin name * @param integer $id_area area ID * @param string $control method name * @param mixed $a unspecified variable * @param mixed $b unspecified variable * @param mixed $c unspecified variable * @param mixed $d unspecified variable * @return void */ public function call_plugin($module, $id_area = '', $control = '', $a = '', $b = '', $c = '', $d = '') { $mod = new X4Plugin_model(); if ($mod->exists($module, $id_area) && file_exists(PATH . 'plugins/' . $module . '/' . $module . '_plugin.php')) { X4Core_core::auto_load($module . '/' . $module . '_plugin'); $plugin = ucfirst($module . '_plugin'); $m = new $plugin($this->site); $m->call_plugin($id_area, $control, $a, $b, $c, $d); } else { header('HTTP/1.0 404 Not Found'); header('Location: ' . BASE_URL . 'msg/message/_page_not_found'); } }
/** * Analize media file * * @static * @param string File to analyze * @return array */ public static function analyze($filename) { if (file_exists($filename)) { X4Core_core::auto_load('getid3_library'); $getID3 = new getID3(); $data = $getID3->analyze($filename); /* echo("Duration: ".$file['playtime_string']. " / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall". " / Filesize: ".$file['filesize']." bytes<br />"); */ } else { $data = array(); } return $data; }
/** * Generic API override __call * * @param string url/controller name * @param array array of arguments * @return void */ public function __call($url, $args) { // load API class $check = X4Core_core::auto_load($url . '_api'); // if API exists if ($check) { // call Restler $r = new Restler(); $r->setSupportedFormats('JsonFormat', 'XmlFormat'); $r->addAPIClass($url); $r->addAuthenticationClass('SimpleAuth'); $r->handle(); } else { return false; } }
/** * Get Facebook user data * * @static * @return mixed */ public static function user() { X4Core_core::auto_load('fbsdk_library'); $fb = new Facebook\Facebook(array('app_id' => FACEBOOK_APP_ID, 'app_secret' => FACEBOOK_SECRET, 'default_graph_version' => 'v2.2')); // already logged with JS $helper = $fb->getJavaScriptHelper(); try { // get the access token from a Cookie $accessToken = $helper->getAccessToken(); //$_SESSION['fb_access_token'] = (string) $accessToken; // Returns a `Facebook\FacebookResponse` object $response = $fb->get('/me?fields=id,first_name,last_name,email,location', $accessToken); $user = $response->getGraphUser(); } catch (Exception $e) { // user not found //echo 'User not found'; //die; return false; } return $user; }
/** * Export a pdf * * @static * @param string $title Document title * @param string $css CSS Contents * @param string $html HTML Contents * @param string $page_format Default A4 * @param string $orientation Can be P|L * @return boolean */ public static function pdf_export($title, $css, $html, $page_format = 'A4', $orientation = 'P') { // language set $l = array(); $l['a_meta_charset'] = 'UTF-8'; $l['a_meta_dir'] = 'rtl'; $l['a_meta_language'] = X4Route_core::$lang; $l['w_page'] = _PAGE; X4Core_core::auto_load('mpdf_library'); // create the PDF object $mpdf = new mPDF(X4Route_core::$lang, $page_format, 0, 0, 0, 0, 0, 0, $orientation); $title = SERVICE . ' - ' . $title . ' - ' . date('Y-m-d H:i:s'); $mpdf->SetAuthor($_SESSION['nickname']); $mpdf->SetCreator(SERVICE); $mpdf->SetTitle($title); $mpdf->SetDisplayMode('fullwidth'); $mpdf->WriteHTML($css, 1); $mpdf->WriteHTML($html, 2); $filename = X4Utils_helper::unspace(str_replace(' - ', '-', $title), true); $mpdf->Output($filename . '.pdf', 'D'); exit; }
/** * Minimize css files * * @return void */ public function minimize($id_theme, $name) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'themes', $id_theme, 4); if (is_null($msg)) { $qs = X4Route_core::get_query_string(); // do action $res = 1; // get the templates in the theme $mod = new Theme_model(); // CSS section $path = PATH . 'themes/' . $name . '/css/'; $items = $mod->get_css($id_theme); foreach ($items as $i) { if (file_exists($path . $i->css . '.css')) { $txt = file_get_contents($path . $i->css . '.css'); $txt = $mod->compress_css($txt); $chk = file_put_contents($path . $i->css . '.min.css', $txt); if (!$chk) { $res = 0; } } } // JS section X4Core_core::auto_load('jshrink_library'); $path = PATH . 'themes/' . $name . '/js/'; $items = $mod->get_js($id_theme); foreach ($items as $i) { if (file_exists($path . $i->js . '.js')) { $txt = file_get_contents($path . $i->js . '.js'); $txt = Minifier::minify($txt, array('flaggedComments' => false)); $chk = file_put_contents($path . $i->js . '.min.js', $txt); if (!$chk) { $res = 0; } } } $result = array(0, $res); // set message $this->dict->get_words(); $msg = AdmUtils_helper::set_msg($result); // set update if ($result[1]) { $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null); } } $this->response($msg); }
/** * output handler. * * @static * @param string current output buffer * @return string */ public static final function output_buffer($output) { // Set final output self::$output = $output; // Set and return the final output return self::$output; }
/** * Load a plugin and execute default method * * @static * @param object $site site obj * @param object $page page obj * @param array $args page's arguments * @param string $module plugin name * @param string $param parameter * @param boolean $force force load plugin even if not usable * @return string */ public static function module($site, $page, $args, $module, $param = '', $force = false) { $plug = new X4Plugin_model(); if ($force || $plug->usable($module, $page->id_area) && file_exists(PATH . 'plugins/' . $module . '/' . $module . '_plugin.php')) { X4Core_core::auto_load($module . '/' . $module . '_plugin'); $plugin = ucfirst($module . '_plugin'); $m = new $plugin($site); return $m->get_module($page, $args, $param); } else { return ''; } }
/** * end point * * @static * @return void */ public static function end_point() { // load library X4Core_core::auto_load('hybridauth_end_library'); }
/** * Perform the importing of words * * @access private * @param array $_post _POST array * @return void */ private function importing($_post) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_key_import', 0, 4); if (is_null($msg)) { // get key list($lang, $area, $what) = explode('-', $_post['what']); // handle _post $post = array('lang' => $_post['lang'], 'area' => $_post['area'], 'what' => $what, 'xon' => 1); // set the translator X4Core_core::auto_load('google_translate_library'); $translator = new GoogleTranslate($lang, $post['lang']); // get words to import $dict = new Dictionary_model(); if ($what == 'ALL') { // import all sections in an area $sections = $dict->get_sections($lang, $area); $result = true; foreach ($sections as $s) { // get words in section $words = $dict->get_words_to_import($lang, $area, $s->what, $post['lang'], $post['area']); if (!empty($words)) { $post['what'] = $s->what; // import foreach ($words as $i) { $post['xkey'] = $i->xkey; // try to translate if ($lang != $post['lang']) { $value = $translator->translate($i->xval); } else { $value = $i->xval; } // set the word $post['xval'] = $value; // insert $result = $dict->insert($post); // add permission if ($result[1]) { $amod = new Area_model(); $id_area = $amod->get_area_id($_post['area']); $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('dictionary', $array, $id_area); } } } } // set what for redirect $what = 'global'; } else { // import only one section $words = $dict->get_words_to_import($lang, $area, $what, $post['lang'], $post['area']); $result = true; // import foreach ($words as $i) { $post['xkey'] = $i->xkey; // try to translate if ($lang != $post['lang']) { $value = $translator->translate($i->xval); } else { $value = $i->xval; } // set the word $post['xval'] = $value; // insert $result = $dict->insert($post); // add permission if ($result[1]) { $amod = new Area_model(); $id_area = $amod->get_area_id($_post['area']); $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('dictionary', $array, $id_area); } } } $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'dictionary/keys/' . $post['lang'] . '/' . $post['area'] . '/' . $what, 'title' => null); } } $this->response($msg); }
*/ // if you use composer // better if you put it only where you need it // require 'vendor/autoload.php'; /** * Load Configuration */ include APATH . 'config/config.php'; /** * Set Timezone */ if (isset($_SESSION['timezone'])) { date_default_timezone_set($_SESSION['timezone']); } else { date_default_timezone_set(TIMEZONE); } /** * Load Router */ include SPATH . 'core/X4Route_core.php'; /** * Load Core */ include SPATH . 'core/X4Core_core.php'; // Start the core if (defined('X3CLI')) { // When called from x3 X4Core_core::setCore($default, $db_config, $cli); } else { X4Core_core::setCore($default, $db_config); }