From 94a0a341180376096f8be03261051ccd4f5fe083 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 25 Oct 2011 19:58:19 +0000 Subject: added wikiFormatting.php --- h-source/Application/Include/myFunctions.php | 339 ---------------------- h-source/Application/Include/wikiFormatting.php | 361 ++++++++++++++++++++++++ h-source/Config/Autoload.php | 1 + h-source/Public/Css/main.css | 27 +- 4 files changed, 382 insertions(+), 346 deletions(-) create mode 100644 h-source/Application/Include/wikiFormatting.php diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index 5cceaea..8c757e7 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -218,345 +218,6 @@ function getLinkToUser($user) } } -$decodeCounter = 0; -$decodeAnotherTime = false; - -//decode the text of the wiki -function decodeWikiText($string) -{ - global $decodeAnotherTime; - global $decodeCounter; - - $decodeCounter++; - - $decodeAnotherTime = false; - - $string = preg_replace('/(\[hr\])/', '
',$string); - - $string = preg_replace_callback('/(\[\[)(.*?)\|(.*?)(\]\])/', 'linkToInternalPageWithText' ,$string); - - $string = preg_replace_callback('/(\[\[)(.*?)(\]\])/', 'linkToInternalPage' ,$string); - - $string = preg_replace_callback('/(\[a\])(.*?)(\[\/a\])/', 'linkTo',$string); - - $string = preg_replace_callback('/(\[a\])(.*?)\|(.*?)(\[\/a\])/', 'linkToWithText',$string); - - $string = preg_replace_callback('/(\[notebook\])([0-9]*?)(\[\/notebook\])/s', 'linkToNotebook',$string); - - $string = preg_replace_callback('/(\[wifi\])([0-9]*?)(\[\/wifi\])/s', 'linkToWifi',$string); - - $string = preg_replace_callback('/(\[videocard\])([0-9]*?)(\[\/videocard\])/s', 'linkToVideocard',$string); - - $string = preg_replace('/(\[b\])(.*?)(\[\/b\])/s', '${2}',$string); - - $string = preg_replace('/(\[u\])(.*?)(\[\/u\])/s', '${2}',$string); - - $string = preg_replace('/(\[i\])(.*?)(\[\/i\])/s', '${2}',$string); - - $string = preg_replace('/(\[del\])(.*?)(\[\/del\])/s', '${2}',$string); - - $string = preg_replace_callback('/(\[\*\])(.*?)(\[\/\*\])/s', 'createItem',$string); - - $string = preg_replace_callback('/(\[list\])(.*?)(\[\/list\])/s', 'createList',$string); - - $string = preg_replace_callback('/(\[enum\])(.*?)(\[\/enum\])/s', 'createEnum',$string); - - $string = preg_replace('/(\[code\])(.*?)(\[\/code\])/s', '
${2}
',$string); - - $string = preg_replace('/(\[p\])(.*?)(\[\/p\])/s', '

${2}

