示例#1
0
 /**
  * Create filename-mirrored thumbnails for the given directory stub (mirrors stub/foo with stub_thumbs/foo).
  *
  * @param  string		Directory to mirror
  */
 function directory_thumb_mirror($dir)
 {
     require_code('images');
     $full = get_custom_file_base() . '/uploads/' . $dir;
     $dh = @opendir($full);
     if ($dh !== false) {
         while (($file = readdir($dh)) !== false) {
             $target = get_custom_file_base() . '/' . $dir . '_thumbs/' . $file;
             if (!file_exists($target) && is_image($full . '/' . $file)) {
                 require_code('images');
                 convert_image($full . '/' . $file, $target, -1, -1, intval(get_option('thumb_width')));
             }
         }
     }
     closedir($dh);
 }
示例#2
0
/**
 * Make sure the detailed image file is not bigger than the defined box width.
 *
 * @param  PATH			The path to the image file
 * @param  string			The original filename of the image
 * @param  integer		The box width
 */
function constrain_gallery_image_to_max_size($file_path, $filename, $box_width)
{
    // We can't watermark an image we can't save
    require_code('images');
    if (!is_saveable_image($filename)) {
        return;
    }
    if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
        convert_image($file_path, $file_path, -1, -1, $box_width, false, get_file_extension($filename), true, true);
    }
}
示例#3
0
/**
 * Take some image/thumbnail info, and if needed make and caches a thumbnail, and return a thumb url whatever the situation.
 *
 * @param  URLPATH		The full URL to the image which will-be/is thumbnailed
 * @param  URLPATH		The URL to the thumbnail (blank: no thumbnail yet)
 * @param  ID_TEXT		The directory, relative to the ocPortal uploads directory, where the thumbnails are stored. MINUS "_thumbs"
 * @param  ID_TEXT		The name of the table that is storing what we are doing the thumbnail for
 * @param  AUTO_LINK		The ID of the table record that is storing what we are doing the thumbnail for
 * @param  ID_TEXT		The name of the table field where thumbnails are saved
 * @param  ?integer		The thumbnail width to use (NULL: default)
 * @return URLPATH		The URL to the thumbnail
 */
function ensure_thumbnail($full_url, $thumb_url, $thumb_dir, $table, $id, $thumb_field_name = 'thumb_url', $thumb_width = NULL)
{
    if (is_null($thumb_width)) {
        $thumb_width = intval(get_option('thumb_width'));
    }
    if (get_option('is_on_gd') == '0' || !function_exists('imagetypes') || $full_url == '') {
        if (url_is_local($thumb_url) && $thumb_url != '') {
            return get_custom_base_url() . '/' . $thumb_url;
        }
        return $thumb_url;
    }
    if ($thumb_url != '') {
        if (url_is_local($thumb_url)) {
            $thumb_path = get_custom_file_base() . '/' . rawurldecode($thumb_url);
            if (!file_exists($thumb_path)) {
                $from = str_replace(' ', '%20', $full_url);
                if (url_is_local($from)) {
                    $from = get_custom_base_url() . '/' . $from;
                }
                if (is_video($from)) {
                    require_code('galleries2');
                    create_video_thumb($full_url, $thumb_path);
                } else {
                    convert_image($from, $thumb_path, intval($thumb_width), -1, -1, false);
                }
            }
            return get_custom_base_url() . '/' . $thumb_url;
        }
        return $thumb_url;
    }
    $url_parts = explode('/', $full_url);
    $i = 0;
    $_file = $url_parts[count($url_parts) - 1];
    $dot_pos = strrpos($_file, '.');
    $ext = substr($_file, $dot_pos + 1);
    if (!is_saveable_image($_file)) {
        $ext = 'png';
    }
    $_file = preg_replace('#[^\\w]#', 'x', substr($_file, 0, $dot_pos));
    $thumb_path = '';
    do {
        $file = rawurldecode($_file) . ($i == 0 ? '' : strval($i));
        $thumb_path = get_custom_file_base() . '/uploads/' . $thumb_dir . '_thumbs/' . $file . '.' . $ext;
        $i++;
    } while (file_exists($thumb_path));
    $thumb_url = 'uploads/' . $thumb_dir . '_thumbs/' . rawurlencode($file) . '.' . $ext;
    if (substr($table, 0, 2) == 'f_' && get_forum_type() == 'ocf') {
        $GLOBALS['FORUM_DB']->query_update($table, array($thumb_field_name => $thumb_url), array('id' => $id), '', 1);
    } else {
        $GLOBALS['SITE_DB']->query_update($table, array($thumb_field_name => $thumb_url), array('id' => $id), '', 1);
    }
    $from = str_replace(' ', '%20', $full_url);
    if (url_is_local($from)) {
        $from = get_custom_base_url() . '/' . $from;
    }
    if (!file_exists($thumb_path)) {
        if (is_video($from)) {
            require_code('galleries2');
            create_video_thumb($full_url, $thumb_path);
        } else {
            convert_image($from, $thumb_path, intval($thumb_width), -1, -1, false);
        }
    }
    return get_custom_base_url() . '/' . $thumb_url;
}
示例#4
0
     $ret = convert_image($filename, $output_filename, $res, $is_thumbnail);
     if ($ret) {
         echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
         $convert_success = true;
     } else {
         echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
         echo "Aborting...\n<br>\n";
         $convert_success = false;
         break;
     }
 }
 // convert image to JPEG with original resolution
 if ($convert_success) {
     $output_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
     $res = $img_data['width'] . 'x' . $img_data['height'];
     $ret = convert_image($filename, $output_filename, $res, false);
     if ($ret) {
         echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
         $convert_success = true;
     } else {
         echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
         echo "Aborting...\n<br>\n";
         $convert_success = false;
     }
 }
 if ($convert_success) {
     // we have all necessary files now, so we get a correct id and move the files
     //
     // in unlikely cases this section will cause trouble, i.e. when someone gets
     // a new id while we are copying and before we insert into the database
     echo "\n<br>\nCopying generated image versions to their correct locations: \n<br><br>\n";
示例#5
0
function process_image_directory($dir, $query, $debug = false)
{
    global $config;
    global $db, $db_prefix, $user;
    global $resolutions_available;
    global $formats_available;
    global $formats_suffix;
    global $imagemagick_identify;
    global $imagemagick_convert;
    global $file_binary, $zip_binary, $unzip_binary;
    $files = array();
    $remove = array();
    if (!read_recursive($dir, $files, $remove)) {
        echo "Error reading directory structure\n<br>\n";
    } else {
        if (!empty($dir)) {
            $offset = strlen($dir) + 1;
        } else {
            $offset = 0;
        }
        foreach ($files as $num => $val) {
            $files[$num] = substr($val, $offset);
        }
        foreach ($remove as $num => $val) {
            $remove[$num] = substr($val, $offset);
        }
        usort($remove, "cmp");
        if ($debug) {
            echo "Files: \n<br>\n<br>\n";
            foreach ($files as $num => $val) {
                echo "[" . $num . "]: " . $val . "\n<br>\n";
            }
            echo "Remove: \n<br>\n<br>\n";
            foreach ($remove as $num => $val) {
                echo "[" . $num . "]: " . $val . "\n<br>\n";
            }
        }
        echo "Reading directory structure done.\n<br>\n<br>\n";
        foreach ($files as $file) {
            echo "<em>Reading file: " . $file . "</em>\n<br>\n";
            if (!empty($dir)) {
                $filename = $dir . addslashes(DIRECTORY_SEPARATOR . $file);
            } else {
                $filename = $file;
            }
            if (is_file($filename)) {
                $mimetype = '';
                $fileext = '';
                $dotpos = strrpos($filename, '.');
                if (strlen($filename) - $dotpos > 3 && strlen($filename) - $dotpos < 6) {
                    $fileext = strtolower(substr($filename, $dotpos + 1));
                }
                $ret = read_mime($filename, $mimetype, $fileext);
                if (!$ret) {
                    $errorstring = "Error reading image mimetype! \n<br>\n";
                    $errorstring .= "File:" . $filename . "\n<br>\n";
                    echo $errorstring;
                } else {
                    echo "Mimetype: " . $mimetype . "\n<br>\n";
                    if (in_array($mimetype, $formats_available)) {
                        // extract image information
                        // we already have the mimetype
                        $img_data = array();
                        $img_data['mime'] = $mimetype;
                        // try to read the rest
                        $ret = read_image($filename, $img_data);
                        if (!$ret) {
                            $errorstring = "Error reading image information! \n<br>\n";
                            $errorstring .= "File:" . $filename . "\n<br>\n";
                            echo $errorstring;
                        } else {
                            echo "Type:\t\t" . $img_data["type"] . "\n<br>\n";
                            echo "Width:\t\t" . $img_data["width"] . "\n<br>\n";
                            echo "Height:\t\t" . $img_data["height"] . "\n<br>\n";
                            // get output directory
                            $baseid = $query['baseid'];
                            $sql = "SELECT base FROM " . $db_prefix . "img_base WHERE img_baseid=" . $db->qstr($baseid);
                            $output_dir = $db->GetOne($sql);
                            if (empty($output_dir)) {
                                $errorstring = "Error reading output directory! \n<br>\n";
                                $errorstring .= "BaseID: " . $baseid . "\n<br>\n";
                                $errorstring .= "Directory: " . $output_dir . "\n<br>\n";
                                die($errorstring);
                            }
                            // use a temporary directory, where we can store the converted files until we have
                            // completed the task for all resolutions.
                            // we will move files from there into the correct directory later
                            $tmpdir = $config['imageTmp'];
                            if (!is_dir($tmpdir)) {
                                $errorstring = "Could not find temporary directory! \n<br>\n";
                                $errorstring .= "Path: " . $tmpdir . "\n<br>\n";
                                die($errorstring);
                            }
                            // check if we already have a cache directory structure, otherwise create
                            $ret = check_dir($tmpdir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, true, true, 0755);
                            if (!$ret) {
                                $errorstring = "Temporary directory cache does not exist or is not writable! \n<br>\n";
                                die($errorstring);
                            }
                            // generate image in all necessary resolutions
                            // you can skip resolutions by changing the array at this point
                            $resolutions = $resolutions_available;
                            foreach ($resolutions as $res) {
                                $ret = check_dir($tmpdir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
                                if (!$ret) {
                                    $errorstring = "Error creating temporary directory cache for resolution: {$res}! \n<br>\n";
                                    die($errorstring);
                                }
                            }
                            // generate temporary id string
                            $tmpid = generate_random_string();
                            // carry out conversion steps
                            echo "\n<br>\n<em>Generating image versions for all resolutions:</em>\n<br><br>\n";
                            if ($config['imagick_mode'] == 'fast') {
                                $ret = convert_image_batch($filename, $tmpdir . 'cache', $tmpid, $resolutions);
                                if ($ret) {
                                    echo "Generating images (batch mode)\t\t\t: success\n<br>\n";
                                    $convert_success = true;
                                } else {
                                    echo "Generating images (batch mode)\t\t\t: failed\n<br>\n";
                                    echo "Aborting...\n<br>\n";
                                    $convert_success = false;
                                }
                            } else {
                                // convert image to JPG at 1600x1200 as a base for the following conversion
                                $baseimage_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
                                $res = '1600x1200';
                                $ret = convert_image($filename, $baseimage_filename, $res, false);
                                if ($ret) {
                                    echo "Generating base image\t\t\t: success\n<br>\n";
                                    $convert_success = true;
                                } else {
                                    echo "Generating base image\t\t\t: failed\n<br>\n";
                                    echo "Aborting...\n<br>\n";
                                    $convert_success = false;
                                }
                                // the following lines will generate a JPG-version of your original image
                                // uncomment them, if you need it (requires additional computation time)
                                /*
                                if ($convert_success)
                                {
                                	$output_filename = $tmpdir.'cache'.DIRECTORY_SEPARATOR.$tmpid.'.jpg';
                                	
                                	$res = $img_data['width'].'x'.$img_data['height'];
                                	
                                	$ret = convert_image($filename,$output_filename,$res, false);
                                	
                                	if ($ret)
                                	{
                                		echo ("Writing (".$res.")\t\t\t: success\n<br>\n");
                                		$convert_success = true;
                                	}
                                	else
                                	{
                                		echo ("Writing (".$res.")\t\t\t: failed\n<br>\n");
                                		echo ("Aborting...\n<br>\n");
                                		$convert_success = false;
                                	}
                                }
                                */
                                if ($convert_success) {
                                    foreach ($resolutions as $res) {
                                        $ret = check_dir($tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
                                        // check if cache subdirectories exist
                                        if (!$ret) {
                                            $errorstring = "Error creating directory for resolution " . $res . "\n<br>\n";
                                            $errorstring .= "or directory exists and is not writable\n<br>\n";
                                            die($errorstring);
                                        }
                                        if ($res == '120x90') {
                                            $is_thumbnail = true;
                                        } else {
                                            $is_thumbnail = false;
                                        }
                                        $output_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
                                        $ret = convert_image($baseimage_filename, $output_filename, $res, $is_thumbnail);
                                        if ($ret) {
                                            echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
                                            $convert_success = true;
                                        } else {
                                            echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
                                            echo "Aborting...\n<br>\n";
                                            $convert_success = false;
                                            break;
                                        }
                                    }
                                }
                            }
                            if ($convert_success) {
                                // we have all necessary files now, so we get a correct id and move the files
                                //
                                // in unlikely cases this section will cause trouble, i.e. when someone gets
                                // a new id while we are copying and before we insert into the database
                                echo "\n<br>\n<em>Copying generated image versions to their correct locations:</em> \n<br><br>\n";
                                // check if we already have a cache directory structure, otherwise create
                                $ret = check_dir($output_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, true, true, 0755);
                                if (!$ret) {
                                    $errorstring = "Output directory cache does not exist or is not writable! \n<br>\n";
                                    die($errorstring);
                                }
                                // get new id for filename
                                $sql = "SELECT max(imageid)+1 FROM " . $db_prefix . "img";
                                $newid = $db->GetOne($sql);
                                if (!$newid) {
                                    $newid = 1;
                                }
                                // iterate through all available resolutions and check whether the target directory exists
                                // if yes, move the corresponding file, otherwise abort.
                                foreach ($resolutions as $res) {
                                    $ret = check_dir($output_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
                                    // check if cache subdirectories exist
                                    if (!$ret) {
                                        $errorstring = "Error creating directory for resolution " . $res . "\n<br>\n";
                                        $errorstring .= "or directory exists and is not writable\n<br>\n";
                                        die($errorstring);
                                    }
                                    $tmp_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
                                    $output_filename = $output_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $query['collectionid'] . '-' . $newid . '.jpg';
                                    $ret = @copy($tmp_filename, $output_filename);
                                    if ($ret) {
                                        echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
                                        $convert_success = true;
                                    } else {
                                        echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
                                        echo "Aborting...\n<br>\n";
                                        $convert_success = false;
                                        break;
                                    }
                                    // if unlink fails, we just loose some disk space
                                    @unlink($tmp_filename);
                                }
                                // if you decided to enable JPG-Versions in original resolution,
                                // uncomment the following lines to copy them to the target
                                // directory
                                /*
                                // copy the JPEG version with original resolution
                                if ($convert_success)
                                {
                                	$tmp_filename = $tmpdir.'cache'.DIRECTORY_SEPARATOR.$tmpid.'.jpg';
                                											
                                	$output_filename = $output_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.$query['collectionid'].'-'.$newid.'.jpg';
                                		
                                	$ret = @copy($tmp_filename,$output_filename);
                                	
                                	$res = $img_data['width'].'x'.$img_data['height'];
                                	
                                	if ($ret)
                                	{
                                		echo ("Writing (".$res.")\t\t\t: success\n<br>\n");
                                		$convert_success = true;
                                	}
                                	else
                                	{
                                		echo ("Writing (".$res.")\t\t\t: failed\n<br>\n");
                                		echo ("Aborting...\n<br>\n");
                                		$convert_success = false;
                                	}
                                	
                                	// if unlink fails, we just loose some disk space
                                	@unlink($tmp_filename);	
                                }			
                                */
                                if ($config['imagick_mode'] != 'fast') {
                                    // try to delete temprorary base image
                                    // if unlink fails, we just loose some disk space
                                    @unlink($baseimage_filename);
                                }
                                if ($convert_success) {
                                    // all generated versions copied, so we finally try the original
                                    $newfilename = $query['collectionid'] . '-' . $newid . '.' . $formats_suffix[$img_data["mime"]];
                                    $source = $filename;
                                    $dest = $output_dir . DIRECTORY_SEPARATOR . $newfilename;
                                    $ret = @copy($filename, $output_dir . DIRECTORY_SEPARATOR . $newfilename);
                                    if (!$ret) {
                                        echo "Copying original image\t: failed\n<br>\n";
                                        echo "Aborting...\n<br>\n";
                                    } else {
                                        echo "Copying original image\t: success\n<br>\n";
                                        // set permissions
                                        $ret = @chmod($output_dir . DIRECTORY_SEPARATOR . $newfilename, 0755);
                                        if (!$ret) {
                                            echo "Modyfing permissions\t: failed\n<br>\n";
                                        } else {
                                            echo "Modyfing permissions\t: success\n<br>\n";
                                        }
                                        $ret = @unlink($filename);
                                        if (!$ret) {
                                            echo "Removing uploaded file\t: failed\n<br>\n";
                                        } else {
                                            echo "Removing uploaded file\t: success\n<br>\n";
                                        }
                                        echo "\n<br>\n";
                                        // here our critical section ends, after the next command, the image counter
                                        // is increased by 1
                                        // get current time
                                        $sql = "SELECT NOW()";
                                        $time = $db->GetOne($sql);
                                        $ret = insert_img($query['collectionid'], $newid, $baseid, $file, $img_data, $time);
                                        if (!$ret) {
                                            echo "Inserting into database (image)\t\t\t: failed\n<br>\n";
                                            echo "Aborting...\n<br>\n";
                                        } else {
                                            echo "Inserting into database (image)\t\t\t: success\n<br>\n";
                                            $ret = insert_meta($query['collectionid'], $newid, $time, $user['login'], $query['type']);
                                            if (!$ret) {
                                                echo "Inserting into database (meta)\t\t\t: failed\n<br>\n";
                                                echo "Aborting...\n<br>\n";
                                            } else {
                                                echo "Inserting into database (meta)\t\t\t: success\n<br>\n";
                                                if (!empty($query['group1id'])) {
                                                    $ret = insert_img_group($query['group1id'], $query['collectionid'], $newid);
                                                    if (!$ret) {
                                                        // a failed group insertion is non-critical, so we continue
                                                        echo "Inserting into database (group1)\t\t\t: failed\n<br>\n";
                                                    } else {
                                                        echo "Inserting into database (group1)\t\t\t: success\n<br>\n";
                                                    }
                                                }
                                                if (!empty($query['group2id'])) {
                                                    $ret = insert_img_group($query['group2id'], $query['collectionid'], $newid);
                                                    if (!$ret) {
                                                        // a failed group insertion is non-critical, so we continue
                                                        echo "Inserting into database (group2)\t\t\t: failed\n<br>\n";
                                                    } else {
                                                        echo "Inserting into database (group2)\t\t\t: success\n<br>\n";
                                                    }
                                                }
                                                if (!empty($query['group3id'])) {
                                                    $ret = insert_img_group($query['group3id'], $query['collectionid'], $newid);
                                                    if (!$ret) {
                                                        // a failed group insertion is non-critical, so we continue
                                                        echo "Inserting into database (group3)\t\t\t: failed\n<br>\n";
                                                    } else {
                                                        echo "Inserting into database (group3)\t\t\t: success\n<br>\n";
                                                    }
                                                }
                                            }
                                            // end of actions - output a newline
                                            echo "\n<br>\n";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Image is processed completely
            echo "<em>" . $file . " done</em>\n<br><br>\n";
            flush();
        }
    }
    // after all images have been processed, we try to clean up the upload directory, so things do not get inserted twice
    foreach ($remove as $removethis) {
        if (!empty($dir)) {
            $removedir = $dir . DIRECTORY_SEPARATOR . $removethis;
        } else {
            $removedir = $removethis;
        }
        if ($debug) {
            echo "Purging possible thumbs.db file from: " . $removedir . "\n<br>\n";
        }
        $ret = @unlink($removedir . 'Thumbs.db');
        if ($debug) {
            echo "Now removing: " . $removedir . "\n<br>\n";
        }
        $ret = @rmdir($removedir);
        if (!$ret) {
            $errorstring = "Notice: " . $removedir . " could not be removed\n<br>\n";
            $errorstring .= "Insufficient permission or directory not empty\n<br>\n";
            echo $errorstring;
        }
    }
    if ($debug) {
        echo "Purging possible thumbs.db file from: " . $dir . "\n<br>\n";
    }
    $ret = @unlink($dir . 'Thumbs.db');
    if ($debug) {
        echo "Now removing: " . $dir . "\n<br>\n";
    }
    $ret = @rmdir($dir);
    if (!$ret) {
        $errorstring = "Notice: " . $dir . " could not be removed\n<br>\n";
        $errorstring .= "Insufficient permission or directory not empty\n<br>\n";
        echo $errorstring;
    }
    return;
}
示例#6
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     $id = intval($_id);
     $validated = post_param_integer('validated', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $news_article = post_param('post', STRING_MAGIC_NULL);
     if (post_param('main_news_category') != 'personal') {
         $main_news_category = post_param_integer('main_news_category', INTEGER_MAGIC_NULL);
     } else {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $news_category = array();
     if (array_key_exists('news_category', $_POST)) {
         foreach ($_POST['news_category'] as $val) {
             $news_category[] = intval($val);
         }
     }
     $allow_rating = post_param_integer('allow_rating', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_comments = post_param_integer('allow_comments', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $allow_trackbacks = post_param_integer('allow_trackbacks', fractional_edit() ? INTEGER_MAGIC_NULL : 0);
     $notes = post_param('notes', STRING_MAGIC_NULL);
     $this->donext_type = $main_news_category;
     if (!fractional_edit()) {
         $urls = get_url('', 'file', 'uploads/grepimages', 0, OCP_UPLOAD_IMAGE);
         $url = $urls[0];
         if ($url != '' && function_exists('imagecreatefromstring')) {
             convert_image(get_base_url() . '/' . $url, get_file_base() . '/uploads/grepimages/' . basename(rawurldecode($url)), -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
         }
         if ($url == '' && post_param_integer('file_unlink', 0) != 1) {
             $url = NULL;
         }
     } else {
         $url = STRING_MAGIC_NULL;
     }
     $owner = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'nc_owner', array('id' => $main_news_category));
     // null_ok in case somehow category setting corrupted
     if (!is_null($owner) && $owner != get_member()) {
         check_specific_permission('can_submit_to_others_categories', array('news', $main_news_category), NULL, 'cms_news');
     }
     $schedule = get_input_date('schedule');
     $add_time = is_null($schedule) ? mixed() : $schedule;
     if (addon_installed('calendar') && has_specific_permission(get_member(), 'scheduled_publication_times')) {
         require_code('calendar2');
         $schedule_code = ':$GLOBALS[\'SITE_DB\']->query_update(\'news\',array(\'date_and_time\'=>$GLOBALS[\'event_timestamp\'],\'validated\'=>1),array(\'id\'=>' . strval($id) . '),\'\',1);';
         $past_event = $GLOBALS['SITE_DB']->query_value_null_ok('calendar_events e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON e.e_content=t.id', 'e.id', array('text_original' => $schedule_code));
         require_code('calendar');
         if (!is_null($past_event)) {
             delete_calendar_event($past_event);
         }
         if (!is_null($schedule) && $schedule > time()) {
             $validated = 0;
             $start_year = post_param_integer('schedule_year');
             $start_month = post_param_integer('schedule_month');
             $start_day = post_param_integer('schedule_day');
             $start_hour = post_param_integer('schedule_hour');
             $start_minute = post_param_integer('schedule_minute');
             $event_id = add_calendar_event(db_get_first_id(), 'none', NULL, 0, do_lang('PUBLISH_NEWS', 0, post_param('title')), $schedule_code, 3, 0, $start_year, $start_month, $start_day, $start_hour, $start_minute);
             regenerate_event_reminder_jobs($event_id, true);
         }
     }
     $title = post_param('title', STRING_MAGIC_NULL);
     if ($validated == 1 && $main_news_category != INTEGER_MAGIC_NULL && $GLOBALS['SITE_DB']->query_value('news', 'validated', array('id' => intval($id))) == 0) {
         $is_blog = true;
         $submitter = $GLOBALS['SITE_DB']->query_value('news', 'submitter', array('id' => $id));
         $activity_title = $is_blog ? 'news:ACTIVITY_ADD_NEWS_BLOG' : 'news:ACTIVITY_ADD_NEWS';
         $activity_title_validate = $is_blog ? 'news:ACTIVITY_VALIDATE_NEWS_BLOG' : 'news:ACTIVITY_VALIDATE_NEWS';
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'news')) {
             // NB: no category permission check, as syndication choice was explicit, and news categorisation is a bit more complex
             syndicate_described_activity($submitter != get_member() ? $activity_title_validate : $activity_title, $title, '', '', '_SEARCH:news:view:' . strval($id), '', '', 'news', 1, NULL, true);
         }
     }
     edit_news(intval($id), $title, post_param('news', STRING_MAGIC_NULL), post_param('author', STRING_MAGIC_NULL), $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $news_article, $main_news_category, $news_category, post_param('meta_keywords', STRING_MAGIC_NULL), post_param('meta_description', STRING_MAGIC_NULL), $url, $add_time);
 }
示例#7
0
/**
 * Get URLs generated according to the specified information. It can also generate a thumbnail if required. It first tries attached upload, then URL, then fails.
 *
 * @param  ID_TEXT		The name of the POST parameter storing the URL (if '', then no POST parameter). Parameter value may be blank.
 * @param  ID_TEXT		The name of the HTTP file parameter storing the upload (if '', then no HTTP file parameter). No file necessarily is uploaded under this.
 * @param  ID_TEXT		The folder name in uploads/ where we will put this upload
 * @param  integer		Whether to obfuscate file names so the URLs can not be guessed/derived (0=do not, 1=do, 2=make extension .dat as well, 3=only obfuscate if we need to)
 * @set    0 1 2 3
 * @param  integer		The type of upload it is (from an OCP_UPLOAD_* constant)
 * @param  boolean		Make a thumbnail (this only makes sense, if it is an image)
 * @param  ID_TEXT		The name of the POST parameter storing the thumb URL. As before
 * @param  ID_TEXT		The name of the HTTP file parameter storing the thumb upload. As before
 * @param  boolean		Whether to copy a URL (if a URL) to the server, and return a local reference
 * @param  boolean		Whether to accept upload errors
 * @param  boolean		Whether to give a (deferred?) error if no file was given at all
 * @return array			An array of 4 URL bits (URL, thumb URL, URL original filename, thumb original filename)
 */
function get_url($specify_name, $attach_name, $upload_folder, $obfuscate = 0, $enforce_type = 0, $make_thumbnail = false, $thumb_specify_name = '', $thumb_attach_name = '', $copy_to_server = false, $accept_errors = false, $should_get_something = false)
{
    require_code('files2');
    $upload_folder = filter_naughty($upload_folder);
    $out = array();
    $thumb = NULL;
    $swf_uploaded = false;
    $swf_uploaded_thumb = false;
    foreach (array($attach_name, $thumb_attach_name) as $i => $_attach_name) {
        if ($_attach_name == '') {
            continue;
        }
        //check whatever it is an incoming upload
        $row_id_file = 'hidFileID_' . $_attach_name;
        $row_id_file_value = post_param($row_id_file, NULL);
        if ($row_id_file_value == '-1') {
            $row_id_file_value = NULL;
        }
        //id of the upload from the incoming uploads database table
        if (!is_null($row_id_file_value)) {
            //get the incoming uploads appropiate db table row
            if (substr($row_id_file_value, -4) == '.dat' && strpos($row_id_file_value, ':') === false) {
                $path = 'uploads/incoming/' . filter_naughty($row_id_file_value);
                if (file_exists(get_custom_file_base() . '/' . $path)) {
                    $_FILES[$_attach_name] = array('type' => 'swfupload', 'name' => post_param(str_replace('hidFileID', 'hidFileName', $row_id_file)), 'tmp_name' => get_custom_file_base() . '/' . $path, 'size' => filesize(get_custom_file_base() . '/' . $path));
                    if ($i == 0) {
                        $swf_uploaded = true;
                    } else {
                        $swf_uploaded_thumb = true;
                    }
                }
            } else {
                $incoming_uploads_id = intval(preg_replace('#:.*$#', '', $row_id_file_value));
                $incoming_uploads_row = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'incoming_uploads WHERE (i_submitter=' . strval(get_member()) . ' OR i_submitter=' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ') AND id=' . strval($incoming_uploads_id), 1);
                //if there is a db record proceed
                if (array_key_exists(0, $incoming_uploads_row)) {
                    if (file_exists(get_custom_file_base() . '/' . $incoming_uploads_row[0]['i_save_url'])) {
                        $_FILES[$_attach_name] = array('type' => 'swfupload', 'name' => $incoming_uploads_row[0]['i_orig_filename'], 'tmp_name' => get_custom_file_base() . '/' . $incoming_uploads_row[0]['i_save_url'], 'size' => filesize(get_custom_file_base() . '/' . $incoming_uploads_row[0]['i_save_url']));
                        if ($i == 0) {
                            $swf_uploaded = true;
                        } else {
                            $swf_uploaded_thumb = true;
                        }
                    }
                }
            }
        }
    }
    if ($obfuscate == 3) {
        $accept_errors = true;
    }
    $thumb_folder = strpos($upload_folder, 'uploads/galleries') !== false ? str_replace('uploads/galleries', 'uploads/galleries_thumbs', $upload_folder) : $upload_folder . '_thumbs';
    if (!file_exists(get_custom_file_base() . '/' . $upload_folder)) {
        $success = @mkdir(get_custom_file_base() . '/' . $upload_folder, 0777);
        if ($success === false) {
            warn_exit(@strval($php_errormsg));
        }
        fix_permissions(get_custom_file_base() . '/' . $upload_folder, 0777);
        sync_file($upload_folder);
    }
    if (!file_exists(get_custom_file_base() . '/' . $thumb_folder) && $make_thumbnail) {
        $success = @mkdir(get_custom_file_base() . '/' . $thumb_folder, 0777);
        if ($success === false) {
            warn_exit(@strval($php_errormsg));
        }
        fix_permissions(get_custom_file_base() . '/' . $thumb_folder, 0777);
        sync_file($thumb_folder);
    }
    // Find URL
    require_code('images');
    if ($enforce_type == OCP_UPLOAD_IMAGE || $enforce_type == OCP_UPLOAD_IMAGE_OR_SWF) {
        $max_size = get_max_image_size();
    } else {
        require_code('files2');
        $max_size = get_max_file_size();
    }
    if ($attach_name != '' && array_key_exists($attach_name, $_FILES) && (is_uploaded_file($_FILES[$attach_name]['tmp_name']) || $swf_uploaded)) {
        if (!has_specific_permission(get_member(), 'exceed_filesize_limit')) {
            if ($_FILES[$attach_name]['size'] > $max_size) {
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
                }
            }
        }
        $url = _get_upload_url($attach_name, $upload_folder, $enforce_type, $obfuscate, $accept_errors);
        if ($url == array('', '')) {
            return array('', '', '', '');
        }
        $is_image = is_image($_FILES[$attach_name]['name']);
    } elseif (post_param($specify_name, '') != '') {
        $is_image = is_image($_POST[$specify_name], true);
        $url = _get_specify_url($specify_name, $upload_folder, $enforce_type, $accept_errors);
        if ($url == array('', '')) {
            return array('', '', '', '');
        }
        if ($copy_to_server && !url_is_local($url[0])) {
            $path2 = ocp_tempnam('ocpfc');
            $tmpfile = fopen($path2, 'wb');
            $file = http_download_file($url[0], $max_size, true, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $tmpfile);
            fclose($tmpfile);
            if (is_null($file)) {
                @unlink($path2);
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('CANNOT_COPY_TO_SERVER'), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('CANNOT_COPY_TO_SERVER'));
                }
            }
            global $HTTP_FILENAME;
            if (is_null($HTTP_FILENAME)) {
                $HTTP_FILENAME = $url[1];
            }
            if (!check_extension($HTTP_FILENAME, $obfuscate == 2, $path2, $accept_errors)) {
                if ($obfuscate == 3) {
                    $obfuscate = 2;
                    if (!check_extension($HTTP_FILENAME, $obfuscate == 2, $path2, $accept_errors)) {
                        return array('', '', '', '');
                    }
                } else {
                    return array('', '', '', '');
                }
            }
            if (url_is_local($url[0])) {
                unlink($path2);
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('CANNOT_COPY_TO_SERVER'), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('CANNOT_COPY_TO_SERVER'));
                }
            }
            if ($obfuscate != 0 && $obfuscate != 3) {
                $ext = $obfuscate == 2 && !is_image($HTTP_FILENAME) ? 'dat' : get_file_extension($HTTP_FILENAME);
                $_file = preg_replace('#\\..*\\.#', '.', $HTTP_FILENAME) . (substr($HTTP_FILENAME, -strlen($ext) - 1) == '.' . $ext ? '' : '.' . $ext);
                $place = get_custom_file_base() . '/' . $upload_folder . '/' . $_file;
                while (file_exists($place)) {
                    $_file = uniqid('', true) . '.' . $ext;
                    $place = get_custom_file_base() . '/' . $upload_folder . '/' . $_file;
                }
            } else {
                $_file = $HTTP_FILENAME;
                $place = get_custom_file_base() . '/' . $upload_folder . '/' . $_file;
            }
            if (!has_specific_permission(get_member(), 'exceed_filesize_limit')) {
                $max_size = intval(get_option('max_download_size')) * 1024;
                if (strlen($file) > $max_size) {
                    if ($accept_errors) {
                        attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)), 'warn');
                        return array('', '', '', '');
                    } else {
                        warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
                    }
                }
            }
            $result = @rename($path2, $place);
            if (!$result) {
                unlink($path2);
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('WRITE_ERROR', escape_html($upload_folder)), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html($upload_folder)));
                }
            }
            fix_permissions($place);
            sync_file($place);
            $url[0] = $upload_folder . '/' . $_file;
            if (strpos($HTTP_FILENAME, '/') === false) {
                $url[1] = $HTTP_FILENAME;
            }
        }
    } else {
        if (array_key_exists($attach_name, $_FILES) && array_key_exists('error', $_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] != 4 || $should_get_something) && $_FILES[$attach_name]['error'] != 0) {
            if ($_FILES[$attach_name]['error'] == 1) {
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
                }
            } elseif ($_FILES[$attach_name]['error'] == 2) {
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('FILE_TOO_BIG_QUOTA', integer_format($max_size)), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('FILE_TOO_BIG_QUOTA', integer_format($max_size)));
                }
            } elseif ($_FILES[$attach_name]['error'] == 3 || $_FILES[$attach_name]['error'] == 4 || $_FILES[$attach_name]['error'] == 6 || $_FILES[$attach_name]['error'] == 7) {
                attach_message(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])), 'warn');
                return array('', '', '', '');
            } else {
                warn_exit(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])));
            }
        }
        $url[0] = '';
        $url[1] = '';
        $is_image = false;
    }
    $out[0] = $url[0];
    $out[2] = $url[1];
    // Generate thumbnail if needed
    if ($make_thumbnail && $url[0] != '' && $is_image) {
        if (array_key_exists($thumb_attach_name, $_FILES) && (is_uploaded_file($_FILES[$thumb_attach_name]['tmp_name']) || $swf_uploaded_thumb)) {
            if ($_FILES[$thumb_attach_name]['size'] > get_max_image_size()) {
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())));
                }
            }
            $_thumb = _get_upload_url($thumb_attach_name, $thumb_folder, OCP_UPLOAD_IMAGE, 0, $accept_errors);
            $thumb = $_thumb[0];
        } elseif (array_key_exists($thumb_specify_name, $_POST)) {
            $_thumb = _get_specify_url($thumb_specify_name, $thumb_folder, OCP_UPLOAD_IMAGE, $accept_errors);
            $thumb = $_thumb[0];
        } else {
            $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
            if ($gd) {
                if (!is_saveable_image($url[0])) {
                    $ext = '.png';
                } else {
                    $ext = '';
                }
                $file = preg_replace('#[^\\w\\.]#', 'x', basename($url[0]));
                $_file = $file;
                $place = get_custom_file_base() . '/' . $thumb_folder . '/' . $_file . $ext;
                $i = 2;
                while (file_exists($place)) {
                    $_file = strval($i) . $file;
                    $place = get_custom_file_base() . '/' . $thumb_folder . '/' . $_file . $ext;
                    $i++;
                }
                $url_full = url_is_local($url[0]) ? get_custom_base_url() . '/' . $url[0] : $url[0];
                convert_image($url_full, $place, -1, -1, intval(get_option('thumb_width')));
                $thumb = $thumb_folder . '/' . rawurlencode($_file) . $ext;
            } else {
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('GD_THUMB_ERROR'), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('GD_THUMB_ERROR'));
                }
            }
        }
        $out[1] = $thumb;
    } elseif ($make_thumbnail) {
        if (array_key_exists($thumb_attach_name, $_FILES) && (is_uploaded_file($_FILES[$thumb_attach_name]['tmp_name']) || $swf_uploaded_thumb)) {
            if ($_FILES[$thumb_attach_name]['size'] > get_max_image_size()) {
                if ($accept_errors) {
                    attach_message(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())), 'warn');
                    return array('', '', '', '');
                } else {
                    warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(get_max_image_size())));
                }
            }
            $_thumb = _get_upload_url($thumb_attach_name, $thumb_folder, OCP_UPLOAD_IMAGE, 0, $accept_errors);
            $thumb = $_thumb[0];
        } elseif (array_key_exists($thumb_specify_name, $_POST)) {
            $_thumb = _get_specify_url($thumb_specify_name, $thumb_folder, OCP_UPLOAD_IMAGE, $accept_errors);
            $thumb = $_thumb[0];
        }
        if (!is_null($thumb)) {
            $out[1] = $thumb;
        } else {
            $out[1] = '';
        }
    }
    // For reentrance of previews
    if ($specify_name != '') {
        $_POST[$specify_name] = array_key_exists(0, $out) ? $out[0] : '';
    }
    if ($thumb_specify_name != '') {
        $_POST[$thumb_specify_name] = array_key_exists(1, $out) ? $out[1] : '';
    }
    return $out;
}
示例#8
0
 /**
  * Convert a VB database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  boolean		Whether to create a thumbnail for it
  * @param  string			Thumbnail data (blank: no thumbnail / generate one if asked)
  * @param  boolean		Whether to obfuscate the file type
  * @return array			A tuple containing the URL, and if requested, the thumbnail
  */
 function data_to_disk($data, $filename, $sections, $thumbnail = true, $thumbnail_data = '', $obfuscate = false)
 {
     if ($filename == '') {
         $filetype = '';
         if (substr($data, 4, 4) == 'JFIF') {
             $filetype = 'jpg';
         } elseif (substr($data, 0, 3) == 'GIF') {
             $filetype = 'gif';
         } elseif (substr($data, 1, 3) == 'PNG') {
             $filetype = 'png';
         }
         if ($filetype != '') {
             $filename = uniqid('', true) . '.' . $filetype;
         }
     }
     //if ((substr($filename,-4,4)=='.gif') && ($thumbnail)) $filename.='.png';
     if ($filename != '') {
         $filename = find_derivative_filename('uploads/' . $sections, $filename);
         $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
         $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : ''))));
         if (fwrite($myfile, $data) < strlen($data)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($path);
         sync_file($path);
         $url = 'uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
         if ($thumbnail_data == '') {
             if ($thumbnail) {
                 $t_filename = $filename;
                 $thumb_url = 'uploads/' . $sections . '_thumbs/' . find_derivative_filename('_thumbs', $t_filename, true);
                 require_code('images');
                 convert_image(get_custom_base_url() . '/' . $url, $thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
                 return array($url, $thumb_url);
             } else {
                 return array($url, '');
             }
         } else {
             $thumb_filename = find_derivative_filename('uploads/' . $sections . '_thumbs', $filename);
             $path = get_custom_file_base() . '/uploads/' . $sections . '_thumbs/' . $thumb_filename;
             $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '_thumbs/' . $thumb_filename)));
             if (fwrite($myfile, $thumbnail_data) < strlen($thumbnail_data)) {
                 warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
             }
             fclose($myfile);
             $thumb_url = 'uploads/' . $sections . '/' . $thumb_filename;
             fix_permissions($path);
             sync_file($path);
             return array($url, $thumb_url);
         }
     }
     return array('', '');
 }
