Пример #1
0
 /**
  * Tests that no output file is written if logging is disabled
  */
 public function testDisabledLogging()
 {
     unlink($this->tempName);
     Configuration::setOption("partkeepr.logger.enable", false);
     Logger::log("test", Logger::LOGLEVEL_CRITICAL);
     $this->assertEquals(false, file_exists($this->tempName));
 }
Пример #2
0
 public function testConfiguration()
 {
     Configuration::setOption("test", "value");
     $this->assertEquals(Configuration::getOption("test"), "value");
     /* Test for the default value of bool false */
     $this->assertEquals(Configuration::getOption("test2"), false);
     /* Test for an user-specified default value */
     $this->assertEquals(Configuration::getOption("test2", "default"), "default");
 }
Пример #3
0
 /**
  * Syncronizes the tip database against the master wiki.
  * @throws \Exception
  */
 public static function syncTips()
 {
     if (ini_get("allow_url_fopen") == 0) {
         throw new \Exception("allow_url_fopen is disabled, but required to query the TipOfTheDay database.");
     }
     $url = Configuration::getOption("partkeepr.tipoftheday.api", "http://partkeepr.org/wiki/api.php?action=query&list=categorymembers&cmtitle=Category:TipOfTheDay&format=json");
     $tipsString = file_get_contents($url);
     $aPageNames = self::extractPageNames($tipsString);
     self::updateTipDatabase($aPageNames);
 }
Пример #4
0
 /**
  * Returns the database schema status.
  * 
  * This method is usuall called once the user logs in, and alerts him if the schema is not up-to-date.
  * 
  * Returns either status incomplete if the schema is not up-to-date, or complete if everything is OK.
  */
 public function getSystemStatus()
 {
     if (Configuration::getOption("partkeepr.cronjobs.disablecheck", false) === true) {
         // Skip cronjob tests
         $inactiveCronjobs = array();
     } else {
         $inactiveCronjobs = CronLoggerManager::getInstance()->getInactiveCronjobs();
     }
     return array("data" => array("inactiveCronjobCount" => count($inactiveCronjobs), "inactiveCronjobs" => $inactiveCronjobs, "schemaStatus" => $this->getSchemaStatus()));
 }
 public function changePassword()
 {
     if (Configuration::getOption("partkeepr.frontend.allow_password_change", true) === false) {
         throw new \Exception("Password changing has been disabled on this server");
     }
     if (!$this->getUser()->compareHashedPassword($this->getParameter("oldpassword"))) {
         throw new \Exception("Invalid Password");
     } else {
         $this->getUser()->setHashedPassword($this->getParameter("newpassword"));
     }
     return array("data" => PartKeepr::i18n("Password changed successfully"));
 }
Пример #6
0
 /**
  * Logs a message.
  * 
  * @param string $message The message to log
  * @param string $severity One of the Logger::LOGLEVEL_* constants
  */
 public static function log($message, $severity = Logger::LOGLEVEL_INFO)
 {
     if (Configuration::getOption("partkeepr.logger.enable", false) === false) {
         // No logging wanted
         return;
     }
     $logFormat = "[%-19s] [%-8s] %s";
     $outputFile = Configuration::getOption("partkeepr.logger.outputfile", sys_get_temp_dir() . "/partkeepr.log");
     $fp = fopen($outputFile, "a");
     $date = date("Y-m-d H:i:s");
     fputs($fp, sprintf($logFormat, $date, $severity, $message) . "\n");
     fclose($fp);
 }
Пример #7
0
 /**
  * Saves the configuration file.
  * 
  * @throws SerializableException An exception which describes what has been going wrong
  */
 private function saveConfig()
 {
     $configFile = PartKeepr::getRootDirectory() . "/config.php";
     if (file_exists($configFile)) {
         if (!is_writable($configFile)) {
             $message = "The config.php file could not be written, because it already exists and the webserver has ";
             $message .= "no write access to it.";
             throw new SerializableException($message, 10000);
         }
     } else {
         if (!is_writable(PartKeepr::getRootDirectory())) {
             $message = "The config.php file could not be written, because the webserver has no write access to it.";
             throw new SerializableException($message, 10001);
         }
     }
     file_put_contents($configFile, Configuration::dumpConfig());
 }
