-
Posts
10,902 -
Joined
-
Last visited
-
Days Won
349
Everything posted by adrian
-
Adding language broke database and PW admin
adrian replied to mikeuk's topic in Multi-Language Support
Just wanted to follow up by saying that when you're running an old version of software, things like this can happen due to changes in dependencies. I know that your issue has come up in the past: https://github.com/ryancramerdesign/ProcessWire/issues/957 and was fixed at the time. I am not sure if your version is possibly from before this fix or not, but regardless there have been some relatively recent changes to the default settings in new MySQL versions that have had similar effects, so it pays to always install the current stable version. -
Adding language broke database and PW admin
adrian replied to mikeuk's topic in Multi-Language Support
Sorry you had a bad experience with languages. A couple of things here: 1) What version of 2.7 are you running - make sure it is 2.7.3 2) 2.7 is pretty old now - you should be running 2.8 or 3.x - both have many fixes since 2.7 3 ) This should be an easy fix - just add a new field to the "pages" database table called "name1022" with these settings: varchar(128) ascii_general_ci null = yes Hope that helps! -
Of course, I wasn't thinking - I have done the same thing myself on occasion
-
Maybe I am confused here, but I think you want the following - you have to get the comments from a given page - obviously in this case, the current one ($page) $latest_comments = $page->comments->find("limit=5, sort=-created"); echo $latest_comments->render(); or translated to: $letzte_kommentare = $page->kommentare->find("limit=5, sort=-created"); echo $letzte_kommentare->render();
-
Surely if it's a count operation then you could just subtract the number of pages that need to be excluded - no need to add them to the selector. Or is count() just an example and you do actually need to return the pages?
-
Pulling in Gravatar Avatars
adrian replied to VirtuallyCreative's topic in Module/Plugin Development
The approach is fine, just a couple of minor problems, one being the if($img) conditional. The others are the "return" at the end of the first couple of checks that are exiting right there. Try this: <?php /** * Module for generating Gravatar URLs for ProcessWire users. * * Use it like this: * * Get URL only with all defaults: * $user->gravatar() * * Get image tag with different size: * $user->gravatar(array('img' => true, 's' => 200)); * */ class Gravatar extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Gravatar', 'version' => 1, 'summary' => 'Gravatar hook for users', 'singular' => true, 'autoload' => true, 'icon' => 'smile-o', ); } public function init() { $this->addHook('User::gravatar', $this, 'methodGravatar'); } public function methodGravatar($event) { $u = $event->object; if ( ! $u instanceof User) return; if ( ! $u->email) return; $params = ($event->arguments(0) ? $event->arguments(0) : array()); // Default options $defaults = array( 's' => 100, 'd' => 'retro', 'r' => 'g', 'img' => false, 'attrs' => array(), ); $opts = array_merge($defaults, $params); extract($opts); $url = '//www.gravatar.com/avatar/'; $url .= md5(strtolower(trim($u->email))); $url .= "?s=$s&d=$d&r=$r"; $url = '<img src="' . $url . '"'; foreach ($attrs as $key => $val ) { $url .= ' ' . $key . '="' . $val . '"'; } $url .= ' />'; $event->return = $url; } } -
Pulling in Gravatar Avatars
adrian replied to VirtuallyCreative's topic in Module/Plugin Development
It looks like: if ($img) { is preventing the $url from being defined. -
Try $users instead - that should work with non-superusers. $event->users->find('roles=client');
-
How do I inline an SVG (that was uploaded by an image field)
adrian replied to Alf S.'s topic in General Support
Rather than trying to hack the url for file_get_contents, you should use ->filename instead and then you can just do: file_get_contents($page->icon->filename); -
Actually I take that back - the function (and therefore the db query) won't be called unless you call $page->courseData so no need for this.
-
You will likely want to add some sort of conditional inside that AddHookProperty to check the template of the page so you only run the query on appropriate pages. eg.: if($event->object->template == "template_that_needs_course_data") {
-
will give an "Array to string conversion on line: 3" error. In Tracy you can dump the array with d(), but in your template code you will likely want to leave off the ->each("title") and foreach through $sayfalar to return various fields.
-
You can add a hook like this in your /site/init.php file: $this->wire()->addHookProperty('Page::courseData', null, function($event) { $sql = "SELECT * FROM ......"; $results = $this->wire('database')->query($sql); $event->return = $results->fetchAll(); }); And then in your template file you can call: $page->courseData You can also make of $event->object->name inside the hook to get the name of the page that the courseData property is called from so you can use that in your sql query. Of course you can get any other field from the page, like $event->object->myfieldname and use that in your query as well. Does that help?
-
"how to store it inside processwire" - I am not sure what you mean here - do you mean save the content to PW pages? You can query content from an external database and simply iterate over it and output in your template file. Here is the docs on $database: https://processwire.com/api/ref/database/ Here is a rough idea of what you can do. Obviously I am querying the PW "pages" table, but you can do this on any table in the database whether PW or not. You can see in the output that you can easily iterate through each row in the returned array and grab whatever array keys (db fields) you want.
-
You can easily make use of PW's $database to call an external database to populate content on a page - nothing fancy and no hooks required. It might help if you can provide more details of the data in these tables and how you want it displayed.
-
@Beluga - are those massive execution times with BCE or Ryan's module? I am using a third party csv parser - I don't think its approach is very efficient, but php's built-in parser is crap when it comes to certain situations. There might be better options out there though. BCE doesn't make any SQL queries directly so not sure any of those mentioned tweaks would be any use. Also given that in PW each field has its own table I don't know how you could make use of LOAD DATA INFILE etc because you'd have to do a lot of data manipulation before inserting so that you were populating one table at a time with all required data - sounds like a real likelyhood of introducing data integrity problems. That said, if you find something that makes a dramatic difference, please let us know.
-
I feel like the "quiet" save option should also work for published. It works for created, but not modified or published. This SQL will do the trick though: $sql = "UPDATE `pages` SET `published` = '2015-01-01 12:30:00' WHERE `id` = '2101';"; $database->query($sql);
-
@Beluga - it sounds like you sorted out your problem with the Import Pages From CSV module, but if you decide to come back to BCE let me know and I'll see what I can do about adding support for no title pages.
-
I kinda also wonder if that $settings variable should be changed in ListerPro - seems like it should be $listerSettings or something?
-
Enable debug mode for only superusers or a given username
adrian replied to lpa's topic in General Support
I know this is ancient, but I wanted to note that if this worked in the past, it no longer works. I think I recently even saw reference to placing $config->debug = true in ready.php. None of these options work properly. If you want conditional debug mode, you need to use the debugif option: https://github.com/processwire/processwire/blob/35df716082b779de0e53a3fcf7996403c49c9f8a/wire/config.php#L56-L71 Keep in mind that setting it to true in a module or ready.php etc might make it look like it's working because the "Debug Mode Tools" link and icon will appear in the admin, but it will not output any errors/notices/warnings to the browser. Also, in the debug panel you'll notice that the "Database Queries", "Timers", and "Autoload" sections are not populated because they require debug mode to be on Also, of course, with Tracy enabled you don't really need debug mode on (or if you do have it on), it will take care of capturing any errors, and hiding them from users, anyway. The only thing you will be missing with it off, are those "Database Queries", "Timers", and "Autoload" sections.* Anyway, hope that helps to avoid any confusion for those who come here in the future. * This really wasn't meant to be a Tracy advert, but thought it was relevant because it solves the reason why you would want debug mode on only for superusers or the like. -
Actually, it's pretty nice running your API call through the Tracy Console - save it as a snippet so you always have it on hand. This way you can easily see the results of the selector as well as the SQL query used to generate them. PS I think this is the thread that was mentioned regarding teppo's version: https://processwire.com/talk/topic/9408-is-there-a-way-to-convert-a-selector-in-sql-using-pw-engine/ although I think it's actually longer.
-
$page->children("start=2, limit=2") Although I don't really see the reason to do that when css columns make it so easy. Also, rather than that, you should probably do an in memory selector to reduce unnecessary db calls, so: $children = $page->children(); $children->filter("start=2, limit=2"); Also, if you haven't discovered TracyDebugger yet, the console panel is the perfect place to test and learn this stuff:
-
Ah yes - sorry, my fault about the php modulus approach - you need to count the number of items and divide by three and do a ceil() to make it an integer and use that number because it is breaking on rows and not actually columns. To be honest, I don't really see the point in using the PHP approach these days since css columns is well supported. As for the first column having the dot list-style-type - do you want them all to have dots, or none? It looks like perhaps you have another css rule that is interfering, but I am sure you have that figured out by now.
-
Yeah, I guess it is very weird that "awe-some" is great, but "aw-ful" is a complete lack awe, or maybe it's full of awe about how bad it is - English is weird!! As for the vertical column order, it seems fine here. Maybe you could show what you are getting and what you expect in case I am misunderstanding.
-
Not sure if there is a translation problem there, but not typically the way to say thanks If you need to sort, just add: "sort=name" as the selector for children(), eg $page->children("sort=name")