',$string); - - $string = preg_replace_callback('/(\[)(h)(1|2|3)(\])(.*?)(\[\/)(h)(1|2|3)(\])/s', 'createHeadGeneric',$string); - - $string = preg_replace_callback('/(\[tab )(lang=)([^\s]+)(\s*\])(.*?)(\[\/tab\])/s', 'createTabs',$string); - - $string = preg_replace_callback('/(__TOC__)/s', 'createToc',$string); - - $string = preg_replace('/(\[lang\])(.*?)(\[\/lang\])/s', '
${2}
',$string); - - $string = preg_replace('/(\{\{)/s', '[',$string); - - $string = preg_replace('/(\}\})/s', ']',$string); - - if ($decodeAnotherTime and $decodeCounter<=30) - { - return decodeWikiText(Toc::render().Tabs::render().$string); - } - else - { - return Toc::render().Tabs::render().$string; - } -} - -//create the list of the tabs in the description entry -function createTabs($match) -{ - $label = Lang::getLabel($match[3]); - Tabs::$tabList[] = "
  • ".$label."
  • \n"; - Tabs::$htmlList[] = "
    $label
    \n
    ".$match[5]."
    \n"; - return null; -} - -//create the HTM Lof the tabs in the description entry -class Tabs -{ - public static $tabList = array(); - public static $htmlList = array(); - - public static function render() - { - $html = null; - if (count(self::$tabList) > 0) - { - $html .= "
    \n"; - $html .= "\n"; - $html .= "\n
    \n"; - foreach (self::$htmlList as $content) - { - $html .= $content; - } - $html .= "
    \n
    \n"; - } - self::$tabList = array(); - self::$htmlList = array(); - return $html; - } - -} - -function checkUrl($url) -{ - $match = '/^http(s)?\:\/\/(www\.)?[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\.(com|net|it|info|org|eu|uk|ca|us|cl)((\/[a-zA-Z0-9\_\.\-\:\+]+)*(\/([a-zA-Z0-9\_\:\-\.\+]+\.(php|html|htm|asp|aspx|jsp|cgi))?)?)?(\?([a-zA-Z0-9\_\-\+\s]+\=[a-zA-Z0-9\_\-\s\+\&]+)+)?(#[a-zA-Z0-9\_\-\+\s]+)?([\s]*)?$/'; - - if (preg_match($match,$url)) - { - return true; - } - else - { - return false; - } -} - -function vitalizeUrl($string) -{ - if (checkUrl($string)) - { - return "".$string.""; - } - return $string; -} - -function linkTo($match) -{ - if (checkUrl($match[2])) - { - return "".$match[2].""; - } - else - { - return $match[0]; - } -} - -function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng) -{ - $numb = strlen($hnodeTag); - global $decodeAnotherTime; - - if (strstr($match[2],$hnodeTag)) - { - $string = substr($match[0],$numb); - $string = decodeWikiText($string); - $decodeAnotherTime = true; - return $hnodeTag.$string; - } - else - { - return $htmlTagBegin.$match[2].$htmlTagEng; - } -} - -function createToc($match) -{ - Toc::create(); - return null; -} - -//table of contents -class Toc -{ - - public static $links = array(); - public static $level = 1; - - private static $html = null; - - public function create() - { - $c=0; - foreach (self::$links as $link) - { - if ((int)substr($link,0,1) === 1) - { - break; - } - $c++; - } - - self::$links = array_slice(self::$links,$c); - - $res = array(); - - if (count(self::$links) > 0) - { - self::$links[] = '1fine'; - - $res[] = "
    ".gtext("Table of contents")."
    "; - } - self::$links = array(); - self::$html = implode('',$res); - } - - public function render() - { - echo self::$html; - } -} - -//create h1, h2, h3 ($level=1,2,3) -function createHead($match,$level) -{ - Toc::$links[] = $level.$match[5]; - - return "
    ".$match[5]."
    "; -} - -//create

    ,

    ,

    -function createHeadGeneric($match) -{ - if (strcmp($match[3],'1') === 0) - { - return createHead($match,'1'); - } - else if (strcmp($match[3],'2') === 0) - { - return createHead($match,'2'); - } - else - { - return createHead($match,'3'); - } -} - -//create
  • -function createItem($match) -{ - return createNode($match,'[*]',"
  • ","
  • "); -} - -//create -function createList($match) -{ - return createNode($match,'[list]',""); -} - -//create
      -function createEnum($match) -{ - return createNode($match,'[enum]',"
        ","
      "); -} - -function linkToInternalPage($match) -{ - return "".$match[2].""; -} - -function linkToInternalPageWithText($match) -{ - return "".$match[3].""; -} - -function linkToWithText($match) -{ - if (checkUrl($match[2])) - { - - return "".$match[3].""; - } - else - { - return $match[0]; - } -} - -//create the link to the wiki page of the notebook -function linkToNotebook($match) -{ - $hardware = new HardwareModel(); - $clean['id_hard'] = (int)$match[2]; - $name = encodeUrl($hardware->getTheModelName($clean['id_hard'])); - $href = "HTTP://".DOMAIN_NAME."/notebooks/view/".Lang::$current."/".$clean['id_hard']."/$name"; - return (strcmp($name,'') !== 0) ? "".$name."" : $match[0]; -} - -//create the link to the wiki page of the wifi -function linkToWifi($match) -{ - $hardware = new HardwareModel(); - $clean['id_hard'] = (int)$match[2]; - $name = encodeUrl($hardware->getTheModelName($clean['id_hard'])); - $href = "HTTP://".DOMAIN_NAME."/wifi/view/".Lang::$current."/".$clean['id_hard']."/$name"; - return (strcmp($name,'') !== 0) ? "".$name."" : $match[0]; -} - -//create the link to the wiki page of the videocard -function linkToVideocard($match) -{ - $hardware = new HardwareModel(); - $clean['id_hard'] = (int)$match[2]; - $name = encodeUrl($hardware->getTheModelName($clean['id_hard'])); - $href = "HTTP://".DOMAIN_NAME."/videocards/view/".Lang::$current."/".$clean['id_hard']."/$name"; - return (strcmp($name,'') !== 0) ? "".$name."" : $match[0]; -} - function getUserName($id_user = 0) { $clean['id_user'] = (int)$id_user; diff --git a/h-source/Application/Include/wikiFormatting.php b/h-source/Application/Include/wikiFormatting.php new file mode 100644 index 0000000..40b7f34 --- /dev/null +++ b/h-source/Application/Include/wikiFormatting.php @@ -0,0 +1,361 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + + +$decodeCounter = 0; +$decodeAnotherTime = false; + +//decode the text of the wiki +function decodeWikiText($string) +{ + global $decodeAnotherTime; + global $decodeCounter; + + $decodeCounter++; + + $decodeAnotherTime = false; + + $string = preg_replace('/(\[hr\])/', '
      ',$string); + + $string = preg_replace_callback('/(\[\[)(.*?)\|(.*?)(\]\])/', 'linkToInternalPageWithText' ,$string); + + $string = preg_replace_callback('/(\[\[)(.*?)(\]\])/', 'linkToInternalPage' ,$string); + + $string = preg_replace_callback('/(\[a\])(.*?)(\[\/a\])/', 'linkTo',$string); + + $string = preg_replace_callback('/(\[a\])(.*?)\|(.*?)(\[\/a\])/', 'linkToWithText',$string); + + $string = preg_replace_callback('/(\[notebook\])([0-9]*?)(\[\/notebook\])/s', 'linkToNotebook',$string); + + $string = preg_replace_callback('/(\[wifi\])([0-9]*?)(\[\/wifi\])/s', 'linkToWifi',$string); + + $string = preg_replace_callback('/(\[videocard\])([0-9]*?)(\[\/videocard\])/s', 'linkToVideocard',$string); + + $string = preg_replace('/(\[b\])(.*?)(\[\/b\])/s', '${2}',$string); + + $string = preg_replace('/(\[u\])(.*?)(\[\/u\])/s', '${2}',$string); + + $string = preg_replace('/(\[i\])(.*?)(\[\/i\])/s', '${2}',$string); + + $string = preg_replace('/(\[del\])(.*?)(\[\/del\])/s', '${2}',$string); + + $string = preg_replace_callback('/(\[\*\])(.*?)(\[\/\*\])/s', 'createItem',$string); + + $string = preg_replace_callback('/(\[list\])(.*?)(\[\/list\])/s', 'createList',$string); + + $string = preg_replace_callback('/(\[enum\])(.*?)(\[\/enum\])/s', 'createEnum',$string); + + $string = preg_replace('/(\[code\])(.*?)(\[\/code\])/s', '
      ${2}
      ',$string); + + $string = preg_replace('/(\[p\])(.*?)(\[\/p\])/s', '

      ${2}

      ',$string); + + $string = preg_replace_callback('/(\[)(h)(1|2|3)(\])(.*?)(\[\/)(h)(1|2|3)(\])/s', 'createHeadGeneric',$string); + + $string = preg_replace_callback('/(\[tab )(lang=)([^\s]+)(\s*\])(.*?)(\[\/tab\])/s', 'createTabs',$string); + + $string = preg_replace_callback('/(__TOC__)/s', 'createToc',$string); + + $string = preg_replace('/(\[lang\])(.*?)(\[\/lang\])/s', '
      ${2}
      ',$string); + + $string = preg_replace('/(\{\{)/s', '[',$string); + + $string = preg_replace('/(\}\})/s', ']',$string); + + if ($decodeAnotherTime and $decodeCounter<=30) + { + return decodeWikiText(Toc::render().Tabs::render().$string); + } + else + { + return Toc::render().Tabs::render().$string; + } +} + +//create the list of the tabs in the description entry +function createTabs($match) +{ + $label = Lang::getLabel($match[3]); + Tabs::$tabList[] = "
    1. ".$label."
    2. \n"; + Tabs::$htmlList[] = "
      $label
      \n
      ".$match[5]."
      \n"; + return null; +} + +//create the HTM Lof the tabs in the description entry +class Tabs +{ + public static $tabList = array(); + public static $htmlList = array(); + + public static function render() + { + $html = null; + if (count(self::$tabList) > 0) + { + $html .= "
      \n"; + $html .= "\n"; + $html .= "\n
      \n"; + foreach (self::$htmlList as $content) + { + $html .= $content; + } + $html .= "
      \n
      \n"; + } + self::$tabList = array(); + self::$htmlList = array(); + return $html; + } + +} + +function checkUrl($url) +{ + $match = '/^http(s)?\:\/\/(www\.)?[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\.(com|net|it|info|org|eu|uk|ca|us|cl)((\/[a-zA-Z0-9\_\.\-\:\+]+)*(\/([a-zA-Z0-9\_\:\-\.\+]+\.(php|html|htm|asp|aspx|jsp|cgi))?)?)?(\?([a-zA-Z0-9\_\-\+\s]+\=[a-zA-Z0-9\_\-\s\+\&]+)+)?(#[a-zA-Z0-9\_\-\+\s]+)?([\s]*)?$/'; + + if (preg_match($match,$url)) + { + return true; + } + else + { + return false; + } +} + +function vitalizeUrl($string) +{ + if (checkUrl($string)) + { + return "".$string.""; + } + return $string; +} + +function linkTo($match) +{ + if (checkUrl($match[2])) + { + return "".$match[2].""; + } + else + { + return $match[0]; + } +} + +function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng) +{ + $numb = strlen($hnodeTag); + global $decodeAnotherTime; + + if (strstr($match[2],$hnodeTag)) + { + $string = substr($match[0],$numb); + $string = decodeWikiText($string); + $decodeAnotherTime = true; + return $hnodeTag.$string; + } + else + { + return $htmlTagBegin.$match[2].$htmlTagEng; + } +} + +function createToc($match) +{ + Toc::create(); + return null; +} + +//table of contents +class Toc +{ + + public static $links = array(); + public static $level = 1; + + private static $html = null; + + public function create() + { + $c=0; + foreach (self::$links as $link) + { + if ((int)substr($link,0,1) === 1) + { + break; + } + $c++; + } + + self::$links = array_slice(self::$links,$c); + + $res = array(); + + if (count(self::$links) > 0) + { + self::$links[] = '1fine'; + + $res[] = "
      ".gtext("Table of contents")."
      "; + } + self::$links = array(); + self::$html = implode('',$res); + } + + public function render() + { + echo self::$html; + } +} + +//create h1, h2, h3 ($level=1,2,3) +function createHead($match,$level) +{ + Toc::$links[] = $level.$match[5]; + + return "
      ".$match[5]."
      "; +} + +//create

      ,

      ,

      +function createHeadGeneric($match) +{ + if (strcmp($match[3],'1') === 0) + { + return createHead($match,'1'); + } + else if (strcmp($match[3],'2') === 0) + { + return createHead($match,'2'); + } + else + { + return createHead($match,'3'); + } +} + +//create
    3. +function createItem($match) +{ + return createNode($match,'[*]',"
    4. ","
    5. "); +} + +//create +function createList($match) +{ + return createNode($match,'[list]',""); +} + +//create
        +function createEnum($match) +{ + return createNode($match,'[enum]',"
          ","
        "); +} + +function linkToInternalPage($match) +{ + return "".$match[2].""; +} + +function linkToInternalPageWithText($match) +{ + return "".$match[3].""; +} + +function linkToWithText($match) +{ + if (checkUrl($match[2])) + { + + return "".$match[3].""; + } + else + { + return $match[0]; + } +} + +//create the link to the wiki page of the notebook +function linkToNotebook($match) +{ + $hardware = new HardwareModel(); + $clean['id_hard'] = (int)$match[2]; + $name = encodeUrl($hardware->getTheModelName($clean['id_hard'])); + $href = "HTTP://".DOMAIN_NAME."/notebooks/view/".Lang::$current."/".$clean['id_hard']."/$name"; + return (strcmp($name,'') !== 0) ? "".$name."" : $match[0]; +} + +//create the link to the wiki page of the wifi +function linkToWifi($match) +{ + $hardware = new HardwareModel(); + $clean['id_hard'] = (int)$match[2]; + $name = encodeUrl($hardware->getTheModelName($clean['id_hard'])); + $href = "HTTP://".DOMAIN_NAME."/wifi/view/".Lang::$current."/".$clean['id_hard']."/$name"; + return (strcmp($name,'') !== 0) ? "".$name."" : $match[0]; +} + +//create the link to the wiki page of the videocard +function linkToVideocard($match) +{ + $hardware = new HardwareModel(); + $clean['id_hard'] = (int)$match[2]; + $name = encodeUrl($hardware->getTheModelName($clean['id_hard'])); + $href = "HTTP://".DOMAIN_NAME."/videocards/view/".Lang::$current."/".$clean['id_hard']."/$name"; + return (strcmp($name,'') !== 0) ? "".$name."" : $match[0]; +} \ No newline at end of file diff --git a/h-source/Config/Autoload.php b/h-source/Config/Autoload.php index 480bb56..3fcc54d 100644 --- a/h-source/Config/Autoload.php +++ b/h-source/Config/Autoload.php @@ -38,6 +38,7 @@ class Autoload 'vendors.php', 'license.php', 'vendorTranslations.php', + 'wikiFormatting.php', ); } \ No newline at end of file diff --git a/h-source/Public/Css/main.css b/h-source/Public/Css/main.css index 0ffd46c..93f5783 100644 --- a/h-source/Public/Css/main.css +++ b/h-source/Public/Css/main.css @@ -180,7 +180,13 @@ div#right .hardware_element { - margin:5px; + width:335px; + float:left; + -moz-border-radius: 8px; + -webkit-border-radius: 8px; + margin:2px; + margin-left:5px; + margin-bottom:5px; padding:10px; background:#c7daef; /* border-bottom:1px solid #6495ED; */ @@ -689,13 +695,16 @@ ins } .tables_of_contents { - margin:10px 0; + margin:20px 0; padding:5px; - background-color:#C7DAEF; + background-color:#EAF2F4; + border:1px solid #C7DAEF; + -moz-border-radius: 15px; + -webkit-border-radius: 15px; } .tables_of_contents_title { - margin:5px; + margin:10px 25px; font-weight:bold; } /*wiki code*/ @@ -1375,11 +1384,13 @@ ins .issues_message_item, .issues_message_item_preview, .issues_message_item_hidden, .talk_message_item_hidden { + -moz-border-radius: 12px; + -webkit-border-radius: 12px; padding:10px; margin:20px 0px; background:#eaf2f4; - border-top:1px solid #4169E1; - border-bottom:1px solid #4169E1; +/* border-top:1px solid #4169E1; */ +/* border-bottom:1px solid #4169E1; */ } .issues_message_item_hidden, .talk_message_item_hidden { @@ -1589,11 +1600,13 @@ ins .moderator_box, .moderator_box_deleted { + -moz-border-radius: 10px; + -webkit-border-radius: 10px; overflow:hidden; padding:10px; margin:5px 5px 25px 5px; background:#fbd59a; - border:1px solid #f65637; +/* border:1px solid #f65637; */ } .moderator_box_deleted { -- cgit v1.2.3