Пример #8
0
 /**
  * Returns all tips along with the information wether they are read or not.
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::get()
  */
 public function get()
 {
     $aTips = array();
     $url = Configuration::getOption("partkeepr.tipoftheday.wiki", "http://partkeepr.org/wiki/index.php/");
     /* Extract all tips which aren't read */
     $dql = "SELECT d FROM PartKeepr\\TipOfTheDay\\TipOfTheDay d WHERE d.name NOT IN ";
     $dql .= "(SELECT dh.name FROM PartKeepr\\TipOfTheDay\\TipOfTheDayHistory dh WHERE dh.user = :user)";
     $query = PartKeepr::getEM()->createQuery($dql);
     $query->setParameter("user", SessionManager::getCurrentSession()->getUser());
     foreach ($query->getResult() as $result) {
         $aTips[] = array("name" => $result->getName(), "read" => false, "url" => $url . $result->getName() . "?useskin=monobookplain");
     }
     /* Extract all tips which are read */
     $dql = "SELECT d FROM PartKeepr\\TipOfTheDay\\TipOfTheDay d WHERE d.name IN ";
     $dql .= "(SELECT dh.name FROM PartKeepr\\TipOfTheDay\\TipOfTheDayHistory dh WHERE dh.user = :user)";
     $query = PartKeepr::getEM()->createQuery($dql);
     $query->setParameter("user", SessionManager::getCurrentSession()->getUser());
     foreach ($query->getResult() as $result) {
         $aTips[] = array("name" => $result->getName(), "read" => true, "url" => $url . $result->getName() . "?useskin=monobookplain");
     }
     return array("data" => $aTips);
 }
<?php

/**
 * This is a script which updates all category path caches to the configured path separator.
 * 
 * This script needs to be called after changing the partkeepr.category.path_separator.
 */
namespace PartKeepr\Scripts;

use PartKeepr\PartKeepr, PartKeepr\PartCategory\PartCategoryManager, PartKeepr\Util\Configuration, PartKeepr\FootprintCategory\FootprintCategoryManager;
include "../src/backend/PartKeepr/PartKeepr.php";
PartKeepr::initialize();
PartCategoryManager::getInstance()->updateCategoryPaths(PartCategoryManager::getInstance()->getRootNode());
FootprintCategoryManager::getInstance()->updateCategoryPaths(FootprintCategoryManager::getInstance()->getRootNode());
PartKeepr::getEM()->flush();
echo "All categories are updated for the configured category seperator of ";
echo Configuration::getOption("partkeepr.category.path_separator") . "\n";
Пример #10
0
<?php

namespace PartKeepr\Frontend;

use PartKeepr\PartKeepr, PartKeepr\Util\Configuration;
include "../src/backend/PartKeepr/PartKeepr.php";
header("Content-Type: text/xml; charset=UTF-8");
PartKeepr::initialize("");
echo file_get_contents(Configuration::getOption("partkeepr.files.path") . "/feed.rss");
Пример #11
0
<?php

namespace PartKeepr;

use PartKeepr\Util\Configuration;
Configuration::setOption("partkeepr.database.dbname", "partkeepr-test");
Configuration::setOption("partkeepr.database.driver", "pdo_sqlite");
 /**
  * Updates the category paths for a given node and all children.
  * 
  * This method is usually called whenever a category is moved.
  * 
  * @param NodeWrapper $startNode The node to start updating at
  */
 public function updateCategoryPaths(NodeWrapper $startNode)
 {
     $pathSeparator = Configuration::getOption("partkeepr.category.path_separator", " ➤ ");
     $startNode->getNode()->setCategoryPath($startNode->getPath($pathSeparator, true));
     foreach ($startNode->getChildren() as $child) {
         $this->updateCategoryPaths($child);
     }
 }
