/** * Used for internal debugging (within session browser) * @param mixed $v Variable to print * @return string */ function _P4A_Debug_Print_Variable($v) { if ($v === null) { $v = '<span style="color:green">NULL</span>'; } if ($v === false) { $v = '<span style="color:green">FALSE</span>'; } if ($v === true) { $v = '<span style="color:green">TRUE</span>'; } if ($v === '') { $v = '<span style="color:green">Empty String</span>'; } if (is_array($v)) { if (empty($v)) { $v = '<span style="color:green">Empty Array</span>'; } else { $todebug = $v; $v = '<table border="1">'; $v .= "<tr><th colspan='2'>Array</th></tr>"; $v .= "<tr><th>key</th><th>value</th></tr>"; foreach ($todebug as $k2 => $v2) { $v2 = _P4A_Debug_Print_Variable($v2); $v .= "<tr><td>{$k2}</td><td>{$v2}</td></tr>"; } $v .= '</table>'; } } if (is_object($v)) { if (is_a($v, 'p4a_object')) { $v = '<a href=".?_p4a_session_browser=' . $v->getId() . '">' . $v->getName() . ' (' . get_class($v) . ')</a>'; } else { $v = '<pre>' . print_r($v, true) . '</pre>'; } } return $v; }
/** * Never call this method if you don't know what you're doing */ public function executeExternalCommands() { if (isset($_REQUEST['_p4a_session_browser'])) { if (!empty($_REQUEST['_p4a_session_browser']) and isset($this->objects[$_REQUEST['_p4a_session_browser']])) { $obj =& $this->objects[$_REQUEST['_p4a_session_browser']]; } else { $obj =& $this; } $vars = get_object_vars($obj); ksort($vars); $name = $obj->getName(); if (empty($name)) { $name = "P4A main object"; } $name .= ' (' . get_class($obj) . ')'; echo "<h1>{$name}</h1>"; echo "<table border='1'>"; echo "<tr><th>key</th><th>value</th></tr>"; foreach ($vars as $k => $v) { $v = _P4A_Debug_Print_Variable($v); echo "<tr><td valign='top'>{$k}</td><td>{$v}</td></tr>"; } echo "</table>"; die; } elseif (isset($_REQUEST['_rte_file_manager']) and isset($_REQUEST['_object_id']) and isset($this->objects[$_REQUEST['_object_id']])) { require P4A_THEME_DIR . '/widgets/rich_textarea/filemanager/connectors/php/connector.php'; die; } elseif (isset($_REQUEST['_upload_path'])) { $path = P4A_UPLOADS_PATH; if (isset($_REQUEST['_object_id']) and isset($this->objects[$_REQUEST['_object_id']])) { $object =& $this->objects[$_REQUEST['_object_id']]; if ($object instanceof P4A_Field) { $path .= '/' . $object->getUploadSubpath(); } } echo preg_replace(array("~/+~", "~/\$~"), array('/', ''), $path); die; } elseif (isset($_REQUEST['_p4a_autocomplete'])) { if (isset($_REQUEST['_object']) and isset($_REQUEST['term']) and isset($this->objects[$_REQUEST['_object']])) { $object =& $this->objects[$_REQUEST['_object']]; $db = P4A_DB::singleton($object->data_field->getDSN()); $data =& $object->data; $old_where = $data->getWhere(); $description_field = $object->getSourceDescriptionField(); if ($object->isActionTriggered('onautocomplete')) { $this->actionHandler('onautocomplete', $data, $_REQUEST['term']); } else { $q = $db->quote($_REQUEST['term'], false); $where = $db->getCaseInsensitiveLikeSQL($description_field, "%{$q}%"); if ($old_where) { $where = "({$old_where}) AND ({$where})"; } $data->setWhere($where); } $all = $data->getAll(); $data->setWhere($old_where); $new_data = array(); $tmp = array(); foreach ($all as $row) { $tmp[$row[$description_field]] = $row[$description_field]; } ksort($tmp); foreach ($tmp as $k => $v) { $new_data[] = array("id" => $k, "label" => htmlspecialchars($k), "value" => $k); } require_once "Zend/Json.php"; echo Zend_Json::encode($new_data); } die; } elseif (isset($_REQUEST['_p4a_date_format'])) { echo $this->i18n->format($_REQUEST['_p4a_date_format'], 'date', null, false); die; } elseif (isset($_REQUEST['_p4a_time_format'])) { echo $this->i18n->format($_REQUEST['_p4a_time_format'], 'time', null, false); die; } elseif (isset($_REQUEST['_p4a_datetime_format'])) { echo $this->i18n->format($_REQUEST['_p4a_datetime_format'], 'datetime', null, false); die; } elseif (isset($_REQUEST['_p4a_image_thumbnail'])) { $image_data = explode('&', $_REQUEST['_p4a_image_thumbnail']); $thumb = new P4A_Thumbnail_Generator(); $thumb->setCacheDir(P4A_UPLOADS_TMP_DIR)->setFilename(P4A_Strip_Double_Slashes(P4A_UPLOADS_DIR . $image_data[0]))->setMaxWidth($image_data[1])->setMaxHeight($image_data[1])->processFile()->outputThumbnail(); die; } elseif (isset($_REQUEST['_p4a_download_file'])) { $file = realpath(P4A_UPLOADS_DIR . '/' . $_REQUEST['_p4a_download_file']); if (P4A_OS == "linux") { if (strpos($file, realpath(P4A_UPLOADS_DIR)) !== 0) { die; } } else { if (stripos($file, realpath(P4A_UPLOADS_DIR)) !== 0) { die; } } if ($file !== false and file_exists($file)) { $name = basename($file); $name = preg_replace("/^_p4a_.*?_/", "", $name); $gmdate = gmdate("D, d M Y H:i:s"); header("Content-Type: text/html; charset=UTF-8"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Pragma: no-cache"); header("Last-Modified: {$gmdate} GMT"); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"{$name}\""); header("Content-Length: " . filesize($file)); $fp = fopen($file, "rb"); fpassthru($fp); fclose($fp); if (strpos($file, realpath(P4A_UPLOADS_TMP_DIR) . DIRECTORY_SEPARATOR . '_p4a_') === 0) { unlink($file); } } die; } elseif (isset($_REQUEST['_p4a_upload_progress']) and P4A_UPLOAD_PROGRESS) { $upload_info = uploadprogress_get_info($_REQUEST['_p4a_upload_progress']); if (is_array($upload_info)) { $percentage = round($upload_info["bytes_uploaded"] / $upload_info["bytes_total"] * 100) . "%"; $speed = round($upload_info["speed_average"] / 1024) . "KB/s"; echo "{$percentage} - {$speed}"; } die; } }