Recent Topics

1 Feb 12, 2008 19:18    

My b2evolution Version: 2.x

Hello,

Just wondering, is it possible to have the skin output *just the URL* of the edit, post, feedback permalinks, etc...

The current method sometimes includes an icon, sometimes not, I would like to hand code these in my skin to use my own classes, etc... (and not have the image output)

2 Feb 12, 2008 19:33

Short Answer: yes.

Long Answer: check out the specific function for each item and you'll see there are some 'canned' ways to call things. For example the permanent_link function says this:

		$params = array_merge( array(
				'before'      => '',
				'after'       => '',
				'text'        => '#',	// possible special values: '#', '#icon#', '#text#', '#title#'
				'title'       => '#',
				'class'       => '',
			//	'format'      => 'htmlbody',
			), $params );


The special values can be fed as parameters for the text of the link, or you can create your own text for that location.

By the way I use Agent Ransack to search a folder or bunch of folders for a specific string inside a file. So like if I want to know what I can do with

	$Item->edit_link( array( // Link to backoffice for editing
			'before'    => ' • ',
			'after'     => '',
		) );

I would use Agent Ransack to find "function edit_link". Sometimes that will make me search for another function, but eventually I find something that makes me go "aha" (or "wtf!?!?!" but hey if that's where I started it's not a problem yah?).

3 Feb 12, 2008 19:52

Thanks for the reply Edb, though I'm not sure in the example above, what parameters do you pass to permanent_link to get just the URL?

(I did find permanent_url() which seems to do the job)...

And what about edit_link and so forth? Looking at the function in _item.class.php this doesn't seem to be possible? (and looking at the function, it's not evident where it's throwing in that edit image either)

4 Feb 12, 2008 20:35

http://www.mythicsoft.com/agentransack/ is great fun!

"function edit_link" takes me to line 1931 in inc/items/model/_item.class.php which shows me

	function edit_link( $params = array() )
	{
		echo $this->get_edit_link( $params );
	}


So then "function get_edit_link" tells me the same file line 1878, which shows me that I this time there are no special values, so to get just the edit link (not clickable yah?) I would try

$Item->get_edit_link( array( // Link to backoffice for editing
			'text'    => '',
		) );

And see what it gets me.

Things aren't as "easy" as they used to be, for sure! You kinda have to follow a function call until it gives up something good, and keep in mind that there are lots of parameters that are 'assumed if not specified'. So if all you want to do is make the edit link be clickable but not use the icon you would do something like this in your skin:

$Item->edit_link( array( // Link to backoffice for editing
			'before'    => ' • ',
			'after'     => '',
			'text'     => 'EDIT',
		) );

Agent Ransack, for me, is absolutely required if I want to follow through the code and see how each bit gets built up into the page it makes.

Hope it helps!!!

5 Feb 12, 2008 20:48

Thanks Edb. yeah I did see that it uses a secondary function and it does not seem possible without hacking the code. So it seems your original "short answer" assertion is incorrect (for the most part).

Ideally, b2evo would use a system where it just generates the links so that you could have a cleaner separation of logic and presentation (and more flexibility) in your templates. i.e.

<a href="<? $Item->edit_link('just_the_url_plz') ?>" class="icon edit">Edit</a>


It's one aspect of b2evo I've always found a bit bloated and sloppy...

Thanks again...

6 Feb 12, 2008 20:58

		$actionurl = $admin_url.'?ctrl=items&amp;action=edit&amp;p='.$this->ID;

Kinda easy to replicate ;)

¥

7 Feb 12, 2008 21:19