Пример #13
0
if (!class_exists("Imagick")) {
    $template = $twig->loadTemplate("error.tpl");
    echo $template->render(array("title" => PartKeepr::i18n("ImageMagick is not installed"), "error" => PartKeepr::i18n("You are missing the ImageMagick extension. Please install it and restart the setup to verify that the library was installed correctly.")));
    exit;
}
/* ImageMagick formats */
$imagick = new \Imagick();
$aParameters["availableImageFormats"] = $imagick->queryFormats();
/* Automatic Login */
if (Configuration::getOption("partkeepr.frontend.autologin.enabled", false) === true) {
    $aParameters["autoLoginUsername"] = Configuration::getOption("partkeepr.frontend.autologin.username");
    $aParameters["autoLoginPassword"] = Configuration::getOption("partkeepr.frontend.autologin.password");
}
if (Configuration::getOption("partkeepr.frontend.motd", false) !== false) {
    $aParameters["motd"] = Configuration::getOption("partkeepr.frontend.motd");
}
/* Load and render the template */
$template = $twig->loadTemplate("index.tpl");
$renderParams = array();
$renderParams["debug_all"] = Configuration::getOption("partkeepr.frontend.debug_all", false);
$renderParams["debug"] = Configuration::getOption("partkeepr.frontend.debug", false);
$renderParams["parameters"] = $aParameters;
if ($renderParams["debug_all"]) {
    $renderParams["scripts"] = unserialize(file_get_contents(PartKeepr::getRootDirectory() . "/partkeepr.jsfiles"));
}
if (isset($_SERVER['HTTPS'])) {
    $renderParams["https"] = true;
} else {
    $renderParams["https"] = false;
}
echo $template->render($renderParams);
Пример #14
0
$channel = $rssDOM->createElement("channel");
$rssElement->appendChild($channel);
$pTitle = $rssDOM->createElement('title', 'PartKeepr RSS Feed');
$pLink = $rssDOM->createElement('link', 'http://www.partkeepr.org');
$pDescription = $rssDOM->createElement('description', 'PartKeepr new part feed');
$pLang = $rssDOM->createElement('language', 'en');
// Here we simply append all the nodes we just created to the channel node
$channel->appendChild($pTitle);
$channel->appendChild($pDescription);
$channel->appendChild($pLink);
$channel->appendChild($pLang);
foreach ($parts as $part) {
    $item = $rssDOM->createElement("item");
    $title = $rssDOM->createElement("title");
    $titleContent = $rssDOM->createTextNode($part->getName());
    $title->appendChild($titleContent);
    $description = $rssDOM->createElement("description");
    $descriptionContent = $rssDOM->createTextNode($part->getComment());
    $description->appendChild($descriptionContent);
    $category = $rssDOM->createElement("partkeepr:category");
    $categoryContent = $rssDOM->createTextNode($part->getCategory()->getCategoryPath());
    $category->appendChild($categoryContent);
    $pubDate = $rssDOM->createElement("pubDate", $part->getCreateDate()->format(DATE_RFC822));
    $item->appendChild($title);
    $item->appendChild($description);
    $item->appendChild($category);
    $item->appendChild($pubDate);
    $channel->appendChild($item);
}
$rssDOM->save(Configuration::getOption("partkeepr.files.path") . "/feed.rss");
Пример #15
0
 /**
  * Scales the image to a specific width and height
  *
  * @param int $w The width
  * @param int $h The height
  * @return string The path to the scaled file
  */
 public function scaleTo($w, $h)
 {
     $this->ensureCachedirExists();
     $outputFile = Configuration::getOption("partkeepr.images.cache") . md5($this->getFilename() . $w . "x" . $h) . ".png";
     if (file_exists($outputFile)) {
         return $outputFile;
     }
     $this->getRenderer()->scaleTo($outputFile, $w, $h);
     $cachedImage = new CachedImage($this, $outputFile);
     PartKeepr::getEM()->persist($cachedImage);
     return $outputFile;
 }
