Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace PandoraBox
- {
- public class APVIDEOPlugin : IPluginMacro
- {
- //пример
- //[APVIDEO]
- Regex _block = new Regex(@"{APVIDEO}(.*?){/APVIDEO}", RegexOptions.Compiled);
- //кодировка
- Encoding _enc = Encoding.GetEncoding("windows-1251");
- //путь к данным
- String _root = @"c:\ap-data\video";
- //шаблон видео
- String _template = "<iframe width='560' height='315' src='https://www.youtube.com/embed/[CODE]' frameborder='0' allowfullscreen></iframe>";
- public string Execute(string template, PluginMacroArgs args)
- {
- return _block.Replace(template, delegate(Match match)
- {
- String key = CleanKey(args.Key);
- String inner = match.Groups[1].Value;
- String file = Path.Combine(_root, key);
- if (!File.Exists(file)) return "";
- String[] lines = File.ReadAllLines(file, _enc);
- String line = lines[Rnd.Next(0, lines.Length - 1)];
- var parts = line.Split('|');
- String code = parts[0];
- if (!code.Contains("=")) return "";
- code = code.Split('=', '&')[1];
- String title = parts[2];
- inner = inner.Replace("[APVIDEO]", _template.Replace("[CODE]", code));
- inner = inner.Replace("[APVIDEOTITLE]", title);
- return inner;
- });
- }
- private string CleanKey(String key)
- {
- String key1 = key;
- key1 = String.Join("", key1.Split(Path.GetInvalidPathChars()));
- key1 = String.Join("", key1.Split(Path.GetInvalidFileNameChars()));
- return key1;
- }
- public ushort Level { get { return 5; } }
- public String Name { get { return "APVIDEOPlugin"; } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment