Ignore:
Timestamp:
Dec 21, 2013, 11:02:24 PM (10 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6 + many code and logical cleaning

Location:
extensions/bbcode_bar/include
Files:
3 added
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/bbcode_bar/include/events.inc.php

    r24342 r26076  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    3 
    4 // add BBCodeBar to textarea
    5 function set_bbcode_bar($prefilter='picture', $textarea_id='contentid')
     2defined('BBCODE_ID') or die('Hacking attempt!');
     3
     4function bbcode_bar_admin_menu($menu)
    65{
    7   global $template, $conf, $pwg_loaded_plugins, $page;
    8  
    9   load_language('plugin.lang', dirname(__FILE__) . '/');
    10   $conf_bbcode_bar = unserialize($conf['bbcode_bar']);
    11  
    12  
    13   // buttons
    14   $tpl_codes = array();
    15   foreach (unserialize(BBcode_codes) as $key)
    16   {
    17     $tpl_codes[$key] = (bool)$conf_bbcode_bar[$key];
    18   }
    19   $tpl_codes['smilies'] = isset($pwg_loaded_plugins['SmiliesSupport']);
    20  
     6  $menu[] = array(
     7    'NAME' => 'BBCode Bar',
     8    'URL' => BBCODE_ADMIN,
     9    );
     10  return $menu;
     11}
     12
     13function add_bbcode_bar()
     14{
     15  global $page, $pwg_loaded_plugins, $template, $conf;
     16 
     17  if (script_basename() == 'picture')
     18  {
     19    $prefilter = 'picture';
     20    $textarea_id = 'contentid';
     21  }
     22  else if (isset($page['section']))
     23  {
     24    if (
     25      script_basename() == 'index' and isset($pwg_loaded_plugins['Comments_on_Albums'])
     26      and $page['section'] == 'categories' and isset($page['category'])
     27      )
     28    {
     29      $prefilter = 'comments_on_albums';
     30      $textarea_id = 'contentid';
     31    }
     32    else if ($page['section'] == 'guestbook')
     33    {
     34      $prefilter = 'guestbook';
     35      $textarea_id = 'contentid';
     36    }
     37    else if ($page['section'] == 'contact')
     38    {
     39      $prefilter = 'contactform';
     40      $textarea_id = 'cf_content';
     41    }
     42  }
     43 
     44  if (!isset($prefilter))
     45  {
     46    return;
     47  }
     48 
     49  $conf['bbcode_bar']['smilies'] = isset($pwg_loaded_plugins['SmiliesSupport']);
    2150 
    2251  // calculate separators between groups
     
    3766    foreach ($groups[$i] as $code)
    3867    {
    39       if ($tpl_codes[$code]) $count++;
     68      if ($conf['bbcode_bar'][$code]) $count++;
    4069    }
    4170    if ($count>0)
     
    4372      foreach ($groups[$i+1] as $code)
    4473      {
    45         if ($tpl_codes[$code]) $separator = true;
     74        if ($conf['bbcode_bar'][$code]) $separator = true;
    4675      }
    4776    }
     
    5483 
    5584  $template->assign(array(
    56     'BBC' => $tpl_codes,
    57     'SEP' => $tpl_groups,
    58     'BBCODE_PATH' => BBcode_PATH,
    59     'BBCODE_ID' => $textarea_id,
     85    'BBCODE_PATH' => BBCODE_PATH,
     86    'BBCODE' => array(
     87      'codes' => $conf['bbcode_bar'],
     88      'separators' => $tpl_groups,
     89      'textarea_id' => $textarea_id,
     90      ),
    6091    ));
    61  
    62   $template->set_prefilter($prefilter, 'set_bbcode_bar_prefilter');   
    63 
    64   // smilies support > 2.3 ## must be parsed after bbcode_bar, because the javascript must be after bbc's one
    65   if (isset($pwg_loaded_plugins['SmiliesSupport']))
    66   {
    67     set_smiliessupport($prefilter, $textarea_id);
    68   } 
    69 }
    70 
    71 function set_bbcode_bar_prefilter($content, &$smarty)
    72 {
    73   $search = '#(<div id="guestbookAdd">|<div id="commentAdd">|<div class="contact">)#';
    74   $replace = file_get_contents(BBcode_PATH.'/template/bbcode_bar.tpl').'$1';
    75   return preg_replace($search, $replace, $content);
    76 }
    77 
    78 
    79 // check tags and eventually close malformed tags, return BBCoded String
    80 function CheckTags($str)
    81 {
    82   //storage stack
    83   $tags = array();
    84 
    85   for ($pos = 0; $pos<strlen($str); $pos++)
    86   {
    87     if ($str{$pos} == '[')
    88     {
    89       $end_pos = strpos($str, ']', $pos);
    90       $tag = substr($str, ++$pos, $end_pos-$pos);
    91       //deals with tags which contains arguments (ie quote)
    92       if ( ($equal_pos = strpos($tag, '=', 0)) !== FALSE)
    93       $tag = substr($tag, 0, $equal_pos);
    94       //check whether we have a defined tag or not.
    95       if (in_array(strtolower($tag),unserialize(BBcode_codes)) || in_array(strtolower(substr($tag,1)),unserialize(BBcode_codes)))
    96       {
    97         //closing tag
    98         if ($tag{0} == '/')
    99         {
    100           //cleaned tag
    101           $tag = substr($tag, 1);   
    102           $before_tag = substr($str, 0, $pos-1);
    103           $after_tag = substr($str, $end_pos+1); 
    104           //pop stack
    105           while (($temp = array_pop($tags)))
    106           {
    107             if ($temp != $tag) {
    108               $before_tag.='[/'.$temp.']';
    109             } else {
    110               $before_tag.='[/'.$tag.']';
    111               break;
    112             }
    113           }
    114           $end_pos += strlen($before_tag)+strlen($after_tag)-strlen($str);
    115           $str = $before_tag.$after_tag;
    116         } else { // push stack
    117           array_push($tags,$tag);
    118         }
    119       }
    120       $pos = $end_pos; 
    121     }
    122   }
    123   // empty stack and closing tags
    124   while ($temp = array_pop($tags))
    125   {   
    126     $str.='[/'.$temp.']';
    127   }
    128   return $str;
     92
     93  $template->set_filename('bbcodebar', realpath(BBCODE_PATH.'/template/bbcode_bar.tpl'));
     94  $template->parse('bbcodebar');
    12995}
    13096
     
    134100  global $conf;
    135101
    136   $conf_bbcode_bar = unserialize($conf['bbcode_bar']);
    137   $str = CheckTags(nl2br($str));
     102  $str = bbcode_checktags(nl2br($str));
    138103
    139104  $patterns = array();
    140105  $replacements = array();
    141106
    142   if ($conf_bbcode_bar['p'])
     107  if ($conf['bbcode_bar']['p'])
    143108  {
    144109    //Paragraph
     
    146111    $replacements[] = '<p>\\1</p>';
    147112  }
    148   if ($conf_bbcode_bar['b'])
     113  if ($conf['bbcode_bar']['b'])
    149114  {
    150115    // Bold
     
    152117    $replacements[] = '<b>\\1</b>';
    153118  }
    154   if ($conf_bbcode_bar['i'])
     119  if ($conf['bbcode_bar']['i'])
    155120  {
    156121    //Italic
     
    158123    $replacements[] = '<i>\\1</i>';
    159124  }
    160   if ($conf_bbcode_bar['u'])
     125  if ($conf['bbcode_bar']['u'])
    161126  {
    162127    //Underline 
     
    164129    $replacements[] = '<u>\\1</u>';
    165130  }
    166   if ($conf_bbcode_bar['s'])
     131  if ($conf['bbcode_bar']['s'])
    167132  {
    168133    //Strikethrough
     
    170135    $replacements[] = '<s>\\1</s>';
    171136  }
    172   if ($conf_bbcode_bar['center'])
     137  if ($conf['bbcode_bar']['center'])
    173138  {
    174139    //Center
    175140    $patterns[] = '#\[center\](.*?)\[/center\]#is';
    176     $replacements[] = '<div align="center"><p>\\1</p></div>';
    177   }
    178   if ($conf_bbcode_bar['right'])
     141    $replacements[] = '<div align="center">\\1</div>';
     142  }
     143  if ($conf['bbcode_bar']['right'])
    179144  {
    180145    //Right
    181146    $patterns[] = '#\[right\](.*?)\[/right\]#is';
    182     $replacements[] = '<div align="right"><p>\\1</p></div>';
    183   }
    184   if ($conf_bbcode_bar['ol'])
     147    $replacements[] = '<div align="right">\\1</div>';
     148  }
     149  if ($conf['bbcode_bar']['ol'])
    185150  {
    186151    //Olist
     
    188153    $replacements[] = '<ol>\\1</ol>';
    189154  }
    190   if ($conf_bbcode_bar['ul'])
     155  if ($conf['bbcode_bar']['ul'])
    191156  {
    192157    //Ulist
     
    194159    $replacements[] = '<ul>\\1</ul>';
    195160  }
    196   if ($conf_bbcode_bar['ol'] || $conf_bbcode_bar['ul'])
     161  if ($conf['bbcode_bar']['ol'] || $conf['bbcode_bar']['ul'])
    197162  {
    198163    //List
     
    200165    $replacements[] = '<li>\\1</li>';
    201166  }
    202   if ($conf_bbcode_bar['quote'])
     167  if ($conf['bbcode_bar']['quote'])
    203168  {
    204169    // Quotes
     
    214179    $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>';
    215180  }
    216   if ($conf_bbcode_bar['img'])
     181  if ($conf['bbcode_bar']['img'])
    217182  {
    218183    //Images
     
    220185    $replacements[] = '<img src="\\1" />';
    221186  }
    222   if ($conf_bbcode_bar['url'])
     187  if ($conf['bbcode_bar']['url'])
    223188  {
    224189    //[url]xxxx://www.zzzz.yyy[/url]
     
    246211    $replacements[] = '<a href="\\1" target="_blank">\\2</a>';
    247212  }
    248   if ($conf_bbcode_bar['email'])
     213  if ($conf['bbcode_bar']['email'])
    249214  {
    250215    //[email]samvure@gmail.com[/email]
     
    252217    $replacements[] = '<a href="mailto:\\1">\\1</a>';
    253218  }
    254   if ($conf_bbcode_bar['size'])
     219  if ($conf['bbcode_bar']['size'])
    255220  {
    256221    //Size
     
    258223    $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>';
    259224  }
    260   if ($conf_bbcode_bar['color'])
     225  if ($conf['bbcode_bar']['color'])
    261226  {
    262227    //Colours
     
    267232  return preg_replace($patterns, $replacements, $str);
    268233}
    269 
    270 ?>
Note: See TracChangeset for help on using the changeset viewer.