示例#9
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_member_files($db, $table_prefix, $file_base)
 {
     global $STRICT_FILE;
     $row_start = 0;
     $rows = array();
     do {
         $query = 'SELECT * FROM ' . $table_prefix . 'members ORDER BY id';
         $rows = $db->query($query, 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('member_files', strval($row['id']))) {
                 continue;
             }
             $member_id = import_id_remap_get('member', strval($row['id']));
             $photo_url = '';
             $photo_thumb_url = '';
             $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'member_extra WHERE id=' . strval($row['id']));
             if (array_key_exists(0, $rows2)) {
                 $row2 = $rows2[0];
                 if ($row2['photo_type'] == 'upload') {
                     $filename = rawurldecode($row2['photo_location']);
                     if (file_exists(get_custom_file_base() . '/uploads/ocf_photos/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_photos/' . $filename)) {
                         $photo_url = 'uploads/ocf_photos/' . $filename;
                         sync_file($photo_url);
                     } else {
                         if ($STRICT_FILE) {
                             warn_exit(do_lang_tempcode('MISSING_PHOTO', $filename));
                         }
                         $photo_url = '';
                     }
                 } else {
                     $photo_url = $row2['photo_location'];
                     $rrpos = strrpos($photo_url, '/');
                     $filename = $rrpos === false ? $photo_url : substr($photo_url, $rrpos);
                 }
                 if ($photo_url != '' && function_exists('imagecreatefromstring')) {
                     $photo_thumb_url = 'uploads/ocf_photos_thumbs/' . find_derivative_filename('ocf_photos_thumbs', $filename, true);
                     require_code('images');
                     convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
                 }
                 if (either_param('importer') == 'ipb2') {
                     $row['avatar'] = $row2['avatar_location'];
                     $row['avatar_type'] = $row2['avatar_type'];
                 }
             }
             if (either_param('importer') == 'ipb2') {
                 if (!array_key_exists('avatar', $row)) {
                     $row['avatar'] = NULL;
                 }
             }
             $avatar_url = '';
             switch ($row['avatar']) {
                 case NULL:
                     break;
                 case 'noavatar':
                     break;
                 default:
                     if (substr($row['avatar'], 0, 7) == 'upload:') {
                         $filename = substr($row['avatar'], 7);
                         if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $filename)) {
                             $avatar_url = 'uploads/ocf_avatars/' . $filename;
                             sync_file($avatar_url);
                         } else {
                             if ($STRICT_FILE) {
                                 warn_exit(do_lang_tempcode('MISSING_AVATAR', $filename));
                             }
                             $avatar_url = '';
                         }
                     } elseif (url_is_local($row['avatar'])) {
                         $filename = rawurldecode($row['avatar']);
                         if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $filename) || @rename($file_base . '/uploads/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $filename)) {
                             $avatar_url = 'uploads/ocf_avatars/' . substr($filename, strrpos($filename, '/'));
                             sync_file($avatar_url);
                         } else {
                             // Try as a pack avatar then
                             $filename = rawurldecode($row['avatar']);
                             $striped_filename = str_replace('/', '_', $filename);
                             if (file_exists(get_custom_file_base() . '/uploads/ocf_avatars/' . $striped_filename) || @rename($file_base . '/style_avatars/' . $filename, get_custom_file_base() . '/uploads/ocf_avatars/' . $striped_filename)) {
                                 $avatar_url = 'uploads/ocf_avatars/' . substr($filename, strrpos($filename, '/'));
                                 sync_file($avatar_url);
                             } else {
                                 if ($STRICT_FILE) {
                                     warn_exit(do_lang_tempcode('MISSING_AVATAR', $filename));
                                 }
                                 $avatar_url = '';
                             }
                         }
                     } else {
                         $avatar_url = $row['avatar'];
                     }
             }
             $GLOBALS['FORUM_DB']->query_update('f_members', array('m_avatar_url' => $avatar_url, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url), array('id' => $member_id), '', 1);
             import_id_remap_put('member_files', strval($row['id']), 1);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
