function ofType($type, $val) { if ($val instanceof $type) { return $val; } throwError("Not of type '{$type}'"); }
public function addDataRow($values, $name = false) { /** * Adds a data row to the existing graph * * @param $values: An array of values * @param $name (optional): The name of the data row * * @return: TRUE if adding the data row suceeded, FALSE if not */ if (!is_array($values)) { throwError('First argument should be an array', __METHOD__); return false; } if ($name !== false) { $name = (string) $name; } else { $name = 'Data row ' . ($this->nrOfDataRows + 1); } $this->dataRow[] = $values; $this->dataRowNames[] = $name; $this->nrOfDataRows++; $max = max($values); $min = min($values); $this->calculateGraduation($min, $max); $this->averages[] = false; $this->averagesNames[] = false; $this->movingAverages[] = false; $this->movingAveragesNames[] = false; $this->hyperlinks[] = false; // re-calculate rect width $this->calculateRectSpecs(); return true; }
/** * * make zip archive * if exists additional paths, add additional items to the zip */ public function makeZip($srcPath, $zipFilepath, $additionPaths = array()) { if (!is_dir($srcPath)) { throwError("The path: '{$srcPath}' don't exists, can't zip"); } $this->zip = new ZipArchive(); $success = $this->zip->open($zipFilepath, ZipArchive::CREATE); if ($success == false) { throwError("Can't create zip file: {$zipFilepath}"); } $this->addItem($srcPath, $srcPath); if (gettype($additionPaths) != "array") { throwError("Wrong additional paths variable."); } //add additional paths if (!empty($additionPaths)) { foreach ($additionPaths as $path) { if (!is_dir($path)) { throwError("Path: {$path} not found, can't zip"); } $this->addItem($path, $path); } } $this->zip->close(); }
/** * Adds a new {@link WizardStep} to this wizard. * @param string $name A short id/name for this step. * @param ref object $step * @access public * @return ref object */ function addStep($name, $step) { if (count($this->getSteps())) { throwError(new Error("SingleStepWizards can only have one step. Cannot add '" . $name . "' step.", "Wizard")); } return parent::addStep($name, $step); }
function isArrayAndReturnValue($val, $index) { if (isArray($val) && array_key_exists($index, $val)) { return $val[$index]; } throwError("The array doesn't has {$index}"); }
/** * Outputs the content of the current template with $variables containing * the variable output. * @param optional mixed $variables,... Either an associative array or a {@link FieldSet} containing * a number of [key]=>content pairs. * @access public * @return void **/ function output() { // go through each argument, check if its good and set all the variables. for ($i = 0; $i < func_num_args(); $i++) { $__v = func_get_arg($i); if (is_array($__v)) { // ok, register them all as local variables foreach (array_keys($__v) as $__k) { ${$__k} = $__v[$__k]; } } else { if ($__v instanceof FieldSet) { $__keys = $__v->getKeys(); foreach ($__keys as $__k) { ${$__k} = $__v->get($__k); } } else { throwError(new Error("Template::output() - could not output: variables passed to method do not seem to be an associative array or a FieldSet.")); return false; } } } // for // otherwise, let's continue and output the file. include $this->_fullPath; }
/** * Answers the target Id for all NavBlocks in the menu * * @return string the target id * @access public * @since 4/12/06 */ function getTargetId() { if ($this->_element->hasAttribute('target_id')) { return $this->_element->getAttribute('target_id'); } throwError(new Error("No target_id available " . $this->_element->toString(true), "XmlSiteComponents")); }
/** * The constructor. * * @param long $_start the start of the time span * @param long $_end the end of the time span * * @access public * @return void */ function HarmoniTimespan($start, $end) { if ($start > $end) { throwError(new Error("The end of a Timespan cannot come before the end", "HarmoniTimespan", true)); } $this->_start = $start; $this->_end = $end; }
/** * Executes the specified action in the specified module, using the Harmoni object as a base. * @param string $module The module in which to execute. * @param string $action The specific action to execute. * @access public * @return ref mixed A {@link Layout} or TRUE/FALSE */ function executeAction($module, $action) { $fullPath = $this->_mkFullPath($module, $action); if (!$this->actionExists($module, $action)) { throwError(new Error("FlatFileActionSource::executeAction({$module}, {$action}) - could not proceed because the file to include does not exist!", "ActionHandler", true)); } $result = (include $fullPath); return $result; }
/** * Answer the string suffix for the desired muliple of 2^10 bytes * i.e. 0 -> B, 10 -> kB, 20 -> MB, 30 -> GB, etc. * * @param integer $power A multiple of 10; Range, 0-80 * @return string * @access public * @since 10/11/05 * @static */ static function suffixForPower($power) { $multiple = intval($power / 10); if ($multiple < 0 || $multiple > 8) { throwError(new Error("Invalid power, {$power}. Valid values are multiples of ten, 0-80.", "ByteSize", true)); } $suffixes = array("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); return $suffixes[$multiple]; }
function TemplateFactory($searchPath1) { if (!func_num_args()) { throwError(new Error("TemplateFactory - you must specify at least one search path.", "TemplateFactory", true)); } foreach (func_get_args() as $arg) { $this->_paths[] = $arg; } }
function __autoload($classname) { $clbase = strtolower($classname) . '.php'; $classfile = $_SERVER['DOCUMENT_ROOT'] . '/class/' . $clbase; if (file_exists($classfile)) { require $classfile; } else { throwError('missing class file'); } }
/** * Create a Tokens Object * * @return object Tokens * @access public * @since 3/1/05 */ function createTokensObject() { $tokensClass = $this->_configuration->getProperty('tokens_class'); $newTokens = new $tokensClass($this->_configuration); $validatorRule = ExtendsValidatorRule::getRule('LDAPAuthNTokens'); if ($validatorRule->check($newTokens)) { return $newTokens; } else { throwError(new Error("Configuration Error: tokens_class, '" . $tokensClass . "' does not extend UsernamePasswordAuthNTokens.", "LDAPAuthNMethod", true)); } }
/** * Sets the DebugHandler service's output level to $level. If not specified will * return the current output level. * @param optional integer $level * @static * @access public * @return integer The current debug output level. **/ static function level($level = null) { if (!Services::serviceAvailable("Debug")) { throwError(new Error("Debug::level({$level}) called but Debug service isn't available.", "debug wrapper", false)); return; } $debugHandler = Services::getService("Debug"); if (is_int($level)) { $debugHandler->setOutputLevel($level); } return $debugHandler->getOutputLevel(); }
function printTime() { if (!isset($this->_start) || !isset($this->_end)) { $err = "Must call start() and end() first."; throwError(new Error($err, "Timer", true)); } list($sm, $ss) = explode(" ", $this->_start); list($em, $es) = explode(" ", $this->_end); $s = $ss + $sm; $e = $es + $em; return $e - $s; }
function DateVersionConstraint($relativeDateString) { $now = time(); $relative = strtotime($relativeDateString, $now); if ($relative === -1) { throwError(new Error("DateVersionConstraint: the passed relative date string, '{$relativeDateString}', does not appear to be valid.", "DateVersionConstraint", true)); } if ($relativeDateString >= $now) { throwError(new Error("DateVersionConstraint: the specified relative date must be in the PAST.", "DateVersionConstraint", true)); } $this->_cutoffDate = $relative; }
/** * Return the name of the day at index. * * @param integer $anInteger * @return string * @access public * @since 5/4/05 */ static function nameOfDay($anInteger) { $names = ChronologyConstants::DayNames(); if ($names[$anInteger]) { return $names[$anInteger]; } $errorString = $anInteger . " is not a valid day index."; if (function_exists('throwError')) { throwError(new Error($errorString)); } else { die($errorString); } }
/** * The set method sets the value for a field while checking constrictions. * @param string $field The field to set. * @param mixed $val The value to set $field to. * @access public * @return boolean True if setting $field succeeds. **/ function set($field, $val) { // first check if this is a valid field. if (!in_array($field, $this->_ruleSet->getKeys())) { // no good throwError(new Error(get_class($this) . " - can not set key '{$field}' because it is not a valid key!", "UserDataContainer", true)); return false; } if ($this->_ruleSet->validate($field, $val)) { $this->_fieldSet->set($field, $val); $this->_setFields[$field] = true; return true; } return false; }
/** * The constructor. * @param string $color The HTML color. * @access public * @return void **/ function HTMLcolor($color) { $color = preg_replace("/^\\#/", "", $color); if (strlen($color) == 3) { $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2]; } if (strlen($color) != 6) { throwError(new Error("HTMLcolor - can not create class for color '{$color}': it is not a valid HTML color.", "HTMLcolor", false)); } // convert each part into its decimal equivaleng. $rgb = explode(" ", chunk_split($color, 2, " ")); $this->_red = (int) hexdec($rgb[0]); $this->_green = (int) hexdec($rgb[1]); $this->_blue = (int) hexdec($rgb[2]); }
function returnSearchString() { $mgr = Services::getService("SchemaManager"); $typeMgr = Services::getService("DataTypeManager"); $def = $mgr->getSchemaByID($this->_schemaID); $def->load(); $fieldID = $def->getFieldIDFromLabel($this->_label); $field = $def->getField($fieldID); // first check if the $value we have is of the correct data type $extendsRule = ExtendsValidatorRule::getRule("HarmoniIterator"); if (!$typeMgr->isObjectOfDataType($this->_value, $field->getType()) && !$extendsRule->check($this->_value)) { throwError(new Error("Cannot take a '" . get_class($this->_value) . "' object as search criteria\n\t\t\tfor field '{$this->_label}'; a '" . $field->getType() . "' is required.", "FieldValueSearch", true)); } $class = $typeMgr->storablePrimitiveClassForType($field->getType()); eval('$string = ' . $class . '::makeSearchString($this->_value, $this->_comparison);'); return "(dm_record_field.fk_schema_field='" . addslashes($fieldID) . "' AND " . $string . " AND dm_record_field.active=1)"; }
/** * Removes the given record from the set. * @param ref object $record A {@link DMRecord} object. * @access public * @return void */ function removeRecord($record) { $id = $record->getID(); if (!$id) { throwError(new Error("Could not remove record from set because the record does not yet have an ID.", "RecordSet", false)); return; } $newArr = array(); for ($i = 0; $i < count($this->_records); $i++) { if ($this->_records[$i]->getID() != $id) { $newArr[] = $this->_records[$i]; } } unset($this->_records); $this->_records = $newArr; $this->_dirty = true; }
/** * Output the content that was returned from an action. This content should * have been created such that it is a type that this OutputHandler can deal * with. * * @param mixed $returnedContent Content returned by the action * @param string $printedContent Additional content printed, but not returned. * @return void * @access public * @since 4/4/05 */ function output($returnedContent, $printedContent) { // alright, if what we got back was a layout, let's print it out! $rule = ExtendsValidatorRule::getRule("ComponentInterface"); if ($rule->check($returnedContent)) { $osidContext = $this->getOsidContext(); $harmoni = $osidContext->getContext('harmoni'); $doctypeDef = $this->_configuration->getProperty('document_type_definition'); $doctype = $this->_configuration->getProperty('document_type'); $characterSet = $this->_configuration->getProperty('character_set'); try { $xmlns = " xmlns=\"" . $this->_configuration->getProperty('xmlns') . "\""; } catch (Exception $e) { $xmlns = ""; } $head = $this->getHead(); $this->_theme->setComponent($returnedContent); $css = $this->_theme->getCSS("\t\t\t"); header("Content-type: {$doctype}; charset={$characterSet}"); print <<<END {$doctypeDef} <html{$xmlns}> \t<head> \t\t<meta http-equiv="Content-Type" content="{$doctype}; charset={$characterSet}" /> \t\t<style type="text/css"> {$css} \t\t</style> \t\t \t\t{$head} \t</head> \t<body> \t\t{$printedContent} \t\t END; $this->_theme->printPage(); print <<<END \t</body> </html> END; } else { // we got something else back... well, let's print out an error // explaining what happened. $type = gettype($content); throwError(new Error("Harmoni::execute() - The result returned from action '{$pair}' was unexpected. Expecting a Layout\n\t\t\t\t\tobject, but got a variable of type '{$type}'.", "Harmoni", true)); } }
/** * Adds a new menu to this theme. * @access public * @param ref object menu A <code>Menu</code> object to be added to this theme. * @param integer level A positive integer specifying the <code>level</code> of the * menu that is being added. Only one menu can exist at any given level. * Levels cannot be skipped. Levels allow the user to create a hierarchy of menus. **/ function addMenu($menu, $level) { // ** parameter validation ArgumentValidator::validate($menu, ExtendsValidatorRule::getRule("Menu"), true); $greaterThanZero = $level > 0; ArgumentValidator::validate($greaterThanZero, TrueValidatorRule::getRule(), true); // ** end of parameter validation // two things need to be true in order for this menu to be added // 1) no levels before the given are empty // 2) no menu has been set for this level already if ($level > 1 && !isset($this->_menus[$level - 1])) { $err = "Error when adding a menu to a theme: all prior menu levels must be non-empty."; throwError(new Error($err, "GUIManager", false)); return; } if (isset($this->_menus[$level])) { $err = "A menu has already been set for the given level."; throwError(new Error($err, "GUIManager", false)); return; } // now add the menu $this->_menus[$level] = $menu; }
/** * Add a subcomponent to an empty cell * * @param object SiteComponent $siteComponent * @param integer $cellIndex * @return void * @access public * @since 3/31/06 */ function addSubcomponentToCell($siteComponent, $cellIndex) { $this->normalizeCells(); $child = $this->_element->firstChild; $i = 0; $success = false; while ($child && !$success) { // is the cell we want, is empty if ($i == $cellIndex) { if (!$child->hasChildNodes()) { $child->appendChild($siteComponent->getElement()); $success = true; } else { throwError(new Error("Cell Not Empty", "SiteComponents")); } } else { $child = $child->nextSibling; $i++; } } if (!$success) { throwError(new Error("Cell {$cellIndex} Not Found", "SiteComponents")); } }
/** * Delete a Part and all its Parts. * * @param object Id $partId * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID} * * @access public */ function deletePart(Id $partId) { $string = $partId->getIdString(); if (preg_match("/(.*)-(" . implode("|", array_keys($this->_parts)) . ")/", $string, $r)) { $recordId = $r[1]; $field = $r[2]; if ($this->_isLastPart($field)) { $dbHandler = Services::getService("DatabaseManager"); // Delete the data $query = new DeleteQuery(); $query->setTable("dr_file_url"); $query->setWhere("fk_file = '" . $this->_id->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // Delete the thumbnail $query = new DeleteQuery(); $query->setTable("dr_thumbnail"); $query->setWhere("fk_file = '" . $this->_id->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // delete the file row. $query = new DeleteQuery(); $query->setTable("dr_file"); $query->setWhere("id = '" . $this->_id->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); } else { $this->_parts[$field]->updateValue("NULL"); } } else { throwError(new Error(RepositoryException::UNKNOWN_ID() . ": {$string}", "FileRecord", true)); } $this->_asset->updateModificationDate(); }
/** * Answer the days in this month on a given year. * * @param string $indexOrNameString * @param ingteger $yearInteger * @return integer * @access public * @since 5/5/05 * @static */ static function daysInMonthForYear($indexOrNameString, $yearInteger) { if (is_numeric($indexOrNameString)) { $index = $indexOrNameString; } else { $index = Month::indexOfMonth($indexOrNameString); } if ($index < 1 | $index > 12) { $errorString = $index . " is not a valid month index."; if (function_exists('throwError')) { throwError(new Error($errorString)); } else { die($errorString); } } $monthDays = ChronologyConstants::DaysInMonth(); $days = $monthDays[$index]; if ($index == 2 && Year::isYearLeapYear($yearInteger)) { return $days + 1; } else { return $days; } }
/** * Set the url of the corner image * * @param string $position * @return void * @access public * @since 11/28/05 */ function getBorderUrl($position) { if (!in_array($position, $this->_positions)) { throwError(new Error("Invalid Position, {$position}")); } return $this->_urls[$position]; }
/** * Filters nodes of incorrect type * * @param object DOMIT_Node * @return boolean * @static * @access public * @since 10/10/05 */ static function isImportable($element) { throwError(new Error(__CLASS__ . "::" . __FUNCTION__ . "() must be overridded in child classes.")); }
/** * * export slider from data, output a file for download */ public function exportSlider($useDummy = false) { $export_zip = true; if (function_exists("unzip_file") == false) { if (UniteZipRev::isZipExists() == false) { $export_zip = false; } //UniteFunctionsRev::throwError("The ZipArchive php extension not exists, can't create the export file. Please turn it on in php ini."); } if (!class_exists('ZipArchive')) { $export_zip = false; } //if(!class_exists('ZipArchive')) UniteFunctionsRev::throwError("The ZipArchive php extension not exists, can't create the export file. Please turn it on in php ini."); if ($export_zip) { $zip = new ZipArchive(); $success = $zip->open(GlobalsRevSlider::$urlExportZip, ZipArchive::OVERWRITE); if ($success == false) { throwError("Can't create zip file: " . GlobalsRevSlider::$urlExportZip); } $this->validateInited(); $sliderParams = $this->getParamsForExport(); $arrSlides = $this->getSlidesForExport($useDummy); $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides); $strExport = serialize($arrSliderExport); //$strExportAnim = serialize(RevOperations::getFullCustomAnimations()); $exportname = !empty($this->alias) ? $this->alias . '.zip' : "slider_export.zip"; $usedCaptions = array(); $usedAnimations = array(); $usedImages = array(); if (!empty($arrSlides) && count($arrSlides) > 0) { foreach ($arrSlides as $key => $slide) { if (isset($slide['params']['image']) && $slide['params']['image'] != '') { $usedImages[$slide['params']['image']] = true; } //['params']['image'] background url if (isset($slide['layers']) && !empty($slide['layers']) && count($slide['layers']) > 0) { foreach ($slide['layers'] as $lKey => $layer) { if (isset($layer['style']) && $layer['style'] != '') { $usedCaptions[$layer['style']] = true; } if (isset($layer['animation']) && $layer['animation'] != '' && strpos($layer['animation'], 'customin') !== false) { $usedAnimations[str_replace('customin-', '', $layer['animation'])] = true; } if (isset($layer['endanimation']) && $layer['endanimation'] != '' && strpos($layer['endanimation'], 'customout') !== false) { $usedAnimations[str_replace('customout-', '', $layer['endanimation'])] = true; } if (isset($layer['image_url']) && $layer['image_url'] != '') { $usedImages[$layer['image_url']] = true; } //image_url if image caption } } } } $styles = ''; if (!empty($usedCaptions)) { $captions = array(); foreach ($usedCaptions as $class => $val) { $captions[] = RevOperations::getCaptionsContentArray($class); } $styles = UniteCssParserRev::parseArrayToCss($captions, "\n"); } $animations = ''; if (!empty($usedAnimations)) { $animation = array(); foreach ($usedAnimations as $anim => $val) { $anima = RevOperations::getFullCustomAnimationByID($anim); if ($anima !== false) { $animation[] = RevOperations::getFullCustomAnimationByID($anim); } } if (!empty($animation)) { $animations = serialize($animation); } } //add images to zip if (!empty($usedImages)) { $upload_dir = UniteFunctionsWPRev::getPathUploads(); foreach ($usedImages as $file => $val) { if ($useDummy == "true") { //only use dummy images } else { //use the real images $zip->addFile($upload_dir . $file, 'images/' . $file); } } } $zip->addFromString("slider_export.txt", $strExport); //add slider settings if (strlen(trim($animations)) > 0) { $zip->addFromString("custom_animations.txt", $animations); } //add custom animations if (strlen(trim($styles)) > 0) { $zip->addFromString("dynamic-captions.css", $styles); } //add dynamic styles //$zip->addFromString("custom_animations.txt", $strExportAnim); //add custom animations //$zip->addFile(GlobalsRevSlider::$filepath_dynamic_captions,'dynamic-captions.css'); //add dynamic styles $zip->addFile(GlobalsRevSlider::$filepath_static_captions, 'static-captions.css'); //add static styles $zip->close(); header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=" . $exportname); header("Pragma: no-cache"); header("Expires: 0"); readfile(GlobalsRevSlider::$urlExportZip); @unlink(GlobalsRevSlider::$urlExportZip); //delete file after sending it to user } else { //fallback, do old export $this->validateInited(); $sliderParams = $this->getParamsForExport(); $arrSlides = $this->getSlidesForExport(); $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides); $strExport = serialize($arrSliderExport); if (!empty($this->alias)) { $filename = $this->alias . ".txt"; } else { $filename = "slider_export.txt"; } UniteFunctionsRev::downloadFile($strExport, $filename); } }
/** * Get all the PartStructures in the RecordStructure. Iterators return a * set, one at a time. * * @return object PartStructureIterator * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED} * * @access public */ function getPartStructure(Id $partStructureId) { if ($this->_partStructures[$partStructureId->getIdString()]) { return $this->_partStructures[$partStructureId->getIdString()]; } else { throwError(new Error(RepositoryException::UNKNOWN_ID(), "Repository :: FileRecordStructure", TRUE)); } }