<?php require_once('includes/requirecompere.inc.php'); require_once('includes/requirepost.inc.php'); $zipfile=$_FILES['zipfile']; $nickname=TPOST('nickname'); $isupdating=TPOST('is_updating'); if (!$zipfile) { redirect("qx-cmd-theme.upload-err-nofile.html"); return; } if ($zipfile['error']!=UPLOAD_ERR_OK) { redirect("qx-cmd-theme.upload-err-failed-errcode-".$zipfile['error'].".html"); return; } if (substr($zipfile['name'],-4,4)!='.zip') { redirect("qx-cmd-theme.upload-err-filetype.html"); return; } $ph=popen("unzip -l ".$zipfile['tmp_name'],'r'); if ($ph) { $snapshot_ok=false; $errorname=false; $errorinfo=false; $state=0; while (($line=fgets($ph)) && !$errorname) { $last_line=$line; $parts=preg_split('/[ \r\t\n]+/',$line,-1,PREG_SPLIT_NO_EMPTY); if ($state==0) { if ($parts[0][0]=='-') $state=1; } else if ($state==1) { if ($parts[0][0]=='-') $state=2; else { if (substr($parts[3],0,7)=='images/') { if (strpos($parts[3],'/',7)===false) { if ($parts[3]=='images/snapshot-theme.gif') $snapshot_ok=true; if (substr($parts[3],-1,1)!='/') switch (substr($parts[3],-4,4)) { case '.gif': case '.jpg': break; default: $errorname="imagetype"; $errorinfo=$parts[3]; break; } } else { $errorname='dirstruct'; $errorinfo=$parts[3]; } } else if (strpos($parts[3],'/')!==false) { $errorname='dirstruct'; $errorinfo=$parts[3]; } else { if (substr($parts[3],-4,4)!='.css') { $errorname='dirstruct'; $errorinfo=$parts[3]; } } } } } pclose($ph); $parts=explode(' ',trim($last_line)); $expandedsize=$parts[0]+0; if ($errorname) { redirect("qx-cmd-theme.upload-err-".$errorname."-errorinfo-".urlencode($errorinfo).".html"); return; } if (!$snapshot_ok) { redirect("qx-cmd-theme.upload-err-nosnapshot.html"); return; } } else $expandedsize=0; if ($expandedsize==0 || $expandedsize>$Config->ThemeLimits['style.expanded.size']) { redirect("qx-cmd-theme.upload-err-filesize.html"); return; } $is_updated=false; if ($isupdating && is_current_theme_updatable_by_user(current_mb_id())) { $themename=deduce_theme_requested(); $is_updated=true; } else $themename=compute_theme_name(current_mb_id(),time()); $themepath=compute_theme_path($themename,$Config->Paths['theme.shared'].'/'); @mkdir($themepath,0755,true); $cmdline="unzip -o ".$zipfile['tmp_name']." -d ".realpath($themepath)." > /dev/null 2> /dev/null"; shell_exec($cmdline); if (@sha1_file($themepath."/images/snapshot-theme.gif")=="5e8fe027c6a903983d9513af15c7e317c642bae6") { remove_dir(realpath($themepath)); redirect("qx-cmd-theme.upload-err-snapshotunset.html"); return; } if (!$is_updated) report_theme_change($themename,$nickname,'new'); store_user_theme_setting(current_mb_id(),array('name'=>$themename,'nickname'=>$nickname)); $cssfiles=glob($themepath.'/*.css'); if ($cssfiles) foreach ($cssfiles as $cf) { $csstext=file_get_contents($cf); $csstext=str_replace('images/','#?IMAGE-PATH?#/',$csstext); file_put_contents($cf,$csstext); } redirect("qx-cmd-theme.manage-op-uploaded.html"); if ($is_updated) { task_send_request('theme','clearcache',$themename); } ?>