示例#10
0
/**
 * Get tempcode for a Comcode tag. This function should always return (errors should be placed in the Comcode output stream), for stability reasons (i.e. if you're submitting something, you can't have the whole submit process die half way through in an unstructured fashion).
 *
 * @param  string			The tag being converted
 * @param  array			A map of the attributes (name=>val) for the tag. Val is usually a string, although in select places, the XML parser may pass tempcode.
 * @param  mixed			Tempcode of the inside of the tag ([between]THIS[/between]); the XML parser may pass in special stuff here, which is interpreted only for select tags
 * @param  boolean		Whether we are allowed to proceed even if this tag is marked as 'dangerous'
 * @param  string			A special identifier to mark where the resultant tempcode is going to end up (e.g. the ID of a post)
 * @param  integer		The position this tag occurred at in the Comcode
 * @param  MEMBER			The member who is responsible for this Comcode
 * @param  boolean		Whether to check as arbitrary admin
 * @param  object			The database connection to use
 * @param  string			The whole chunk of comcode
 * @param  boolean		Whether this is for WML output
 * @param  boolean		Whether this is only a structure sweep
 * @param  boolean		Whether we are in semi-parse-mode (some tags might convert differently)
 * @param  ?array			A list of words to highlight (NULL: none)
 * @param  ?MEMBER		The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating)
 * @param  boolean		Whether what we have came from inside a semihtml tag
 * @param  boolean		Whether what we have came from semihtml mode
 * @return tempcode		The tempcode for the Comcode
 */
