PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
real-time
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my settings
my profile
Public Pastes
Uploaded.to Premiu...
11 sec ago
Untitled
1 sec ago
$.post returning (...
8 sec ago
Broken anydbm.py o...
14 sec ago
Convert string to ...
20 sec ago
Untitled
21 sec ago
ttttttt
39 sec ago
how use an onclick...
26 sec ago
New Paste
<?php defined('SYSPATH') OR die('No direct access allowed.'); /** * helper for working with system-generated messages * * Each message has a type (error/warning/success etc). Also there are two * additional types: custom (for data store) and validate (for validation errors) * * @package CMS * @author Brotkin Ivan (BIakaVeron) <BIakaVeron@gmail.com> * @copyright Copyright (c) 2009 Brotkin Ivan */ class message_Core { /* * @property Session $session * */ // all helper data static protected $data = array(); // array for previous requests data static protected $loaded = array(); // array for currently added data only static protected $added = array(); // default template name (use in render() method) static protected $template = 'messages/default'; // this property allow to render all-in-one validation errors static protected $show_validation = FALSE; // what is the name of session variable static protected $session_var; // session object static protected $session = FALSE; /* * Initial data loading */ public function init() { // don't call init() twice! if (self::$session !== FALSE) return FALSE; // set the session var name self::$session_var = Kohana::config('message.message_key'); self::$session = Session::instance(); // load session data self::$loaded = self::$session->get_once(self::$session_var); if (empty(self::$loaded)) { // create empty array - there is no data self::$loaded = array(); } self::$data = self::$loaded; } /** * * Save data in session. Saves new data only ($added array) * */ public function save() { self::$session->set(self::$session_var, self::$added); } /** * * Save all data in session ($data array). * Needed if we want to use current data on the next page * */ public function save_all() { self::$session->set(self::$session_var, self::$data); } /** * * Sets new template. * * @param string $template new template name */ public function set_template($template = 'default') { self::$template = 'messages/'.$template; } /** * * Syncronizes $data, $added and $loaded arrays. Uses when some new data added * * @param string $type which type of messages will we syncronize */ private function sync($type = NULL) { if (is_null($type)) { // sync all data self::$data = self::$loaded + self::$added; } else { // sync $type messages only self::$data[$type] = (isset(self::$loaded[$type]) ? self::$loaded[$type] : array()) + (isset(self::$added[$type]) ? self::$added[$type] : array()); } } /** * * Removes data from helper. * * Can delete all data ($type is NULL), or $type data, or one value ($tag is set) * * @param string $type messages type to remove * @param string $tag tagname to remove one value */ private function remove($type, $tag = NULL) { if (is_null($tag)) { // remove all data if (isset(self::$data[$type])) unset(self::$data[$type]); if (isset(self::$added[$type])) unset(self::$added[$type]); if (isset(self::$loaded[$type])) unset(self::$loaded[$type]); } else { // remove only $type data (with $tag checking) if (isset(self::$data[$type][$tag])) unset(self::$data[$type][$tag]); if (isset(self::$added[$type][$tag])) unset(self::$added[$type][$tag]); if (isset(self::$loaded[$type][$tag])) unset(self::$loaded[$type][$tag]); } } /** * * Returns all values of supplied type and tagname and removes them from helper * * @param string $type messages type * @param string $tag tagname if one value needed * @return array */ public function get_type($type, $tag = NULL) { if (is_null($type)) { // full data request $result = self::$data; self::clear(); return $result; } // check for data of supplied type if (!isset(self::$data[$type])) return array(); if (isset($tag)) { // returns one value if tagname supplied if (!isset(self::$data[$type][$tag])) return array(); else $result = array(self::$data[$type][$tag]); } else { // get all data of this type $result = self::$data[$type]; } // delete returned data from helper self::remove($type, $tag); return $result; } /** * * @param string|array $message data to store * @param string $type data type */ public function add($message, $type = 'info') { if (is_array($message)) { // save data as $key=>$value if (isset(self::$added[$type])) { // this data type array already exists self::$added[$type] += $message; } else { // its a first data of this type self::$added[$type] = $message; } } else { // its a string data if (!isset(self::$added[$type])) { // there is no such type data self::$added[$type][] = $message; } elseif (!in_array($message, self::$added[$type])) { // add message string self::$added[$type][] = $message; } } // sync data after every change self::sync($type); } /** * * Adds validation errors (usually from Validation->errors() method) * * Data key will be a fieldname, value - i18n-string with error description * * @param array $errors validation errors * @param string $i18n_file i18n filename */ public function add_validation(array $errors, $i18n_file) { $result = array(); // collecting error messages in result array foreach($errors as $key => $value) $result[$key] = Kohana::lang($i18n_file.".".$key."_".$value); // add errors to $added array with validation type self::add($result, 'validation'); } /** * * Delete all storing data (possible by type and tagname) * * @param string $type data type to delete */ public function clear($type = NULL, $tag = NULL) { if (is_null($type)) { // remove all data self::$data = self::$added = self::$loaded = array(); } else { // remove supplied type only self::remove($type, $tag); } } /** * * Returns custom type data by tagname. * * @param string $tag tagname * @param mixed $default default value if not exists * @return string|array */ public function custom($tag = NULL, $default = NULL) { if (is_null($tag)) { // returns all custom data if (!isset(self::$data['custom'])) return array(); $result = self::$data['custom']; // dont forget to clear data! self::remove('custom'); return $result; } // check for existing if (isset(self::$data['custom'][$tag])) { // get tagged value and delete it from data $result = self::$data['custom'][$tag]; self::remove('custom', $tag); return $result; } else return $default; } /** * Shows message box with supplied type and tagname * * @param string $type data type to render * @param string $tag tagname if only one value needed * @return boolean FALSE if there was no rendering */ public function render($type = NULL, $tag = NULL) { // check for data if (count(self::$data)==0) return FALSE; // custom data may use in form submitting for example if ($type === 'custom') return FALSE; if (is_null($type)) { // render all data by existing types foreach(self::$data as $type=>$value) { self::render($type, $tag); } return TRUE; } // don't show validation data without tagname if (self::$show_validation===FALSE AND $type == 'validation' AND is_null($tag)) return FALSE; $data = self::get_type($type, $tag); // there is no data to render if (count($data)==0) return FALSE; $view = new View(self::$template); $view->data = $data; $view->type = $type; // if tagname supplied it will be a single box without many message string $view->inline = (isset($tag) ? " inline" : ""); echo $view->render(); return TRUE; } }
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
HTML 5
Java
JavaScript
Lua
None
Perl
PHP
Python
Rails
-------------
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
ActionScript
ActionScript 3
Ada
ALGOL 68
Apache Log
AppleScript
APT Sources
ASM (NASM)
ASP
autoconf
Autohotkey
AutoIt
Avisynth
Awk
BASCOM AVR
Bash
Basic4GL
BibTeX
Blitz Basic
BNF
BOO
BrainFuck
C
C for Macs
C Intermediate Language
C#
C++
C++ (with QT extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
ChaiScript
Clojure
Clone C
Clone C++
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
DCS
Delphi
Delphi Prism (Oxygene)
Diff
DIV
DOS
DOT
E
ECMAScript
Eiffel
Email
EPC
Erlang
F#
Falcon
FO Language
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
Game Maker
GDB
Genero
Genie
GetText
Go
Groovy
GwBasic
Haskell
HicEst
HQ9 Plus
HTML
HTML 5
Icon
IDL
INI file
Inno Script
INTERCAL
IO
J
Java
Java 5
JavaScript
jQuery
KiXtart
Latex
Liberty BASIC
Linden Scripting
Lisp
LLVM
Loco Basic
Logtalk
LOL Code
Lotus Formulas
Lotus Script
LScript
Lua
M68000 Assembler
MagikSF
Make
MapBasic
MatLab
mIRC
MIX Assembler
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MPASM
MXML
MySQL
newLISP
None
NullSoft Installer
Oberon 2
Objeck Programming Langua
Objective C
OCalm Brief
OCaml
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
Pascal
PAWN
PCRE
Per
Perl
Perl 6
PHP
PHP Brief
Pic 16
Pike
Pixel Bender
PL/SQL
PostgreSQL
POV-Ray
Power Shell
PowerBuilder
ProFTPd
Progress
Prolog
Properties
ProvideX
PureBasic
PyCon
Python
q/kdb+
QBasic
R
Rails
REBOL
REG
Robots
RPM Spec
Ruby
Ruby Gnuplot
SAS
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
SQL
SystemVerilog
T-SQL
TCL
Tera Term
thinBasic
TypoScript
Unicon
UnrealScript
Vala
VB.NET
VeriLog
VHDL
VIM
Visual Pro Log
VisualBasic
VisualFoxPro
WhiteSpace
WHOIS
Winbatch
XBasic
XML
Xorg Config
XPP
YAML
Z80 Assembler
ZXBasic
Paste Expiration:
Never
10 Minutes
1 Hour
1 Day
1 Month
Paste Exposure:
Public
Unlisted
Private (members only)
Paste Name / Title:
Hello
Guest
Sign Up
or
Login
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login