<?php
 class vB_DataManager_StyleVarDefn extends vB_DataManager { protected $validfields = [ 'stylevarid' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_YES], 'styleid' => [vB_Cleaner::TYPE_INT, vB_DataManager_Constants::REQ_NO, vB_DataManager_Constants::VF_METHOD], 'parentid' => [vB_Cleaner::TYPE_INT, vB_DataManager_Constants::REQ_YES, vB_DataManager_Constants::VF_METHOD], 'parentlist' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_NO], 'stylevargroup' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_YES], 'product' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_YES, vB_DataManager_Constants::VF_METHOD], 'datatype' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_YES, vB_DataManager_Constants::VF_METHOD], 'validation' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_NO], 'failsafe' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_NO], 'units' => [vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_NO, vB_DataManager_Constants::VF_METHOD], 'uneditable' => [vB_Cleaner::TYPE_BOOL, vB_DataManager_Constants::REQ_YES], ]; protected $table = 'vBForum:stylevardfn'; protected $stylevardfn = []; protected $datatype = 'Custom'; protected $keyField = 'stylevarid'; public function verify_parentid(&$parentid) { if ($parentid == $this->fetch_field('styleid')) { $this->error('cant_parent_style_to_self'); return false; } else if ($parentid <= 0) { $parentid = -1; return true; } $stylecache = vB_Library::instance('Style')->fetchStyles(false, false); if (!isset($stylecache["$parentid"])) { $this->error('invalid_style_specified'); return false; } else if ($this->condition !== null) { return $this->is_substyle_of($this->fetch_field('styleid'), $parentid); } else { return true; } } protected function verify_styleid(&$data) { if ($data < -1) { $data = 0; } return true; } public function is_substyle_of($styleid, $parentid) { $stylecache = vB_Library::instance('Style')->fetchStyles(false, false); while (is_array($stylecache["$styleid"])) { $curstyle = $stylecache["$styleid"]; if ($curstyle['parentid'] == $parentid) { return true; } if ($curstyle['parentid'] == -1) { break; } $styleid = $curstyle['parentid']; } $this->error('cant_parent_style_to_child'); return false; } public function verify_product($product) { return (preg_match('#^[a-z0-9_]+$#s', $product) AND strlen($product) < 25); } public function verify_datatype($datatype) { $valid_datatypes = array( 'numeric', 'string', 'color', 'url', 'path', 'background', 'imagedir', 'fontlist', 'textdecoration', 'texttransform', 'textalign', 'dimension', 'border', 'padding', 'margin', 'font', 'size', 'boolean', ); return in_array($datatype, $valid_datatypes); } public function verify_units($unit) { $valid_units = array( '', '%', 'px', 'pt', 'em', 'rem', 'ch', 'ex', 'pc', 'in', 'cm', 'mm', 'vw', 'vh', 'vmin', 'vmax', ); return in_array($unit, $valid_units); } public function pre_save($doquery = true) { if ($this->presave_called !== null) { return $this->presave_called; } $return_value = true; $this->presave_called = $return_value; return $return_value; } public function post_save_each($doquery = true) { } public function delete($doquery = true) { $matchedids = $this->assertor->getColumn($this->table, 'stylevarid', $this->condition); $result = parent::delete($doquery); if ($result AND ($doquery OR true)) { $this->assertor->delete('stylevar', $matchedids); } return $result; } } 