function _do_tags_comcode($tag, $attributes, $embed, $comcode_dangerous, $pass_id, $marker, $source_member, $as_admin, $connection, &$comcode, $wml, $structure_sweep, $semiparse_mode, $highlight_bits = NULL, $on_behalf_of_member = NULL, $in_semihtml = false, $is_all_semihtml = false)
{
    if ($structure_sweep && $tag != 'title') {
        return new ocp_tempcode();
    }
    $param_given = isset($attributes['param']);
    if (!isset($attributes['param']) && $tag != 'block') {
        $attributes['param'] = '';
    }
    global $DANGEROUS_TAGS, $STRUCTURE_LIST, $COMCODE_PARSE_TITLE;
    if (isset($DANGEROUS_TAGS[$tag]) && !$comcode_dangerous) {
        $username = $GLOBALS['FORUM_DRIVER']->get_username($source_member);
        if (is_null($username)) {
            $username = do_lang('UNKNOWN');
        }
        if ($semiparse_mode) {
            $params = '';
            foreach ($attributes as $key => $val) {
                $params .= ' ' . $key . '="' . comcode_escape($val) . '"';
            }
            return make_string_tempcode('<input class="ocp_keep_ui_controlled" size="45" title="[' . $tag . '' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? escape_html($embed->evaluate()) : escape_html($embed->evaluate())) . '[/' . $tag . ']" type="text" value="' . ($tag == 'block' ? do_lang('COMCODE_EDITABLE_BLOCK', escape_html($embed->evaluate())) : do_lang('COMCODE_EDITABLE_TAG', escape_html($tag))) . '" />');
        }
        return do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:NO_ACCESS_FOR_TAG', escape_html($tag), escape_html($username))));
        //return new ocp_tempcode();
    }
    // These are just bbcode compatibility tags.. we will remap to our proper comcode
    if ($tag == 'php') {
        $attributes['param'] = 'php';
        $tag = 'code';
    } elseif ($tag == 'sql') {
        $attributes['param'] = 'sql';
        $tag = 'code';
    } elseif ($tag == 'codebox') {
        $attributes['scroll'] = '1';
        $tag = 'code';
    } elseif ($tag == 'left') {
        $attributes['param'] = 'left';
        $tag = 'align';
    } elseif ($tag == 'center') {
        $attributes['param'] = 'center';
        $tag = 'align';
    } elseif ($tag == 'right') {
        $attributes['param'] = 'right';
        $tag = 'align';
    } elseif ($tag == 'thread') {
        $tag = 'topic';
    } elseif ($tag == 'internal_table' || $tag == 'external_table') {
        $tag = 'box';
        if (array_key_exists('class', $attributes)) {
            $attributes['type'] = $attributes['class'];
        }
    }
    if ($semiparse_mode) {
        $non_text_tags = array('attachment', 'section_controller', 'big_tab_controller', 'currency', 'block', 'contents', 'concepts', 'flash', 'menu', 'email', 'reference', 'upload', 'page', 'exp_thumb', 'exp_ref', 'thumb', 'snapback', 'post', 'thread', 'topic', 'include', 'random', 'jumping', 'shocker');
        // Also in JAVASCRIPT_EDITING.tpl
        if ($tag == 'attachment_safe') {
            if (preg_match('#^new\\_\\d+$#', $embed->evaluate()) != 0) {
                $non_text_tags[] = 'attachment_safe';
            }
        }
        if (in_array($tag, $non_text_tags)) {
            $params = '';
            foreach ($attributes as $key => $val) {
                $params .= ' ' . $key . '="' . str_replace('"', '\\"', $val) . '"';
            }
            if ($tag != 'block' || !is_file(get_file_base() . '/sources_custom/miniblocks/' . $embed->evaluate() . '.php')) {
                return make_string_tempcode('<input class="ocp_keep_ui_controlled" size="45" title="[' . $tag . '' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? escape_html($embed->evaluate()) : escape_html($embed->evaluate())) . '[/' . $tag . ']" type="text" value="' . ($tag == 'block' ? do_lang('comcode:COMCODE_EDITABLE_BLOCK', escape_html($embed->evaluate())) : do_lang('comcode:COMCODE_EDITABLE_TAG', escape_html($tag))) . '" />');
            } else {
                return make_string_tempcode('[block' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? $embed->evaluate() : escape_html($embed->evaluate())) . '[/block]');
            }
        }
    }
    $temp_tpl = new ocp_tempcode();
    switch ($tag) {
        case 'no_parse':
            $temp_tpl->attach($embed);
            break;
        case 'currency':
            if (addon_installed('ecommerce')) {
                $bracket = array_key_exists('bracket', $attributes) && $attributes['bracket'] == '1';
                if ($attributes['param'] == '') {
                    $attributes['param'] = get_option('currency');
                }
                $temp_tpl = do_template('COMCODE_CURRENCY', array('_GUID' => 'ee1fcdae082af6397ff3bad89006e012', 'AMOUNT' => $embed, 'FROM_CURRENCY' => $attributes['param'], 'BRACKET' => $bracket));
            }
            break;
        case 'overlay':
            $x = strval(array_key_exists('x', $attributes) ? intval($attributes['x']) : 100);
            $y = strval(array_key_exists('y', $attributes) ? intval($attributes['y']) : 100);
            $width = strval(array_key_exists('width', $attributes) ? intval($attributes['width']) : 300);
            $height = strval(array_key_exists('height', $attributes) ? intval($attributes['height']) : 300);
            $timein = strval(array_key_exists('timein', $attributes) ? intval($attributes['timein']) : 0);
            $timeout = strval(array_key_exists('timeout', $attributes) ? intval($attributes['timeout']) : -1);
            $temp_tpl = do_template('COMCODE_OVERLAY', array('_GUID' => 'dfd0f7a72cc2bf6b613b28f8165a0034', 'UNIQ_ID' => 'a' . uniqid('', true), 'EMBED' => $embed, 'ID' => $attributes['param'] != '' ? $attributes['param'] : 'rand' . uniqid('', true), 'X' => $x, 'Y' => $y, 'WIDTH' => $width, 'HEIGHT' => $height, 'TIMEIN' => $timein, 'TIMEOUT' => $timeout));
            break;
        case 'code':
            if ($wml) {
                $temp_tpl->attach('<b>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</b>');
                break;
            }
            list($_embed, $title) = do_code_box($attributes['param'], $embed, array_key_exists('numbers', $attributes) && $attributes['numbers'] == '1', $in_semihtml, $is_all_semihtml);
            if (!is_null($_embed)) {
                $tpl = array_key_exists('scroll', $attributes) && $attributes['scroll'] == '1' ? 'COMCODE_CODE_SCROLL' : 'COMCODE_CODE';
                if ($tpl == 'COMCODE_CODE_SCROLL' && substr_count($_embed, chr(10)) < 10) {
                    $style = 'height: auto';
                } else {
                    $style = '';
                }
                $temp_tpl = do_template($tpl, array('_GUID' => 'c5d46d0927272fcacbbabcfab0ef6b0c', 'STYLE' => $style, 'TYPE' => $attributes['param'], 'CONTENT' => $_embed, 'TITLE' => $title));
            } else {
                $_embed = '';
            }
            if ($temp_tpl->is_empty()) {
                if ($in_semihtml || $is_all_semihtml) {
                    require_code('comcode_from_html');
                    $back_to_comcode = semihtml_to_comcode($embed->evaluate());
                    // Undo what's happened already
                    //$back_to_comcode=html_entity_decode($back_to_comcode,ENT_QUOTES,get_charset()); // Remove the escaping entities that were inside the code tag
                    $embed = comcode_to_tempcode($back_to_comcode, $source_member, $as_admin, 80, $pass_id, $connection);
                    // Re-parse (with full security)
                }
                $_embed = $embed->evaluate();
                if (!array_key_exists('scroll', $attributes) && strlen($_embed) > 1000) {
                    $attributes['scroll'] = '1';
                }
                $tpl = array_key_exists('scroll', $attributes) && $attributes['scroll'] == '1' ? 'COMCODE_CODE_SCROLL' : 'COMCODE_CODE';
                $title = do_lang_tempcode('CODE');
                if ($tpl == 'COMCODE_CODE_SCROLL' && substr_count($_embed, chr(10)) < 10) {
                    $style = 'height: auto';
                } else {
                    $style = '';
                }
                $temp_tpl = do_template($tpl, array('CONTENT' => $_embed, 'TITLE' => $title, 'STYLE' => $style, 'TYPE' => $attributes['param']));
            }
            break;
        case 'list':
            if (is_array($embed)) {
                $parts = $embed;
            } else {
                $_embed = trim($embed->evaluate());
                $_embed = str_replace('[/*]', '', $_embed);
                $parts = explode('[*]', $_embed);
            }
            if (isset($temp_tpl->preprocessable_bits)) {
                $temp_tpl->preprocessable_bits = array_merge($temp_tpl->preprocessable_bits, $embed->preprocessable_bits);
            }
            if ($wml) {
                foreach ($parts as $i => $part) {
                    if ($i == 0 && str_replace(array('&nbsp;', '<br />', ' '), array('', '', ''), trim($part)) == '') {
                        continue;
                    }
                    $temp_tpl->attach('<br />* ');
                    $temp_tpl->attach($part);
                }
                $temp_tpl->attach('<br />* ');
                break;
            }
            $type = $attributes['param'];
            if ($type != '') {
                if ($type == '1') {
                    $type = 'decimal';
                } elseif ($type == 'a') {
                    $type = 'lower-alpha';
                } elseif ($type == 'i') {
                    $type = 'lower-roman';
                } elseif ($type == 'x') {
                    $type = 'none';
                } elseif (!in_array($type, array('circle', 'disc', 'square', 'armenian', 'decimal', 'decimal-leading-zero', 'georgian', 'lower-alpha', 'lower-greek', 'lower-latin', 'lower-roman', 'upper-alpha', 'upper-latin', 'upper-roman'))) {
                    $type = 'disc';
                }
                $tag = in_array($type, array('circle', 'disc', 'square')) ? 'ul' : 'ol';
                $temp_tpl->attach('<' . $tag . ' style="list-style-type: ' . $type . '">');
                foreach ($parts as $i => $part) {
                    if ($i == 0 && str_replace(array('&nbsp;', '<br />', ' '), array('', '', ''), trim($part)) == '') {
                        continue;
                    }
                    $temp_tpl->attach('<li>' . preg_replace('#\\<br /\\>(\\&nbsp;|\\s)*$#D', '', preg_replace('#^\\<br /\\>(\\&nbsp;|\\s)*#D', '', $part)) . '</li>');
                }
                $temp_tpl->attach('</' . $tag . '>');
            } else {
                $temp_tpl->attach('<ul>');
                foreach ($parts as $i => $part) {
                    if ($i == 0 && str_replace(array('&nbsp;', '<br />', ' '), array('', '', ''), trim($part)) == '') {
                        continue;
                    }
                    $temp_tpl->attach('<li>' . preg_replace('#\\<br /\\>(\\&nbsp;|\\s)*$#D', '', preg_replace('#^\\<br /\\>(\\&nbsp;|\\s)*#D', '', $part)) . '</li>');
                }
                $temp_tpl->attach('</ul>');
            }
            break;
        case 'snapback':
            require_lang('ocf');
            $post_id = intval($embed->evaluate());
            $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_POST_NUMBERED', integer_format($post_id)) : make_string_tempcode($attributes['param']);
            $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : '';
            $temp_tpl = do_template('COMCODE_SNAPBACK', array('URL' => $GLOBALS['FORUM_DRIVER']->post_url($post_id, $forum), 'TITLE' => $s_title));
            break;
        case 'post':
            require_lang('ocf');
            $post_id = intval($embed->evaluate());
            $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_POST_NUMBERED', integer_format($post_id)) : make_string_tempcode($attributes['param']);
            $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : '';
            $temp_tpl->attach(hyperlink($GLOBALS['FORUM_DRIVER']->post_url($post_id, $forum), $s_title));
            break;
        case 'topic':
            require_lang('ocf');
            $topic_id = intval($embed->evaluate());
            $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_TOPIC_NUMBERED', integer_format($topic_id)) : make_string_tempcode($attributes['param']);
            $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : '';
            $temp_tpl->attach(hyperlink($GLOBALS['FORUM_DRIVER']->topic_url($topic_id, $forum), $s_title));
            break;
        case 'staff_note':
            $temp_tpl = new ocp_tempcode();
            return $temp_tpl;
        case 'section':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'section' . strval(mt_rand(0, 100));
            $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0';
            $temp_tpl = do_template('COMCODE_SECTION', array('_GUID' => 'a902962ccdc80046c999d6fed907d105', 'PASS_ID' => 'x' . $pass_id, 'DEFAULT' => $default == '1', 'NAME' => $name, 'CONTENT' => $embed));
            break;
        case 'section_controller':
            if ($wml) {
                break;
            }
            $sections = explode(',', $embed->evaluate());
            $temp_tpl = do_template('COMCODE_SECTION_CONTROLLER', array('_GUID' => '133bf24892e9e3ec2a01146d6ec418fe', 'SECTIONS' => $sections, 'PASS_ID' => 'x' . $pass_id));
            break;
        case 'big_tab':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'big_tab' . strval(mt_rand(0, 100));
            $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0';
            $temp_tpl = do_template('COMCODE_BIG_TABS_TAB', array('PASS_ID' => 'x' . $pass_id, 'DEFAULT' => $default == '1', 'NAME' => $name, 'CONTENT' => $embed));
            break;
        case 'big_tab_controller':
            if ($wml) {
                break;
            }
            $tabs = explode(',', $embed->evaluate());
            if (!array_key_exists('switch_time', $attributes)) {
                $attributes['switch_time'] = '6000';
            }
            $temp_tpl = do_template('COMCODE_BIG_TABS_CONTROLLER', array('SWITCH_TIME' => $attributes['switch_time'], 'TABS' => $tabs, 'PASS_ID' => 'x' . $pass_id));
            break;
        case 'tab':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0';
            $temp_tpl = do_template('COMCODE_TAB_BODY', array('DEFAULT' => $default == '1', 'TITLE' => trim($attributes['param']), 'CONTENT' => $embed));
            break;
        case 'tabs':
            if ($wml) {
                break;
            }
            $heads = new ocp_tempcode();
            $tabs = explode(',', $attributes['param']);
            foreach ($tabs as $i => $tab) {
                $heads->attach(do_template('COMCODE_TAB_HEAD', array('TITLE' => trim($tab), 'FIRST' => $i == 0, 'LAST' => !array_key_exists($i + 1, $tabs))));
            }
            $temp_tpl = do_template('COMCODE_TAB_CONTROLLER', array('HEADS' => $heads, 'CONTENT' => $embed));
            break;
        case 'carousel':
            if ($attributes['param'] == '') {
                $attributes['param'] = '40';
            }
            $temp_tpl = do_template('COMCODE_CAROUSEL', array('CONTENT' => $embed, 'SCROLL_AMOUNT' => $attributes['param']));
            break;
        case 'menu':
            if ($wml) {
                break;
            }
            $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'mnu' . strval(mt_rand(0, 100));
            $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'tree';
            require_code('menus');
            require_code('menus_comcode');
            $temp_tpl = build_comcode_menu($embed->evaluate(), $name, $source_member, $type);
            break;
        case 'if_in_group':
            $groups = '';
            $_groups = explode(',', $attributes['param']);
            $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
            foreach ($_groups as $group) {
                $find = array_search($group, $all_groups);
                if ($find === false) {
                    if ($groups != '') {
                        $groups .= ',';
                    }
                    $groups .= $group;
                } else {
                    if ($groups != '') {
                        $groups .= ',';
                    }
                    $groups .= strval($find);
                }
            }
            $temp_tpl = do_template('COMCODE_IF_IN_GROUP', array('_GUID' => '761a7cc07f7b4b68508d68ce19b87d2c', 'TYPE' => array_key_exists('type', $attributes) ? $attributes['type'] : '', 'CONTENT' => $embed, 'GROUPS' => $groups));
            break;
        case 'acronym':
        case 'abbr':
            $temp_tpl = do_template('COMCODE_ABBR', array('_GUID' => 'acbc4f991dsf03f81b61919b74ac24c91', 'CONTENT' => $embed, 'TITLE' => $attributes['param']));
            break;
        case 'address':
            $temp_tpl = do_template('COMCODE_ADDRESS', array('_GUID' => 'acbcsdf9910703f81b61919b74ac24c91', 'CONTENT' => $embed));
            break;
        case 'dfn':
            $temp_tpl = do_template('COMCODE_DFN', array('_GUID' => 'acbc4f9910703f81b61sf19b74ac24c91', 'CONTENT' => $embed));
            break;
        case 'pulse':
            $min_color = array_key_exists('min', $attributes) ? $attributes['min'] : '0000FF';
            $max_color = array_key_exists('max', $attributes) ? $attributes['max'] : 'FF0044';
            if (substr($min_color, 0, 1) == '#') {
                $min_color = substr($min_color, 1);
            }
            if (substr($max_color, 0, 1) == '#') {
                $max_color = substr($max_color, 1);
            }
            $speed = $attributes['param'] == '' ? 100 : intval($attributes['param']);
            $temp_tpl = do_template('COMCODE_PULSE', array('_GUID' => 'adsd4f9910sfd03f81b61919b74ac24c91', 'RAND_ID' => uniqid('', true), 'CONTENT' => $embed, 'MIN_COLOR' => $min_color, 'MAX_COLOR' => $max_color, 'SPEED' => strval($speed)));
            break;
        case 'del':
            $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL;
            if (!is_null($cite)) {
                $temp_tpl = test_url($cite, 'del', $cite, $source_member);
            }
            $datetime = array_key_exists('datetime', $attributes) ? $attributes['datetime'] : NULL;
            $temp_tpl->attach(do_template('COMCODE_DEL', array('_GUID' => 'acsd4f9910sfd03f81b61919b74ac24c91', 'CONTENT' => $embed, 'CITE' => $cite, 'DATETIME' => $datetime)));
            break;
        case 'ins':
            $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL;
            if (!is_null($cite)) {
                $temp_tpl = test_url($cite, 'ins', $cite, $source_member);
                if (!$temp_tpl->is_empty()) {
                    break;
                }
            }
            $datetime = array_key_exists('datetime', $attributes) ? $attributes['datetime'] : NULL;
            $temp_tpl->attach(do_template('COMCODE_INS', array('_GUID' => 'asss4f9910703f81b61919bsfc24c91', 'CONTENT' => $embed, 'CITE' => $cite, 'DATETIME' => $datetime)));
            break;
        case 'cite':
            $temp_tpl = do_template('COMCODE_CITE', array('_GUID' => 'acbcsf910703f81b61919b74ac24c91', 'CONTENT' => $embed));
            break;
        case 'b':
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<b>' . $embed->evaluate() . '</b>');
                break;
            }
            $temp_tpl = do_template('COMCODE_BOLD', array('_GUID' => 'acbc4fds910703f81b619sf74ac24c91', 'CONTENT' => $embed));
            break;
        case 'align':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $align = array_key_exists('param', $attributes) ? $attributes['param'] : 'left';
            $temp_tpl = do_template('COMCODE_ALIGN', array('_GUID' => '950b4d9db12cac6bf536860bedd96a36', 'ALIGN' => $align, 'CONTENT' => $embed));
            break;
        case 'indent':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $indent = array_key_exists('param', $attributes) ? $attributes['param'] : '10';
            if (!is_numeric($indent)) {
                $indent = '10';
            }
            $temp_tpl = do_template('COMCODE_INDENT', array('_GUID' => 'd8e69fa17eebd5312e3ad5788e3a1343', 'INDENT' => $indent, 'CONTENT' => $embed));
            break;
        case 'surround':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if ($semiparse_mode && $embed->evaluate() == '') {
                $temp_tpl = make_string_tempcode('<kbd class="ocp_keep" title="no_parse">[surround="' . comcode_escape(array_key_exists('param', $attributes) ? $attributes['param'] : 'float_surrounder') . '"]' . $embed->evaluate() . '[/surround]</kbd>');
                break;
            }
            $class = array_key_exists('param', $attributes) && $attributes['param'] != '' ? $attributes['param'] : 'float_surrounder';
            $temp_tpl = do_template('COMCODE_SURROUND', array('_GUID' => 'e8e69fa17eebd5312e3ad5788e3a1343', 'CLASS' => $class, 'CONTENT' => $embed));
            break;
        case 'i':
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<i>' . $embed->evaluate() . '</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_ITALICS', array('_GUID' => '4321a1fe3825418e57a29410183c0c60', 'CONTENT' => $embed));
            break;
        case 'u':
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<u>' . $embed->evaluate() . '</u>');
                break;
            }
            $temp_tpl = do_template('COMCODE_UNDERLINE', array('_GUID' => '69cc8e73b17f9e6a35eb1af2bd1dc6ab', 'CONTENT' => $embed));
            break;
        case 's':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<strike>' . $embed->evaluate() . '</strike>');
                break;
            }
            $temp_tpl = do_template('COMCODE_STRIKE', array('_GUID' => 'ed242591cefd365497cc0c63abbb11a9', 'CONTENT' => $embed));
            break;
        case 'tooltip':
            $param = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            if ($wml) {
                $temp_tpl->attach($embed);
                $temp_tpl->attach('[ ');
                $temp_tpl->attach($param);
                $temp_tpl->attach(' ]');
                break;
            }
            $temp_tpl = do_template('COMCODE_TOOLTIP', array('_GUID' => 'c9f4793dc0c1a92cd7d08ae1b87c2308', 'URL' => array_key_exists('url', $attributes) ? $attributes['url'] : '', 'TOOLTIP' => $param, 'CONTENT' => $embed));
            break;
        case 'sup':
            if ($wml) {
                $temp_tpl->attach('^');
                $temp_tpl->attach($embed);
                break;
            }
            $temp_tpl = do_template('COMCODE_SUP', array('_GUID' => '74d2ecfe193dacb6d922bc288828196a', 'CONTENT' => $embed));
            break;
        case 'sub':
            if ($wml) {
                $temp_tpl->attach('{');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('}');
                break;
            }
            $temp_tpl = do_template('COMCODE_SUB', array('_GUID' => '515e310e00a6d7c30f7dca0a5956ebcf', 'CONTENT' => $embed));
            break;
        case 'title':
            if ($semiparse_mode && strpos($comcode, '[contents') !== false) {
                $temp_tpl = make_string_tempcode('[title' . reinsert_parameters($attributes) . ']' . $embed->evaluate() . '[/title]');
                break;
            }
            $level = $attributes['param'] != '' ? intval($attributes['param']) : 1;
            if ($level == 0) {
                $level = 1;
            }
            // Stop crazy Comcode causing stack errors with the toc
            $uniq_id = strval(count($STRUCTURE_LIST));
            $STRUCTURE_LIST[] = array($level, $embed, $uniq_id);
            if ($level == 1) {
                $template = 'SCREEN_TITLE';
            } elseif ($level == 2) {
                $template = 'COMCODE_SECTION_TITLE';
            } elseif ($level == 3) {
                $template = 'COMCODE_MINOR_TITLE';
            } elseif ($level == 4) {
                $template = 'COMCODE_VERY_MINOR_TITLE';
            } else {
                $template = 'COMCODE_VERY_MINOR_TITLE';
            }
            if ($level == 1) {
                if (is_null($COMCODE_PARSE_TITLE)) {
                    $COMCODE_PARSE_TITLE = $embed->evaluate();
                    if (is_object($COMCODE_PARSE_TITLE)) {
                        $COMCODE_PARSE_TITLE = $COMCODE_PARSE_TITLE->evaluate();
                    }
                }
            }
            $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 2;
            if (array_key_exists('number', $attributes) && $level >= $base) {
                $list_types = $attributes['number'] == '' ? array() : explode(',', $attributes['number']);
                $list_types = array_merge($list_types, array('decimal', 'lower-alpha', 'lower-roman', 'upper-alpha', 'upper-roman', 'disc'));
                $numerals = array('i', 'ii', 'iii', 'iv', 'v', 'vi', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx');
                $symbol_lookup = array('decimal' => range(1, 100), 'lower-alpha' => range('a', 'z'), 'lower-roman' => $numerals, 'upper-alpha' => range('A', 'Z'), 'upper-roman' => str_replace('i', 'I', str_replace('v', 'V', str_replace('x', 'X', $numerals))));
                $level_text = '';
                $list_pos = count($STRUCTURE_LIST) - 2;
                for ($j = $level; $j >= $base; $j--) {
                    $num_before = 0;
                    for ($i = $list_pos; $i >= 0; $i--) {
                        $list_pos--;
                        if ($STRUCTURE_LIST[$i][0] == $j - 1) {
                            break;
                        }
                        if ($STRUCTURE_LIST[$i][0] == $j) {
                            $num_before++;
                        }
                    }
                    $level_number = @strval($symbol_lookup[$list_types[$j - $base]][$num_before]);
                    $level_text = $level_number . ($level_text != '' ? '.' : '') . $level_text;
                }
                $old_embed = $embed;
                $embed = make_string_tempcode($level_text . ' &ndash; ');
                $embed->attach($old_embed);
            }
            if ($wml) {
                if ($level == 1) {
                    $temp_tpl->attach('<br /><p><big><u><b>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</b></u></big></p><br />');
                } elseif ($level == 2) {
                    $temp_tpl->attach('<br /><p><big><u>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</u></big></p><br />');
                } elseif ($level == 3) {
                    $temp_tpl->attach('<br /><p><big>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</big></p><br />');
                } elseif ($level == 4) {
                    $temp_tpl->attach('<br /><p>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</p><br />');
                }
                break;
            }
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<h' . strval($level) . ($level == 1 ? ' class="main_page_title"' : '') . '><span class="inner">' . $embed->evaluate() . '</span></h' . strval($level) . '>');
                break;
            }
            $tpl_map = array('ID' => substr($pass_id, 0, 5) == 'panel' ? NULL : $uniq_id, 'TITLE' => $embed, 'HELP_URL' => '', 'HELP_TERM' => '');
            if (array_key_exists('sub', $attributes)) {
                $tpl_map['SUB'] = protect_from_escaping(comcode_to_tempcode($attributes['sub'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member));
            }
            $temp_tpl = do_template($template, $tpl_map);
            break;
        case 'attachment':
        case 'attachment2':
            // legacy
        // legacy
        case 'attachment_safe':
            if ($wml) {
                break;
            }
            require_code('attachments');
            if (is_null($on_behalf_of_member)) {
                $on_behalf_of_member = $source_member;
            }
            $id = $embed->evaluate();
            global $COMCODE_ATTACHMENTS;
            if (!is_numeric($id) && !$as_admin && !has_specific_permission($source_member, 'exceed_filesize_limit')) {
                // We work all this out before we do any downloads, to make sure orphaned files aren't dumped on the file system (possible hack method)
                if (get_forum_type() == 'ocf') {
                    require_lang('ocf');
                    require_code('ocf_groups');
                    $daily_quota = ocf_get_member_best_group_property($source_member, 'max_daily_upload_mb');
                } else {
                    $daily_quota = 5;
                    // 5 is a hard coded default for non-OCF forums
                }
                if (!is_null($daily_quota)) {
                    $_size_uploaded_today = $connection->query('SELECT SUM(a_file_size) AS the_answer FROM ' . $connection->get_table_prefix() . 'attachments WHERE a_member_id=' . strval((int) $source_member) . ' AND a_add_time>' . strval(time() - 60 * 60 * 24));
                    if (is_null($_size_uploaded_today[0]['the_answer'])) {
                        $_size_uploaded_today[0]['the_answer'] = 0;
                    }
                    $size_uploaded_today = ceil((double) $_size_uploaded_today[0]['the_answer'] / 1024.0 / 1024.0);
                    $attach_size = 0;
                    require_code('uploads');
                    is_swf_upload(true);
                    foreach ($_FILES as $_file) {
                        $attach_size += floatval($_file['size']) / 1024.0 / 1024.0;
                    }
                    if ($size_uploaded_today + $attach_size > floatval($daily_quota)) {
                        $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('OVER_DAILY_QUOTA', integer_format($daily_quota), float_format($size_uploaded_today))));
                        break;
                    }
                }
            }
            $thumb_url = array_key_exists('thumb_url', $attributes) ? $attributes['thumb_url'] : '';
            // Embedded attachments
            if (!is_numeric($id) && substr($id, 0, 4) != 'new_' && substr($id, 0, 4) != 'url_') {
                $file = base64_decode(str_replace(chr(10), '', $id));
                if ($file === false) {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:CORRUPT_ATTACHMENT')));
                    break;
                }
                $md5 = md5(substr($file, 0, 30));
                $original_filename = array_key_exists('filename', $attributes) ? $attributes['filename'] : $md5 . '.dat';
                if (get_file_extension($original_filename) != 'dat') {
                    require_code('files2');
                    check_extension($original_filename, true);
                    $new_filename = $md5 . '.' . get_file_extension($original_filename) . '.dat';
                } else {
                    $new_filename = $md5 . '.' . get_file_extension($original_filename);
                }
                $path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
                $myfile = @fopen($path, 'wb');
                if ($myfile === false) {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => intelligent_write_error_inline($path)));
                    break;
                }
                if (fwrite($myfile, $file) < strlen($file)) {
                    warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                }
                fclose($myfile);
                fix_permissions($path);
                sync_file($path);
                $_size = strlen($file);
                $url = 'uploads/attachments/' . $new_filename;
                if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                    $url = get_custom_base_url() . '/' . $url;
                }
                // Thumbnail
                if ($thumb_url == '') {
                    require_code('images');
                    if (is_image($original_filename)) {
                        $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
                        if ($gd) {
                            require_code('images');
                            if (!is_saveable_image($url)) {
                                $ext = '.png';
                            } else {
                                $ext = '.' . get_file_extension($original_filename);
                            }
                            $thumb_url = 'uploads/attachments_thumbs/' . $md5 . $ext;
                            convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . $thumb_url, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
                            if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                                $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                            }
                        } else {
                            $thumb_url = $url;
                        }
                    }
                }
                if (addon_installed('galleries')) {
                    require_code('images');
                    if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                        require_code('transcoding');
                        $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                    }
                }
                $attachment = array('a_member_id' => $on_behalf_of_member, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => 0, 'a_last_downloaded_time' => NULL, 'a_add_time' => time());
                $attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : '';
                $attach_id = $connection->query_insert('attachments', $attachment, true);
                $attachment['id'] = $attach_id;
                // Create and document attachment
                if (!array_key_exists('type', $attributes)) {
                    $attributes['type'] = 'auto';
                }
                $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'type' => 'new', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode);
                // Marker will allow us to search back and replace this with the added id
            } elseif (!is_numeric($id)) {
                require_code('uploads');
                if (substr($id, 0, 4) == 'new_') {
                    $_id = substr($id, 4);
                    if (!is_numeric($_id)) {
                        $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT')));
                        break;
                    }
                    $attributes['type'] = post_param('attachmenttype' . $_id, array_key_exists('type', $attributes) ? $attributes['type'] : 'auto');
                    if (substr($attributes['type'], -8) == '_extract') {
                        $attributes['type'] = substr($attributes['type'], 0, strlen($attributes['type']) - 8);
                    }
                    $urls = get_url('', 'file' . $_id, 'uploads/attachments', 2, OCP_UPLOAD_ANYTHING, (!array_key_exists('thumb', $attributes) || $attributes['thumb'] != '0') && $thumb_url == '', '', '', true, true, true);
                    if ($urls[0] == '') {
                        return new ocp_tempcode();
                    }
                    //warn_exit(do_lang_tempcode('ERROR_UPLOADING'));  Can't do this, because this might not be post-calculated if something went wrong once
                    is_swf_upload(true);
                    $_size = $_FILES['file' . $_id]['size'];
                    $original_filename = $_FILES['file' . $_id]['name'];
                    if (get_magic_quotes_gpc()) {
                        $original_filename = stripslashes($original_filename);
                    }
                } elseif (substr($id, 0, 4) == 'url_') {
                    if (!has_specific_permission($source_member, 'draw_to_server') && !$as_admin) {
                        break;
                    }
                    $_id = '!';
                    $attributes['type'] = post_param('attachmenttype' . $_id, array_key_exists('type', $attributes) ? $attributes['type'] : 'auto');
                    $url = remove_url_mistakes(substr($id, 4));
                    $_POST['_specify_url'] = $url;
                    // Little hack, as we need to read it from a POST
                    if (get_magic_quotes_gpc()) {
                        $_POST['_specify_url'] = addslashes($_POST['_specify_url']);
                    }
                    $urls = get_url('_specify_url', '', 'uploads/filedump', 1, OCP_UPLOAD_ANYTHING, (!array_key_exists('thumb', $attributes) || $attributes['thumb'] != '0') && $thumb_url == '', '', '', true, true);
                    if ($urls[0] == '') {
                        return new ocp_tempcode();
                    }
                    $original_filename = rawurldecode(substr($url, strrpos($url, '/') + 1));
                    if (url_is_local($urls[0])) {
                        $_size = @filesize(get_custom_file_base() . '/' . rawurldecode($urls[0]));
                        if ($_size === false) {
                            $_size = filesize(get_file_base() . '/' . rawurldecode($urls[0]));
                        }
                    } else {
                        $_size = 0;
                    }
                } else {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT')));
                    break;
                }
                if ($urls[0] == '') {
                    require_code('images');
                    require_code('files2');
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('ATTACHMENT_WOULD_NOT_UPLOAD', float_format(get_max_file_size() / 1024 / 1024), float_format(get_max_image_size() / 1024 / 1024))));
                    break;
                }
                $url = $urls[0];
                if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                    $url = get_custom_base_url() . '/' . $url;
                }
                if ($thumb_url == '') {
                    $thumb_url = array_key_exists(1, $urls) ? $urls[1] : '';
                }
                if ($thumb_url != '' && $connection != $GLOBALS['SITE_DB']) {
                    $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                }
                $num_downloads = 0;
                $last_downloaded_time = NULL;
                $add_time = time();
                $member_id = $on_behalf_of_member;
                if (addon_installed('galleries')) {
                    require_code('images');
                    if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                        require_code('transcoding');
                        $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                    }
                }
                $attachment = array('a_member_id' => $member_id, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => $num_downloads, 'a_last_downloaded_time' => $last_downloaded_time, 'a_add_time' => $add_time);
                $attachment['a_description'] = post_param('caption' . $_id, array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : '');
                $attach_id = $connection->query_insert('attachments', $attachment, true);
                $attachment['id'] = $attach_id;
                if ($tag == 'attachment2' || $tag == 'attachment_safe' || substr($id, 0, 4) == 'url_') {
                    $connection->query_delete('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => '', 'a_id' => $attachment['id']), '', 1);
                    $connection->query_insert('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => '', 'a_id' => $attachment['id']));
                }
                // Create and document attachment
                $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'time' => time(), 'type' => substr($id, 0, 4) == 'new_' ? 'new' : 'url', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode);
                // Marker will allow us to search back and replace this with the added id
                // Existing attachments
            } else {
                $__id = intval($id);
                // Check we have permission to re-use this
                $owner = $connection->query_value_null_ok('attachments', 'a_member_id', array('id' => $__id));
                if (is_null($owner)) {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'attachment', escape_html(strval($__id)))));
                    if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        require_code('failure');
                        relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'attachment', strval($__id)), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                    }
                    break;
                }
                $_attachment = $connection->query_select('attachments', array('*'), array('id' => $__id), '', 1);
                $attachment = $_attachment[0];
                $already_referenced = array_key_exists($__id, $GLOBALS['ATTACHMENTS_ALREADY_REFERENCED']);
                if ($already_referenced || $as_admin || $source_member === $owner || (has_specific_permission($source_member, 'reuse_others_attachments') || $owner == $source_member) && has_attachment_access($source_member, $__id)) {
                    if (!array_key_exists('type', $attributes)) {
                        $attributes['type'] = 'auto';
                    }
                    $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'time' => $attachment['a_add_time'], 'type' => 'existing', 'id' => $__id, 'attachmenttype' => $attributes['type'], 'marker' => $marker, 'comcode' => $comcode);
                } else {
                    require_lang('permissions');
                    $username = $GLOBALS['FORUM_DRIVER']->get_username($source_member);
                    if (is_null($username)) {
                        $username = do_lang('DELETED');
                    }
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('permissions:ACCESS_DENIED__REUSE_ATTACHMENT', $username)));
                    break;
                    //access_denied('REUSE_ATTACHMENT');
                }
                if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                    if (url_is_local($attachment['a_url'])) {
                        $attachment['a_url'] = get_custom_base_url() . '/' . $attachment['a_url'];
                    }
                    if (url_is_local($attachment['a_url'])) {
                        $attachment['a_thumb_url'] = get_custom_base_url() . '/' . $attachment['a_thumb_url'];
                    }
                }
                $attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : $attachment['a_description'];
            }
            // Now, render it
            // ==============
            $temp_tpl = render_attachment($tag, $attributes, $attachment, $pass_id, $source_member, $as_admin, $connection, $highlight_bits, $on_behalf_of_member, $semiparse_mode);
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => '802fe29019be80993296de7cc8b5cc5e', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'include':
            $codename = $embed->evaluate();
            $zone = $attributes['param'];
            if ($zone == '_SEARCH') {
                $zone = get_comcode_zone($codename);
            }
            if ($zone == '_SELF') {
                $zone = get_zone_name();
            }
            $temp_comcode_parse_title = $COMCODE_PARSE_TITLE;
            $temp = request_page($codename, false, $zone, NULL, true);
            $COMCODE_PARSE_TITLE = $temp_comcode_parse_title;
            if ($temp->is_empty()) {
                $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'include', hyperlink(build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'page_link' => $zone . ':' . $codename), get_module_zone('cms_comcode_pages')), $zone . ':' . $codename, false, true))));
                if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                    require_code('failure');
                    relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'include', $zone . ':' . $codename), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                }
            } else {
                $temp_tpl = symbol_tempcode('LOAD_PAGE', array($codename, $zone));
            }
            break;
        case 'random':
            unset($attributes['param']);
            if ($wml) {
                $top_attribute = array_pop($attributes);
                $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                break;
            }
            $max = $embed->evaluate() == '' ? intval($embed->evaluate()) : 0;
            foreach ($attributes as $num => $val) {
                $_temp = is_object($val) ? $val : comcode_to_tempcode($val, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                $attributes[$num] = $_temp->evaluate();
                if (intval($num) > $max) {
                    $max = intval($num);
                }
            }
            $_parts = new ocp_tempcode();
            krsort($attributes);
            foreach ($attributes as $num => $val) {
                $_parts->attach(do_template('COMCODE_RANDOM_PART', array('_GUID' => '5fa49a916304f9caa0ddedeb01531142', 'NUM' => strval($num), 'VAL' => $val)));
            }
            $temp_tpl = do_template('COMCODE_RANDOM', array('_GUID' => '9b77aaf593b12c763fb0c367fab415b6', 'UNIQID' => uniqid('', true), 'FULL' => $embed, 'MAX' => strval($max), 'PARTS' => $_parts));
            break;
        case 'jumping':
            unset($attributes['param']);
            if ($wml) {
                $top_attribute = array_pop($attributes);
                $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                break;
            }
            $_parts = new ocp_tempcode();
            foreach ($attributes as $val) {
                $_temp = is_object($val) ? $val : comcode_to_tempcode($val, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                $_parts->attach(do_template('COMCODE_JUMPING_PART', array('_GUID' => 'd163bd11920f39f0cb8ff2f6ba48bc80', 'PART' => $_temp->evaluate())));
            }
            $embed = $embed->evaluate();
            $temp_tpl = do_template('COMCODE_JUMPING', array('_GUID' => '85e9f83ed134868436a7db7692f56047', 'UNIQID' => uniqid('', true), 'FULL' => implode(', ', $attributes), 'TIME' => strval((int) $embed), 'PARTS' => $_parts));
            break;
        case 'shocker':
            if ($wml) {
                $top_attribute = array_pop($attributes);
                $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                break;
            }
            $_parts = new ocp_tempcode();
            foreach ($attributes as $key => $val) {
                if (substr($key, 0, 5) == 'left_') {
                    $left = $val;
                    $right = array_key_exists('right_' . substr($key, 5), $attributes) ? $attributes['right_' . substr($key, 5)] : '';
                    $left = is_object($left) ? $left : comcode_to_tempcode($left, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $right = is_object($right) ? $right : comcode_to_tempcode($right, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $_parts->attach(do_template('COMCODE_SHOCKER_PART', array('LEFT' => $left, 'RIGHT' => $right)));
                }
            }
            $min_color = array_key_exists('min', $attributes) ? $attributes['min'] : '0000FF';
            $max_color = array_key_exists('max', $attributes) ? $attributes['max'] : 'FF0044';
            if (substr($min_color, 0, 1) == '#') {
                $min_color = substr($min_color, 1);
            }
            if (substr($max_color, 0, 1) == '#') {
                $max_color = substr($max_color, 1);
            }
            $embed = $embed->evaluate();
            $temp_tpl = do_template('COMCODE_SHOCKER', array('UNIQID' => uniqid('', true), 'MIN_COLOR' => $min_color, 'MAX_COLOR' => $max_color, 'FULL' => implode(', ', $attributes), 'TIME' => strval(intval($embed)), 'PARTS' => $_parts));
            break;
        case 'ticker':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $width = $attributes['param'];
            if (!is_numeric($width)) {
                $width = '300';
            }
            $fspeed = array_key_exists('speed', $attributes) ? float_to_raw_string(floatval($attributes['speed'])) : '1';
            $temp_tpl = do_template('COMCODE_TICKER', array('_GUID' => 'e48893cda61995261577f0556443c537', 'UNIQID' => uniqid('', true), 'SPEED' => $fspeed, 'WIDTH' => $width, 'TEXT' => $embed));
            break;
        case 'highlight':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_HIGHLIGHT', array('_GUID' => '695d041b6605f06ec2aeee1e82f87185', 'CONTENT' => $embed));
            break;
        case 'size':
            $size = array_key_exists('param', $attributes) ? $attributes['param'] : '1';
            if ($wml) {
                if (floatval($size) >= 1.5) {
                    $temp_tpl->attach('<big>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</big>');
                } elseif (floatval($size) < 0.8) {
                    $temp_tpl->attach('<small>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</small>');
                } else {
                    $temp_tpl->attach($embed);
                }
                break;
            }
            if (is_numeric($size)) {
                $size = 'font-size: ' . $size . 'em;';
            } elseif (substr($size, 0, 1) == '+') {
                $size = 'font-size: ' . substr($size, 1) . 'em';
            } elseif (substr($size, -1) == '%') {
                $size = 'font-size: ' . float_to_raw_string(floatval(substr($size, 0, strlen($size) - 1)) / 100.0) . 'em';
            } elseif (substr($size, -2) == 'of') {
                $new_size = '1em';
                switch ($size) {
                    case '1of':
                        $new_size = '8pt';
                        break;
                    case '2of':
                        $new_size = '10pt';
                        break;
                    case '3of':
                        $new_size = '12pt';
                        break;
                    case '4of':
                        $new_size = '14pt';
                        break;
                    case '5of':
                        $new_size = '18pt';
                        break;
                    case '6of':
                        $new_size = '24pt';
                        break;
                    case '7of':
                        $new_size = '36pt';
                        break;
                }
                $size = 'font-size: ' . $new_size;
            } else {
                $size = 'font-size: ' . $size;
            }
            $size_len = strlen($size);
            filter_html($as_admin, $source_member, 0, $size_len, $size, false, false);
            $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'fb23fdcb45aabdfeca9f37ed8098948e', 'CONTENT' => $embed, 'SIZE' => $size, 'COLOR' => '', 'FACE' => ''));
            break;
        case 'color':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $color = array_key_exists('param', $attributes) ? 'color: ' . $attributes['param'] . ';' : '';
            $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'bd146414c9239ba2076f4b683df437d7', 'CONTENT' => $embed, 'SIZE' => '', 'COLOR' => $color, 'FACE' => ''));
            $color_len = strlen($color);
            filter_html($as_admin, $source_member, 0, $color_len, $color, false, false);
            break;
        case 'tt':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_TELETYPE', array('CONTENT' => $embed));
            break;
        case 'samp':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_SAMP', array('CONTENT' => $embed));
            break;
        case 'q':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_Q', array('CONTENT' => $embed));
            break;
        case 'var':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_VAR', array('CONTENT' => $embed));
            break;
        case 'font':
            $face = $attributes['param'];
            if ($face == '' && array_key_exists('face', $attributes)) {
                $face = $attributes['face'];
            }
            $color = array_key_exists('color', $attributes) ? $attributes['color'] : '';
            $size = array_key_exists('size', $attributes) ? $attributes['size'] : '';
            if ($face == '/') {
                $face = '';
            }
            if ($color == '/') {
                $color = '';
            }
            if ($size == '/') {
                $size = '';
            }
            if ($wml) {
                $before = '';
                $after = '';
                if ($size != '') {
                    if (floatval($size) >= 1.5) {
                        $before = '<big>';
                        $after = '</big>';
                    } elseif (floatval($size) < 0.8) {
                        $before = '<small>';
                        $after = '</small>';
                    }
                }
                $temp_tpl->attach($before);
                $temp_tpl->attach($embed);
                $temp_tpl->attach($after);
                break;
            }
            if ($color != '') {
                $color = 'color: ' . $color . ';';
            }
            if ($size != '') {
                if (is_numeric($size)) {
                    $size = 'font-size: ' . $size . 'em;';
                } elseif (substr($size, 0, 1) == '+') {
                    $size = 'font-size: ' . substr($size, 1) . 'em';
                } elseif (substr($size, -1) == '%') {
                    $size = 'font-size: ' . float_to_raw_string(floatval(substr($size, 0, strlen($size) - 1)) / 100.0) . 'em';
                } elseif (substr($size, -2) == 'of') {
                    $new_size = '1em';
                    switch ($size) {
                        case '1of':
                            $new_size = '8pt';
                            break;
                        case '2of':
                            $new_size = '10pt';
                            break;
                        case '3of':
                            $new_size = '12pt';
                            break;
                        case '4of':
                            $new_size = '14pt';
                            break;
                        case '5of':
                            $new_size = '18pt';
                            break;
                        case '6of':
                            $new_size = '24pt';
                            break;
                        case '7of':
                            $new_size = '36pt';
                            break;
                    }
                    $size = 'font-size: ' . $new_size;
                } else {
                    $size = 'font-size: ' . $size;
                }
            }
            if ($face != '') {
                $face = 'font-family: ' . str_replace('\'', '', $face) . ';';
            }
            $size_len = strlen($size);
            filter_html($as_admin, $source_member, 0, $size_len, $size, false, false);
            $color_len = strlen($color);
            filter_html($as_admin, $source_member, 0, $color_len, $color, false, false);
            $face_len = strlen($face);
            filter_html($as_admin, $source_member, 0, $face_len, $face, false, false);
            $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'f5fcafe737b8fdf466a6a51773e09c9b', 'CONTENT' => $embed, 'SIZE' => $size, 'COLOR' => $color, 'FACE' => $face));
            break;
        case 'box':
            if ($wml) {
                $temp_tpl->attach('<br /><p>');
                if ($attributes['param'] != '') {
                    $temp_tpl->attach('<big>');
                    $temp_tpl->attach($attributes['param']);
                    $temp_tpl->attach('</big><br /><br />');
                }
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</p></br />');
                break;
            }
            // Legacy parameter. There used to be 'place' and 'nowrap' and 'class', but these are now gone.
            $breadth = array_key_exists('breadth', $attributes) ? $attributes['breadth'] : '100%';
            if ($breadth == 'WIDE') {
                $breadth = '100%';
            }
            if ($breadth == 'WIDE_HIGH') {
                $breadth = '100%';
            }
            if ($breadth == 'THIN') {
                $breadth = 'auto';
            }
            // The new versions
            $dimensions = array_key_exists('dimensions', $attributes) ? comcode_to_tempcode($attributes['dimensions'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member) : make_string_tempcode($breadth);
            $type = array_key_exists('type', $attributes) ? $attributes['type'] : '';
            $options = array_key_exists('options', $attributes) ? $attributes['options'] : '';
            $meta = $comcode_dangerous && array_key_exists('meta', $attributes) ? $attributes['meta'] : '';
            //Insecure, unneeded here
            $links = $comcode_dangerous && array_key_exists('links', $attributes) ? $attributes['links'] : '';
            //Insecure, unneeded here
            $converted = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            $temp_tpl = directive_tempcode('BOX', $embed, array($converted, $dimensions, make_string_tempcode($type), make_string_tempcode($options), make_string_tempcode($meta), make_string_tempcode($links)));
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => '54e8fc9ec1e16cfc5c8824e22f1e8745', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'concept':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if (!array_key_exists('param', $attributes) || $attributes['param'] == '') {
                $key = $embed->evaluate();
                $temp_tpl = symbol_tempcode('DISPLAY_CONCEPT', array($key));
            } else {
                $temp_tpl = do_template('COMCODE_CONCEPT_INLINE', array('_GUID' => '381a59de4d6f8967446c12bf4641a9ce', 'TEXT' => $embed, 'FULL' => $attributes['param']));
            }
            break;
        case 'concepts':
            if ($wml) {
                break;
            }
            $title = $embed->evaluate();
            $concepts = new ocp_tempcode();
            foreach ($attributes as $_key => $_value) {
                if (substr($_key, -4) == '_key') {
                    $key = $_value;
                    $cid = substr($_key, 0, strlen($_key) - 4);
                    $to_parse = array_key_exists($cid . '_value', $attributes) ? $attributes[$cid . '_value'] : new ocp_tempcode();
                    $value = is_object($to_parse) ? $to_parse : comcode_to_tempcode($to_parse, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $concepts->attach(do_template('COMCODE_CONCEPTS_CONCEPT', array('_GUID' => '4baf6dabc32146c594c7fd922791b6b2', 'A' => 'concept___' . preg_replace('#[^\\w]#', '_', $key), 'KEY' => $key, 'VALUE' => $value)));
                }
            }
            $temp_tpl = do_template('COMCODE_CONCEPTS', array('_GUID' => '4c7a1d70753dc1d209b9951aa10f361a', 'TITLE' => $title, 'CONCEPTS' => $concepts));
            break;
        case 'exp_ref':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            if (strpos($_embed, '.') !== false) {
                break;
            }
            $stub = get_file_base() . '/data_custom/images/' . get_zone_name() . '/';
            $stub2 = get_base_url() . '/data_custom/images/' . get_zone_name() . '/';
            if (!file_exists($stub)) {
                $stub = get_file_base() . '/data/images/' . get_zone_name() . '/';
                $stub2 = get_base_url() . '/data/images/' . get_zone_name() . '/';
            }
            if (!file_exists($stub)) {
                $stub = get_file_base() . '/data_custom/images/';
                $stub2 = get_base_url() . '/data_custom/images/';
            }
            if (!file_exists($stub)) {
                $stub = get_file_base() . '/data/images/';
                $stub2 = get_base_url() . '/data/images/';
            }
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            if (file_exists($stub . $_embed . '.png')) {
                $url = $stub2 . $_embed . '.png';
            } elseif (file_exists($stub . $_embed . '.gif')) {
                $url = $stub2 . $_embed . '.gif';
            } elseif (file_exists($stub . $_embed . '.jpg')) {
                $url = $stub2 . $_embed . '.jpg';
            } elseif (file_exists($stub . $_embed . '.jpeg')) {
                $url = $stub2 . $_embed . '.jpeg';
            } else {
                $stub = get_file_base() . '/data/images/docs/';
                $stub2 = get_base_url() . '/data/images/docs/';
                if (substr($_embed, 0, 1) == '/') {
                    $_embed = substr($_embed, 1);
                }
                if (file_exists($stub . $_embed . '.png')) {
                    $url = $stub2 . $_embed . '.png';
                } elseif (file_exists($stub . $_embed . '.gif')) {
                    $url = $stub2 . $_embed . '.gif';
                } elseif (file_exists($stub . $_embed . '.jpg')) {
                    $url = $stub2 . $_embed . '.jpg';
                } elseif (file_exists($stub . $_embed . '.jpeg')) {
                    $url = $stub2 . $_embed . '.jpeg';
                } else {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'exp_ref', escape_html($_embed))));
                    if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) {
                        $GLOBALS['COMCODE_BROKEN_URLS'][] = array($_embed, NULL);
                    } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        require_code('failure');
                        relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'exp_ref', $_embed), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                    }
                    break;
                }
            }
            $text = make_string_tempcode($attributes['param']);
            if ($text->is_empty()) {
                $text = do_lang_tempcode('EXAMPLE');
            }
            $temp_tpl = do_template('COMCODE_EXP_REF', array('_GUID' => '89e7f528e72096e3458d6acb70734d0b', 'TEXT' => $text, 'URL' => $url));
            break;
        case 'exp_thumb':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            if (strpos($_embed, '.') !== false) {
                break;
            }
            $stub = get_file_base() . '/data/images/' . get_zone_name() . '/';
            $stub2 = get_base_url() . '/data/images/' . get_zone_name() . '/';
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            if (file_exists($stub . $_embed . '.png')) {
                $url_full = $stub2 . $_embed . '.png';
            } elseif (file_exists($stub . $_embed . '.gif')) {
                $url_full = $stub2 . $_embed . '.gif';
            } elseif (file_exists($stub . $_embed . '.jpg')) {
                $url_full = $stub2 . $_embed . '.jpg';
            } elseif (file_exists($stub . $_embed . '.jpeg')) {
                $url_full = $stub2 . $_embed . '.jpeg';
            } else {
                $stub = get_file_base() . '/data/images/docs/';
                $stub2 = get_base_url() . '/data/images/docs/';
                if (substr($_embed, 0, 1) == '/') {
                    $_embed = substr($_embed, 1);
                }
                if (file_exists($stub . $_embed . '.png')) {
                    $url_full = $stub2 . $_embed . '.png';
                } elseif (file_exists($stub . $_embed . '.gif')) {
                    $url_full = $stub2 . $_embed . '.gif';
                } elseif (file_exists($stub . $_embed . '.jpg')) {
                    $url_full = $stub2 . $_embed . '.jpg';
                } elseif (file_exists($stub . $_embed . '.jpeg')) {
                    $url_full = $stub2 . $_embed . '.jpeg';
                } else {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'exp_thumb', escape_html($_embed))));
                    if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) {
                        $GLOBALS['COMCODE_BROKEN_URLS'][] = $_embed;
                    } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        require_code('failure');
                        relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'exp_thumb', $_embed), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                    }
                    break;
                }
            }
            $float = array_key_exists('float', $attributes) ? $attributes['float'] : 'right';
            $text = $attributes['param'];
            if (get_option('is_on_gd') == '0' || !function_exists('imagetypes')) {
                $url_thumb = $url_full;
            } else {
                $new_name = $_embed . '_thumb.png';
                $file_thumb = $stub . $new_name;
                if (file_exists($file_thumb)) {
                    $url_thumb = $stub2 . rawurlencode($new_name);
                } else {
                    $new_name = $_embed . '.png';
                    $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
                    if (!file_exists($file_thumb)) {
                        require_code('images');
                        convert_image($url_full, $file_thumb, -1, -1, 150, false);
                    }
                    $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
                }
            }
            if (get_param_integer('wide_print', 0) == 1) {
                $temp_tpl = do_template('COMCODE_EXP_THUMB_PRINT', array('_GUID' => 'de7f8a7fa29c2335f381a0beb3da9406', 'FLOAT' => $float, 'TEXT' => $text, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full));
            } else {
                $temp_tpl = do_template('COMCODE_EXP_THUMB', array('_GUID' => 'ce7f8a7fa29c2335f381a0beb3da9406', 'FLOAT' => $float, 'TEXT' => $text, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full));
            }
            break;
        case 'thumb':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            $_embed = remove_url_mistakes($_embed);
            $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            if (url_is_local($_embed)) {
                if (file_exists(get_file_base() . '/' . $_embed) && !file_exists(get_custom_file_base() . '/' . $_embed)) {
                    $url_full = get_base_url() . '/' . $_embed;
                } else {
                    $url_full = get_custom_base_url() . '/' . $_embed;
                }
            } else {
                $url_full = $_embed;
            }
            $align = array_key_exists('align', $attributes) ? $attributes['align'] : 'bottom';
            if (get_option('is_on_gd') == '0' || !function_exists('imagetypes') || !has_specific_permission($source_member, 'draw_to_server') && !$as_admin) {
                $url_thumb = $url_full;
            } else {
                if ($attributes['param'] != '') {
                    $url_thumb = url_is_local($attributes['param']) ? get_custom_base_url() . '/' . $attributes['param'] : $attributes['param'];
                }
                if ($attributes['param'] == '' || url_is_local($attributes['param']) && !file_exists(get_custom_file_base() . '/' . rawurldecode($attributes['param']))) {
                    $new_name = url_to_filename($url_full);
                    require_code('images');
                    if (!is_saveable_image($new_name)) {
                        $new_name .= '.png';
                    }
                    if (is_null($new_name)) {
                        $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('URL_THUMB_TOO_LONG')));
                        break;
                    }
                    $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
                    if (!file_exists($file_thumb) && strpos($file_thumb, '{$') === false) {
                        convert_image($url_full, $file_thumb, -1, -1, intval(get_option('thumb_width')), false);
                    }
                    $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
                }
            }
            $caption = array_key_exists('caption', $attributes) ? $attributes['caption'] : '';
            $temp_tpl = do_template('COMCODE_THUMB', array('_GUID' => '1b0d25f72ef5f816091269e29c586d60', 'CAPTION' => $caption, 'RAND' => strval(mt_rand(0, 32000)), 'ALIGN' => $align, 'PASS_ID' => intval($pass_id) < 0 ? strval(mt_rand(0, 10000)) : $pass_id, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full));
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => 'cbc56770714a44f56676f43da282cc7a', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'img':
            if ($wml) {
                break;
            }
            if ($semiparse_mode && array_key_exists('rollover', $attributes)) {
                $temp_tpl = make_string_tempcode('[img' . reinsert_parameters($attributes) . ']' . $embed->evaluate() . '[/img]');
                break;
            }
            $_embed = $embed->evaluate();
            $given_url = $_embed;
            $_embed = remove_url_mistakes($_embed);
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
            if (url_is_local($_embed)) {
                if (file_exists(get_file_base() . '/' . $_embed) && !file_exists(get_custom_file_base() . '/' . $_embed)) {
                    $url_full = get_base_url() . '/' . $_embed;
                } else {
                    $url_full = get_custom_base_url() . '/' . $_embed;
                }
            } else {
                $url_full = $_embed;
            }
            $temp_tpl = test_url($url_full, 'img', @html_entity_decode($given_url, ENT_QUOTES, get_charset()), $source_member);
            $align = array_key_exists('align', $attributes) ? $attributes['align'] : '';
            $caption = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            if (array_key_exists('title', $attributes)) {
                $tooltip = is_object($attributes['title']) ? $attributes['title'] : comcode_to_tempcode($attributes['title'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            } else {
                $tooltip = $caption;
            }
            $rollover = array_key_exists('rollover', $attributes) ? $attributes['rollover'] : NULL;
            if (!is_null($rollover) && url_is_local($rollover)) {
                if (file_exists(get_file_base() . '/' . $rollover) && !file_exists(get_custom_file_base() . '/' . $rollover)) {
                    $rollover = get_base_url() . '/' . $rollover;
                } else {
                    $rollover = get_custom_base_url() . '/' . $rollover;
                }
            }
            $refresh_time = array_key_exists('refresh_time', $attributes) ? strval(intval($attributes['refresh_time'])) : '0';
            $temp_tpl->attach(do_template('COMCODE_IMG', array('_GUID' => '70166d8dbb0aff064b99c0dd30ed77a8', 'RAND' => uniqid('', true), 'REFRESH_TIME' => $refresh_time, 'ROLLOVER' => $rollover, 'ALIGN' => $align, 'URL' => $url_full, 'TOOLTIP' => $tooltip, 'CAPTION' => $caption)));
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => '918162250c80e10212efd9a051545b9b', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'flash':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            $given_url = $_embed;
            $_embed = remove_url_mistakes($_embed);
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
            $url_full = url_is_local($_embed) ? get_custom_base_url() . '/' . $_embed : $_embed;
            $temp_tpl = test_url($url_full, 'flash', @html_entity_decode($given_url, ENT_QUOTES, get_charset()), $source_member);
            if ($attributes['param'] == '' || strpos($attributes['param'], 'x') === false) {
                if (!array_key_exists('width', $attributes)) {
                    $attributes['width'] = '300';
                }
                if (!array_key_exists('height', $attributes)) {
                    $attributes['height'] = '300';
                }
                $attributes['param'] = $attributes['width'] . 'x' . $attributes['height'];
            }
            list($width, $height) = explode('x', $attributes['param'], 2);
            if (addon_installed('jwplayer') && (substr($url_full, -4) == '.flv' || substr($url_full, -4) == '.mp4' || substr($url_full, -4) == '.mp3' || substr($url_full, -4) == '.webm')) {
                $temp_tpl->attach(do_template('COMCODE_FLV', array('_GUID' => '4746684d9e098709cc6671e1b00ce47e', 'URL' => $url_full, 'WIDTH' => $width, 'HEIGHT' => $height)));
            } else {
                $temp_tpl->attach(do_template('COMCODE_SWF', array('_GUID' => '8bc61ad75977a5a85eff96454af31fe8', 'URL' => $url_full, 'WIDTH' => $width, 'HEIGHT' => $height)));
            }
            break;
        case 'url':
            // Make them both HTML strings
            $url = $embed->evaluate();
            if (is_object($attributes['param'])) {
                $switch_over = true;
                // We know if must be Comcode XML
                $attributes['param'] = $attributes['param']->evaluate();
            } else {
                $switch_over = !looks_like_url($url) && looks_like_url($attributes['param'], true);
                if (strpos($attributes['param'], '[') !== false || strpos($attributes['param'], '{') !== false) {
                    $param_temp = comcode_to_tempcode(escape_html($attributes['param']), $source_member, $as_admin, 60, NULL, $connection, false, false, true, false, false, $highlight_bits, $on_behalf_of_member);
                    global $ADVERTISING_BANNERS;
                    $temp_ab = $ADVERTISING_BANNERS;
                    $ADVERTISING_BANNERS = array();
                    $caption = $param_temp;
                    $ADVERTISING_BANNERS = $temp_ab;
                } else {
                    $caption = make_string_tempcode(escape_html($attributes['param']));
                    // Consistency of escaping
                }
            }
            // Do we need to switch around?
            if ($switch_over) {
                $url = $attributes['param'];
                $caption = $embed;
            }
            // If we weren't given a caption, use the URL, but crop if necessary
            if ($caption->evaluate() == '') {
                $_caption = $url;
                // Shorten the URL if it is too long
                $max_link_length = 50;
                if (strlen($_caption) > $max_link_length) {
                    $_caption = escape_html(substr(@html_entity_decode($_caption, ENT_QUOTES, get_charset()), 0, intval($max_link_length / 2 - 3))) . '&hellip;' . escape_html(substr(@html_entity_decode($_caption, ENT_QUOTES, get_charset()), intval(-$max_link_length / 2)));
                }
                $caption = make_string_tempcode($_caption);
            }
            // Tidy up the URL now
            $url = @html_entity_decode($url, ENT_QUOTES, get_charset());
            $url = fixup_protocolless_urls($url);
            // Integrity and security
            $url = check_naughty_javascript_url($source_member, $url, $as_admin);
            // More URL tidying
            $local = url_is_local($url) || strpos($url, get_domain()) !== false;
            $given_url = $url;
            if ($url != '' && $url[0] != '#') {
                if (substr($url, 0, 1) == '/') {
                    $url = substr($url, 1);
                }
                $url_full = url_is_local($url) ? get_base_url() . '/' . $url : $url;
                if ($GLOBALS['XSS_DETECT']) {
                    ocp_mark_as_escaped($url_full);
                }
            } else {
                $url_full = $url;
            }
            $striped_base_url = str_replace('www.', '', str_replace('http://', '', get_base_url()));
            if ($striped_base_url != '' && substr($url, 0, 1) != '%' && strpos($url_full, $striped_base_url) === false) {
                $temp_tpl = test_url($url_full, 'url', $given_url, $source_member);
            }
            // Render
            if (!array_key_exists('target', $attributes)) {
                $attributes['target'] = $local ? '_top' : '_blank';
            }
            if ($attributes['target'] == 'blank') {
                $attributes['target'] = '_blank';
            }
            $rel = $as_admin || has_specific_permission($source_member, 'search_engine_links') ? '' : 'nofollow';
            if ($attributes['target'] == '_blank') {
                $title = (is_object($caption) ? static_evaluate_tempcode($caption) : $caption) . ' ' . do_lang('LINK_NEW_WINDOW');
            } else {
                $title = '';
            }
            $temp_tpl->attach(do_template('COMCODE_URL', array('_GUID' => 'd1657530e6d3d57e6a4791fb3bfa0dd7', 'TITLE' => $title, 'REL' => $rel, 'TARGET' => $attributes['target'], 'URL' => $url_full, 'CAPTION' => $caption)));
            break;
        case 'email':
            $_embed = $embed->evaluate();
            require_code('type_validation');
            require_code('obfuscate');
            // If we need to switch
            if (is_object($attributes['param']) || !is_valid_email_address($_embed) && is_valid_email_address($attributes['param'])) {
                $temp = $embed;
                // Is tempcode
                $_embed = $attributes['param'];
                $attributes['param'] = $temp;
            } else {
                $attributes['param'] = comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                // Becomes tempcode
            }
            if ($attributes['param']->is_empty()) {
                $attributes['param'] = obfuscate_email_address($_embed);
            }
            $subject = array_key_exists('subject', $attributes) ? $attributes['subject'] : '';
            $body = array_key_exists('body', $attributes) ? $attributes['body'] : '';
            $title = '';
            if (array_key_exists('title', $attributes)) {
                $title = $attributes['title'];
            }
            $temp_tpl = do_template('COMCODE_EMAIL', array('_GUID' => '5f6ade8fe07701b6858575153d78f4e9', 'TITLE' => $title, 'ADDRESS' => obfuscate_email_address($_embed), 'SUBJECT' => $subject, 'BODY' => $body, 'CAPTION' => $attributes['param']));
            break;
        case 'reference':
            if ($wml) {
                break;
            }
            if (array_key_exists('type', $attributes) && $attributes['type'] == 'url') {
                $_embed = $embed->evaluate();
                $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
                if (!array_key_exists('title', $attributes)) {
                    $attributes['title'] = $attributes['param'];
                }
                if (is_object($attributes['title']) || $attributes['title'] != '') {
                    $_title = is_object($attributes['title']) ? make_string_tempcode(escape_html($attributes['title'])) : comcode_to_tempcode($attributes['title'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $title = $_title->evaluate();
                } else {
                    $title = $_embed;
                }
                $embed = hyperlink($_embed, $title, true);
            }
            $temp_tpl = do_template('COMCODE_REFERENCE', array_merge($attributes, array('SOURCE' => $embed)));
            break;
        case 'upload':
            // This points to a file path, not a URL
            $_embed = $embed->evaluate();
            $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'downloads';
            if (is_object($attributes['param']) || $attributes['param'] != '') {
                $_caption = is_object($attributes['param']) ? make_string_tempcode(escape_html($attributes['param'])) : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                $__caption = $_caption->evaluate();
            } else {
                $__caption = $_embed;
            }
            $url = get_custom_base_url() . '/' . $type . '/' . rawurlencode($_embed);
            $url = check_naughty_javascript_url($source_member, $url, $as_admin);
            $temp_tpl = test_url($url, 'upload', $_embed, $source_member);
            $temp_tpl->attach(hyperlink($url, $__caption));
            break;
        case 'page':
            $ignore_if_hidden = array_key_exists('ignore_if_hidden', $attributes) && $attributes['ignore_if_hidden'] == '1';
            unset($attributes['ignore_if_hidden']);
            // Two sets of parameters: simple style and complex style; both are completely incompatible
            $hash = '';
            if ($attributes == array('param' => '')) {
                $zone = '_SEARCH';
                $caption = $embed;
                $attributes = array('page' => $caption->evaluate());
            } elseif (array_keys($attributes) == array('param')) {
                $caption = $embed;
                if ($wml) {
                    $temp_tpl = $embed;
                    break;
                } else {
                    if (strpos($attributes['param'], ':') !== false) {
                        global $OVERRIDE_SELF_ZONE;
                        $page_link = $attributes['param'];
                        list($zone, $attributes, $hash) = page_link_decode($page_link);
                        if (!array_key_exists('page', $attributes)) {
                            $attributes['page'] = '';
                        }
                        if ($zone == '_SELF' && !is_null($OVERRIDE_SELF_ZONE)) {
                            $zone = $OVERRIDE_SELF_ZONE;
                        }
                    } else {
                        $zone = '_SEARCH';
                        // Changed in v3 from '_SELF', to allow context-sensitivity
                        $attributes = array_merge(array('page' => $attributes['param']), $attributes);
                    }
                }
            } else {
                $caption = array_key_exists('caption', $attributes) ? comcode_to_tempcode($attributes['caption'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member) : $embed;
                if ($wml) {
                    $temp_tpl = $caption;
                    break;
                } else {
                    $zone = $param_given ? $attributes['param'] : '_SEARCH';
                    // Changed in v3 from '_SELF', to allow context-sensitivity
                    unset($attributes['caption']);
                    if (!array_key_exists('page', $attributes)) {
                        $attributes = array_merge(array('page' => $embed->evaluate()), $attributes);
                    }
                }
            }
            unset($attributes['param']);
            foreach ($attributes as $key => $val) {
                if (is_object($val)) {
                    $attributes[$key] = $val->evaluate();
                }
            }
            if ($zone == '_SEARCH') {
                $zone = get_page_zone($attributes['page'], false);
                if (is_null($zone)) {
                    $zone = '';
                }
            }
            $pl_url = build_url($attributes, $zone, NULL, false, false, false, $hash);
            $temp_tpl = hyperlink($pl_url, $caption);
            $page = $attributes['page'];
            if ($page != '') {
                if ($zone == '_SELF') {
                    $zone = get_zone_name();
                }
                if ($zone == '_SEARCH') {
                    $zone = get_page_zone($page, false);
                    if (is_null($zone)) {
                        $zone = '';
                    }
                    // Oh dear, well it will be correctly identified as not found anyway
                }
                $ptest = _request_page($page, $zone);
                if ($ptest !== false) {
                    if ($page == 'topicview' && array_key_exists('id', $attributes)) {
                        if (!is_numeric($attributes['id'])) {
                            $attributes['id'] = $GLOBALS['SITE_DB']->query_value_null_ok('url_id_monikers', 'm_resource_id', array('m_resource_page' => $page, 'm_moniker' => $attributes['id']));
                        }
                        if (!is_null($attributes['id'])) {
                            $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 'id', array('id' => $attributes['id']));
                            if (is_null($test)) {
                                $ptest = false;
                            }
                        } else {
                            $ptest = false;
                        }
                    }
                }
                if ($ptest === false) {
                    //$temp_tpl->attach(' ['.do_lang('MISSING_RESOURCE').']');  // Don't want this as we might be making the page immediately
                    if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !in_array($page, $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        if ($ignore_if_hidden) {
                            $temp_tpl = do_template('COMCODE_DEL', array('CONTENT' => $caption));
                        } else {
                            require_code('failure');
                            relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'page_link', $page_link), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                        }
                    }
                }
            }
            break;
        case 'hide':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if (array_key_exists('param', $attributes)) {
                $text = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            } else {
                $text = do_lang_tempcode('EXPAND');
            }
            $temp_tpl = do_template('COMCODE_HIDE', array('_GUID' => 'a591a0d1e6bb3dde0f22cebb9c7ab93e', 'TEXT' => $text, 'CONTENT' => $embed));
            break;
        case 'quote':
            if ($wml) {
                $temp_tpl->attach('<br /><br />' . $attributes['param'] . ':');
                $temp_tpl->attach($embed);
                break;
            }
            $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL;
            if (!is_null($cite)) {
                $temp_tpl = test_url($cite, 'quote', $cite, $source_member);
            }
            if ($attributes['param'] == '' && isset($attributes['author'])) {
                $attributes['param'] = $attributes['author'];
            }
            // Compatibility with SMF
            if ($attributes['param'] != '') {
                if (is_numeric($attributes['param'])) {
                    $attributes['param'] = $GLOBALS['FORUM_DRIVER']->get_username($attributes['param']);
                    if (is_null($attributes['param'])) {
                        $attributes['param'] = do_lang('UNKNOWN');
                    }
                } else {
                    $attributes['param'] = protect_from_escaping(comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member));
                }
                $temp_tpl->attach(do_template('COMCODE_QUOTE_BY', array('_GUID' => '18f55a548892ad08b0b50b3b586b5b95', 'CITE' => $cite, 'CONTENT' => $embed, 'BY' => $attributes['param'], 'SAIDLESS' => array_key_exists('saidless', $attributes) ? $attributes['saidless'] : '0')));
            } else {
                $temp_tpl->attach(do_template('COMCODE_QUOTE', array('_GUID' => 'fa275de59433c17da19b22814c17fdc5', 'CITE' => $cite, 'CONTENT' => $embed)));
            }
            break;
        case 'html':
            if ($wml) {
                break;
            }
            $temp_tpl = $embed;
            // Plain HTML. But it's been filtered already
            break;
        case 'semihtml':
            $temp_tpl = $embed;
            // Hybrid HTML. But it's been filtered already
            break;
        case 'block':
            if ($wml) {
                break;
            }
            $attributes['block'] = trim($embed->evaluate());
            if (preg_match('#^[\\w\\-]*$#', $attributes['block']) == 0) {
                $temp_tpl = paragraph(do_lang_tempcode('MISSING_BLOCK_FILE', escape_html($attributes['block'])), '90dfdlksds8d7dyddssddxs', 'error_marker');
                break;
                // Avoids a suspected hack attempt by just filtering early
            }
            $_attributes = array();
            foreach ($attributes as $key => $val) {
                $_attributes[] = $key . '=' . $val;
            }
            $temp_tpl = symbol_tempcode('BLOCK', $_attributes);
            break;
        case 'contents':
            if ($wml) {
                break;
            }
            // Do structure sweep
            $urls_for = array();
            $old_structure_list = $STRUCTURE_LIST;
            $STRUCTURE_LIST = array();
            // reset for e.g. comcode_text_to_tempcode calls (which don't itself reset it, although _comcode_to_tempcode does for top level parses)
            if (array_key_exists('files', $attributes) && $comcode_dangerous) {
                $s_zone = array_key_exists('zone', $attributes) ? $attributes['zone'] : get_zone_name();
                $pages = find_all_pages($s_zone, 'comcode_custom/' . get_site_default_lang(), 'txt') + find_all_pages($s_zone, 'comcode/' . get_site_default_lang(), 'txt');
                $prefix = $attributes['files'];
                foreach ($pages as $pg_name => $pg_type) {
                    if (substr($pg_name, 0, strlen($prefix)) == $prefix) {
                        $i = count($STRUCTURE_LIST);
                        comcode_to_tempcode(file_get_contents(zone_black_magic_filterer(get_file_base() . '/' . $s_zone . '/pages/' . $pg_type . '/' . $pg_name . '.txt'), FILE_TEXT), $source_member, $as_admin, 60, NULL, $connection, false, false, false, true, false, NULL, $on_behalf_of_member);
                        $page_url = build_url(array('page' => $pg_name), $s_zone);
                        while (array_key_exists($i, $STRUCTURE_LIST)) {
                            $urls_for[] = $page_url;
                            $i++;
                        }
                    }
                }
                $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 1;
            } else {
                if (substr($comcode, 0, 8) == '<comcode') {
                    require_code('comcode_xml');
                    if (!$as_admin) {
                        check_specific_permission('comcode_dangerous', NULL, $source_member);
                    }
                    $_ = new comcode_xml_to_tempcode($comcode, $source_member, 60, NULL, $connection, false, false, false, true, false, $on_behalf_of_member);
                } else {
                    require_code('comcode_text');
                    comcode_text_to_tempcode($comcode, $source_member, $as_admin, 60, NULL, $connection, false, false, false, true, false, NULL, $on_behalf_of_member);
                }
                $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 1;
            }
            $list_types = $embed->evaluate() == '' ? array() : explode(',', $embed->evaluate());
            $list_types += array('decimal', 'lower-alpha', 'lower-roman', 'upper-alpha', 'upper-roman', 'disc');
            $levels_allowed = array_key_exists('levels', $attributes) ? intval($attributes['levels']) : NULL;
            // Convert the list structure into a tree structure
            $past_level_stack = array(1);
            $subtree_stack = array(array());
            $levels = 1;
            foreach ($STRUCTURE_LIST as $i => $struct) {
                $level = $struct[0];
                $title = $struct[1];
                $uniq_id = $struct[2];
                $url = array_key_exists($i, $urls_for) ? $urls_for[$i] : '';
                if ($level > $levels_allowed && !is_null($levels_allowed)) {
                    continue;
                }
                // Going down the tree
                if ($level > $past_level_stack[$levels - 1]) {
                    array_push($past_level_stack, $level);
                    array_push($subtree_stack, array(array($uniq_id, $title->evaluate(), $url)));
                    $levels++;
                } else {
                    // Going back up the tree, destroying levels that must have now closed off
                    while ($level < $past_level_stack[$levels - 1] && $levels > 2) {
                        array_pop($past_level_stack);
                        $subtree = array_pop($subtree_stack);
                        $levels--;
                        // Alter the last of the next level on stack so it is actually taking the closed off level as children, and changing from a property list to a pair: property list & children
                        $subtree_stack[$levels - 1][count($subtree_stack[$levels - 1]) - 1] = array($subtree_stack[$levels - 1][count($subtree_stack[$levels - 1]) - 1], $subtree);
                    }
                    // Store the title where we are
                    $subtree_stack[$levels - 1][] = array($uniq_id, $title->evaluate(), $url);
                }
            }
            // Clean up... going up until we're with 1
            while ($levels > 1) {
                array_pop($past_level_stack);
                $subtree = array_pop($subtree_stack);
                $levels--;
                $parent_level_start_index = count($subtree_stack[$levels - 1]) - 1;
                if ($parent_level_start_index < 0) {
                    $subtree_stack[$levels - 1] = $subtree;
                } else {
                    $subtree_stack[$levels - 1][$parent_level_start_index] = array($subtree_stack[$levels - 1][$parent_level_start_index], $subtree);
                }
            }
            // Now we have the structure to display
            $levels_t = _do_contents_level($subtree_stack[0], $list_types, $base);
            $temp_tpl = do_template('COMCODE_CONTENTS', array('_GUID' => 'ca2f5320fa930e2257a2e74e4f98e5a0', 'LEVELS' => $levels_t));
            $STRUCTURE_LIST = $old_structure_list;
            // Restore, so subsequent 'title' tags have correct numbering
            break;
    }
    // Last ditch effort: custom tags
    if ($temp_tpl->is_definitely_empty() && !$wml) {
        global $REPLACE_TARGETS;
        if (array_key_exists($tag, $REPLACE_TARGETS)) {
            $replace = $REPLACE_TARGETS[$tag]['replace'];
            $parameters = explode(',', $REPLACE_TARGETS[$tag]['parameters']);
            $binding = array('CONTENT' => $embed, 'RAND' => uniqid('', true));
            foreach ($parameters as $parameter) {
                $parameter = trim($parameter);
                $parts = explode('=', $parameter);
                if (count($parts) == 1) {
                    $parts[] = '';
                }
                if (count($parts) != 2) {
                    continue;
                }
                list($parameter, $default) = $parts;
                if (!array_key_exists($parameter, $attributes) || $attributes[$parameter] == '') {
                    $attributes[$parameter] = $default;
                }
                $binding[strtoupper($parameter)] = $attributes[$parameter];
                $replace = str_replace('{' . $parameter . '}', '{' . strtoupper($parameter) . '*}', $replace);
            }
            $replace = str_replace('{content}', array_key_exists($tag, $GLOBALS['TEXTUAL_TAGS']) ? '{CONTENT}' : '{CONTENT*}', $replace);
            require_code('tempcode_compiler');
            $temp_tpl = template_to_tempcode($replace);
            $temp_tpl = $temp_tpl->bind($binding, '(custom comcode: ' . $tag . ')');
        }
    }
    return $temp_tpl;
}
示例#11
0
 /**
  * Take a file in the gallery uploads directory, and add it to a gallery.
  *
  * @param  URLPATH	The URL to the file
  * @param  URLPATH	The thumb URL to the file
  * @param  string		The filename
  * @param  ID_TEXT	The gallery to add to
  */
 function simple_add($url, $thumb_url, $file, $cat)
 {
     require_code('exif');
     if (substr($thumb_url, -4, 4) == '.gif') {
         $thumb_url = substr($thumb_url, 0, strlen($thumb_url) - 4) . '.png';
     }
     if (is_video($url)) {
         $ret = get_video_details(get_custom_file_base() . '/' . rawurldecode($url), $file, true);
         if ($ret !== false) {
             list($width, $height, $length) = $ret;
             if (is_null($width)) {
                 $width = 100;
             }
             if (is_null($height)) {
                 $height = 100;
             }
             if (is_null($length)) {
                 $length = 0;
             }
             $exif = get_exif_data(get_custom_file_base() . '/' . rawurldecode($url), $file);
             $id = add_video($exif['UserComment'], $cat, '', $url, '', 1, post_param_integer('allow_rating', 0), post_param_integer('allow_reviews', post_param_integer('allow_comments', 0)), post_param_integer('allow_trackbacks', 0), post_param('notes', ''), $length, $width, $height);
             store_exif('video', strval($id), $exif);
             if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
                 syndicate_described_activity('galleries:ACTIVITY_ADD_VIDEO', $exif['UserComment'] == '' ? basename($url) : $exif['UserComment'], '', '', '_SEARCH:galleries:video:' . strval($id), '', '', 'galleries');
             }
         }
     } else {
         $ok = true;
         if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
             require_code('images');
             $ok = convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . rawurldecode($thumb_url), -1, -1, intval(get_option('thumb_width')), true);
         }
         if ($ok) {
             $exif = get_exif_data(get_custom_file_base() . '/' . rawurldecode($url), $file);
             if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
                 // See if we need to resize the image
                 constrain_gallery_image_to_max_size(get_custom_file_base() . '/' . rawurldecode($url), $file, intval(get_option('maximum_image_size')));
                 // See if we need to do watermarking
                 $watermark = post_param_integer('watermark', 0);
                 if ($watermark == 1) {
                     watermark_gallery_image($cat, rawurldecode($url), $file);
                 }
             }
             $id = add_image($exif['UserComment'], $cat, '', $url, $thumb_url, 1, post_param_integer('allow_rating', 0), post_param_integer('allow_reviews', post_param_integer('allow_comments', 0)), post_param_integer('allow_trackbacks', 0), post_param('notes', ''));
             store_exif('image', strval($id), $exif);
             if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries') && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'galleries', $cat)) {
                 syndicate_described_activity('galleries:ACTIVITY_ADD_IMAGE', $exif['UserComment'] == '' ? basename($url) : $exif['UserComment'], '', '', '_SEARCH:galleries:image:' . strval($id), '', '', 'galleries');
             }
         }
     }
 }