Пример #16
0
if ($ask) {
    echo "If you are sure you want to do this, type YES and hit return.\n";
    $fp = fopen('php://stdin', 'r');
    $data = fgets($fp, 1024);
    if ($data !== "YES\n") {
        echo "Aborting.\n";
        die;
    }
}
echo "Performing actions...\n";
$setup = new Setup();
$setup->setConsole();
$setup->runCLIChecks();
$setup->run();
if ($migration) {
    if (Configuration::getOption("partkeepr.migration.partdb.hostname", false) === false || Configuration::getOption("partkeepr.migration.partdb.username", false) === false || Configuration::getOption("partkeepr.migration.partdb.password", false) === false || Configuration::getOption("partkeepr.migration.partdb.dbname", false) === false) {
        echo "Error migrating from partdb: One or more configuration settings are missing.\n";
        echo "Please make sure that you define the partkeepr.migration.partdb.* keys, as shown in config.php.template\n\n";
        echo "After adjusting the keys, you can safely re-run the setup, even if you already have worked with PartKeepr.\n";
        exit;
    }
    mysql_connect(Configuration::getOption("partkeepr.migration.partdb.hostname"), Configuration::getOption("partkeepr.migration.partdb.username"), Configuration::getOption("partkeepr.migration.partdb.password"));
    mysql_query("SET CHARACTER SET UTF8");
    mysql_query("SET NAMES UTF8");
    mysql_select_db(Configuration::getOption("partkeepr.migration.partdb.dbname"));
    $migration = new PartDBMigration();
    $migration->setConsole();
    $migration->run();
}
echo "All done.\n\n";
echo "Use the user 'admin' with password 'admin' to login. Access the frontend using the `frontend` directory.\n";
Пример #17
0
 /**
  * Returns the path to the file. May be overridden by
  * subclasses.
  *
  * @param none
  * @return string The path to the file
  */
 public function getFilePath()
 {
     return Configuration::getOption("partkeepr.files.path", PartKeepr::getRootDirectory() . "/data/") . $this->getType() . "/";
 }
Пример #18
0
 public static function createConnectionOptionsFromConfig()
 {
     $connectionOptions = array();
     $driver = PartKeeprConfiguration::getOption("partkeepr.database.driver");
     switch ($driver) {
         case "pdo_mysql":
             // Force SET NAMES, as PHP/PDO <5.3.6 silently ignores "charset"
             $connectionOptions["driverOptions"] = array(1002 => 'SET NAMES utf8');
         case "pdo_pgsql":
         case "pdo_oci":
         case "oci8":
         case "pdo_sqlsrv":
             $connectionOptions["driver"] = $driver;
             $connectionOptions["dbname"] = PartKeeprConfiguration::getOption("partkeepr.database.dbname", "partkeepr");
             $connectionOptions["user"] = PartKeeprConfiguration::getOption("partkeepr.database.username", "partkeepr");
             $connectionOptions["password"] = PartKeeprConfiguration::getOption("partkeepr.database.password", "partkeepr");
             $connectionOptions["charset"] = "utf8";
             /**
              * Compatibility with older configuration files. We check for the key "hostname" as well as "host".
              */
             if (PartKeeprConfiguration::getOption("partkeepr.database.hostname", null) !== null) {
                 $connectionOptions["host"] = PartKeeprConfiguration::getOption("partkeepr.database.hostname");
             } else {
                 $connectionOptions["host"] = PartKeeprConfiguration::getOption("partkeepr.database.host", "localhost");
             }
             if (PartKeeprConfiguration::getOption("partkeepr.database.port") !== null) {
                 $connectionOptions["port"] = PartKeeprConfiguration::getOption("partkeepr.database.port");
             }
             if (PartKeeprConfiguration::getOption("partkeepr.database.mysql_socket", null) !== null) {
                 $connectionOptions["unix_socket"] = PartKeeprConfiguration::getOption("partkeepr.database.mysql_socket");
             }
             break;
         case "pdo_sqlite":
             $connectionOptions["driver"] = $driver;
             $connectionOptions["user"] = PartKeeprConfiguration::getOption("partkeepr.database.username", "partkeepr");
             $connectionOptions["password"] = PartKeeprConfiguration::getOption("partkeepr.database.password", "partkeepr");
             $connectionOptions["path"] = PartKeeprConfiguration::getOption("partkeepr.database.sqlite_path", PartKeepr::getRootDirectory() . "/data/partkeepr.sqlite");
             break;
         default:
             throw new \Exception(sprintf("Unknown driver %s", $driver));
     }
     return $connectionOptions;
 }
Пример #19
0
 /**
  * Runs some checks for the CLI setup
  */
 public function runCLIChecks()
 {
     if (PartKeeprConfiguration::getOption("partkeepr.database.driver") == "pdo_mysql") {
         $dbname = PartKeeprConfiguration::getOption("partkeepr.database.dbname");
         if (!SchemaSetup::mysqlHasUTF8Encoding(PartKeepr::getEM()->getConnection(), $dbname)) {
             echo "Error: The database {$dbname} hasn't got the UTF-8 encoding. You need to set the database encoding to UTF-8. Aborting.\n";
             die;
         }
     }
 }