public function setProperty($ps_property, $pm_value)
 {
     if (!($va_info = $this->getPropertyInfo($ps_property))) {
         return null;
     }
     // invalid property
     switch ($va_info['fieldType']) {
         case 'FT_TIMECODE':
             $o_timecode_parser = new TimecodeParser();
             $vn_seconds = $o_timecode_parser->parse($pm_value);
             if (is_numeric($vn_seconds)) {
                 $this->opa_property_values[$ps_property] = (string) $vn_seconds;
                 return true;
             }
             $this->postError(1500, _t("Invalid timecode '%1' for %2", $pm_value, $va_info['label']), 'TimeBasedRepresentationAnnotationCoder->setProperty()');
             return false;
             break;
         default:
             // unsupported property?
             //$this->postError(1500, _t("Invalid property '%1'", $ps_property), 'TimeBasedRepresentationAnnotationCoder->setProperty()');
             //return null;
             $this->opa_property_values[$ps_property] = $pm_value;
             return true;
             break;
     }
 }
Beispiel #2
0
 /** 
  *
  */
 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
 public function parseValue($ps_value, $pa_element_info, $pa_options = null)
 {
     $ps_value = trim($ps_value);
     $va_settings = $this->getSettingValuesFromElementArray($pa_element_info, array('dateRangeBoundaries', 'requireValue'));
     $o_tcp = new TimecodeParser();
     if (strlen($ps_value)) {
         if ($o_tcp->parse($ps_value) === false) {
             // invalid timecode
             $this->postError(1970, _t('%1 is invalid', $pa_element_info['displayLabel']), 'TimecodeAttributeValue->parseValue()');
             return false;
         }
         $vn_seconds = (double) $o_tcp->getParsedValueInSeconds();
     } else {
         if (isset($va_settings['requireValue']) && $va_settings['requireValue']) {
             $this->postError(1970, _t('%1 must not be empty', $pa_element_info['displayLabel']), 'DataRangeAttributeValue->parseValue()');
             return false;
         }
         $ps_value = null;
         $vn_seconds = null;
     }
     return array('value_longtext1' => $ps_value, 'value_decimal1' => $vn_seconds);
 }
Beispiel #5
0
 public function &writePreviews($ps_filepath, $pa_options)
 {
     if (!(bool) $this->opo_config->get("video_preview_generate_frames")) {
         return false;
     }
     if (!isset($pa_options['outputDirectory']) || !$pa_options['outputDirectory'] || !file_exists($pa_options['outputDirectory'])) {
         if (!($vs_tmp_dir = $this->opo_config->get("taskqueue_tmp_directory"))) {
             // no dir
             return false;
         }
     } else {
         $vs_tmp_dir = $pa_options['outputDirectory'];
     }
     $o_tc = new TimecodeParser();
     if (($vn_min_number_of_frames = $pa_options['minNumberOfFrames']) < 1) {
         $vn_min_number_of_frames = 0;
     }
     if (($vn_max_number_of_frames = $pa_options['maxNumberOfFrames']) < 1) {
         $vn_max_number_of_frames = 100;
     }
     $vn_duration = $this->properties["duration"];
     if (!($vn_frame_interval = $o_tc->parse($pa_options['frameInterval']) ? $o_tc->getSeconds() : 0)) {
         $vn_frame_interval = 30;
     }
     if (!($vn_start_at = $o_tc->parse($pa_options['startAtTime']) ? $o_tc->getSeconds() : 0)) {
         $vn_start_at = 0;
     }
     if (!($vn_end_at = $o_tc->parse($pa_options['endAtTime']) ? $o_tc->getSeconds() : 0)) {
         $vn_end_at = 0;
     }
     if (($vn_previewed_duration = $vn_duration - $vn_start_at - $vn_end_at) < 0) {
         $vn_previewed_duration = $vn_duration;
         $vn_start_at = $vn_end_at = 0;
     }
     if ($vn_frame_interval > $vn_previewed_duration) {
         $vn_frame_interval = $vn_previewed_duration;
     }
     $vn_preview_width = isset($pa_options['width']) && (int) $pa_options['width'] > 0 ? (int) $pa_options['width'] : 320;
     $vn_preview_height = isset($pa_options['height']) && (int) $pa_options['height'] > 0 ? (int) $pa_options['height'] : 320;
     $vn_s = $vn_start_at;
     $vn_e = $vn_duration - $vn_end_at;
     $vn_num_frames = $vn_previewed_duration / $vn_frame_interval;
     if ($vn_num_frames < $vn_min_number_of_frames) {
         $vn_frame_interval = $vn_previewed_duration / $vn_min_number_of_frames;
         $vn_num_frames = $vn_min_number_of_frames;
         $vn_previewed_duration = $vn_num_frames * $vn_frame_interval;
     }
     if ($vn_num_frames > $vn_max_number_of_frames) {
         $vn_frame_interval = $vn_previewed_duration / $vn_max_number_of_frames;
         $vn_num_frames = $vn_max_number_of_frames;
         $vn_previewed_duration = $vn_num_frames * $vn_frame_interval;
     }
     $vs_freq = 1 / $vn_frame_interval;
     $vs_output_file_prefix = tempnam($vs_tmp_dir, 'caQuicktimeVRPreview');
     $vs_output_file = $vs_output_file_prefix . '%05d.jpg';
     exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($this->filepath) . " -f image2 -r " . $vs_freq . " -ss {$vn_s} -t {$vn_previewed_duration} -s " . $vn_preview_width . "x" . $vn_preview_height . " -y " . caEscapeShellArg($vs_output_file), $va_output, $vn_return);
     $vn_i = 1;
     $va_files = array();
     while (file_exists($vs_output_file_prefix . sprintf("%05d", $vn_i) . '.jpg')) {
         // add frame to list
         $va_files['' . sprintf("%4.2f", ($vn_i - 1) * $vn_frame_interval + $vn_s) . 's'] = $vs_output_file_prefix . sprintf("%05d", $vn_i) . '.jpg';
         $vn_i++;
     }
     if (!sizeof($va_files)) {
         $this->postError(1610, _t("Couldn't not write video preview frames to tmp directory (%1)", $vs_tmp_dir), "WLPlugQuicktimeVR->write()");
     }
     @unlink($vs_output_file_prefix);
     return $va_files;
 }
Beispiel #6
0
 /** 
  *
  */
 public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
 {
     $o_tc = new TimecodeParser();
     $vn_start = $vn_end = 0;
     if ($o_tc->parse($ps_start)) {
         $vn_start = (double) $o_tc->getSeconds();
     }
     if ($o_tc->parse($ps_end)) {
         $vn_end = (double) $o_tc->getSeconds();
     }
     if ($vn_end == 0) {
         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 mp3 -t {$vn_duration}  -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath), $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)), "WLPlugAudio->writeClip()");
         return false;
     }
     return true;
 }
Beispiel #7
0
 /** 
  *
  */
 public function writeClip($ps_filepath, $ps_start, $ps_end, $pa_options = null)
 {
     if (!caMediaPluginFFmpegInstalled()) {
         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(caGetExternalApplicationPath('ffmpeg') . " -i " . caEscapeShellArg($this->filepath) . " -f mp4 -vcodec libx264 -acodec mp3 -t {$vn_duration}  -y -ss {$vn_start} " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
     if ($vn_return != 0) {
         @unlink($ps_filepath);
         $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;
 }
Beispiel #8
0
 /**
  * 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;
 }