示例#12
0
/**
 * Allows conversion of a URL to a thumbnail via a simple script.
 */
function thumb_script()
{
    $url_full = get_param('url');
    if (strpos($url_full, '://') === false) {
        $url_full = base64_decode($url_full);
    }
    require_code('images');
    $new_name = url_to_filename($url_full);
    if (!is_saveable_image($new_name)) {
        $new_name .= '.png';
    }
    if (is_null($new_name)) {
        warn_exit(do_lang_tempcode('URL_THUMB_TOO_LONG'));
    }
    $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
    if (!file_exists($file_thumb)) {
        convert_image($url_full, $file_thumb, -1, -1, intval(get_option('thumb_width')), false);
    }
    $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
    if (strpos($url_thumb, chr(10)) !== false || strpos($url_thumb, chr(13)) !== false) {
        log_hack_attack_and_exit('HEADER_SPLIT_HACK');
    }
    header('Location: ' . $url_thumb);
}
示例#13
0
 /**
  * Convert a field value to something renderable.
  *
  * @param  array			The field details
  * @param  mixed			The raw value
  * @param  integer		Position in fieldset
  * @param  ?array			List of fields the output is being limited to (NULL: N/A)
  * @return mixed			Rendered field (tempcode or string)
  */
 function render_field_value($field, $ev, $i, $only_fields)
 {
     if (is_object($ev)) {
         return $ev;
     }
     if ($ev == '') {
         return '';
     }
     $img_url = $ev;
     if (url_is_local($img_url)) {
         $img_url = get_custom_base_url() . '/' . $img_url;
     }
     if (get_option('is_on_gd') == '0' || !function_exists('imagetypes')) {
         $img_thumb_url = $img_url;
     } else {
         $new_name = url_to_filename($ev);
         require_code('images');
         if (!is_saveable_image($new_name)) {
             $new_name .= '.png';
         }
         $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
         if (!file_exists($file_thumb)) {
             convert_image($img_url, $file_thumb, -1, -1, intval(get_option('thumb_width')), false);
         }
         $img_thumb_url = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
     }
     if (!array_key_exists('c_name', $field)) {
         $field['c_name'] = 'other';
     }
     $tpl_set = $field['c_name'];
     $GLOBALS['META_DATA'] += array('image' => $img_url);
     return do_template('CATALOGUE_' . $tpl_set . '_ENTRY_FIELD_PICTURE', array('I' => is_null($only_fields) ? '-1' : strval($i), 'CATALOGUE' => $field['c_name'], 'URL' => $img_url, 'THUMB_URL' => $img_thumb_url), NULL, false, 'CATALOGUE_DEFAULT_ENTRY_FIELD_PICTURE');
 }
