public function buildContent($wrapper) { $this->addStylesheetToHead(URL . '/extensions/profiledevkit/assets/devkit.css', 'screen', 9126343); $table = new XMLElement('table'); $table->setAttribute('id', $this->_view); if ($this->_view == 'render-statistics') { $xml_generation = $this->_profiler->retrieveByMessage('XML Generation'); $xsl_transformation = $this->_profiler->retrieveByMessage('XSLT Transformation'); $event_total = 0; foreach ($this->_records['events'] as $data) { $event_total += $data[1]; } $ds_total = 0; foreach ($this->_records['data-sources'] as $data) { $ds_total += $data[1]; } $this->_records = array(array(__('Total Database Queries'), $this->_dbstats['queries'], NULL, NULL, false), array(__('Slow Queries (> 0.09s)'), count($this->_dbstats['slow-queries']), NULL, NULL, false), array(__('Total Time Spent on Queries'), $this->_dbstats['total-query-time']), array(__('Time Triggering All Events'), $event_total), array(__('Time Running All Data Sources'), $ds_total), array(__('XML Generation Function'), $xml_generation[1]), array(__('XSLT Generation'), $xsl_transformation[1]), array(__('Output Creation Time'), $this->_profiler->retrieveTotalRunningTime()), array(__('Total Memory Usage'), General::formatFilesize($this->_profiler->retrieveTotalMemoryUsage()), NULL, NULL, false)); foreach ($this->_records as $data) { $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $data[0])); $row->appendChild(new XMLElement('td', $data[1] . (isset($data[4]) && $data[4] == false ? '' : ' s'))); $table->appendChild($row); } } elseif ($this->_view == 'memory-usage') { $items = $this->_profiler->retrieve(); $base = $items[0][5]; $total = 0; $last = 0; foreach ($items as $index => $item) { $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $item[0])); $row->appendChild(new XMLElement('td', General::formatFilesize(max(0, $item[5] - $base - $last)))); $table->appendChild($row); $last = $item[5] - $base; } } else { if ($this->_records = $this->_records[$this->_view]) { $ds_total = 0; foreach ($this->_records as $data) { $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $data[0])); if ($this->_view == 'general') { $row->appendChild(new XMLElement('td', $data[1] . ' s')); } else { if ($this->_view == 'slow-queries') { $row->appendChild(new XMLElement('td', $data[1] . (isset($data[4]) && $data[4] == false ? '' : ' s'))); } else { $row->appendChild(new XMLElement('td', $data[1] . ' s from ' . $data[4] . ' ' . ($data[4] == 1 ? 'query' : 'queries'))); } } $ds_total += $data[1]; $table->appendChild($row); } } } $wrapper->appendChild($table); }
public function appendFormattedElement(&$wrapper, $data, $encode = false) { if (!is_array($data) || empty($data)) { return; } if (!is_array($data['file'])) { if (!$data['file']) { return; } $data = array('file' => array($data['file'])); } $item = new XMLElement($this->get('element_name')); $path = DOCROOT; $item->setAttributeArray(array('path' => str_replace(WORKSPACE, '', $path))); foreach ($data['file'] as $index => $file) { $item->appendChild(new XMLElement('item', General::sanitize($file), array('size' => General::formatFilesize(filesize($path . $file))))); } $wrapper->appendChild($item); }
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { // It is possible an array of null data will be passed in. Check for this. if (!is_array($data) || !isset($data['file']) || is_null($data['file'])) { return; } $item = new XMLElement($this->get('element_name')); $url = $this->getUrl($data['file']); $filesize = $data['size']; $item->setAttributeArray(array('size' => !is_null($filesize) ? General::formatFilesize($filesize) : 'unknown', 'bytes' => !is_null($filesize) ? $filesize : 'unknown', 'url' => $url, 'type' => $data['mimetype'])); $item->appendChild(new XMLElement('filename', General::sanitize(basename($data['file'])))); // These are 'deprecated', should use the attributes $item->appendChild(new XMLElement('size', $data['size'])); $item->appendChild(new XMLElement('mimetype', $data['mimetype'])); $m = unserialize($data['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', NULL, $m)); } $wrapper->appendChild($item); }
function grab($param = array()) { ## Decide if we return an emtpy set or not if ($this->__forceEmptySet()) { ##Create the XML container $xml = new XMLElement("archive-entry-list"); $xml->setAttribute("section", $this->getType()); $xml->addChild(new XMLElement("error", "No Records Found.")); return $xml; } $obDate = $this->_parent->getDateObj(); extract($this->_env, EXTR_PREFIX_ALL, 'env'); $where = $sort = $joins = NULL; include_once TOOLKIT . '/class.entrymanager.php'; $entryManager = new EntryManager($this->_parent); $section_id = $entryManager->fetchSectionIDFromHandle($this->getType()); ##Prepare the Query if ($handle = $this->__resolveDefine("dsFilterHANDLE")) { $entries = $entryManager->fetchEntryIDFromPrimaryFieldHandle($section_id, $handle); $where .= " AND t1.`id`" . ($this->__isDefineNotClause("dsFilterHANDLE") ? ' NOT' : '') . " IN ('" . @implode("', '", $entries) . "') "; } if ($date = $this->__resolveDefine("dsFilterDAY")) { $where .= " AND DATE_FORMAT(t1.publish_date, '%d') " . ($this->__isDefineNotClause("dsFilterDAY") ? '!' : '') . "= '" . $date . "' "; } if ($month = $this->__resolveDefine("dsFilterMONTH")) { $where .= " AND DATE_FORMAT(t1.publish_date, '%m') " . ($this->__isDefineNotClause("dsFilterMONTH") ? '!' : '') . "= '" . $month . "' "; } if ($year = $this->__resolveDefine("dsFilterYEAR")) { $where .= " AND DATE_FORMAT(t1.publish_date, '%Y') " . ($this->__isDefineNotClause("dsFilterYEAR") ? '!' : '') . "= '" . $year . "' "; } if ($this->_dsFilterINCLUDEPOSTDATED != 'yes') { $where .= " AND UNIX_TIMESTAMP(t1.publish_date_gmt) <= '" . $obDate->get(false, false) . "' "; } if (is_array($this->_dsFilterCUSTOM) && !empty($this->_dsFilterCUSTOM)) { $table_id = 15; foreach ($this->_dsFilterCUSTOM as $handle => $value) { $field = $this->_db->fetchRow(0, "SELECT `id`, `type`, `foreign_select_multiple` FROM `tbl_customfields` WHERE `parent_section` = '{$section_id}' AND `handle` = '{$handle}' LIMIT 1"); $value_handle = Lang::createHandle($value, $this->_parent->getConfigVar('handle_length', 'admin')); if ($field['type'] == 'multiselect' || $field['type'] == 'foreign' && $field['foreign_select_multiple'] == 'yes') { $joins .= " LEFT JOIN `tbl_entries2customfields_list` AS t{$table_id} ON t1.`id` = t{$table_id}.`entry_id` AND t{$table_id}.field_id = " . $field['id'] . " "; $where .= " AND (t{$table_id}.value_raw = '{$value}' OR t{$table_id}.handle = '{$value_handle}') "; } else { $joins .= " LEFT JOIN `tbl_entries2customfields` AS t{$table_id} ON t1.`id` = t{$table_id}.`entry_id` AND t{$table_id}.field_id = " . $field['id'] . " "; $where .= " AND (t{$table_id}.value_raw = '{$value}' OR t{$table_id}.handle = '{$value_handle}') "; } $table_id++; } } if ($this->_dsFilterSORT != '') { $sort = strtoupper($this->_dsFilterSORT); } if ($max_months = $this->__resolveDefine("dsFilterLIMIT_MONTHS")) { $sql = "SELECT UNIX_TIMESTAMP(t1.publish_date) AS publish_timestamp " . "FROM `tbl_entries` AS t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` " . "AND t2.`class` = 'entry' " . "LEFT JOIN `tbl_authors` AS t4 ON t1.`author_id` = t4.`id` " . $joins . "LEFT JOIN `tbl_entries2sections` AS t8 ON t1.id = t8.entry_id " . "WHERE t8.section_id = '{$section_id}' " . $where . "GROUP BY t1.`id` " . "ORDER BY t1.`publish_date` {$sort} " . "LIMIT 1"; $relative_start = $this->_db->fetchVar('publish_timestamp', 0, $sql); switch ($sort) { case "DESC": $end = mktime(0, 0, 0, date('m', $relative_start) - $max_months + 1, 1, date('Y', $relative_start)); $where .= " AND (UNIX_TIMESTAMP(t1.publish_date) <= '{$relative_start}' AND UNIX_TIMESTAMP(t1.publish_date) >= '{$end}')"; break; case "ASC": ## Since this is assending, we need to start from 0. The DS editor will give us 1+ $max_months--; $last_day = date('d', mktime(0, 0, 0, date('m', $relative_start) + 1, 0, date('Y', $relative_start))); $end = mktime(23, 59, 59, date('m', $relative_start) + $max_months, $last_day, date('Y', $relative_start)); $where .= " AND (UNIX_TIMESTAMP(t1.publish_date) >= '{$relative_start}' AND UNIX_TIMESTAMP(t1.publish_date) <= '{$end}')"; break; } } else { ##We are trying to preview if (isset($param['limit'])) { $limit = " LIMIT 0, " . $param['limit']; } elseif ($this->_dsFilterLIMIT != '') { $limit = " LIMIT 0, " . $this->_dsFilterLIMIT; } elseif ($where == NULL) { $limit = " LIMIT 0, 50"; } } $sql = "SELECT t1.id " . "FROM `tbl_entries` AS t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` " . "AND t2.`class` = 'entry' " . "LEFT JOIN `tbl_authors` AS t4 ON t1.`author_id` = t4.`id` " . $joins . "LEFT JOIN `tbl_entries2sections` AS t8 ON t1.id = t8.entry_id " . "WHERE t8.section_id = '{$section_id}' " . $where . "GROUP BY t1.`id` " . "ORDER BY t1.`publish_date_gmt` " . $sort . $limit; ##Check the cache $hash_id = md5(get_class($this) . serialize($env_url)); if ($param['caching'] && ($cache = $this->check_cache($hash_id))) { return $cache; exit; } ##------------------------------ ##Create the XML container $xml = new XMLElement("archive-entry-list"); $xml->setAttribute("section", $this->getType()); $xml->setAttribute("section-id", $section_id); ##Grab the records $entries = $this->_db->fetchCol("id", $sql); ##Populate the XML if (empty($entries) || !is_array($entries)) { $xml->addChild(new XMLElement("error", "No Records Found.")); return $xml; } else { $bin = array(); foreach ($entries as $id) { $row = $entryManager->fetchEntriesByID($id, false, true); list($dYear, $dMonth, $dDay) = explode("-", date("Y-m-d", $obDate->get(true, false, strtotime($row['publish_date_gmt'])))); $bin[$dYear][$dMonth][$dDay][] = $row; } foreach ($bin as $year => $months) { $xYear = new XMLElement("year"); $xYear->setAttribute("value", $year); foreach ($months as $month => $days) { $xMonth = new XMLElement("month"); $xMonth->setAttribute("value", $month); foreach ($days as $day => $entries) { $xDay = new XMLElement("day"); $xDay->setAttribute("value", $day); foreach ($entries as $row) { $entry = new XMLElement("entry"); $entry->setAttribute("id", $row['id']); $entry->setAttribute("handle", trim($row['fields'][$row['primary_field']]['handle'])); $entry->setAttribute('linked-count', '' . count($row['linked_entries']) . ''); $date_local = $obDate->get(true, false, $row['timestamp_gmt']); $entry_fields = array("date" => General::createXMLDateObject($date_local), "time" => General::createXMLTimeObject($date_local), "rfc822-date" => date("D, d M Y H:i:s \\G\\M\\T", $obDate->get(false, false, $row['timestamp_gmt']))); $this->__addChildFieldsToXML($entry_fields, $entry); ##Author Details $author_rec = $this->_db->fetchRow(0, "SELECT * FROM `tbl_authors` WHERE `id` = '" . $row['author_id'] . "' LIMIT 1"); $author = new XMLElement("author"); $author_fields = array("first-name" => $author_rec['firstname'], "last-name" => $author_rec['lastname'], "email" => $author_rec['email'], "username" => $author_rec['username']); $this->__addChildFieldsToXML($author_fields, $author, "author"); $entry->addChild($author); ##Custom Fields $fields = $row['fields']; if (is_array($fields) && !empty($fields)) { $customFields = new XMLElement("fields"); foreach ($fields as $f) { if (@in_array($f['field_handle'], $this->_dsFilterXMLFIELDS)) { $newField = new XMLElement($f['field_handle']); if ($f['type'] == 'list' || $f['type'] == 'multiselect') { foreach ($f['value_raw'] as $val) { $item = new XMLElement("item", $val); $item->setAttribute("handle", Lang::createHandle($val, $this->_parent->getConfigVar('handle_length', 'admin'))); $newField->addChild($item); } } elseif ($f['type'] == 'foreign') { $sid = $f['foreign_section']; $section_handle = $this->_db->fetchVar('handle', 0, "SELECT `handle` FROM `tbl_sections` WHERE `id` = '{$sid} ' LIMIT 1"); $newField->setAttribute("handle", $f['handle']); $newField->setAttribute("type", 'foreign'); $newField->setAttribute("section-id", $sid); $newField->setAttribute("section-handle", $sid); if (!is_array($f['value_raw'])) { $f['value_raw'] = array($f['value_raw']); } foreach ($f['value_raw'] as $h) { $entry_id = $entryManager->fetchEntryIDFromPrimaryFieldHandle($sid, $h); $e = $entryManager->fetchEntriesByID($entry_id, false, true); $item = new XMLElement("item", trim($e['fields'][$e['primary_field']]['value'])); $item->setAttribute("entry-id", $entry_id[0]); $item->setAttribute("entry-handle", $e['fields'][$e['primary_field']]['handle']); $newField->addChild($item); } } elseif ($f['type'] == 'upload') { foreach ($f['value_raw'] as $val) { $item = new XMLElement("item"); $item->addChild(new XMLElement("path", trim($val['path'], '/'))); $item->addChild(new XMLElement("type", $val['type'])); $item->addChild(new XMLElement("size", General::formatFilesize($val['size']))); $newField->addChild($item); } } elseif ($f['type'] == 'checkbox') { $newField->setValue($f['value_raw']); } elseif ($f['type'] == 'select') { $newField->setValue($f['value_raw']); $newField->setAttribute("handle", $f['handle']); } else { $key = 'value'; if ($f['format'] != 1) { $key = 'value_raw'; } $f[$key] = trim($f[$key]); $value = $f[$key]; if ($this->_dsFilterENCODE == "yes") { $value = trim(General::sanitize($f[$key])); } if ($f['type'] == 'textarea') { $newField->setValue($value); $newField->setAttribute("word-count", General::countWords(strip_tags($f['value']))); } elseif ($f['type'] == 'input' && $f['field_id'] != $row['primary_field']) { $newField->setAttribute("handle", $f['handle']); $newField->setValue($value); } } $customFields->addChild($newField); } } $entry->addChild($customFields); } ##Comments $commenting = $this->_db->fetchVar('commenting', 0, "SELECT `commenting` FROM `tbl_sections` WHERE `id` = '{$section_id}' LIMIT 1"); if ($commenting == 'on') { $comments = new XMLElement("comments"); $sql = "SELECT count(*) as `count` " . "FROM `tbl_comments` " . "WHERE `entry_id` = '" . $row['id'] . "'"; $comment_count = max(0, @intval($this->_db->fetchVar("count", 0, $sql . " AND `spam` = 'no'"))); $spam_count = max(0, @intval($this->_db->fetchVar("count", 0, $sql . " AND `spam` = 'yes'"))); $comments->setAttribute("count", "" . $comment_count . ""); $comments->setAttribute("spam", "" . $spam_count . ""); $entry->addChild($comments); } $xDay->addChild($entry); } $xMonth->addChild($xDay); } $xYear->addChild($xMonth); } $xml->addChild($xYear); } } ##------------------------------ ##Write To Cache if ($param['caching']) { $result = $xml->generate($param['indent'], $param['indent-depth']); $this->write_to_cache($hash_id, $result, $this->_cache_sections); return $result; } return $xml; }
function checkPostFieldData($data, &$message, $entry_id = NULL) { /* UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success. UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded. UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded. UPLOAD_ERR_NO_TMP_DIR Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. UPLOAD_ERR_EXTENSION Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0. */ // Array // ( // [name] => filename.pdf // [type] => application/pdf // [tmp_name] => /tmp/php/phpYtdlCl // [error] => 0 // [size] => 16214 // ) $message = NULL; if (empty($data) || $data['error'] == UPLOAD_ERR_NO_FILE) { if ($this->get('required') == 'yes') { $message = __("'%s' is a required field.", $this->get('label')); return self::__MISSING_FIELDS__; } return self::__OK__; } ## Its not an array, so just retain the current data and return if (!is_array($data)) { return self::__OK__; } if (!is_writable(DOCROOT . $this->get('destination') . '/')) { $message = __('Destination folder, <code>%s</code>, is not writable. Please check permissions.', array($this->get('destination'))); return self::__ERROR__; } if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) { switch ($data['error']) { case UPLOAD_ERR_INI_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize'))); break; case UPLOAD_ERR_FORM_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize($this->_engine->Configuration->get('max_upload_size', 'admin')))); break; case UPLOAD_ERR_PARTIAL: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_NO_TMP_DIR: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_CANT_WRITE: $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label'))); break; case UPLOAD_ERR_EXTENSION: $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label'))); break; } return self::__ERROR_CUSTOM__; } ## Sanitize the filename $data['name'] = Lang::createFilename($data['name']); if ($this->get('validator') != NULL) { $rule = $this->get('validator'); if (!General::validateString($data['name'], $rule)) { $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label'))); return self::__INVALID_FIELDS__; } } $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $new_file = $abs_path . '/' . $data['name']; $existing_file = NULL; if ($entry_id) { $row = $this->Database->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `entry_id` = '{$entry_id}' LIMIT 1"); $existing_file = $abs_path . '/' . trim($row['file'], '/'); } if ($existing_file != $new_file && file_exists($new_file)) { $message = __('A file with the name %1$s already exists in %2$s. Please rename the file first, or choose another.', array($data['name'], $this->get('destination'))); return self::__INVALID_FIELDS__; } return self::__OK__; }
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { // It is possible an array of null data will be passed in. Check for this. if (!is_array($data) || !isset($data['file']) || is_null($data['file'])) { return; } $file = $this->getFilePath($data['file']); $filesize = file_exists($file) && is_readable($file) ? filesize($file) : null; $item = new XMLElement($this->get('element_name')); $item->setAttributeArray(array('size' => !is_null($filesize) ? General::formatFilesize($filesize) : 'unknown', 'bytes' => !is_null($filesize) ? $filesize : 'unknown', 'path' => General::sanitize(str_replace(WORKSPACE, null, dirname($file))), 'type' => $data['mimetype'])); $item->appendChild(new XMLElement('filename', General::sanitize(basename($file)))); $m = unserialize($data['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', null, $m)); } $wrapper->appendChild($item); }
public function frontendOutputPostGenerate($context) { // don't output anything for unauthenticated users if (!Frontend::instance()->isLoggedIn()) { return; } require_once EXTENSIONS . '/firebug_profiler/lib/FirePHPCore/FirePHP.class.php'; $firephp = FirePHP::getInstance(true); $events = Frontend::instance()->Profiler->retrieveGroup('Events'); $datasources = Frontend::instance()->Profiler->retrieveGroup('Datasource'); $xml_generation = Frontend::instance()->Profiler->retrieveByMessage('XML Generation'); $dbstats = Frontend::instance()->Database->getStatistics(); // Profile group $firephp->group('Profile', array('Collapsed' => false)); $table = array(); $table[] = array('', ''); foreach (Frontend::instance()->Profiler->retrieveGroup('General') as $profile) { $table[] = array($profile[0], $profile[1] . 's'); } $firephp->table('Page Building', $table); $event_total = 0; foreach ($events as $r) { $event_total += $r[1]; } $ds_total = 0; foreach ($datasources as $r) { $ds_total += $r[1]; } $table = array(); $table[] = array('', ''); $table[] = array(__('Total Database Queries'), $dbstats['queries']); if (count($dbstats['slow-queries']) > 0) { $table[] = array(__('Slow Queries (> 0.09s)'), count($dbstats['slow-queries']) . 's'); } $table[] = array(__('Total Time Spent on Queries'), $dbstats['total-query-time'] . 's'); $table[] = array(__('Time Triggering All Events'), $event_total) . 's'; $table[] = array(__('Time Running All Data Sources'), $ds_total . 's'); $table[] = array(__('XML Generation Function'), $xml_generation[1] . 's'); // $table[] = array(__('XSLT Generation'), $xsl_transformation[1]); not available for this delegate $total = Frontend::instance()->Profiler->retrieveTotalRunningTime(); $table[] = array(__('Output Creation Time'), $total); $table[] = array(__('Total Memory Usage'), General::formatFilesize(Frontend::instance()->Profiler->retrieveTotalMemoryUsage())); $firephp->table('Page Output (' . $total . 's, ' . $dbstats['queries'] . ' queries, ' . General::formatFilesize(Frontend::instance()->Profiler->retrieveTotalMemoryUsage()) . ')', $table); if (count($datasources) > 0) { $table = array(); $table[] = array('Data Source', 'Time', 'Queries'); foreach ($datasources as $profile) { $table[] = array($profile[0], $profile[1] . 's', $profile[4]); } $firephp->table('Data Sources', $table); } if (count($events) > 0) { $table = array(); $table[] = array('Event', 'Time', 'Queries'); foreach ($events as $profile) { $table[] = array($profile[0], $profile[1] . 's', $profile[4]); } $firephp->table('Events', $table); } $firephp->groupEnd(); // Debug group $xml = simplexml_load_string($this->xml); $firephp->group('Debug', array('Collapsed' => false)); if ($this->_Parent->Configuration->get('enabled', 'firebug_profiler') == 'yes') { $table = array(); $table[] = array('Event', 'XML'); $xml_events = $xml->xpath('/data/events/*'); if (count($xml_events) > 0) { foreach ($xml_events as $event) { $table[] = array($event->getName(), $event->asXML()); } $firephp->table('Events (' . count($xml_events) . ')', $table); } $table = array(); $table[] = array('Data Source', 'Entries', 'XML'); $xml_datasources = $xml->xpath('/data/*[name() != "events"]'); if (count($xml_datasources) > 0) { foreach ($xml_datasources as $ds) { $entries = $ds->xpath('entry[@id]'); $table[] = array($ds->getName(), count($entries), $ds->asXML()); } $firephp->table('Data Sources (' . count($xml_datasources) . ')', $table); } } $param_table = array(); $param_table[] = array('Parameter', 'Value'); foreach ($this->params as $name => $value) { if ($name == 'root') { continue; } $param_table[] = array('$' . trim($name), $value == null ? '' : $value); } $firephp->table('Page Parameters', $param_table); $firephp->groupEnd(); }
function checkPostFieldData($data, &$message, $entry_id = NULL) { /* UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success. UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded. UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded. UPLOAD_ERR_NO_TMP_DIR Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. UPLOAD_ERR_EXTENSION Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0. Array ( [name] => filename.pdf [type] => application/pdf [tmp_name] => /tmp/php/phpYtdlCl [error] => 0 [size] => 16214 ) */ $message = NULL; if (empty($data) || $data['error'] == UPLOAD_ERR_NO_FILE) { if ($this->get('required') == 'yes') { $message = __("'%s' is a required field.", array($this->get('label'))); return self::__MISSING_FIELDS__; } return self::__OK__; } // Its not an array, so just retain the current data and return if (!is_array($data)) { // Ensure the file exists in the `WORKSPACE` directory // @link http://symphony-cms.com/discuss/issues/view/610/ $file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)../%'), '/', $data); if (!file_exists($file) || !is_readable($file)) { $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.'); return self::__INVALID_FIELDS__; } // Ensure that the file still matches the validator and hasn't // changed since it was uploaded. if ($this->get('validator') != NULL) { $rule = $this->get('validator'); if (!General::validateString($file, $rule)) { $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label'))); return self::__INVALID_FIELDS__; } } return self::__OK__; } if (!is_dir(DOCROOT . $this->get('destination') . '/')) { $message = __('The destination directory, <code>%s</code>, does not exist.', array($this->get('destination'))); return self::__ERROR__; } elseif (!is_writable(DOCROOT . $this->get('destination') . '/')) { $message = __('Destination folder, <code>%s</code>, is not writable. Please check permissions.', array($this->get('destination'))); return self::__ERROR__; } if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) { switch ($data['error']) { case UPLOAD_ERR_INI_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize'))); break; case UPLOAD_ERR_FORM_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize(Symphony::Configuration()->get('max_upload_size', 'admin')))); break; case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_TMP_DIR: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_CANT_WRITE: $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label'))); break; case UPLOAD_ERR_EXTENSION: $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label'))); break; } return self::__ERROR_CUSTOM__; } // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); if ($this->get('validator') != NULL) { $rule = $this->get('validator'); if (!General::validateString($data['name'], $rule)) { $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label'))); return self::__INVALID_FIELDS__; } } $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $new_file = $abs_path . '/' . $data['name']; $existing_file = NULL; if ($entry_id) { $row = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `entry_id` = '{$entry_id}' LIMIT 1"); $existing_file = $abs_path . '/' . basename($row['file'], '/'); } if (strtolower($existing_file) != strtolower($new_file) && file_exists($new_file)) { $message = __('A file with the name %1$s already exists in %2$s. Please rename the file first, or choose another.', array($data['name'], $this->get('destination'))); return self::__INVALID_FIELDS__; } return self::__OK__; }
public function appendFormattedElement(SymphonyDOMElement $wrapper, $data, $encode = false, $mode = null, Entry $entry = null) { if (!$this->sanitizeDataArray($data)) { return null; } $document = $wrapper->ownerDocument; $meta = unserialize($data->meta); if (!is_array($meta)) { $meta = array(); } $meta['size'] = General::formatFilesize($data->size); $meta['type'] = $data->type; ksort($meta); $field = $document->createElement($this->{'element-name'}); $field->appendChild($document->createElement('file', $data->name, array('path' => trim($data->path, '/'), 'name' => $data->file))); $element = $document->createElement('meta'); foreach ($meta as $key => $value) { if ($key == 'creation' or $key == 'type') { $element->setAttribute($key, $value); } else { if ($key == 'size') { $bits = explode(' ', $value); if (count($bits) != 2) { continue; } $element->appendChild($document->createElement('size', $bits[0], array('unit' => $bits[1]))); } else { if (is_array($value)) { $element->appendChild($document->createElement($key, null, $value)); } else { $element->appendChild($document->createElement($key, (string) $value)); } } } } $field->appendChild($element); ### # Delegate: UploadField_AppendFormattedElement # Description: Allow other extensions to add media previews. Extension::notify('UploadField_AppendFormattedElement', '/publish/', array('data' => $data, 'entry' => $entry, 'field' => $this, 'wrapper' => $field)); $wrapper->appendChild($field); }
public function buildContent(XMLElement $wrapper) { $this->addStylesheetToHead(URL . '/extensions/profiledevkit/assets/devkit.css', 'screen', 9126343); $table = new XMLElement('table'); $table->setAttribute('id', $this->_view); if ($this->_view == 'render-statistics') { $xml_generation = Symphony::Profiler()->retrieveByMessage('XML Generation'); $xsl_transformation = Symphony::Profiler()->retrieveByMessage('XSLT Transformation'); $event_total = 0; foreach ($this->_records['events'] as $data) { $event_total += $data[1]; } $ds_total = 0; foreach ($this->_records['data-sources'] as $data) { $ds_total += $data[1]; } $this->_records = array(array(__('Total Database Queries'), $this->_dbstats['queries'], NULL, NULL, false), array(__('Slow Queries (> 0.09s)'), (string) count($this->_dbstats['slow-queries']), NULL, NULL, false), array(__('Total Time Spent on Queries'), $this->_dbstats['total-query-time']), array(__('Time Triggering All Events'), $event_total), array(__('Time Running All Data Sources'), $ds_total), array(__('XML Generation'), $xml_generation[1]), array(__('XSLT Transformation'), $xsl_transformation[1]), array(__('Output Creation Time'), Symphony::Profiler()->retrieveTotalRunningTime()), array(__('Total Memory Usage'), General::formatFilesize(Symphony::Profiler()->retrieveTotalMemoryUsage()), NULL, NULL, false)); foreach ($this->_records as $data) { if (!isset($data[4]) || $data[4] !== false) { $data[1] = number_format($data[1], 4) . ' s'; } $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $data[0])); $row->appendChild(new XMLElement('td', $data[1])); $table->appendChild($row); } } else { if ($this->_view == 'memory-usage') { $items = Symphony::Profiler()->retrieve(); $base = $items[0][5]; $total = 0; $last = 0; foreach ($items as $index => $item) { // Build row display name if (in_array($item[3], array('Datasource', 'Event'))) { $display_value = $item[3] . ': ' . $item[0]; } else { if ($item[3] == 'Delegate') { $display_value = str_replace('|', ': ', $item[0]); } else { $display_value = $item[0]; } } $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $display_value)); $row->appendChild(new XMLElement('td', General::formatFilesize(max(0, $item[5] - $base - $last)))); $table->appendChild($row); $last = $item[5] - $base; } } else { if ($this->_view == 'database-queries') { $debug = Symphony::Database()->debug(); if (count($debug) > 0) { $i = 1; foreach ($debug as $query) { $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $i)); $row->appendChild(new XMLElement('td', number_format($query['execution_time'], 4))); $row->appendChild(new XMLElement('td', $query['query'])); $table->appendChild($row); $i++; } } } else { if ($this->_view == 'delegates') { $delegates = array(); $debug = Symphony::Database()->debug(); // Build an array of delegate => extensions foreach ($this->_records['delegates'] as $data) { $parts = explode('|', $data[0]); $data[0] = $parts[1]; $delegates[$parts[0]][] = $data; } foreach ($delegates as $delegate => $extensions) { $tt = $tq = 0; $te = array(); $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $delegate)); $table->appendChild($row); foreach ($extensions as $extension) { $execution_time = number_format($extension[1], 4); $extension_row = new XMLElement('tr'); // Poor man's grouping. $extension_row->appendChild(new XMLElement('td', ' ')); $extension_row->appendChild(new XMLElement('th', $extension[0])); $extension_row->appendChild(new XMLElement('td', $execution_time . ' s from ' . $extension[4] . ' ' . ($extension[4] == 1 ? 'query' : 'queries'))); $table->appendChild($extension_row); $tt += $execution_time; $tq += is_array($extension[4]) ? count($extension[4]) : $extension[4]; if (!in_array($extension[0], $te)) { $te[] = $extension[0]; } } $row->appendChild(new XMLElement('td', number_format($tt, 4) . ' s from ' . count($te) . ' extensions and ' . $tq . ' ' . ($tq == 1 ? 'query' : 'queries'))); } } else { if ($this->_records = $this->_records[$this->_view]) { $ds_total = 0; foreach ($this->_records as $data) { $row = new XMLElement('tr'); $row->appendChild(new XMLElement('th', $data[0])); if ($this->_view == 'general') { $row->appendChild(new XMLElement('td', number_format($data[1], 4) . ' s')); } elseif ($this->_view == 'slow-queries') { if (!isset($data[4]) || $data[4] !== false) { $data[1] = number_format($data[1], 4) . ' s'; } $row->appendChild(new XMLElement('td', $data[1])); } else { $row->appendChild(new XMLElement('td', number_format($data[1], 4) . ' s from ' . $data[4] . ' ' . ($data[4] == 1 ? 'query' : 'queries'))); } $ds_total += $data[1]; $table->appendChild($row); } } } } } } $wrapper->appendChild($table); }
function appendFormattedElement(&$wrapper, $data) { $item = new XMLElement($this->get('element_name')); $item->setAttributeArray(array('size' => General::formatFilesize(filesize(WORKSPACE . $data['file'])), 'path' => str_replace(WORKSPACE, NULL, dirname(WORKSPACE . $data['file'])), 'type' => $data['mimetype'], 'signature' => $data['signature'])); $item->appendChild(new XMLElement('filename', General::sanitize(basename($data['file'])))); $m = unserialize($data['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', NULL, $m)); } $wrapper->appendChild($item); }
</td> </tr> </tfoot> <tbody> <?php if (!empty($files) && is_array($files)) { $bEven = false; foreach ($files as $row) { $handle = "/" . trim($row['path'], "/") . "/" . $row['name']; $handle = preg_replace('/\\/{2,}/', "/", $handle); $abs_filename = WORKSPACE . $handle; $filename = URL . "/workspace" . $handle; $file_cell_handle = str_replace($row['name'], "", $handle); $file_cell_handle = "/" . ltrim($file_cell_handle, "/"); $file_size = General::formatFilesize(filesize($abs_filename)); $downloads = $recorded_files[$handle]['downloads']; if (empty($downloads)) { $downloads = 0; } else { $downloads = "<strong>{$downloads}</strong>"; } ?> <tr<?php print $bEven ? ' class="even"' : ""; ?> > <td><a href="<?php print $filename; ?> " class="content"><?php
public function checkPostFieldData($data, &$message, $entry_id = NULL) { /** * For information about PHPs upload error constants see: * @link http://php.net/manual/en/features.file-upload.errors.php */ $message = null; if (empty($data) || is_array($data) && isset($data['error']) && $data['error'] == UPLOAD_ERR_NO_FILE) { if ($this->get('required') == 'yes') { $message = __('‘%s’ is a required field.', array($this->get('label'))); return self::__MISSING_FIELDS__; } return self::__OK__; } // Its not an array, so just retain the current data and return if (is_array($data) === false) { /** * Ensure the file exists in the `WORKSPACE` directory * @link http://symphony-cms.com/discuss/issues/view/610/ */ $file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data); //var_dump($data['file']); if (file_exists($file) === false || !is_readable($file)) { $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.'); return self::__INVALID_FIELDS__; } // Ensure that the file still matches the validator and hasn't // changed since it was uploaded. if ($this->get('validator') != null) { $rule = $this->get('validator'); if (General::validateString($file, $rule) === false) { $message = __('File chosen in ‘%s’ does not match allowable file types for that field.', array($this->get('label'))); return self::__INVALID_FIELDS__; } } return self::__OK__; } if (is_dir(DOCROOT . $this->get('destination') . '/') === false) { $message = __('The destination directory, %s, does not exist.', array('<code>' . $this->get('destination') . '</code>')); return self::__ERROR__; } else { if (is_writable(DOCROOT . $this->get('destination') . '/') === false) { $message = __('Destination folder is not writable.') . ' ' . __('Please check permissions on %s.', array('<code>' . $this->get('destination') . '</code>')); return self::__ERROR__; } } if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) { switch ($data['error']) { case UPLOAD_ERR_INI_SIZE: $message = __('File chosen in ‘%1$s’ exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize'))); break; case UPLOAD_ERR_FORM_SIZE: $message = __('File chosen in ‘%1$s’ exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize($_POST['MAX_FILE_SIZE']))); break; case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_TMP_DIR: $message = __('File chosen in ‘%s’ was only partially uploaded due to an error.', array($this->get('label'))); break; case UPLOAD_ERR_CANT_WRITE: $message = __('Uploading ‘%s’ failed. Could not write temporary file to disk.', array($this->get('label'))); break; case UPLOAD_ERR_EXTENSION: $message = __('Uploading ‘%s’ failed. File upload stopped by extension.', array($this->get('label'))); break; } return self::__ERROR_CUSTOM__; } // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); if ($this->get('validator') != null) { $rule = $this->get('validator'); if (!General::validateString($data['name'], $rule)) { $message = __('File chosen in ‘%s’ does not match allowable file types for that field.', array($this->get('label'))); return self::__INVALID_FIELDS__; } } return self::__OK__; }
public function buildTableRow(DirectoryIterator $file, $includeParentDirectoryDots = true) { if (!$file->isDot() && substr($file->getFilename(), 0, 1) == '.' && Administration::instance()->Configuration->get('show-hidden', 'filemanager') != 'yes') { return; } elseif ($file->isDot() && !$includeParentDirectoryDots && $file->getFilename() == '..') { return; } elseif ($file->getFilename() == '.') { return; } $relpath = str_replace($this->getStartLocation() == '' ? DOCROOT : DOCROOT . $this->getStartLocation(), NULL, $file->getPathname()); if (!$file->isDir()) { //if(File::fileType($file->getFilename()) == self::CODE) // $download_uri = self::baseURL() . 'edit/?file=' . urlencode($relpath); //else $download_uri = self::baseURL() . 'download/?file=' . urlencode($relpath); } else { $download_uri = self::baseURL() . 'properties/?file=' . urlencode($relpath) . '/'; } if (!$file->isDot()) { $td1 = Widget::TableData(Widget::Anchor($file->getFilename(), self::baseURL() . ($file->isDir() ? 'browse' . $relpath . '/' : 'properties/?file=' . urlencode($relpath)), NULL, 'file-type ' . ($file->isDir() ? 'folder' : File::fileType($file->getFilename())))); //$group = (function_exists('posix_getgrgid') ? posix_getgrgid($file->getGroup()) : $file->getGroup()); //$owner = (function_exists('posix_getpwuid') ? posix_getpwuid($file->getOwner()) : $file->getOwner()); $group = $file->getGroup(); $owner = $file->getOwner(); $td3 = Widget::TableData(File::getOctalPermission($file->getPerms()) . ' <span class="inactive">' . File::getReadablePerm($file->getPerms()), NULL, NULL, NULL, array('title' => (isset($owner['name']) ? $owner['name'] : $owner) . ', ' . (isset($group['name']) ? $group['name'] : $group)) . '</span>'); $td4 = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, $file->getMTime())); if ($file->isWritable()) { if ($file->isDir()) { $td5 = Widget::TableData(Widget::Anchor('Edit', $download_uri)); } else { $td5 = Widget::TableData(Widget::Anchor('Download', $download_uri)); } } else { $td5 = Widget::TableData('-', 'inactive'); } } else { $td1 = Widget::TableData(Widget::Anchor('↵', self::baseURL() . 'browse' . $relpath . '/')); $td3 = Widget::TableData('-', 'inactive'); $td4 = Widget::TableData('-', 'inactive'); $td5 = Widget::TableData('-', 'inactive'); } $td2 = Widget::TableData($file->isDir() ? '-' : General::formatFilesize($file->getSize()), $file->isDir() ? 'inactive' : NULL); $startlocation = DOCROOT . $this->getStartLocation(); if (!$file->isDot()) { $td5->appendChild(Widget::Input('items[' . str_replace($startlocation, '', $file->getPathname()) . ($file->isDir() ? '/' : NULL) . ']', NULL, 'checkbox')); } return Widget::TableRow(array($td1, $td2, $td3, $td4, $td5)); }
public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { if (!$this->sanitizeDataArray($data)) { return null; } $item = new XMLElement($this->get('element_name')); $item->setAttributeArray(array('size' => General::formatFilesize($data['size']), 'type' => General::sanitize($data['mimetype']), 'name' => General::sanitize($data['name']))); $item->appendChild(new XMLElement('path', str_replace(WORKSPACE, NULL, dirname(WORKSPACE . $data['file'])))); $item->appendChild(new XMLElement('file', General::sanitize(basename($data['file'])))); $meta = unserialize($data['meta']); if (is_array($meta) and !empty($meta)) { $item->appendChild(new XMLElement('meta', null, $meta)); } ### # Delegate: UploadField_AppendFormattedElement # Description: Allow other extensions to add media previews. $this->Symphony->ExtensionManager->notifyMembers('UploadField_AppendFormattedElement', '/frontend/', array('data' => $data, 'entry_id' => $entry_id, 'field_id' => $this->get('id'), 'wrapper' => $item)); $wrapper->appendChild($item); }
function checkPostFieldData($data, &$message, $entry_id = NULL) { /* UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success. UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded. UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded. UPLOAD_ERR_NO_TMP_DIR Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. UPLOAD_ERR_EXTENSION Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0. */ // Array // ( // [name] => filename.pdf // [type] => application/pdf // [tmp_name] => /tmp/php/phpYtdlCl // [error] => 0 // [size] => 16214 // ) $message = NULL; try { $this->S3->getBucket($this->get('bucket')); } catch (Exception $e) { $message = __('The bucket %s doesn\'t exist! Please update this section.', array($this->get('bucket'))); return self::__INVALID_FIELDS__; } if (empty($data) || isset($data['error']) && $data['error'] == UPLOAD_ERR_NO_FILE) { if ($this->get('required') == 'yes') { $message = __("'%s' is a required field.", array($this->get('label'))); return self::__MISSING_FIELDS__; } return self::__OK__; } ## Its not an array, so just retain the current data and return if (!is_array($data)) { return self::__OK__; } if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) { switch ($data['error']) { case UPLOAD_ERR_INI_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize'))); break; case UPLOAD_ERR_FORM_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize(Symphony::Configuration()->get('max_upload_size', 'admin')))); break; case UPLOAD_ERR_PARTIAL: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_NO_TMP_DIR: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_CANT_WRITE: $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label'))); break; case UPLOAD_ERR_EXTENSION: $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label'))); break; } return self::__ERROR_CUSTOM__; } ## Sanitize the filename $data['name'] = Lang::createFilename($data['name']); ## uniq the filename if ($this->get('unique_filename') == true && isset($data['name'])) { $this->getUniqueFilename($data['name']); } if ($this->get('validator') != NULL) { $rule = $this->get('validator'); if (!General::validateString($data['name'], $rule)) { $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label'))); return self::__INVALID_FIELDS__; } } ## check if the file exists since we can't check directly through the s3 library, the file field is unique $row = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `file`='" . $data['name'] . "'"); if (isset($row['file'])) { $message = __('A file with the name %1$s already exists at that bucket. Please rename the file first, or choose another.', array($data['name'])); return self::__INVALID_FIELDS__; } return self::__OK__; }
/** * DATA SOURCES */ public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = null) { if (!is_array($data) or empty($data)) { return; } if (!is_array($data['relation_id'])) { $data['relation_id'] = array($data['relation_id']); } // get title information $titles = $this->_engine->Database->fetch("SELECT `entry_id`, `value`, `handle` \n\t\t\t\tFROM `tbl_entries_data_" . $this->get('related_title_id') . "` \n\t\t\t\tWHERE `entry_id` IN (" . implode(', ', $data['relation_id']) . ") \n\t\t\t\tLIMIT 100"); foreach ($titles as $title) { $filedata[$title['entry_id']]['value'] = $title['value']; $filedata[$title['entry_id']]['handle'] = $title['handle']; } // get file information $files = $this->_engine->Database->fetch("SELECT `entry_id`, `file`, `mimetype`, `meta` \n\t\t\t\tFROM `tbl_entries_data_" . $this->get('related_field_id') . "` \n\t\t\t\tWHERE `entry_id` IN (" . implode(', ', $data['relation_id']) . ") \n\t\t\t\tLIMIT 100"); foreach ($files as $file) { $filedata[$file['entry_id']]['file'] = $file['file']; $filedata[$file['entry_id']]['mimetype'] = $file['mimetype']; $filedata[$file['entry_id']]['meta'] = $file['meta']; } // set mediathek attributes $list = new XMLElement($this->get('element_name'), NULL, array('count' => count($data['relation_id']), 'related-section-id' => $this->get('related_section_id'), 'path' => str_replace(WORKSPACE, NULL, dirname(WORKSPACE . $files[0]['file'])))); // create items foreach ($data['relation_id'] as $index => $value) { $item = new XMLElement('item', NULL, array('related-id' => $data['relation_id'][$index], 'size' => General::formatFilesize(filesize(WORKSPACE . $filedata[$value]['file'])), 'type' => $filedata[$value]['mimetype'])); $item->appendChild(new XMLElement('title', $filedata[$value]['value'], array('handle' => $filedata[$value]['handle']))); $item->appendChild(new XMLElement('filename', General::sanitize(basename($filedata[$value]['file'])))); $m = unserialize($filedata[$value]['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', NULL, $m)); } $list->appendChild($item); } $wrapper->appendChild($list); }
public function appendFormattedElement(&$wrapper, $data) { // It is possible an array of NULL data will be passed in. Check for this. if (!is_array($data) || !isset($data['file']) || is_null($data['file'])) { return; } $item = new XMLElement($this->get('element_name')); $file = WORKSPACE . $data['file']; $item->setAttributeArray(array('size' => file_exists($file) && is_readable($file) ? General::formatFilesize(filesize($file)) : 'unknown', 'path' => str_replace(WORKSPACE, NULL, dirname(WORKSPACE . $data['file'])), 'type' => $data['mimetype'])); $item->appendChild(new XMLElement('filename', General::sanitize(basename($data['file'])))); $m = unserialize($data['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', NULL, $m)); } $wrapper->appendChild($item); }
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { $data = $this->buildFileItems($data); $field = new XMLElement($this->get('element_name')); foreach ($data as $file_item) { // It is possible an array of NULL data will be passed in. Check for this. if (!is_array($file_item) || !isset($file_item['file']) || is_null($file_item['file'])) { return; } $file = $this->getFilePath(basename($file_item['file'])); $item = new XMLElement('file'); $item->setAttributeArray(array('size' => file_exists($file) && is_readable($file) ? General::formatFilesize(filesize($file)) : 'unknown', 'path' => General::sanitize(str_replace(WORKSPACE, NULL, dirname($file))), 'type' => $file_item['mimetype'], 'extension' => General::getExtension($file))); $item->appendChild(new XMLElement('filename', General::sanitize(basename($file)))); $m = unserialize($file_item['meta']); if (is_array($m) && !empty($m)) { $item->appendChild(new XMLElement('meta', NULL, $m)); } $field->appendChild($item); } $wrapper->appendChild($field); return $wrapper; }