view compos.inc.php @ 24:5bc8bd5c7ecc

Make voting toggle for individual compos.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 07 Dec 2012 10:05:02 +0200
parents e36c4d2b09c4
children 0980e705dea0
line wrap: on
line source

<?
echo stGetSetting("compoDescription");

function stConvSwitchMode(&$str, &$mode, $newMode)
{
  if ($newMode != $mode)
  {
    if ($mode != "")
      $str .= "\n</".$mode.">\n";

    $mode = $newMode;

    if ($mode != "")
      $str .= "<".$mode.">\n";
  }
}


function stConvertCompoDesc($desc)
{
  global $stDescConversion;
  $str = "";
  $mode = "";

  foreach (explode("\n", $desc) as $line)
  {
    if (preg_match("/^\s*\s*\*(.+)$/", $line, $m))
    {
      stConvSwitchMode($str, $mode, "ol");
      $str .= "<li>".$m[1]."</li>\n";
    }
    else
    if (preg_match("/^\s*-\s*(.+)$/", $line, $m))
    {
      stConvSwitchMode($str, $mode, "ul");
      $str .= "<li>".$m[1]."</li>\n";
    }
    else
    {
      stConvSwitchMode($str, $mode, "p");
      $str .= $line;
    }
  }

  stConvSwitchMode($str, $mode, "");

  return $str;
}

$sql = "SELECT * FROM compos WHERE visible<>0 ORDER BY id ASC";

if (($res = stExecSQL($sql)) !== FALSE)
{
  foreach ($res as $item)
  {
    echo
    "<div id=\"compo".$item["id"]."\">\n".
    "<h2>".chentities($item["name"])."</h2>\n".
    stConvertCompoDesc($item["description"]).
    "</div>\n";
  }
}
?>