示例#14
0
/**
 * Edit a member's avatar, and check validity.
 *
 * @param  URLPATH	The new avatar URL.
 * @param  ?MEMBER	The member (NULL: the current member).
 */
function ocf_member_choose_avatar($avatar_url, $member_id = NULL)
{
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    $old = $GLOBALS['FORUM_DB']->query_value('f_members', 'm_avatar_url', array('id' => $member_id));
    if ($old == $avatar_url) {
        return;
    }
    // Check it has valid dimensions
    if ($avatar_url != '') {
        require_code('images');
        if (!is_image($avatar_url, true)) {
            $ext = get_file_extension($avatar_url);
            warn_exit(do_lang_tempcode('UNKNOWN_FORMAT', escape_html($ext)));
        }
        $stub = url_is_local($avatar_url) ? get_complex_base_url($avatar_url) . '/' : '';
        if (get_option('is_on_gd') == '1' && function_exists('imagetypes')) {
            $file_path_stub = convert_url_to_path($stub . $avatar_url);
            if (!is_null($file_path_stub)) {
                $from_file = @file_get_contents($file_path_stub);
            } else {
                $from_file = http_download_file($stub . $avatar_url, 1024 * 1024 * 4, false);
            }
            if (is_null($from_file)) {
                warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
            }
            $source = @imagecreatefromstring($from_file);
            if ($source === false) {
                warn_exit(do_lang_tempcode('CORRUPT_FILE', escape_html($avatar_url)));
            }
            if (get_file_extension($avatar_url) == 'gif') {
                $header = unpack('@6/' . 'vwidth/' . 'vheight', $from_file);
                $sx = $header['width'];
                $sy = $header['height'];
            } else {
                $sx = imagesx($source);
                $sy = imagesy($source);
            }
            imagedestroy($source);
            $width = ocf_get_member_best_group_property($member_id, 'max_avatar_width');
            $height = ocf_get_member_best_group_property($member_id, 'max_avatar_height');
            if ($sx > $width || $sy > $height) {
                require_code('images');
                $file_path = get_custom_file_base() . '/' . rawurldecode($avatar_url);
                if (!is_saveable_image($file_path) || !url_is_local($avatar_url)) {
                    if (url_is_local($avatar_url) && substr($avatar_url, 0, 20) == 'uploads/ocf_avatars/') {
                        unlink($file_path);
                        sync_file(rawurldecode($avatar_url));
                    }
                    warn_exit(do_lang_tempcode('IMAGE_BAD_DIMENSIONS', strval($width) . 'x' . strval($height), strval($sx) . 'x' . strval($sy)));
                }
                convert_image($file_path, $file_path, $width, $height, -1, false, get_file_extension($file_path), true, true);
            }
        }
        if (substr($avatar_url, 0, 7) != 'themes/' && addon_installed('ocf_avatars')) {
            require_code('notifications');
            dispatch_notification('ocf_choose_avatar', NULL, do_lang('CHOOSE_AVATAR_SUBJECT', $GLOBALS['FORUM_DRIVER']->get_username($member_id), NULL, NULL, get_lang($member_id)), do_lang('CHOOSE_AVATAR_BODY', $stub . $avatar_url, $GLOBALS['FORUM_DRIVER']->get_username($member_id), NULL, get_lang($member_id)));
        }
    }
    // Cleanup old avatar
    if (url_is_local($old) && (substr($old, 0, 20) == 'uploads/ocf_avatars/' || substr($old, 0, 16) == 'uploads/avatars/') && $old != $avatar_url) {
        @unlink(get_custom_file_base() . '/' . rawurldecode($old));
    }
    $GLOBALS['FORUM_DB']->query_update('f_members', array('m_avatar_url' => $avatar_url), array('id' => $member_id), '', 1);
    // Decache from run-time cache
    unset($GLOBALS['FORUM_DRIVER']->MEMBER_ROWS_CACHED[$member_id]);
    unset($GLOBALS['MEMBER_CACHE_FIELD_MAPPINGS'][$member_id]);
}
                // resize image to maximum height and width, if set
                if ($tinybrowser['imageresize']['width'] > 0 || $tinybrowser['imageresize']['height'] > 0) {
                    // assign new width and height values, only if they are less than existing image size
                    $widthnew = $tinybrowser['imageresize']['width'] > 0 && $tinybrowser['imageresize']['width'] < $imginfo[0] ? $tinybrowser['imageresize']['width'] : $imginfo[0];
                    $heightnew = $tinybrowser['imageresize']['height'] > 0 && $tinybrowser['imageresize']['height'] < $imginfo[1] ? $tinybrowser['imageresize']['height'] : $imginfo[1];
                    // only resize if width or height values are different
                    if ($widthnew != $imginfo[0] || $heightnew != $imginfo[1]) {
                        $im = convert_image($dest_filename, $mime);
                        resizeimage($im, $widthnew, $heightnew, $dest_filename, $tinybrowser['imagequality'], $mime);
                        imagedestroy($im);
                    }
                }
                // generate thumbnail
                $thumbimg = $folder . '_thumbs/_' . rtrim($file, '_');
                if (!file_exists($thumbimg)) {
                    $im = convert_image($dest_filename, $mime);
                    resizeimage($im, $tinybrowser['thumbsize'], $tinybrowser['thumbsize'], $thumbimg, $tinybrowser['thumbquality'], $mime);
                    imagedestroy($im);
                }
            }
        }
    }
    closedir($handle);
}
$bad = $total - ($good + $dup);
// Check for problem during upload
if ($total > 0 && $bad == $total) {
    Header('Location: ./upload.php?type=' . $_GET['type'] . $passfeid . '&permerror=1&total=' . $total);
} else {
    Header('Location: ./upload.php?type=' . $_GET['type'] . $passfeid . '&folder=' . $foldernow . '&badfiles=' . $bad . '&goodfiles=' . $good . '&dupfiles=' . $dup);
}
示例#16
0
/**
 * Get an array containing new comcode, and tempcode. The function wraps the normal comcode_to_tempcode function. The function will do attachment management, including deleting of attachments that have become unused due to editing of some comcode and removing of the reference.
 *
 * @param  LONG_TEXT		The unparsed comcode that references the attachments
 * @param  ID_TEXT		The type the attachment will be used for (e.g. download)
 * @param  ID_TEXT		The ID the attachment will be used for
 * @param  boolean		Whether we are only previewing the attachments (i.e. don't store them!)
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  ?boolean		Whether to insert it as an admin (any comcode parsing will be carried out with admin privileges) (NULL: autodetect)
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return array			A map containing 'comcode' (after substitution for tying down the new attachments) and 'tempcode'
 */
