Forums » Customize

Automatically section name

joshdehn
FRANCE
2010-02-08 10:11:07
Permalink Post
 

Hi everyone,

I would like to add a 'div' in the '#content' of my file 'index.php' with automatically the section name.

I'm using the system variable .
It works with exhibit title , but not with section name ?

Thanks in advance
J.

Vaska A
I WROTE THIS
2010-02-08 10:12:57
Permalink Post
 

Section name is not available as a variable. I've posted a few times the way to make this happen...you will need to add ndxz_section to the query in your root index.php. But have a search for the full answer...

joshdehn
FRANCE
2010-02-08 10:52:31
Permalink Post
 

Thanks for your answer.
I'm sorry ! I've made some researches on the forum but I haven't found what you are talking about...
Maybe you can help me to find the link I'm looking for ? (It would be very helpfull).

Thanks in advance
J.

Vaska A
I WROTE THIS
2010-02-08 10:58:06
Permalink Post
 
  1. // page query
  2. $rs = $OBJ->db->fetchRecord("SELECT * 
  3.     FROM ".PX."objects, ".PX."objects_prefs, ".PX."sections 
  4.     WHERE url = '$uri'
  5.     AND status = '1' 
  6.     AND section_id = secid 
  7.     AND object = obj_ref_type");

Look for "page query" in the root index.php file and then replace the query with this one which has the sections parts added.

Now, you can access 'sec_desc' to get the name of the section. Consult the database for the other variables this makes possible as well.

joshdehn
FRANCE
2010-02-08 12:00:11
Permalink Post
 

Great, it works fine!
Thank you very much Vaska.
Have a nice day,
J.

rickykappa
ITALY
2010-02-08 12:34:39
Permalink Post
 
  1. as the example above, I've adjusted the root index.php and I've tried this in the site/mysite/index.php
  2. <div class='<%sec_desc%>'></div>

Tried as well this call in the text area and in the plugin (where I'd like to have also that section name)

  1. $a .="<p><a href='#' onclick="swap(); return false;"><b>«</b> Back to <b><%title%></b> | <b><%sec_desc%></b> thumbnails</a> | ";

(I think the code above will be a mess, though the point should be understandable)
tried as well many combinations, but can't make it work...
what am I missing?

beam
UNITED KINGDOM
2010-06-02 16:39:07
Permalink Post
 

Could it be possible to generate a variable for media_file?

by adding

  1. ".PX."media

as well as

  1. AND media_ref_id = id

? but i dont think its that simple.

Vaska A
I WROTE THIS
2010-06-02 17:02:50
Permalink Post
 

Not really. What are you trying to do...

beam
UNITED KINGDOM
2010-06-02 21:39:24
Permalink Post
 

I would like to have the media_file name as a system variable to use within a plugin on a page.

Ive tried using a plugin for the same purpose but its a bit long winded.

Vaska A
I WROTE THIS
2010-06-02 22:52:00
Permalink Post
 

But, you could have possible many "media_file"s for a single page. More specifically, what are you trying to do...

beam
UNITED KINGDOM
2010-06-04 11:36:02
Permalink Post
 

i understand that, i wanted a system varible that was for the first media_file on each page to enter into a custom plugin which would pass to an external page out side of the indexhibit folder.

its no matter tho, i ended up trying another method, by adding a query to the plugin to pull the media file direct from the database.

Another question, is it possible to pass one variable from a plugin to another? for example if i had a form with in a plugin in the pre nav box, and wanted the results displayed on another page by another plugin.

Vaska A
I WROTE THIS
2010-06-04 12:46:39
Permalink Post
 

Yes, that would be my suggestion...have the plugin query get the media_file info you need.

Display the results in another page? You mean, passing the info via $_POST or $_GET?

beam
UNITED KINGDOM
2010-06-04 14:13:19
Permalink Post
 

yeah, building a search function

this is what i have so far, it gets results for title, but im having errors getting any by searching two tables/columns in the query, eg sec_desc and title.

sec_desc is the one im having difficulty with.

  1. function search()
  2. {
  3. $term = $_POST['term'];

$OBJ =& get_instance();

global $rs;
$pages = $OBJ->db->fetchArray("SELECT id, media_file, url, media_order, media_id, title, media_title, sec_ord, secid, ord, sec_desc
FROM ".PX."objects, ".PX."sections, ".PX."media         
WHERE media_ref_id = id
AND title LIKE '%$term%'
AND hidden != '0'
        AND status = 1
        AND section_id = secid
        AND media_order = (SELECT MIN(media_order) FROM ".PX."media WHERE media_ref_id = id )
        ORDER BY sec_ord ASC, ord ASC         ");

beam
UNITED KINGDOM
2010-06-04 14:14:34
Permalink Post
 

code again.

  1. function search()
  2. {
  3. $term = $_POST['term'];
  4. $OBJ =& get_instance();
  5.     global $rs;
  6.     $pages = $OBJ->db->fetchArray("SELECT id, media_file, url, media_order, media_id, title, media_title, sec_ord, secid, ord, sec_desc
  7.          FROM ".PX."objects, ".PX."sections, ".PX."media          
  8.          WHERE media_ref_id = id
  9.         AND title LIKE '%$term%'
  10.         AND hidden != '0'
  11.         AND status = 1
  12.         AND section_id = secid 
  13.         AND media_order = (SELECT MIN(media_order) FROM ".PX."media WHERE media_ref_id = id )
  14.         ORDER BY sec_ord ASC, ord ASC         ");
Vaska A
I WROTE THIS
2010-06-04 14:55:35
Permalink Post
 

The seearch should be returning just info regarding to pages?

Also, I think I would broaden the search and go through 'content' as well...

  1. AND (title LIKE '%$term%' OR content LIKE '%term%')

And be sure you validate the $term. You can tap into the validation functions from the frontend as well...

  1. $P = load_class('processor', true, 'lib');

And there you go...validation functions... ;)

Vaska A
I WROTE THIS
2010-06-04 14:56:47
Permalink Post
 

Just realized, maybe I answered your question but used 'content' instead of 'sec_desc'?

beam
UNITED KINGDOM
2010-06-04 16:44:42
Permalink Post
 

thanks vaska.

just added that, i think ive put the validation in the right place?

ive also played with the keywords entered so it doesnt need an exact match to return results.

see bellow.

  1. function search()
  2. {
  3. $var = @$_GET['term'] ;
  4.       $trimmed = trim($var);
  5. $trimmed_array = explode(" ",$trimmed);
  6. $P = load_class('processor', true, 'lib');
  7. foreach ($trimmed_array as  $trimm){
  8. $OBJ =& get_instance();
  9. global $rs;
  10.     $pages = $OBJ->db->fetchArray("SELECT id, content, media_file, url, media_order, title, media_title, sec_ord, secid, ord, sec_desc
  11.          FROM ".PX."objects, ".PX."sections, ".PX."media          
  12.          WHERE media_ref_id = id 
  13.          AND (title LIKE '%$trimmed%' OR sec_desc LIKE '%$trimm%' OR content LIKE '%$trimm%')
  14.          AND hidden != '0'
  15.         AND status = 1
  16.         AND section_id = secid 
  17.         AND media_order = (SELECT MIN(media_order) FROM ".PX."media WHERE media_ref_id = id )
  18.         ORDER BY sec_ord ASC, ord ASC
  19. ");

if people are interested i can release this as a simple search function with or with out images, maybe link / title instead?

Vaska A
I WROTE THIS
2010-06-04 17:26:58
Permalink Post
 

Sure, if you are up for it...but...I don't see any actual validation going on there.

beam
UNITED KINGDOM
2010-06-04 21:17:55
Permalink Post
 

by validation what do you mean, that theres a keyword entered? or if results will show.

i have this which returns 'no results' if there is either nothing found or no term entered.

  1. $t ='';
  2.     $t .= "No Results for: $trimmed";
  3.     $b =  'No Results';
  1. if (!$pages) return $t;
  2.     if ($trimmed == "") return $b;
  3. ;
Vaska A
I WROTE THIS
2010-06-04 23:52:10
Permalink Post
 

No, I mean people could easily take control of your website via mysql injection if you don't validate the inputs.

beam
UNITED KINGDOM
2010-06-07 15:32:39
Permalink Post
 

ok, so ive had a look at mysql injection and included addslashes and mysql_real_escape_string for validation.

ive also added an AND to the query for a more refined search result for more than one keyword entered.

i can only search one field though, as it returns with a fatal error from the server for more than one, as the search exceeds the allowed limit for the script. i cant find a way round this, a part from asking my host to raise the limit?

  1. function search()
  2. {
  3. $var = addslashes(htmlspecialchars(@$_GET['term'])) ;
  4. $trimmed = trim($var);
  5. //validation on unwanted characters 
  6. $trimmed = mysql_real_escape_string($trimmed);
  7. //separate key-phrases into keywords
  8. $trimmed_array = explode(" ",$trimmed);
  9. // count keywords
  10. $trimm_total = count($trimmed_array);
  11. $i = 0;
  12. $searchstring = '';
  13. // looping to get the search string
  14. foreach ($trimmed_array as $trimm)
  15. { if ($i != 0 and $i != $wordcount)
  16.     { 
  17.         $searchstring .= " AND ";
  18.     } 
  19.     $searchstring .= "content LIKE '%$trimm%'"; 
  20.     // incrementing the value 
  21.     $i = $i + 1; }
  22. $OBJ =& get_instance();
  23.     global $rs;
  24.     $pages = $OBJ->db->fetchArray("SELECT *
  25.         FROM ".PX."objects, ".PX."sections, ".PX."media          
  26.         WHERE $searchstring
  27.         AND media_ref_id = id
  28.         AND status = 1
  29.         AND section_id = secid 
  30.         AND media_order = (SELECT MIN(media_order) FROM ".PX."media WHERE media_ref_id = id )
  31.         ORDER BY sec_ord ASC, ord ASC 
  32.         ");
  33.     $t ='';
  34.     $t .= "No Results Found";
  35. $b =  'No Results - Please Enter a Search Value' ;
  36.     if (!$pages) return $t;
  37.     if ($var == "") return $b;

Showing 1 - 21 of 21 posts in Forum > Customize > Automatically section name
 

You need to be logged in to post.