Jump to content

FrancisChung

Members
  • Posts

    472
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by FrancisChung

  1. Coming from the .NET world, I'm used to using Namespaces and it's pretty much defacto but was surprised it wasn't as widely adopted by PHP Developers. So I thought I was doing the right thing by using a custom namespace in case there's any name clashes with other libraries I use. How would I resolve name clashes if I used \Processwire ?
  2. Yes, that is 1 of the first things I cross checked. I assume you mean the Index.php file in the root directory. Also double checked to make sure it's V3.
  3. Once again, bitten by PHP's idiosyncrasies. Not sure why wire(config) worked with older version of PHP (5.5) but not newer. Thanks Adrian for the quick response
  4. <?php namespace Site; require_once(__DIR__."/../../../../index.php"); use function \Processwire\wire; Define(SITE_DIR, $config->paths->templates); Define(IMG_DIR , $config->urls->templates."img/"); Define(IMG_SQDIR, $config->urls->templates."img/square/"); Define(IMG_SDIR, $config->urls->templates."img/small/"); Define(IMG_MDIR, $config->urls->templates."img/medium/"); Define(IMG_LDIR, $config->urls->templates."img/large/"); Define(IMG_PATH, SITE_DIR."img/"); Define(IMG_SQPATH, SITE_DIR."img/square/"); Define(LOGO_PATH, IMG_DIR."linguino-wortbild_weiss_fb_twothirds.png"); Define(DEV_SITE, "kinder-reime.com"); Define(UAT_SITE, "finger-spiele.com"); Define(LIVE_SITE, "sprachspielspass.de"); It's failing on the first DEFINE statement where it doesn't know what $config is.
  5. SITE_DIR is not defined because it is failing on the wire(config) or $config line of code. I've tried the following debug code echo $config->paths->templates; echo wire(config)->paths->templates; and it's returning the following for both Use of undefined constant config - assumed 'config' in /Users/FrancisChung/Sites/PHP7PW3/site/templates/php/const/Const.php on line 29 Apologies for any confusion in the previous post.
  6. Hi @LostKobrakai, I'm having another crack at upgrading our website stack to PHP 7 and PW3. I tried your suggestion of using also tried adding a \ at the front. In both instances, I get Notice: Use of undefined constant SITE_DIR - assumed 'SITE_DIR' in /Users/FrancisChung/Sites/PHP7PW3/site/templates/php/const/Const.php on line 29 Call Stack I've tried using $config and wire(config) and it's throwing up the same error. Any ideas? I'm trying to access wire(config)->paths->templates
  7. Update : Just tried to revisit this and it's an issue with PHP v7.0.10 Will try and upgrade to PW3 and see if that fixes it ....
  8. Redgate is giving out non commercial licenses for its MySQL Compare and MySQL Data Compare tool. I've used their SQL Server Compare tools and the ToolBelt extensively many years ago, and it saved my back side time and time again. I only happen to come across it because I was looking out for a MySQL Compare tool to work out the difference between my Test & Live Servers. The unfortunate caveat is that it only runs on Windows ...... perhaps it will still be of use to someone. I will try running it on Parallels and see if it can access a MySQL Instance running on the OS X Parent .... http://www.red-gate.com/products/mysql/mysql-comparison-bundle/
  9. If you look at the API Cheatsheet, there's a section for $user. It has several properties of interest to you situation. You should have a look at these and check for user permissions and hide / show those sensitive fields accordingly. $user->rolesGet roles this user has. Returns PageArray. more $user->hasRole($role)Does the user have the given role? Returns true or false.more $user->hasPermission($permission)Does the user have the given permission? Returns true or false. more $user->hasPermission($permission, $page)Does the user have the given permission name on $page? Returns true or false. more
  10. What do you mean by turning Debug mode on exactly? Are you talking about using XDebug or Zen Debugger to debug the site?
  11. Hi @abdus and @Gazley, I was wondering if you guys managed to get XDebug (and PHPStorm) working with PHP 5.6? Or should I not bother and go straight to v7.0?
  12. Thanks for the info. I think it'll come in handy when I try and attempt to upgrade to PW3. Tried a few weeks ago, and I had plenty of issues because I'm using Wire(xxx) instead of $this->wire(xxx) in many places, so I rolled back. I also did noticed a manual install resulted in some modules upgrading itself. I use PHPStorm but I haven't been able to get XDebug working with PHP 5.6. I wonder if the Short Tag Enabling is a factor in it.
  13. Is that a setting in the php.ini file? Incidentally from which version to which new version were you upgrading PHP to?
  14. Thanks for the article, Bitpoet. Bookmarked it and had a scan through read. Here's hoping I won't ever need it in the future
  15. Hi @Adrian, I'm planning to upgrade our base PW when I get a chance so I will try out again then. The "Protect Hidden / Unpublished Pages and also their children options" are redundant options for the site, come to think of it. I'll also try using Tracy as it's something on the planner to have a detailed look at it.
  16. I was installing Page Protector on 1 of my websites, and I selected the options Protect Hidden / Unpublished Pages and also their children options and I got the following error. I had to rollback the Database and just leave all the options as default and it seems to work then. I'm using PW 2.7.x on that site. I think on my other site, I was just using the default options so I didn't have this problem previously. Error: Exception: Method Page::hasStatus does not exist or is not callable in this context (in /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/wire/core/Wire.php line 350) #0 [internal function]: Wire->___callUnknown('hasStatus', Array) #1 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/wire/core/Wire.php(387): call_user_func_array(Array, Array) #2 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/wire/core/Wire.php(325): Wire->runHooks('callUnknown', Array) #3 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/wire/core/Wire.php(329): Wire->__call('callUnknown', Array) #4 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/wire/core/Wire.php(329): Page->callUnknown('hasStatus', Array) #5 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/site/modules/PageProtector/PageProtector.module(179): Wire->__call('hasStatus', Array) #6 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/site/modules/PageProtector/PageProtector.module(179): Page->hasStatus(2048) #7 /is/htdocs/wp12420480_J71V5E124H/www/sprach-dev/wire/core/Wire.php(409): Pag This error message was shown because you are logged in as a Superuser. Error has been logged.
  17. In case any new users end up here, just make sure you've logged out all users of the admin area before you're convinced the module doesn't work. Had my 15 minutes of *FacePalm* today.
  18. Couple of more suggestions : 1) Have you tried grabbing 1 of the fields with the problematic "spaces" and pasting it on a text editor like Sublime Text? Are you definitely sure it's just 'whitespace'? 2) Have you tried using functions like str_replace when doing the copying, like replacing the space with a space?
  19. How are you doing the import? I remember I had a tough time with UTF-8 and German Umlauts when I implemented a Spreadsheet Content importer. I had to get the CSV file in a particular format (UTF8-BOM or Byte Order Marker) for it work. Below is what i wrote in the Header of that spreadsheet code.
  20. I thought I should post my implementation based on Bernhard's code. It tries to work out the length of the first tag and modifies the ->asXML parameters accordingly. The Import Code is as follows : class ImportFromXML { private $file; public function __construct($file) { $this->file = $file; } public function Execute() { $import = true; $xmlFile = $this->file; if ($import) { if (!file_exists($xmlFile)) exit($xmlFile . ' failed to open'); $items = simplexml_load_file($xmlFile); foreach ($items as $xml) { $p = new \Processwire\Page(); //$p = new \Page(); $p->of(false); $p->template = wire(templates)->get("id=" . $xml->template); $p->parent = wire(pages)->get("id=" . $xml->parent); $p->title = $xml->title; //Struggle to call Sanitizer $p->name = wire(sanitizer)->pageNameUTF8($xml->title, true); $p->name = $xml->title; //while ($xmls->find('parent=' . $p->parent . ',name=' . $p->name)->count() > 0) $p->name .= '-1'; //$p->content = $this->PopulateContent($xml->content); $p->content = $this->PopulateMarkup($xml->content); //$p->content_intro = $this->PopulateIntro($xml->content_intro); $p->content_intro = $this->PopulateMarkup($xml->content_intro); $p->author = $xml->author; $p->content_path = $xml->content_path; $p->seo_title = $xml->seo_title; $p->seo_keywords = $xml->seo_keywords; $p->seo_description = $xml->seo_description; $p->seo_image = $xml->seo_image; $p->seo_custom = $xml->seo_custom; $p->image = $xml->seo_custom; $p->image_alt = $xml->image_alt; $p->keywords = $xml->keywords; $p->title_nav = $xml->title_nav; $p->seo_section_title = $xml->seo_section_title; //$p->save(); // try creating PageArray first ???? //$cats = new \PageArray(); $cats = new \Processwire\PageArray(); foreach ($xml->category->id as $id) { //$cat = wire(pages)->get("name='" . $catname . "', parent='/Categories/'"); $pageid = (string) $id; $cat = wire(pages)->get($pageid); if (!IsNullPage($cat)) $cats->add($cat); //$p->categories->add($cat);- } $p->category->import($cats); $p->save(); echo 'new page <a href="' . $p->editUrl . '" target="_blank">' . $p->path . '</a><br>'; } //die(); } } private function PopulateMarkup($node) { $xml = $node->asXML(); //Check for tags if($xml != strip_tags($xml)) { //$startTag = strpos($node,"<"); $endTag = strpos($xml,">"); if ($endTag > 0) return substr($xml, $endTag+1, -1*($endTag+2)); } return $node; } } And the Export : class ExportToXML { private $pages ; public function __construct($pages) { $this->pages=$pages; } public function Execute() { $import = true; if($import) { echo "<?xml version='1.0' ?>"; echo '<pages>'; //$parent = $pages->get('/blog'); $results = $this->pages; //$results = $pages->find('id=3198'); // ohne pic //$results = $pages->find('id=3204'); // mit pic foreach($results as $p): $p->of(false); ?> <page> <name><?= $p->name ?></name> <title><?= $p->title ?></title> <template><?= $p->template->id ?></template> <parent><?= $p->parent ?></parent> <category><?php foreach($p->category as $category) { echo '<id>' . $category->id . '</id>'; } ?></category> <content><?= $p->content ?></content> <content_intro><?= $p->content_intro ?></content_intro> <author><?= $p->author ?></author> <content_path><?= $p->content_path ?></content_path> <seo_title><?= $p->seo_title ?></seo_title> <seo_keywords><?= $p->seo_keywords ?></seo_keywords> <seo_description><?= $p->seo_description ?></seo_description> <seo_image><?= $p->seo_image ?></seo_image> <seo_custom><?= $p->seo_custom ?></seo_custom> <seo_canonical><?= $p->seo_canonical ?></seo_canonical> <image><?= $p->image ?></image> <image_alt><?= $p->image_alt ?></image_alt> <keywords><?= $p->keywords ?></keywords> <title_nav><?= $p->title_nav ?></title_nav> <seo_section_title><?= $p->seo_section_title ?></seo_section_title> </page> <?php endforeach; echo '</pages>'; //die(); /** * <date><?= $p->created ?></date> <featured>1</featured> */ } } } In particular, I had a field that was a PageArray linking to other Pages. <category><?php foreach($p->category as $category) { echo '<id>' . $category->id . '</id>'; } ?></category> Hope it helps some one out!
  21. I'm guessing there's not a PHP 5.5 solution for this problem? Reason why I'm still using PHP 5.5 is because it's the latest version I could get XDebug + PHPStorm 2016.2 + MAMP Pro 3.4 to work nicely. I've just tried again to see if I could get PHP 5.6 working but it didn't work. I could upgrade to MAMP Pro 4 to see if it's a difference maker, but I have doubts it will actually fix my issue.
  22. Did you upgrade your Processwire by any chance? Or installed any new modules?
  23. I've updated my site's PW version from PW 2.6.x to the latest version. I've updated manually by copying the wire directory and overwriting index.php and .htaccess. When I try and load up the page I'm getting the following error. Error: Call to undefined function Site\wire() (line 5 of /Users/FrancisChung/Sites/Develop/site/templates/php/const/Const.php) My Const.php looks like : namespace Site; require_once(__DIR__."/../../../../index.php"); Define(SITE_DIR, wire(config)->paths->templates); Define(IMG_DIR , wire(config)->urls->templates."img/"); Define(IMG_SQDIR, wire(config)->urls->templates."img/square/"); Define(IMG_SDIR, wire(config)->urls->templates."img/small/"); Define(IMG_MDIR, wire(config)->urls->templates."img/medium/"); Define(IMG_LDIR, wire(config)->urls->templates."img/large/"); Define(IMG_PATH, SITE_DIR."img/"); Define(IMG_SQPATH, SITE_DIR."img/square/"); I'm guessing the wire(config) calls are failing because of the new Namespace implementation? Is there a way of fixing this without having to change every wire(config) or other wire(fnXXX) calls?
  24. I normally start the day with some classical music, then progress into something else when the classical music sets me up nicely for the rest of the day. I recommend Idagio (https://www.idagio.com/) where it allows you to configure your music to your moods or other parameters. Whilst it's not quite music, but for those looking for something less "intrusive" can try Noisli (https://www.noisli.com) for some allegedly productive background noise.
  25. If the file itself doesn't change (i.e. you're not adding new fields to Page or Template), then it shouldn't be an issue. One of my partners uses this on a regular basis, so I can't see why your user won't be able to either. If the fields are being changed or removed, you'll need a more generic solution. You could perhaps code in such a way that you match the field name of the Excel file to the field name of the Template/Page you're trying to update. i.e. column 1 title corresponds to a field called title on the page and so on. You would loop through the columns and row(s) and update fields and page(s) accordingly.
×
×
  • Create New...