Well, yes and no ¥åßßå (though I hadn't realized the admin_url was already global - thanx). A check still needs to be done if the user has permission to edit, or comment, etc... which seems to be tricky in some cases.

For example, I tried the following in my skin, which works fine if you're logged in, but not otherwise:

<?php
  if ($current_User->check_perm( 'item_post!'.$Item->status, 'edit', false, $Item)) {
?>
  <a href="<?= $admin_url ?>'?ctrl=items&amp;action=edit&amp;p=<?= $Item->ID ?>" class="icon edit">Edit</a>
<?php 
  }
?> 

8 Feb 12, 2008 22:48

Wait a minute. Seems like what you're trying to do is build a way to reach what the edit_link function already does! In your index.main.php file, this will give a link to edit each post that uses the provided text and is not available to someone who is not logged in:

$Item->edit_link( array( // Link to backoffice for editing
         'before'    => ' &bull; ',
         'after'     => '',
         'text'     => 'EDIT',
      ) );

In my current skin I use an image for the edit link that is not the 'stock' image:

$Item->edit_link( array( 
		'before' => '&nbsp;',
		'after' => '',
		'text' => '<img src="img/32_edit.png" title="edit" alt="edit" class="visuals" />',
		'title' => 'edit',
		'class' => '',
	) );

Perhaps I misunderstood what you meant by getting "just the URL"? If you want it as a value you can plug into a manually crafted link with custom text that you can then contain inside logic that figures out if the visitor is authorized to edit a post, well, why bother when the function does it just fine?

So I guess I should ask "what is it you're trying to do with the edit link that the function can't do already" instead of assume I understand yah?

BTW you probably want to wrap the whole $current_User->check_perm() bit inside "if( is_logged_in() ) { ..... }" so that you can know that the $current_User will mean something if you need to go that way. There are probably better ways to do that, but it works for me when I need it ;)

9 Feb 12, 2008 23:00

Erp.. sorry Edb... no we just went off on a tangent. What I was looking to really have as the $Item->edit_link return only the URL of the edit link if the item was editable and false otherwise:

if ($Item->edit_link()) {
  // Output my own HTML edit link
}


I know of the inserting img src for the text trick, but it's a bit messy and would like to have a link where I can have no icon and assign my own class.

After looking at the edit_link code in more detail, though it seems I have to explicity assign the text and then I can apply my class(es) and it should generate fairly clean code (I have a class icon and another edit, etc... that basically makes the icon a background image for the hyperlink and applies padding, etc...)

Thanks both again for your help :)

$Item->edit_link(array(
         'text' => 'Edit',
         'class' => 'icon edit'
      ));


Sorry - just getting the hang of the 2.X setup - hence my other recent queries :)

10 Feb 13, 2008 15:32

For the sake of completeness to this post, just following up as to what I found to get the clean, style-based links I wanted (which generate an icon).

There's a bit of inconsistency with b2evo at this point as the link functions generate the links in slightly different ways:

The "feedback_link" (for showing/link to # of comments in a post) does not allow for specification of a style class nor does it generate an icon, so I wrap it in a span with the desired style:

echo '<span class="icon comments">';
$Item->feedback_link(array('type' => 'comments'));
echo '</span>';


This isn't ideal as the icon generated by the stylesheet is not clickable as with the examples below.

The edit_link and permanent_link functions for posts and the permalink for comments do work as desired in allowing you to specify a class and no-icon - the text must be explicitly set so the icon doesn't appear:

$Item->permanent_link(array('text'  => 'Link to Post',
                            'class' => 'icon link'));


The edit and delete links work as desired, but do not accept an array as arguments, and again the link text must be explicitly set so the icon does not appear:

$Comment->edit_link( '', '', 'Edit', '#', 'icon comments' );

(For anyone curious, my CSS for these links is:)

.icon {
  padding-left: 20px;
}

.link {
  background: url('/themes/CCT/images/icons/chainlink.gif') 0 50%
  no-repeat;
}

11 May 04, 2008 05:00

i think this is related, but i've been searching for too long. please move if necessary. I'm trying to display the date as a link to the permalink and the title shows the time of the post.

can i do this within the functions that exist already on the page, or do i need to use edb's method and search like crazy until i find the functions within the functions that do not echo.

ps. thanks edb for linking to agent ransack. i've never searched for anything like that, though i knew something like it existed. does it work in ubuntu?

12 May 05, 2008 14:41

alright, so my php knowledge is enough to just use mysql queries to find out the things i need to know... but i know for sure b2evolution has a way to do this using the functions in place already... i'd really like to get my permalink to be just the date, with the time in the title attribute. for my comments, i'd like to change the "leave a comment" text to be Comments unless there was already a comment at which point it would say 1 comment and multiple comments say x comments.

13 May 07, 2008 04:20

haha i'm retarded. i can do the comments one easily. i completely spaced looking over the parameters in the comment link. i still can't figure out how to do the date with a title tag showing the time and the link being the permalink, but since the title of the post links to the permalink, i think i'll settle for what i have now.

does anyone have any ideas of software similar to what edb posted for searching through files which will work in ubuntu?


Form is loading...