/**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the link
     $this->_linkId = $this->_request->getValue("linkId");
     $links = new MyLinks();
     $link = $links->getMyLink($this->_linkId, $this->_blogInfo->getId());
     // show an error if we couldn't fetch the link
     if (!$link) {
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_link"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_LINK_LOADED, array("link" => &$link));
     // otherwise show the form to edit its fields
     $this->_view = new AdminEditLinkView($this->_blogInfo);
     $this->_view->setValue("linkName", $link->getName());
     $this->_view->setValue("linkDescription", $link->getDescription());
     $this->_view->setValue("linkUrl", $link->getUrl());
     $this->_view->setValue("linkRssFeed", $link->getRssFeed());
     $this->_view->setValue("linkId", $link->getId());
     $this->_view->setValue("linkCategoryId", $link->getCategoryId());
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the data
     $this->_linkName = Textfilter::filterAllHTML($this->_request->getValue("linkName"));
     $this->_linkUrl = Textfilter::filterAllHTML($this->_request->getValue("linkUrl"));
     $this->_linkCategoryId = $this->_request->getValue("linkCategoryId");
     $this->_linkDescription = Textfilter::filterAllHTML($this->_request->getValue("linkDescription"));
     $this->_linkRss = Textfilter::filterAllHTML($this->_request->getValue("linkRssFeed"));
     $this->_properties = array();
     // adds the new link to the database
     $myLinks = new MyLinks();
     $myLink = new MyLink($this->_linkName, $this->_linkDescription, $this->_linkUrl, $this->_blogInfo->getId(), $this->_linkCategoryId, 0, $this->_linkRss, $this->_properties);
     $this->notifyEvent(EVENT_PRE_LINK_ADD, array("link" => &$link));
     if (!$myLinks->addMyLink($myLink, $this->_blogInfo->getId())) {
         $this->_view = new AdminNewLinkView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_adding_link"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_LINK_ADD, array("link" => &$link));
     $this->_view = new AdminLinksListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("link_added_ok", $myLink->getName()));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     // better to return true if everything fine
     return true;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // data is fine, we have already validated it
     $this->_linkName = Textfilter::filterAllHTML($this->_request->getValue("linkName"));
     $this->_linkDescription = Textfilter::filterAllHTML($this->_request->getValue("linkDescription"));
     $this->_linkUrl = Textfilter::filterAllHTML($this->_request->getValue("linkUrl"));
     $this->_linkCategoryId = $this->_request->getValue("linkCategoryId");
     $this->_linkId = $this->_request->getValue("linkId");
     $this->_linkFeed = Textfilter::filterAllHTML($this->_request->getValue("linkRssFeed"));
     // fetch the link we're trying to update
     $links = new MyLinks();
     $link = $links->getMyLink($this->_linkId, $this->_blogInfo->getId());
     if (!$link) {
         $this->_view = new AdminLinksListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_link"));
         $this->setCommonData();
         return false;
     }
     // update the fields
     $link->setName($this->_linkName);
     $link->setDescription($this->_linkDescription);
     $link->setCategoryId($this->_linkCategoryId);
     $link->setUrl($this->_linkUrl);
     $link->setProperties($this->_properties);
     $link->setRssFeed($this->_linkFeed);
     $this->notifyEvent(EVENT_PRE_LINK_UPDATE, array("link" => &$link));
     // and now update it in the database
     if (!$links->updateMyLink($link)) {
         $this->_view = new AdminLinksListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_link"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_LINK_UPDATE, array("link" => &$link));
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     // and go back to the view with the list of links
     $this->_view = new AdminLinksListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("link_updated_ok", $link->getName()));
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * Returns the categories for my_links for a given blog
  *
  * @param blogId Identifier of the blog.
  * @param order
  * @param page
  * @param itemsPerPage
  */
 function getMyLinksCategories($blogId, $order = MYLINKS_CATEGORIES_NO_ORDER, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE)
 {
     $prefix = $this->getPrefix();
     // basic query
     $query = "SELECT c.id AS id, c.name AS name, c.blog_id AS blog_id, \n\t\t\t\t\t\t\tc.last_modification AS last_modification, c.properties AS properties, \n\t\t\t\t\t\t\tIF(l.id IS NULL, 0, COUNT(*)) AS num_links\n\t\t\t\t\t\tFROM {$prefix}mylinks_categories c LEFT JOIN {$prefix}mylinks l\n\t\t\t\t\t\tON l.blog_id = c.blog_id AND l.category_id = c.id \n\t\t\t\t\t\tWHERE c.blog_id= {$blogId}\n\t\t\t\t\t\tGROUP BY c.id";
     if ($order == MYLINKS_CATEGORIES_ALPHABETICAL_ORDER) {
         $query .= " ORDER BY c.name ASC";
     } elseif ($order == MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER) {
         $query .= " ORDER BY c.name DESC";
     } elseif ($order == MYLINKS_CATEGORIES_MOST_LINKS_FIRST) {
         $query .= " ORDER BY num_links DESC";
     } elseif ($order == MYLINKS_CATEGORIES_LESS_LINKS_FIRST) {
         $query .= " ORDER BY num_links ASC";
     } elseif ($order == MYLINKS_CATEGORIES_LAST_UPDATED_FIRST) {
         $query .= " ORDER BY c.last_modification ASC";
     } elseif ($order == MYLINKS_CATEGORIES_LAST_UPDATED_LAST) {
         $query .= " ORDER BY c.last_modification ASC";
     }
     // execute the query
     $result = $this->Execute($query, $page, $itemsPerPage);
     if (!$result) {
         return array();
     }
     if ($result->RowCount() == 0) {
         return array();
     }
     $myLinks = new MyLinks();
     $blogLinks = $myLinks->getLinks($blogId);
     $myLinksCategories = array();
     while ($row = $result->fetchRow($result)) {
         // configure the data for the category
         $myLinksCategory = new MyLinksCategory($row["name"], $row["blog_id"], $row["num_links"], unserialize($row["properties"]), $row["id"]);
         $myLinksCategories[$myLinksCategory->getId()] = $myLinksCategory;
     }
     // now assign the links to the correct category
     foreach ($blogLinks as $blogLink) {
         if ($myLinksCategories[$blogLink->getCategoryId()]) {
             $myLinksCategories[$blogLink->getCategoryId()]->addLink($blogLink);
         }
     }
     return $myLinksCategories;
 }
 /**
  * Carries out the specified action
  * @private
  */
 function _deleteLinks()
 {
     // delete the link
     $links = new MyLinks();
     $errorMessage = "";
     $successMessage = "";
     $numOk = 0;
     foreach ($this->_linkIds as $linkId) {
         // load the link
         $link = $links->getMyLink($linkId, $this->_blogInfo->getId());
         if ($link) {
             if (!$links->deleteMyLink($linkId, $this->_blogInfo->getId())) {
                 $errorMessage .= $this->_locale->pr("error_removing_link", $link->getName()) . "<br/>";
             } else {
                 $numOk++;
                 if ($numOk > 1) {
                     $successMessage = $this->_locale->pr("links_deleted_ok", $numOk);
                 } else {
                     $successMessage = $this->_locale->pr("link_deleted_ok", $link->getName());
                 }
             }
         } else {
             $errorMessage .= $this->_locale->pr("error_removing_link2", $linkId) . "<br/>";
         }
     }
     $this->_view = new AdminLinksListView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     // better to return true if everything fine
     return true;
 }
 /**
  * Carries out the specified action
  */
 function render()
 {
     // get the parameters
     $order = $this->getValue("showOrder");
     $categoryId = $this->getValue("showCategory");
     // get all the links and throw the event
     $links = new MyLinks();
     $blogLinks = $links->getLinks($this->_blogInfo->getId(), $categoryId, $this->_page, DEFAULT_ITEMS_PER_PAGE);
     $this->notifyEvent(EVENT_LINKS_LOADED, array("links" => &$blogLinks));
     // get the number of links
     $numLinks = $links->getNumLinks($this->_blogInfo->getId(), $categoryId);
     // get all the link categories but we have to respect the order that the user asked
     $linkCategories = new MyLinksCategories();
     $blogLinkCategories = $linkCategories->getMyLinksCategories($this->_blogInfo->getId(), $order);
     $this->notifyEvent(EVENT_LINK_CATEGORIES_LOADED, array("linkcategories" => &$blogLinkCategories));
     // prepare the pager
     $pager = new Pager("?op=editLinks&amp;showCategory={$categoryId}&amp;page=", $this->_page, $numLinks, DEFAULT_ITEMS_PER_PAGE);
     // put the data in the view
     $this->setValue("links", $blogLinks);
     $this->setValue("linkscategories", $blogLinkCategories);
     $this->setValue("currentcategory", $categoryId);
     $this->setValue("pager", $pager);
     parent::render();
 }
 /**
  * Removes a blog from the database. It also removes all its posts, its posts categories
  * its links, its links categories, its trackbacks and its comments
  *
  * @param blogId the id of the blog we'd like to delete
  */
 function deleteBlog($blogId)
 {
     // first of all, delete the posts
     $articles = new Articles();
     $articles->deleteBlogPosts($blogId);
     // next is to remove the article categories
     $articleCategories = new ArticleCategories();
     $articleCategories->deleteBlogCategories($blogId);
     // next, all the links and links categories
     $myLinks = new MyLinks();
     $myLinks->deleteBlogMyLinks($blogId);
     $myLinksCategories = new MyLinksCategories();
     $myLinksCategories->deleteBlogMyLinksCategories($blogId);
     // the permissions for the blog
     $perms = new UserPermissions();
     $perms->revokeBlogPermissions($blogId);
     // and finally, delete the blog
     $query = "DELETE FROM " . $this->getPrefix() . "blogs WHERE id = {$blogId}";
     $result = $this->Execute($query);
     return $result;
 }
 /**
  * Returns an array of MyLink objects
  *
  * @return Array of MyLink object
  */
 function getLinks()
 {
     if ($this->_links == null) {
         $myLinks = new MyLinks();
         $categoryLinks = $myLinks->getLinks($this->getBlogId(), $this->getId());
         $this->setLinks($categoryLinks);
     }
     return $this->_links;
 }