/** * Retourne le dossier base(ROOT) de Magix CMS */ public static function basePath() { try { return filter_path::basePath(array('lib', 'magepattern')); } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * Instance la classe DateTime * @param $time * @return \DateTime * @throws Exception */ private function _datetime($time) { try { $datetime = self::create($time); if ($datetime instanceof DateTime) { return $datetime; } else { throw new Exception('not instantiate the class: DateTime'); } } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * Retourne l'extension du fichier image * @param $filename * @return size */ public static function imageAnalyze($filename) { try { $size = getimagesize($filename); switch ($size['mime']) { case "image/gif": $imgtype = '.gif'; break; case "image/jpeg": $imgtype = '.jpg'; break; case "image/png": $imgtype = '.png'; break; case false: break; } return $imgtype; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * Envoi du message avec la méthode batch send * @param string $message * @param bool $failures * @param bool $log * @internal param void $mailer * @internal param void $failed * @internal param string $logger */ public function batch_send_mail($message, $failures = false, $log = false) { if (!$this->_mailer->send($message)) { debug_firephp::dump("Failures: ", $failures); } if ($log) { $echologger = new Swift_Plugins_Loggers_EchoLogger(); $this->_mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($echologger)); debug_firephp::dump("Failures: ", $echologger->dump()); $logger = new debug_logger(MP_LOG_DIR); $logger->log('mail', 'Failures', 'Failures : ' . $echologger->dump(), debug_logger::LOG_VOID); } }
/** * Chargement du fichier SQL pour la lecture du fichier * @param $sqlfile * @throws Exception * @return array|bool|string */ private function load_sql_file($sqlfile) { try { $db_structure = ""; $structureFile = $sqlfile; if (!file_exists($structureFile)) { throw new Exception("Error : Not File exist .sql"); } else { $db_structure = preg_split("/;\\s*[\r\n]+/", file_get_contents($structureFile)); if ($db_structure != null) { $tables = $db_structure; } else { debug_firephp::error("Error : SQL File is empty"); return false; } } return $tables; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * @access public * Check si le domaine est disponible * @param $url * @param bool $ssl * @param bool $debug * @internal param string $domain * @return bool */ public function isDomainAvailible($url, $ssl = false, $debug = false) { try { if (self::curl_exist()) { //check, if a valid url is provided if (!filter_var($url, FILTER_VALIDATE_URL)) { return false; } //initialize curl $curlInit = curl_init($url); curl_setopt($curlInit, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curlInit, CURLOPT_HEADER, true); curl_setopt($curlInit, CURLOPT_NOBODY, true); curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true); if ($ssl) { /*Vérification SSL*/ curl_setopt($curlInit, CURLOPT_SSL_VERIFYPEER, false); } //get answer $response = curl_exec($curlInit); curl_close($curlInit); if ($debug) { $firephp = new debug_firephp(); $firephp->log($response); } if ($response) { return true; } return false; } } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID); } }
/** * Charge le theme selectionné ou le theme par défaut */ public function load_theme() { $db = self::$collectionsSetting->fetch('theme'); if ($db['setting_value'] != null) { if ($db['setting_value'] == 'default') { $theme = $db['setting_value']; } elseif (file_exists(magixglobal_model_system::base_path() . '/skin/' . $db['setting_value'] . '/')) { $theme = $db['setting_value']; } else { try { $theme = 'default'; throw new Exception('template ' . $db['setting_value'] . ' is not found'); } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } } } else { $theme = 'default'; } return $theme; }
/** * @access public * Initialise la session ou renouvelle la session * @param $session_tabs * @param bool $setOption * @internal param array $session * @internal param bool $debug */ public function run($session_tabs = false, $setOption = false) { try { if ($setOption != false) { $setOption; } if ($session_tabs != false) { $this->iniSessionVar($session_tabs); } } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID); } }
/** * function truncate table * * @param void $table * @param bool $setOption * @throws Exception */ public function truncateTable($table, $setOption = false) { try { /** * Charge la configuration */ $sql = 'TRUNCATE TABLE ' . $table; $setConfig = $this->setConfig($sql, $setOption = false); $prepare = $this->prepare($sql); if (is_object($prepare)) { $prepare->execute(); $setConfig['debugParams'] ? $prepare->debugDumpParams() : ''; $setConfig['closeCursor'] ? $prepare->closeCursor() : ''; } else { throw new Exception('showTable Error with SQL prepare'); } } catch (PDOException $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('statement', 'db', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * This function rename files and dir * * @access public * @param $files * @throws Exception */ public function rename($files) { try { if (is_array($files)) { foreach ($files as $origin => $target) { // we check that target does not exist if (is_readable($target)) { throw new Exception(sprintf('Cannot rename because the target "%s" already exist.', $origin)); } if (!file_exists($origin)) { continue; } if (true !== @rename($origin, $target)) { throw new Exception(sprintf('Failed to rename %s', $origin)); } } } else { throw new Exception(sprintf('%s is not array', $files)); } } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * @static * @param array|bool $tabsearch * @throws Exception * @internal param array $tabreplace * @return mixed|string * @example : filesystem_path::basePath( array('component','filesystem') ); */ public static function basePath($tabsearch = false) { try { $default_path = array('component', 'filter'); if ($tabsearch != false) { if (is_array($tabsearch)) { $search = array_merge($tabsearch, $default_path, array(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR)); } else { throw new Exception(__METHOD__ . ' params "tabsearch" is not array'); } } else { //$search = array_merge(explode(DIRECTORY_SEPARATOR,__DIR__),array(DIRECTORY_SEPARATOR)); $search = array_merge($default_path, array(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR)); } /*if($tabreplace != false){ if(is_array($tabreplace)){ $replace = array_merge($tabreplace,array('','')); }else{ throw new Exception(__METHOD__.' params "tabreplace" is not array'); } }else{ $replace = array_fill(0,count($search),''); }*/ if (count($search) > 0) { $replace = array_fill(0, count($search), ''); } else { throw new Exception('Error replace : internal params is null'); } $pathreplace = str_replace($search, $replace, __DIR__); if (strrpos($pathreplace, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR)) { $pathclean = substr($pathreplace, -1); } else { $pathclean = $pathreplace; } if (strrpos($pathclean, DIRECTORY_SEPARATOR, strlen($pathclean) - 1)) { $path = $pathclean; //$path = substr($pathclean,0, -1); } else { $path = $pathclean . DIRECTORY_SEPARATOR; } return $path; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * Select Field * * Return HTML CODE for SELECT MENU * @static * @param string|array $nid Element ID and name * @param array $arrayOption * @param bool $arrInput * @throws Exception * @return string * * @example : * #### BASE ##### * $form->select( 'myselect', array(1=>'opt1',2=>'opt2'), 'maclass' ); * ##### WITH Database ####### $fetch = $db->fetchAll($sql); //ASSOCIATIVE DATA $option = ''; foreach($fetch as $value){ $id[] = $value['id']; $color[] = $value['color']; } $selectcolor = array_combine($id,$color); $form->select( 'monselect', $selectcolor, 'maclass' ); * * Return Source : <select name="myselect" id="myselect" class="myclass"> <option value="1">couleur verte</option> <option value="2">couleur rouge</option> </select> */ public static function select($nid, $arrayOption, $arrInput = false) { try { self::getNameAndId($nid, $name, $id); $getInput = self::setInputConfig($arrInput); if (is_array($arrayOption)) { $res = '<select name="' . $name . '" '; $res .= $id ? 'id="' . $id . '"' : ''; $res .= $getInput['class'] ? ' class="' . $getInput['class'] . '"' : ''; $res .= '>' . "\n"; foreach ($arrayOption as $key => $value) { $selected = null; if (isset($getInput['default']) and $getInput['default'] != '') { if (array_key_exists($getInput['default'], $arrayOption)) { $selected = $getInput['default'] == $key ? ' selected="selected"' : null; } } $res .= '<option' . $selected . ' value="' . $key . '">'; $res .= $value; $res .= '</option>' . "\n"; } $res .= '</select>' . "\n"; return $res; } else { throw new Exception(sprintf('%s is not array in ' . __METHOD__, $arrayOption)); } } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('php', 'error', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_MONTH); } }
/** * filterFiles => filter files with extension * $t = new magixcjquery_files_makefiles(); * var_dump($t->filterFiles('mydir',array('gif','png','jpe?g'))); * or * var_dump($t->filterFiles('mydir','php')); * @param $directory * @param $extension * @internal param $dir * @return string */ public function filterFiles($directory, $extension) { try { $filterfiles = new filterFiles($directory, $extension); $filter = ''; foreach ($filterfiles as $file) { if ($file->isDot() || $file->isDir()) { continue; } $filter[] .= $file; } return $filter; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID); } }