/** * */ public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null) { if (!$this->opb_ffmpeg_available) { return false; } $o_tc = new TimecodeParser(); $vn_start = $vn_end = null; if ($o_tc->parse($ps_start)) { $vn_start = $o_tc->getSeconds(); } if ($o_tc->parse($ps_end)) { $vn_end = $o_tc->getSeconds(); } if (!$vn_start || !$vn_end) { return null; } if ($vn_start >= $vn_end) { return null; } $vn_duration = $vn_end - $vn_start; exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration} -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caGetOSFamily() == OS_POSIX ? " 2> /dev/null" : ""), $va_output, $vn_return); if ($vn_return != 0) { @unlink($filepath . "." . $ext); $this->postError(1610, _t("Error extracting clip from %1 to %2: %3", $ps_start, $ps_end, join("; ", $va_output)), "WLPlugVideo->writeClip()"); return false; } return true; }
public function write($filepath, $mimetype, $pa_options = null) { if (!$this->handle) { return false; } if (!($ext = $this->info["EXPORT"][$mimetype])) { # this plugin can't write this mimetype return false; } # is mimetype valid? switch ($mimetype) { # ------------------------------------ case 'image/jpeg': $vn_preview_width = $this->properties["width"]; $vn_preview_height = $this->properties["height"]; if (caMediaPluginFFfmpegInstalled($this->ops_path_to_ffmpeg) && $this->handle["mime_type"] != "application/x-shockwave-flash") { if (($vn_start_secs = $this->properties["duration"] / 8) > 120) { $vn_start_secs = 120; // always take a frame from the first two minutes to ensure performance (ffmpeg gets slow if it has to seek far into a movie to extract a frame) } exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f image2 -ss " . $vn_start_secs . " -t 0.04 -s {$vn_preview_width}x{$vn_preview_height} -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); if ($vn_return < 0 || $vn_return > 1 || !@filesize($filepath . "." . $ext)) { @unlink($filepath . "." . $ext); // try again, with -ss 1 (seems to work consistently on some files where other -ss values won't work) exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f image2 -ss " . $vn_start_secs . " -t 1 -s {$vn_preview_width}x{$vn_preview_height} -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); } if ($vn_return < 0 || $vn_return > 1 || !@filesize($filepath . "." . $ext)) { @unlink($filepath . "." . $ext); // don't throw error as ffmpeg cannot generate frame still from all file } } $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = isset($this->typenames[$mimetype]) ? $this->typenames[$mimetype] : $mimetype; break; # ------------------------------------ # ------------------------------------ case 'image/png': $vn_preview_width = $this->properties["width"]; $vn_preview_height = $this->properties["height"]; if (caMediaPluginFFfmpegInstalled($this->ops_path_to_ffmpeg) && $this->handle["mime_type"] != "application/x-shockwave-flash") { if (($vn_start_secs = $this->properties["duration"] / 8) > 120) { $vn_start_secs = 120; // always take a frame from the first two minutes to ensure performance (ffmpeg gets slow if it has to seek far into a movie to extract a frame) } exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -vcodec png -ss " . $vn_start_secs . " -t 0.04 -s {$vn_preview_width}x{$vn_preview_height} -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); if ($vn_return < 0 || $vn_return > 1 || !@filesize($filepath . "." . $ext)) { @unlink($filepath . "." . $ext); // try again, with -ss 1 (seems to work consistently on some files where other -ss values won't work) exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -vcodec png -ss " . $vn_start_secs . " -t 1 -s {$vn_preview_width}x{$vn_preview_height} -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); } if ($vn_return < 0 || $vn_return > 1 || !@filesize($filepath . "." . $ext)) { @unlink($filepath . "." . $ext); // don't throw error as ffmpeg cannot generate frame still from all file } } $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = isset($this->typenames[$mimetype]) ? $this->typenames[$mimetype] : $mimetype; break; # ------------------------------------ # ------------------------------------ case 'video/x-flv': if (caMediaPluginFFfmpegInstalled($this->ops_path_to_ffmpeg)) { $vn_video_bitrate = $this->get('video_bitrate'); if ($vn_video_bitrate < 20000) { $vn_video_bitrate = 256000; } $vn_audio_bitrate = $this->get('audio_bitrate'); if ($vn_audio_bitrate < 8000) { $vn_audio_bitrate = 32000; } $vn_audio_sample_freq = $this->get('audio_sample_freq'); if ($vn_audio_sample_freq != 44100 && $vn_audio_sample_freq != 22050 && $vn_audio_sample_freq != 11025) { $vn_audio_sample_freq = 44100; } exec($vs_cmd = $this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f flv -b " . intval($vn_video_bitrate) . " -ab " . intval($vn_audio_bitrate) . " -ar " . intval($vn_audio_sample_freq) . " -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); if ($vn_return < 0 || $vn_return > 1 || filesize($filepath . "." . $ext) == 0) { @unlink($filepath . "." . $ext); $this->postError(1610, _t("Couldn't convert file to FLV format"), "WLPlugVideo->write()"); return false; } $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = $this->typenames[$mimetype]; } break; # ------------------------------------ # ------------------------------------ case 'video/mpeg': case 'video/ogg': // only support "command" option... if (caMediaPluginFFfmpegInstalled($this->ops_path_to_ffmpeg)) { $va_ffmpeg_params = array(); if (!($vs_ffmpeg_command = $this->get('command'))) { // Video bitrate $vn_video_bitrate = $this->get('video_bitrate'); if ($vn_video_bitrate != '') { if ($vn_video_bitrate < 20000) { $vn_video_bitrate = 256000; } $va_ffmpeg_params["video_bitrate"] = "-b " . intval($vn_video_bitrate); } // Audio bitrate $vn_audio_bitrate = $this->get('audio_bitrate'); if ($vn_audio_bitrate < 8000) { $vn_audio_bitrate = 32000; } $va_ffmpeg_params["audio_bitrate"] = "-ab " . intval($vn_audio_bitrate); // Audio sample frequency $vn_audio_sample_freq = $this->get('audio_sample_freq'); if ($vn_audio_sample_freq != 44100 && $vn_audio_sample_freq != 22050 && $vn_audio_sample_freq != 11025) { $vn_audio_sample_freq = 44100; } $va_ffmpeg_params["audio_sample_freq"] = "-ar " . intval($vn_audio_sample_freq); // Multithreading $vn_threads = $this->get('threads'); if ($vn_threads < 1 || $vn_threads == '') { $vn_threads = 1; } $va_ffmpeg_params["threads"] = "-threads " . $vn_threads; // Quantitizers $vn_qmin = $this->get('qmin'); if ($vn_qmin != '') { $va_ffmpeg_params["qmin"] = "-qmin " . $vn_qmin; } $vn_qmax = $this->get('qmax'); if ($vn_qmax != '') { $va_ffmpeg_params["qmax"] = "-qmax " . $vn_qmax; } // Flags if (($vs_flags = $this->get('flags')) != '') { $va_ffmpeg_params["flags"] = "-flags " . $vs_flags; } // Resolution if (($vs_res = $this->get('resolution')) != '') { $va_ffmpeg_params["resolution"] = "-s " . $vs_res; } // Coder if (($vn_coder = $this->get('coder')) != '') { $va_ffmpeg_params["coder"] = "-coder " . $vn_coder; } // 2-pass encoding if ($this->get('twopass')) { $vb_twopass = true; } else { $vb_twopass = false; } // qdiff if (($vs_qdiff = $this->get('qdiff')) != '') { $va_ffmpeg_params["qdiff"] = "-qdiff " . $vs_qdiff; } // partitions if (($vs_partitions = $this->get('partitions')) != '') { $va_ffmpeg_params["partitions"] = "-partitions " . $vs_partitions; } // cmp if (($vs_cmp = $this->get('cmp')) != '') { $va_ffmpeg_params["cmp"] = "-cmp " . $vs_cmp; } // qdiff if (($vs_sc_threshold = $this->get('sc_threshold')) != '') { $va_ffmpeg_params["sc_threshold"] = "-sc_threshold " . $vs_sc_threshold; } // vpre if (!($vs_vpreset = $this->get('vpre')) != '') { $vs_vpreset = null; } } // put it all together // we need to be in a directory where we can write (libx264 logfiles) $vs_cwd = getcwd(); chdir(__CA_APP_DIR__ . "/tmp/"); $vs_cmd = ''; if ($vs_ffmpeg_command) { exec($vs_cmd .= $this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " {$vs_ffmpeg_command} " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); } else { if ($vs_vpreset) { $vs_other_params = ""; if ($vn_audio_bitrate) { $vs_other_params .= "-ab {$vn_audio_bitrate} "; } if ($vn_audio_sample_freq) { $vs_other_params .= "-ar {$vn_audio_sample_freq} "; } if ($vs_res && $vs_res != '') { $vs_other_params .= "-s " . $vs_res; } exec($vs_cmd .= $this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec libfaac {$vs_other_params} -vpre {$vs_vpreset} -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); } else { if (!$vb_twopass) { exec($vs_cmd .= $this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec libfaac " . join(" ", $va_ffmpeg_params) . " -y " . caEscapeShellArg($filepath . "." . $ext) . (caGetOSFamily() == OS_POSIX ? " 2> /dev/null" : ""), $va_output, $vn_return); } else { exec($vs_cmd .= $this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -pass 1 -acodec libfaac " . join(" ", $va_ffmpeg_params) . " -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); exec($vs_cmd .= $this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -pass 2 -acodec libfaac " . join(" ", $va_ffmpeg_params) . " -y " . caEscapeShellArg($filepath . "." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); // probably cleanup logfiles here } } } chdir($vs_cwd); // avoid fun side-effects if (@filesize($filepath . "." . $ext) == 0) { @unlink($filepath . "." . $ext); if ($vs_vpreset) { $this->postError(1610, _t("Couldn't convert file to MPEG4 format [%1]; does the ffmpeg preset '%2' exist? (command was %3)", $vn_return, $vs_vpreset, $vs_cmd), "WLPlugVideo->write()"); } else { $this->postError(1610, _t("Couldn't convert file to MPEG4 format [%1] (command was %2)", $vn_return, $vs_cmd), "WLPlugVideo->write()"); } return false; } // try to hint for streaming if (file_exists($this->ops_path_to_qt_faststart)) { exec($this->ops_path_to_qt_faststart . " " . caEscapeShellArg($filepath . "." . $ext) . " " . caEscapeShellArg($filepath . "_tmp." . $ext) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return); rename("{$filepath}_tmp.{$ext}", "{$filepath}.{$ext}"); } # ------------------------------------ $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = $this->typenames[$mimetype]; } break; # ------------------------------------ # ------------------------------------ default: if ($mimetype != $this->handle["mime_type"]) { # this plugin can't write this mimetype (no conversions allowed) $this->postError(1610, _t("Can't convert '%1' to %2", $this->handle["mime_type"], $mimetype), "WLPlugVideo->write()"); return false; } # write the file if (!copy($this->filepath, $filepath . "." . $ext)) { $this->postError(1610, _t("Couldn't write file to '%1'", $filepath), "WLPlugVideo->write()"); return false; } break; # ------------------------------------ } // if output file doesn't exist, ffmpeg failed or isn't installed // so use default icons if (!file_exists($filepath . "." . $ext)) { # use default media icons return __CA_MEDIA_VIDEO_DEFAULT_ICON__; } return $filepath . "." . $ext; }
/** * Set field value(s) for the table row represented by this object * * @param string|array string $pa_fields representation of a field name * or array of string representations of field names * @param mixed $pm_value value to set the given field(s) to * @param array $pa_options associative array of options * possible options (keys): * when dealing with date/time fields: * - SET_DIRECT_DATE * - SET_DIRECT_TIME * - SET_DIRECT_TIMES * * for media/files fields: * - original_filename : (note that it is lower case) optional parameter which enables you to pass the original filename of a file, in addition to the representation in the temporary, global _FILES array; * * for text fields: * - purify : if set then text input is run through HTML Purifier before being set * * for parent_id field: * - treatParentIDAsIdno: force parent_id value to be used as idno lookup rather than a primary key value */ public function set($pa_fields, $pm_value = "", $pa_options = null) { $this->errors = array(); if (!is_array($pa_fields)) { $pa_fields = array($pa_fields => $pm_value); } foreach ($pa_fields as $vs_field => $vm_value) { if (array_key_exists($vs_field, $this->FIELDS)) { $pa_fields_type = $this->getFieldInfo($vs_field, "FIELD_TYPE"); $pb_need_reload = false; if (!$this->verifyFieldValue($vs_field, $vm_value, $pb_need_reload)) { return false; } if ($pb_need_reload) { return true; } // was set to default if ($vs_field == $this->primaryKey()) { $vm_value = preg_replace("/[\"']/", "", $vm_value); } $vs_cur_value = isset($this->_FIELD_VALUES[$vs_field]) ? $this->_FIELD_VALUES[$vs_field] : null; switch ($pa_fields_type) { case FT_NUMBER: if ($vs_cur_value != $vm_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } if ($vs_field == $this->HIERARCHY_PARENT_ID_FLD && (strlen($vm_value) > 0 && (!is_numeric($vm_value) || caGetOption('treatParentIDAsIdno', $pa_options, false)))) { if (is_array($va_ids = call_user_func_array($this->tableName() . "::find", array(array('idno' => $vm_value, 'deleted' => 0), array('returnAs' => 'ids', 'transaction' => $this->getTransaction()))))) { $vm_value = array_shift($va_ids); } } if ($vm_value !== "" || $this->getFieldInfo($vs_field, "IS_NULL") && $vm_value == "") { if ($vm_value) { if (($vs_list_code = $this->getFieldInfo($vs_field, "LIST_CODE")) && !is_numeric($vm_value)) { // translate ca_list_item idno's into item_ids if necessary if ($vn_id = ca_lists::getItemID($vs_list_code, $vm_value)) { $vm_value = $vn_id; } else { $this->postError(1103, _t('Value %1 is not in list %2', $vm_value, $vs_list_code), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } } else { $vm_orig_value = $vm_value; $vm_value = preg_replace("/[^\\d-.]+/", "", $vm_value); # strip non-numeric characters if (!preg_match("/^[\\-]{0,1}[\\d.]+\$/", $vm_value)) { $this->postError(1100, _t("'%1' for %2 is not numeric", $vm_orig_value, $vs_field), "BaseModel->set()", $this->tableName() . '.' . $vs_field); return false; } } } $this->_FIELD_VALUES[$vs_field] = $vm_value; } break; case FT_BIT: if ($vs_cur_value != $vm_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vm_value ? 1 : 0; break; case FT_DATETIME: case FT_HISTORIC_DATETIME: case FT_DATE: case FT_HISTORIC_DATE: if ($this->DIRECT_DATETIMES || $pa_options["SET_DIRECT_DATE"]) { $this->_FIELD_VALUES[$vs_field] = $vm_value; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($vs_cur_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = null; } else { $o_tep = new TimeExpressionParser(); if ($pa_fields_type == FT_DATE || $pa_fields_type == FT_HISTORIC_DATE) { $va_timestamps = $o_tep->parseDate($vm_value); } else { $va_timestamps = $o_tep->parseDatetime($vm_value); } if (!$va_timestamps) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } if ($pa_fields_type == FT_HISTORIC_DATETIME || $pa_fields_type == FT_HISTORIC_DATE) { if ($vs_cur_value != $va_timestamps["start"]) { $this->_FIELD_VALUES[$vs_field] = $va_timestamps["start"]; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } else { $va_timestamps = $o_tep->getUnixTimestamps(); if ($va_timestamps[0] == -1) { $this->postError(1830, $o_tep->getParseErrorMessage(), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } if ($vs_cur_value != $va_timestamps["start"]) { $this->_FIELD_VALUES[$vs_field] = $va_timestamps["start"]; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } } } break; case FT_TIME: if ($this->DIRECT_TIMES || $pa_options["SET_DIRECT_TIME"]) { $this->_FIELD_VALUES[$vs_field] = $vm_value; } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($vs_cur_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = null; } else { $o_tep = new TimeExpressionParser(); if (!$o_tep->parseTime($vm_value)) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } $va_times = $o_tep->getTimes(); if ($vs_cur_value != $va_times['start']) { $this->_FIELD_VALUES[$vs_field] = $va_times['start']; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } } break; case FT_TIMESTAMP: # can't set timestamp break; case FT_DATERANGE: case FT_HISTORIC_DATERANGE: $vs_start_field_name = $this->getFieldInfo($vs_field, "START"); $vs_end_field_name = $this->getFieldInfo($vs_field, "END"); $vn_start_date = isset($this->_FIELD_VALUES[$vs_start_field_name]) ? $this->_FIELD_VALUES[$vs_start_field_name] : null; $vn_end_date = isset($this->_FIELD_VALUES[$vs_end_field_name]) ? $this->_FIELD_VALUES[$vs_end_field_name] : null; if ($this->DIRECT_DATETIMES || $pa_options["SET_DIRECT_DATE"]) { if (is_array($vm_value) && sizeof($vm_value) == 2 && $vm_value[0] <= $vm_value[1]) { if ($vn_start_date != $vm_value[0]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $vm_value[0]; } if ($vn_end_date != $vm_value[1]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $vm_value[1]; } } else { $this->postError(1100, _t("Invalid direct date values"), "BaseModel->set()", $this->tableName() . '.' . $vs_field); } } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($vn_start_date || $vn_end_date) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_start_field_name] = null; $this->_FIELD_VALUES[$vs_end_field_name] = null; } else { $o_tep = new TimeExpressionParser(); if (!$o_tep->parseDatetime($vm_value)) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } if ($pa_fields_type == FT_HISTORIC_DATERANGE) { $va_timestamps = $o_tep->getHistoricTimestamps(); } else { $va_timestamps = $o_tep->getUnixTimestamps(); if ($va_timestamps[0] == -1) { $this->postError(1830, $o_tep->getParseErrorMessage(), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } } if ($vn_start_date != $va_timestamps["start"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $va_timestamps["start"]; } if ($vn_end_date != $va_timestamps["end"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $va_timestamps["end"]; } } } break; case FT_TIMERANGE: $vs_start_field_name = $this->getFieldInfo($vs_field, "START"); $vs_end_field_name = $this->getFieldInfo($vs_field, "END"); if ($this->DIRECT_TIMES || $pa_options["SET_DIRECT_TIMES"]) { if (is_array($vm_value) && sizeof($vm_value) == 2 && $vm_value[0] <= $vm_value[1]) { if ($this->_FIELD_VALUES[$vs_start_field_name] != $vm_value[0]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $vm_value[0]; } if ($this->_FIELD_VALUES[$vs_end_field_name] != $vm_value[1]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $vm_value[1]; } } else { $this->postError(1100, _t("Invalid direct time values"), "BaseModel->set()", $this->tableName() . '.' . $vs_field); } } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($this->_FIELD_VALUES[$vs_start_field_name] || $this->_FIELD_VALUES[$vs_end_field_name]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_start_field_name] = null; $this->_FIELD_VALUES[$vs_end_field_name] = null; } else { $o_tep = new TimeExpressionParser(); if (!$o_tep->parseTime($vm_value)) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()', $this->tableName() . '.' . $vs_field); return false; } $va_timestamps = $o_tep->getTimes(); if ($this->_FIELD_VALUES[$vs_start_field_name] != $va_timestamps["start"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $va_timestamps["start"]; } if ($this->_FIELD_VALUES[$vs_end_field_name] != $va_timestamps["end"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $va_timestamps["end"]; } } } break; case FT_TIMECODE: $o_tp = new TimecodeParser(); if ($o_tp->parse($vm_value)) { if ($o_tp->getParsedValueInSeconds() != $vs_cur_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_field] = $o_tp->getParsedValueInSeconds(); } } break; case FT_TEXT: $vm_value = (string) $vm_value; if (is_string($vm_value)) { $vm_value = stripSlashes($vm_value); } if (isset($pa_options['purify']) && $pa_options['purify'] || (bool) $this->opb_purify_input || $this->getFieldInfo($vs_field, "PURIFY")) { $vm_value = BaseModel::getPurifier()->purify((string) $vm_value); } if ($this->getFieldInfo($vs_field, "DISPLAY_TYPE") == DT_LIST_MULTIPLE) { if (is_array($vm_value)) { if (!($vs_list_multiple_delimiter = $this->getFieldInfo($vs_field, 'LIST_MULTIPLE_DELIMITER'))) { $vs_list_multiple_delimiter = ';'; } $vs_string_value = join($vs_list_multiple_delimiter, $vm_value); $vs_string_value = str_replace("", '', $vs_string_value); if ($vs_cur_value !== $vs_string_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vs_string_value; } } else { $vm_value = str_replace("", '', $vm_value); if ($this->getFieldInfo($vs_field, "ENTITY_ENCODE_INPUT")) { $vs_value_entity_encoded = htmlentities(html_entity_decode($vm_value)); if ($vs_cur_value !== $vs_value_entity_encoded) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vs_value_entity_encoded; } else { if ($this->getFieldInfo($vs_field, "URL_ENCODE_INPUT")) { $vs_value_url_encoded = urlencode($vm_value); if ($vs_cur_value !== $vs_value_url_encoded) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vs_value_url_encoded; } else { if ($vs_cur_value !== $vm_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vm_value; } } } break; case FT_PASSWORD: if (isset($pa_options['purify']) && $pa_options['purify'] || (bool) $this->opb_purify_input || $this->getFieldInfo($vs_field, "PURIFY")) { $vm_value = BaseModel::getPurifier()->purify((string) $vm_value); } if (!$vm_value) { // store blank passwords as blank, $this->_FIELD_VALUES[$vs_field] = ""; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } else { // leave the treatment of the password to the AuthAdapter, i.e. don't do hashing here if ($vs_cur_value != $vm_value) { $this->_FIELD_VALUES[$vs_field] = $vm_value; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } break; case FT_VARS: if (md5(print_r($vs_cur_value, true)) != md5(print_r($vm_value, true))) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vm_value; break; case FT_MEDIA: case FT_FILE: $vb_allow_fetching_of_urls = (bool) $this->_CONFIG->get('allow_fetching_of_media_from_remote_urls'); # if there's a tmp_name is the global _FILES array # then we'll process it in insert()/update()... $this->_SET_FILES[$vs_field]['options'] = $pa_options; if (caGetOSFamily() == OS_WIN32) { // fix for paths using backslashes on Windows failing in processing $vm_value = str_replace('\\', '/', $vm_value); } if (isset($pa_options['purify']) && $pa_options['purify'] || (bool) $this->opb_purify_input || $this->getFieldInfo($vs_field, "PURIFY")) { $pa_options["original_filename"] = BaseModel::getPurifier()->purify((string) $pa_options["original_filename"]); $vm_value = BaseModel::getPurifier()->purify((string) $vm_value); } $va_matches = null; if (is_string($vm_value) && (file_exists($vm_value) || $vb_allow_fetching_of_urls && isURL($vm_value) || preg_match("!^userMedia[\\d]+/!", $vm_value))) { $this->_SET_FILES[$vs_field]['original_filename'] = $pa_options["original_filename"]; $this->_SET_FILES[$vs_field]['tmp_name'] = $vm_value; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } else { # only return error when file name is not 'none' # 'none' is PHP's stupid way of telling you there # isn't a file... if ($vm_value != "none" && $vm_value) { //$this->postError(1500,_t("%1 does not exist", $vm_value),"BaseModel->set()", $this->tableName().'.'.$vs_field); } return false; } break; default: die("Invalid field type in BaseModel->set()"); break; } } else { $this->postError(710, _t("'%1' does not exist in this object", $vs_field), "BaseModel->set()", $this->tableName() . '.' . $vs_field); return false; } } return true; }
/** * Returns true if running on a POSIX system * * @return bool */ function caIsPOSIX() { return caGetOSFamily() === OS_POSIX; }
public function write($ps_filepath, $mimetype) { if (!$this->handle) { return false; } if (strpos($ps_filepath, ':') && caGetOSFamily() != OS_WIN32) { $this->postError(1610, _t("Filenames with colons (:) are not allowed"), "WLPlugGmagick->write()"); return false; } if ($mimetype == "image/tilepic") { if ($this->properties["mimetype"] == "image/tilepic") { copy($this->filepath, $ps_filepath); } else { $tp = new TilepicParser(); if (!($properties = $tp->encode($this->filepath, $ps_filepath, array("tile_width" => $this->properties["tile_width"], "tile_height" => $this->properties["tile_height"], "layer_ratio" => $this->properties["layer_ratio"], "quality" => $this->properties["quality"], "antialiasing" => $this->properties["antialiasing"], "output_mimetype" => $this->properties["tile_mimetype"], "layers" => $this->properties["layers"])))) { $this->postError(1610, $tp->error, "WLPlugTilepic->write()"); return false; } } # update mimetype foreach ($properties as $k => $v) { $this->properties[$k] = $v; } $this->properties["mimetype"] = "image/tilepic"; $this->properties["typename"] = "Tilepic"; return 1; } else { # is mimetype valid? if (!($ext = $this->info["EXPORT"][$mimetype])) { # this plugin can't write this mimetype return false; } $this->handle->setimageformat($this->magick_names[$mimetype]); # set quality if ($this->properties["quality"] && $this->properties["mimetype"] != "image/tiff") { $this->handle->setcompressionquality($this->properties["quality"]); } $this->handle->setimagebackgroundcolor(new GmagickPixel("#CC0000")); if ($this->properties['gamma']) { if (!$this->properties['reference-black']) { $this->properties['reference-black'] = 0; } if (!$this->properties['reference-white']) { $this->properties['reference-white'] = 65535; } $this->handle->levelimage($this->properties['reference-black'], $this->properties['gamma'], $this->properties['reference-white']); } $this->handle->stripimage(); // remove all lingering metadata # write the file try { if (!$this->handle->writeimage($ps_filepath . "." . $ext)) { $this->postError(1610, _t("Error writing file"), "WLPlugGmagick->write()"); return false; } if (!file_exists($ps_filepath . "." . $ext)) { if ($this->handle->getnumberimages() > 1) { if (file_exists($ps_filepath . "-1." . $ext)) { @rename($ps_filepath . "-0." . $ext, $ps_filepath . "." . $ext); $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = $this->handle->getimageformat(); // get rid of other pages $i = 1; while (file_exists($vs_f = $ps_filepath . "-" . $i . "." . $ext)) { @unlink($vs_f); $i++; } return $ps_filepath . "." . $ext; } } $this->postError(1610, _t("Error writing file"), "WLPlugGmagick->write()"); return false; } } catch (Exception $e) { $this->postError(1610, _t("Error writing file: %1", $e->getMessage()), "WLPlugGmagick->write()"); return false; } # update mimetype $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = $this->handle->getimageformat(); return $ps_filepath . "." . $ext; } }
/** * I suspect that the application would die before we even reach this check if the base dir is messed up? */ public static function caBaseDirQuickCheck() { $vs_script_filename = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]); $va_script_name_parts = explode("/", $vs_script_filename); $vs_script_called = $va_script_name_parts[sizeof($va_script_name_parts) - 1]; // index.php or service.php $vs_probably_correct_base = str_replace("/{$vs_script_called}", "", $vs_script_filename); if (caGetOSFamily() === OS_WIN32) { // Windows paths are case insensitive if (strcasecmp($vs_probably_correct_base, __CA_BASE_DIR__) != 0) { self::addError(_t("It looks like the __CA_BASE_DIR__ variable in your setup.php is not set correctly. Please try to set it to "%1". We came up with this suggestion because the location of this script is "%2".", $vs_probably_correct_base, $vs_script_filename)); } } else { if (!($vs_probably_correct_base == __CA_BASE_DIR__)) { self::addError(_t("It looks like the __CA_BASE_DIR__ variable in your setup.php is not set correctly. Please try to set it to "%1". We came up with this suggestion because the location of this script is "%2". Note that paths are case sensitive.", $vs_probably_correct_base, $vs_script_filename)); } } return true; }
public function write($filepath, $mimetype) { if (!$this->handle) { return false; } if (strpos($filepath, ':') && caGetOSFamily() != OS_WIN32) { $this->postError(1610, _t("Filenames with colons (:) are not allowed"), "WLPlugImageMagick->write()"); return false; } if ($mimetype == "image/tilepic") { if ($this->properties["mimetype"] == "image/tilepic") { copy($this->filepath, $filepath); } else { $tp = new TilepicParser(); if (!($properties = $tp->encode($this->filepath, $filepath, array("tile_width" => $this->properties["tile_width"], "tile_height" => $this->properties["tile_height"], "layer_ratio" => $this->properties["layer_ratio"], "quality" => $this->properties["quality"], "antialiasing" => $this->properties["antialiasing"], "output_mimetype" => $this->properties["tile_mimetype"], "layers" => $this->properties["layers"])))) { $this->postError(1610, $tp->error, "WLPlugTilepic->write()"); return false; } } # update mimetype foreach ($properties as $k => $v) { $this->properties[$k] = $v; } $this->properties["mimetype"] = "image/tilepic"; $this->properties["typename"] = "Tilepic"; return 1; } else { # is mimetype valid? if (!($ext = $this->info["EXPORT"][$mimetype])) { # this plugin can't write this mimetype return false; } if (!$this->_graphicsMagickWrite($this->handle, $filepath . "." . $ext, $mimetype, $this->properties["quality"])) { $this->postError(1610, _t("Could not write file %1", $filepath . "." . $ext), "WLPlugImageMagick->write()"); return false; } # update mimetype $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = $this->magick_names[$mimetype]; return $filepath . "." . $ext; } }
/** * Detects if ExifTool (http://www.sno.phy.queensu.ca/~phil/exiftool/) is installed in the given path. * * @param string $ps_exiftool_path path to ExifTool * @return boolean */ function caExifToolInstalled($ps_exiftool_path = null) { if (!$ps_exiftool_path) { $ps_exiftool_path = caGetExternalApplicationPath('exiftool'); } global $_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL; if (isset($_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL[$ps_exiftool_path])) { return $_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL[$ps_exiftool_path]; } else { $_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL = array(); } if (!trim($ps_exiftool_path) || preg_match("/[^\\/A-Za-z0-9\\.:]+/", $ps_exiftool_path) || !file_exists($ps_exiftool_path)) { return false; } if (!file_exists($ps_exiftool_path)) { return $_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL[$ps_exiftool_path] = false; } if (caGetOSFamily() == OS_WIN32) { return true; } // don't try exec test on Windows exec($ps_exiftool_path . " > /dev/null", $va_output, $vn_return); if ($vn_return == 0) { return $_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL[$ps_exiftool_path] = true; } return $_MEDIAHELPER_PLUGIN_CACHE_EXIFTOOL[$ps_exiftool_path] = false; }
function processExists($pn_proc_id) { if (!$this->canDetectProcesses()) { return null; } switch (caGetOSFamily()) { case OS_WIN32: $va_proc_info = win32_ps_stat_proc($pn_proc_id); return is_array($va_proc_info); break; default: return posix_kill($pn_proc_id, 0) ? true : false; break; } }
public static function lockRelease() { if (function_exists('sem_get') && caGetOSFamily() == OS_POSIX) { if (!self::$s_lock_resource) { self::$s_lock_resource = sem_get(ftok(__FILE__, 'CASearchIndexingQueue')); } sem_release(self::$s_lock_resource); } else { if (is_resource(self::$s_lock_resource)) { @fclose(self::$s_lock_resource); } @unlink(caGetTempDirPath() . DIRECTORY_SEPARATOR . 'search_indexing_queue.lock'); } }
/** * Set field value(s) for the table row represented by this object * * @param string|array string $pa_fields representation of a field name * or array of string representations of field names * @param mixed $pm_value value to set the given field(s) to * @param array $pa_options associative array of options * possible options (keys): * when dealing with date/time fields: * - SET_DIRECT_DATE * - SET_DIRECT_TIME * - SET_DIRECT_TIMES * * for media/files fields: * - original_filename : (note that it is lower case) optional parameter which enables you to pass the original filename of a file, in addition to the representation in the temporary, global _FILES array; * * for text fields: * - purify : if set then text input is run through HTML Purifier before being set */ public function set($pa_fields, $pm_value = "", $pa_options = null) { $this->errors = array(); if (!is_array($pa_fields)) { $pa_fields = array($pa_fields => $pm_value); } foreach ($pa_fields as $vs_field => $vm_value) { if (array_key_exists($vs_field, $this->FIELDS)) { $pa_fields_type = $this->getFieldInfo($vs_field, "FIELD_TYPE"); $pb_need_reload = false; if (!$this->verifyFieldValue($vs_field, $vm_value, $pb_need_reload)) { return false; } if ($pb_need_reload) { return true; } // was set to default if ($vs_field == $this->primaryKey()) { $vm_value = preg_replace("/[\"']/", "", $vm_value); } // what markup is supported for text fields? $vs_markup_type = $this->getFieldInfo($vs_field, "MARKUP_TYPE"); // if markup is non-HTML then strip out HTML special chars for safety if (!($vs_markup_type == __CA_MT_HTML__)) { $vm_value = htmlspecialchars($vm_value, ENT_QUOTES, 'UTF-8'); } $vs_cur_value = isset($this->_FIELD_VALUES[$vs_field]) ? $this->_FIELD_VALUES[$vs_field] : null; switch ($pa_fields_type) { case FT_NUMBER: if ($vs_cur_value != $vm_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } if ($vm_value !== "" || $this->getFieldInfo($vs_field, "IS_NULL") && $vm_value == "") { if ($vm_value) { if (($vs_list_code = $this->getFieldInfo($vs_field, "LIST_CODE")) && !is_numeric($vm_value)) { // translate ca_list_item idno's into item_ids if necessary if ($vn_id = ca_lists::getItemID($vs_list_code, $vm_value)) { $vm_value = $vn_id; } } else { $vm_orig_value = $vm_value; $vm_value = preg_replace("/[^\\d-.]+/", "", $vm_value); # strip non-numeric characters if (!preg_match("/^[\\-]{0,1}[\\d.]+\$/", $vm_value)) { $this->postError(1100, _t("'%1' for %2 is not numeric", $vm_orig_value, $vs_field), "BaseModel->set()"); return ""; } } } $this->_FIELD_VALUES[$vs_field] = $vm_value; } break; case FT_BIT: if ($vs_cur_value != $vm_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vm_value ? 1 : 0; break; case FT_DATETIME: case FT_HISTORIC_DATETIME: case FT_DATE: case FT_HISTORIC_DATE: if ($this->DIRECT_DATETIMES || $pa_options["SET_DIRECT_DATE"]) { $this->_FIELD_VALUES[$vs_field] = $vm_value; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($vs_cur_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = null; } else { $o_tep = new TimeExpressionParser(); if ($pa_fields_type == FT_DATE || $pa_fields_type == FT_HISTORIC_DATE) { $va_timestamps = $o_tep->parseDate($vm_value); } else { $va_timestamps = $o_tep->parseDatetime($vm_value); } if (!$va_timestamps) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()'); return false; } if ($pa_fields_type == FT_HISTORIC_DATETIME || $pa_fields_type == FT_HISTORIC_DATE) { if ($vs_cur_value != $va_timestamps["start"]) { $this->_FIELD_VALUES[$vs_field] = $va_timestamps["start"]; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } else { $va_timestamps = $o_tep->getUnixTimestamps(); if ($va_timestamps[0] == -1) { $this->postError(1830, $o_tep->getParseErrorMessage(), 'BaseModel->set()'); return false; } if ($vs_cur_value != $va_timestamps["start"]) { $this->_FIELD_VALUES[$vs_field] = $va_timestamps["start"]; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } } } break; case FT_TIME: if ($this->DIRECT_TIMES || $pa_options["SET_DIRECT_TIME"]) { $this->_FIELD_VALUES[$vs_field] = $vm_value; } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($vs_cur_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = null; } else { $o_tep = new TimeExpressionParser(); if (!$o_tep->parseTime($vm_value)) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()'); return false; } $va_times = $o_tep->getTimes(); if ($vs_cur_value != $va_times['start']) { $this->_FIELD_VALUES[$vs_field] = $va_times['start']; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } } break; case FT_TIMESTAMP: # can't set timestamp break; case FT_DATERANGE: case FT_HISTORIC_DATERANGE: $vs_start_field_name = $this->getFieldInfo($vs_field, "START"); $vs_end_field_name = $this->getFieldInfo($vs_field, "END"); $vn_start_date = isset($this->_FIELD_VALUES[$vs_start_field_name]) ? $this->_FIELD_VALUES[$vs_start_field_name] : null; $vn_end_date = isset($this->_FIELD_VALUES[$vs_end_field_name]) ? $this->_FIELD_VALUES[$vs_end_field_name] : null; if ($this->DIRECT_DATETIMES || $pa_options["SET_DIRECT_DATE"]) { if (is_array($vm_value) && sizeof($vm_value) == 2 && $vm_value[0] <= $vm_value[1]) { if ($vn_start_date != $vm_value[0]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $vm_value[0]; } if ($vn_end_date != $vm_value[1]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $vm_value[1]; } } else { $this->postError(1100, _t("Invalid direct date values"), "BaseModel->set()"); } } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($vn_start_date || $vn_end_date) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_start_field_name] = null; $this->_FIELD_VALUES[$vs_end_field_name] = null; } else { $o_tep = new TimeExpressionParser(); if (!$o_tep->parseDatetime($vm_value)) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()'); return false; } if ($pa_fields_type == FT_HISTORIC_DATERANGE) { $va_timestamps = $o_tep->getHistoricTimestamps(); } else { $va_timestamps = $o_tep->getUnixTimestamps(); if ($va_timestamps[0] == -1) { $this->postError(1830, $o_tep->getParseErrorMessage(), 'BaseModel->set()'); return false; } } if ($vn_start_date != $va_timestamps["start"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $va_timestamps["start"]; } if ($vn_end_date != $va_timestamps["end"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $va_timestamps["end"]; } } } break; case FT_TIMERANGE: $vs_start_field_name = $this->getFieldInfo($vs_field, "START"); $vs_end_field_name = $this->getFieldInfo($vs_field, "END"); if ($this->DIRECT_TIMES || $pa_options["SET_DIRECT_TIMES"]) { if (is_array($vm_value) && sizeof($vm_value) == 2 && $vm_value[0] <= $vm_value[1]) { if ($this->_FIELD_VALUES[$vs_start_field_name] != $vm_value[0]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $vm_value[0]; } if ($this->_FIELD_VALUES[$vs_end_field_name] != $vm_value[1]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $vm_value[1]; } } else { $this->postError(1100, _t("Invalid direct time values"), "BaseModel->set()"); } } else { if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) { if ($this->_FIELD_VALUES[$vs_start_field_name] || $this->_FIELD_VALUES[$vs_end_field_name]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_start_field_name] = null; $this->_FIELD_VALUES[$vs_end_field_name] = null; } else { $o_tep = new TimeExpressionParser(); if (!$o_tep->parseTime($vm_value)) { $this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()'); return false; } $va_timestamps = $o_tep->getTimes(); if ($this->_FIELD_VALUES[$vs_start_field_name] != $va_timestamps["start"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_start_field_name] = $va_timestamps["start"]; } if ($this->_FIELD_VALUES[$vs_end_field_name] != $va_timestamps["end"]) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_end_field_name] = $va_timestamps["end"]; } } } break; case FT_TIMECODE: $o_tp = new TimecodeParser(); if ($o_tp->parse($vm_value)) { if ($o_tp->getParsedValueInSeconds() != $vs_cur_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; $this->_FIELD_VALUES[$vs_field] = $o_tp->getParsedValueInSeconds(); } } break; case FT_TEXT: $vm_value = (string) $vm_value; if (is_string($vm_value)) { $vm_value = stripSlashes($vm_value); } if (isset($pa_options['purify']) && $pa_options['purify'] || (bool) $this->opb_purify_input || $this->getFieldInfo($vs_field, "PURIFY") || (bool) $this->getAppConfig()->get('useHTMLPurifier')) { if (!BaseModel::$html_purifier) { BaseModel::$html_purifier = new HTMLPurifier(); } $vm_value = BaseModel::$html_purifier->purify((string) $vm_value); } if ($this->getFieldInfo($vs_field, "DISPLAY_TYPE") == DT_LIST_MULTIPLE) { if (is_array($vm_value)) { if (!($vs_list_multiple_delimiter = $this->getFieldInfo($vs_field, 'LIST_MULTIPLE_DELIMITER'))) { $vs_list_multiple_delimiter = ';'; } $vs_string_value = join($vs_list_multiple_delimiter, $vm_value); $vs_string_value = str_replace("", '', $vs_string_value); if ($vs_cur_value !== $vs_string_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vs_string_value; } } else { $vm_value = str_replace("", '', $vm_value); if ($this->getFieldInfo($vs_field, "ENTITY_ENCODE_INPUT")) { $vs_value_entity_encoded = htmlentities(html_entity_decode($vm_value)); if ($vs_cur_value !== $vs_value_entity_encoded) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vs_value_entity_encoded; } else { if ($this->getFieldInfo($vs_field, "URL_ENCODE_INPUT")) { $vs_value_url_encoded = urlencode($vm_value); if ($vs_cur_value !== $vs_value_url_encoded) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vs_value_url_encoded; } else { if ($vs_cur_value !== $vm_value) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vm_value; } } } break; case FT_PASSWORD: if (!$vm_value) { // store blank passwords as blank, not MD5 of blank $this->_FIELD_VALUES[$vs_field] = $vs_crypt_pw = ""; } else { if ($this->_CONFIG->get("use_old_style_passwords")) { $vs_crypt_pw = crypt($vm_value, substr($vm_value, 0, 2)); } else { $vs_crypt_pw = md5($vm_value); } if ($vs_cur_value != $vm_value && $vs_cur_value != $vs_crypt_pw) { $this->_FIELD_VALUES[$vs_field] = $vs_crypt_pw; } if ($vs_cur_value != $vs_crypt_pw) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } } break; case FT_VARS: if (md5(print_r($vs_cur_value, true)) != md5(print_r($vm_value, true))) { $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } $this->_FIELD_VALUES[$vs_field] = $vm_value; break; case FT_MEDIA: case FT_FILE: $vb_allow_fetching_of_urls = (bool) $this->_CONFIG->get('allow_fetching_of_media_from_remote_urls'); # if there's a tmp_name is the global _FILES array # then we'll process it in insert()/update()... $this->_SET_FILES[$vs_field]['options'] = $pa_options; if (caGetOSFamily() == OS_WIN32) { // fix for paths using backslashes on Windows failing in processing $vm_value = str_replace('\\', '/', $vm_value); } $va_matches = null; if (is_string($vm_value) && (file_exists($vm_value) || $vb_allow_fetching_of_urls && isURL($vm_value))) { $this->_SET_FILES[$vs_field]['original_filename'] = $pa_options["original_filename"]; $this->_SET_FILES[$vs_field]['tmp_name'] = $vm_value; $this->_FIELD_VALUE_CHANGED[$vs_field] = true; } else { # only return error when file name is not 'none' # 'none' is PHP's stupid way of telling you there # isn't a file... if ($vm_value != "none" && $vm_value) { //$this->postError(1500,_t("%1 does not exist", $vm_value),"BaseModel->set()"); } return false; } break; default: die("Invalid field type in BaseModel->set()"); break; } } else { $this->postError(710, _t("'%1' does not exist in this object", $vs_field), "BaseModel->set()"); return false; } } return true; }
/** * Return text in ANSI color * * @param string $ps_string The string to output * @param string $ps_color The background color to output $ps_string with. Colors are defined in CLIBaseUtils::ansiBackgroundColors * @return string The string with ANSI color codes. If $ps_color is invalid the original string will be returned without ANSI codes. */ public static function textWithBackgroundColor($ps_string, $ps_color) { if (!isset(self::$background[$color])) { return $ps_string; } // Disabling color printing under Windows if (caGetOSFamily() == OS_WIN32) { return $ps_string; } return "[" . self::$ansiBackgroundColors[$ps_color] . 'm' . $ps_string . "[0m"; }