Return to Snippet

Revision: 30583
at August 17, 2010 22:21 by microbians


Updated Code
/*
mysql_fetch_alias_array:

is a function by Mehdi Haresi that get's de mysql entry and format into an array, to handle more like objects

isTypeOfPage:

Check if current page is a type of page

projectsList:

This function by default get the projects list of last 6 by date but you can change parameters and paint the projects using the $template. A template is a regular php file, with html extension if you like, that renders the variables this functions get from database. The template file must be inside the theme folder inside a folder named "templates". And example of a template can be "projects_thumb.html" that is like that:

-------------------------------------------------------------------
	<li class="thumb">
		<a rel="content" href="<?php echo $project['projects.url']; ?>">
			<img src="<?php echo $project['projects.thumbnail']; ?>" width="<?php echo $project['projects.thumbnail.width']; ?>" height="<?php echo $project['projects.thumbnail.height']; ?>"/>
			<div class="cover">
				<div class="info">
					<span class="section"><?php echo $project['projects.sectionname']; ?></span>
					<div style="clear: both;"></div>
					<span class="titleproject"><?php echo $project['projects.title']; ?></span>
				</div>
			</div>
		</a>
	</li>
-------------------------------------------------------------------

getProjectContent:

This function get data of a project with $idslug, if $onlyProject si true it gets only the project data but not the content, if false it get also the content and return an array with all data. For example 

list ($content,$project)=getProjectContent($idslug);

Get's the content of $idslug variable with the id or slog you need to get, and return in $content the content data of the project and in $project the project data.

The for example you can get data from: $project['projects.sectionname'] or similar things.

If $content is collected you can manually get the items with something like this:

				foreach( $content as $item){
						// here do semething with text
						// This function collect all data ready to use:
						// $item[id] 		- Item's id
						// $item[title] 	- Item's title
						// $item[caption]	- Item's caption
						// $item[file]		- Item's ...
						// $item[thumbnail]	- ...
						// $item[width]
						// $item[height]
						// $item[project_id]
						// $item[pos]
						// $item[type]
						// $item[filegroup]
						// $item[media]		- Url of image
						// $item[media_thumb]	- Url of thmbnail
						// $item[options]	- Caption used to get options, if you add to the caption for example "mydata=myvalue" with $item['option']['mydata'] you will get "myvalue" in return, so this way you can get personal data, to do with you need, for example can be used to make a shop item, and show the price of an item over the image (item).
						// $item[group]
						// $item[sectionslug]
						// $item[sectionname]
				}

showProjectContent:

This function get the data collected by getProjectContent can be launch following the prior example with: showProjectContent($content,$project);

It use a rule of names for templates inside the "templates" folders inside the theme:

for example if the item is a text, till look for content_default_text.html
for example if the item is an image inside a group "one-by-one", will look for content_one-by-one_image.html, to get more control if you have content_one-by-one_open.html and content_one-by-one_close.html will render this file before and after the group.

getPrevProjectByDate:
returns the previous project to $idslug by date of $section

getNextProjectByDate:
returns the next project to $idslug by date of $section


*/
	function mysql_fetch_alias_array($result) {
		// Avoid the problem of duplicated field names in joint queries
		// From Post by Mehdi Haresi in PHP.net
	    if (!($row = mysql_fetch_array($result))) {
	        return null;
	    }
	
	    $assoc = Array();
	    $rowCount = mysql_num_fields($result);
	    
	    for ($idx = 0; $idx < $rowCount; $idx++) {
	        $table = mysql_field_table($result, $idx);
	        $field = mysql_field_name($result, $idx);
	        $assoc["$table.$field"] = $row[$idx];
	    }
	    return $assoc;
	}

	
	function isTypeOfPage( $page = '' ){
		$pageInf=pageInfo(PAGE);
		if ($pageInf['content_type']==$page) return true;

		return false;
	}


	function projectsList($template='projects_thumb.html', $whereadd='', $orderby='date DESC LIMIT 6', $sectionname='') {
		global $clerk, $project;

		$project = Array();
		
		if ($orderby!='') {
			$orderby='ORDER BY '.$orderby;
		}
		
		$projectGet= $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.section=project_sections.id AND projects.publish=1 '.$whereadd.' GROUP BY projects.slug '.$orderby );

		while ( $project = mysql_fetch_alias_array( $projectGet ) ) {
			$project['projects.sectionname']    = $project['project_sections.name'];
			$project['projects.sectionslug']    = $project['project_sections.slug'];
			
			$project['projects.tags'] = '';
			
			$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$project['projects.id'] );
			
			$project['projects.options']=array();
			$project['projects.tags']=array();
			while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
				preg_match('/(.*?)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
				if ($matches[1]!='') {
					$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
				}
				array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
			}

			/*
			foreach( $project['projects.tags'] as $key => $value) {
				echo $key.'='.$value; 
			}
			*/
			
			$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
			
			while ( $file = mysql_fetch_alias_array($filesGet)) {
				if ($project['projects.thumbnail'] != '') {
					//$project['projects.thumbnail'] = $project['projects.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				} else {
					// If project thumbnail not exist get the first thumnail from the project_files table
					$project['projects.thumbnail'] 		= $file['project_files.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
					$project['project_files.file.width']  = $width;
					$project['project_files.file.height'] = $height;
				}
			}

			list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
			$project['projects.thumbnail.width']  = $width;
			$project['projects.thumbnail.height'] = $height;
			$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			$project['projects.url'] = '?page='.currentPage().'&id='.$project['projects.slug'];
			
			// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
			$project['id']			=$project['projects.id'];
			$project['title']		=$project['projects.title'];
			$project['slug']		=$project['projects.slug'];
			$project['description']	=$project['projects.description'];
			$project['date']		=$project['projects.date'];
			$project['section']		=$project['projects.section'];
			$project['pos']			=$project['projects.pos'];
			$project['flow']		=$project['projects.flow'];
			$project['thumbnail']	=$project['projects.thumbnail'];
			$project['publish']		=$project['projects.publish'];
			
			include HQ . 'site/themes/' . THEME . '/templates/'.$template;
		}
	}

	function getProjectContent($idslug, $onlyProject){
		global $clerk, $project;

		$filesbyID = Array();

		// Only one row (because one id unique)
		$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.slug="'.$idslug.'" AND projects.section=project_sections.id' ) );
		// Not found try by ID not slug
		if ($project=="") { 
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.id="'.$idslug.'" AND projects.section=project_sections.id' ) );
		}

		$project['projects.sectionname']=$project['project_sections.name'];
		$project['projects.sectionslug']=$project['project_sections.slug'];

		$idnum=$project['projects.id'];

		// TAGS
		$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$idnum);
		
		$project['projects.options']=array();
		$project['projects.tags']=array();
		while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
			preg_match('/(.*)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
			if ($matches[1]!='') {
				$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
			}
			array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
		}

		/*
		foreach( $project['projects.tags'] as $key => $value) {
			echo $key.'='.$value; 
		}
		*/
		
		if ($onlyProject==true) return $project;

		$filesGet   = $clerk->query_select( 'project_files', '', 'WHERE project_id='.$idnum.' ORDER BY filegroup,pos ASC');

		$firstThumbFound=false;		
		while ( $file = mysql_fetch_alias_array( $filesGet )) {
			$filesbyID[$file['project_files.id']]=$file;
			
			if (!$firstThumbFound) {
				if ($file['project_files.type']=='image') {
					if ($project['projects.thumbnail'] != '') {
						//$project['projects.thumbnail'] = $project['projects.thumbnail'];
						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
					} else {
						// If project thumbnail not exist get the first thumnail from the project_files table
						$project['projects.thumbnail'] = $file['project_files.thumbnail'];

						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
						list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
						$project['project_files.file.width']  = $width;
						$project['project_files.file.height'] = $height;
					}
			
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
					$project['projects.thumbnail.width']  = $width;
					$project['projects.thumbnail.height'] = $height;
					$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				}
				$firstThumbFound=true;
			}
		}

		$content = Array();

		$flow= explode( ',', $project['projects.flow'] );
		foreach ( $flow as $part ) {
			if ( strstr($part, 'textblock') )	{
					$textID		= str_replace( 'textblock', '', $part );
					$textblock	= $filesbyID[$textID]['project_files.caption'];
					array_push($content, array(
						'type'=> $filesbyID[$textID]['project_files.type'],
						'text'=> $textblock
					));
			}
			if ( strstr($part, 'group') )	{
				$group=	getGroupInfo($part);

				foreach ( $filesbyID as $i )	{
					if ( $i['project_files.filegroup'] == $group['num'] ) {
					
						$options=str_replace(', ',',',$i['project_files.caption']);
						$options=str_replace(' ,',',',$options);
						$options=explode(',',$options);

						$i['options']=array();
						foreach ($options as $j) {
							preg_match('/(.*?)\=(.*)/i', $j, $matches);
							if ($matches[1]!='') {
								$i['options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
							}
						}

						array_push($content, array(
							'id'			=> $i['project_files.id'],
							'title'			=> $i['project_files.title'],
							'caption'		=> $i['project_files.caption'],
							'file'			=> $i['project_files.file'],
							'thumbnail'		=> $i['project_files.thumbnail'],
							'width'			=> $i['project_files.width']==0?'':$i['project_files.width'],
							'height'		=> $i['project_files.height']==0?'':$i['project_files.height'],
							'project_id'	=> $i['project_files.project_id'],
							'pos'			=> $i['project_files.pos'],
							'type'			=> $i['project_files.type'],
							'filegroup'		=> $i['project_files.filegroup'],
							'media'			=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.file'],
							'media_thumb'	=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.thumbnail'],
							'options'		=> $i['options'],
							'group'			=> $group,
							'sectionslug'	=> $project['projects.sectionslug'],
							'sectionname'	=> $project['projects.sectionname'],
						));
					}
				}
			}
		}

		// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
		$project['id']			=$project['projects.id'];
		$project['title']		=$project['projects.title'];
		$project['slug']		=$project['projects.slug'];
		$project['description']	=$project['projects.description'];
		$project['date']		=$project['projects.date'];
		$project['section']		=$project['projects.section'];
		$project['pos']			=$project['projects.pos'];
		$project['flow']		=$project['projects.flow'];
		$project['thumbnail']	=$project['projects.thumbnail'];
		$project['publish']		=$project['projects.publish'];

		return array($content,$project);
	}

	function showProjectContent($content, $project){
		$current_type='';
		$current_num='';
		$groupopen=false;
		$grouptag='';
		foreach( $content as $item){
			$isNewgroup=($current_type!==$item['group']['type'] && $current_num!==$item['group']['num']);
			if ( $isNewgroup && $current_type!='' && $groupopen==true) {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$current_type.'_close.html') {
					echo '</'.$grouptag.'>';
					echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
				}
				$groupopen=false;
			}
			if ($isNewgroup && $item['type']!=='text') {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_open.html') {
					$grouptag='div';
					echo "\n\n".'<!-- OPEN '.$item['group']['type'].' //-->'."\n\n";
					echo '<div class="'.$item['group']['type'].'" id="'.$item['group']['type'].$item['group']['num'].'">';
				}
				$current_type=$item['group']['type'];
				$current_num =$item['group']['num'];
				$groupopen=true;
			}
			switch($item['type']) {
				case 'text':
					echo "\n\n".'<!-- OPEN '.$item['type'].' //-->'."\n\n";
					include HQ.'site/themes/'.THEME.'/templates/content_default_text.html';
					echo "\n\n".'<!-- CLOSE '.$item['type'].' //-->'."\n\n";
				break;
				case 'image':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_image.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_image.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'video':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_video.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_video.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'audio':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_audio.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_audio.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
			}
		}
		if ($groupopen==true) {
			if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_close.html') {
				echo '</'.$grouptag.'>';
				echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
			}
		}
		
		// IF last is text add an extra espace down.
		if ($kindOf=="text") { echo '<div style="clear:both" class="spacedown"></div>'; }
	}

	function getPrevProjectByDate($idslug, $section) {
			global $clerk;
	
			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"') );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date < '.$project['projects.date'].$section.' ORDER BY date DESC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}

	function getNextProjectByDate($idslug, $section) {
			global $clerk;

			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"' ) );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date > '.$project['projects.date'].$section.' ORDER BY date ASC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}


	/*
	-----------------------------------------------------------------
		PROYECT FIRST THUMBNAIL
	-----------------------------------------------------------------
	*/
	
	function projectFirstThumb($idslug){
			global $clerk;

			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.id="'.$idslug.'"' ) );
			}

			if ($project['projects.thumbnail'] != '') {
				return PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			} else {
				$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
				while ( $file = mysql_fetch_alias_array($filesGet)) {
					return PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.thumbnail'];
				}
			}
			return '';
	}

Revision: 30582
at August 17, 2010 22:20 by microbians


Updated Code
/*
mysql_fetch_alias_array:

is a function by Mehdi Haresi that get's de mysql entry and format into an array, to handle more like objects

isTypeOfPage:

Check if current page is a type of page

projectsList:

This function by default get the projects list of last 6 by date but you can change parameters and paint the projects using the $template. A template is a regular php file, with html extension if you like, that renders the variables this functions get from database. The template file must be inside the theme folder inside a folder named "templates". And example of a template can be "projects_thumb.html" that is like that:

-------------------------------------------------------------------
	<li class="thumb">
		<a rel="content" href="<?php echo $project['projects.url']; ?>">
			<img src="<?php echo $project['projects.thumbnail']; ?>" width="<?php echo $project['projects.thumbnail.width']; ?>" height="<?php echo $project['projects.thumbnail.height']; ?>"/>
			<div class="cover">
				<div class="info">
					<span class="section"><?php echo $project['projects.sectionname']; ?></span>
					<div style="clear: both;"></div>
					<span class="titleproject"><?php echo $project['projects.title']; ?></span>
				</div>
			</div>
		</a>
	</li>
-------------------------------------------------------------------

getProjectContent:

This function get data of a project with $idslug, if $onlyProject si true it gets only the project data but not the content, if false it get also the content and return an array with all data. For example 

list ($content,$project)=getProjectContent($idslug);

Get's the content of $idslug variable with the id or slog you need to get, and return in $content the content data of the project and in $project the project data.

The for example you can get data from: $project['projects.sectionname'] or similar things.

If $content is collected you can manually get the items with something like this:

				foreach( $content as $item){
					if ($item['type']=='text'){
						// here do semething with text
						// This function collect all data ready to use:
						// $item[id] 		- Item's id
						// $item[title] 	- Item's title
						// $item[caption]	- Item's caption
						// $item[file]		- Item's ...
						// $item[thumbnail]	- ...
						// $item[width]
						// $item[height]
						// $item[project_id]
						// $item[pos]
						// $item[type]
						// $item[filegroup]
						// $item[media]		- Url of image
						// $item[media_thumb]	- Url of thmbnail
						// $item[options]	- Caption used to get options, if you add to the caption for example "mydata=myvalue" with $item['option']['mydata'] you will get "myvalue" in return, so this way you can get èrsonal data, to do with you need, for example can be used to make a shop item, and show the price of an item over the image (item).
						// $item[group]
						// $item[sectionslug]
						// $item[sectionname]
					}
				}

showProjectContent:

This function get the data collected by getProjectContent can be launch following the prior example with: showProjectContent($content,$project);

It use a rule of names for templates inside the "templates" folders inside the theme:

for example if the item is a text, till look for content_default_text.html
for example if the item is an image inside a group "one-by-one", will look for content_one-by-one_image.html, to get more control if you have content_one-by-one_open.html and content_one-by-one_close.html will render this file before and after the group.

getPrevProjectByDate:
returns the previous project to $idslug by date of $section

getNextProjectByDate:
returns the next project to $idslug by date of $section


*/
	function mysql_fetch_alias_array($result) {
		// Avoid the problem of duplicated field names in joint queries
		// From Post by Mehdi Haresi in PHP.net
	    if (!($row = mysql_fetch_array($result))) {
	        return null;
	    }
	
	    $assoc = Array();
	    $rowCount = mysql_num_fields($result);
	    
	    for ($idx = 0; $idx < $rowCount; $idx++) {
	        $table = mysql_field_table($result, $idx);
	        $field = mysql_field_name($result, $idx);
	        $assoc["$table.$field"] = $row[$idx];
	    }
	    return $assoc;
	}

	
	function isTypeOfPage( $page = '' ){
		$pageInf=pageInfo(PAGE);
		if ($pageInf['content_type']==$page) return true;

		return false;
	}


	function projectsList($template='projects_thumb.html', $whereadd='', $orderby='date DESC LIMIT 6', $sectionname='') {
		global $clerk, $project;

		$project = Array();
		
		if ($orderby!='') {
			$orderby='ORDER BY '.$orderby;
		}
		
		$projectGet= $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.section=project_sections.id AND projects.publish=1 '.$whereadd.' GROUP BY projects.slug '.$orderby );

		while ( $project = mysql_fetch_alias_array( $projectGet ) ) {
			$project['projects.sectionname']    = $project['project_sections.name'];
			$project['projects.sectionslug']    = $project['project_sections.slug'];
			
			$project['projects.tags'] = '';
			
			$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$project['projects.id'] );
			
			$project['projects.options']=array();
			$project['projects.tags']=array();
			while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
				preg_match('/(.*?)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
				if ($matches[1]!='') {
					$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
				}
				array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
			}

			/*
			foreach( $project['projects.tags'] as $key => $value) {
				echo $key.'='.$value; 
			}
			*/
			
			$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
			
			while ( $file = mysql_fetch_alias_array($filesGet)) {
				if ($project['projects.thumbnail'] != '') {
					//$project['projects.thumbnail'] = $project['projects.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				} else {
					// If project thumbnail not exist get the first thumnail from the project_files table
					$project['projects.thumbnail'] 		= $file['project_files.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
					$project['project_files.file.width']  = $width;
					$project['project_files.file.height'] = $height;
				}
			}

			list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
			$project['projects.thumbnail.width']  = $width;
			$project['projects.thumbnail.height'] = $height;
			$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			$project['projects.url'] = '?page='.currentPage().'&id='.$project['projects.slug'];
			
			// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
			$project['id']			=$project['projects.id'];
			$project['title']		=$project['projects.title'];
			$project['slug']		=$project['projects.slug'];
			$project['description']	=$project['projects.description'];
			$project['date']		=$project['projects.date'];
			$project['section']		=$project['projects.section'];
			$project['pos']			=$project['projects.pos'];
			$project['flow']		=$project['projects.flow'];
			$project['thumbnail']	=$project['projects.thumbnail'];
			$project['publish']		=$project['projects.publish'];
			
			include HQ . 'site/themes/' . THEME . '/templates/'.$template;
		}
	}

	function getProjectContent($idslug, $onlyProject){
		global $clerk, $project;

		$filesbyID = Array();

		// Only one row (because one id unique)
		$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.slug="'.$idslug.'" AND projects.section=project_sections.id' ) );
		// Not found try by ID not slug
		if ($project=="") { 
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.id="'.$idslug.'" AND projects.section=project_sections.id' ) );
		}

		$project['projects.sectionname']=$project['project_sections.name'];
		$project['projects.sectionslug']=$project['project_sections.slug'];

		$idnum=$project['projects.id'];

		// TAGS
		$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$idnum);
		
		$project['projects.options']=array();
		$project['projects.tags']=array();
		while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
			preg_match('/(.*)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
			if ($matches[1]!='') {
				$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
			}
			array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
		}

		/*
		foreach( $project['projects.tags'] as $key => $value) {
			echo $key.'='.$value; 
		}
		*/
		
		if ($onlyProject==true) return $project;

		$filesGet   = $clerk->query_select( 'project_files', '', 'WHERE project_id='.$idnum.' ORDER BY filegroup,pos ASC');

		$firstThumbFound=false;		
		while ( $file = mysql_fetch_alias_array( $filesGet )) {
			$filesbyID[$file['project_files.id']]=$file;
			
			if (!$firstThumbFound) {
				if ($file['project_files.type']=='image') {
					if ($project['projects.thumbnail'] != '') {
						//$project['projects.thumbnail'] = $project['projects.thumbnail'];
						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
					} else {
						// If project thumbnail not exist get the first thumnail from the project_files table
						$project['projects.thumbnail'] = $file['project_files.thumbnail'];

						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
						list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
						$project['project_files.file.width']  = $width;
						$project['project_files.file.height'] = $height;
					}
			
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
					$project['projects.thumbnail.width']  = $width;
					$project['projects.thumbnail.height'] = $height;
					$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				}
				$firstThumbFound=true;
			}
		}

		$content = Array();

		$flow= explode( ',', $project['projects.flow'] );
		foreach ( $flow as $part ) {
			if ( strstr($part, 'textblock') )	{
					$textID		= str_replace( 'textblock', '', $part );
					$textblock	= $filesbyID[$textID]['project_files.caption'];
					array_push($content, array(
						'type'=> $filesbyID[$textID]['project_files.type'],
						'text'=> $textblock
					));
			}
			if ( strstr($part, 'group') )	{
				$group=	getGroupInfo($part);

				foreach ( $filesbyID as $i )	{
					if ( $i['project_files.filegroup'] == $group['num'] ) {
					
						$options=str_replace(', ',',',$i['project_files.caption']);
						$options=str_replace(' ,',',',$options);
						$options=explode(',',$options);

						$i['options']=array();
						foreach ($options as $j) {
							preg_match('/(.*?)\=(.*)/i', $j, $matches);
							if ($matches[1]!='') {
								$i['options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
							}
						}

						array_push($content, array(
							'id'			=> $i['project_files.id'],
							'title'			=> $i['project_files.title'],
							'caption'		=> $i['project_files.caption'],
							'file'			=> $i['project_files.file'],
							'thumbnail'		=> $i['project_files.thumbnail'],
							'width'			=> $i['project_files.width']==0?'':$i['project_files.width'],
							'height'		=> $i['project_files.height']==0?'':$i['project_files.height'],
							'project_id'	=> $i['project_files.project_id'],
							'pos'			=> $i['project_files.pos'],
							'type'			=> $i['project_files.type'],
							'filegroup'		=> $i['project_files.filegroup'],
							'media'			=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.file'],
							'media_thumb'	=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.thumbnail'],
							'options'		=> $i['options'],
							'group'			=> $group,
							'sectionslug'	=> $project['projects.sectionslug'],
							'sectionname'	=> $project['projects.sectionname'],
						));
					}
				}
			}
		}

		// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
		$project['id']			=$project['projects.id'];
		$project['title']		=$project['projects.title'];
		$project['slug']		=$project['projects.slug'];
		$project['description']	=$project['projects.description'];
		$project['date']		=$project['projects.date'];
		$project['section']		=$project['projects.section'];
		$project['pos']			=$project['projects.pos'];
		$project['flow']		=$project['projects.flow'];
		$project['thumbnail']	=$project['projects.thumbnail'];
		$project['publish']		=$project['projects.publish'];

		return array($content,$project);
	}

	function showProjectContent($content, $project){
		$current_type='';
		$current_num='';
		$groupopen=false;
		$grouptag='';
		foreach( $content as $item){
			$isNewgroup=($current_type!==$item['group']['type'] && $current_num!==$item['group']['num']);
			if ( $isNewgroup && $current_type!='' && $groupopen==true) {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$current_type.'_close.html') {
					echo '</'.$grouptag.'>';
					echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
				}
				$groupopen=false;
			}
			if ($isNewgroup && $item['type']!=='text') {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_open.html') {
					$grouptag='div';
					echo "\n\n".'<!-- OPEN '.$item['group']['type'].' //-->'."\n\n";
					echo '<div class="'.$item['group']['type'].'" id="'.$item['group']['type'].$item['group']['num'].'">';
				}
				$current_type=$item['group']['type'];
				$current_num =$item['group']['num'];
				$groupopen=true;
			}
			switch($item['type']) {
				case 'text':
					echo "\n\n".'<!-- OPEN '.$item['type'].' //-->'."\n\n";
					include HQ.'site/themes/'.THEME.'/templates/content_default_text.html';
					echo "\n\n".'<!-- CLOSE '.$item['type'].' //-->'."\n\n";
				break;
				case 'image':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_image.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_image.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'video':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_video.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_video.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'audio':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_audio.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_audio.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
			}
		}
		if ($groupopen==true) {
			if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_close.html') {
				echo '</'.$grouptag.'>';
				echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
			}
		}
		
		// IF last is text add an extra espace down.
		if ($kindOf=="text") { echo '<div style="clear:both" class="spacedown"></div>'; }
	}

	function getPrevProjectByDate($idslug, $section) {
			global $clerk;
	
			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"') );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date < '.$project['projects.date'].$section.' ORDER BY date DESC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}

	function getNextProjectByDate($idslug, $section) {
			global $clerk;

			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"' ) );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date > '.$project['projects.date'].$section.' ORDER BY date ASC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}


	/*
	-----------------------------------------------------------------
		PROYECT FIRST THUMBNAIL
	-----------------------------------------------------------------
	*/
	
	function projectFirstThumb($idslug){
			global $clerk;

			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.id="'.$idslug.'"' ) );
			}

			if ($project['projects.thumbnail'] != '') {
				return PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			} else {
				$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
				while ( $file = mysql_fetch_alias_array($filesGet)) {
					return PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.thumbnail'];
				}
			}
			return '';
	}

Revision: 30581
at August 17, 2010 22:20 by microbians


Updated Code
/*
mysql_fetch_alias_array:

is a function by Mehdi Haresi that get's de mysql entry and format into an array, to handle more like objects

isTypeOfPage:

Check if current page is a type of page

projectsList:

This function by default get the projects list of last 6 by date but you can change parameters and paint the projects using the $template. A template is a regular php file, with html extension if you like, that renders the variables this functions get from database. The template file must be inside the theme folder inside a folder named "templates". And example of a template can be "projects_thumb.html" that is like that:

-------------------------------------------------------------------
						<li class="thumb">
							<a rel="content" href="<?php echo $project['projects.url']; ?>">
								<img src="<?php echo $project['projects.thumbnail']; ?>" width="<?php echo $project['projects.thumbnail.width']; ?>" height="<?php echo $project['projects.thumbnail.height']; ?>"/>
								<div class="cover">
									<div class="info">
										<span class="section"><?php echo $project['projects.sectionname']; ?></span>
										<div style="clear: both;"></div>
										<span class="titleproject"><?php echo $project['projects.title']; ?></span>
									</div>
								</div>
							</a>
						</li>
-------------------------------------------------------------------

getProjectContent:

This function get data of a project with $idslug, if $onlyProject si true it gets only the project data but not the content, if false it get also the content and return an array with all data. For example 

list ($content,$project)=getProjectContent($idslug);

Get's the content of $idslug variable with the id or slog you need to get, and return in $content the content data of the project and in $project the project data.

The for example you can get data from: $project['projects.sectionname'] or similar things.

If $content is collected you can manually get the items with something like this:

				foreach( $content as $item){
					if ($item['type']=='text'){
						// here do semething with text
						// This function collect all data ready to use:
						// $item[id] 		- Item's id
						// $item[title] 	- Item's title
						// $item[caption]	- Item's caption
						// $item[file]		- Item's ...
						// $item[thumbnail]	- ...
						// $item[width]
						// $item[height]
						// $item[project_id]
						// $item[pos]
						// $item[type]
						// $item[filegroup]
						// $item[media]		- Url of image
						// $item[media_thumb]	- Url of thmbnail
						// $item[options]	- Caption used to get options, if you add to the caption for example "mydata=myvalue" with $item['option']['mydata'] you will get "myvalue" in return, so this way you can get èrsonal data, to do with you need, for example can be used to make a shop item, and show the price of an item over the image (item).
						// $item[group]
						// $item[sectionslug]
						// $item[sectionname]
					}
				}

showProjectContent:

This function get the data collected by getProjectContent can be launch following the prior example with: showProjectContent($content,$project);

It use a rule of names for templates inside the "templates" folders inside the theme:

for example if the item is a text, till look for content_default_text.html
for example if the item is an image inside a group "one-by-one", will look for content_one-by-one_image.html, to get more control if you have content_one-by-one_open.html and content_one-by-one_close.html will render this file before and after the group.

getPrevProjectByDate:
returns the previous project to $idslug by date of $section

getNextProjectByDate:
returns the next project to $idslug by date of $section


*/
	function mysql_fetch_alias_array($result) {
		// Avoid the problem of duplicated field names in joint queries
		// From Post by Mehdi Haresi in PHP.net
	    if (!($row = mysql_fetch_array($result))) {
	        return null;
	    }
	
	    $assoc = Array();
	    $rowCount = mysql_num_fields($result);
	    
	    for ($idx = 0; $idx < $rowCount; $idx++) {
	        $table = mysql_field_table($result, $idx);
	        $field = mysql_field_name($result, $idx);
	        $assoc["$table.$field"] = $row[$idx];
	    }
	    return $assoc;
	}

	
	function isTypeOfPage( $page = '' ){
		$pageInf=pageInfo(PAGE);
		if ($pageInf['content_type']==$page) return true;

		return false;
	}


	function projectsList($template='projects_thumb.html', $whereadd='', $orderby='date DESC LIMIT 6', $sectionname='') {
		global $clerk, $project;

		$project = Array();
		
		if ($orderby!='') {
			$orderby='ORDER BY '.$orderby;
		}
		
		$projectGet= $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.section=project_sections.id AND projects.publish=1 '.$whereadd.' GROUP BY projects.slug '.$orderby );

		while ( $project = mysql_fetch_alias_array( $projectGet ) ) {
			$project['projects.sectionname']    = $project['project_sections.name'];
			$project['projects.sectionslug']    = $project['project_sections.slug'];
			
			$project['projects.tags'] = '';
			
			$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$project['projects.id'] );
			
			$project['projects.options']=array();
			$project['projects.tags']=array();
			while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
				preg_match('/(.*?)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
				if ($matches[1]!='') {
					$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
				}
				array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
			}

			/*
			foreach( $project['projects.tags'] as $key => $value) {
				echo $key.'='.$value; 
			}
			*/
			
			$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
			
			while ( $file = mysql_fetch_alias_array($filesGet)) {
				if ($project['projects.thumbnail'] != '') {
					//$project['projects.thumbnail'] = $project['projects.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				} else {
					// If project thumbnail not exist get the first thumnail from the project_files table
					$project['projects.thumbnail'] 		= $file['project_files.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
					$project['project_files.file.width']  = $width;
					$project['project_files.file.height'] = $height;
				}
			}

			list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
			$project['projects.thumbnail.width']  = $width;
			$project['projects.thumbnail.height'] = $height;
			$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			$project['projects.url'] = '?page='.currentPage().'&id='.$project['projects.slug'];
			
			// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
			$project['id']			=$project['projects.id'];
			$project['title']		=$project['projects.title'];
			$project['slug']		=$project['projects.slug'];
			$project['description']	=$project['projects.description'];
			$project['date']		=$project['projects.date'];
			$project['section']		=$project['projects.section'];
			$project['pos']			=$project['projects.pos'];
			$project['flow']		=$project['projects.flow'];
			$project['thumbnail']	=$project['projects.thumbnail'];
			$project['publish']		=$project['projects.publish'];
			
			include HQ . 'site/themes/' . THEME . '/templates/'.$template;
		}
	}

	function getProjectContent($idslug, $onlyProject){
		global $clerk, $project;

		$filesbyID = Array();

		// Only one row (because one id unique)
		$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.slug="'.$idslug.'" AND projects.section=project_sections.id' ) );
		// Not found try by ID not slug
		if ($project=="") { 
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.id="'.$idslug.'" AND projects.section=project_sections.id' ) );
		}

		$project['projects.sectionname']=$project['project_sections.name'];
		$project['projects.sectionslug']=$project['project_sections.slug'];

		$idnum=$project['projects.id'];

		// TAGS
		$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$idnum);
		
		$project['projects.options']=array();
		$project['projects.tags']=array();
		while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
			preg_match('/(.*)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
			if ($matches[1]!='') {
				$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
			}
			array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
		}

		/*
		foreach( $project['projects.tags'] as $key => $value) {
			echo $key.'='.$value; 
		}
		*/
		
		if ($onlyProject==true) return $project;

		$filesGet   = $clerk->query_select( 'project_files', '', 'WHERE project_id='.$idnum.' ORDER BY filegroup,pos ASC');

		$firstThumbFound=false;		
		while ( $file = mysql_fetch_alias_array( $filesGet )) {
			$filesbyID[$file['project_files.id']]=$file;
			
			if (!$firstThumbFound) {
				if ($file['project_files.type']=='image') {
					if ($project['projects.thumbnail'] != '') {
						//$project['projects.thumbnail'] = $project['projects.thumbnail'];
						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
					} else {
						// If project thumbnail not exist get the first thumnail from the project_files table
						$project['projects.thumbnail'] = $file['project_files.thumbnail'];

						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
						list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
						$project['project_files.file.width']  = $width;
						$project['project_files.file.height'] = $height;
					}
			
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
					$project['projects.thumbnail.width']  = $width;
					$project['projects.thumbnail.height'] = $height;
					$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				}
				$firstThumbFound=true;
			}
		}

		$content = Array();

		$flow= explode( ',', $project['projects.flow'] );
		foreach ( $flow as $part ) {
			if ( strstr($part, 'textblock') )	{
					$textID		= str_replace( 'textblock', '', $part );
					$textblock	= $filesbyID[$textID]['project_files.caption'];
					array_push($content, array(
						'type'=> $filesbyID[$textID]['project_files.type'],
						'text'=> $textblock
					));
			}
			if ( strstr($part, 'group') )	{
				$group=	getGroupInfo($part);

				foreach ( $filesbyID as $i )	{
					if ( $i['project_files.filegroup'] == $group['num'] ) {
					
						$options=str_replace(', ',',',$i['project_files.caption']);
						$options=str_replace(' ,',',',$options);
						$options=explode(',',$options);

						$i['options']=array();
						foreach ($options as $j) {
							preg_match('/(.*?)\=(.*)/i', $j, $matches);
							if ($matches[1]!='') {
								$i['options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
							}
						}

						array_push($content, array(
							'id'			=> $i['project_files.id'],
							'title'			=> $i['project_files.title'],
							'caption'		=> $i['project_files.caption'],
							'file'			=> $i['project_files.file'],
							'thumbnail'		=> $i['project_files.thumbnail'],
							'width'			=> $i['project_files.width']==0?'':$i['project_files.width'],
							'height'		=> $i['project_files.height']==0?'':$i['project_files.height'],
							'project_id'	=> $i['project_files.project_id'],
							'pos'			=> $i['project_files.pos'],
							'type'			=> $i['project_files.type'],
							'filegroup'		=> $i['project_files.filegroup'],
							'media'			=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.file'],
							'media_thumb'	=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.thumbnail'],
							'options'		=> $i['options'],
							'group'			=> $group,
							'sectionslug'	=> $project['projects.sectionslug'],
							'sectionname'	=> $project['projects.sectionname'],
						));
					}
				}
			}
		}

		// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
		$project['id']			=$project['projects.id'];
		$project['title']		=$project['projects.title'];
		$project['slug']		=$project['projects.slug'];
		$project['description']	=$project['projects.description'];
		$project['date']		=$project['projects.date'];
		$project['section']		=$project['projects.section'];
		$project['pos']			=$project['projects.pos'];
		$project['flow']		=$project['projects.flow'];
		$project['thumbnail']	=$project['projects.thumbnail'];
		$project['publish']		=$project['projects.publish'];

		return array($content,$project);
	}

	function showProjectContent($content, $project){
		$current_type='';
		$current_num='';
		$groupopen=false;
		$grouptag='';
		foreach( $content as $item){
			$isNewgroup=($current_type!==$item['group']['type'] && $current_num!==$item['group']['num']);
			if ( $isNewgroup && $current_type!='' && $groupopen==true) {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$current_type.'_close.html') {
					echo '</'.$grouptag.'>';
					echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
				}
				$groupopen=false;
			}
			if ($isNewgroup && $item['type']!=='text') {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_open.html') {
					$grouptag='div';
					echo "\n\n".'<!-- OPEN '.$item['group']['type'].' //-->'."\n\n";
					echo '<div class="'.$item['group']['type'].'" id="'.$item['group']['type'].$item['group']['num'].'">';
				}
				$current_type=$item['group']['type'];
				$current_num =$item['group']['num'];
				$groupopen=true;
			}
			switch($item['type']) {
				case 'text':
					echo "\n\n".'<!-- OPEN '.$item['type'].' //-->'."\n\n";
					include HQ.'site/themes/'.THEME.'/templates/content_default_text.html';
					echo "\n\n".'<!-- CLOSE '.$item['type'].' //-->'."\n\n";
				break;
				case 'image':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_image.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_image.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'video':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_video.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_video.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'audio':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_audio.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_audio.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
			}
		}
		if ($groupopen==true) {
			if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_close.html') {
				echo '</'.$grouptag.'>';
				echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
			}
		}
		
		// IF last is text add an extra espace down.
		if ($kindOf=="text") { echo '<div style="clear:both" class="spacedown"></div>'; }
	}

	function getPrevProjectByDate($idslug, $section) {
			global $clerk;
	
			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"') );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date < '.$project['projects.date'].$section.' ORDER BY date DESC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}

	function getNextProjectByDate($idslug, $section) {
			global $clerk;

			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"' ) );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date > '.$project['projects.date'].$section.' ORDER BY date ASC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}


	/*
	-----------------------------------------------------------------
		PROYECT FIRST THUMBNAIL
	-----------------------------------------------------------------
	*/
	
	function projectFirstThumb($idslug){
			global $clerk;

			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.id="'.$idslug.'"' ) );
			}

			if ($project['projects.thumbnail'] != '') {
				return PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			} else {
				$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
				while ( $file = mysql_fetch_alias_array($filesGet)) {
					return PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.thumbnail'];
				}
			}
			return '';
	}

Revision: 30580
at August 17, 2010 21:48 by microbians


Initial Code
function mysql_fetch_alias_array($result) {
		// Avoid the problem of duplicated field names in joint queries
		// From Post by Mehdi Haresi in PHP.net
	    if (!($row = mysql_fetch_array($result))) {
	        return null;
	    }
	
	    $assoc = Array();
	    $rowCount = mysql_num_fields($result);
	    
	    for ($idx = 0; $idx < $rowCount; $idx++) {
	        $table = mysql_field_table($result, $idx);
	        $field = mysql_field_name($result, $idx);
	        $assoc["$table.$field"] = $row[$idx];
	    }
	    return $assoc;
	}

	
	function isTypeOfPage( $page = '' ){
		$pageInf=pageInfo(PAGE);
		if ($pageInf['content_type']==$page) return true;

		return false;
	}


	function projectsList($template='projects_thumb.html', $whereadd='', $orderby='date DESC LIMIT 6', $sectionname='') {
		global $clerk, $project;

		$project = Array();
		
		if ($orderby!='') {
			$orderby='ORDER BY '.$orderby;
		}
		
		$projectGet= $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.section=project_sections.id AND projects.publish=1 '.$whereadd.' GROUP BY projects.slug '.$orderby );

		while ( $project = mysql_fetch_alias_array( $projectGet ) ) {
			$project['projects.sectionname']    = $project['project_sections.name'];
			$project['projects.sectionslug']    = $project['project_sections.slug'];
			
			$project['projects.tags'] = '';
			
			$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$project['projects.id'] );
			
			$project['projects.options']=array();
			$project['projects.tags']=array();
			while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
				preg_match('/(.*?)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
				if ($matches[1]!='') {
					$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
				}
				array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
			}

			/*
			foreach( $project['projects.tags'] as $key => $value) {
				echo $key.'='.$value; 
			}
			*/
			
			$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
			
			while ( $file = mysql_fetch_alias_array($filesGet)) {
				if ($project['projects.thumbnail'] != '') {
					//$project['projects.thumbnail'] = $project['projects.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				} else {
					// If project thumbnail not exist get the first thumnail from the project_files table
					$project['projects.thumbnail'] 		= $file['project_files.thumbnail'];
					$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
					$project['project_files.file.width']  = $width;
					$project['project_files.file.height'] = $height;
				}
			}

			list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
			$project['projects.thumbnail.width']  = $width;
			$project['projects.thumbnail.height'] = $height;
			$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			$project['projects.url'] = '?page='.currentPage().'&id='.$project['projects.slug'];
			
			// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
			$project['id']			=$project['projects.id'];
			$project['title']		=$project['projects.title'];
			$project['slug']		=$project['projects.slug'];
			$project['description']	=$project['projects.description'];
			$project['date']		=$project['projects.date'];
			$project['section']		=$project['projects.section'];
			$project['pos']			=$project['projects.pos'];
			$project['flow']		=$project['projects.flow'];
			$project['thumbnail']	=$project['projects.thumbnail'];
			$project['publish']		=$project['projects.publish'];
			
			include HQ . 'site/themes/' . THEME . '/templates/'.$template;
		}
	}

	function getProjectContent($idslug, $onlyProject){
		global $clerk, $project;

		$filesbyID = Array();

		// Only one row (because one id unique)
		$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.slug="'.$idslug.'" AND projects.section=project_sections.id' ) );
		// Not found try by ID not slug
		if ($project=="") { 
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects, project_sections', '', 'WHERE projects.id="'.$idslug.'" AND projects.section=project_sections.id' ) );
		}

		$project['projects.sectionname']=$project['project_sections.name'];
		$project['projects.sectionslug']=$project['project_sections.slug'];

		$idnum=$project['projects.id'];

		// TAGS
		$tagsGet= $clerk->query_select( 'projects_to_tags', '', 'WHERE projects_to_tags.projectid='.$idnum);
		
		$project['projects.options']=array();
		$project['projects.tags']=array();
		while ( $tags = mysql_fetch_alias_array( $tagsGet ) ) {
			preg_match('/(.*)\=(.*)/i', $tags['projects_to_tags.tag'], $matches);
			if ($matches[1]!='') {
				$project['projects.options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
			}
			array_push($project['projects.tags'], $tags['projects_to_tags.tag']);
		}

		/*
		foreach( $project['projects.tags'] as $key => $value) {
			echo $key.'='.$value; 
		}
		*/
		
		if ($onlyProject==true) return $project;

		$filesGet   = $clerk->query_select( 'project_files', '', 'WHERE project_id='.$idnum.' ORDER BY filegroup,pos ASC');

		$firstThumbFound=false;		
		while ( $file = mysql_fetch_alias_array( $filesGet )) {
			$filesbyID[$file['project_files.id']]=$file;
			
			if (!$firstThumbFound) {
				if ($file['project_files.type']=='image') {
					if ($project['projects.thumbnail'] != '') {
						//$project['projects.thumbnail'] = $project['projects.thumbnail'];
						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
					} else {
						// If project thumbnail not exist get the first thumnail from the project_files table
						$project['projects.thumbnail'] = $file['project_files.thumbnail'];

						$project['project_files.file']		= PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.file'];
						list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$file['project_files.file'] );
						$project['project_files.file.width']  = $width;
						$project['project_files.file.height'] = $height;
					}
			
					list( $width, $height )= getimagesize( PROJECTS_PATH.$project['projects.slug'].'/'.$project['projects.thumbnail'] );
					$project['projects.thumbnail.width']  = $width;
					$project['projects.thumbnail.height'] = $height;
					$project['projects.thumbnail']= PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
				}
				$firstThumbFound=true;
			}
		}

		$content = Array();

		$flow= explode( ',', $project['projects.flow'] );
		foreach ( $flow as $part ) {
			if ( strstr($part, 'textblock') )	{
					$textID		= str_replace( 'textblock', '', $part );
					$textblock	= $filesbyID[$textID]['project_files.caption'];
					array_push($content, array(
						'type'=> $filesbyID[$textID]['project_files.type'],
						'text'=> $textblock
					));
			}
			if ( strstr($part, 'group') )	{
				$group=	getGroupInfo($part);

				foreach ( $filesbyID as $i )	{
					if ( $i['project_files.filegroup'] == $group['num'] ) {
					
						$options=str_replace(', ',',',$i['project_files.caption']);
						$options=str_replace(' ,',',',$options);
						$options=explode(',',$options);

						$i['options']=array();
						foreach ($options as $j) {
							preg_match('/(.*?)\=(.*)/i', $j, $matches);
							if ($matches[1]!='') {
								$i['options'][$matches[1]]=mb_convert_encoding( $matches[2], "HTML-ENTITIES", "utf-8" );
							}
						}

						array_push($content, array(
							'id'			=> $i['project_files.id'],
							'title'			=> $i['project_files.title'],
							'caption'		=> $i['project_files.caption'],
							'file'			=> $i['project_files.file'],
							'thumbnail'		=> $i['project_files.thumbnail'],
							'width'			=> $i['project_files.width']==0?'':$i['project_files.width'],
							'height'		=> $i['project_files.height']==0?'':$i['project_files.height'],
							'project_id'	=> $i['project_files.project_id'],
							'pos'			=> $i['project_files.pos'],
							'type'			=> $i['project_files.type'],
							'filegroup'		=> $i['project_files.filegroup'],
							'media'			=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.file'],
							'media_thumb'	=> PROJECTS_URL.$project['projects.slug'].'/'.$i['project_files.thumbnail'],
							'options'		=> $i['options'],
							'group'			=> $group,
							'sectionslug'	=> $project['projects.sectionslug'],
							'sectionname'	=> $project['projects.sectionname'],
						));
					}
				}
			}
		}

		// FOR COMPATIBILITY WITH REGULAR OPTIONS OF THE CMS
		$project['id']			=$project['projects.id'];
		$project['title']		=$project['projects.title'];
		$project['slug']		=$project['projects.slug'];
		$project['description']	=$project['projects.description'];
		$project['date']		=$project['projects.date'];
		$project['section']		=$project['projects.section'];
		$project['pos']			=$project['projects.pos'];
		$project['flow']		=$project['projects.flow'];
		$project['thumbnail']	=$project['projects.thumbnail'];
		$project['publish']		=$project['projects.publish'];

		return array($content,$project);
	}

	function showProjectContent($content, $project){
		$current_type='';
		$current_num='';
		$groupopen=false;
		$grouptag='';
		foreach( $content as $item){
			$isNewgroup=($current_type!==$item['group']['type'] && $current_num!==$item['group']['num']);
			if ( $isNewgroup && $current_type!='' && $groupopen==true) {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$current_type.'_close.html') {
					echo '</'.$grouptag.'>';
					echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
				}
				$groupopen=false;
			}
			if ($isNewgroup && $item['type']!=='text') {
				if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_open.html') {
					$grouptag='div';
					echo "\n\n".'<!-- OPEN '.$item['group']['type'].' //-->'."\n\n";
					echo '<div class="'.$item['group']['type'].'" id="'.$item['group']['type'].$item['group']['num'].'">';
				}
				$current_type=$item['group']['type'];
				$current_num =$item['group']['num'];
				$groupopen=true;
			}
			switch($item['type']) {
				case 'text':
					echo "\n\n".'<!-- OPEN '.$item['type'].' //-->'."\n\n";
					include HQ.'site/themes/'.THEME.'/templates/content_default_text.html';
					echo "\n\n".'<!-- CLOSE '.$item['type'].' //-->'."\n\n";
				break;
				case 'image':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_image.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_image.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'video':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_video.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_video.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
				case 'audio':
					if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_audio.html') {
						if (!@include HQ.'site/themes/'.THEME.'/templates/content_default_audio.html') {
							$typeFunc	= 	str_replace( "-", "_", $item['group']['type'] );
							if ( is_callable( $typeFunc ) ) {
								echo call_user_func_array( $typeFunc, array( $project, $content, $item['group'] ) );
							}
						}
					}
				break;
			}
		}
		if ($groupopen==true) {
			if (!@include HQ.'site/themes/'.THEME.'/templates/content_'.$item['group']['type'].'_close.html') {
				echo '</'.$grouptag.'>';
				echo "\n\n".'<!-- CLOSE '.$current_type.' //-->'."\n\n";
			}
		}
		
		// IF last is text add an extra espace down.
		if ($kindOf=="text") { echo '<div style="clear:both" class="spacedown"></div>'; }
	}

	function getPrevProjectByDate($idslug, $section) {
			global $clerk;
	
			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"') );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date < '.$project['projects.date'].$section.' ORDER BY date DESC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}

	function getNextProjectByDate($idslug, $section) {
			global $clerk;

			if ($section!='') {
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section="'.$sections['project_sections.id'].'" ';
				}
			} else {
				$section='pages';
				$sections = mysql_fetch_alias_array( $clerk->query_select( 'project_sections', 'id', 'WHERE slug="'.$section.'"' ) );
				if ($sections!='') {
					$section= ' AND section!="'.$sections['project_sections.id'].'" ';
				}
			}
	
			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
						$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'date', 'WHERE id="'.$idslug.'"' ) );
			}

			if ($project!="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', 'projects.slug', 'WHERE date > '.$project['projects.date'].$section.' ORDER BY date ASC LIMIT 1') );
				return $project['projects.slug'];
			}
			return null;
	}


	/*
	-----------------------------------------------------------------
		PROYECT FIRST THUMBNAIL
	-----------------------------------------------------------------
	*/
	
	function projectFirstThumb($idslug){
			global $clerk;

			// Only one row (because one id unique)
			$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.slug="'.$idslug.'"' ) );
			// Not found try by ID not slug
			if ($project=="") { 
				$project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.id="'.$idslug.'"' ) );
			}

			if ($project['projects.thumbnail'] != '') {
				return PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
			} else {
				$filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
				while ( $file = mysql_fetch_alias_array($filesGet)) {
					return PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.thumbnail'];
				}
			}
			return '';
	}

Initial URL
http://www.thesecretary.org/

Initial Description


Initial Title
thesecretary.org / Various Functions

Initial Tags


Initial Language
PHP