/** * Creates a unique identifier for a given article or * category title * * @param string $title * @param int $type * @return string */ protected function makeIdentifier($title, $type = self::_TYPE_ARTICLE) { $title = zula_clean($title); if (!$title) { $title = 'id-'; } $table = $type & self::_TYPE_ARTICLE ? 'mod_articles' : 'mod_article_cats'; $pdoSt = $this->_sql->prepare('SELECT identifier FROM {PREFIX}' . $table . ' WHERE identifier = :ident'); $i = null; do { $identifier = $title . $i; $pdoSt->bindValue(':ident', $identifier); $pdoSt->execute(); ++$i; } while ($pdoSt->rowCount() > 0); $pdoSt->closeCursor(); return $identifier; }
/** * Adds a new page and returns ID and identifier if successfuly * * @param string $title * @param string $body * @param int $parent * @return array|bool */ public function add($title, $body, $parent = 0) { $editor = new Editor($body); $i = null; do { try { $identifier = zula_clean($title) . $i; $this->getPage($identifier, false); ++$i; } catch (Page_NoExist $e) { break; } } while (true); $pdoSt = $this->_sql->prepare('INSERT INTO {PREFIX}mod_page (title, body, author, parent ,date, identifier) VALUES(?, ?, ?, ?, UTC_TIMESTAMP(), ?)'); $pdoSt->execute(array($title, $editor->preParse(), $this->_session->getUserId(), abs($parent), $identifier)); if ($pdoSt->rowCount()) { $id = $this->_sql->lastInsertId(); Hooks::notifyAll('page_add', $id, $identifier); return array('id' => $id, 'identifier' => $identifier); } else { return false; } }
/** * Adds a new media item to a category * * @param int $cid * @param string $name * @param string $desc * @param string $type Video/Image/Audio/External * @param string $filename * @param string $thumbnail * @param string $externalService * @param string $externalId * @return array */ public function addItem($cid, $name, $desc, $type, $filename, $thumbnail, $externalService = '', $externalId = '') { $category = $this->getCategory($cid); // Create the identifier for the item $i = null; do { try { $identifier = zula_clean($name) . $i; $this->getItem($identifier, false); ++$i; } catch (Media_ItemNoExist $e) { break; } } while (true); // Insert the new media item $pdoSt = $this->_sql->prepare('INSERT INTO {PREFIX}mod_media_items (cat_id, type, date, name, identifier, description, filename, thumbnail, external_service, external_id) VALUES(?, ?, UTC_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?)'); $pdoSt->execute(array($category['id'], $type, $name, $identifier, $desc, $filename, $thumbnail, $externalService, $externalId)); return array('id' => $this->_sql->lastInsertId(), 'identifier' => $identifier); }
/** * Adds a new contact form * * @param string $name * @param string $email * @param string $body * @return array|bool */ public function addForm($name, $email, $body) { $i = null; do { try { $identifier = zula_clean($name) . $i; $this->getForm($identifier, false); ++$i; } catch (Contact_NoExist $e) { break; } } while (true); $pdoSt = $this->_sql->prepare('INSERT INTO {PREFIX}mod_contact (name, identifier, email, body) VALUES(?, ?, ?, ?)'); $pdoSt->execute(array($name, $identifier, $email, $body)); $pdoSt->closeCursor(); if ($pdoSt->rowCount()) { $id = $this->_sql->lastInsertId(); $this->_cache->delete('contact_forms'); Hooks::notifyAll('contact_add_form', $id, $name, $identifier, $email, $body); return array('id' => $id, 'identifier' => $identifier); } else { return false; } }