function do_comcode_attachments($original_comcode, $type, $id, $previewing_only = false, $connection = NULL, $insert_as_admin = NULL, $for_member = NULL)
{
    require_lang('comcode');
    global $COMCODE_ATTACHMENTS;
    unset($COMCODE_ATTACHMENTS[$id]);
    // In case we have some kind of conflict
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    if ($for_member !== NULL) {
        $member = $for_member;
        if (is_null($insert_as_admin)) {
            $insert_as_admin = false;
        }
    } else {
        if (function_exists('get_member')) {
            $member = get_member();
            if (is_null($insert_as_admin)) {
                $insert_as_admin = false;
            }
        } else {
            $member = 0;
            if (is_null($insert_as_admin)) {
                $insert_as_admin = true;
            }
        }
    }
    $comcode_text = substr($original_comcode, 0, 8) != '<comcode';
    // Handle data URLs for attachment embedding
    if (function_exists('imagecreatefromstring')) {
        $matches = array();
        $matches2 = array();
        $num_matches = preg_match_all('#<img[^<>]*src="data:image/\\w+;base64,([^"]*)"[^<>]*>#', $original_comcode, $matches);
        $num_matches2 = preg_match_all('#\\[img[^\\[\\]]*\\]data:image/\\w+;base64,([^"]*)\\[/img\\]#', $original_comcode, $matches2);
        for ($i = 0; $i < $num_matches2; $i++) {
            $matches[0][$num_matches] = $matches2[0][$i];
            $matches[1][$num_matches] = $matches2[1][$i];
            $num_matches++;
        }
        for ($i = 0; $i < $num_matches; $i++) {
            if (strpos($original_comcode, $matches[0][$i]) !== false) {
                $data = @base64_decode($matches[1][$i]);
                if ($data !== false && function_exists('imagepng')) {
                    $image = @imagecreatefromstring($data);
                    if ($image !== false) {
                        do {
                            $new_filename = uniqid('', true) . '.png';
                            $new_path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
                        } while (file_exists($new_path));
                        imagepng($image, $new_path);
                        $attachment_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => get_member(), 'a_file_size' => strlen($data), 'a_url' => 'uploads/attachments/' . $new_filename, 'a_thumb_url' => '', 'a_original_filename' => basename($new_filename), 'a_num_downloads' => 0, 'a_last_downloaded_time' => time(), 'a_description' => '', 'a_add_time' => time()), true);
                        $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment_id));
                        $original_comcode = str_replace($matches[0][$i], '[attachment type="inline" thumb="0"]' . strval($attachment_id) . '[/attachment]', $original_comcode);
                    }
                }
            }
        }
    }
    global $ATTACHMENTS_ALREADY_REFERENCED;
    $old_already = $ATTACHMENTS_ALREADY_REFERENCED;
    $ATTACHMENTS_ALREADY_REFERENCED = array();
    $before = $connection->query_select('attachment_refs', array('a_id', 'id'), array('r_referer_type' => $type, 'r_referer_id' => $id));
    foreach ($before as $ref) {
        $ATTACHMENTS_ALREADY_REFERENCED[$ref['a_id']] = 1;
    }
    $has_one = false;
    $may_have_one = false;
    foreach ($_POST as $key => $value) {
        if (preg_match('#^hidFileID\\_#i', $key) != 0) {
            require_code('uploads');
            $may_have_one = is_swf_upload();
        }
    }
    if ($may_have_one) {
        require_code('uploads');
        is_swf_upload(true);
        require_code('comcode_from_html');
        $original_comcode = preg_replace_callback('#<input [^>]*class="ocp_keep_ui_controlled" [^>]*title="([^"]*)" [^>]*type="text" [^>]*value="[^"]*"[^>]*/?' . '>#siU', 'debuttonise', $original_comcode);
    }
    $myfile = mixed();
    foreach ($_FILES as $key => $file) {
        $matches = array();
        if (($may_have_one && is_swf_upload() || is_uploaded_file($file['tmp_name'])) && preg_match('#file(\\d+)#', $key, $matches) != 0) {
            $has_one = true;
            $atype = post_param('attachmenttype' . $matches[1], '');
            $is_extract = preg_match('#\\[attachment [^\\]]*type="\\w+_extract"[^\\]]*\\]new_' . $matches[1] . '\\[/#', $original_comcode) != 0 || preg_match('#<attachment [^>]*type="\\w+_extract"[^>]*>new_' . $matches[1] . '</#', $original_comcode) != 0;
            if (substr($atype, -8) == '_extract' || $is_extract) {
                require_code('uploads');
                require_code('files');
                require_code('files2');
                $thumb = preg_match('#\\[(attachment|attachment_safe) [^\\]]*thumb="1"[^\\]]*\\]new_' . $matches[1] . '\\[/#', $original_comcode) != 0 || preg_match('#<(attachment|attachment_safe) [^>]*thumb="1"[^>]*>new_' . $matches[1] . '</#', $original_comcode) != 0;
                $arcext = get_file_extension($_FILES[$key]['name']);
                if ($arcext == 'tar' || $arcext == 'zip') {
                    if ($arcext == 'tar') {
                        require_code('tar');
                        $myfile = tar_open($file['tmp_name'], 'rb');
                        $dir = tar_get_directory($myfile, true);
                    } elseif ($arcext == 'zip') {
                        if (!function_exists('zip_open') && get_option('unzip_cmd') == '') {
                            warn_exit(do_lang_tempcode('ZIP_NOT_ENABLED'));
                        }
                        if (!function_exists('zip_open')) {
                            require_code('m_zip');
                            $mzip = true;
                        } else {
                            $mzip = false;
                        }
                        $myfile = zip_open($file['tmp_name']);
                        if (is_integer($myfile)) {
                            require_code('failure');
                            warn_exit(zip_error($myfile, $mzip));
                        }
                        $dir = array();
                        while (($zip_entry = zip_read($myfile)) !== false) {
                            $dir[] = array('zip_entry' => $zip_entry, 'path' => zip_entry_name($zip_entry), 'size' => zip_entry_filesize($zip_entry));
                        }
                    }
                    if (count($dir) > 100) {
                        require_code('site');
                        attach_message(do_lang_tempcode('TOO_MANY_FILES_TO_EXTRACT'), 'warn');
                    } else {
                        foreach ($dir as $entry) {
                            if (substr($entry['path'], -1) == '/') {
                                continue;
                            }
                            // Ignore folders
                            $_file = preg_replace('#\\..*\\.#', '.', basename($entry['path']));
                            if (!check_extension($_file, false, NULL, true)) {
                                continue;
                            }
                            if (should_ignore_file($entry['path'], IGNORE_ACCESS_CONTROLLERS | IGNORE_HIDDEN_FILES)) {
                                continue;
                            }
                            $place = get_custom_file_base() . '/uploads/attachments/' . $_file;
                            $i = 2;
                            // Hunt with sensible names until we don't get a conflict
                            while (file_exists($place)) {
                                $_file = strval($i) . basename($entry['path']);
                                $place = get_custom_file_base() . '/uploads/attachments/' . $_file;
                                $i++;
                            }
                            $i = 2;
                            $_file_thumb = basename($entry['path']);
                            $place_thumb = get_custom_file_base() . '/uploads/attachments_thumbs/' . $_file_thumb;
                            // Hunt with sensible names until we don't get a conflict
                            while (file_exists($place_thumb)) {
                                $_file_thumb = strval($i) . basename($entry['path']);
                                $place_thumb = get_custom_file_base() . '/uploads/attachments_thumbs/' . $_file_thumb;
                                $i++;
                            }
                            if ($arcext == 'tar') {
                                $file_details = tar_get_file($myfile, $entry['path'], false, $place);
                            } elseif ($arcext == 'zip') {
                                zip_entry_open($myfile, $entry['zip_entry']);
                                $file_details = array('size' => $entry['size']);
                                $out_file = @fopen($place, 'wb') or intelligent_write_error($place);
                                $more = mixed();
                                do {
                                    $more = zip_entry_read($entry['zip_entry']);
                                    if ($more !== false) {
                                        if (fwrite($out_file, $more) < strlen($more)) {
                                            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                                        }
                                    }
                                } while ($more !== false && $more != '');
                                fclose($out_file);
                                zip_entry_close($entry['zip_entry']);
                            }
                            $description = do_lang('EXTRACTED_FILE');
                            if (strpos($entry['path'], '/') !== false) {
                                $description = do_lang('EXTRACTED_FILE_PATH', dirname($entry['path']));
                            }
                            // Thumbnail
                            $thumb_url = '';
                            require_code('images');
                            if (is_image($_file)) {
                                $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
                                if ($gd) {
                                    require_code('images');
                                    if (!is_saveable_image($_file)) {
                                        $ext = '.png';
                                    } else {
                                        $ext = '.' . get_file_extension($_file);
                                    }
                                    $thumb_url = 'uploads/attachments_thumbs/' . $_file_thumb;
                                    convert_image(get_custom_base_url() . '/uploads/attachments/' . $_file, $place_thumb, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
                                    if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                                        $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                                    }
                                } else {
                                    $thumb_url = 'uploads/attachments/' . $_file;
                                }
                            }
                            $url = 'uploads/attachments/' . $_file;
                            if (addon_installed('galleries')) {
                                require_code('images');
                                if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                                    require_code('transcoding');
                                    $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                                }
                            }
                            $attachment_id = $connection->query_insert('attachments', array('a_member_id' => get_member(), 'a_file_size' => $file_details['size'], 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => basename($entry['path']), 'a_num_downloads' => 0, 'a_last_downloaded_time' => time(), 'a_description' => $description, 'a_add_time' => time()), true);
                            $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment_id));
                            if ($comcode_text) {
                                $original_comcode .= chr(10) . chr(10) . '[attachment type="' . comcode_escape(str_replace('_extract', '', $atype)) . '" description="' . comcode_escape($description) . '" thumb="' . ($thumb ? '1' : '0') . '"]' . strval($attachment_id) . '[/attachment]';
                            } else {
                                require_code('comcode_xml');
                                //$original_comcode.=chr(10).chr(10).'<attachment type="'.comcode_escape(str_replace('_extract','',$atype)).'" thumb="'.($thumb?'1':'0').'"><attachmentDescription>'.comcode_text__to__comcode_xml($description).'</attachmentDescription>'.strval($attachment_id).'</attachment>';			Would go in bad spot
                            }
                        }
                    }
                    if ($arcext == 'tar') {
                        tar_close($myfile);
                    } elseif ($arcext == 'zip') {
                        zip_close($myfile);
                    }
                }
            } else {
                if (strpos($original_comcode, ']new_' . $matches[1] . '[/attachment]') === false && strpos($original_comcode, '>new_' . $matches[1] . '</attachment>') === false && strpos($original_comcode, ']new_' . $matches[1] . '[/attachment_safe]') === false && strpos($original_comcode, '>new_' . $matches[1] . '</attachment_safe>') === false) {
                    if (preg_match('#\\]\\d+\\[/attachment\\]#', $original_comcode) == 0 && preg_match('#>\\d+</attachment>#', $original_comcode) == 0) {
                        if ($comcode_text) {
                            $original_comcode .= chr(10) . chr(10) . '[attachment]new_' . $matches[1] . '[/attachment]';
                        } else {
                            //$original_comcode.=chr(10).chr(10).'<attachment>new_'.$matches[1].'</attachment>';		Would go in bad spot
                        }
                    }
                }
            }
        }
    }
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    if ($has_one) {
        $LAX_COMCODE = true;
    }
    // We don't want a simple syntax error to cause us to lose our attachments
    $tempcode = comcode_to_tempcode($original_comcode, $member, $insert_as_admin, 60, $id, $connection, false, false, false, false, false, NULL, $for_member);
    $LAX_COMCODE = $temp;
    $ATTACHMENTS_ALREADY_REFERENCED = $old_already;
    /*if ((array_key_exists($id,$COMCODE_ATTACHMENTS)) && (array_key_exists(0,$COMCODE_ATTACHMENTS[$id])))
    	{
    		$original_comcode=$COMCODE_ATTACHMENTS[$id][0]['comcode'];
    	}*/
    $new_comcode = $original_comcode;
    if (array_key_exists($id, $COMCODE_ATTACHMENTS)) {
        $ids_present = array();
        for ($i = 0; $i < count($COMCODE_ATTACHMENTS[$id]); $i++) {
            $attachment = $COMCODE_ATTACHMENTS[$id][$i];
            // If it's a new one, we need to change the comcode to reference the ID we made for it
            if ($attachment['type'] == 'new') {
                $marker = $attachment['marker'];
                //				echo $marker.'!'.$new_comcode;
                $a_id = $attachment['id'];
                $old_length = strlen($new_comcode);
                // Search backwards from $marker
                $tag_end_start = $marker - strlen('[/' . $attachment['tag_type'] . ']');
                // </attachment> would be correct if it is Comcode-XML, but they have the same length, so it's irrelevant
                $tag_start_end = $tag_end_start;
                while ($tag_start_end > 1 && (!isset($new_comcode[$tag_start_end - 1]) || $new_comcode[$tag_start_end - 1] != ']' && $new_comcode[$tag_start_end - 1] != '>')) {
                    $tag_start_end--;
                }
                $param_keep = substr($new_comcode, 0, $tag_start_end - 1);
                $end_keep = substr($new_comcode, $tag_end_start);
                if ($comcode_text) {
                    $new_comcode = $param_keep;
                    if (strpos(substr($param_keep, strrpos($param_keep, '[')), ' type=') === false) {
                        $new_comcode .= ' type="' . comcode_escape($attachment['attachmenttype']) . '"';
                    }
                    if (strpos(substr($param_keep, strrpos($param_keep, '[')), ' description=') === false) {
                        $new_comcode .= ' description="' . comcode_escape($attachment['description']) . '"';
                    }
                    $new_comcode .= ']' . strval($a_id) . $end_keep;
                } else {
                    require_code('comcode_xml');
                    $new_comcode = $param_keep;
                    if (strpos(substr($param_keep, strrpos($param_keep, '<')), ' type=') === false) {
                        $new_comcode .= ' type="' . comcode_escape($attachment['attachmenttype']);
                    }
                    $new_comcode .= '">';
                    if (strpos(substr($param_keep, strrpos($param_keep, '<')), ' description=') === false) {
                        require_code('comcode_xml');
                        $new_comcode .= '<attachmentDescription>' . comcode_text__to__comcode_xml($attachment['description'], true) . '</attachmentDescription>';
                    }
                    $new_comcode .= strval($a_id) . $end_keep;
                }
                //				echo $new_comcode.'<br />!<br />';
                // Update other attachment markers
                $dif = strlen($new_comcode) - $old_length;
                for ($j = $i + 1; $j < count($COMCODE_ATTACHMENTS[$id]); $j++) {
                    //					echo $COMCODE_ATTACHMENTS[$id][$i]['marker'].'!';
                    $COMCODE_ATTACHMENTS[$id][$j]['marker'] += $dif;
                }
                if (!is_null($type)) {
                    $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $a_id));
                }
            } else {
                // (Re-)Reference it
                $connection->query_delete('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment['id']), '', 1);
                $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment['id']));
            }
            $ids_present[] = $attachment['id'];
        }
        if (!$previewing_only && get_value('disable_attachment_cleanup') !== '1') {
            // Clear any de-referenced attachments
            foreach ($before as $ref) {
                if (!in_array($ref['a_id'], $ids_present) && strpos($new_comcode, 'attachment.php?id=') === false && !multi_lang()) {
                    // Delete reference (as it's not actually in the new comcode!)
                    $connection->query_delete('attachment_refs', array('id' => $ref['id']), '', 1);
                    // Was that the last reference to this attachment? (if so -- delete attachment)
                    $test = $connection->query_value_null_ok('attachment_refs', 'id', array('a_id' => $ref['a_id']));
                    if (is_null($test)) {
                        require_code('attachments3');
                        _delete_attachment($ref['a_id'], $connection);
                    }
                }
            }
        }
    }
    return array('comcode' => $new_comcode, 'tempcode' => $tempcode);
}
示例#17
0
				// image specific info or general
				if($typenow=='image' && $imginfo = getimagesize($tinybrowser['docroot'].$browsepath.$filename))
					{
					$file['width'][] = $imginfo[0];
					$file['height'][] = $imginfo[1];
					$file['dimensions'][] = $imginfo[0] + $imginfo[1];
					$file['type'][] = $imginfo['mime'];

					// Check a thumbnail exists
					if(!file_exists($tinybrowser['docroot'].$browsepath.'_thumbs/')) createfolder($tinybrowser['docroot'].$browsepath.'_thumbs/',$tinybrowser['unixpermissions']);
			  		$thumbimg = $tinybrowser['docroot'].$browsepath.'_thumbs/_'.$filename;
					if (!file_exists($thumbimg))
						{
						$nothumbimg = $tinybrowser['docroot'].$browsepath.$filename;
						$mime = getimagesize($nothumbimg);
						$im = convert_image($nothumbimg,$mime['mime']);
						resizeimage($im,$tinybrowser['thumbsize'],$tinybrowser['thumbsize'],$thumbimg,$tinybrowser['thumbquality'],$mime['mime']);
						imagedestroy($im);
						$newthumbqty++;
						}
					}
				else
					{
					$file['width'][] = 'N/A';
					$file['height'][] = 'N/A';
					$file['dimensions'][] = 'N/A';
					$file['type'][] = returnMIMEType($filename);
					}
				}
			}
		}
