PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/functions.inc.php

https://github.com/adamfranco/segue-1.x
PHP | 2665 lines | 1862 code | 376 blank | 427 comment | 254 complexity | 0fee78a9d212fae9faad4dc222b468ae MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <? /* $Id$ */
  2. function makedownloadbar($o) {
  3. global $site,$section,$page,$uploaddir,$uploadurl;
  4. if ($o->getField("type")!='file') return;
  5. $b = db_get_line("media INNER JOIN slot ON media.FK_site=slot.FK_site","media_id='".addslashes($o->getField("longertext"))."'");
  6. ob_start();
  7. print "\n";
  8. print "\n<div class='downloadbar' style='margin-bottom: 10px'>";
  9. // print "\n\t<table width='100%' cellpadding='0' cellspacing='0'>\n\t<tr>\n\t\t<td>";
  10. if ($o->getField("title")) {
  11. print "\n<div style='float: left; '><strong><a href='index.php?$sid&amp;action=site&amp;site=$site&amp;section=$section&amp;page=$page&amp;story=".$o->id."&amp;detail=".$o->id."'>";
  12. print "".spchars($o->getField("title"))."</a></strong>\n\t\t\t</div>";
  13. }
  14. print printDownloadLink($b);
  15. print printMediaPlayer($b);
  16. print "\n\t\t\t\t\t<div style='clear: left; font-size: smaller; margin-bottom: 10px; '>";
  17. print printCitation($b);
  18. print "\n\t\t\t\t\t</div>";
  19. if ($o->getField("shorttext"))
  20. print "".stripslashes($o->getField("shorttext"));
  21. print "\n\t<div style='clear: both;'> </div>";
  22. print "</div>\n";
  23. return ob_get_clean();
  24. }
  25. function printMediaPlayer($mediaRow) {
  26. global $site,$section,$page,$uploaddir,$uploadurl, $cfg;
  27. // printpre($mediaRow);
  28. $filename = htmlspecialchars(urldecode($mediaRow[media_tag]));
  29. $filetype = ereg(".mp3", $filename);
  30. /* print $filename; */
  31. $dir = $mediaRow[slot_name];
  32. $size =$mediaRow[media_size];
  33. $fileurl = "$uploadurl/$dir/$filename";
  34. $filepath = "$uploaddir/$dir/$filename";
  35. $filesize = convertfilesize($size);
  36. if (ereg("\.mp3$", $filename) && !preg_match('/[^\x00-\x7F]/', $filename) ) {
  37. if (!isset($GLOBALS['playerid']))
  38. $GLOBALS['playerid'] = 0;
  39. $GLOBALS['playerid']++;
  40. $audioplayer = "
  41. <div style='clear: left; float: left; '>
  42. <script type='text/javaScript' src='".$cfg['full_uri']."/audio-player/audio-player/audio-player.js'></script>
  43. <object width='290' height='24' id='audioplayer".$GLOBALS['playerid']."' data='".$cfg['full_uri']."/audio-player/audio-player/player.swf' type='application/x-shockwave-flash'>
  44. <param value='".$cfg['full_uri']."/audio-player/audio-player/player.swf' name='movie' />
  45. <param value='playerID=".$GLOBALS['playerid']."&amp;soundFile=$fileurl' name='FlashVars' />
  46. <param value='high' name='quality' />
  47. <param value='false' name='menu' />
  48. <param value='transparent' name='wmode' />
  49. </object>
  50. </div>
  51. ";
  52. return $audioplayer;
  53. }
  54. }
  55. function printDownloadLink($mediaRow) {
  56. global $site,$section,$page,$uploaddir,$uploadurl, $cfg;
  57. $filename = urldecode($mediaRow[media_tag]);
  58. $filetype = ereg(".mp3", $filename);
  59. /* print $filename; */
  60. $dir = $mediaRow[slot_name];
  61. $size =$mediaRow[media_size];
  62. $fileurl = "$uploadurl/$dir/$filename";
  63. $filepath = "$uploaddir/$dir/$filename";
  64. $filesize = convertfilesize($size);
  65. //print "\n\t\t\t<table width='100%' cellpadding='0' cellspacing='0' style='margin: 0px; border: 0px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='leftmargin' align='left'>\n\t\t\t\t\t\t<a href='$fileurl' target='new_window'>\n\t\t\t\t\t\t\t<img src='downarrow.gif' border='0' width='15' height='15' align='middle' alt='Download Arrow' />\n\t\t\t\t\t\t\t $filename\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' style='padding-right: 10px;'><b>$filesize</b></td>\n\t\t\t\t</tr>\n\t\t\t</table>";
  66. $downloadlink = "\n\t\t\t<div style=' float: right; text-align: right;'>";
  67. $downloadlink .= "<span style='font-size: smaller;'>$filename</span><br />";
  68. $downloadlink .= "<a href='$fileurl' target='new_window'><img src='downarrow.gif' border='0' width='15' height='15' align='top' alt='Download Arrow' /></a> <a href='$fileurl' target='new_window'>Download</a>";
  69. $downloadlink .= " <span style='font-size: smaller;'>($filesize)</span></div>";
  70. return $downloadlink;
  71. }
  72. /**
  73. * Print a citation from a row of the media table
  74. *
  75. * @param array $mediaRow
  76. * @return <##>
  77. * @access public
  78. * @since 10/18/06
  79. */
  80. function printCitation ($mediaRow) {
  81. // Citation
  82. ob_start();
  83. if ($mediaRow['author'])
  84. print $mediaRow['author'].". ";
  85. if ($mediaRow['title_part'])
  86. print '"'.$mediaRow['title_part'].'"';
  87. if ($mediaRow['title_part'] && $mediaRow['title_whole'])
  88. print " ";
  89. else if ($mediaRow['title_part'])
  90. print ". ";
  91. if ($mediaRow['title_whole'])
  92. print '<em>'.$mediaRow['title_whole'].'</em>. ';
  93. if ($mediaRow['publisher'])
  94. print $mediaRow['publisher'];
  95. if ($mediaRow['publisher'] && $mediaRow['pubyear'])
  96. print ", ";
  97. else if ($mediaRow['publisher'])
  98. print ". ";
  99. if ($mediaRow['pubyear'])
  100. print $mediaRow['pubyear'].". ";
  101. if ($mediaRow['pagerange'])
  102. print "(".$mediaRow['pagerange'].") ";
  103. // if ($mediaRow['is_published'])
  104. // print " &copy; ";
  105. return trim(ob_get_clean());
  106. }
  107. function mkfilesize($filename) {
  108. $j = 0;
  109. $ext = array("B","KB","MB","GB","TB");
  110. // $filename = ereg_replace(" ","\\ ",$filename);
  111. // print "<br /><br />$filename<br /><br />";
  112. $file_size = filesize($filename);
  113. while ($file_size >= pow(1024,$j)) ++$j;
  114. $file_size = round($file_size / pow(1024,$j-1) * 100) / 100 . $ext[$j-1];
  115. return $file_size;
  116. }
  117. function convertfilesize($size) {
  118. $j = 0;
  119. $ext = array("B","KB","MB","GB","TB");
  120. while ($size >= pow(1024,$j)) ++$j;
  121. $size = round($size / pow(1024,$j-1) * 100) / 100 . $ext[$j-1];
  122. return $size;
  123. }
  124. function get_size($pic) {
  125. $imageInfo = GetImageSize($pic);
  126. $size[x]=$imageInfo[0];
  127. $size[y]=$imageInfo[1];
  128. return $size;
  129. }
  130. function get_sizes($pic,$maxsize) {
  131. //-----This function takes an image and a maximum dimension and returns scaled dimensions
  132. $imageInfo=getimagesize($pic);
  133. $iwidth=$imageInfo[0];
  134. $iheight=$imageInfo[1];
  135. if ($iwidth > $maxsize || $iheight > $maxsize) {
  136. $winX = $maxsize;
  137. $winY = $maxsize;
  138. if ($iwidth > $iheight) {
  139. $winY = $winX*$iheight/$iwidth;
  140. } else {
  141. $winX = $winY*$iwidth/$iheight;
  142. }
  143. } else {
  144. $winX = $iwidth;
  145. $winY = $iheight;
  146. }
  147. $size = array();
  148. $size['x'] = $winX;
  149. $size['y'] = $winY;
  150. return $size;
  151. }
  152. function copyuserfile($file,$site,$replace,$replace_id,$allreadyuploaded=0) {
  153. global $uploaddir;
  154. $sitename = $site;
  155. $query = "SELECT FK_site FROM slot WHERE slot_name='".addslashes($site)."'";
  156. $r = db_query($query);
  157. $a = db_fetch_assoc($r);
  158. $siteid = $a[FK_site];
  159. if (!$file[name]) {
  160. print "No File";
  161. return "ERROR";
  162. }
  163. $siteObj =& new site($site);
  164. $userdir = "$uploaddir/$site";
  165. $name = ereg_replace("[\x27\x22]",'',stripslashes(trim($file['name'])));
  166. $extn = explode(".",$name);
  167. $last = count($extn)-1;
  168. $extn = strtolower($extn[$last]);
  169. // print "$extn <br />";
  170. $image_extns = array(
  171. "jpeg",
  172. "jpg",
  173. "gif",
  174. "bmp",
  175. "png",
  176. "tiff"
  177. );
  178. if (in_array($extn, $image_extns)) $type = "image";
  179. else $type = "file";
  180. // print "$userdir/$file[name]<br />";
  181. if (!is_dir($userdir)) {
  182. mkdir($userdir,0700);
  183. chmod($userdir,0700);
  184. }
  185. if ($replace) {
  186. $unlink = unlink($userdir."/".$name);
  187. /* print "unlink: $unlink"; */
  188. }
  189. if (!is_writeable($userdir)) {
  190. print "<strong>Can not write to '".$userdir."'. <br />Please contact your system administrator with the message above to fix this problem.</strong> <br />";
  191. return "ERROR";
  192. }
  193. if (file_exists($userdir."/".$name) && !is_writeable($userdir."/".$name)) {
  194. print "<strong>Can not write to '".$userdir."/".$name."'. <br />Please contact your system administrator with the message above to fix this problem.</strong> <br />";
  195. return "ERROR";
  196. }
  197. if ($allreadyuploaded) {
  198. $r = copy($file[tmp_name],"$userdir/".$name);
  199. } else {
  200. /* print "move uploaded file ($file[tmp_name], $userdir/$file[name])<br />"; */
  201. $r=move_uploaded_file($file['tmp_name'],$userdir."/".$name);
  202. }
  203. if (!$r) {
  204. print "Upload file error!<br />";
  205. log_entry("media_error","File upload attempt by ".$_SESSION[auser]." in site $site failed.",$site,$siteid,"site");
  206. return "ERROR";
  207. } else if ($replace) {
  208. $size = filesize($userdir."/".$name);
  209. $query = "UPDATE media SET
  210. media_updated_tstamp=NOW(),
  211. FK_updatedby='".addslashes($_SESSION[aid])."',
  212. media_size='".addslashes($size)."',
  213. is_published ='". $file['is_published']."',
  214. title_whole ='". $file['title_whole']."',
  215. title_part ='". $file['title_part']."',
  216. author ='". $file['author']."',
  217. pagerange ='". $file['pagerange']."',
  218. publisher ='". $file['publisher']."',
  219. pubyear ='". $file['pubyear']."',
  220. isbn ='". $file['isbn']."'
  221. WHERE
  222. media_id='".addslashes($replace_id)."'
  223. ";
  224. /* print $query."<br />"; */
  225. db_query($query);
  226. print mysql_error()."<br />";
  227. $media_id = $replace_id;
  228. log_entry("media_upload","$_SESSION[auser] updated file: $name, id: $media_id, in site $site",$site,$siteid,"site");
  229. return $media_id;
  230. } else {
  231. $size = filesize($userdir."/".$name);
  232. $query = "INSERT INTO media SET
  233. media_tag='".addslashes($name)."',
  234. FK_site='".addslashes($siteid)."',
  235. FK_createdby='".addslashes($_SESSION[aid])."',
  236. FK_updatedby='".addslashes($_SESSION[aid])."',
  237. media_type='".addslashes($type)."',
  238. media_size='".addslashes($size)."',
  239. is_published ='". $file['is_published']."',
  240. title_whole ='". $file['title_whole']."',
  241. title_part ='". $file['title_part']."',
  242. author ='". $file['author']."',
  243. pagerange ='". $file['pagerange']."',
  244. publisher ='". $file['publisher']."',
  245. pubyear ='". $file['pubyear']."',
  246. isbn ='". $file['isbn']."'
  247. ";
  248. db_query($query);
  249. // print mysql_error()."<br />";
  250. $media_id = lastid();
  251. log_entry("media_upload","$_SESSION[auser] uploaded file: $name, id: $media_id, to site $site",$site,$siteid,"site");
  252. return $media_id;
  253. }
  254. }
  255. function copy_media($id,$newsitename) {
  256. global $uploaddir;
  257. $oldsitename = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site","slot_name","media_id='".addslashes($id)."'");
  258. $file_name = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site","media_tag","media_id='".addslashes($id)."'");
  259. $sourcedir = "$uploaddir/$oldsitename";
  260. $destdir = "$uploaddir/$newsitename";
  261. $old_file_path = $sourcedir."/".$file_name;
  262. $new_file_path = $destdir."/".$file_name;
  263. if (!is_dir($destdir)) {
  264. mkdir($destdir,0700);
  265. chmod($destdir,0700);
  266. }
  267. if (file_exists($new_file_path)) {
  268. $newid = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site","media_id","slot_name='".addslashes($newsitename)."' && media_tag='".addslashes($file_name)."'");
  269. } else {
  270. $query = "
  271. SELECT
  272. is_published,
  273. title_whole,
  274. title_part,
  275. author,
  276. pagerange,
  277. publisher,
  278. pubyear,
  279. isbn
  280. FROM
  281. media
  282. INNER JOIN
  283. slot
  284. ON media.FK_site = slot.FK_site
  285. INNER JOIN
  286. user
  287. ON media.FK_createdby = user_id
  288. WHERE
  289. media_id='".addslashes($id)."'
  290. ";
  291. // printpre($query);
  292. $r = db_query($query);
  293. $file = array();
  294. while ($a = db_fetch_assoc($r)) {
  295. $file['is_published'] = addslashes($a['is_published']);
  296. $file['title_whole'] = addslashes($a['title_whole']);
  297. $file['title_part'] = addslashes($a['title_part']);
  298. $file['author'] = addslashes($a['author']);
  299. $file['pagerange'] = addslashes($a['pagerange']);
  300. $file['publisher'] = addslashes($a['publisher']);
  301. $file['pubyear'] = addslashes($a['pubyear']);
  302. $file['isbn'] = addslashes($a['isbn']);
  303. }
  304. $file[name] = $file_name;
  305. $file[tmp_name] = $old_file_path;
  306. // print_r ($file);
  307. // print "<br />";
  308. $newid = copyuserfile($file,$newsitename,0,0,1);
  309. }
  310. return $newid;
  311. }
  312. function copy_media_with_fname($fname, $oldsitename, $newsitename) {
  313. $mediaid = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site","media_id","slot_name='".addslashes($oldsitename)."' AND media_tag='".addslashes($fname)."'");
  314. return copy_media($mediaid, $newsitename);
  315. }
  316. function deleteuserfile($fileid) {
  317. global $uploaddir, $site, $settings;
  318. $query = "
  319. SELECT
  320. *
  321. FROM
  322. media
  323. INNER JOIN
  324. slot
  325. ON
  326. media.FK_site = slot.FK_site
  327. WHERE
  328. media_id='".addslashes($fileid)."'
  329. ";
  330. $r = db_query($query);
  331. $a = db_fetch_assoc($r);
  332. $a[media_tag] = urldecode($a[media_tag]);
  333. $siteObj =& new site($a[slot_name]);
  334. $file_path = $uploaddir."/".$siteObj->getField("name")."/".$a[media_tag];
  335. // $file_path = "../segue_userfiles/afranco/close2.gif";
  336. // print "file = \"$file_path\" <br />";
  337. if (file_exists($file_path)) {
  338. // $exists = file_exists($file_path);
  339. // print "fileexists = $exists $file_path<br /> ";
  340. $success = unlink($file_path);
  341. // print "success = $success <br />";
  342. if ($success) {
  343. $query = "DELETE FROM media WHERE media_id='".addslashes($fileid)."' LIMIT 1";
  344. db_query($query);
  345. log_entry("media_delete","$_SESSION[auser] deleted file: ".$a[media_tag].", id: $fileid, from site ".$siteObj->getField("name"),$siteObj->name,$siteObj->id,"site");
  346. } else {
  347. log_entry("media_error","Delete failed of file: ".$a[media_tag].", id: $fileid, from site ".$siteObj->getField("name")." by ".$_SESSION[auser],$siteObj->name,$siteObj->id,"site");
  348. error("File could not be Deleted");
  349. }
  350. } else {
  351. log_entry("media_error","Delete failed of file: ".$a[media_tag].", id: $fileid, from site ".$siteObj->getField("name")." by ".$_SESSION[auser].". File does not exist. Removed entry.",$siteObj->name,$siteObj->id,"site");
  352. error("File does not exist. Its Entry was deleted");
  353. $query = "DELETE FROM media WHERE media_id='".addslashes($fileid)."' LIMIT 1";
  354. db_query($query);
  355. }
  356. }
  357. function deleteComplete($file) {
  358. // posted by georg@spieleflut.de on PHP.net 24-Dec-2001 10:28
  359. // This function will completely delete even a non-empty directory.
  360. global $uploaddir;
  361. $uploadDirs = array(
  362. $uploaddir,
  363. $uploaddir."/",
  364. $uploaddir."//",
  365. $uploaddir."///"
  366. );
  367. if (in_array($file, $uploadDirs)) return false;
  368. chmod($file,0777);
  369. if (is_dir($file)) {
  370. $handle = opendir($file);
  371. while($filename = readdir($handle)) {
  372. if ($filename != "." && $filename != "..") {
  373. deleteComplete($file."/".$filename);
  374. }
  375. }
  376. closedir($handle);
  377. rmdir($file);
  378. } else {
  379. unlink($file);
  380. }
  381. }
  382. function deletePath($path) {
  383. // posted by georg@spieleflut.de on PHP.net 24-Dec-2001 10:28
  384. // This function will completely delete even a non-empty directory.
  385. chmod($path,0777);
  386. if (is_dir($path)) {
  387. $handle = opendir($path);
  388. while($filename = readdir($handle)) {
  389. if ($filename != "." && $filename != "..") {
  390. deletePath($path."/".$filename);
  391. }
  392. }
  393. closedir($handle);
  394. rmdir($path);
  395. } else {
  396. unlink($path);
  397. }
  398. }
  399. function dir_copy ($from_path, $to_path)
  400. {
  401. // posted by dallask at sbcglobal dot net 21-Oct-2002 10:14
  402. // on PHP.net
  403. // Recursively copies a directory.
  404. $this_path = getcwd();
  405. if(!is_dir($to_path))
  406. { mkdir($to_path, 0775);
  407. }
  408. if (is_dir($from_path))
  409. {
  410. chdir($from_path);
  411. $handle=opendir('.');
  412. while (($file = readdir($handle))!==false)
  413. {
  414. if (($file != ".") && ($file != ".."))
  415. {
  416. if (is_dir($file))
  417. {
  418. chdir($this_path);
  419. dir_copy ($from_path.$file."/", $to_path.$file."/");
  420. chdir($this_path);
  421. chdir($from_path);
  422. }
  423. if (is_file($file))
  424. {
  425. chdir($this_path);
  426. copy($from_path.$file, $to_path.$file);
  427. chdir($from_path);
  428. }
  429. }
  430. }
  431. closedir($handle);
  432. }
  433. chdir($this_path);
  434. }
  435. function decode_array($string) {
  436. $array = array();
  437. if ($string) {
  438. $string = urldecode($string);
  439. $array = unserialize($string);
  440. }
  441. return $array;
  442. }
  443. function encode_array($array) {
  444. if (!$array || $array=='') return '';
  445. return urlencode(serialize($array));
  446. }
  447. // adds a link entry onto topnav, leftnav or rightnav
  448. function add_link($array,$name="",$url="",$extra='',$id=0,$target="_self",$type='normal',$content='') {
  449. global $$array;
  450. if ($type == "page" || $type == "link") {
  451. $type = 'normal';
  452. }
  453. array_push($$array,array("type"=>$type,"name"=>$name,"url"=>$url,"extra"=>$extra,"id"=>$id,"target"=>$target,"content"=>$content));
  454. // return $array;
  455. }
  456. // makelink($i,$samepage,$e)
  457. // $i = single entry of a navbar variable (made with add_link)
  458. // $samepage = are we on the page this link describes?
  459. // $e = extra HTML for the link
  460. // $bold = if on story detail then bold link
  461. function makelink($i,$samepage=0,$e='',$newline=0,$bold=0) {
  462. $s = '';
  463. $s=(!$samepage&&$i[url])?"<a href='$i[url]'".(($i['target'])?" target='$i[target]'":"").(($e)?" $e":"").">":"";
  464. if (!$bold) {
  465. $s.=$i[name];
  466. } else {
  467. $s.="<b>".$i[name]."</b>";
  468. }
  469. $s.=(!$samepage&&$i[url])?"</a>\n":"";
  470. $s.=($i[extra])?(($newline)?"<div class='nav_extras'>":" ").$i[extra].(($newline)?"</div>\n":""):"";
  471. return $s;
  472. }
  473. function printc($string) {
  474. global $content;
  475. // print "printc called...<br />";
  476. // $content .= $string . "\n";
  477. $content .= $string;
  478. }
  479. function preprintc($string) {
  480. global $content;
  481. $content = $string . $content;
  482. }
  483. function spchars($string) {
  484. return htmlspecialchars(stripslashes($string),ENT_QUOTES);
  485. }
  486. function log_entry($type,$content,$site=0,$siteunit=0,$siteunit_type="site") {
  487. global $dbhost, $dbuser,$dbpass, $dbdb;
  488. if ($site) {
  489. $query = "
  490. SELECT
  491. slot_id
  492. FROM
  493. slot
  494. WHERE
  495. slot_name = '".addslashes($site)."'
  496. ";
  497. $r = db_query($query);
  498. $a = db_fetch_assoc($r);
  499. $slot_id = "'".addslashes($a[slot_id])."'";
  500. } else {
  501. $slot_id = "NULL";
  502. }
  503. db_connect($dbhost,$dbuser,$dbpass, $dbdb);
  504. db_query("insert into log set
  505. log_type='".addslashes($type)."',
  506. log_desc='".addslashes($content)."',
  507. FK_luser='".addslashes($_SESSION[lid])."',
  508. FK_auser='".addslashes($_SESSION[aid])."',
  509. FK_slot=".$slot_id.",
  510. FK_siteunit='".addslashes($siteunit)."',
  511. log_siteunit_type='".addslashes($siteunit_type)."'
  512. ");
  513. }
  514. /******************************************************************************
  515. * Get all tags for a given site (or section or page...)
  516. ******************************************************************************/
  517. function get_tags($site,$section,$page, $record_type="story") {
  518. global $dbhost, $dbuser,$dbpass, $dbdb;
  519. $tags = array();
  520. // Validate that the record type is safe.
  521. if (!preg_match("/^[a-z]+$/i", $record_type))
  522. die("Invalid record type - line: ".__LINE__." in ".__FILE__);
  523. $record_type_id = $record_type."_id";
  524. if ($site && $record_type == "story") {
  525. $query = "
  526. SELECT
  527. DISTINCT record_tag
  528. FROM
  529. tags
  530. INNER JOIN
  531. $record_type
  532. ON FK_record_id = $record_type_id
  533. INNER JOIN
  534. page
  535. ON FK_page = page_id
  536. INNER JOIN
  537. section
  538. ON FK_section = section_id
  539. INNER JOIN
  540. site
  541. ON section.FK_site = site.site_id
  542. INNER JOIN
  543. slot
  544. ON site.site_id = slot.FK_site
  545. WHERE
  546. slot_name = '".addslashes($site)."'
  547. ORDER BY
  548. record_tag ASC
  549. ";
  550. $r = db_query($query);
  551. while ($a = db_fetch_assoc($r)) {
  552. $record_tag = $a[record_tag];
  553. $query2 = "
  554. SELECT
  555. COUNT(*) AS num_stories
  556. FROM
  557. tags
  558. INNER JOIN
  559. $record_type
  560. ON FK_record_id = $record_type_id
  561. INNER JOIN
  562. page
  563. ON FK_page = page_id
  564. INNER JOIN
  565. section
  566. ON FK_section = section_id
  567. INNER JOIN
  568. site
  569. ON section.FK_site = site.site_id
  570. INNER JOIN
  571. slot
  572. ON site.site_id = slot.FK_site
  573. WHERE
  574. slot_name = '".addslashes($site)."'
  575. AND
  576. record_tag = '".addslashes($record_tag)."'
  577. ";
  578. $r2 = db_query($query2);
  579. $a2 = db_fetch_assoc($r2);
  580. $tags[$a[record_tag]] = $a2[num_stories];
  581. }
  582. }
  583. // printpre($tags);
  584. // printpre($tags[tag]);
  585. //exit();
  586. return $tags;
  587. }
  588. /******************************************************************************
  589. * Gets all tags for a given record (story or discussion or...)
  590. ******************************************************************************/
  591. function get_record_tags($record_id) {
  592. global $dbhost, $dbuser,$dbpass, $dbdb;
  593. $tags = array();
  594. $query = "
  595. SELECT
  596. record_tag
  597. FROM
  598. tags
  599. WHERE
  600. FK_record_id = '".addslashes($record_id)."'
  601. ";
  602. $r = db_query($query);
  603. while ($a = db_fetch_assoc($r)) {
  604. $tags[]= $a[record_tag];
  605. }
  606. return $tags;
  607. }
  608. /******************************************************************************
  609. * Gets all tag information for a given record (story or discussion or...)
  610. ******************************************************************************/
  611. function get_record_tags_info($record_id) {
  612. global $dbhost, $dbuser,$dbpass, $dbdb;
  613. $tags = array();
  614. $query = "
  615. SELECT
  616. record_tag, user_uname, record_tag_added
  617. FROM
  618. tags
  619. INNER JOIN
  620. user
  621. ON FK_user_id = user_id
  622. WHERE
  623. FK_record_id = '".addslashes($record_id)."'
  624. ";
  625. $r = db_query($query);
  626. while ($a = db_fetch_assoc($r)) {
  627. $tags[$a[record_tag]][time_stamp] = $a[record_tag_added];
  628. $tags[$a[record_tag]][agent_id] = $a[user_uname];
  629. }
  630. return $tags;
  631. }
  632. /******************************************************************************
  633. * deletes all tags for a given record (story or discussion or...)
  634. ******************************************************************************/
  635. function delete_record_tags($site,$record_id,$record_type,$user_id='') {
  636. global $dbhost, $dbuser,$dbpass, $dbdb;
  637. if ($site && $record_id) {
  638. $query = "
  639. DELETE
  640. FROM
  641. tags
  642. WHERE
  643. FK_record_id = '".addslashes( $record_id)."'
  644. AND
  645. record_type = '".addslashes($record_type)."'
  646. ";
  647. $r = db_query($query);
  648. }
  649. }
  650. /******************************************************************************
  651. * saves all tags for a given record (story or discussion or...)
  652. * save_record_tags = urlencoded array of tags to save
  653. * delete_record_tags = urlencoded array of tags to delete
  654. * record_type = story or discussions or...
  655. * record_id = story_id or discussion_id or ...
  656. ******************************************************************************/
  657. function save_record_tags($save_record_tags,$delete_record_tags,$record_id,$user_id,$record_type) {
  658. global $dbhost, $dbuser,$dbpass, $dbdb;
  659. if ($record_id) {
  660. //check if record_tag to be saved already exists...
  661. if (is_array($save_record_tags)) {
  662. foreach ($save_record_tags as $record_tag) {
  663. $query = "
  664. SELECT
  665. record_tag
  666. FROM
  667. tags
  668. WHERE
  669. FK_record_id = '".addslashes($record_id)."'
  670. AND
  671. record_tag = '".addslashes($record_tag)."'
  672. ";
  673. $r = db_query($query);
  674. //printpre($query);
  675. //if record tag doesn't exist then add
  676. if (db_num_rows($r) == 0) {
  677. $query = "
  678. INSERT INTO
  679. tags
  680. SET
  681. record_type = '".addslashes($record_type)."',
  682. FK_record_id = '".addslashes($record_id)."',
  683. FK_user_id = '".addslashes($user_id)."',
  684. record_tag = '".addslashes($record_tag)."',
  685. record_tag_added = NOW();
  686. ";
  687. $r = db_query($query);
  688. }
  689. }
  690. }
  691. // printpre(count($delete_record_tags));
  692. // printpre(count($save_record_tags));
  693. //check again that record tag to be deleted exists
  694. if (is_array($delete_record_tags)) {
  695. foreach ($delete_record_tags as $record_tag) {
  696. $query = "
  697. SELECT
  698. record_tag
  699. FROM
  700. tags
  701. WHERE
  702. FK_record_id = '".addslashes($record_id)."'
  703. AND
  704. record_tag = '".addslashes($record_tag)."'
  705. ";
  706. $r = db_query($query);
  707. // if record tag does exist, then delete
  708. if (db_num_rows($r)) {
  709. $query = "
  710. DELETE FROM
  711. tags
  712. WHERE
  713. record_type = '".addslashes($record_type)."'
  714. AND
  715. FK_record_id = '".addslashes($record_id)."'
  716. AND
  717. FK_user_id = '".addslashes($user_id)."'
  718. AND
  719. record_tag = '".addslashes($record_tag)."'
  720. ";
  721. $r = db_query($query);
  722. }
  723. }
  724. }
  725. }
  726. }
  727. /******************************************************************************
  728. * Saves previous version to version table
  729. ******************************************************************************/
  730. function save_version ($version_short, $version_long, $story_id, $version_comments) {
  731. global $dbhost, $dbuser,$dbpass, $dbdb;
  732. // make sure number of versions is within limit
  733. // $num_versions = count(get_versions($story_id));
  734. // printpre($num_versions);
  735. //exit;
  736. // if ($num_versions > 30) {
  737. // $query = "
  738. // SELECT
  739. // version_order
  740. // FROM
  741. // version
  742. // WHERE
  743. // FK_parent = '".addslashes($story_id)."'
  744. // ORDER BY
  745. // version_created_tstamp ASC
  746. // LIMIT
  747. // 0,1
  748. // ";
  749. // $r = db_query($query);
  750. // $a = db_fetch_assoc($r);
  751. // $last_version_num = $a['version_order'];
  752. //
  753. // $query = "
  754. // DELETE FROM
  755. // version
  756. // WHERE
  757. // FK_parent = '".addslashes($story_id)."'
  758. // AND
  759. // version_order = '".addslashes($last_version_num)."'
  760. // ";
  761. //
  762. // $r = db_query($query);
  763. // }
  764. // get the last version number
  765. $query = "
  766. SELECT
  767. version_order, version_text_short, version_text_long
  768. FROM
  769. version
  770. WHERE
  771. FK_parent = '".addslashes($story_id)."'
  772. ORDER BY
  773. version_order DESC
  774. LIMIT
  775. 0,1
  776. ";
  777. $r = db_query($query);
  778. $a = db_fetch_assoc($r);
  779. $last_version_num = $a['version_order'];
  780. $last_version_text_short = urldecode($a['version_text_short']);
  781. $last_version_text_long = urldecode($a['version_text_long']);
  782. // printpre(htmlspecialchars($last_version_text_short));
  783. // printpre(htmlspecialchars($version_short));
  784. // printpre("versioncommment: ".$version_comments);
  785. // exit;
  786. $version_number = $last_version_num + 1;
  787. $lastLines = explode("\n", $last_version_text_short);
  788. $newLines = explode("\n", $version_short);
  789. for ($i =0; $i < max(count($newLines), count($lastLines)); $i++) {
  790. if ($lastLines[$i] != $newLines[$i]) {
  791. // printpre("<strong>Lines $i are not equal:</strong>");
  792. // printpre("Old: ".htmlspecialchars($lastLines[$i]));
  793. // printpre("New: ".htmlspecialchars($newLines[$i]));
  794. }
  795. }
  796. // add previous version to the version table
  797. if ($last_version_text_short != $version_short) {
  798. $query = "
  799. INSERT INTO
  800. version
  801. SET
  802. FK_parent = '".addslashes($story_id)."',
  803. FK_createdby ='".addslashes($_SESSION[aid])."',
  804. version_order = '".addslashes($version_number)."',
  805. version_created_tstamp = NOW(),
  806. version_text_short = '".addslashes(urlencode($version_short))."',
  807. version_text_long = '".addslashes(urlencode($version_long))."',
  808. version_comments = '".addslashes($version_comments)."'
  809. ";
  810. $r = db_query($query);
  811. // update story table with new version
  812. $query = "
  813. UPDATE
  814. story
  815. SET
  816. FK_updatedby ='".addslashes($_SESSION[aid])."',
  817. story_updated_tstamp = NOW(),
  818. story_text_short = '".addslashes(urlencode($version_short))."',
  819. story_text_long = '".addslashes(urlencode($version_long))."'
  820. WHERE
  821. story_id = '".addslashes($story_id)."'
  822. ";
  823. $r = db_query($query);
  824. }
  825. }
  826. /******************************************************************************
  827. * Gets previous version(s) and returns a list
  828. * if no version_id is passed then gets all versions
  829. ******************************************************************************/
  830. function get_versions ($story_id, $version_num = 0) {
  831. global $dbhost, $dbuser,$dbpass, $dbdb;
  832. $versions = array();
  833. if ($version_num == 0) {
  834. $where = "FK_parent = '".addslashes($story_id)."'";
  835. } else {
  836. $where = "
  837. FK_parent = '".addslashes($story_id)."'
  838. AND
  839. version_order = '".addslashes($version_num)."'
  840. ";
  841. }
  842. $query = "
  843. SELECT
  844. *
  845. FROM
  846. version
  847. WHERE
  848. $where
  849. ORDER BY
  850. version_created_tstamp DESC
  851. ";
  852. // printpre($query);
  853. //exit;
  854. $r = db_query($query);
  855. while ($a = db_fetch_assoc($r)) {
  856. $version_author = $a[FK_createdby];
  857. $version_authorname = db_get_value("user", "user_fname", "user_id = '".addslashes($version_author)."'");
  858. $version_created = timestamp2usdate($a[version_created_tstamp]);
  859. $version[FK_createdby]= $version_authorname;
  860. $version[version_order]= $a[version_order];
  861. $version[version_created_tstamp]= $version_created;
  862. $version[version_text_short]= $a[version_text_short];
  863. $version[version_text_long]= $a[version_text_long];
  864. $version[version_comments]= $a[version_comments];
  865. $version[version_id]= $a[version_id];
  866. // New for export:
  867. $version['author_uname'] = trim(db_get_value("user", "user_uname", "user_id = '".addslashes($version_author)."'"));
  868. $version['create_time_stamp'] = $a['version_created_tstamp'];
  869. $versions[] = $version;
  870. }
  871. return $versions;
  872. }
  873. /******************************************************************************
  874. * Get all records with a given tag
  875. * returns array with story, page and section ids
  876. ******************************************************************************/
  877. function get_tagged_stories ($site,$section,$page,$tag,$record_type="story") {
  878. global $dbhost, $dbuser,$dbpass, $dbdb;
  879. $tagged_stories = array();
  880. $story_id = array();
  881. $page_id = array();
  882. $section_id = array();
  883. // Validate that the record type is safe.
  884. if (!preg_match("/^[a-z]+$/i", $record_type))
  885. die("Invalid record type - line: ".__LINE__." in ".__FILE__);
  886. $record_type_id = $record_type."_id";
  887. if ($site) {
  888. $query = "
  889. SELECT
  890. story_id, page_id, section_id
  891. FROM
  892. tags
  893. INNER JOIN
  894. $record_type
  895. ON FK_record_id = $record_type_id
  896. INNER JOIN
  897. page
  898. ON FK_page = page_id
  899. INNER JOIN
  900. section
  901. ON FK_section = section_id
  902. INNER JOIN
  903. site
  904. ON section.FK_site = site.site_id
  905. INNER JOIN
  906. slot
  907. ON site.site_id = slot.FK_site
  908. WHERE
  909. slot_name = '".addslashes($site)."'
  910. AND
  911. record_tag = '".addslashes($tag)."'
  912. ORDER BY
  913. record_tag_added DESC
  914. ";
  915. // printpre($query);
  916. $r = db_query($query);
  917. while ($a = db_fetch_assoc($r)) {
  918. $tagged_stories[story_id][]= $a[story_id];
  919. $tagged_stories[page_id][]= $a[page_id];
  920. $tagged_stories[section_id][]= $a[section_id];
  921. }
  922. }
  923. return $tagged_stories;
  924. }
  925. function htmlbr($string) {
  926. // It seems that Safari (at least) submits line returns that are \r\n instead
  927. // of just \n. This was causing a doubling of line-returns.
  928. return preg_replace("/((\r?)\n(\r?))/","<br />",$string);
  929. }
  930. function sitenamevalid($name) {
  931. /******************************************************************************
  932. * sitenamevalid checks to see if $name has a value
  933. * it is possible for $name to become null and a no name site to be created
  934. * when a user creates a site and then immediately uses the browser back
  935. * to tweak the appearance...
  936. ******************************************************************************/
  937. if ($name =='') {
  938. return 0;
  939. } else {
  940. return 1;
  941. }
  942. }
  943. function insite($site,$section,$page=0,$story=0) {
  944. $ok=1;
  945. if (!in_array($section,decode_array(db_get_value("sites","sections","name='".addslashes($site)."'")))) $ok=0;
  946. if ($page && !in_array($page,decode_array(db_get_value("sections","pages","id='".addslashes($section)."'")))) $ok=0;
  947. if ($story && !in_array($story,decode_array(db_get_value("pages","stories","id='".addslashes($page)."'")))) $ok=0;
  948. return $ok;
  949. }
  950. $_isgroup_cache = array();
  951. function isgroup ($group) {
  952. global $_isgroup_cache;
  953. if (isset($_isgroup_cache[$group]))
  954. return $_isgroup_cache[$group];
  955. $query = "SELECT class_id FROM class INNER JOIN classgroup ON FK_classgroup = classgroup_id WHERE classgroup_name='".addslashes($group)."'";
  956. $r = db_query($query);
  957. if (db_num_rows($r)) {
  958. $temp_c = array();
  959. while ($a = db_fetch_assoc($r)) {
  960. $temp_c[] = generateCourseCode($a[class_id]);
  961. }
  962. $_isgroup_cache[$group] = true;
  963. return $temp_c;
  964. }
  965. $_isgroup_cache[$group] = false;
  966. return 0;
  967. }
  968. /**
  969. * Return the current semester,
  970. *
  971. * @return string, the semester key of the current semester.
  972. * @access public
  973. * @date 9/7/04
  974. */
  975. function currentsemester () {
  976. global $cfg;
  977. $currDay = date("z");
  978. foreach (array_keys($cfg['semesters']) as $semesterKey) {
  979. $startDay = date("z",
  980. strtotime(
  981. $cfg['semesters'][$semesterKey]['start_month']
  982. ."/".$cfg['semesters'][$semesterKey]['start_day']
  983. )
  984. );
  985. $endDay = date("z",
  986. strtotime(
  987. $cfg['semesters'][$semesterKey]['end_month']
  988. ."/".$cfg['semesters'][$semesterKey]['end_day']
  989. )
  990. );
  991. // Process if the semester doesn't go across the new year
  992. if (($endDay - $startDay) >= 0) {
  993. if ($currDay >= $startDay && $currDay <= $endDay)
  994. return $semesterKey;
  995. }
  996. // Process if the semester goes accross the new year
  997. else {
  998. if ($currDay >= $startDay || $currDay <= $endDay)
  999. return $semesterKey;
  1000. }
  1001. }
  1002. return $semester;
  1003. }
  1004. /**
  1005. * The semorder function returns what order througout the calender year the
  1006. * semesters occur, this information can then be used to determine if
  1007. * a semester has yet to occur
  1008. *
  1009. * @param string $semester
  1010. * @return integer, the order of the semester
  1011. * @access public
  1012. * @date 9/8/04
  1013. */
  1014. function semorder($semester) {
  1015. global $cfg;
  1016. $order = 1;
  1017. foreach (array_keys($cfg['semesters']) as $semesterKey) {
  1018. if ($semester == $semesterKey) {
  1019. return $order;
  1020. } else
  1021. $order++;
  1022. }
  1023. printerr("Semester, '$semester', is not specified in the config.");
  1024. }
  1025. function inclassgroup($class) {
  1026. $query = "
  1027. SELECT
  1028. classgroup_name
  1029. FROM
  1030. classgroup
  1031. INNER JOIN
  1032. class ON classgroup_id = FK_classgroup AND ".addslashes(generateTermsFromCode($class))."
  1033. ";
  1034. $r = db_query($query);
  1035. if (db_num_rows($r)) {
  1036. $a = db_fetch_assoc($r);
  1037. return $a[classgroup_name];
  1038. }
  1039. return 0;
  1040. }
  1041. /**
  1042. * Determin if the semester and year specified are the current one
  1043. *
  1044. * @param string $semester The semester in question.
  1045. * @param integer $year The year of the semester in question.
  1046. * @return boolean
  1047. * @access public
  1048. * @date 9/9/04
  1049. */
  1050. function isSemesterNow ($semester, $year) {
  1051. global $cfg;
  1052. // If we aren't in the semester that is specified, don't bother
  1053. // checking the year.
  1054. if ($semester != currentSemester()) {
  1055. return FALSE;
  1056. }
  1057. // Make sure we have a 4-digit year.
  1058. if (strlen($year) == 2) {
  1059. $year = $year + 2000;
  1060. }
  1061. // We are good if we are in the same year as asked for.
  1062. if (date("Y") == $year) {
  1063. return TRUE;
  1064. }
  1065. // If we aren't in the same year, then we need to check if we are in a
  1066. // year beyond the specified one if the semester in question spans the
  1067. // NewYear.
  1068. $startDay = date("z",
  1069. strtotime(
  1070. $cfg['semesters'][$semester]['start_month']
  1071. ."/".$cfg['semesters'][$semester]['start_day']
  1072. )
  1073. );
  1074. $endDay = date("z",
  1075. strtotime(
  1076. $cfg['semesters'][$semester]['end_month']
  1077. ."/".$cfg['semesters'][$semester]['end_day']
  1078. )
  1079. );
  1080. // If the semester in question doesn't go across the new year,
  1081. // then we are definately not in it. since we checked before
  1082. // if our year was the same as the semester in question.
  1083. if (($endDay - $startDay) >= 0) {
  1084. return FALSE;
  1085. }
  1086. // If the semester in question goes accross the new year,
  1087. // make sure that we are just a year beyond the specified
  1088. // semester and still before the end day of the semester.
  1089. else {
  1090. if (date("Y") == ($year+1) && date("z") <= $endDay)
  1091. return TRUE;
  1092. else
  1093. return FALSE;
  1094. }
  1095. }
  1096. /**
  1097. * Determin if the semester and year specified are in the past
  1098. *
  1099. * @param string $semester The semester in question.
  1100. * @param integer $year The year of the semester in question.
  1101. * @return boolean
  1102. * @access public
  1103. * @date 9/9/04
  1104. */
  1105. function isSemesterPast ($semester, $year) {
  1106. global $cfg;
  1107. // If we are in the semester that is specified, don't bother
  1108. // continuing. Since we aren't past yet.
  1109. if (isSemesterNow($semester, $year)) {
  1110. return FALSE;
  1111. }
  1112. // Make sure we have a 4-digit year.
  1113. if (strlen($year) == 2) {
  1114. $year = $year + 2000;
  1115. }
  1116. // If our year is greater than the current one, then we definately
  1117. // aren't past yet.
  1118. if ($year > date("Y"))
  1119. return FALSE;
  1120. // If our year is less than the current one, then we definately
  1121. // are past.
  1122. if ($year < date("Y"))
  1123. return TRUE;
  1124. // If we are in the same year, then we need to check if we are before or
  1125. // after the semester in question.
  1126. $currDay = date("z");
  1127. $startDay = date("z",
  1128. strtotime(
  1129. $cfg['semesters'][$semester]['start_month']
  1130. ."/".$cfg['semesters'][$semester]['start_day']
  1131. )
  1132. );
  1133. // If our day of the year is after the start of the semester
  1134. // (and we've already checked that we are not in this semester),
  1135. // then the semester is past. Otherwise it is future.
  1136. if ($currDay > $startDay)
  1137. return TRUE;
  1138. else
  1139. return FALSE;
  1140. }
  1141. /**
  1142. * Determin if the semester and year specified are in the future
  1143. *
  1144. * @param string $semester The semester in question.
  1145. * @param integer $year The year of the semester in question.
  1146. * @return boolean
  1147. * @access public
  1148. * @date 9/9/04
  1149. */
  1150. function isSemesterFuture ($semester, $year) {
  1151. // If we are in the semester that is specified or it is past, don't bother
  1152. // continuing.
  1153. if (isSemesterNow($semester, $year) || isSemesterPast($semester, $year)) {
  1154. return FALSE;
  1155. }
  1156. // If the semester in question is not the current one or in the past,
  1157. // then it must be in the future.
  1158. else {
  1159. return TRUE;
  1160. }
  1161. }
  1162. /******************************************************************************
  1163. * canview - to be phased out by $obj->canview($user)
  1164. ******************************************************************************/
  1165. function canview($a,$type=SITE) {
  1166. // if (!$a[type]=='page'&&!$a[type]=='section'&&!$a[theme]) return 0;
  1167. if ($a[type] == 'heading' || $a[type] == 'divider') return 1;
  1168. if ($type == SITE || $type == SECTION || $type==PAGE) {
  1169. if (!$a[active]) return 0;
  1170. }
  1171. if (!indaterange($a[activatedate],$a[deactivatedate])) return 0;
  1172. return 1;
  1173. }
  1174. /******************************************************************************
  1175. * the reorder function -- recieves an array, id and a direction... and then returns the new array
  1176. ******************************************************************************/
  1177. function reorder($array,$id,$d) {
  1178. $num = count($array)-1;
  1179. for ($i=0; $i<=$num; $i++) {
  1180. if ($array[$i] == $id) {
  1181. if ($d == 'down') {
  1182. if ($i != $num) {
  1183. $array[$i]=$array[$i+1];
  1184. $array[$i+1]=$id;
  1185. break;
  1186. }
  1187. }
  1188. if ($d == 'up') {
  1189. if ($i != 0) {
  1190. $array[$i]=$array[$i-1];
  1191. $array[$i-1] = $id;
  1192. break;
  1193. }
  1194. }
  1195. }
  1196. }
  1197. return $array;
  1198. }
  1199. function handlearchive($stories,$pa) {
  1200. global $startday,$startmonth,$startyear,$endday,$endmonth,$endyear,$usestart,$useend,$months;
  1201. global $usesearch;
  1202. global $site,$section,$page;
  1203. $newstories = array();
  1204. if (!$usesearch) {
  1205. $endyear = date("Y");
  1206. $endmonth = date("n");
  1207. $endday = date("j");
  1208. }
  1209. printc("<div>");
  1210. // printc("<b>Search:</b> ");
  1211. printc("Display content in date rage: ");
  1212. printc("<form action='$PHP_SELF?$sid&amp;action=site&amp;site=$site&amp;section=$section&amp;page=$page' method='post'>");
  1213. printc("<input type='hidden' name='usesearch' value='1' />");
  1214. printc("<select name='startday'>");
  1215. for ($i=1;$i<=31;$i++) {
  1216. printc("<option" . (($startday == $i)?" selected":"") . ">$i\n");
  1217. }
  1218. printc("</select>\n");
  1219. printc("<select name='startmonth'>");
  1220. for ($i=0; $i<12; $i++)
  1221. printc("<option value=".($i+1). (($startmonth == $i+1)?" selected":"") . ">$months[$i]\n");
  1222. printc("</select>\n<select name='startyear'>");
  1223. $curryear = date("Y");
  1224. for ($i=$curryear-10; $i <= ($curryear); $i++) {
  1225. printc("<option" . (($startyear == $i)?" selected":"") . ">$i\n");
  1226. }
  1227. printc("</select>");
  1228. // printc("<br />");
  1229. printc(" to <select name='endday'>");
  1230. for ($i=1;$i<=31;$i++) {
  1231. printc("<option" . (($endday == $i)?" selected":"") . ">$i\n");
  1232. }
  1233. printc("</select>\n");
  1234. printc("<select name='endmonth'>");
  1235. for ($i=0; $i<12; $i++) {
  1236. printc("<option value=".($i+1) . (($endmonth == $i+1)?" selected":"") . ">$months[$i]\n");
  1237. }
  1238. printc("</select>\n<select name='endyear'>");
  1239. for ($i=$curryear; $i <= ($curryear+5); $i++) {
  1240. printc("<option" . (($endyear == $i)?" selected":"") . ">$i\n");
  1241. }
  1242. printc("</select>");
  1243. printc(" <input type='submit' class='button' value='go' />");
  1244. printc("</form></div>");
  1245. $start = mktime(1,1,1,$startmonth,$startday,$startyear);
  1246. $end = mktime(1,1,1,$endmonth,$endday,$endyear);
  1247. if ($pa == 'week') {
  1248. if (!$usesearch) {
  1249. $start = mktime(0,0,0,date("n"),date('j')-7,date('Y'));
  1250. $end = time();
  1251. }
  1252. }
  1253. if ($pa == 'month') {
  1254. if (!$usesearch) {
  1255. $start = mktime(0,0,0,date("n")-1,date('j'),date("Y"));
  1256. $end = time();
  1257. }
  1258. }
  1259. if ($pa == 'year') {
  1260. if (!$usesearch) {
  1261. $start = mktime(0,0,0,date("n"),date('j'),date("Y")-1);
  1262. $end = time();
  1263. }
  1264. }
  1265. $txtstart = date("n/j/y",$start);
  1266. $txtend = date("n/j/y",$end);
  1267. foreach ($stories as $s) {
  1268. $a = db_get_line("stories","id='".addslashes($s)."'");
  1269. $added = $a[addedtimestamp];
  1270. ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$added,$regs);
  1271. $year = (integer)$regs[1];
  1272. $month = (integer)$regs[2];
  1273. $day = (integer)$regs[3];
  1274. $t = mktime(0,0,0,$month,$day,$year);
  1275. // $week = date("W",$t-(date("w",$t)*86400));
  1276. //
  1277. // if ($startyear == $year && $startweek == $week)
  1278. // $newstories[] = $s;
  1279. // if ((!$usestart || $start < $t) && (!$useend || $t < $end)) {
  1280. if (($start < $t) && ($t < $end) || false) {
  1281. $newstories[$s] = $t;
  1282. }
  1283. }
  1284. // print_r($newstories);
  1285. arsort($newstories,SORT_NUMERIC);
  1286. // print_r($newstories);
  1287. $newstories = array_keys($newstories);
  1288. printc("<b>Content ranging from $txtstart to $txtend.</b><br /><br />");
  1289. return $newstories;
  1290. }
  1291. function handlestoryorder($stories,$order) {
  1292. // reorders the stories array passed to it depending on the order specified.
  1293. // Orders: addedesc, addedasc, editeddesc, editedasc, author, editor, category, titledesc, titleasc
  1294. return $stories;
  1295. }
  1296. function printpre($array, $return=FALSE) {
  1297. ob_start();
  1298. print "\n<pre>";
  1299. print_r($array);
  1300. print "\n</pre>";
  1301. if ($return)
  1302. return ob_get_clean();
  1303. else
  1304. ob_end_flush();
  1305. }
  1306. /**
  1307. * Var dump a variable inside of <pre> tags.
  1308. *
  1309. * @param <##>
  1310. * @return <##>
  1311. * @access public
  1312. * @since 10/24/06
  1313. */
  1314. function var_dumpPre($array, $return=FALSE) {
  1315. ob_start();
  1316. print "\n<pre>";
  1317. var_dump($array);
  1318. print "\n</pre>";
  1319. if ($return)
  1320. return ob_get_clean();
  1321. else
  1322. ob_end_flush();
  1323. }
  1324. /**
  1325. * print a string outside of any output buffers
  1326. *
  1327. * @param string $string
  1328. * @return void
  1329. * @access public
  1330. * @since 10/24/06
  1331. */
  1332. function printOb0 ($string) {
  1333. // move the output buffers out of the way
  1334. $outputBuffers = array();
  1335. $level = ob_get_level();
  1336. while ($level > 0) {
  1337. $outputBuffers[$level] = ob_get_clean();
  1338. $level = ob_get_level();
  1339. }
  1340. // Print out the string
  1341. print $string;
  1342. flush();
  1343. // rebuild the output buffers
  1344. ksort($outputBuffers);
  1345. foreach ($outputBuffers as $level => $data) {
  1346. ob_start();
  1347. print $data;
  1348. unset($outputBuffers[$level]);
  1349. }
  1350. }
  1351. function _error_handler($num, $str, $file, $line, $context) {
  1352. if ($num & E_NOTICE) return;
  1353. print "ERROR! ($num) $str<br/>";
  1354. print "in $file:$line --> ";
  1355. var_dump($context);
  1356. print "<p>";
  1357. printpre(print_r(debug_backtrace(),true));
  1358. }
  1359. //set_error_handler("_error_handler");
  1360. /**
  1361. * Order an array of classes. The input array should contain elements
  1362. * which are arrays containing the following fields: sem, year, code
  1363. *
  1364. * @param array $classes The classes array to sort
  1365. * @param optional const $direction One of the directions to pass to array_multisort().
  1366. * @return array The sorted array of classes
  1367. * @access public
  1368. * @date 9/9/04
  1369. */
  1370. function sortClasses ( $classes, $direction=SORT_DESC) {
  1371. global $cfg;
  1372. $years = array();
  1373. $semesterOrder = array_keys($cfg['semesters']);
  1374. $semesters = array();
  1375. $codes = array();
  1376. $sections = array();
  1377. foreach($classes as $key => $class) {
  1378. // get the year-classkey relation.
  1379. if ($class['year'] < 100)
  1380. $years[$key] = '20'.$class['year'];
  1381. else
  1382. $years[$key] = $class['year'];
  1383. // get the semesterorder-classkey relation
  1384. $semesters[$key] = array_search($class['sem'], $semesterOrder);
  1385. // get the code-classkey relation.
  1386. $codes[$key] = $class['code'];
  1387. $sections[$key] = $class['sect'];
  1388. }
  1389. // print "<hr />";
  1390. // printpre($classes);
  1391. // printpre($years);
  1392. // printpre($semesters);
  1393. // printpre($codes);
  1394. array_multisort($years, $direction, SORT_NUMERIC, $semesters, $direction, SORT_NUMERIC, $codes, SORT_ASC, SORT_STRING, $sections, SORT_ASC, SORT_STRING, $classes);
  1395. // printpre($classes);
  1396. return $classes;
  1397. }
  1398. /**
  1399. * Convert all the links in $sitename that point to other parts of this segue site, or
  1400. * to this site's media, to placeholder tags for storage. This allows those
  1401. * tags to still be valid if the segue server url changes.
  1402. *
  1403. * @param string $sitename The site search for links.
  1404. * @return void
  1405. * @access public
  1406. * @date 9/15/04
  1407. */
  1408. function convertAllInteralLinksToTags ($sitename) {
  1409. global $cfg;
  1410. if (!$sitename)
  1411. printError("convertInteralLinksToTags: no sitename passed!");
  1412. $site =& new site ($sitename);
  1413. $site->fetchSiteAtOnceForeverAndEverAndDontForgetThePermissionsAsWell_Amen();
  1414. // Start with the site level text
  1415. $site->setField("header",
  1416. convertInteralLinksToTags($sitename, $site->getField('header')));
  1417. $site->setField("footer",
  1418. convertInteralLinksToTags($sitename, $site->getField('footer')));
  1419. // Do the sections
  1420. foreach (array_keys($site->sections) as $sectionId) {
  1421. $section =& $site->sections[$sectionId];
  1422. $section->setField("url",
  1423. convertInteralLinksToTags($sitename, $section->getField('url')));
  1424. // Do the Pages
  1425. foreach (array_keys($section->pages) as $pageId) {
  1426. $page =& $section->pages[$pageId];
  1427. $page->setField("url",
  1428. convertInteralLinksToTags($sitename, $page->getField('url')));
  1429. // Do the Stories
  1430. foreach (array_keys($page->stories) as $storyId) {
  1431. $story =& $page->stories[$storyId];
  1432. $story->setField("url",
  1433. convertInteralLinksToTags($sitename, $story->getField('url')));
  1434. $story->setField("shorttext",
  1435. convertInteralLinksToTags($sitename, $story->getField('shorttext')));
  1436. $story->setField("longertext",
  1437. convertInteralLinksToTags($sitename, $story->getField('longertext')));
  1438. }
  1439. }
  1440. }
  1441. $site->updatedb(1,1,1);
  1442. }
  1443. /******************************************************************************
  1444. * Gets pages titles
  1445. * @param string $section the id of section with pages.
  1446. * return array of page titles
  1447. ******************************************************************************/
  1448. function getPageTitles ($section) {
  1449. $page_titles = array();
  1450. $query = "
  1451. SELECT
  1452. page_title, page_id
  1453. FROM
  1454. page
  1455. WHERE
  1456. FK_section ='".addslashes($section)."'
  1457. ";
  1458. $r = db_query($query);
  1459. while ($a = db_fetch_assoc($r)) {
  1460. $page_titles[$a[page_title]] = $a[page_id];
  1461. }
  1462. return $page_titles;
  1463. }
  1464. function getLinkingPages($site, $section, $page) {
  1465. global $cfg;
  1466. $links = array();
  1467. $query = "
  1468. SELECT
  1469. source_id, source_type
  1470. FROM
  1471. links
  1472. WHERE
  1473. target_id ='".addslashes($page)."'
  1474. AND
  1475. target_type = 'page'
  1476. ";
  1477. //printpre($query);
  1478. //exit;
  1479. $r = db_query($query);
  1480. while ($a = db_fetch_assoc($r)) {
  1481. $linkingpage = $a['source_id'];
  1482. $linkingpagetitle = db_get_value("page", "page_title", "page_id=".$linkingpage);
  1483. if ($linkingpagetitle) {
  1484. $linkingsection = db_get_value("page", "FK_section", "page_id=".$linkingpage);
  1485. $linkingsite = db_get_value("section", "FK_site", "section_id=".$linkingsection);
  1486. $linkingsite = db_get_value("slot", "slot_name", "FK_site=".$linkingsite);
  1487. $links[$linkingpagetitle] = $cfg['full_uri']."/index.php?action=site"."&site=".$linkingsite."&section=".$linkingsection."&page=".$a['source_id'];
  1488. }
  1489. }
  1490. // printpre($links);
  1491. return $links;
  1492. //exit;
  1493. }
  1494. /**
  1495. * Convert links in $text that point to other parts of this segue site, or
  1496. * to this site's media, to placeholder tags for storage. This allows those
  1497. * tags to still be valid if the segue server url changes.
  1498. *
  1499. * @param string $text The text to parse for links.
  1500. * @return string The text with links converted to tags.
  1501. * @access public
  1502. * @date 9/15/04
  1503. */
  1504. function convertInteralLinksToTags ($sitename, $text) {
  1505. global $cfg;
  1506. if (!$sitename)
  1507. printError("convertInteralLinksToTags: no sitename passed!");
  1508. $patterns = array();
  1509. $replacements = array();
  1510. // get https and http versions of urls
  1511. if (ereg("https", $cfg['full_uri'])) {
  1512. $alternative_full_uri = ereg_replace("https", "http", $cfg['full_uri']);
  1513. } else {
  1514. $alternative_full_uri = ereg_replace("http", "https", $cfg['full_uri']);
  1515. }
  1516. if (ereg("https", $cfg['personalsitesurl'])) {
  1517. $alternative_personalsitesurl = ereg_replace("https", "http", $cfg['personalsitesurl']);
  1518. } else {
  1519. $alternative_personalsitesurl = ereg_replace("http", "https", $cfg['personalsitesurl']);
  1520. }
  1521. if (ereg("https", $cfg['classsitesurl'])) {
  1522. $alternative_classsitesurl = ereg_replace("https", "http", $cfg['classsitesurl']);
  1523. } else {
  1524. $alternative_classsitesurl = ereg_replace("http", "https", $cfg['classsitesurl']);
  1525. }
  1526. // printpre (htmlentities($text));
  1527. //check for missing index.php and add in
  1528. $text = str_replace('\[\[linkpath\]\]/?', '\[\[linkpath\]\]/index.php?', $text);
  1529. // replace internal link urls with constant [[linkpath]]
  1530. $patterns[] = $cfg['full_uri'];
  1531. $replacements[] = "\[\[linkpath\]\]";
  1532. $patterns[] = $alternative_full_uri;
  1533. $replacements[] = "\[\[linkpath\]\]";
  1534. if ($cfg['personalsitesurl']) {
  1535. $patterns[] = $cfg['personalsitesurl'];
  1536. $replacements[] = "\[\[linkpath\]\]";
  1537. $patterns[] = $alternative_personalsitesurl;
  1538. $replacements[] = "\[\[linkpath\]\]";
  1539. }
  1540. if ($cfg['classsitesurl']) {
  1541. $patterns[] = $cfg['classsitesurl'];
  1542. $replacements[] = "\[\[linkpath\]\]";
  1543. $patterns[] = $alternative_classsitesurl;
  1544. $replacements[] = "\[\[linkpath\]\]";
  1545. }
  1546. //look for <a href="index.php and replace with <a href="[[linkpath]]/index.php
  1547. $patterns[] = 'href=(["\'])index.php';
  1548. $replacements[] = 'href=\1\[\[linkpath\]\]/index.php';
  1549. // replace specific site reference with general
  1550. $patterns[] = "site=".$sitename;
  1551. $replacements[] = "site=\[\[site\]\]";
  1552. // replace intern…

Large files files are truncated, but you can click here to view the full file