if (isset($_FILES['file'])) { $uploadsCount = count($_FILES['file']['name']); if ($uploadsCount > 0) { $errors = array(); $messages = array(); for ($i = 0; $i < $uploadsCount; $i++) { if ($_FILES["file"]["error"][$i] > 0) { $errors[] = i18n_r('ERROR_UPLOAD'); } else { //set variables $count = '1'; $file_base = clean_img_name(to7bit($_FILES["file"]["name"][$i])); $file_loc = $path . $file_base; //prevent overwriting if (!isset($_POST['fileoverwrite']) && file_exists($file_loc)) { list($file_base, $filecount) = getNextFileName($path, $file_base); $file_loc = $path . $file_base; } //validate file if (validate_safe_file($_FILES["file"]["tmp_name"][$i], $_FILES["file"]["name"][$i])) { move_uploaded_file($_FILES["file"]["tmp_name"][$i], $file_loc); gs_chmod($file_loc); exec_action('file-uploaded'); // generate thumbnail genStdThumb($subFolder, $file_base); $messages[] = i18n_r('FILE_SUCCESS_MSG'); if (requestIsAjax()) { header("HTTP/1.0 200"); die; } } else {
/** * create a page xml obj * * @since 3.4 * @param str $title title of page * @param str $url optional, url slug of page, if null title is used * @param array $data optional, array of data fields for page * @param boolean $overwrite optional, overwrite exisitng slugs, if false auto increments slug id * @return obj xml object of page */ function createPageXml($title, $url = null, $data = array(), $overwrite = false) { global $reservedSlugs; $fields = array('title', 'titlelong', 'summary', 'url', 'author', 'template', 'parent', 'menu', 'menuStatus', 'menuOrder', 'private', 'meta', 'metad', 'metarNoIndex', 'metarNoFollow', 'metarNoArchive', 'content'); // setup url, falls back to title if not set if (!isset($url)) { $url = $title; } $url = prepareSlug($url); // prepare slug, clean it, translit, truncate $title = truncate($title, GSTITLEMAX); // truncate long titles // If overwrite is false do not use existing slugs, get next incremental slug, eg. "slug-count" if (!$overwrite && (file_exists(GSDATAPAGESPATH . $url . ".xml") || in_array($url, $reservedSlugs))) { list($newfilename, $count) = getNextFileName(GSDATAPAGESPATH, $url . '.xml'); $url = $url . '-' . $count; // die($url.' '.$newfilename.' '.$count); } // store url and title in data, if passed in param they are ignored $data['url'] = $url; $data['title'] = $title; // create new xml $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>'); $xml->addChild('pubDate', date('r')); foreach ($fields as $field) { $node = $xml->addChild($field); if (isset($data[$field])) { $node->addCData($data[$field]); } // saving all cdata for some reason } // debugLog(__FUNCTION__ . ': page created with slug of ' . $xml->url); return $xml; }
/** * Clone a page * Automatically names page id to next incremental copy eg. "slug-n" * Clone title becomes "title [copy]"" * * @param str $id page id to clone * @return mixed returns new url on succcess, bool false on failure */ function clone_page($id) { list($cloneurl, $count) = getNextFileName(GSDATAPAGESPATH, $id . '.xml'); // get page and resave with new slug and title $newxml = getPageXML($id); $newurl = getFileName($cloneurl); $newxml->url = getFileName($cloneurl); $newxml->title = $newxml->title . ' [' . sprintf(i18n_r('COPY_N', i18n_r('COPY')), $count) . ']'; $newxml->pubDate = date('r'); $status = XMLsave($newxml, GSDATAPAGESPATH . $cloneurl); if ($status) { return $newurl; } return false; }