示例#18
0
 /**
  * The actualiser for importing a CSV file.
  *
  * @return tempcode		The UI
  */
 function _import_csv()
 {
     $title = get_page_title('IMPORT_MEMBER_CSV');
     disable_php_memory_limit();
     // Even though we split into chunks, PHP does leak memory :(
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/import_csv';
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     require_lang('ocf');
     require_code('ocf_members_action');
     $default_password = post_param('default_password');
     $num_added = 0;
     $num_edited = 0;
     $done = 0;
     $headings = $this->_get_csv_headings();
     $all_cpfs = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_default', 'cf_type', 'cf_name'), NULL, 'ORDER BY cf_order');
     foreach ($all_cpfs as $i => $c) {
         $c['text_original'] = get_translated_text($c['cf_name'], $GLOBALS['FORUM_DB']);
         $all_cpfs[$i] = $c;
         $headings[$c['text_original']] = NULL;
     }
     $_all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, false, true);
     $all_groups = array_flip($_all_groups);
     $all_members = collapse_2d_complexity('id', 'm_username', $GLOBALS['FORUM_DB']->query_select('f_members', array('id', 'm_username')));
     $all_members_flipped = array_flip($all_members);
     // Import
     require_code('uploads');
     if (is_swf_upload(true) || array_key_exists('file', $_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) {
         $_csv_data = array();
         $fixed_contents = unixify_line_format(file_get_contents($_FILES['file']['tmp_name']));
         $myfile = @fopen($_FILES['file']['tmp_name'], 'wb');
         if ($myfile !== false) {
             fwrite($myfile, $fixed_contents);
             fclose($myfile);
         }
         $myfile = fopen($_FILES['file']['tmp_name'], 'rb');
         $del = ',';
         $csv_header = fgetcsv($myfile, 102400, $del);
         if ($csv_header === false) {
             warn_exit(do_lang_tempcode('NO_DATA_IMPORTED'));
         }
         if (count($csv_header) == 1 && strpos($csv_header[0], ';') !== false) {
             $del = ';';
             rewind($myfile);
             $csv_header = fgetcsv($myfile, 102400, $del);
         }
         while (($csv_line = fgetcsv($myfile, 102400, $del)) !== false) {
             $line = array();
             foreach ($csv_header as $i => $h) {
                 $extracted_value = trim(unixify_line_format(array_key_exists($i, $csv_line) ? $csv_line[$i] : ''));
                 if (strpos($h, ':') !== false) {
                     $parts = explode(':', $h, 2);
                     $h = trim($parts[0]);
                     if ($extracted_value != '') {
                         $extracted_value = $parts[1] . ': ' . $extracted_value;
                     }
                 }
                 if (array_key_exists($h, $line)) {
                     if ($extracted_value != '') {
                         $line[$h] .= ($line[$h] != '' ? chr(10) : '') . $extracted_value;
                     }
                 } else {
                     $line[$h] = $extracted_value;
                 }
             }
             if (!array_key_exists('Username', $line) || $line['Username'] == '') {
                 // Can we auto-generate it
                 $forename = NULL;
                 if (array_key_exists('Forenames', $line)) {
                     $forename = $line['Forenames'];
                 }
                 if (array_key_exists('Forename', $line)) {
                     $forename = $line['Forename'];
                 }
                 if (array_key_exists('First name', $line)) {
                     $forename = $line['First name'];
                 }
                 if (array_key_exists('First Name', $line)) {
                     $forename = $line['First Name'];
                 }
                 $surname = NULL;
                 if (array_key_exists('Surname', $line)) {
                     $surname = $line['Surname'];
                 }
                 if (array_key_exists('Last name', $line)) {
                     $surname = $line['Last name'];
                 }
                 if (array_key_exists('Last Name', $line)) {
                     $surname = $line['Last Name'];
                 }
                 if (!is_null($forename) || !is_null($surname)) {
                     // Can we get a year too?
                     $year = '';
                     foreach ($line as $tl_key => $tl_val) {
                         if (substr($tl_key, 0, 4) == 'Year') {
                             $year = $tl_val;
                             break;
                         }
                     }
                     if (strlen($year) == 4 && (substr($year, 0, 2) == '19' || substr($year, 0, 2) == '20')) {
                         $year = substr($year, 2);
                     }
                     // Tidy up forename
                     $_forename = preg_replace('#[^\\w]#', '', preg_replace('#[\\s\\.].*#', '', $forename));
                     // Tidy up surname (last bit strips like 'OBE')
                     $_surname = preg_replace('#[^\\w]#', '', trim(preg_replace('#\\s*[A-Z\\d][A-Z\\d]+#', '', $surname)));
                     // Put it together
                     $line['Username'] = ucfirst($_forename) . ucfirst($_surname) . $year;
                 } else {
                     continue;
                     // This field is needed
                 }
             }
             $username = $line['Username'];
             $linked_id = NULL;
             if (array_key_exists('ID', $line)) {
                 $linked_id = $line['ID'] != '' && array_key_exists(intval($line['ID']), $all_members) ? intval($line['ID']) : NULL;
             }
             if (is_null($linked_id)) {
                 $linked_id = array_key_exists($username, $all_members_flipped) ? $all_members_flipped[$username] : NULL;
             }
             $new_member = is_null($linked_id);
             $email_address_key = 'E-mail address';
             if (array_key_exists('Email address', $line)) {
                 $email_address_key = 'Email address';
             }
             if (array_key_exists('E-mail Address', $line)) {
                 $email_address_key = 'E-mail Address';
             }
             if (array_key_exists('Email Address', $line)) {
                 $email_address_key = 'Email Address';
             }
             if (array_key_exists('E-mail', $line)) {
                 $email_address_key = 'E-mail';
             }
             if (array_key_exists('Email', $line)) {
                 $email_address_key = 'Email';
             }
             $dob_key = 'Date of birth';
             if (array_key_exists('Date Of Birth', $line)) {
                 $dob_key = 'Date Of Birth';
             }
             if (array_key_exists('DOB', $line)) {
                 $dob_key = 'DOB';
             }
             // If it's an edited member, add in their existing CSV details, so that if it's a partial merge it'll still work without deleting anything!
             if (!$new_member) {
                 $member_groups = $GLOBALS['FORUM_DB']->query_select('f_group_members', array('gm_member_id', 'gm_group_id'), array('gm_validated' => 1, 'gm_member_id' => $linked_id));
                 $member_cpfs = list_to_map('mf_member_id', $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields', array('*'), array('mf_member_id' => $linked_id), '', 1));
                 $this_record = $this->_get_csv_member_record($member_cpfs, $GLOBALS['FORUM_DRIVER']->get_member_row($linked_id), $_all_groups, $headings, $all_cpfs, $member_groups);
                 // Remember "+" in PHP won't overwrite existing keys
                 if (!array_key_exists($email_address_key, $line)) {
                     unset($this_record['E-mail address']);
                 }
                 if (!array_key_exists($dob_key, $line)) {
                     unset($this_record['Date of birth']);
                 }
                 $line += $this_record;
             }
             // Set up member row
             if (array_key_exists('Password', $line) && $line['Password'] != '') {
                 $parts = explode('/', $line['Password']);
                 $password = $parts[0];
                 $salt = array_key_exists(1, $parts) ? $parts[1] : NULL;
                 $password_compatibility_scheme = array_key_exists(2, $parts) ? $parts[2] : NULL;
             } else {
                 $password = NULL;
                 $salt = NULL;
                 $password_compatibility_scheme = NULL;
             }
             $matches = array();
             if (array_key_exists($email_address_key, $line)) {
                 $email_address = $line[$email_address_key];
             } else {
                 $email_address = NULL;
             }
             if (preg_match('#^([^\\s]*)\\s+\\(.*\\)$#', $email_address, $matches) != 0) {
                 $email_address = $matches[1];
             }
             if (preg_match('#^.*\\s+<(.*)>$#', $email_address, $matches) != 0) {
                 $email_address = $matches[1];
             }
             if (array_key_exists($dob_key, $line)) {
                 $parts = explode('/', $line[$dob_key]);
                 $dob_day = array_key_exists(2, $parts) ? intval($parts[2]) : NULL;
                 $dob_month = array_key_exists(1, $parts) ? intval($parts[1]) : NULL;
                 $dob_year = array_key_exists(0, $parts) ? intval($parts[0]) : NULL;
             } else {
                 $dob_day = NULL;
                 $dob_month = NULL;
                 $dob_year = NULL;
             }
             $validated = array_key_exists('Validated', $line) ? strtoupper($line['Validated']) == 'YES' || $line['Validated'] == '1' || strtoupper($line['Validated']) == 'Y' || strtoupper($line['Validated']) == 'ON' ? 1 : 0 : 1;
             if (array_key_exists('Join time', $line)) {
                 if (strpos($line['Join time'], '-') !== false) {
                     $parts = explode('-', $line['Join time']);
                 } else {
                     $parts = explode('/', $line['Join time']);
                 }
                 if (!array_key_exists(1, $parts)) {
                     $parts[1] = '1';
                 }
                 if (!array_key_exists(2, $parts)) {
                     $parts[2] = '1';
                 }
                 if (strlen($parts[2]) != 4) {
                     $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[2]), intval($parts[0]));
                     // yy(yy)-mm-dd
                 } else {
                     $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[0]), intval($parts[2]));
                     // dd-mm-yyyy
                 }
                 if ($join_time > time()) {
                     $join_time = time();
                 }
                 // Fixes MySQL out of range error that could happen
             } else {
                 $join_time = NULL;
             }
             $avatar_url = array_key_exists('Avatar', $line) ? $line['Avatar'] : '';
             if (!is_null($avatar_url)) {
                 if (substr($avatar_url, 0, strlen(get_base_url() . '/')) == get_base_url() . '/') {
                     $avatar_url = substr($avatar_url, strlen(get_base_url() . '/'));
                 }
             }
             $signature = array_key_exists('Signature', $line) ? $line['Signature'] : '';
             $is_perm_banned = array_key_exists('Banned', $line) ? strtoupper($line['Banned']) == 'YES' || $line['Banned'] == '1' || strtoupper($line['Banned']) == 'Y' || strtoupper($line['Banned']) == 'ON' ? 1 : 0 : 0;
             $reveal_age = array_key_exists('Reveal age', $line) ? strtoupper($line['Reveal age']) == 'YES' || $line['Reveal age'] == '1' || strtoupper($line['Reveal age']) == 'Y' || strtoupper($line['Reveal age']) == 'ON' ? 1 : 0 : 0;
             $language = array_key_exists('Language', $line) ? $line['Language'] : '';
             $allow_emails = array_key_exists('Accept member e-mails', $line) ? strtoupper($line['Accept member e-mails']) == 'YES' || $line['Accept member e-mails'] == '1' || strtoupper($line['Accept member e-mails']) == 'Y' || strtoupper($line['Accept member e-mails']) == 'ON' ? 1 : 0 : 0;
             $allow_emails_from_staff = array_key_exists('Opt-in', $line) ? strtoupper($line['Opt-in']) == 'YES' || $line['Opt-in'] == '1' || strtoupper($line['Opt-in']) == 'Y' || strtoupper($line['Opt-in']) == 'ON' ? 1 : 0 : 0;
             $primary_group = NULL;
             $groups = NULL;
             if (array_key_exists('Usergroup', $line)) {
                 $parts = explode('/', $line['Usergroup']);
                 foreach ($parts as $p) {
                     if (!array_key_exists($p, $all_groups)) {
                         require_code('ocf_groups_action');
                         $g_id = ocf_make_group($p, 0, 0, 0, '');
                         $all_groups[$p] = $g_id;
                         $_group_edit_url = build_url(array('page' => 'admin_ocf_groups', 'type' => '_ed', 'id' => $g_id), get_module_zone('admin_ocf_groups'));
                         $group_edit_url = $_group_edit_url->evaluate();
                         attach_message(do_lang_tempcode('MEMBER_IMPORT_GROUP_ADDED', escape_html($p), escape_html($group_edit_url)), 'inform');
                     }
                 }
                 $primary_group = $all_groups[$parts[0]];
                 unset($parts[0]);
                 $groups = array();
                 foreach ($parts as $p) {
                     $groups[] = $all_groups[$p];
                 }
             }
             $photo_url = array_key_exists('Photo', $line) ? $line['Photo'] : '';
             if ($photo_url != '') {
                 require_code('images');
                 $photo_thumb_url = 'uploads/ocf_photos_thumbs/' . uniqid('', true) . '.png';
                 convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false);
             } else {
                 $photo_thumb_url = '';
             }
             $custom_fields = array();
             foreach ($all_cpfs as $cpf) {
                 $custom_fields[$cpf['id']] = array_key_exists($cpf['text_original'], $line) ? $line[$cpf['text_original']] : $cpf['cf_default'];
                 if (!array_key_exists($cpf['text_original'], $line) && $cpf['cf_type'] == 'list') {
                     $parts = explode($custom_fields[$cpf['id']], '|');
                     $custom_fields[$cpf['id']] = $parts[0];
                 }
                 if ($cpf['cf_type'] == 'integer') {
                     $custom_fields[$cpf['id']] = intval($custom_fields[$cpf['id']]);
                 } elseif ($cpf['cf_type'] == 'tick') {
                     $custom_fields[$cpf['id']] = strtoupper($custom_fields[$cpf['id']]) == 'YES' || strtoupper($custom_fields[$cpf['id']]) == 'Y' || strtoupper($custom_fields[$cpf['id']]) == 'ON' || $custom_fields[$cpf['id']] == '1' ? 1 : 0;
                 } elseif ($cpf['cf_type'] == 'short_text' || $cpf['cf_type'] == 'short_trans') {
                     $custom_fields[$cpf['id']] = substr(str_replace(chr(10), ', ', str_replace(',' . chr(10), chr(10), $custom_fields[$cpf['id']])), 0, 255);
                 } elseif ($cpf['cf_type'] == 'long_text' || $cpf['cf_type'] == 'long_trans') {
                     //$custom_fields[$cpf['id']]=$custom_fields[$cpf['id']];
                 } elseif ($cpf['cf_type'] == 'float') {
                     if (preg_match('#^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\n(\\d\\d\\d\\d)$#', $custom_fields[$cpf['id']]) != 0) {
                         $parts = explode(chr(10), $custom_fields[$cpf['id']], 2);
                         $month_lookup = array('Jan' => 0.1, 'Feb' => 0.2, 'Mar' => 0.3, 'Apr' => 0.4, 'May' => 0.5, 'Jun' => 0.6, 'Jul' => 0.7, 'Aug' => 0.8, 'Sep' => 0.9, 'Oct' => 0.1, 'Nov' => 0.11, 'Dec' => 0.12);
                         $custom_fields[$cpf['id']] = floatval($parts[1]) + $month_lookup[$parts[0]];
                     } else {
                         $custom_fields[$cpf['id']] = floatval($custom_fields[$cpf['id']]);
                     }
                 }
                 unset($line[$cpf['text_original']]);
             }
             foreach (array_keys($headings) as $h) {
                 unset($line[$h]);
             }
             unset($line[$email_address_key]);
             unset($line[$dob_key]);
             foreach ($line as $h => $f) {
                 $cf_id = ocf_make_custom_field($h, 0, '', '', 0, 0, 0, 0, 'long_text');
                 $_cpf_edit_url = build_url(array('page' => 'admin_ocf_customprofilefields', 'type' => '_ed', 'id' => $cf_id), get_module_zone('admin_ocf_customprofilefields'));
                 $cpf_edit_url = $_cpf_edit_url->evaluate();
                 attach_message(do_lang_tempcode('MEMBER_IMPORT_CPF_ADDED', escape_html($h), escape_html($cpf_edit_url)), 'inform');
                 $custom_fields[$cf_id] = $f;
                 $all_cpfs[] = array('id' => $cf_id, 'cf_default' => '', 'text_original' => $h, 'cf_type' => 'short_line');
             }
             if ($new_member) {
                 if (is_null($password)) {
                     $password = $default_password;
                 }
                 if (is_null($salt)) {
                     $salt = '';
                 }
                 if (is_null($password_compatibility_scheme)) {
                     $password_compatibility_scheme = '';
                 }
                 $linked_id = ocf_make_member($username, $password, is_null($email_address) ? '' : $email_address, $groups, $dob_day, $dob_month, $dob_year, $custom_fields, NULL, $primary_group, $validated, $join_time, NULL, '', $avatar_url, $signature, $is_perm_banned, get_option('default_preview_guests') == '1' ? 1 : 0, $reveal_age, '', $photo_url, $photo_thumb_url, 1, 1, $language, $allow_emails, $allow_emails_from_staff, '', NULL, '', false, $password_compatibility_scheme, $salt, 1, NULL, NULL, 0, '*', '');
                 $all_members[$linked_id] = $username;
                 $all_members_flipped[$username] = $linked_id;
                 $num_added++;
             } else {
                 $old_username = $GLOBALS['OCF_DRIVER']->get_member_row_field($linked_id, 'm_username');
                 if ($old_username == $username) {
                     $username = NULL;
                 }
                 ocf_edit_member($linked_id, $email_address, NULL, $dob_day, $dob_month, $dob_year, NULL, $primary_group, $custom_fields, NULL, $reveal_age, NULL, NULL, $language, $allow_emails, $allow_emails_from_staff, $validated, $username, $password, NULL, NULL, NULL, NULL, NULL, $join_time, $avatar_url, $signature, $is_perm_banned, $photo_url, $photo_thumb_url, $salt, $password_compatibility_scheme, true);
                 $num_edited++;
             }
             $done++;
         }
         fclose($myfile);
     } else {
         warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
     }
     if ($done == 0) {
         warn_exit(do_lang_tempcode('NO_DATA_IMPORTED'));
     }
     breadcrumb_set_parents(array(array('_SEARCH:admin_ocf_join:menu', do_lang_tempcode('MEMBERS')), array('_SEARCH:admin_ocf_join:import_csv', do_lang_tempcode('IMPORT_MEMBER_CSV'))));
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     return inform_screen($title, do_lang_tempcode('NUM_MEMBERS_IMPORTED', escape_html(integer_format($num_added)), escape_html(integer_format($num_edited))));
 }
示例#19
0
                    $degree = 90;
                }
                $mime = getimagesize($targetimg);
                $im = convert_image($targetimg, $mime['mime']);
                $newim = imagerotate($im, $degree, 0);
                imagedestroy($im);
                imagejpeg($newim, $targetimg, $tinybrowser['imagequality']);
                imagedestroy($newim);
                $rotateqty++;
                // delete and recreate thumbnail image
                $targetthumb = $tinybrowser['docroot'] . $editpath . "_thumbs/_" . $_POST['actionfile'][$rotatethis];
                if (file_exists($targetthumb)) {
                    unlink($targetthumb);
                }
                $mime = getimagesize($targetimg);
                $im = convert_image($targetimg, $mime['mime']);
                resizeimage($im, $tinybrowser['thumbsize'], $tinybrowser['thumbsize'], $targetthumb, $tinybrowser['thumbquality']);
                imagedestroy($im);
            } else {
                $errorqty++;
            }
        }
    }
}
// Read directory contents and populate $file array
$dh = opendir($tinybrowser['docroot'] . $editpath);
$file = array();
while (($filename = readdir($dh)) !== false) {
    if ($filename != "." && $filename != ".." && !is_dir($tinybrowser['docroot'] . $editpath . $filename)) {
        // search file name if search term entered
        if ($findnow) {
示例#20
0
     if ($convert_success) {
         foreach ($resolutions as $res) {
             $ret = check_dir($tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
             // check if cache subdirectories exist
             if (!$ret) {
                 $errorstring = "Error creating directory for resolution " . $res . "\n<br>\n";
                 $errorstring .= "or directory exists and is not writable\n<br>\n";
                 die($errorstring);
             }
             if ($res == '120x90') {
                 $is_thumbnail = true;
             } else {
                 $is_thumbnail = false;
             }
             $output_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
             $ret = convert_image($baseimage_filename, $output_filename, $res, $is_thumbnail);
             if ($ret) {
                 echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
                 $convert_success = true;
             } else {
                 echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
                 echo "Aborting...\n<br>\n";
                 $convert_success = false;
                 break;
             }
         }
     }
 }
 if ($convert_success) {
     // we have all necessary files now, so we get a correct id and move the files
     //